Changeset 6675

Show
Ignore:
Timestamp:
02/06/10 09:01:31 (2 years ago)
Author:
westram
Message:
  • AW_awar / widget interaction
    • replaced AW_INSERT_BUTTON_IN_AWAR_LIST by AW_awar/tie_widget
    • link AW_widget_refresh_cb in AW_awar (leak)
    • use Widget type instead of void*
    • untie_all_widgets() in dtor
  • removed deprecated header aw_awar.hxx
  • AW_root
    • delete focus_callback_list (leak)
    • method remove_button_from_sens_list replaces AW_remove_button_from_sens_list
    • moved member 'button_list' from AW_root_Motif, renamed it into 'button_sens_list' and destroy it in dtor
    • use Widget type instead of void*
Location:
trunk
Files:
1 removed
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/NTREE/ad_spec.cxx

    r6656 r6675  
    11751175 
    11761176        cb_info->remap(new_awar); // remap the callback from old awar to new unique awar 
    1177         aww->update_label((int*)di->get_detach_button(), "GET"); 
     1177        aww->update_label(di->get_detach_button(), "GET"); 
    11781178 
    11791179        *aww_pointer = 0;       // caller window will be recreated on next open after clearing this pointer 
  • trunk/WINDOW/AW_button.cxx

    r6584 r6675  
    1515#include "aw_size.hxx" 
    1616#include "aw_select.hxx" 
    17 #include "aw_awar.hxx" 
     17#include "aw_nawar.hxx" 
    1818#include "aw_window_Xm.hxx" 
    1919 
     
    3939#endif // DEBUG 
    4040 
    41 static void aw_cp_awar_2_widget_cb(AW_root *root, AW_widget_list_for_variable *widgetlist) { 
    42     if (widgetlist->widget == (int *)root->changer_of_variable) { 
     41struct AW_widget_refresh_cb { 
     42    AW_widget_refresh_cb(AW_widget_refresh_cb *previous, AW_awar *vs, AW_CL cd1, Widget w, AW_widget_type type, AW_window *awi); 
     43    ~AW_widget_refresh_cb(); 
     44 
     45    AW_CL           cd; 
     46    AW_awar        *awar; 
     47    Widget          widget; 
     48    AW_widget_type  widget_type; 
     49    AW_window      *aw; 
     50 
     51    AW_widget_refresh_cb *next; 
     52}; 
     53 
     54static void aw_cp_awar_2_widget_cb(AW_root *root, AW_CL cl_widget_refresh_cb) { 
     55    AW_widget_refresh_cb *widgetlist = (AW_widget_refresh_cb*)cl_widget_refresh_cb; 
     56    if (widgetlist->widget == root->changer_of_variable) { 
    4357        root->changer_of_variable = 0; 
    4458        root->value_changed = false; 
     
    8195} 
    8296 
    83  
    84 AW_widget_list_for_variable::AW_widget_list_for_variable(AW_awar *vs, AW_CL cd1, int *widgeti, AW_widget_type type, AW_window *awi) { 
     97AW_widget_refresh_cb::AW_widget_refresh_cb(AW_widget_refresh_cb *previous, AW_awar *vs, AW_CL cd1, Widget w, AW_widget_type type, AW_window *awi) { 
    8598    cd          = cd1; 
    86     widget      = widgeti; 
     99    widget      = w; 
    87100    widget_type = type; 
    88101    awar        = vs; 
    89102    aw          = awi; 
    90     next        = 0; 
    91     awar->add_callback((AW_RCB1)aw_cp_awar_2_widget_cb, (AW_CL)this); 
    92 } 
     103    next        = previous; 
     104 
     105    awar->add_callback(aw_cp_awar_2_widget_cb, (AW_CL)this); 
     106} 
     107 
     108AW_widget_refresh_cb::~AW_widget_refresh_cb() { 
     109    if (next) delete next; 
     110    awar->remove_callback(aw_cp_awar_2_widget_cb, (AW_CL)this); 
     111} 
     112 
     113void AW_awar::tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww) { 
     114    refresh_list = new AW_widget_refresh_cb(refresh_list, this, cd1, widget, type, aww); 
     115} 
     116void AW_awar::untie_all_widgets() { 
     117    delete refresh_list; refresh_list = NULL; 
     118} 
     119 
    93120 
    94121struct AW_variable_update_struct { // used to refresh single items on change 
     
    139166 
    140167    if (root->value_changed) { 
    141         root->changer_of_variable = (long)vus->widget; 
     168        root->changer_of_variable = vus->widget; 
    142169    } 
    143170 
     
    847874} 
    848875 
    849 void AW_window::update_label(int *widget, const char *var_value) { 
    850     Widget w = (Widget) widget; 
    851  
    852     if (get_root()->changer_of_variable != (long)widget) { 
    853         XtVaSetValues(w, RES_CONVERT(XmNlabelString, var_value), NULL); 
     876void AW_window::update_label(Widget widget, const char *var_value) { 
     877    if (get_root()->changer_of_variable != widget) { 
     878        XtVaSetValues(widget, RES_CONVERT(XmNlabelString, var_value), NULL); 
    854879    } 
    855880    else { 
     
    867892}; 
    868893 
    869 void AW_window::update_toggle(int *wgt, const char *var, AW_CL cd_toggle_data) 
    870 { 
     894void AW_window::update_toggle(Widget widget, const char *var, AW_CL cd_toggle_data) { 
    871895    aw_toggle_data *tdata = (aw_toggle_data*)cd_toggle_data; 
    872896    const char     *text  = tdata->bitmapOrText[(var[0] == '0' || var[0] == 'n') ? 0 : 1]; 
    873897 
    874898    if (tdata->isTextToggle) { 
    875         XtVaSetValues((Widget)wgt, RES_CONVERT(XmNlabelString, text), NULL); 
     899        XtVaSetValues(widget, RES_CONVERT(XmNlabelString, text), NULL); 
    876900    } 
    877901    else { 
    878902        char *path = pixmapPath(text+1); 
    879         XtVaSetValues((Widget)wgt, RES_CONVERT(XmNlabelPixmap, path), NULL); 
     903        XtVaSetValues(widget, RES_CONVERT(XmNlabelPixmap, path), NULL); 
    880904        free(path); 
    881905    } 
     
    913937        char *var_value = vs->read_as_string(); 
    914938 
    915         this->update_toggle((int*)p_w->toggle_field, var_value, (AW_CL)tdata); 
     939        this->update_toggle(p_w->toggle_field, var_value, (AW_CL)tdata); 
    916940        free(var_value); 
    917941    } 
     
    924948                  (XtPointer) vus); 
    925949 
    926     AW_INSERT_BUTTON_IN_AWAR_LIST(vs, (AW_CL)tdata, p_w->toggle_field, AW_WIDGET_TOGGLE, this); 
     950    vs->tie_widget((AW_CL)tdata, p_w->toggle_field, AW_WIDGET_TOGGLE, this); 
    927951} 
    928952 
     
    10601084                  (XtPointer) root); 
    10611085 
    1062     AW_INSERT_BUTTON_IN_AWAR_LIST(vs, 0, textField, AW_WIDGET_INPUT_FIELD, this); 
     1086    vs->tie_widget(0, textField, AW_WIDGET_INPUT_FIELD, this); 
    10631087    root->make_sensitive(textField, _at->widget_mask); 
    10641088 
     
    10881112} 
    10891113 
    1090  
    1091 void AW_window::update_input_field(int *widget, const char *var_value) { 
    1092     Widget w = (Widget) widget; 
    1093  
    1094     XtVaSetValues(w, XmNvalue, var_value, NULL); 
    1095 } 
    1096  
    1097  
    1098  
     1114void AW_window::update_input_field(Widget widget, const char *var_value) { 
     1115    XtVaSetValues(widget, XmNvalue, var_value, NULL); 
     1116} 
    10991117 
    11001118void AW_window::create_text_field(const char *var_name, int columns, int rows) { 
     
    12241242    XtAddCallback(scrolledText, XmNvalueChangedCallback, (XtCallbackProc) AW_value_changed_callback, (XtPointer) root); 
    12251243 
    1226     AW_INSERT_BUTTON_IN_AWAR_LIST(vs, 0, scrolledText, AW_WIDGET_TEXT_FIELD, this); 
     1244    vs->tie_widget(0, scrolledText, AW_WIDGET_TEXT_FIELD, this); 
    12271245    root->make_sensitive(scrolledText, _at->widget_mask); 
    12281246 
     
    12321250 
    12331251 
    1234 void AW_window::update_text_field(int *widget, const char *var_value) { 
    1235     Widget w = (Widget) widget; 
    1236  
    1237     XtVaSetValues(w, XmNvalue, var_value, NULL); 
     1252void AW_window::update_text_field(Widget widget, const char *var_value) { 
     1253    XtVaSetValues(widget, XmNvalue, var_value, NULL); 
    12381254} 
    12391255 
     
    13991415                          (XtPointer) _d_callback); 
    14001416        } 
    1401         AW_INSERT_BUTTON_IN_AWAR_LIST(vs, (AW_CL)p_global->last_selection_list, scrolledList, AW_WIDGET_SELECTION_LIST, this); 
     1417        vs->tie_widget((AW_CL)p_global->last_selection_list, scrolledList, AW_WIDGET_SELECTION_LIST, this); 
    14021418        root->make_sensitive(scrolledList, _at->widget_mask); 
    14031419    } 
     
    22092225    p_global->current_option_menu = p_global->last_option_menu; 
    22102226 
    2211     AW_INSERT_BUTTON_IN_AWAR_LIST(vs, (AW_CL)p_global->current_option_menu, optionMenu, AW_WIDGET_CHOICE_MENU, this); 
     2227    vs->tie_widget((AW_CL)p_global->current_option_menu, optionMenu, AW_WIDGET_CHOICE_MENU, this); 
    22122228    root->make_sensitive(optionMenu1, _at->widget_mask); 
    22132229 
     
    22162232 
    22172233static void remove_option_from_option_menu(AW_root *aw_root, AW_option_struct *os) { 
    2218     AW_remove_button_from_sens_list(aw_root, os->choice_widget); 
     2234    aw_root->remove_button_from_sens_list(os->choice_widget); 
    22192235    XtDestroyWidget(os->choice_widget); 
    22202236} 
     
    23522368 
    23532369void AW_window::update_option_menu(AW_option_menu_struct *oms) { 
    2354     if (get_root()->changer_of_variable != (long)oms->label_widget) { 
     2370    if (get_root()->changer_of_variable != oms->label_widget) { 
    23552371        AW_option_struct *active_choice = oms->first_choice; 
    23562372        { 
     
    25182534    } 
    25192535 
    2520     AW_INSERT_BUTTON_IN_AWAR_LIST(vs, get_root()->number_of_toggle_fields, toggle_field, AW_WIDGET_TOGGLE_FIELD, this); 
     2536    vs->tie_widget(get_root()->number_of_toggle_fields, toggle_field, AW_WIDGET_TOGGLE_FIELD, this); 
    25212537    root->make_sensitive(toggle_field, _at->widget_mask); 
    25222538} 
  • trunk/WINDOW/AW_nawar.cxx

    r6666 r6675  
    3030    value_changed_cb_cd2 = cd2; 
    3131    next                 = nexti; 
     32} 
     33AW_var_callback::~AW_var_callback() { 
     34    delete next; 
    3235} 
    3336 
     
    244247 
    245248void AW_awar::remove_all_callbacks() { 
    246     while (callback_list) { 
    247         AW_var_callback *del = callback_list; 
    248         callback_list        = del->next; 
    249         delete del; 
    250     } 
     249    delete callback_list; callback_list = NULL; 
    251250} 
    252251 
     
    629628 
    630629AW_awar::~AW_awar() { 
    631     remove_all_target_vars(); 
    632630    unlink(); 
     631    untie_all_widgets(); 
    633632    free(awar_name); 
    634633} 
  • trunk/WINDOW/AW_window.cxx

    r6674 r6675  
    1111#include "aw_commn.hxx" 
    1212#include "aw_at.hxx" 
    13 #include "aw_awar.hxx" 
     13#include "aw_nawar.hxx" 
    1414#include "aw_xfig.hxx" 
    1515#include "aw_Xm.hxx" 
     
    8484 
    8585    if (mask != AWM_ALL) { // no need to make widget sensitive, if its shown unconditionally 
    86         prvt->button_list = new AW_buttons_struct(mask, w, prvt->button_list); 
     86        button_sens_list = new AW_buttons_struct(mask, w, button_sens_list); 
    8787        if (!(mask & global_mask)) XtSetSensitive(w, False); // disable widget if mask doesn't match 
    8888    } 
     
    9999 
    100100AW_buttons_struct::~AW_buttons_struct() { 
    101     aw_assert(next == 0); // has to be removed from global list before calling dtor 
    102 } 
    103  
    104 bool AW_remove_button_from_sens_list(AW_root *root, Widget w) { 
     101    delete next; 
     102} 
     103 
     104bool AW_root::remove_button_from_sens_list(Widget button) { 
    105105    bool removed = false; 
    106     if (p_global->button_list) { 
     106    if (button_sens_list) { 
    107107        AW_buttons_struct *prev = 0; 
    108         AW_buttons_struct *bl   = p_global->button_list; 
     108        AW_buttons_struct *bl   = button_sens_list; 
    109109 
    110110        while (bl) { 
    111             if (bl->button == w) break; // found wanted widget 
     111            if (bl->button == button) break; // found wanted widget 
    112112            prev = bl; 
    113113            bl = bl->next; 
     
    116116        if (bl) { 
    117117            // remove from list 
    118             if (prev) prev->next       = bl->next; 
    119             else p_global->button_list = bl->next; 
     118            if (prev) prev->next  = bl->next; 
     119            else button_sens_list = bl->next; 
    120120 
    121121            bl->next = 0; 
     
    129129 
    130130AW_option_struct::AW_option_struct(const char *variable_valuei, 
    131         Widget choice_widgeti) : 
     131                                   Widget choice_widgeti) : 
    132132    variable_value(strdup(variable_valuei)), choice_widget(choice_widgeti), 
    133133            next(0) { 
     
    273273 
    274274AW_root::~AW_root() { 
     275    delete focus_callback_list; focus_callback_list = NULL; 
     276    delete button_sens_list;    button_sens_list    = NULL; 
     277 
    275278    exit_root(); 
    276279    exit_variables(); 
    277280    aw_assert(this == AW_root::SINGLETON); 
    278281 
    279      
    280282    delete prvt; 
    281283 
     
    14641466    p_r->fontlist = XmFontListCreate(fontstruct, XmSTRING_DEFAULT_CHARSET); 
    14651467 
    1466     p_r->button_list = 0; 
     1468    button_sens_list = 0; 
    14671469 
    14681470    p_r->last_option_menu = p_r->current_option_menu = p_r->option_menu_list = NULL; 
     
    17731775        char *var_value = is_awar->read_as_string(); 
    17741776        if (var_value) { 
    1775             aww->update_label((int*)widget, var_value); 
     1777            aww->update_label(widget, var_value); 
    17761778        } 
    17771779        else { 
    17781780            AW_ERROR("AW_label_in_awar_list:: AWAR %s not found\n", str); 
    1779             aww->update_label((int*)widget, str); 
     1781            aww->update_label(widget, str); 
    17801782        } 
    17811783        free(var_value); 
    1782         AW_INSERT_BUTTON_IN_AWAR_LIST(is_awar, 0, widget, AW_WIDGET_LABEL_FIELD, aww); 
     1784        is_awar->tie_widget(0, widget, AW_WIDGET_LABEL_FIELD, aww); 
    17831785    } 
    17841786} 
     
    26542656 
    26552657    global_mask = mask; 
    2656     for (list = p_r->button_list; list; list = list->next) { 
     2658    for (list = button_sens_list; list; list = list->next) { 
    26572659        XtSetSensitive(list->button, (list->mask & mask) ? True : False); 
    26582660    } 
  • trunk/WINDOW/Makefile

    r6582 r6675  
    9595 
    9696AW_button.o: aw_at.hxx 
    97 AW_button.o: aw_awar.hxx 
    9897AW_button.o: aw_click.hxx 
    9998AW_button.o: aw_device.hxx 
    10099AW_button.o: aw_keysym.hxx 
     100AW_button.o: aw_nawar.hxx 
    101101AW_button.o: aw_position.hxx 
    102102AW_button.o: aw_print.hxx 
     
    407407 
    408408AW_window.o: aw_at.hxx 
    409 AW_window.o: aw_awar.hxx 
    410409AW_window.o: aw_click.hxx 
    411410AW_window.o: aw_commn.hxx 
     
    413412AW_window.o: aw_global.hxx 
    414413AW_window.o: aw_keysym.hxx 
     414AW_window.o: aw_nawar.hxx 
    415415AW_window.o: aw_position.hxx 
    416416AW_window.o: aw_print.hxx 
  • trunk/WINDOW/aw_nawar.hxx

    r6381 r6675  
    1818struct AW_var_callback { 
    1919    AW_var_callback(void (*vc_cb)(AW_root*, AW_CL, AW_CL), AW_CL cd1, AW_CL cd2, AW_var_callback *next); 
     20    ~AW_var_callback(); 
    2021 
    2122    void (*value_changed_cb)(AW_root*, AW_CL, AW_CL); 
  • trunk/WINDOW/aw_root.hxx

    r6674 r6675  
    7575} AW_VARIABLE_TYPE; 
    7676 
     77 
     78typedef enum { 
     79    AW_WIDGET_INPUT_FIELD, 
     80    AW_WIDGET_TEXT_FIELD, 
     81    AW_WIDGET_LABEL_FIELD, 
     82    AW_WIDGET_CHOICE_MENU, 
     83    AW_WIDGET_TOGGLE_FIELD, 
     84    AW_WIDGET_SELECTION_LIST, 
     85    AW_WIDGET_TOGGLE 
     86} AW_widget_type; 
     87 
     88 
    7789typedef struct { 
    7890    int t, b, l, r; 
     
    168180class  AW_root_Motif; 
    169181class  AW_awar; 
     182struct AW_buttons_struct; 
    170183struct AW_var_callback; 
    171184 
     
    177190 
    178191class AW_root { 
    179     AW_default application_database; 
    180      
     192    AW_default         application_database; 
     193    AW_buttons_struct *button_sens_list; 
     194 
    181195    void init_variables(AW_default database); 
    182196    void exit_variables(); 
     
    191205    AW_root_Motif *prvt;                            // Do not use !!! 
    192206    bool           value_changed; 
    193     long           changer_of_variable; 
     207    Widget         changer_of_variable; 
    194208    int            y_correction_for_input_labels; 
    195209    AW_active      global_mask; 
     
    266280    void apply_sensitivity(AW_active mask); 
    267281    void make_sensitive(Widget w, AW_active mask); 
     282    bool remove_button_from_sens_list(Widget button); 
    268283 
    269284    GB_ERROR start_macro_recording(const char *file, const char *application_id, const char *stop_action_name); 
     
    293308struct AW_var_callback; 
    294309struct AW_var_target; 
     310struct AW_widget_refresh_cb; 
    295311 
    296312typedef void (*Awar_CB)(AW_root *, AW_CL, AW_CL); 
     
    308324    } pp; 
    309325 
    310     struct AW_var_callback *callback_list; 
    311     struct AW_var_target   *target_list; 
     326    struct AW_var_callback      *callback_list; 
     327    struct AW_var_target        *target_list; 
     328    struct AW_widget_refresh_cb *refresh_list; 
    312329 
    313330#if defined(DEBUG) 
     
    342359    AW_awar(AW_VARIABLE_TYPE var_type, const char *var_name, const char *var_value, double var_double_value, AW_default default_file, AW_root *root); 
    343360    ~AW_awar(); 
     361 
     362    void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww); 
     363    void untie_all_widgets(); 
    344364 
    345365    AW_awar *add_callback(Awar_CB2 f, AW_CL cd1, AW_CL cd2); 
  • trunk/WINDOW/aw_window.hxx

    r6584 r6675  
    242242    char *align_string(const char *string, int columns); 
    243243 
    244     void update_label(int *widget, const char *var_value); 
    245     void update_toggle(int *widget, const char *var_value, AW_CL cd); 
    246     void update_input_field(int *widget, const char *var_value); 
    247     void update_text_field(int *widget, const char *var_value); 
     244    void update_label(Widget widget, const char *var_value); 
     245    void update_toggle(Widget widget, const char *var_value, AW_CL cd); 
     246    void update_input_field(Widget widget, const char *var_value); 
     247    void update_text_field(Widget widget, const char *var_value); 
    248248 
    249249    void  create_invisible(int columns); 
  • trunk/WINDOW/aw_window_Xm.hxx

    r6666 r6675  
    1616#define  p_global   (root->prvt) 
    1717#define  p_aww(aww) (aww->p_w) 
    18  
    19 bool AW_remove_button_from_sens_list(AW_root *aw_root, Widget w); 
    2018 
    2119#define MAP_ARAM(ar) p_w->areas[ar] 
     
    234232    XmFontList fontlist; 
    235233 
    236     AW_buttons_struct *button_list; 
    237  
    238234    AW_option_menu_struct *option_menu_list; 
    239235    AW_option_menu_struct *last_option_menu;