X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=src%2Ffreeglut_main.c;h=c6d9c73bf273b15e45ab54950afef936ad451b89;hb=9aef0d00666699035d13b4889b9b2ddcbafb9bba;hp=d2f4d458004a700ab562694e85e7723997f0613d;hpb=4634982c39857ee13ad0c5fa67b3ad197a37daf1;p=freeglut diff --git a/src/freeglut_main.c b/src/freeglut_main.c index d2f4d45..c6d9c73 100644 --- a/src/freeglut_main.c +++ b/src/freeglut_main.c @@ -29,12 +29,16 @@ #include "freeglut_internal.h" #include #include -#if HAVE_VPRINTF +#if TARGET_HOST_WIN32 # define VFPRINTF(s,f,a) vfprintf((s),(f),(a)) -#elif HAVE_DOPRNT -# define VFPRINTF(s,f,a) _doprnt((f),(a),(s)) #else -# define VFPRINTF(s,f,a) +# if HAVE_VPRINTF +# define VFPRINTF(s,f,a) vfprintf((s),(f),(a)) +# elif HAVE_DOPRNT +# define VFPRINTF(s,f,a) _doprnt((f),(a),(s)) +# else +# define VFPRINTF(s,f,a) +# endif #endif #if TARGET_HOST_WINCE @@ -89,7 +93,7 @@ struct GXKeyList gxKeyList; */ static void fghReshapeWindow ( SFG_Window *window, int width, int height ) { - SFG_Window *current_window = fgStructure.Window; + SFG_Window *current_window = fgStructure.CurrentWindow; freeglut_return_if_fail( window != NULL ); @@ -100,9 +104,7 @@ static void fghReshapeWindow ( SFG_Window *window, int width, int height ) width, height ); XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */ -#elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE - -#if !TARGET_HOST_WINCE +#elif TARGET_HOST_WIN32 { RECT winRect; int x, y, w, h; @@ -152,7 +154,7 @@ static void fghReshapeWindow ( SFG_Window *window, int width, int height ) SWP_NOZORDER ); } -#endif /* TARGET_HOST_WINCE */ +#endif /* * XXX Should update {window->State.OldWidth, window->State.OldHeight} @@ -166,8 +168,6 @@ static void fghReshapeWindow ( SFG_Window *window, int width, int height ) glViewport( 0, 0, width, height ); } -#endif - /* * Force a window redraw. In Windows at least this is only a partial * solution: if the window is increasing in size in either dimension, @@ -187,7 +187,7 @@ static void fghReshapeWindow ( SFG_Window *window, int width, int height ) */ static void fghRedrawWindow ( SFG_Window *window ) { - SFG_Window *current_window = fgStructure.Window; + SFG_Window *current_window = fgStructure.CurrentWindow; freeglut_return_if_fail( window ); freeglut_return_if_fail( FETCH_WCB ( *window, Display ) ); @@ -458,7 +458,7 @@ static void fghSleepForEvents( void ) msec = fghNextTimer( ); /* XXX Use GLUT timers for joysticks... */ /* XXX Dumb; forces granularity to .01sec */ - if( fghHaveJoystick( ) && ( msec < 10 ) ) + if( fghHaveJoystick( ) && ( msec > 10 ) ) msec = 10; #if TARGET_HOST_UNIX_X11 @@ -495,17 +495,17 @@ static void fghSleepForEvents( void ) #if TARGET_HOST_UNIX_X11 /* - * Returns GLUT modifier mask for an XEvent. + * Returns GLUT modifier mask for the state field of an X11 event. */ -static int fghGetXModifiers( XEvent *event ) +static int fghGetXModifiers( int state ) { int ret = 0; - if( event->xkey.state & ( ShiftMask | LockMask ) ) + if( state & ( ShiftMask | LockMask ) ) ret |= GLUT_ACTIVE_SHIFT; - if( event->xkey.state & ControlMask ) + if( state & ControlMask ) ret |= GLUT_ACTIVE_CTRL; - if( event->xkey.state & Mod1Mask ) + if( state & Mod1Mask ) ret |= GLUT_ACTIVE_ALT; return ret; @@ -513,6 +513,450 @@ static int fghGetXModifiers( XEvent *event ) #endif +#if TARGET_HOST_UNIX_X11 && _DEBUG + +static const char* fghTypeToString( int type ) +{ + switch( type ) { + case KeyPress: return "KeyPress"; + case KeyRelease: return "KeyRelease"; + case ButtonPress: return "ButtonPress"; + case ButtonRelease: return "ButtonRelease"; + case MotionNotify: return "MotionNotify"; + case EnterNotify: return "EnterNotify"; + case LeaveNotify: return "LeaveNotify"; + case FocusIn: return "FocusIn"; + case FocusOut: return "FocusOut"; + case KeymapNotify: return "KeymapNotify"; + case Expose: return "Expose"; + case GraphicsExpose: return "GraphicsExpose"; + case NoExpose: return "NoExpose"; + case VisibilityNotify: return "VisibilityNotify"; + case CreateNotify: return "CreateNotify"; + case DestroyNotify: return "DestroyNotify"; + case UnmapNotify: return "UnmapNotify"; + case MapNotify: return "MapNotify"; + case MapRequest: return "MapRequest"; + case ReparentNotify: return "ReparentNotify"; + case ConfigureNotify: return "ConfigureNotify"; + case ConfigureRequest: return "ConfigureRequest"; + case GravityNotify: return "GravityNotify"; + case ResizeRequest: return "ResizeRequest"; + case CirculateNotify: return "CirculateNotify"; + case CirculateRequest: return "CirculateRequest"; + case PropertyNotify: return "PropertyNotify"; + case SelectionClear: return "SelectionClear"; + case SelectionRequest: return "SelectionRequest"; + case SelectionNotify: return "SelectionNotify"; + case ColormapNotify: return "ColormapNotify"; + case ClientMessage: return "ClientMessage"; + case MappingNotify: return "MappingNotify"; + default: return "UNKNOWN"; + } +} + +static const char* fghBoolToString( Bool b ) +{ + return b == False ? "False" : "True"; +} + +static const char* fghNotifyHintToString( char is_hint ) +{ + switch( is_hint ) { + case NotifyNormal: return "NotifyNormal"; + case NotifyHint: return "NotifyHint"; + default: return "UNKNOWN"; + } +} + +static const char* fghNotifyModeToString( int mode ) +{ + switch( mode ) { + case NotifyNormal: return "NotifyNormal"; + case NotifyGrab: return "NotifyGrab"; + case NotifyUngrab: return "NotifyUngrab"; + case NotifyWhileGrabbed: return "NotifyWhileGrabbed"; + default: return "UNKNOWN"; + } +} + +static const char* fghNotifyDetailToString( int detail ) +{ + switch( detail ) { + case NotifyAncestor: return "NotifyAncestor"; + case NotifyVirtual: return "NotifyVirtual"; + case NotifyInferior: return "NotifyInferior"; + case NotifyNonlinear: return "NotifyNonlinear"; + case NotifyNonlinearVirtual: return "NotifyNonlinearVirtual"; + case NotifyPointer: return "NotifyPointer"; + case NotifyPointerRoot: return "NotifyPointerRoot"; + case NotifyDetailNone: return "NotifyDetailNone"; + default: return "UNKNOWN"; + } +} + +static const char* fghVisibilityToString( int state ) { + switch( state ) { + case VisibilityUnobscured: return "VisibilityUnobscured"; + case VisibilityPartiallyObscured: return "VisibilityPartiallyObscured"; + case VisibilityFullyObscured: return "VisibilityFullyObscured"; + default: return "UNKNOWN"; + } +} + +static const char* fghConfigureDetailToString( int detail ) +{ + switch( detail ) { + case Above: return "Above"; + case Below: return "Below"; + case TopIf: return "TopIf"; + case BottomIf: return "BottomIf"; + case Opposite: return "Opposite"; + default: return "UNKNOWN"; + } +} + +static const char* fghPlaceToString( int place ) +{ + switch( place ) { + case PlaceOnTop: return "PlaceOnTop"; + case PlaceOnBottom: return "PlaceOnBottom"; + default: return "UNKNOWN"; + } +} + +static const char* fghMappingRequestToString( int request ) +{ + switch( request ) { + case MappingModifier: return "MappingModifier"; + case MappingKeyboard: return "MappingKeyboard"; + case MappingPointer: return "MappingPointer"; + default: return "UNKNOWN"; + } +} + +static const char* fghPropertyStateToString( int state ) +{ + switch( state ) { + case PropertyNewValue: return "PropertyNewValue"; + case PropertyDelete: return "PropertyDelete"; + default: return "UNKNOWN"; + } +} + +static const char* fghColormapStateToString( int state ) +{ + switch( state ) { + case ColormapUninstalled: return "ColormapUninstalled"; + case ColormapInstalled: return "ColormapInstalled"; + default: return "UNKNOWN"; + } +} + +static void fghPrintEvent( XEvent *event ) +{ + switch( event->type ) { + + case KeyPress: + case KeyRelease: { + XKeyEvent *e = &event->xkey; + fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, " + "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, " + "keycode=%u, same_screen=%s", fghTypeToString( e->type ), + e->window, e->root, e->subwindow, (unsigned long)e->time, + e->x, e->y, e->x_root, e->y_root, e->state, e->keycode, + fghBoolToString( e->same_screen ) ); + break; + } + + case ButtonPress: + case ButtonRelease: { + XButtonEvent *e = &event->xbutton; + fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, " + "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, " + "button=%u, same_screen=%d", fghTypeToString( e->type ), + e->window, e->root, e->subwindow, (unsigned long)e->time, + e->x, e->y, e->x_root, e->y_root, e->state, e->button, + fghBoolToString( e->same_screen ) ); + break; + } + + case MotionNotify: { + XMotionEvent *e = &event->xmotion; + fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, " + "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, " + "is_hint=%s, same_screen=%d", fghTypeToString( e->type ), + e->window, e->root, e->subwindow, (unsigned long)e->time, + e->x, e->y, e->x_root, e->y_root, e->state, + fghNotifyHintToString( e->is_hint ), + fghBoolToString( e->same_screen ) ); + break; + } + + case EnterNotify: + case LeaveNotify: { + XCrossingEvent *e = &event->xcrossing; + fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, " + "(x,y)=(%d,%d), mode=%s, detail=%s, same_screen=%d, " + "focus=%d, state=0x%x", fghTypeToString( e->type ), + e->window, e->root, e->subwindow, (unsigned long)e->time, + e->x, e->y, fghNotifyModeToString( e->mode ), + fghNotifyDetailToString( e->detail ), (int)e->same_screen, + (int)e->focus, e->state ); + break; + } + + case FocusIn: + case FocusOut: { + XFocusChangeEvent *e = &event->xfocus; + fgWarning( "%s: window=0x%x, mode=%s, detail=%s", + fghTypeToString( e->type ), e->window, + fghNotifyModeToString( e->mode ), + fghNotifyDetailToString( e->detail ) ); + break; + } + + case KeymapNotify: { + XKeymapEvent *e = &event->xkeymap; + char buf[32 * 2 + 1]; + int i; + for ( i = 0; i < 32; i++ ) { + snprintf( &buf[ i * 2 ], sizeof( buf ) - i * 2, + "%02x", e->key_vector[ i ] ); + } + buf[ i ] = '\0'; + fgWarning( "%s: window=0x%x, %s", fghTypeToString( e->type ), e->window, + buf ); + break; + } + + case Expose: { + XExposeEvent *e = &event->xexpose; + fgWarning( "%s: window=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), " + "count=%d", fghTypeToString( e->type ), e->window, e->x, + e->y, e->width, e->height, e->count ); + break; + } + + case GraphicsExpose: { + XGraphicsExposeEvent *e = &event->xgraphicsexpose; + fgWarning( "%s: drawable=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), " + "count=%d, (major_code,minor_code)=(%d,%d)", + fghTypeToString( e->type ), e->drawable, e->x, e->y, + e->width, e->height, e->count, e->major_code, + e->minor_code ); + break; + } + + case NoExpose: { + XNoExposeEvent *e = &event->xnoexpose; + fgWarning( "%s: drawable=0x%x, (major_code,minor_code)=(%d,%d)", + fghTypeToString( e->type ), e->drawable, e->major_code, + e->minor_code ); + break; + } + + case VisibilityNotify: { + XVisibilityEvent *e = &event->xvisibility; + fgWarning( "%s: window=0x%x, state=%s", fghTypeToString( e->type ), + e->window, fghVisibilityToString( e->state) ); + break; + } + + case CreateNotify: { + XCreateWindowEvent *e = &event->xcreatewindow; + fgWarning( "%s: (x,y)=(%d,%d), (width,height)=(%d,%d), border_width=%d, " + "window=0x%x, override_redirect=%s", + fghTypeToString( e->type ), e->x, e->y, e->width, e->height, + e->border_width, e->window, + fghBoolToString( e->override_redirect ) ); + break; + } + + case DestroyNotify: { + XDestroyWindowEvent *e = &event->xdestroywindow; + fgWarning( "%s: event=0x%x, window=0x%x", + fghTypeToString( e->type ), e->event, e->window ); + break; + } + + case UnmapNotify: { + XUnmapEvent *e = &event->xunmap; + fgWarning( "%s: event=0x%x, window=0x%x, from_configure=%s", + fghTypeToString( e->type ), e->event, e->window, + fghBoolToString( e->from_configure ) ); + break; + } + + case MapNotify: { + XMapEvent *e = &event->xmap; + fgWarning( "%s: event=0x%x, window=0x%x, override_redirect=%s", + fghTypeToString( e->type ), e->event, e->window, + fghBoolToString( e->override_redirect ) ); + break; + } + + case MapRequest: { + XMapRequestEvent *e = &event->xmaprequest; + fgWarning( "%s: parent=0x%x, window=0x%x", + fghTypeToString( event->type ), e->parent, e->window ); + break; + } + + case ReparentNotify: { + XReparentEvent *e = &event->xreparent; + fgWarning( "%s: event=0x%x, window=0x%x, parent=0x%x, (x,y)=(%d,%d), " + "override_redirect=%s", fghTypeToString( e->type ), + e->event, e->window, e->parent, e->x, e->y, + fghBoolToString( e->override_redirect ) ); + break; + } + + case ConfigureNotify: { + XConfigureEvent *e = &event->xconfigure; + fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d), " + "(width,height)=(%d,%d), border_width=%d, above=0x%x, " + "override_redirect=%s", fghTypeToString( e->type ), e->event, + e->window, e->x, e->y, e->width, e->height, e->border_width, + e->above, fghBoolToString( e->override_redirect ) ); + break; + } + + case ConfigureRequest: { + XConfigureRequestEvent *e = &event->xconfigurerequest; + fgWarning( "%s: parent=0x%x, window=0x%x, (x,y)=(%d,%d), " + "(width,height)=(%d,%d), border_width=%d, above=0x%x, " + "detail=%s, value_mask=%lx", fghTypeToString( e->type ), + e->parent, e->window, e->x, e->y, e->width, e->height, + e->border_width, e->above, + fghConfigureDetailToString( e->detail ), e->value_mask ); + break; + } + + case GravityNotify: { + XGravityEvent *e = &event->xgravity; + fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d)", + fghTypeToString( e->type ), e->event, e->window, e->x, e->y ); + break; + } + + case ResizeRequest: { + XResizeRequestEvent *e = &event->xresizerequest; + fgWarning( "%s: window=0x%x, (width,height)=(%d,%d)", + fghTypeToString( e->type ), e->window, e->width, e->height ); + break; + } + + case CirculateNotify: { + XCirculateEvent *e = &event->xcirculate; + fgWarning( "%s: event=0x%x, window=0x%x, place=%s", + fghTypeToString( e->type ), e->event, e->window, + fghPlaceToString( e->place ) ); + break; + } + + case CirculateRequest: { + XCirculateRequestEvent *e = &event->xcirculaterequest; + fgWarning( "%s: parent=0x%x, window=0x%x, place=%s", + fghTypeToString( e->type ), e->parent, e->window, + fghPlaceToString( e->place ) ); + break; + } + + case PropertyNotify: { + XPropertyEvent *e = &event->xproperty; + fgWarning( "%s: window=0x%x, atom=%lu, time=%lu, state=%s", + fghTypeToString( e->type ), e->window, + (unsigned long)e->atom, (unsigned long)e->time, + fghPropertyStateToString( e->state ) ); + break; + } + + case SelectionClear: { + XSelectionClearEvent *e = &event->xselectionclear; + fgWarning( "%s: window=0x%x, selection=%lu, time=%lu", + fghTypeToString( e->type ), e->window, + (unsigned long)e->selection, (unsigned long)e->time ); + break; + } + + case SelectionRequest: { + XSelectionRequestEvent *e = &event->xselectionrequest; + fgWarning( "%s: owner=0x%x, requestor=0x%x, selection=0x%x, " + "target=0x%x, property=%lu, time=%lu", + fghTypeToString( e->type ), e->owner, e->requestor, + (unsigned long)e->selection, (unsigned long)e->target, + (unsigned long)e->property, (unsigned long)e->time ); + break; + } + + case SelectionNotify: { + XSelectionEvent *e = &event->xselection; + fgWarning( "%s: requestor=0x%x, selection=0x%x, target=0x%x, " + "property=%lu, time=%lu", fghTypeToString( e->type ), + e->requestor, (unsigned long)e->selection, + (unsigned long)e->target, (unsigned long)e->property, + (unsigned long)e->time ); + break; + } + + case ColormapNotify: { + XColormapEvent *e = &event->xcolormap; + fgWarning( "%s: window=0x%x, colormap=%lu, new=%s, state=%s", + fghTypeToString( e->type ), e->window, + (unsigned long)e->colormap, fghBoolToString( e->new ), + fghColormapStateToString( e->state ) ); + break; + } + + case ClientMessage: { + XClientMessageEvent *e = &event->xclient; + char buf[ 61 ]; + char* p = buf; + char* end = buf + sizeof( buf ); + int i; + switch( e->format ) { + case 8: + for ( i = 0; i < 20; i++, p += 3 ) { + snprintf( p, end - p, " %02x", e->data.b[ i ] ); + } + break; + case 16: + for ( i = 0; i < 10; i++, p += 5 ) { + snprintf( p, end - p, " %04x", e->data.s[ i ] ); + } + break; + case 32: + for ( i = 0; i < 5; i++, p += 9 ) { + snprintf( p, end - p, " %08lx", e->data.l[ i ] ); + } + break; + } + *p = '\0'; + fgWarning( "%s: window=0x%x, message_type=%lu, format=%d, data=(%s )", + fghTypeToString( e->type ), e->window, + (unsigned long)e->message_type, e->format, buf ); + break; + } + + case MappingNotify: { + XMappingEvent *e = &event->xmapping; + fgWarning( "%s: window=0x%x, request=%s, first_keycode=%d, count=%d", + fghTypeToString( e->type ), e->window, + fghMappingRequestToString( e->request ), e->first_keycode, + e->count ); + break; + } + + default: { + fgWarning( "%s", fghTypeToString( event->type ) ); + break; + } + } +} + +#endif + /* -- INTERFACE FUNCTIONS -------------------------------------------------- */ /* @@ -539,6 +983,9 @@ void FGAPIENTRY glutMainLoopEvent( void ) while( XPending( fgDisplay.Display ) ) { XNextEvent( fgDisplay.Display, &event ); +#if _DEBUG + fghPrintEvent( &event ); +#endif switch( event.type ) { @@ -570,24 +1017,26 @@ void FGAPIENTRY glutMainLoopEvent( void ) * * GLUT presumably does this because it generally tries to treat * sub-windows the same as windows. - * - * XXX Technically, GETWINDOW( xconfigure ) and - * XXX {event.xconfigure} may not be legit ways to get at - * XXX data for CreateNotify events. In practice, the data - * XXX is in a union which is laid out much the same either - * XXX way. But if you want to split hairs, this isn't legit, - * XXX and we should instead duplicate some code. */ case CreateNotify: case ConfigureNotify: - GETWINDOW( xconfigure ); { - int width = event.xconfigure.width; - int height = event.xconfigure.height; + int width, height; + if( event.type == CreateNotify ) { + GETWINDOW( xcreatewindow ); + width = event.xcreatewindow.width; + height = event.xcreatewindow.height; + } else { + GETWINDOW( xconfigure ); + width = event.xconfigure.width; + height = event.xconfigure.height; + } if( ( width != window->State.OldWidth ) || ( height != window->State.OldHeight ) ) { + SFG_Window *current_window = fgStructure.CurrentWindow; + window->State.OldWidth = width; window->State.OldHeight = height; if( FETCH_WCB( *window, Reshape ) ) @@ -598,6 +1047,8 @@ void FGAPIENTRY glutMainLoopEvent( void ) glViewport( 0, 0, width, height ); } glutPostRedisplay( ); + if( window->IsMenu ) + fgSetWindow( current_window ); } } break; @@ -624,17 +1075,19 @@ void FGAPIENTRY glutMainLoopEvent( void ) if( event.xexpose.count == 0 ) { GETWINDOW( xexpose ); - fgSetWindow( window ); - glutPostRedisplay( ); + window->State.Redisplay = GL_TRUE; } break; case MapNotify: + break; + case UnmapNotify: - /* - * If we never do anything with this, can we just not ask to - * get these messages? - */ + /* We get this when iconifying a window. */ + GETWINDOW( xunmap ); + fgSetWindow( window ); + INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) ); + window->State.Visible = GL_FALSE; break; case MappingNotify: @@ -659,7 +1112,9 @@ void FGAPIENTRY glutMainLoopEvent( void ) * Sending this event, the X server can notify us that the window * has just acquired one of the three possible visibility states: * VisibilityUnobscured, VisibilityPartiallyObscured or - * VisibilityFullyObscured + * VisibilityFullyObscured. Note that we DO NOT receive a + * VisibilityNotify event when iconifying a window, we only get an + * UnmapNotify then. */ switch( event.xvisibility.state ) { @@ -691,6 +1146,10 @@ void FGAPIENTRY glutMainLoopEvent( void ) case LeaveNotify: GETWINDOW( xcrossing ); GETMOUSE( xcrossing ); + if( ( event.type == LeaveNotify ) && window->IsMenu && + window->ActiveMenu && window->ActiveMenu->IsActive ) + fgUpdateMenuHighlight( window->ActiveMenu ); + INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ? GLUT_ENTERED : GLUT_LEFT ) ); @@ -710,8 +1169,8 @@ void FGAPIENTRY glutMainLoopEvent( void ) window->ActiveMenu->Window->State.MouseY = event.xmotion.y_root - window->ActiveMenu->Y; } - window->ActiveMenu->Window->State.Redisplay = GL_TRUE ; - fgSetWindow( window->ActiveMenu->ParentWindow ); + + fgUpdateMenuHighlight( window->ActiveMenu ); break; } @@ -722,14 +1181,15 @@ void FGAPIENTRY glutMainLoopEvent( void ) * XXX track ButtonPress/ButtonRelease events in our own * XXX bit-mask? */ -#define BUTTON_MASK \ - ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) - if ( event.xmotion.state & BUTTON_MASK ) + fgState.Modifiers = fghGetXModifiers( event.xmotion.state ); + if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) { INVOKE_WCB( *window, Motion, ( event.xmotion.x, event.xmotion.y ) ); - else + } else { INVOKE_WCB( *window, Passive, ( event.xmotion.x, event.xmotion.y ) ); + } + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -775,14 +1235,10 @@ void FGAPIENTRY glutMainLoopEvent( void ) ! FETCH_WCB( *window, MouseWheel ) ) break; - fgState.Modifiers = fghGetXModifiers( &event ); + fgState.Modifiers = fghGetXModifiers( event.xbutton.state ); - /* - * Finally execute the mouse or mouse wheel callback - * - * XXX Use a symbolic constant, *not* "4"! ("3, sire!") - */ - if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) ) + /* Finally execute the mouse or mouse wheel callback */ + if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) ) INVOKE_WCB( *window, Mouse, ( button, pressed ? GLUT_DOWN : GLUT_UP, event.xbutton.x, @@ -802,7 +1258,7 @@ void FGAPIENTRY glutMainLoopEvent( void ) * XXX Note that {button} has already been decremeted * XXX in mapping from X button numbering to GLUT. */ - int wheel_number = (button - 3) / 2; + int wheel_number = (button - glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS )) / 2; int direction = -1; if( button % 2 ) direction = 1; @@ -814,9 +1270,7 @@ void FGAPIENTRY glutMainLoopEvent( void ) event.xbutton.y ) ); } - - /* Trash the modifiers state */ - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -862,13 +1316,13 @@ void FGAPIENTRY glutMainLoopEvent( void ) if( event.type == KeyPress ) { - keyboard_cb = FETCH_WCB( *window, Keyboard ); - special_cb = FETCH_WCB( *window, Special ); + keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, Keyboard )); + special_cb = (FGCBSpecial) ( FETCH_WCB( *window, Special )); } else { - keyboard_cb = FETCH_WCB( *window, KeyboardUp ); - special_cb = FETCH_WCB( *window, SpecialUp ); + keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, KeyboardUp )); + special_cb = (FGCBSpecial) ( FETCH_WCB( *window, SpecialUp )); } /* Is there a keyboard/special callback hooked for this window? */ @@ -891,11 +1345,11 @@ void FGAPIENTRY glutMainLoopEvent( void ) if( keyboard_cb ) { fgSetWindow( window ); - fgState.Modifiers = fghGetXModifiers( &event ); + fgState.Modifiers = fghGetXModifiers( event.xkey.state ); keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } } else @@ -945,9 +1399,9 @@ void FGAPIENTRY glutMainLoopEvent( void ) if( special_cb && (special != -1) ) { fgSetWindow( window ); - fgState.Modifiers = fghGetXModifiers( &event ); + fgState.Modifiers = fghGetXModifiers( event.xkey.state ); special_cb( special, event.xkey.x, event.xkey.y ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } } } @@ -1025,7 +1479,7 @@ void FGAPIENTRY glutMainLoop( void ) { if ( FETCH_WCB( *window, Visibility ) ) { - SFG_Window *current_window = fgStructure.Window ; + SFG_Window *current_window = fgStructure.CurrentWindow ; INVOKE_WCB( *window, Visibility, ( window->State.Visible ) ); fgSetWindow( current_window ); @@ -1056,7 +1510,13 @@ void FGAPIENTRY glutMainLoop( void ) else { if( fgState.IdleCallback ) + { + if( fgStructure.CurrentWindow && + fgStructure.CurrentWindow->IsMenu ) + /* fail safe */ + fgSetWindow( window ); fgState.IdleCallback( ); + } fghSleepForEvents( ); } @@ -1139,13 +1599,13 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, if( fgStructure.MenuContext ) wglMakeCurrent( window->Window.Device, - fgStructure.MenuContext->Context + fgStructure.MenuContext->MContext ); else { fgStructure.MenuContext = (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) ); - fgStructure.MenuContext->Context = + fgStructure.MenuContext->MContext = wglCreateContext( window->Window.Device ); } @@ -1265,6 +1725,20 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, */ return 0; + /* XXX For a future patch: we need a mouse entry event. Unfortunately Windows + * XXX doesn't give us one, so we will probably need a "MouseInWindow" flag in + * XXX the SFG_Window structure. Set it to true to begin with and then have the + * XXX WM_MOUSELEAVE code set it to false. Then when we get a WM_MOUSEMOVE event, + * XXX if the flag is false we invoke the Entry callback and set the flag to true. + */ + case 0x02a2: /* This is the message we get when the mouse is leaving the window */ + if( window->IsMenu && + window->ActiveMenu && window->ActiveMenu->IsActive ) + fgUpdateMenuHighlight( window->ActiveMenu ); + + INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) ); + break ; + case WM_MOUSEMOVE: { #if TARGET_HOST_WINCE @@ -1281,8 +1755,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, if ( window->ActiveMenu ) { - window->State.Redisplay = GL_TRUE; - fgSetWindow ( window->ActiveMenu->ParentWindow ); + fgUpdateMenuHighlight( window->ActiveMenu ); break; } @@ -1297,7 +1770,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, INVOKE_WCB( *window, Passive, ( window->State.MouseX, window->State.MouseY ) ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -1407,7 +1880,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, ) ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -1455,11 +1928,14 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, else /* No mouse wheel, call the mouse button callback twice */ { /* + * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4 + * " " one +1 to 5, -1 to 6, ... + * * XXX The below assumes that you have no more than 3 mouse * XXX buttons. Sorry. */ - int button = wheel_number*2 + 4; - if( direction > 0 ) + int button = wheel_number * 2 + 3; + if( direction < 0 ) ++button; INVOKE_WCB( *window, Mouse, ( button, GLUT_DOWN, @@ -1467,11 +1943,11 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, ); INVOKE_WCB( *window, Mouse, ( button, GLUT_UP, - window->State.MouseX, window->State.MouseX ) + window->State.MouseX, window->State.MouseY ) ); } - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break ; @@ -1558,7 +2034,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, window->State.MouseX, window->State.MouseY ) ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -1641,7 +2117,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, window->State.MouseX, window->State.MouseY ) ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break; @@ -1656,7 +2132,7 @@ LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, ( (char)wParam, window->State.MouseX, window->State.MouseY ) ); - fgState.Modifiers = 0xffffffff; + fgState.Modifiers = INVALID_MODIFIERS; } break;