4 * The windows message processing methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define G_LOG_DOMAIN "freeglut-main"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * There are some issues concerning window redrawing under X11, and maybe
41 * some events are not handled. The Win32 version lacks some more features,
42 * but seems acceptable for not demanding purposes.
44 * Need to investigate why the X11 version breaks out with an error when
45 * closing a window (using the window manager, not glutDestroyWindow)...
48 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
51 * Calls a window's redraw method. This is used when
52 * a redraw is forced by the incoming window messages.
55 static void fghRedrawWindowByHandle
56 #if TARGET_HOST_UNIX_X11
58 #elif TARGET_HOST_WIN32
63 * Find the window we have to redraw...
65 SFG_Window* window = fgWindowByHandle( handle );
66 freeglut_return_if_fail( window != NULL );
69 * Check if there is a display callback hooked to it
71 freeglut_return_if_fail( window->Callbacks.Display != NULL );
74 * Return if the window is not visible
76 freeglut_return_if_fail( window->State.Visible == TRUE );
79 * Set the window as the current one.
81 fgSetWindow( window );
84 * Do not exagerate with the redisplaying
86 window->State.Redisplay = FALSE;
89 * Have the callback executed now. The buffers should
90 * be swapped by the glutSwapBuffers() execution inside
91 * the callback itself.
94 window->Callbacks.Display();
98 * Handle a window configuration change. When no reshape
99 * callback is hooked, the viewport size is updated to
100 * match the new window size.
102 static void fghReshapeWindowByHandle
103 #if TARGET_HOST_UNIX_X11
104 ( Window handle, int width, int height )
105 #elif TARGET_HOST_WIN32
106 ( HWND handle, int width, int height )
109 SFG_Window *current_window = fgStructure.Window ;
112 * Find the window that received the reshape event
114 SFG_Window* window = fgWindowByHandle( handle );
115 freeglut_return_if_fail( window != NULL );
118 * Remember about setting the current window...
120 fgSetWindow( window );
123 * Check if there is a reshape callback hooked
125 if( window->Callbacks.Reshape != NULL )
128 * OKi, have it called immediately
130 window->Callbacks.Reshape( width, height );
135 * Otherwise just resize the viewport
137 glViewport( 0, 0, width, height );
141 * Force a window redraw. In Windows at least this is only a partial solution: if the
142 * window is increasing in size in either dimension, the already-drawn part does not get
143 * drawn again and things look funny. But without this we get this bad behaviour whenever
144 * we resize the window.
146 window->State.Redisplay = TRUE ;
149 * If this is a menu, restore the active window
151 if ( window->IsMenu )
152 fgSetWindow ( current_window ) ;
156 * A static helper function to execute display callback for a window
158 static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
160 #if TARGET_HOST_UNIX_X11
162 * Check if there is an idle callback hooked
164 if( (window->Callbacks.Display != NULL) &&
165 (window->State.Redisplay == TRUE) &&
166 (window->State.Visible == TRUE) )
168 SFG_Window *current_window = fgStructure.Window ;
171 * OKi, this is the case: have the window set as the current one
173 fgSetWindow( window );
176 * Do not exagerate with the redisplaying
178 window->State.Redisplay = FALSE;
181 * And execute the display callback immediately after
183 window->Callbacks.Display();
185 fgSetWindow ( current_window ) ;
188 #elif TARGET_HOST_WIN32
191 * Do we need to explicitly resize the window?
193 if( window->State.NeedToResize )
195 SFG_Window *current_window = fgStructure.Window ;
197 fgSetWindow( window );
199 fghReshapeWindowByHandle(
200 window->Window.Handle,
201 glutGet( GLUT_WINDOW_WIDTH ),
202 glutGet( GLUT_WINDOW_HEIGHT )
206 * Never ever do that again:
208 window->State.NeedToResize = FALSE;
210 fgSetWindow ( current_window ) ;
214 * This is done in a bit different way under Windows
216 if( (window->Callbacks.Display != NULL) &&
217 (window->State.Redisplay == TRUE) &&
218 (window->State.Visible == TRUE) )
221 * Do not exagerate with the redisplaying
223 window->State.Redisplay = FALSE;
226 window->Window.Handle, NULL, NULL,
227 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
234 * Process this window's children (if any)
236 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
240 * Make all windows perform a display call
242 static void fghDisplayAll( void )
244 SFG_Enumerator enumerator;
247 * Uses a method very similiar for fgWindowByHandle...
249 enumerator.found = FALSE;
250 enumerator.data = NULL;
253 * Start the enumeration now:
255 fgEnumWindows( fghcbDisplayWindow, &enumerator );
259 * Window enumerator callback to check for the joystick polling code
261 static void fghcbCheckJoystickPolls( SFG_Window *window, SFG_Enumerator *enumerator )
263 long int checkTime = fgElapsedTime();
266 * Check if actually need to do the poll for the currently enumerated window:
268 if( window->State.JoystickLastPoll + window->State.JoystickPollRate >= checkTime )
271 * Yeah, that's it. Poll the joystick...
273 fgJoystickPollWindow( window );
276 * ...and reset the polling counters:
278 window->State.JoystickLastPoll = checkTime;
282 * Process this window's children (if any)
284 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
288 * Check all windows for joystick polling
290 static void fghCheckJoystickPolls( void )
292 SFG_Enumerator enumerator;
295 * Uses a method very similiar for fgWindowByHandle...
297 enumerator.found = FALSE;
298 enumerator.data = NULL;
301 * Start the enumeration now:
303 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
307 * Check the global timers
309 static void fghCheckTimers( void )
311 long checkTime = fgElapsedTime();
312 SFG_Timer *timer, *next;
315 fgListInit(&timedOut);
318 * For every timer that is waiting for triggering
320 for( timer = (SFG_Timer *)fgState.Timers.First; timer; timer = (SFG_Timer *)next )
322 next = (SFG_Timer *)timer->Node.Next;
325 * Check for the timeout:
327 if( timer->TriggerTime <= checkTime )
330 * Add the timer to the timed out timers list
332 fgListRemove( &fgState.Timers, &timer->Node );
333 fgListAppend( &timedOut, &timer->Node );
338 * Now feel free to execute all the hooked and timed out timer callbacks
339 * And delete the timed out timers...
341 while ( (timer = (SFG_Timer *)timedOut.First) )
343 if( timer->Callback != NULL )
344 timer->Callback( timer->ID );
345 fgListRemove( &timedOut, &timer->Node );
354 long fgElapsedTime( void )
356 #if TARGET_HOST_UNIX_X11
360 gettimeofday( &now, NULL );
362 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
363 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
366 #elif TARGET_HOST_WIN32
367 return (timeGetTime() - fgState.Time.Value);
374 void fgError( const char *fmt, ... )
380 fprintf( stderr, "freeglut: ");
381 vfprintf( stderr, fmt, ap );
382 fprintf( stderr, "\n" );
389 void fgWarning( const char *fmt, ... )
395 fprintf( stderr, "freeglut: ");
396 vfprintf( stderr, fmt, ap );
397 fprintf( stderr, "\n" );
405 static void fgCleanUpGlutsMess( void )
411 if ( fgStructure.Windows.First != NULL )
413 SFG_Window *win = (SFG_Window *)fgStructure.Windows.First ;
417 while ( win != NULL )
419 SFG_Window *temp_win = (SFG_Window *)win->Node.Next ;
420 fgDestroyWindow ( win, FALSE ) ;
426 /* these are pointers to external handles */
428 __glutWindowListSize = 0;
429 __glutStaleWindowList = NULL;
430 __glutWindowList = NULL;
431 __glutCurrentWindow = NULL;
433 /* make sure we no longer have a GL context */
435 if ( wglGetCurrentContext() != NULL )
437 wglDeleteContext( wglGetCurrentContext() );
440 hInstance = GetModuleHandle(NULL);
441 UnregisterClass( classname, hInstance );
443 /* clean up allocated timer memory */
445 tList = __glutTimerList;
448 while ( __glutTimerList )
451 tList = __glutTimerList;
453 if ( __glutTimerList )
454 __glutTimerList = __glutTimerList->next;
463 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
466 * Executes a single iteration in the freeglut processing loop.
468 void FGAPIENTRY glutMainLoopEvent( void )
470 #if TARGET_HOST_UNIX_X11
476 * This code was repeated constantly, so here it goes into a definition:
478 # define GETWINDOW(a) window = fgWindowByHandle( event.a.window );if( window == NULL ) break;
479 # define GETMOUSE(a) window->State.MouseX = event.a.x; window->State.MouseY = event.a.y;
482 * Make sure the display has been created etc.
484 freeglut_assert_ready;
487 * Do we have any event messages pending?
489 if( XPending( fgDisplay.Display ) )
492 * Grab the next event to be processed...
494 XNextEvent( fgDisplay.Display, &event );
497 * Check the event's type
503 * The window creation confirmation
509 * This is sent to confirm the XDestroyWindow call.
512 * Call the window closure callback, remove from the structure, etc.
514 /* fgAddToWindowDestroyList ( window, FALSE ); */
520 * Destroy the window when the WM_DELETE_WINDOW message arrives
522 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
524 GETWINDOW( xclient );
527 * Call the XWindows functions to close the window
529 fgCloseWindow ( window ) ;
532 * Call the window closure callback, remove from the structure, etc.
534 fgAddToWindowDestroyList ( window, FALSE );
540 * A window of ours has been unmapped...
546 * We are too dumb to process partial exposes...
548 if( event.xexpose.count == 0 )
549 fghRedrawWindowByHandle( event.xexpose.window );
552 case ConfigureNotify:
554 * The window gets resized
556 fghReshapeWindowByHandle(
557 event.xconfigure.window,
558 event.xconfigure.width,
559 event.xconfigure.height
565 * Have the client's keyboard knowledge updated (xlib.ps,
566 * page 206, says that's a good thing to do)
568 XRefreshKeyboardMapping( (XMappingEvent *) &event );
571 case VisibilityNotify:
574 * The window's visiblity might have changed
576 GETWINDOW( xvisibility );
579 * Break now if no window status callback has been hooked to that window
581 if( window->Callbacks.WindowStatus == NULL )
585 * We're going to send a callback to a window. Make it current.
587 fgSetWindow( window );
590 * Sending this event, the X server can notify us that the window has just
591 * acquired one of the three possible visibility states: VisibilityUnobscured,
592 * VisibilityPartiallyObscured or VisibilityFullyObscured
594 switch( event.xvisibility.state )
596 case VisibilityUnobscured:
598 * We are fully visible...
600 window->Callbacks.WindowStatus( GLUT_FULLY_RETAINED );
601 window->State.Visible = TRUE;
604 case VisibilityPartiallyObscured:
606 * The window is partially visible
608 window->Callbacks.WindowStatus( GLUT_PARTIALLY_RETAINED );
609 window->State.Visible = TRUE;
612 case VisibilityFullyObscured:
614 * The window is totally obscured
616 window->Callbacks.WindowStatus( GLUT_FULLY_COVERED );
617 window->State.Visible = FALSE;
626 * Mouse is over one of our windows
628 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
631 * Is there an entry callback hooked to the window?
633 if( window->Callbacks.Entry != NULL )
636 * Set the current window
638 fgSetWindow ( window ) ;
641 * Yeah. Notify the window about having the mouse cursor over
643 window->Callbacks.Entry( GLUT_ENTERED );
651 * Mouse is no longer over one of our windows
653 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
656 * Is there an entry callback hooked to the window?
658 if( window->Callbacks.Entry != NULL )
661 * Set the current window
663 fgSetWindow ( window ) ;
666 * Yeah. Notify the window about having the mouse cursor over
668 window->Callbacks.Entry( GLUT_LEFT );
676 * The mouse cursor was moved...
678 GETWINDOW( xmotion ); GETMOUSE( xmotion );
681 * Fallback if there's an active menu hooked to this window
683 if( window->ActiveMenu != NULL )
686 * Let's make the window redraw as a result of the mouse motion.
688 window->State.Redisplay = TRUE ;
691 * Since the window is a menu, make the parent window current
693 fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
699 * What kind of a movement was it?
701 if( (event.xmotion.state & Button1Mask) || (event.xmotion.state & Button2Mask) ||
702 (event.xmotion.state & Button3Mask) || (event.xmotion.state & Button4Mask) ||
703 (event.xmotion.state & Button5Mask) )
706 * A mouse button was pressed during the movement...
707 * Is there a motion callback hooked to the window?
709 if( window->Callbacks.Motion != NULL )
712 * Set the current window
714 fgSetWindow ( window ) ;
717 * Yup. Have it executed immediately
719 window->Callbacks.Motion( event.xmotion.x, event.xmotion.y );
725 * Otherwise it was a passive movement...
727 if( window->Callbacks.Passive != NULL )
730 * Set the current window
732 fgSetWindow ( window ) ;
735 * That's right, and there is a passive callback, too.
737 window->Callbacks.Passive( event.xmotion.x, event.xmotion.y );
746 GLboolean pressed = TRUE ;
749 if ( event.type == ButtonRelease ) pressed = FALSE ;
752 * A mouse button has been pressed or released. Traditionally,
753 * break if the window was found within the freeglut structures.
755 GETWINDOW( xbutton ); GETMOUSE( xbutton );
758 * GLUT API assumes that you can't have more than three mouse buttons, so:
760 switch( event.xbutton.button )
763 * WARNING: this might be wrong, if we only have two mouse buttons,
764 * Button2 might mean the right button, isn't that right?
766 case Button1: button = GLUT_LEFT_BUTTON; break;
767 case Button2: button = GLUT_MIDDLE_BUTTON; break;
768 case Button3: button = GLUT_RIGHT_BUTTON; break;
769 default: button = -1; break;
773 * Skip the unwanted mouse buttons...
779 * Do not execute the application's mouse callback if a menu is hooked to this button.
780 * In that case an appropriate private call should be generated.
781 * Near as I can tell, this is the menu behaviour:
782 * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
783 * - Down-click any button outside the menu, menu active: deactivate the menu
784 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
785 * - Up-click the menu button, menu not active: nothing happens
786 * - Up-click the menu button outside the menu, menu active: nothing happens
787 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
789 if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
791 if ( fgCheckActiveMenu ( window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
793 /* Save the current window and menu and set the current window to the window whose menu this is */
794 SFG_Window *save_window = fgStructure.Window ;
795 SFG_Menu *save_menu = fgStructure.Menu ;
796 SFG_Window *parent_window = window->ActiveMenu->ParentWindow ;
797 fgSetWindow ( window ) ;
798 fgStructure.Menu = window->ActiveMenu ;
800 /* Execute the menu callback */
801 fgExecuteMenuCallback ( window->ActiveMenu ) ;
802 fgDeactivateMenu ( parent_window ) ;
804 /* Restore the current window and menu */
805 fgSetWindow ( save_window ) ;
806 fgStructure.Menu = save_menu ;
808 else /* Outside the menu, deactivate the menu if it's a downclick */
810 if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
814 * Let's make the window redraw as a result of the mouse click and menu activity.
816 window->State.Redisplay = TRUE ;
822 * No active menu, let's check whether we need to activate one.
824 if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
827 * Let's make the window redraw as a result of the mouse click.
829 window->State.Redisplay = TRUE ;
832 * Set the current window
834 fgSetWindow( window );
837 * Activate the appropriate menu structure...
839 fgActivateMenu( window, button );
845 * Check if there is a mouse callback hooked to the window
847 if( window->Callbacks.Mouse == NULL )
851 * Set the current window
853 fgSetWindow ( window );
856 * Remember the current modifiers state
859 if (event.xbutton.state & (ShiftMask|LockMask))
860 modifiers |= GLUT_ACTIVE_SHIFT;
861 if (event.xbutton.state & ControlMask)
862 modifiers |= GLUT_ACTIVE_CTRL;
863 if (event.xbutton.state & Mod1Mask)
864 modifiers |= GLUT_ACTIVE_ALT;
865 fgStructure.Window->State.Modifiers = modifiers;
868 * Finally execute the mouse callback
870 fgStructure.Window->Callbacks.Mouse(
872 event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
878 * Trash the modifiers state
880 fgStructure.Window->State.Modifiers = 0xffffffff;
887 FGCBkeyboard keyboard_cb;
888 FGCBspecial special_cb;
891 * A key has been pressed, find the window that had the focus:
893 GETWINDOW( xkey ); GETMOUSE( xkey );
895 if( event.type == KeyPress )
897 keyboard_cb = window->Callbacks.Keyboard;
898 special_cb = window->Callbacks.Special;
902 keyboard_cb = window->Callbacks.KeyboardUp;
903 special_cb = window->Callbacks.SpecialUp;
907 * Is there a keyboard/special callback hooked for this window?
909 if( (keyboard_cb != NULL) || (special_cb != NULL) )
911 XComposeStatus composeStatus;
912 char asciiCode[ 32 ];
917 * Check for the ASCII/KeySym codes associated with the event:
919 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
922 * GLUT API tells us to have two separate callbacks...
927 * ...one for the ASCII translateable keypresses...
929 if( keyboard_cb != NULL )
932 * Set the current window
934 fgSetWindow( window );
937 * Remember the current modifiers state
940 if (event.xkey.state & (ShiftMask|LockMask))
941 modifiers |= GLUT_ACTIVE_SHIFT;
942 if (event.xkey.state & ControlMask)
943 modifiers |= GLUT_ACTIVE_CTRL;
944 if (event.xkey.state & Mod1Mask)
945 modifiers |= GLUT_ACTIVE_ALT;
946 window->State.Modifiers = modifiers;
949 * Execute the callback
951 keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y );
954 * Trash the modifiers state
956 window->State.Modifiers = 0xffffffff;
964 * ...and one for all the others, which need to be translated to GLUT_KEY_Xs...
969 * First the function keys come:
971 case XK_F1: special = GLUT_KEY_F1; break;
972 case XK_F2: special = GLUT_KEY_F2; break;
973 case XK_F3: special = GLUT_KEY_F3; break;
974 case XK_F4: special = GLUT_KEY_F4; break;
975 case XK_F5: special = GLUT_KEY_F5; break;
976 case XK_F6: special = GLUT_KEY_F6; break;
977 case XK_F7: special = GLUT_KEY_F7; break;
978 case XK_F8: special = GLUT_KEY_F8; break;
979 case XK_F9: special = GLUT_KEY_F9; break;
980 case XK_F10: special = GLUT_KEY_F10; break;
981 case XK_F11: special = GLUT_KEY_F11; break;
982 case XK_F12: special = GLUT_KEY_F12; break;
985 * Then the arrows and stuff:
987 case XK_Left: special = GLUT_KEY_LEFT; break;
988 case XK_Right: special = GLUT_KEY_RIGHT; break;
989 case XK_Up: special = GLUT_KEY_UP; break;
990 case XK_Down: special = GLUT_KEY_DOWN; break;
993 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
995 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
997 case XK_Home: special = GLUT_KEY_HOME; break;
999 case XK_End: special = GLUT_KEY_END; break;
1001 case XK_Insert: special = GLUT_KEY_INSERT; break;
1005 * Execute the callback (if one has been specified),
1006 * given that the special code seems to be valid...
1008 if( (special_cb != NULL) && (special != -1) )
1011 * Set the current window
1013 fgSetWindow( window );
1016 * Remember the current modifiers state
1019 if (event.xkey.state & (ShiftMask|LockMask))
1020 modifiers |= GLUT_ACTIVE_SHIFT;
1021 if (event.xkey.state & ControlMask)
1022 modifiers |= GLUT_ACTIVE_CTRL;
1023 if (event.xkey.state & Mod1Mask)
1024 modifiers |= GLUT_ACTIVE_ALT;
1025 window->State.Modifiers = modifiers;
1027 special_cb( special, event.xkey.x, event.xkey.y );
1030 * Trash the modifiers state
1032 window->State.Modifiers = 0xffffffff;
1043 * Have all the timers checked.
1048 * Poll the joystick and notify all windows that want to be notified...
1050 fghCheckJoystickPolls();
1053 * No messages in the queue, which means we are idling...
1055 if( fgState.IdleCallback != NULL )
1056 fgState.IdleCallback();
1059 * Remember about displaying all the windows that have
1060 * been marked for a redisplay (possibly in the idle call):
1065 #elif TARGET_HOST_WIN32
1070 * The windows processing is considerably smaller
1072 if( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1075 * Grab the message now, checking for WM_QUIT
1077 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1078 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1081 * Translate virtual-key messages and send them to the window...
1083 TranslateMessage( &stMsg );
1084 DispatchMessage( &stMsg );
1089 * Have all the timers checked.
1094 * Poll the joystick and notify all windows that want to be notified...
1096 fghCheckJoystickPolls();
1099 * No messages in the queue, which means we are idling...
1101 if( fgState.IdleCallback != NULL )
1102 fgState.IdleCallback();
1105 * Remember about displaying all the windows that have
1106 * been marked for a redisplay (possibly in the idle call):
1113 * If an event caused a window to be closed, do the actual closing here
1119 * Enters the freeglut processing loop. Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1121 void FGAPIENTRY glutMainLoop( void )
1123 #if TARGET_HOST_WIN32
1124 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1128 * Make sure the display has been created etc.
1130 freeglut_assert_ready;
1132 #if TARGET_HOST_WIN32
1134 * Processing before the main loop: If there is a window which is open and which
1135 * has a visibility callback, call it. I know this is an ugly hack, but I'm not sure
1136 * what else to do about it. Ideally we should leave something uninitialized in the
1137 * create window code and initialize it in the main loop, and have that initialization
1138 * create a "WM_ACTIVATE" message. Then we would put the visibility callback code in
1139 * the "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1141 while ( window != NULL )
1143 if ( window->Callbacks.Visibility != NULL )
1145 SFG_Window *current_window = fgStructure.Window ;
1148 * Set the current window
1150 fgSetWindow( window );
1152 window->Callbacks.Visibility ( window->State.Visible ) ;
1155 * Restore the current window
1157 fgSetWindow( current_window );
1160 window = (SFG_Window *)window->Node.Next ;
1165 * Set freeglut to be running
1167 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1170 * Enter the main loop itself. Inside the loop, process events and check for loop exit.
1172 while ( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1174 glutMainLoopEvent () ;
1177 * If there are no more windows open, stop execution
1179 if ( fgStructure.Windows.First == NULL )
1180 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1185 * If we got here by the user closing a window or by the application closing down, there may still be windows open.
1187 fgCleanUpGlutsMess () ;
1190 * Check whether we return to the calling program or simply exit
1192 if ( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1196 * When this loop terminates, destroy the display, state and structure
1197 * of a freeglut session, so that another glutInit() call can happen
1203 * Leaves the freeglut processing loop.
1205 void FGAPIENTRY glutLeaveMainLoop( void )
1207 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1211 * The window procedure for handling Win32 events
1213 #if TARGET_HOST_WIN32
1214 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
1216 SFG_Window* window = fgWindowByHandle( hWnd );
1220 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1221 return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
1223 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0, uMsg, wParam, lParam ) ; */
1225 * Check what type of message are we receiving
1231 * The window structure is passed as the creation structure paramter...
1233 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1234 assert( window != NULL );
1237 * We can safely store the window's handle now:
1239 window->Window.Handle = hWnd;
1242 * Get the window's device context
1244 window->Window.Device = GetDC( hWnd );
1247 * Create or get the OpenGL rendering context now
1249 if ( fgState.BuildingAMenu )
1252 * Setup the pixel format of our window
1254 unsigned int current_DisplayMode = fgState.DisplayMode ;
1255 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
1256 fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
1257 fgState.DisplayMode = current_DisplayMode ;
1260 * If there isn't already an OpenGL rendering context for menu windows, make one
1262 if ( !fgStructure.MenuContext )
1264 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
1265 fgStructure.MenuContext->Context = wglCreateContext( window->Window.Device );
1268 wglMakeCurrent ( window->Window.Device, fgStructure.MenuContext->Context ) ;
1270 /* window->Window.Context = wglGetCurrentContext () ; */
1271 window->Window.Context = wglCreateContext( window->Window.Device );
1276 * Setup the pixel format of our window
1278 fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
1280 if ( fgState.UseCurrentContext == TRUE )
1282 window->Window.Context = wglGetCurrentContext();
1283 if ( ! window->Window.Context )
1284 window->Window.Context = wglCreateContext( window->Window.Device );
1287 window->Window.Context = wglCreateContext( window->Window.Device );
1291 * Still, we'll be needing to explicitly resize the window
1293 window->State.NeedToResize = TRUE;
1296 * Finally, have the window's device context released
1298 ReleaseDC( window->Window.Handle, window->Window.Device );
1303 * We got resized... But check if the window has been already added...
1305 fghReshapeWindowByHandle( hWnd, LOWORD(lParam), HIWORD(lParam) );
1309 printf("WM_SETFOCUS: %p\n", window );
1310 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1314 if (LOWORD(wParam) != WA_INACTIVE)
1316 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1317 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window, window->State.Cursor );
1319 glutSetCursor( window->State.Cursor );
1322 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1328 * Windows seems to need reminding to erase the cursor for NONE.
1331 if ((LOWORD(lParam) == HTCLIENT) &&
1332 (fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE))
1335 /* Set the cursor AND change it for this window class. */
1336 # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \
1338 /* Nuke the cursor AND change it for this window class. */
1339 # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \
1342 if (LOWORD(lParam) == HTCLIENT)
1343 switch( window->State.Cursor )
1345 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1346 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1347 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1348 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1349 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1350 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1351 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1352 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1353 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1354 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1355 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1356 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1359 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1363 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1368 * We are now Visible!
1370 window->State.Visible = TRUE;
1371 window->State.Redisplay = TRUE;
1376 * Start the painting job
1379 BeginPaint( hWnd, &ps );
1382 * Call the engine's main frame drawing method
1384 fghRedrawWindowByHandle( hWnd );
1387 * End the painting job, release the device context
1389 EndPaint( hWnd, &ps );
1394 * Make sure we don't close a window with current context active
1396 if( fgStructure.Window == window )
1401 wglMakeCurrent( NULL, NULL );
1402 /* Step through the list of windows. If the rendering context is notbeing used
1403 * by another window, then we delete it.
1405 for ( iter = (SFG_Window *)fgStructure.Windows.First; iter; iter = (SFG_Window *)iter->Node.Next )
1407 if ( ( iter->Window.Context == window->Window.Context ) && ( iter != window ) )
1411 if ( used == FALSE ) wglDeleteContext( window->Window.Context );
1415 * Put on a linked list of windows to be removed after all the callbacks have returned
1417 fgAddToWindowDestroyList ( window, FALSE ) ;
1420 * Proceed with the window destruction
1422 DestroyWindow( hWnd );
1427 * The window already got destroyed, so don't bother with it.
1434 * The mouse cursor has moved. Remember the new mouse cursor's position
1436 window->State.MouseX = LOWORD( lParam );
1437 window->State.MouseY = HIWORD( lParam );
1440 * Fallback if there's an active menu hooked to this window
1442 if ( window->ActiveMenu != NULL )
1445 * Let's make the window redraw as a result of the mouse motion.
1447 window->State.Redisplay = TRUE ;
1450 * Since the window is a menu, make the parent window current
1452 fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
1458 * Remember the current modifiers state.
1460 window->State.Modifiers =
1461 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1462 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1463 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1466 * Check if any of the mouse buttons is pressed...
1468 if( (wParam & MK_LBUTTON) || (wParam & MK_MBUTTON) || (wParam & MK_RBUTTON) )
1471 * Yeah, indeed. We need to use the motion callback then:
1473 if( window->Callbacks.Motion != NULL )
1476 * Make sure the current window is set...
1478 fgSetWindow( window );
1481 * Execute the active mouse motion callback now
1483 window->Callbacks.Motion( window->State.MouseX, window->State.MouseY );
1489 * All mouse buttons are up, execute the passive mouse motion callback
1491 if( window->Callbacks.Passive != NULL )
1494 * Make sure the current window is set
1496 fgSetWindow( window );
1499 * Execute the passive mouse motion callback
1501 window->Callbacks.Passive( window->State.MouseX, window->State.MouseY );
1506 * Thrash the current modifiers state now
1508 window->State.Modifiers = 0xffffffff;
1512 case WM_LBUTTONDOWN:
1513 case WM_MBUTTONDOWN:
1514 case WM_RBUTTONDOWN:
1519 GLboolean pressed = TRUE;
1523 * The mouse cursor has moved. Remember the new mouse cursor's position
1525 window->State.MouseX = LOWORD( lParam );
1526 window->State.MouseY = HIWORD( lParam );
1529 * We're curious about the GLUT API button name...
1533 case WM_LBUTTONDOWN: pressed = TRUE; button = GLUT_LEFT_BUTTON; break;
1534 case WM_MBUTTONDOWN: pressed = TRUE; button = GLUT_MIDDLE_BUTTON; break;
1535 case WM_RBUTTONDOWN: pressed = TRUE; button = GLUT_RIGHT_BUTTON; break;
1536 case WM_LBUTTONUP: pressed = FALSE; button = GLUT_LEFT_BUTTON; break;
1537 case WM_MBUTTONUP: pressed = FALSE; button = GLUT_MIDDLE_BUTTON; break;
1538 case WM_RBUTTONUP: pressed = FALSE; button = GLUT_RIGHT_BUTTON; break;
1539 default: pressed = FALSE; button = -1; break;
1543 * The left and right mouse buttons might have been swapped...
1545 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1546 if( button == GLUT_LEFT_BUTTON ) button = GLUT_RIGHT_BUTTON;
1547 else if( button == GLUT_RIGHT_BUTTON ) button = GLUT_LEFT_BUTTON;
1550 * Hey, what's up with you?
1553 return( DefWindowProc( hWnd, uMsg, lParam, wParam ) );
1556 * Do not execute the application's mouse callback if a menu is hooked to this button.
1557 * In that case an appropriate private call should be generated.
1558 * Near as I can tell, this is the menu behaviour:
1559 * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
1560 * - Down-click any button outside the menu, menu active: deactivate the menu
1561 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
1562 * - Up-click the menu button, menu not active: nothing happens
1563 * - Up-click the menu button outside the menu, menu active: nothing happens
1564 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
1566 if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
1568 if ( fgCheckActiveMenu ( window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
1570 /* Save the current window and menu and set the current window to the window whose menu this is */
1571 SFG_Window *save_window = fgStructure.Window ;
1572 SFG_Menu *save_menu = fgStructure.Menu ;
1573 fgSetWindow ( window ) ;
1574 fgStructure.Menu = window->ActiveMenu ;
1576 /* Execute the menu callback */
1577 fgExecuteMenuCallback ( window->ActiveMenu ) ;
1578 fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
1580 /* Restore the current window and menu */
1581 fgSetWindow ( save_window ) ;
1582 fgStructure.Menu = save_menu ;
1584 else /* Outside the menu, deactivate the menu if it's a downclick */
1586 if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
1590 * Let's make the window redraw as a result of the mouse click and menu activity.
1592 if ( ! window->IsMenu ) window->State.Redisplay = TRUE ;
1598 * No active menu, let's check whether we need to activate one.
1600 if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
1603 * Let's make the window redraw as a result of the mouse click.
1605 window->State.Redisplay = TRUE ;
1608 * Set the current window
1610 fgSetWindow( window );
1613 * Activate the appropriate menu structure...
1615 fgActivateMenu( window, button );
1621 * Check if there is a mouse callback hooked to the window
1623 if( window->Callbacks.Mouse == NULL )
1627 * Set the current window
1629 fgSetWindow ( window );
1632 * Remember the current modifiers state.
1634 fgStructure.Window->State.Modifiers =
1635 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1636 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1637 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1640 * Finally execute the mouse callback
1642 window->Callbacks.Mouse(
1644 pressed == TRUE ? GLUT_DOWN : GLUT_UP,
1645 window->State.MouseX,
1646 window->State.MouseY
1650 * Trash the modifiers state
1652 fgStructure.Window->State.Modifiers = 0xffffffff;
1663 * Ignore the automatic key repetition if needed:
1665 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1669 * Remember the current modifiers state. This is done here in order
1670 * to make sure the VK_DELETE keyboard callback is executed properly.
1672 window->State.Modifiers =
1673 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1674 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1675 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1678 * Set the mouse position
1680 GetCursorPos ( &mouse_pos ) ;
1681 ScreenToClient ( window->Window.Handle, &mouse_pos ) ;
1683 window->State.MouseX = mouse_pos.x ;
1684 window->State.MouseY = mouse_pos.y ;
1687 * Convert the Win32 keystroke codes to GLUTtish way
1689 # define KEY(a,b) case a: keypress = b; break;
1694 * Most of the special characters can be handled automagically...
1696 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1697 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1698 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1699 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1700 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1701 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1702 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1703 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1704 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1705 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1706 KEY( VK_INSERT, GLUT_KEY_INSERT );
1709 * ...yet there is a small exception we need to have handled...
1713 * The delete key should be treated as an ASCII keypress:
1715 if( window->Callbacks.Keyboard != NULL )
1717 fgSetWindow( window );
1718 window->Callbacks.Keyboard( 127, window->State.MouseX, window->State.MouseY );
1723 * Execute the special callback, if present, given the conversion was a success:
1725 if( (keypress != -1) && (window->Callbacks.Special != NULL) )
1728 * Set the current window
1730 fgSetWindow( window );
1733 * Have the special callback executed:
1735 window->Callbacks.Special( keypress, window->State.MouseX, window->State.MouseY );
1739 * Thrash the modifiers register now
1741 window->State.Modifiers = 0xffffffff;
1752 * Remember the current modifiers state. This is done here in order
1753 * to make sure the VK_DELETE keyboard callback is executed properly.
1755 window->State.Modifiers =
1756 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1757 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1758 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1761 * Set the mouse position
1763 GetCursorPos ( &mouse_pos ) ;
1764 ScreenToClient ( window->Window.Handle, &mouse_pos ) ;
1766 window->State.MouseX = mouse_pos.x ;
1767 window->State.MouseY = mouse_pos.y ;
1770 * Convert the Win32 keystroke codes to GLUTtish way. "KEY(a,b)" was defined under "WM_KEYDOWN"
1776 * Most of the special characters can be handled automagically...
1778 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1779 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1780 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1781 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1782 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1783 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1784 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1785 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1786 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1787 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1788 KEY( VK_INSERT, GLUT_KEY_INSERT );
1791 * ...yet there is a small exception we need to have handled...
1795 * The delete key should be treated as an ASCII keypress:
1797 if( window->Callbacks.KeyboardUp != NULL )
1799 fgSetWindow ( window ) ;
1800 window->Callbacks.KeyboardUp( 127, window->State.MouseX, window->State.MouseY );
1807 * Call the KeyboardUp callback for a regular character if there is one.
1812 GetKeyboardState(state);
1814 if ( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1817 if( window->Callbacks.KeyboardUp != NULL )
1820 * Set the current window
1822 fgSetWindow( window );
1824 window->Callbacks.KeyboardUp( (char)wParam, window->State.MouseX, window->State.MouseY );
1830 * Execute the special callback, if present, given the conversion was a success:
1832 if( (keypress != -1) && (window->Callbacks.SpecialUp != NULL) )
1835 * Set the current window
1837 fgSetWindow( window );
1840 * Have the special callback executed:
1842 window->Callbacks.SpecialUp( keypress, window->State.MouseX, window->State.MouseY );
1846 * Thrash the modifiers register now
1848 window->State.Modifiers = 0xffffffff;
1856 * Ignore the automatic key repetition if needed:
1858 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1862 * Clear to go with the keyboard callback, if registered:
1864 if( window->Callbacks.Keyboard != NULL )
1867 * Set the current window
1869 fgSetWindow( window );
1872 * Remember the current modifiers state
1874 window->State.Modifiers =
1875 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1876 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1877 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1880 * Have the special callback executed:
1882 window->Callbacks.Keyboard( (char)wParam, window->State.MouseX, window->State.MouseY );
1885 * Thrash the modifiers register now
1887 window->State.Modifiers = 0xffffffff;
1892 case WM_CAPTURECHANGED : /* User has finished resizing the window, force a redraw */
1893 if ( window->Callbacks.Display )
1896 * Set the current window
1898 fgSetWindow( window );
1900 window->Callbacks.Display () ;
1903 /* lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */
1907 * Other messages that I have seen and which are not handled already
1909 case WM_SETTEXT : /* 0x000c */
1910 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Pass it on to "DefWindowProc" to set the window text */
1913 case WM_GETTEXT : /* 0x000d */
1914 /* Ideally we would copy the title of the window into "lParam" */
1915 /* strncpy ( (char *)lParam, "Window Title", wParam ) ;
1916 lRet = ( wParam > 12 ) ? 12 : wParam ; */ /* the number of characters copied */
1917 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1920 case WM_GETTEXTLENGTH : /* 0x000e */
1921 /* Ideally we would get the length of the title of the window */
1922 lRet = 12 ; /* the number of characters in "Window Title\0" (see above) */
1925 case WM_ERASEBKGND : /* 0x0014 */
1926 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1929 case WM_SYNCPAINT : /* 0x0088 */
1930 /* Another window has moved, need to update this one */
1931 window->State.Redisplay = TRUE ;
1932 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Help screen says this message must be passed to "DefWindowProc" */
1935 case WM_NCPAINT : /* 0x0085 */
1936 /* Need to update the border of this window */
1937 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Pass it on to "DefWindowProc" to repaint a standard border */
1942 * Handle unhandled messages
1944 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1952 /*** END OF FILE ***/