Changeset 537 for trunk/thune/gl/gui.c

Show
Ignore:
Timestamp:
06/07/08 03:35:15 (6 months ago)
Author:
krobillard
Message:

Added show, hide, and gui_setMouseFocus().
Quit & halt propogate up nested ur_eval() calls.
Thune-gl RPM builds again.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/thune/gl/gui.c

    r536 r537  
    7272    for(it.id = ui->rootList; IS_VALID(it.id); it.id = it.w->next) { \ 
    7373        it.w = WPTR(it.id); 
     74 
     75#define EACH_SHOWN_ROOT(it) \ 
     76    EACH_ROOT(it) \ 
     77        if( it.w->flags & GW_HIDDEN ) \ 
     78            continue; 
    7479 
    7580#define EACH_END    } 
     
    121126 
    122127 
    123 static void gui_freeWidgetP( GUI* ui, GWidget* w, GWidgetId id ) 
    124 { 
    125     GWidgetIt it; 
    126     GWidgetId next; 
    127  
    128     w->next = ui->firstFree; 
    129     ui->firstFree = id; 
    130  
     128static void gui_removeFocus( GUI* ui, GWidgetId id ) 
     129{ 
    131130    if( ui->mouseFocus == id ) 
    132131    { 
     
    137136    if( ui->keyFocus == id ) 
    138137        ui->keyFocus = NO_WID; 
     138} 
     139 
     140 
     141static void gui_freeWidgetP( GUI* ui, GWidget* w, GWidgetId id ) 
     142{ 
     143    GWidgetIt it; 
     144    GWidgetId next; 
     145 
     146    w->next = ui->firstFree; 
     147    ui->firstFree = id; 
     148 
     149    gui_removeFocus( ui, id ); 
    139150 
    140151    //EACH_CHILD( w, it ) 
     
    896907    ui->ut         = ut; 
    897908    ui->style      = 0; 
    898     ui->root       = NO_WID; 
    899909    ui->keyFocus   = NO_WID; 
    900910    ui->mouseFocus = NO_WID; 
     
    956966 
    957967 
     968void gui_setKeyFocus( GUI* ui, GWidgetId id ) 
     969{ 
     970    ui->keyFocus = id; 
     971} 
     972 
     973 
     974void gui_setMouseFocus( GUI* ui, GWidgetId id ) 
     975{ 
     976    ui->mouseFocus = id; 
     977} 
     978 
     979 
     980void gui_grabMouse( GUI* ui, GWidgetId id ) 
     981{ 
     982    ui->mouseFocus = id; 
     983    ui->mouseGrabbed = 1; 
     984} 
     985 
     986 
     987void gui_ungrabMouse( GUI* ui, GWidgetId id ) 
     988{ 
     989    if( ui->mouseFocus == id ) 
     990    { 
     991        ui->mouseGrabbed = 0; 
     992    } 
     993} 
     994 
     995 
    958996static GWidget* childAt( GUI* ui, GWidget* wp, const GLViewEvent* ev ) 
    959997{ 
     
    9671005 
    9681006 
    969 void gui_setKeyFocus( GUI* ui, GWidgetId id ) 
    970 { 
    971     ui->keyFocus = id; 
    972 } 
    973  
    974  
    975 void gui_grabMouse( GUI* ui, GWidgetId id ) 
    976 { 
    977     ui->mouseFocus = id; 
    978     ui->mouseGrabbed = 1; 
    979 } 
    980  
    981  
    982 void gui_ungrabMouse( GUI* ui, GWidgetId id ) 
    983 { 
    984     if( ui->mouseFocus == id ) 
    985     { 
    986         ui->mouseGrabbed = 0; 
    987     } 
     1007static GWidgetId widgetAt( GUI* ui, const GLViewEvent* ev ) 
     1008{ 
     1009    GWidgetIt it; 
     1010    EACH_SHOWN_ROOT( it ) 
     1011        if( gui_widgetContains( it.w, ev->x, ev->y ) ) 
     1012        { 
     1013            it.w = childAt( ui, it.w, ev ); 
     1014            return it.w ? WID(it.w) : NO_WID; 
     1015        } 
     1016    EACH_END 
     1017    return NO_WID; 
    9881018} 
    9891019 
     
    9941024 
    9951025#if 0 
    996     printf( "KR dispatch %d  root %d  mouseFocus %d  keyFocus %d\n", 
    997             ev->type, ui->root, ui->mouseFocus, ui->keyFocus ); 
     1026    printf( "KR dispatch %d  mouseFocus %d  keyFocus %d\n", 
     1027            ev->type, ui->mouseFocus, ui->keyFocus ); 
    9981028#endif 
    9991029 
     
    10041034            // Convert window system origin from top of window to the bottom. 
    10051035            ev->y = ui->rootH - ev->y; 
     1036            // Fall through... 
    10061037 
    10071038        case GLV_EVENT_WHEEL: 
     
    10311062                                ev->state, ev->x, ev->y ); 
    10321063                    CLASS( w ).dispatch( ui, w, &me ); 
    1033                     ui->mouseFocus = NO_WID; 
    10341064                } 
    10351065            } 
    1036             if( IS_VALID(ui->root) ) 
     1066 
     1067            ui->mouseFocus = widgetAt( ui, ev ); 
     1068            if( IS_VALID(ui->mouseFocus) ) 
    10371069            { 
    1038                 GWidget* rw = WPTR(ui->root); 
    1039                 w = childAt( ui, rw, ev ); 
    1040                 if( /*(w != rw) &&*/ (! (w->flags & GW_DISABLED)) ) 
     1070                w = WPTR(ui->mouseFocus); 
     1071                if( ! (w->flags & GW_DISABLED) ) 
    10411072                { 
    10421073                    GLViewEvent me; 
     
    10441075                                ev->state, ev->x, ev->y ); 
    10451076                    CLASS( w ).dispatch( ui, w, &me ); 
    1046                     ui->mouseFocus = WID(w); 
    10471077                    goto dispatch; 
    10481078                } 
     
    10601090 
    10611091        case GLV_EVENT_FOCUS_IN: 
     1092            ui->mouseFocus = widgetAt( ui, ev ); 
     1093            // Fall through... 
     1094 
    10621095        case GLV_EVENT_FOCUS_OUT: 
    1063             goto root; 
    1064     } 
    1065  
    1066 root: 
    1067  
    1068     if( ! IS_VALID(ui->root) ) 
    1069         return; 
    1070     w = WPTR(ui->root); 
     1096            if( IS_VALID(ui->mouseFocus) ) 
     1097            { 
     1098                w = WPTR(ui->mouseFocus); 
     1099                goto dispatch; 
     1100            } 
     1101            break; 
     1102    } 
     1103    return; 
    10711104 
    10721105dispatch: 
     
    11701203 
    11711204/** 
    1172   Returns pointer to root widget or zero if id is invalid. 
     1205  Returns pointer to root parent widget or zero if id is invalid. 
    11731206*/ 
    11741207GWidget* gui_root( const GUI* ui, GWidgetId id ) 
     
    12251258    else if( ! hidden ) 
    12261259    { 
     1260        GWidgetId id = WID(wp); 
     1261        gui_removeFocus( ui, id ); 
    12271262        wp->flags |= GW_HIDDEN; 
    12281263        markLayoutDirty( ui, wp->parent ); 
     
    13391374                        { 
    13401375                            linkRoot( ui, wp, ms->wid ); 
    1341                             ui->root = ms->wid; 
    1342  
    13431376                            if( ! IS_VALID(ui->keyFocus) ) 
    1344                                 ui->keyFocus = ui->root; 
     1377                                ui->keyFocus = ms->wid; 
    13451378                        } 
    13461379                        //return wp;