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 #include "../include/GL/freeglut.h"
33 #include "freeglut_internal.h"
36 #if TARGET_HOST_UNIX_X11
37 #include <sys/types.h>
42 #elif TARGET_HOST_WIN32
46 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
50 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
55 * TODO BEFORE THE STABLE RELEASE:
57 * There are some issues concerning window redrawing under X11, and maybe
58 * some events are not handled. The Win32 version lacks some more features,
59 * but seems acceptable for not demanding purposes.
61 * Need to investigate why the X11 version breaks out with an error when
62 * closing a window (using the window manager, not glutDestroyWindow)...
65 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
68 * Handle a window configuration change. When no reshape
69 * callback is hooked, the viewport size is updated to
70 * match the new window size.
72 static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
73 int width, int height )
75 SFG_Window *current_window = fgStructure.Window;
77 SFG_Window* window = fgWindowByHandle( handle );
78 freeglut_return_if_fail( window != NULL );
81 #if TARGET_HOST_UNIX_X11
83 XResizeWindow( fgDisplay.Display, window->Window.Handle,
85 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
87 #elif TARGET_HOST_WIN32
93 * For windowed mode, get the current position of the
94 * window and resize taking the size of the frame
95 * decorations into account.
98 GetWindowRect( window->Window.Handle, &rect );
99 rect.right = rect.left + width;
100 rect.bottom = rect.top + height;
102 if ( window->Parent == NULL )
104 if ( ! window->IsMenu && !window->State.IsGameMode )
106 rect.right += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
107 rect.bottom += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
108 GetSystemMetrics( SM_CYCAPTION );
113 GetWindowRect( window->Parent->Window.Handle, &rect );
114 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
115 WS_CLIPCHILDREN, FALSE );
119 * SWP_NOACTIVATE Do not activate the window
120 * SWP_NOOWNERZORDER Do not change position in z-order
121 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
122 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
125 SetWindowPos( window->Window.Handle,
129 rect.right - rect.left,
130 rect.bottom - rect.top,
131 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
137 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
138 * XXX to keep in lockstep with UNIX_X11 code.
140 if( FETCH_WCB( *window, Reshape ) )
141 INVOKE_WCB( *window, Reshape, ( width, height ) );
144 fgSetWindow( window );
145 glViewport( 0, 0, width, height );
151 * Force a window redraw. In Windows at least this is only a partial
152 * solution: if the window is increasing in size in either dimension,
153 * the already-drawn part does not get drawn again and things look funny.
154 * But without this we get this bad behaviour whenever we resize the
157 window->State.Redisplay = GL_TRUE;
160 fgSetWindow( current_window );
164 * Calls a window's redraw method. This is used when
165 * a redraw is forced by the incoming window messages.
167 static void fghRedrawWindowByHandle ( SFG_WindowHandleType handle )
169 SFG_Window* window = fgWindowByHandle( handle );
170 freeglut_return_if_fail( window );
171 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
173 window->State.Redisplay = GL_FALSE;
175 freeglut_return_if_fail( window->State.Visible );
177 if( window->State.NeedToResize )
179 SFG_Window *current_window = fgStructure.Window;
181 fgSetWindow( window );
183 fghReshapeWindowByHandle(
184 window->Window.Handle,
189 window->State.NeedToResize = GL_FALSE;
190 fgSetWindow ( current_window );
193 INVOKE_WCB( *window, Display, ( ) );
197 * A static helper function to execute display callback for a window
199 static void fghcbDisplayWindow( SFG_Window *window,
200 SFG_Enumerator *enumerator )
202 if( window->State.NeedToResize )
204 SFG_Window *current_window = fgStructure.Window;
206 fgSetWindow( window );
208 fghReshapeWindowByHandle(
209 window->Window.Handle,
214 window->State.NeedToResize = GL_FALSE;
215 fgSetWindow( current_window );
218 if( window->State.Redisplay &&
219 window->State.Visible )
221 window->State.Redisplay = GL_FALSE;
223 #if TARGET_HOST_UNIX_X11
225 SFG_Window *current_window = fgStructure.Window;
227 INVOKE_WCB( *window, Display, ( ) );
228 fgSetWindow( current_window );
230 #elif TARGET_HOST_WIN32
232 window->Window.Handle, NULL, NULL,
233 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
238 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
242 * Make all windows perform a display call
244 static void fghDisplayAll( void )
246 SFG_Enumerator enumerator;
248 enumerator.found = GL_FALSE;
249 enumerator.data = NULL;
251 fgEnumWindows( fghcbDisplayWindow, &enumerator );
255 * Window enumerator callback to check for the joystick polling code
257 static void fghcbCheckJoystickPolls( SFG_Window *window,
258 SFG_Enumerator *enumerator )
260 long int checkTime = fgElapsedTime( );
262 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
265 fgJoystickPollWindow( window );
266 window->State.JoystickLastPoll = checkTime;
269 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
273 * Check all windows for joystick polling
275 static void fghCheckJoystickPolls( void )
277 SFG_Enumerator enumerator;
279 enumerator.found = GL_FALSE;
280 enumerator.data = NULL;
282 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
286 * Check the global timers
288 static void fghCheckTimers( void )
290 long checkTime = fgElapsedTime( );
292 while( fgState.Timers.First )
294 SFG_Timer *timer = fgState.Timers.First;
296 if( timer->TriggerTime > checkTime )
299 fgListRemove( &fgState.Timers, &timer->Node );
300 fgListAppend( &fgState.FreeTimers, &timer->Node );
302 timer->Callback( timer->ID );
309 long fgElapsedTime( void )
311 if ( fgState.Time.Set )
313 #if TARGET_HOST_UNIX_X11
317 gettimeofday( &now, NULL );
319 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
320 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
323 #elif TARGET_HOST_WIN32
324 return timeGetTime() - fgState.Time.Value;
329 #if TARGET_HOST_UNIX_X11
330 gettimeofday( &fgState.Time.Value, NULL );
331 #elif TARGET_HOST_WIN32
332 fgState.Time.Value = timeGetTime ();
334 fgState.Time.Set = GL_TRUE ;
343 void fgError( const char *fmt, ... )
349 fprintf( stderr, "freeglut ");
350 if( fgState.ProgramName )
351 fprintf (stderr, "(%s): ", fgState.ProgramName);
352 vfprintf( stderr, fmt, ap );
353 fprintf( stderr, "\n" );
357 if ( fgState.Initialised )
363 void fgWarning( const char *fmt, ... )
369 fprintf( stderr, "freeglut ");
370 if( fgState.ProgramName )
371 fprintf( stderr, "(%s): ", fgState.ProgramName );
372 vfprintf( stderr, fmt, ap );
373 fprintf( stderr, "\n" );
379 * Indicates whether Joystick events are being used by ANY window.
381 * The current mechanism is to walk all of the windows and ask if
382 * there is a joystick callback. Certainly in some cases, maybe
383 * in all cases, the joystick is attached to the system and accessed
384 * from ONE point by GLUT/freeglut, so this is not the right way,
385 * in general, to do this. However, the Joystick code is segregated
386 * in its own little world, so we can't access the information that
387 * we need in order to do that nicely.
390 * * Store Joystick data into freeglut global state.
391 * * Provide NON-static functions or data from Joystick *.c file.
393 * Basically, the RIGHT way to do this requires knowing something
394 * about the Joystick. Right now, the Joystick code is behind
398 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
400 if( FETCH_WCB( *w, Joystick ) )
405 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
407 static int fgHaveJoystick( void )
409 SFG_Enumerator enumerator;
410 enumerator.found = GL_FALSE;
411 enumerator.data = NULL;
412 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
413 return !!enumerator.data;
415 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
417 if( w->State.Redisplay )
422 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
424 static int fgHavePendingRedisplays (void)
426 SFG_Enumerator enumerator;
427 enumerator.found = GL_FALSE;
428 enumerator.data = NULL;
429 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
430 return !!enumerator.data;
433 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
435 static long fgNextTimer( void )
438 SFG_Timer *timer = fgState.Timers.First;
441 ret = timer->TriggerTime - fgElapsedTime();
448 * Does the magic required to relinquish the CPU until something interesting
451 static void fgSleepForEvents( void )
455 if( fgState.IdleCallback || fgHavePendingRedisplays( ) )
458 msec = fgNextTimer( );
459 if( fgHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
460 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
462 #if TARGET_HOST_UNIX_X11
469 socket = ConnectionNumber( fgDisplay.Display );
471 FD_SET( socket, &fdset );
472 wait.tv_sec = msec / 1000;
473 wait.tv_usec = (msec % 1000) * 1000;
474 err = select( socket+1, &fdset, NULL, NULL, &wait );
477 fgWarning ( "freeglut select() error: %d\n", errno );
479 #elif TARGET_HOST_WIN32
480 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
484 #if TARGET_HOST_UNIX_X11
486 * Returns GLUT modifier mask for an XEvent.
488 int fgGetXModifiers( XEvent *event )
492 if( event->xkey.state & ( ShiftMask | LockMask ) )
493 ret |= GLUT_ACTIVE_SHIFT;
494 if( event->xkey.state & ControlMask )
495 ret |= GLUT_ACTIVE_CTRL;
496 if( event->xkey.state & Mod1Mask )
497 ret |= GLUT_ACTIVE_ALT;
504 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
507 * Executes a single iteration in the freeglut processing loop.
509 void FGAPIENTRY glutMainLoopEvent( void )
511 #if TARGET_HOST_UNIX_X11
516 * This code was repeated constantly, so here it goes into a definition:
518 #define GETWINDOW(a) \
519 window = fgWindowByHandle( event.a.window ); \
520 if( window == NULL ) \
523 #define GETMOUSE(a) \
524 window->State.MouseX = event.a.x; \
525 window->State.MouseY = event.a.y;
527 freeglut_assert_ready;
529 while( XPending( fgDisplay.Display ) )
531 XNextEvent( fgDisplay.Display, &event );
537 * Destroy the window when the WM_DELETE_WINDOW message arrives
539 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
541 GETWINDOW( xclient );
543 fgDestroyWindow ( window );
545 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
551 fgState.ExecState = GLUT_EXEC_STATE_STOP;
557 * CreateNotify causes a configure-event so that sub-windows are
558 * handled compatibly with GLUT. Otherwise, your sub-windows
559 * (in freeglut only) will not get an initial reshape event,
560 * which can break things.
562 * GLUT presumably does this because it generally tries to treat
563 * sub-windows the same as windows.
565 * XXX Technically, GETWINDOW( xconfigure ) and
566 * XXX {event.xconfigure} may not be legit ways to get at
567 * XXX data for CreateNotify events. In practice, the data
568 * XXX is in a union which is laid out much the same either
569 * XXX way. But if you want to split hairs, this isn't legit,
570 * XXX and we should instead duplicate some code.
573 case ConfigureNotify:
574 GETWINDOW( xconfigure );
576 int width = event.xconfigure.width;
577 int height = event.xconfigure.height;
579 if( ( width != window->State.OldWidth ) ||
580 ( height != window->State.OldHeight ) )
582 window->State.OldWidth = width;
583 window->State.OldHeight = height;
584 if( FETCH_WCB( *window, Reshape ) )
585 INVOKE_WCB( *window, Reshape, ( width, height ) );
588 fgSetWindow( window );
589 glViewport( 0, 0, width, height );
591 glutPostRedisplay( );
598 * This is sent to confirm the XDestroyWindow call.
599 * XXX WHY is this commented out? Should we re-enable it?
601 /* fgAddToWindowDestroyList ( window ); */
606 * We are too dumb to process partial exposes...
608 * XXX Well, we could do it. However, it seems to only
609 * XXX be potentially useful for single-buffered (since
610 * XXX double-buffered does not respect viewport when we
611 * XXX do a buffer-swap).
613 * XXX GETWINDOW( xexpose );
614 * XXX fgSetWindow( window );
615 * XXX glutPostRedisplay( );
617 if( event.xexpose.count == 0 )
618 fghRedrawWindowByHandle( event.xexpose.window );
624 * If we never do anything with this, can we just not ask to
625 * get these messages?
631 * Have the client's keyboard knowledge updated (xlib.ps,
632 * page 206, says that's a good thing to do)
634 XRefreshKeyboardMapping( (XMappingEvent *) &event );
637 case VisibilityNotify:
639 GETWINDOW( xvisibility );
641 * XXX INVOKE_WCB() does this check for us.
643 if( ! FETCH_WCB( *window, WindowStatus ) )
645 fgSetWindow( window );
648 * Sending this event, the X server can notify us that the window
649 * has just acquired one of the three possible visibility states:
650 * VisibilityUnobscured, VisibilityPartiallyObscured or
651 * VisibilityFullyObscured
653 switch( event.xvisibility.state )
655 case VisibilityUnobscured:
656 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
657 window->State.Visible = GL_TRUE;
660 case VisibilityPartiallyObscured:
661 INVOKE_WCB( *window, WindowStatus,
662 ( GLUT_PARTIALLY_RETAINED ) );
663 window->State.Visible = GL_TRUE;
666 case VisibilityFullyObscured:
667 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
668 window->State.Visible = GL_FALSE;
672 fgWarning( "Uknown X visibility state: %d",
673 event.xvisibility.state );
681 GETWINDOW( xcrossing );
682 GETMOUSE( xcrossing );
683 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
690 GETWINDOW( xmotion );
693 if( window->ActiveMenu )
695 if( window == window->ActiveMenu->ParentWindow )
697 window->ActiveMenu->Window->State.MouseX =
698 event.xmotion.x_root - window->ActiveMenu->X;
699 window->ActiveMenu->Window->State.MouseY =
700 event.xmotion.y_root - window->ActiveMenu->Y;
702 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
703 fgSetWindow( window->ActiveMenu->ParentWindow );
709 * XXX For more than 5 buttons, just check {event.xmotion.state},
710 * XXX rather than a host of bit-masks? Or maybe we need to
711 * XXX track ButtonPress/ButtonRelease events in our own
714 #define BUTTON_MASK \
715 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
716 if ( event.xmotion.state & BUTTON_MASK )
717 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
720 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
728 GLboolean pressed = GL_TRUE;
731 if( event.type == ButtonRelease )
735 * A mouse button has been pressed or released. Traditionally,
736 * break if the window was found within the freeglut structures.
738 GETWINDOW( xbutton );
742 * An X button (at least in XFree86) is numbered from 1.
743 * A GLUT button is numbered from 0.
744 * Old GLUT passed through buttons other than just the first
745 * three, though it only gave symbolic names and official
746 * support to the first three.
748 button = event.xbutton.button - 1;
751 * XXX This comment is replicated in the WIN32 section and
752 * XXX maybe also in the menu code. Can we move the info
753 * XXX to one central place and *reference* it from here?
755 * Do not execute the application's mouse callback if a menu
756 * is hooked to this button. In that case an appropriate
757 * private call should be generated.
758 * Near as I can tell, this is the menu behaviour:
759 * - Down-click the menu button, menu not active: activate
760 * the menu with its upper left-hand corner at the mouse
762 * - Down-click any button outside the menu, menu active:
763 * deactivate the menu
764 * - Down-click any button inside the menu, menu active:
765 * select the menu entry and deactivate the menu
766 * - Up-click the menu button, menu not active: nothing happens
767 * - Up-click the menu button outside the menu, menu active:
769 * - Up-click the menu button inside the menu, menu active:
770 * select the menu entry and deactivate the menu
772 /* Window has an active menu, it absorbs any mouse click */
773 if( window->ActiveMenu )
775 if( window == window->ActiveMenu->ParentWindow )
777 window->ActiveMenu->Window->State.MouseX =
778 event.xbutton.x_root - window->ActiveMenu->X;
779 window->ActiveMenu->Window->State.MouseY =
780 event.xbutton.y_root - window->ActiveMenu->Y;
783 /* In the menu, invoke the callback and deactivate the menu*/
784 if( fgCheckActiveMenu( window->ActiveMenu->Window,
785 window->ActiveMenu ) )
788 * Save the current window and menu and set the current
789 * window to the window whose menu this is
791 SFG_Window *save_window = fgStructure.Window;
792 SFG_Menu *save_menu = fgStructure.Menu;
793 SFG_Window *parent_window =
794 window->ActiveMenu->ParentWindow;
795 fgSetWindow( parent_window );
796 fgStructure.Menu = window->ActiveMenu;
798 /* Execute the menu callback */
799 fgExecuteMenuCallback( window->ActiveMenu );
800 fgDeactivateMenu( parent_window );
802 /* Restore the current window and menu */
803 fgSetWindow( save_window );
804 fgStructure.Menu = save_menu;
808 * Outside the menu, deactivate if it's a downclick
810 * XXX This isn't enough. A downclick outside of
811 * XXX the interior of our freeglut windows should also
812 * XXX deactivate the menu. This is more complicated.
814 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
817 * XXX Why does an active menu require a redisplay at
818 * XXX this point? If this can come out cleanly, then
819 * XXX it probably should do so; if not, a comment should
822 window->State.Redisplay = GL_TRUE;
827 * No active menu, let's check whether we need to activate one.
829 if( ( 0 <= button ) &&
830 ( FREEGLUT_MAX_MENUS > button ) &&
831 ( window->Menu[ button ] ) &&
835 * XXX Posting a requisite Redisplay seems bogus.
837 window->State.Redisplay = GL_TRUE;
838 fgSetWindow( window );
839 fgActivateMenu( window, button );
844 * Check if there is a mouse or mouse wheel callback hooked to the
847 if( ! FETCH_WCB( *window, Mouse ) &&
848 ! FETCH_WCB( *window, MouseWheel ) )
851 fgState.Modifiers = fgGetXModifiers( &event );
854 * Finally execute the mouse or mouse wheel callback
856 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
858 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
859 INVOKE_WCB( *window, Mouse, ( button,
860 pressed ? GLUT_DOWN : GLUT_UP,
867 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
868 * " 6 and 7 " " one; ...
870 * XXX This *should* be behind some variables/macros,
871 * XXX since the order and numbering isn't certain
872 * XXX See XFree86 configuration docs (even back in the
873 * XXX 3.x days, and especially with 4.x).
875 * XXX Note that {button} has already been decremeted
876 * XXX in mapping from X button numbering to GLUT.
878 int wheel_number = (button - 3) / 2;
884 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
892 * Trash the modifiers state
894 fgState.Modifiers = 0xffffffff;
901 FGCBKeyboard keyboard_cb;
902 FGCBSpecial special_cb;
907 if( event.type == KeyPress )
909 keyboard_cb = FETCH_WCB( *window, Keyboard );
910 special_cb = FETCH_WCB( *window, Special );
914 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
915 special_cb = FETCH_WCB( *window, SpecialUp );
919 * Is there a keyboard/special callback hooked for this window?
921 if( keyboard_cb || special_cb )
923 XComposeStatus composeStatus;
924 char asciiCode[ 32 ];
929 * Check for the ASCII/KeySym codes associated with the event:
931 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
932 &keySym, &composeStatus
936 * GLUT API tells us to have two separate callbacks...
941 * ...one for the ASCII translateable keypresses...
945 fgSetWindow( window );
946 fgState.Modifiers = fgGetXModifiers( &event );
947 keyboard_cb( asciiCode[ 0 ],
948 event.xkey.x, event.xkey.y
950 fgState.Modifiers = 0xffffffff;
958 * ...and one for all the others, which need to be
959 * translated to GLUT_KEY_Xs...
963 case XK_F1: special = GLUT_KEY_F1; break;
964 case XK_F2: special = GLUT_KEY_F2; break;
965 case XK_F3: special = GLUT_KEY_F3; break;
966 case XK_F4: special = GLUT_KEY_F4; break;
967 case XK_F5: special = GLUT_KEY_F5; break;
968 case XK_F6: special = GLUT_KEY_F6; break;
969 case XK_F7: special = GLUT_KEY_F7; break;
970 case XK_F8: special = GLUT_KEY_F8; break;
971 case XK_F9: special = GLUT_KEY_F9; break;
972 case XK_F10: special = GLUT_KEY_F10; break;
973 case XK_F11: special = GLUT_KEY_F11; break;
974 case XK_F12: special = GLUT_KEY_F12; break;
976 case XK_Left: special = GLUT_KEY_LEFT; break;
977 case XK_Right: special = GLUT_KEY_RIGHT; break;
978 case XK_Up: special = GLUT_KEY_UP; break;
979 case XK_Down: special = GLUT_KEY_DOWN; break;
982 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
984 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
986 case XK_Home: special = GLUT_KEY_HOME; break;
988 case XK_End: special = GLUT_KEY_END; break;
990 case XK_Insert: special = GLUT_KEY_INSERT; break;
994 * Execute the callback (if one has been specified),
995 * given that the special code seems to be valid...
997 if( special_cb && (special != -1) )
999 fgSetWindow( window );
1000 fgState.Modifiers = fgGetXModifiers( &event );
1001 special_cb( special, event.xkey.x, event.xkey.y );
1002 fgState.Modifiers = 0xffffffff;
1009 case ReparentNotify:
1010 break; /* XXX Should disable this event */
1013 fgWarning ("Unknown X event type: %d", event.type);
1018 #elif TARGET_HOST_WIN32
1022 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1024 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1026 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1031 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1035 TranslateMessage( &stMsg );
1036 DispatchMessage( &stMsg );
1040 if( fgState.Timers.First )
1042 fghCheckJoystickPolls( );
1049 * Enters the freeglut processing loop.
1050 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1052 void FGAPIENTRY glutMainLoop( void )
1054 #if TARGET_HOST_WIN32
1055 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1058 freeglut_assert_ready;
1060 #if TARGET_HOST_WIN32
1062 * Processing before the main loop: If there is a window which is open and
1063 * which has a visibility callback, call it. I know this is an ugly hack,
1064 * but I'm not sure what else to do about it. Ideally we should leave
1065 * something uninitialized in the create window code and initialize it in
1066 * the main loop, and have that initialization create a "WM_ACTIVATE"
1067 * message. Then we would put the visibility callback code in the
1068 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1072 if ( FETCH_WCB( *window, Visibility ) )
1074 SFG_Window *current_window = fgStructure.Window ;
1076 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1077 fgSetWindow( current_window );
1080 window = (SFG_Window *)window->Node.Next ;
1084 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1085 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1089 glutMainLoopEvent( );
1091 * Step through the list of windows, seeing if there are any
1092 * that are not menus
1094 for( window = ( SFG_Window * )fgStructure.Windows.First;
1096 window = ( SFG_Window * )window->Node.Next )
1097 if ( ! ( window->IsMenu ) )
1101 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1104 if( fgState.IdleCallback )
1105 fgState.IdleCallback( );
1107 fgSleepForEvents( );
1112 * When this loop terminates, destroy the display, state and structure
1113 * of a freeglut session, so that another glutInit() call can happen
1116 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1121 * Leaves the freeglut processing loop.
1123 void FGAPIENTRY glutLeaveMainLoop( void )
1125 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1129 #if TARGET_HOST_WIN32
1131 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1133 int fgGetWin32Modifiers (void)
1136 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1137 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1138 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1139 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1140 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1141 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1145 * The window procedure for handling Win32 events
1147 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1150 SFG_Window* window = fgWindowByHandle( hWnd );
1154 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1155 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1157 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1158 uMsg, wParam, lParam ); */
1163 * The window structure is passed as the creation structure paramter...
1165 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1166 assert( window != NULL );
1168 window->Window.Handle = hWnd;
1169 window->Window.Device = GetDC( hWnd );
1170 if( window->IsMenu )
1172 unsigned int current_DisplayMode = fgState.DisplayMode;
1173 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1174 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1175 fgState.DisplayMode = current_DisplayMode;
1177 if( fgStructure.MenuContext )
1178 wglMakeCurrent( window->Window.Device,
1179 fgStructure.MenuContext->Context
1183 fgStructure.MenuContext =
1184 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1185 fgStructure.MenuContext->Context =
1186 wglCreateContext( window->Window.Device );
1189 /* window->Window.Context = wglGetCurrentContext (); */
1190 window->Window.Context = wglCreateContext( window->Window.Device );
1194 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1196 if( ! fgState.UseCurrentContext )
1197 window->Window.Context =
1198 wglCreateContext( window->Window.Device );
1201 window->Window.Context = wglGetCurrentContext( );
1202 if( ! window->Window.Context )
1203 window->Window.Context =
1204 wglCreateContext( window->Window.Device );
1208 window->State.NeedToResize = GL_TRUE;
1209 window->State.Width = fgState.Size.X;
1210 window->State.Height = fgState.Size.Y;
1212 ReleaseDC( window->Window.Handle, window->Window.Device );
1217 * We got resized... But check if the window has been already added...
1219 window->State.NeedToResize = GL_TRUE;
1220 window->State.Width = LOWORD(lParam);
1221 window->State.Height = HIWORD(lParam);
1225 printf("WM_SETFOCUS: %p\n", window );
1226 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1230 if (LOWORD(wParam) != WA_INACTIVE)
1232 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1233 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1234 window->State.Cursor );
1235 glutSetCursor( window->State.Cursor );
1238 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1243 * XXX Why not re-use some common code with the glutSetCursor()
1244 * XXX function (or perhaps invoke glutSetCursor())?
1245 * XXX That is, why are we duplicating code, here, from
1246 * XXX glutSetCursor()? The WIN32 code should be able to just
1247 * XXX call glutSetCurdsor() instead of defining two macros
1248 * XXX and implementing a nested case in-line.
1251 /* Set the cursor AND change it for this window class. */
1252 #define MAP_CURSOR(a,b) \
1254 SetCursor( LoadCursor( NULL, b ) ); \
1257 /* Nuke the cursor AND change it for this window class. */
1258 #define ZAP_CURSOR(a,b) \
1260 SetCursor( NULL ); \
1263 if( LOWORD( lParam ) == HTCLIENT )
1264 switch( window->State.Cursor )
1266 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1267 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1268 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1269 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1270 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1271 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1272 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1273 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1274 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1275 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1276 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1277 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1280 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1283 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1287 window->State.Visible = GL_TRUE;
1288 window->State.Redisplay = GL_TRUE;
1292 /* Turn on the visibility in case it was turned off somehow */
1293 window->State.Visible = GL_TRUE;
1294 BeginPaint( hWnd, &ps );
1295 fghRedrawWindowByHandle( hWnd );
1296 EndPaint( hWnd, &ps );
1300 fgDestroyWindow ( window );
1301 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1307 * The window already got destroyed, so don't bother with it.
1313 window->State.MouseX = LOWORD( lParam );
1314 window->State.MouseY = HIWORD( lParam );
1316 if ( window->ActiveMenu )
1318 window->State.Redisplay = GL_TRUE;
1319 fgSetWindow ( window->ActiveMenu->ParentWindow );
1323 fgState.Modifiers = fgGetWin32Modifiers( );
1325 if( ( wParam & MK_LBUTTON ) ||
1326 ( wParam & MK_MBUTTON ) ||
1327 ( wParam & MK_RBUTTON ) )
1328 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1329 window->State.MouseY ) );
1331 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1332 window->State.MouseY ) );
1334 fgState.Modifiers = 0xffffffff;
1338 case WM_LBUTTONDOWN:
1339 case WM_MBUTTONDOWN:
1340 case WM_RBUTTONDOWN:
1345 GLboolean pressed = GL_TRUE;
1348 window->State.MouseX = LOWORD( lParam );
1349 window->State.MouseY = HIWORD( lParam );
1353 case WM_LBUTTONDOWN:
1355 button = GLUT_LEFT_BUTTON;
1357 case WM_MBUTTONDOWN:
1359 button = GLUT_MIDDLE_BUTTON;
1361 case WM_RBUTTONDOWN:
1363 button = GLUT_RIGHT_BUTTON;
1367 button = GLUT_LEFT_BUTTON;
1371 button = GLUT_MIDDLE_BUTTON;
1375 button = GLUT_RIGHT_BUTTON;
1383 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1385 if( button == GLUT_LEFT_BUTTON )
1386 button = GLUT_RIGHT_BUTTON;
1388 if( button == GLUT_RIGHT_BUTTON )
1389 button = GLUT_LEFT_BUTTON;
1393 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1396 * XXX This comment is duplicated in two other spots.
1397 * XXX Can we centralize it?
1399 * Do not execute the application's mouse callback if a
1400 * menu is hooked to this button.
1401 * In that case an appropriate private call should be generated.
1402 * Near as I can tell, this is the menu behaviour:
1403 * - Down-click the menu button, menu not active: activate
1404 * the menu with its upper left-hand corner at the mouse location.
1405 * - Down-click any button outside the menu, menu active:
1406 * deactivate the menu
1407 * - Down-click any button inside the menu, menu active:
1408 * select the menu entry and deactivate the menu
1409 * - Up-click the menu button, menu not active: nothing happens
1410 * - Up-click the menu button outside the menu, menu active:
1412 * - Up-click the menu button inside the menu, menu active:
1413 * select the menu entry and deactivate the menu
1415 /* Window has an active menu, it absorbs any mouse click */
1416 if( window->ActiveMenu )
1418 /* Outside the menu, deactivate the menu if it's a downclick */
1419 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1422 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1424 else /* In menu, invoke the callback and deactivate the menu*/
1427 * Save the current window and menu and set the current
1428 * window to the window whose menu this is
1430 SFG_Window *save_window = fgStructure.Window;
1431 SFG_Menu *save_menu = fgStructure.Menu;
1432 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1433 fgSetWindow( parent_window );
1434 fgStructure.Menu = window->ActiveMenu;
1436 /* Execute the menu callback */
1437 fgExecuteMenuCallback( window->ActiveMenu );
1438 fgDeactivateMenu( parent_window );
1440 /* Restore the current window and menu */
1441 fgSetWindow( save_window );
1442 fgStructure.Menu = save_menu;
1446 * Let's make the window redraw as a result of the mouse
1447 * click and menu activity.
1449 if( ! window->IsMenu )
1450 window->State.Redisplay = GL_TRUE;
1455 if( window->Menu[ button ] && pressed )
1457 window->State.Redisplay = GL_TRUE;
1458 fgSetWindow( window );
1459 fgActivateMenu( window, button );
1464 if( ! FETCH_WCB( *window, Mouse ) )
1467 fgSetWindow( window );
1468 fgState.Modifiers = fgGetWin32Modifiers( );
1473 pressed ? GLUT_DOWN : GLUT_UP,
1474 window->State.MouseX,
1475 window->State.MouseY
1479 fgState.Modifiers = 0xffffffff;
1484 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1487 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1488 * XXX Should use WHEEL_DELTA instead of 120
1490 int wheel_number = LOWORD( wParam );
1491 short ticks = ( short )HIWORD( wParam ) / 120;
1501 * The mouse cursor has moved. Remember the new mouse cursor's position
1503 /* window->State.MouseX = LOWORD( lParam ); */
1504 /* Need to adjust by window position, */
1505 /* window->State.MouseY = HIWORD( lParam ); */
1506 /* change "lParam" to other parameter */
1508 if( ! FETCH_WCB( *window, MouseWheel ) &&
1509 ! FETCH_WCB( *window, Mouse ) )
1512 fgSetWindow( window );
1513 fgState.Modifiers = fgGetWin32Modifiers( );
1516 if( FETCH_WCB( *window, MouseWheel ) )
1517 INVOKE_WCB( *window, MouseWheel,
1520 window->State.MouseX,
1521 window->State.MouseY
1524 else /* No mouse wheel, call the mouse button callback twice */
1527 * XXX The below assumes that you have no more than 3 mouse
1528 * XXX buttons. Sorry.
1530 int button = wheel_number*2 + 4;
1533 INVOKE_WCB( *window, Mouse,
1534 ( button, GLUT_DOWN,
1535 window->State.MouseX, window->State.MouseY )
1537 INVOKE_WCB( *window, Mouse,
1539 window->State.MouseX, window->State.MouseX )
1543 fgState.Modifiers = 0xffffffff;
1553 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1557 * Remember the current modifiers state. This is done here in order
1558 * to make sure the VK_DELETE keyboard callback is executed properly.
1560 fgState.Modifiers = fgGetWin32Modifiers( );
1562 GetCursorPos( &mouse_pos );
1563 ScreenToClient( window->Window.Handle, &mouse_pos );
1565 window->State.MouseX = mouse_pos.x;
1566 window->State.MouseY = mouse_pos.y;
1569 * Convert the Win32 keystroke codes to GLUTtish way
1571 # define KEY(a,b) case a: keypress = b; break;
1575 KEY( VK_F1, GLUT_KEY_F1 );
1576 KEY( VK_F2, GLUT_KEY_F2 );
1577 KEY( VK_F3, GLUT_KEY_F3 );
1578 KEY( VK_F4, GLUT_KEY_F4 );
1579 KEY( VK_F5, GLUT_KEY_F5 );
1580 KEY( VK_F6, GLUT_KEY_F6 );
1581 KEY( VK_F7, GLUT_KEY_F7 );
1582 KEY( VK_F8, GLUT_KEY_F8 );
1583 KEY( VK_F9, GLUT_KEY_F9 );
1584 KEY( VK_F10, GLUT_KEY_F10 );
1585 KEY( VK_F11, GLUT_KEY_F11 );
1586 KEY( VK_F12, GLUT_KEY_F12 );
1587 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1588 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1589 KEY( VK_HOME, GLUT_KEY_HOME );
1590 KEY( VK_END, GLUT_KEY_END );
1591 KEY( VK_LEFT, GLUT_KEY_LEFT );
1592 KEY( VK_UP, GLUT_KEY_UP );
1593 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1594 KEY( VK_DOWN, GLUT_KEY_DOWN );
1595 KEY( VK_INSERT, GLUT_KEY_INSERT );
1599 * The delete key should be treated as an ASCII keypress:
1601 INVOKE_WCB( *window, Keyboard,
1602 ( 127, window->State.MouseX, window->State.MouseY )
1606 if( keypress != -1 )
1607 INVOKE_WCB( *window, Special,
1609 window->State.MouseX, window->State.MouseY )
1612 fgState.Modifiers = 0xffffffff;
1623 * Remember the current modifiers state. This is done here in order
1624 * to make sure the VK_DELETE keyboard callback is executed properly.
1626 fgState.Modifiers = fgGetWin32Modifiers( );
1628 GetCursorPos( &mouse_pos );
1629 ScreenToClient( window->Window.Handle, &mouse_pos );
1631 window->State.MouseX = mouse_pos.x;
1632 window->State.MouseY = mouse_pos.y;
1635 * Convert the Win32 keystroke codes to GLUTtish way.
1636 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1641 KEY( VK_F1, GLUT_KEY_F1 );
1642 KEY( VK_F2, GLUT_KEY_F2 );
1643 KEY( VK_F3, GLUT_KEY_F3 );
1644 KEY( VK_F4, GLUT_KEY_F4 );
1645 KEY( VK_F5, GLUT_KEY_F5 );
1646 KEY( VK_F6, GLUT_KEY_F6 );
1647 KEY( VK_F7, GLUT_KEY_F7 );
1648 KEY( VK_F8, GLUT_KEY_F8 );
1649 KEY( VK_F9, GLUT_KEY_F9 );
1650 KEY( VK_F10, GLUT_KEY_F10 );
1651 KEY( VK_F11, GLUT_KEY_F11 );
1652 KEY( VK_F12, GLUT_KEY_F12 );
1653 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1654 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1655 KEY( VK_HOME, GLUT_KEY_HOME );
1656 KEY( VK_END, GLUT_KEY_END );
1657 KEY( VK_LEFT, GLUT_KEY_LEFT );
1658 KEY( VK_UP, GLUT_KEY_UP );
1659 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1660 KEY( VK_DOWN, GLUT_KEY_DOWN );
1661 KEY( VK_INSERT, GLUT_KEY_INSERT );
1665 * The delete key should be treated as an ASCII keypress:
1667 INVOKE_WCB( *window, KeyboardUp,
1668 ( 127, window->State.MouseX, window->State.MouseY )
1677 GetKeyboardState( state );
1679 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1682 INVOKE_WCB( *window, KeyboardUp,
1684 window->State.MouseX, window->State.MouseY )
1689 if( keypress != -1 )
1690 INVOKE_WCB( *window, SpecialUp,
1692 window->State.MouseX, window->State.MouseY )
1695 fgState.Modifiers = 0xffffffff;
1702 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1705 fgState.Modifiers = fgGetWin32Modifiers( );
1706 INVOKE_WCB( *window, Keyboard,
1708 window->State.MouseX, window->State.MouseY )
1710 fgState.Modifiers = 0xffffffff;
1714 case WM_CAPTURECHANGED:
1715 /* User has finished resizing the window, force a redraw */
1716 INVOKE_WCB( *window, Display, ( ) );
1718 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1722 * Other messages that I have seen and which are not handled already
1724 case WM_SETTEXT: /* 0x000c */
1725 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1726 /* Pass it on to "DefWindowProc" to set the window text */
1729 case WM_GETTEXT: /* 0x000d */
1730 /* Ideally we would copy the title of the window into "lParam" */
1731 /* strncpy ( (char *)lParam, "Window Title", wParam );
1732 lRet = ( wParam > 12 ) ? 12 : wParam; */
1733 /* the number of characters copied */
1734 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1737 case WM_GETTEXTLENGTH: /* 0x000e */
1738 /* Ideally we would get the length of the title of the window */
1740 /* the number of characters in "Window Title\0" (see above) */
1743 case WM_ERASEBKGND: /* 0x0014 */
1744 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1747 case WM_SYNCPAINT: /* 0x0088 */
1748 /* Another window has moved, need to update this one */
1749 window->State.Redisplay = GL_TRUE;
1750 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1751 /* Help screen says this message must be passed to "DefWindowProc" */
1754 case WM_NCPAINT: /* 0x0085 */
1755 /* Need to update the border of this window */
1756 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1757 /* Pass it on to "DefWindowProc" to repaint a standard border */
1760 case WM_SYSCOMMAND : /* 0x0112 */
1763 * We have received a system command message. Try to act on it.
1764 * The commands are passed in through the "lParam" parameter:
1765 * Clicking on a corner to resize the window gives a "F004" message
1766 * but this is not defined in my header file.
1777 /* User has clicked on the "-" to minimize the window */
1778 /* Turn off the visibility */
1779 window->State.Visible = GL_FALSE ;
1786 case SC_NEXTWINDOW :
1789 case SC_PREVWINDOW :
1793 /* Followed very closely by a WM_CLOSE message */
1817 case SC_SCREENSAVE :
1825 /* We need to pass the message on to the operating system as well */
1826 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1831 * Handle unhandled messages
1833 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1841 /*** END OF FILE ***/