Engine/lib/sdl/src/video/x11/SDL_x11messagebox.c
/* Loop and handle message box event messages until something kills it. */
Loop and handle message box event messages until something kills it.
Loop and handle message box event messages until something kills it .
static int
X11_MessageBoxLoop( SDL_MessageBoxDataX11 *data )
{
    GC ctx;
    XGCValues ctx_vals;
    SDL_bool close_dialog = SDL_FALSE;
    SDL_bool has_focus = SDL_TRUE;
    KeySym last_key_pressed = XK_VoidSymbol;
    unsigned long gcflags = GCForeground | GCBackground;
    SDL_zero(ctx_vals);
    ctx_vals.foreground = data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ];
    ctx_vals.background = data->color[ SDL_MESSAGEBOX_COLOR_BACKGROUND ];
    if (!SDL_X11_HAVE_UTF8) {
        gcflags |= GCFont;
        ctx_vals.font = data->font_struct->fid;
    }
    ctx = X11_XCreateGC( data->display, data->window, gcflags, &ctx_vals );
    if ( ctx == None ) {
        return SDL_SetError("Couldn't create graphics context");
    }
    data->button_press_index = -1;  
    data->mouse_over_index = -1;    
    while( !close_dialog ) {
        XEvent e;
        SDL_bool draw = SDL_TRUE;
        X11_XIfEvent( data->display, &e, X11_MessageBoxEventTest, (XPointer) data );
        if ( ( e.type != Expose ) && X11_XFilterEvent( &e, None ) )
            continue;
        switch( e.type ) {
        case Expose:
            if ( e.xexpose.count > 0 ) {
                draw = SDL_FALSE;
            }
            break;
        case FocusIn:
            has_focus = SDL_TRUE;
            break;
        case FocusOut:
            has_focus = SDL_FALSE;
            data->button_press_index = -1;
            data->mouse_over_index = -1;
            break;
        case MotionNotify:
            if ( has_focus ) {
                const int previndex = data->mouse_over_index;
                data->mouse_over_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
                if (data->mouse_over_index == previndex) {
                    draw = SDL_FALSE;
                }
            }
            break;
        case ClientMessage:
            if ( e.xclient.message_type == data->wm_protocols &&
                 e.xclient.format == 32 &&
                 e.xclient.data.l[ 0 ] == data->wm_delete_message ) {
                close_dialog = SDL_TRUE;
            }
            break;
        case KeyPress:
            last_key_pressed = X11_XLookupKeysym( &e.xkey, 0 );
            break;
        case KeyRelease: {
            Uint32 mask = 0;
            KeySym key = X11_XLookupKeysym( &e.xkey, 0 );
            if ( key != last_key_pressed )
                break;
            if ( key == XK_Escape )
                mask = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
            else if ( ( key == XK_Return ) || ( key == XK_KP_Enter ) )
                mask = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
            if ( mask ) {
                int i;
                for ( i = 0; i < data->numbuttons; i++ ) {
                    SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ i ];
                    if ( buttondatax11->buttondata->flags & mask ) {
                        *data->pbuttonid = buttondatax11->buttondata->buttonid;
                        close_dialog = SDL_TRUE;
                        break;
                    }
                }
            }
            break;
        }
        case ButtonPress:
            data->button_press_index = -1;
            if ( e.xbutton.button == Button1 ) {
                data->button_press_index = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
            }
            break;
        case ButtonRelease:
            if ( ( e.xbutton.button == Button1 ) && ( data->button_press_index >= 0 ) ) {
                int button = GetHitButtonIndex( data, e.xbutton.x, e.xbutton.y );
                if ( data->button_press_index == button ) {
                    SDL_MessageBoxButtonDataX11 *buttondatax11 = &data->buttonpos[ button ];
                    *data->pbuttonid = buttondatax11->buttondata->buttonid;
                    close_dialog = SDL_TRUE;
                }
            }
            data->button_press_index = -1;
            break;
        }
        if ( draw ) {
            X11_MessageBoxDraw( data, ctx );
        }
    }
    X11_XFreeGC( data->display, ctx );
    return 0;
}
static int X11_MessageBoxLoop ( SDL_MessageBoxDataX11 * data ) { GC ctx ; XGCValues ctx_vals ; SDL_bool close_dialog = SDL_FALSE ; SDL_bool has_focus = SDL_TRUE ; KeySym last_key_pressed = XK_VoidSymbol ; unsigned long gcflags = GCForeground | GCBackground ; SDL_zero ( ctx_vals ) ; ctx_vals . foreground = data -> color [ SDL_MESSAGEBOX_COLOR_BACKGROUND ] ; ctx_vals . background = data -> color [ SDL_MESSAGEBOX_COLOR_BACKGROUND ] ; if ( ! SDL_X11_HAVE_UTF8 ) { gcflags |= GCFont ; ctx_vals . font = data -> font_struct -> fid ; } ctx = X11_XCreateGC ( data -> display , data -> window , gcflags , & ctx_vals ) ; if ( ctx == None ) { return SDL_SetError ( " " ) ; } data -> button_press_index = -1 ; data -> mouse_over_index = -1 ; while ( ! close_dialog ) { XEvent e ; SDL_bool draw = SDL_TRUE ; X11_XIfEvent ( data -> display , & e , X11_MessageBoxEventTest , ( XPointer ) data ) ; if ( ( e . type != Expose ) && X11_XFilterEvent ( & e , None ) ) continue ; switch ( e . type ) { case Expose : if ( e . xexpose . count > 0 ) { draw = SDL_FALSE ; } break ; case FocusIn : has_focus = SDL_TRUE ; break ; case FocusOut : has_focus = SDL_FALSE ; data -> button_press_index = -1 ; data -> mouse_over_index = -1 ; break ; case MotionNotify : if ( has_focus ) { const int previndex = data -> mouse_over_index ; data -> mouse_over_index = GetHitButtonIndex ( data , e . xbutton . x , e . xbutton . y ) ; if ( data -> mouse_over_index == previndex ) { draw = SDL_FALSE ; } } break ; case ClientMessage : if ( e . xclient . message_type == data -> wm_protocols && e . xclient . format == 32 && e . xclient . data . l [ 0 ] == data -> wm_delete_message ) { close_dialog = SDL_TRUE ; } break ; case KeyPress : last_key_pressed = X11_XLookupKeysym ( & e . xkey , 0 ) ; break ; case KeyRelease : { Uint32 mask = 0 ; KeySym key = X11_XLookupKeysym ( & e . xkey , 0 ) ; if ( key != last_key_pressed ) break ; if ( key == XK_Escape ) mask = SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT ; else if ( ( key == XK_Return ) || ( key == XK_KP_Enter ) ) mask = SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT ; if ( mask ) { int i ; for ( i = 0 ; i < data -> numbuttons ; i ++ ) { SDL_MessageBoxButtonDataX11 * buttondatax11 = & data -> buttonpos [ i ] ; if ( buttondatax11 -> buttondata -> flags & mask ) { * data -> pbuttonid = buttondatax11 -> buttondata -> buttonid ; close_dialog = SDL_TRUE ; break ; } } } break ; } case ButtonPress : data -> button_press_index = -1 ; if ( e . xbutton . button == Button1 ) { data -> button_press_index = GetHitButtonIndex ( data , e . xbutton . x , e . xbutton . y ) ; } break ; case ButtonRelease : if ( ( e . xbutton . button == Button1 ) && ( data -> button_press_index >= 0 ) ) { int button = GetHitButtonIndex ( data , e . xbutton . x , e . xbutton . y ) ; if ( data -> button_press_index == button ) { SDL_MessageBoxButtonDataX11 * buttondatax11 = & data -> buttonpos [ button ] ; * data -> pbuttonid = buttondatax11 -> buttondata -> buttonid ; close_dialog = SDL_TRUE ; } } data -> button_press_index = -1 ; break ; } if ( draw ) { X11_MessageBoxDraw ( data , ctx ) ; } } X11_XFreeGC ( data -> display , ctx ) ; return 0 ; }
Loop and handle message box event messages until something kills it.
Loop and handle message box event messages until something kills it .
/* Reset what button is currently depressed. */ /* Reset what button the mouse is over. */ /* can't use XWindowEvent() because it can't handle ClientMessage events. */ /* can't use XNextEvent() because we only want events for this window. */ /* If X11_XFilterEvent returns True, then some input method has filtered the
           event, and the client should discard the event. */ /* Got focus. */ /* lost focus. Reset button and mouse info. */ /* Mouse moved... */ /* Store key press - we make sure in key release that we got both. */ /* If this is a key release for something we didn't get the key down for, then bail. */ /* Look for first button with this mask set, and return it if found. */ /* Find index of button they clicked on. */ /* If button is released over the same button that was clicked down on, then return it. */ /* Draw our dialog box. */