These change a bunch of assignments to calls to set the current window correctly...
authorJ.C. Jones <jc@insufficient.coffee>
Fri, 29 Aug 2003 18:10:06 +0000 (18:10 +0000)
committerJ.C. Jones <jc@insufficient.coffee>
Fri, 29 Aug 2003 18:10:06 +0000 (18:10 +0000)
git-svn-id: svn+ssh://svn.code.sf.net/p/freeglut/code/trunk/freeglut/freeglut@174 7f0cb862-5218-0410-a997-914c9d46530a

src/freeglut_main.c
src/freeglut_menu.c
src/freeglut_structure.c

index 3874517..6219980 100644 (file)
@@ -106,6 +106,8 @@ static void fghReshapeWindowByHandle
     ( HWND handle, int width, int height )
 #endif
 {
+  SFG_Window *current_window = fgStructure.Window ;
+
     /*
      * Find the window that received the reshape event
      */
@@ -142,6 +144,12 @@ static void fghReshapeWindowByHandle
      * we resize the window.
      */
     window->State.Redisplay = TRUE ;
+
+    /*
+     * If this is a menu, restore the active window
+     */
+    if ( window->IsMenu )
+      fgSetWindow ( current_window ) ;
 }
 
 /*
@@ -157,6 +165,8 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
         (window->State.Redisplay == TRUE) &&
         (window->State.Visible == TRUE) )
     {
+        SFG_Window *current_window = fgStructure.Window ;
+
         /*
          * OKi, this is the case: have the window set as the current one
          */
@@ -171,6 +181,8 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
          * And execute the display callback immediately after
          */
         window->Callbacks.Display();
+
+        fgSetWindow ( current_window ) ;
     }
 
 #elif TARGET_HOST_WIN32
@@ -180,6 +192,8 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
      */
     if( window->State.NeedToResize )
     {
+        SFG_Window *current_window = fgStructure.Window ;
+
         fgSetWindow( window );
 
         fghReshapeWindowByHandle( 
@@ -192,6 +206,8 @@ static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
          * Never ever do that again:
          */
         window->State.NeedToResize = FALSE;
+
+        fgSetWindow ( current_window ) ;
     }
 
     /*
@@ -313,7 +329,7 @@ static void fghCheckTimers( void )
             /*
              * Add the timer to the timed out timers list
              */
-           fgListRemove( &fgState.Timers, &timer->Node );
+                 fgListRemove( &fgState.Timers, &timer->Node );
             fgListAppend( &timedOut, &timer->Node );
         }
     }
@@ -617,6 +633,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
         if( window->Callbacks.Entry != NULL )
         {
           /*
+           * Set the current window
+           */
+          fgSetWindow ( window ) ;
+
+          /*
            * Yeah. Notify the window about having the mouse cursor over
            */
           window->Callbacks.Entry( GLUT_ENTERED );
@@ -637,6 +658,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
         if( window->Callbacks.Entry != NULL )
         {
           /*
+           * Set the current window
+           */
+          fgSetWindow ( window ) ;
+
+          /*
            * Yeah. Notify the window about having the mouse cursor over
            */
           window->Callbacks.Entry( GLUT_LEFT );
@@ -659,7 +685,12 @@ void FGAPIENTRY glutMainLoopEvent( void )
             /*
              * Let's make the window redraw as a result of the mouse motion.
              */
-            if ( window->IsMenu ) window->State.Redisplay = TRUE ;
+            window->State.Redisplay = TRUE ;
+
+            /*
+             * Since the window is a menu, make the parent window current
+             */
+            fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
 
             break;
         }
@@ -680,7 +711,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
             /*
              * Set the current window
              */
-            fgStructure.Window = window ;
+            fgSetWindow ( window ) ;
 
             /*
              * Yup. Have it executed immediately
@@ -698,7 +729,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
             /*
              * Set the current window
              */
-            fgStructure.Window = window ;
+            fgSetWindow ( window ) ;
 
             /*
              * That's right, and there is a passive callback, too.
@@ -778,6 +809,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
             if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
           }
 
+          /*
+           * Let's make the window redraw as a result of the mouse click and menu activity.
+           */
+          window->State.Redisplay = TRUE ;
+
           break ;
         }
 
@@ -787,6 +823,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
         if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
         {
           /*
+           * Let's make the window redraw as a result of the mouse click.
+           */
+          window->State.Redisplay = TRUE ;
+
+          /*
            * Set the current window
            */
           fgSetWindow( window );
@@ -802,13 +843,13 @@ void FGAPIENTRY glutMainLoopEvent( void )
         /*
          * Check if there is a mouse callback hooked to the window
          */
-        if( fgStructure.Window->Callbacks.Mouse == NULL )
+        if( window->Callbacks.Mouse == NULL )
           break;
 
         /*
          * Set the current window
          */
-        fgSetWindow( window );
+        fgSetWindow ( window );
 
         /*
          * Remember the current modifiers state
@@ -877,11 +918,6 @@ void FGAPIENTRY glutMainLoopEvent( void )
           len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
 
           /*
-           * Get ready to calling the keyboard/special callbacks
-           */
-          fgSetWindow( window );
-
-          /*
            * GLUT API tells us to have two separate callbacks...
            */
           if( len > 0 )
@@ -892,6 +928,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
             if( keyboard_cb != NULL )
             {
               /*
+               * Set the current window
+               */
+              fgSetWindow( window );
+
+              /*
                * Remember the current modifiers state
                */
               modifiers = 0;
@@ -966,6 +1007,11 @@ void FGAPIENTRY glutMainLoopEvent( void )
             if( (special_cb != NULL) && (special != -1) )
             {
               /*
+               * Set the current window
+               */
+              fgSetWindow( window );
+
+              /*
                * Remember the current modifiers state
                */
               modifiers = 0;
@@ -1005,7 +1051,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
     /*
      * No messages in the queue, which means we are idling...
      */
-    if ( fgState.IdleCallback != NULL )
+    if( fgState.IdleCallback != NULL )
         fgState.IdleCallback();
 
     /*
@@ -1051,7 +1097,7 @@ void FGAPIENTRY glutMainLoopEvent( void )
     /*
      * No messages in the queue, which means we are idling...
      */
-    if ( fgState.IdleCallback != NULL )
+    if( fgState.IdleCallback != NULL )
       fgState.IdleCallback();
 
     /*
@@ -1094,8 +1140,22 @@ void FGAPIENTRY glutMainLoop( void )
   while ( window != NULL )
   {
     if ( window->Callbacks.Visibility != NULL )
+    {
+      SFG_Window *current_window = fgStructure.Window ;
+
+      /*
+       * Set the current window
+       */
+      fgSetWindow( window );
+
       window->Callbacks.Visibility ( window->State.Visible ) ;
 
+      /*
+       * Restore the current window
+       */
+      fgSetWindow( current_window );
+    }
+
     window = (SFG_Window *)window->Node.Next ;
   }
 #endif
@@ -1383,7 +1443,12 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
             /*
              * Let's make the window redraw as a result of the mouse motion.
              */
-            if ( window->IsMenu ) window->State.Redisplay = TRUE ;
+            window->State.Redisplay = TRUE ;
+
+            /*
+             * Since the window is a menu, make the parent window current
+             */
+            fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
 
             break;
         }
@@ -1520,6 +1585,11 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
             if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
           }
 
+          /*
+           * Let's make the window redraw as a result of the mouse click and menu activity.
+           */
+          if ( ! window->IsMenu ) window->State.Redisplay = TRUE ;
+
           break ;
         }
 
@@ -1529,6 +1599,11 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
         {
             /*
+             * Let's make the window redraw as a result of the mouse click.
+             */
+            window->State.Redisplay = TRUE ;
+
+            /*
              * Set the current window
              */
             fgSetWindow( window );
@@ -1544,13 +1619,13 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         /*
          * Check if there is a mouse callback hooked to the window
          */
-        if( fgStructure.Window->Callbacks.Mouse == NULL )
+        if( window->Callbacks.Mouse == NULL )
             break;
 
         /*
          * Set the current window
          */
-        fgSetWindow( window );
+        fgSetWindow ( window );
 
         /*
          * Remember the current modifiers state.
@@ -1563,7 +1638,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         /*
          * Finally execute the mouse callback
          */
-        fgStructure.Window->Callbacks.Mouse(
+        window->Callbacks.Mouse(
             button,
             pressed == TRUE ? GLUT_DOWN : GLUT_UP,
             window->State.MouseX,
@@ -1590,11 +1665,6 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
             break;
 
         /*
-         * Set the current window
-         */
-        fgSetWindow( window );
-
-        /*
          * Remember the current modifiers state. This is done here in order 
          * to make sure the VK_DELETE keyboard callback is executed properly.
          */
@@ -1642,7 +1712,10 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
                  * The delete key should be treated as an ASCII keypress:
                  */
                 if( window->Callbacks.Keyboard != NULL )
+                {
+                    fgSetWindow( window );
                     window->Callbacks.Keyboard( 127, window->State.MouseX, window->State.MouseY );
+                }
         }
 
         /*
@@ -1651,6 +1724,11 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         if( (keypress != -1) && (window->Callbacks.Special != NULL) )
         {
             /*
+             * Set the current window
+             */
+            fgSetWindow( window );
+
+            /*
              * Have the special callback executed:
              */
             window->Callbacks.Special( keypress, window->State.MouseX, window->State.MouseY );
@@ -1670,11 +1748,6 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         POINT mouse_pos ;
 
         /*
-         * Set the current window
-         */
-        fgSetWindow( window );
-
-        /*
          * Remember the current modifiers state. This is done here in order 
          * to make sure the VK_DELETE keyboard callback is executed properly.
          */
@@ -1721,7 +1794,10 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
              * The delete key should be treated as an ASCII keypress:
              */
             if( window->Callbacks.KeyboardUp != NULL )
+            {
+                fgSetWindow ( window ) ;
                 window->Callbacks.KeyboardUp( 127, window->State.MouseX, window->State.MouseY );
+            }
 
             break ;
           default:
@@ -1738,7 +1814,14 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
                 wParam=code[ 0 ];
 
               if( window->Callbacks.KeyboardUp != NULL )
+              {
+                /*
+                 * Set the current window
+                 */
+                fgSetWindow( window );
+
                 window->Callbacks.KeyboardUp( (char)wParam, window->State.MouseX, window->State.MouseY );
+              }
             }
         }
 
@@ -1748,6 +1831,11 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         if( (keypress != -1) && (window->Callbacks.SpecialUp != NULL) )
         {
             /*
+             * Set the current window
+             */
+            fgSetWindow( window );
+
+            /*
              * Have the special callback executed:
              */
             window->Callbacks.SpecialUp( keypress, window->State.MouseX, window->State.MouseY );
@@ -1775,6 +1863,11 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
         if( window->Callbacks.Keyboard != NULL )
         {
             /*
+             * Set the current window
+             */
+            fgSetWindow( window );
+
+            /*
              * Remember the current modifiers state
              */
             window->State.Modifiers = 
@@ -1797,7 +1890,14 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPara
 
     case WM_CAPTURECHANGED :  /* User has finished resizing the window, force a redraw */
       if ( window->Callbacks.Display )
+      {
+        /*
+         * Set the current window
+         */
+        fgSetWindow( window );
+
         window->Callbacks.Display () ;
+      }
 
 /*      lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */
       break ;
index 9054cce..87e476f 100644 (file)
@@ -594,7 +594,7 @@ void fgDeactivateMenu( SFG_Window *window )
         fgDeactivateSubMenu ( menuEntry ) ;
     }
 
-    fgStructure.Window = current_window ;
+    fgSetWindow ( current_window ) ;
 }
 
 /*
@@ -629,7 +629,7 @@ void fgDeactivateSubMenu( SFG_MenuEntry *menuEntry )
         fgDeactivateSubMenu ( subMenuIter ) ;
     }
 
-    fgStructure.Window = current_window ;
+    fgSetWindow ( current_window ) ;
 }
 
 /*
index da29757..d8e09ad 100644 (file)
@@ -168,7 +168,7 @@ SFG_Menu* fgCreateMenu( FGCBmenu menuCallback )
     fgState.BuildingAMenu = FALSE ;
 
     glutHideWindow () ;  /* Hide the window for now */
-    fgStructure.Window = current_window ;
+    fgSetWindow ( current_window ) ;
 
     /*
      * Initialize the object properties:
@@ -296,9 +296,9 @@ void fgDestroyWindow( SFG_Window* window, GLboolean needToClose )
     if ( window->Callbacks.Destroy != NULL )
     {
       SFG_Window *activeWindow = fgStructure.Window ;
-      fgStructure.Window = window ;
+      fgSetWindow ( window ) ;
       window->Callbacks.Destroy () ;
-      fgStructure.Window = activeWindow ;
+      fgSetWindow ( activeWindow ) ;
     }
 
     /*