Moving some Windows-specific code out of "freeglut_main.c" into the Windows-specific...
[freeglut] / src / Common / freeglut_main.c
index 2eed2d4..5287010 100644 (file)
@@ -77,6 +77,12 @@ struct GXKeyList gxKeyList;
        static pCloseTouchInputHandle fghCloseTouchInputHandle = (pCloseTouchInputHandle)0xDEADBEEF;\r
 #endif\r
 \r
+extern void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height );\r
+extern void fghcbPlatformDisplayWindow ( SFG_Window *window );\r
+extern void fghPlatformSleepForEvents( long msec );\r
+extern void fghProcessSingleEvent ( void );\r
+\r
+\r
 /*\r
  * TODO BEFORE THE STABLE RELEASE:\r
  *\r
@@ -95,65 +101,22 @@ struct GXKeyList gxKeyList;
  * callback is hooked, the viewport size is updated to\r
  * match the new window size.\r
  */\r
-static void fghReshapeWindow ( SFG_Window *window, int width, int height )\r
-{\r
-    SFG_Window *current_window = fgStructure.CurrentWindow;\r
-\r
-    freeglut_return_if_fail( window != NULL );\r
-\r
 #if TARGET_HOST_POSIX_X11\r
-\r
+static void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height )\r
+{\r
     XResizeWindow( fgDisplay.Display, window->Window.Handle,\r
                    width, height );\r
     XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */\r
+}\r
+#endif\r
 \r
-#elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)\r
-    {\r
-        RECT windowRect;\r
-\r
-        /*\r
-         * For windowed mode, get the current position of the\r
-         * window and resize taking the size of the frame\r
-         * decorations into account.\r
-         */\r
-\r
-        /* "GetWindowRect" returns the pixel coordinates of the outside of the window */\r
-        GetWindowRect( window->Window.Handle, &windowRect );\r
+static void fghReshapeWindow ( SFG_Window *window, int width, int height )\r
+{\r
+    SFG_Window *current_window = fgStructure.CurrentWindow;\r
 \r
-        /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */\r
-        windowRect.right    = windowRect.left+width;\r
-        windowRect.bottom   = windowRect.top+height;\r
+    freeglut_return_if_fail( window != NULL );\r
 \r
-        if (window->Parent == NULL)\r
-            /* get the window rect from this to feed to SetWindowPos, correct for window decorations */\r
-            fghComputeWindowRectFromClientArea_QueryWindow(window,&windowRect,TRUE);\r
-        else\r
-        {\r
-            /* correct rect for position client area of parent window\r
-             * (SetWindowPos input for child windows is in coordinates\r
-             * relative to the parent's client area).\r
-             * Child windows don't have decoration, so no need to correct\r
-             * for them.\r
-             */\r
-            RECT parentRect;\r
-            parentRect = fghGetClientArea( window->Parent, FALSE );\r
-            windowRect.left   -= parentRect.left;\r
-            windowRect.right  -= parentRect.left;\r
-            windowRect.top    -= parentRect.top;\r
-            windowRect.bottom -= parentRect.top;\r
-        }\r
-        \r
-        /* Do the actual resizing */\r
-        SetWindowPos( window->Window.Handle,\r
-                      HWND_TOP,\r
-                      windowRect.left, windowRect.top,\r
-                      windowRect.right - windowRect.left,\r
-                      windowRect.bottom- windowRect.top,\r
-                      SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |\r
-                      SWP_NOZORDER\r
-        );\r
-    }\r
-#endif\r
+       fghPlatformReshapeWindow ( window, width, height );\r
 \r
     if( FETCH_WCB( *window, Reshape ) )\r
         INVOKE_WCB( *window, Reshape, ( width, height ) );\r
@@ -212,6 +175,13 @@ static void fghRedrawWindow ( SFG_Window *window )
 /*\r
  * A static helper function to execute display callback for a window\r
  */\r
+#if TARGET_HOST_POSIX_X11\r
+static void fghcbPlatformDisplayWindow ( SFG_Window *window )\r
+{\r
+        fghRedrawWindow ( window ) ;\r
+}\r
+#endif\r
+\r
 static void fghcbDisplayWindow( SFG_Window *window,\r
                                 SFG_Enumerator *enumerator )\r
 {\r
@@ -219,16 +189,7 @@ static void fghcbDisplayWindow( SFG_Window *window,
         window->State.Visible )\r
     {\r
         window->State.Redisplay = GL_FALSE;\r
-\r
-#if TARGET_HOST_POSIX_X11\r
-        fghRedrawWindow ( window ) ;\r
-#elif TARGET_HOST_MS_WINDOWS\r
-\r
-        RedrawWindow(\r
-            window->Window.Handle, NULL, NULL,\r
-            RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW\r
-        );\r
-#endif\r
+               fghcbPlatformDisplayWindow ( window );\r
     }\r
 \r
     fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );\r
@@ -459,20 +420,10 @@ static long fghNextTimer( void )
  * Does the magic required to relinquish the CPU until something interesting\r
  * happens.\r
  */\r
-static void fghSleepForEvents( void )\r
-{\r
-    long msec;\r
-\r
-    if( fgState.IdleCallback || fghHavePendingRedisplays( ) )\r
-        return;\r
-\r
-    msec = fghNextTimer( );\r
-    /* XXX Use GLUT timers for joysticks... */\r
-    /* XXX Dumb; forces granularity to .01sec */\r
-    if( fghHaveJoystick( ) && ( msec > 10 ) )     \r
-        msec = 10;\r
 \r
 #if TARGET_HOST_POSIX_X11\r
+static void fghPlatformSleepForEvents( long msec )\r
+{\r
     /*\r
      * Possibly due to aggressive use of XFlush() and friends,\r
      * it is possible to have our socket drained but still have\r
@@ -501,9 +452,23 @@ static void fghSleepForEvents( void )
             fgWarning ( "freeglut select() error: %d", errno );\r
 #endif\r
     }\r
-#elif TARGET_HOST_MS_WINDOWS\r
-    MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );\r
+}\r
 #endif\r
+\r
+static void fghSleepForEvents( void )\r
+{\r
+    long msec;\r
+\r
+    if( fgState.IdleCallback || fghHavePendingRedisplays( ) )\r
+        return;\r
+\r
+    msec = fghNextTimer( );\r
+    /* XXX Use GLUT timers for joysticks... */\r
+    /* XXX Dumb; forces granularity to .01sec */\r
+    if( fghHaveJoystick( ) && ( msec > 10 ) )     \r
+        msec = 10;\r
+\r
+       fghPlatformSleepForEvents ( msec );\r
 }\r
 \r
 #if TARGET_HOST_POSIX_X11\r
@@ -523,10 +488,8 @@ int fghGetXModifiers( int state )
 \r
     return ret;\r
 }\r
-#endif\r
 \r
 \r
-#if TARGET_HOST_POSIX_X11 && _DEBUG\r
 \r
 static const char* fghTypeToString( int type )\r
 {\r
@@ -968,16 +931,9 @@ static void fghPrintEvent( XEvent *event )
     }\r
 }\r
 \r
-#endif\r
-\r
-/* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
 \r
-/*\r
- * Executes a single iteration in the freeglut processing loop.\r
- */\r
-void FGAPIENTRY glutMainLoopEvent( void )\r
+void fghProcessSingleEvent ( void )\r
 {\r
-#if TARGET_HOST_POSIX_X11\r
     SFG_Window* window;\r
     XEvent event;\r
 \r
@@ -1452,32 +1408,17 @@ void FGAPIENTRY glutMainLoopEvent( void )
             break;\r
         }\r
     }\r
+}\r
+#endif\r
 \r
-#elif TARGET_HOST_MS_WINDOWS\r
-\r
-    MSG stMsg;\r
-\r
-    FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );\r
-\r
-    while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )\r
-    {\r
-        if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )\r
-        {\r
-            if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )\r
-            {\r
-                fgDeinitialize( );\r
-                exit( 0 );\r
-            }\r
-            else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )\r
-                fgState.ExecState = GLUT_EXEC_STATE_STOP;\r
-\r
-            return;\r
-        }\r
+/* -- INTERFACE FUNCTIONS -------------------------------------------------- */\r
 \r
-        TranslateMessage( &stMsg );\r
-        DispatchMessage( &stMsg );\r
-    }\r
-#endif\r
+/*\r
+ * Executes a single iteration in the freeglut processing loop.\r
+ */\r
+void FGAPIENTRY glutMainLoopEvent( void )\r
+{\r
+       fghProcessSingleEvent ();\r
 \r
     if( fgState.Timers.First )\r
         fghCheckTimers( );\r