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

Show
Ignore:
Timestamp:
05/30/08 18:36:20 (6 months ago)
Author:
krobillard
Message:

GL testfw reload works again.
Added UG_GUI_THROW macro to be used by widget event handlers.
Added gui_matchArgs() and GUI_PARSE macros.

Files:
1 modified

Legend:

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

    r527 r528  
    2929  [x] Layout 
    3030  [/] Input 
    31   [ ] Replace old widget code (gx.t) with widget class for all-Thune code. 
    32      [ ] Convert all demos. 
    3331*/ 
    3432 
     
    9088    ms.x     = ex; \ 
    9189    ms.y     = ey 
     90 
    9291 
    9392#define SET_AREA(wp,rect) \ 
     
    201200static GWidget* base_parse( GUI* ui, GMakeState* ms, int classId ) 
    202201{ 
    203     GWidget* wp = gui_allocWidget( ui, classId ); 
    204     if( wp ) 
    205         ++ms->it; 
    206     else 
    207         ms->error = "allocWidget failed"; 
     202    GWidget* wp; 
     203    GUI_PARSE_ALLOC( wp ) 
     204    ++ms->it; 
    208205    return wp; 
    209206} 
     
    331328    { 
    332329no_block: 
    333         ms->error = "box requires block!"; 
    334         return 0; 
     330        GUI_PARSE_ERR( "box requires block!" ); 
    335331    } 
    336332    if( ur_is(bc, UT_COORD) ) 
     
    343339        goto no_block; 
    344340 
    345     wp = gui_allocWidget( ui, classId ); 
    346     if( wp ) 
     341    GUI_PARSE_ALLOC( wp ) 
     342 
    347343    { 
    348344        GMakeState cms; 
     
    364360        } 
    365361        ms->it = bc + 1; 
    366     } 
    367     else 
    368     { 
    369         ms->error = "allocWidget failed"; 
    370362    } 
    371363    return wp; 
     
    829821    GWidget* wp; 
    830822    ButtonData* wd; 
    831     //UThread* ut = ui->ut; 
    832     const UCell* sc = ms->it + 1; 
    833     const UCell* bc = ms->it + 2; 
    834  
    835     if( ((ms->end - ms->it) < 3) || 
    836         (! ur_is(sc, UT_STRING)) || 
    837         (! ur_is(bc, UT_BLOCK)) ) 
    838     { 
    839         ms->error = "button requires string! and block!"; 
    840         return 0; 
    841     } 
    842  
    843     wp = gui_allocWidget( ui, classId ); 
    844     if( ! wp ) 
    845     { 
    846         ms->error = "allocWidget failed"; 
    847         return 0; 
    848     } 
    849  
    850     wd = BUTTON_DATA(wp); 
    851     wd->labelN = sc->series.n; 
    852     wd->codeN  = bc->series.n; 
    853  
    854     ms->it += 3; 
    855     return wp; 
     823    const UCell* arg0; 
     824 
     825    arg0 = gui_matchArgs( ms, 2, UT_STRING, UT_BLOCK ); 
     826    if( arg0 ) 
     827    { 
     828        GUI_PARSE_ALLOC( wp ) 
     829 
     830        wd = BUTTON_DATA(wp); 
     831        wd->labelN = arg0->series.n; 
     832        wd->codeN  = (arg0 + 1)->series.n; 
     833        return wp; 
     834    } 
     835 
     836    GUI_PARSE_ERR( "button requires string! and block!" ); 
    856837} 
    857838 
     
    958939    if( wd->codeN ) 
    959940    { 
    960         if( UR_EVAL_ERROR == ur_eval( ui->ut, wd->codeN, 0 ) ) 
     941        if( UR_EVAL_OK != ur_eval( ui->ut, wd->codeN, 0 ) ) 
    961942        { 
    962             // TODO: Throw or catch error. 
     943            UG_GUI_THROW; 
    963944        } 
    964945    } 
     
    10621043 
    10631044#include "widgets/twidget.c" 
    1064  
    1065  
    1066 static int wclassCount = 6; 
     1045#include "widgets/listw.c" 
     1046 
     1047/* 
     1048   :tok 
     1049   'expand                   (tok make-widget) 
     1050 | 'hbox      block!         (tok make-widget) 
     1051 | 'vbox      block!         (tok make-widget) 
     1052 | 'window    block!         (tok make-widget) 
     1053 | 'button    string! block! (tok make-widget) 
     1054 | 't-widget  block!         (tok make-widget) 
     1055 | 'list      block!  block! (tok make-widget) 
     1056*/ 
     1057 
     1058static int wclassCount = 7; 
    10671059 
    10681060static GWidgetClass wclass[ WCLASS_MAX ] = 
     
    10981090    0, 0, 0 }, 
    10991091 
     1092  { "list", // "block! block!" 
     1093    listw_parse,      listw_init,     listw_mark,     listw_event, 
     1094    expand_sizeHint,  listw_layout,   listw_render, 
     1095    0, 0, 0 }, 
     1096 
    11001097  /* 
    11011098  { "option", 
    11021099  { "choice", 
    1103   { "list", 
    11041100  { "menu", 
    11051101  { "data",         // label 
     
    15881584 
    15891585/* 
     1586  Returns pointer to first arg if all types match, or zero. 
     1587*/ 
     1588const UCell* gui_matchArgs( GMakeState* ms, int argc, ... ) 
     1589{ 
     1590    va_list args; 
     1591    int type; 
     1592    const UCell* it; 
     1593    const UCell* first = ms->it + 1; 
     1594 
     1595    if( (ms->end - first) < argc ) 
     1596        return 0; 
     1597    it = first; 
     1598 
     1599    va_start( args, argc ); 
     1600    while( argc ) 
     1601    { 
     1602        type = va_arg( args, int ); 
     1603        if( ur_type(it) != type ) 
     1604            break; 
     1605        ++it; 
     1606        --argc; 
     1607    } 
     1608    va_end( args ); 
     1609 
     1610    if( argc ) 
     1611        return 0; 
     1612    ms->it = it; 
     1613    return first; 
     1614} 
     1615 
     1616 
     1617/* 
    15901618  Only mark and sweep on top-level (parent-less) widgets. 
    15911619*/