root/branches/stable_5.0/AWT/AWT_item_sel_list.cxx

Revision 6154, 7.5 KB (checked in by westram, 3 years ago)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1// ==================================================================== //
2//                                                                      //
3//   File      : AWT_item_sel_list.cxx                                  //
4//   Purpose   : selection lists for items (ad_item_selector)           //
5//                                                                      //
6//                                                                      //
7// Coded by Ralf Westram (coder@reallysoft.de) in May 2005              //
8// Copyright Department of Microbiology (Technical University Munich)   //
9//                                                                      //
10// Visit our web site at: http://www.arb-home.de/                       //
11//                                                                      //
12// ==================================================================== //
13
14#include <string.h>
15
16#include <aw_awars.hxx>
17
18#include "awt.hxx"
19#include "awtlocal.hxx"
20#include "awt_item_sel_list.hxx"
21
22#include <arbdbt.h>
23
24static AW_window *awt_existing_window(AW_window *, AW_CL cl1, AW_CL) {
25    return (AW_window*)cl1;
26}
27
28static void populate_selection_list_on_scandb_cb(GBDATA *dummy, struct adawcbstruct *cbs)
29{
30    GBDATA *gb_key_data;
31    gb_key_data = GB_search(cbs->gb_main, cbs->selector->change_key_path, GB_CREATE_CONTAINER);
32    AWUSE(dummy);
33
34    cbs->aws->clear_selection_list(cbs->id);
35
36    if (cbs->add_pseudo_fields) {
37        cbs->aws->insert_selection(cbs->id, PSEUDO_FIELD_ANY_FIELD, PSEUDO_FIELD_ANY_FIELD);
38        cbs->aws->insert_selection(cbs->id, PSEUDO_FIELD_ALL_FIELDS, PSEUDO_FIELD_ALL_FIELDS);
39    }
40
41    for (GBDATA *gb_key = GB_entry(gb_key_data,CHANGEKEY); gb_key; gb_key = GB_nextEntry(gb_key)) {
42        GBDATA *gb_key_type = GB_entry(gb_key,CHANGEKEY_TYPE);
43        if ( !( ((long)cbs->def_filter) & (1<<GB_read_int(gb_key_type)))) continue; // type does not match filter
44
45        GBDATA *gb_key_name = GB_entry(gb_key,CHANGEKEY_NAME);
46        if (!gb_key_name) continue;                 // key w/o name -> don't show
47
48        const char *name = GB_read_char_pntr(gb_key_name);
49        if (!name) {
50            fprintf(stderr, "WARNING: can't read key name (Reason: %s)", GB_await_error());
51            name = "<unnamedKey?>";
52        }
53
54        long       *hiddenPtr = GBT_read_int(gb_key, CHANGEKEY_HIDDEN);
55        const char *display   = 0;
56
57        if (!hiddenPtr) {                           // it's an older db version w/o hidden flag -> add it
58            GB_ERROR error = GBT_write_int(gb_key, CHANGEKEY_HIDDEN, 0); // default is "not hidden"
59            if (error) {
60                GB_warningf("WARNING: can't create " CHANGEKEY_HIDDEN " (Reason: %s)\n", error);
61            }
62
63            static long not_hidden = 0;;
64            hiddenPtr              = &not_hidden;
65        }
66
67        if (*hiddenPtr) { // hidden ?
68            if (cbs->include_hidden_fields) {       // show hidden fields ?
69                display = GBS_global_string("[hidden] %s", name);
70            }
71        }
72        else display = name;
73
74        if (display) cbs->aws->insert_selection(cbs->id, display, name);
75    }
76
77    cbs->aws->insert_default_selection( cbs->id, "????", "----" );
78    cbs->aws->update_selection_list( cbs->id );
79}
80
81
82AW_CL awt_create_selection_list_on_scandb(GBDATA                 *gb_main,
83                                          AW_window              *aws,
84                                          const char             *varname,
85                                          long                    type_filter,
86                                          const char             *scan_xfig_label,
87                                          const char             *rescan_xfig_label,
88                                          const ad_item_selector *selector,
89                                          size_t                  columns,
90                                          size_t                  visible_rows,
91                                          awt_selected_fields     field_filter,
92                                          const char             *popup_button_id)
93{
94    /* show fields of a item (e.g. species, SAI, gene)
95     * 'varname'                is the awar set by the selection list
96     * 'type_filter'            is a bitstring which controls what types are shown in the selection list
97     *                          (e.g '1<<GB_INT || 1 <<GB_STRING' enables ints and strings)
98     * 'scan_xfig_label'        is the position of the selection box (or selection button)
99     * 'rescan_xfig_label'      if not NULL, a 'RESCAN' button is added at that position
100     * 'selector'               describes the item type, for which fields are shown
101     * 'columns'/'visible_rows' specify the size of the selection list
102     * 'field_filter'           controls if pseudo-fields and/or hidden fields are added
103     * 'popup_button_id'        if not NULL, a button (with this id) is inserted.
104     *                          When clicked a popup window containing the selection list opens.
105     */
106
107
108    AW_selection_list *id              = 0;
109    GBDATA            *gb_key_data;
110    AW_window         *win_for_sellist = aws;
111
112    GB_push_transaction(gb_main);
113
114    if (scan_xfig_label) aws->at(scan_xfig_label);
115
116    if (popup_button_id) { 
117        // create HIDDEN popup window containing the selection list
118        {
119            AW_window_simple *aw_popup = new AW_window_simple;
120            aw_popup->init(aws->get_root(), "SELECT_LIST_ENTRY", "SELECT AN ENTRY");
121            //         aw_popup->load_xfig(0, true);
122
123            aw_popup->auto_space(10, 10);
124            aw_popup->at_newline();
125
126            aw_popup->callback((AW_CB0)AW_POPDOWN);
127            id = aw_popup->create_selection_list(varname, 0, "", columns, visible_rows);
128
129            aw_popup->at_newline();
130            aw_popup->callback((AW_CB0)AW_POPDOWN);
131            aw_popup->create_button("CLOSE", "CLOSE", "C");
132
133            aw_popup->window_fit();
134
135            win_for_sellist = aw_popup;
136        }
137
138        // and bind hidden window popup to button
139        aws->button_length(columns);
140        aws->callback((AW_CB2)AW_POPUP,(AW_CL)awt_existing_window, (AW_CL)win_for_sellist);
141        aws->create_button(popup_button_id, varname);
142
143    }
144    else { // otherwise just insert the selection list at point
145        id = aws->create_selection_list(varname,0,"",columns,visible_rows); // 20,10);
146    }
147
148    struct adawcbstruct *cbs = new adawcbstruct;
149    memset(cbs, 0, sizeof(*cbs));
150
151    cbs->aws                   = win_for_sellist;
152    cbs->awr                   = win_for_sellist->get_root();
153    cbs->gb_main               = gb_main;
154    cbs->id                    = id;
155    cbs->def_filter            = (char *)type_filter;
156    cbs->selector              = selector;
157    cbs->add_pseudo_fields     = field_filter & AWT_SF_PSEUDO;
158    cbs->include_hidden_fields = field_filter & AWT_SF_HIDDEN;
159
160    if (rescan_xfig_label) {
161        int x, y;
162        aws->get_at_position(&x, &y);
163
164        aws->at(rescan_xfig_label);
165        aws->callback(selector->selection_list_rescan_cb, (AW_CL)cbs->gb_main,(AW_CL)-1);
166        aws->create_button(rescan_xfig_label, "RESCAN","R");
167
168        if (popup_button_id) aws->at(x, y); // restore 'at' position if popup_list_in_window
169    }
170
171    populate_selection_list_on_scandb_cb(0,cbs);
172
173    gb_key_data = GB_search(gb_main, cbs->selector->change_key_path, GB_CREATE_CONTAINER);
174    GB_add_callback(gb_key_data, GB_CB_CHANGED, (GB_CB)populate_selection_list_on_scandb_cb, (int *)cbs);
175
176    GB_pop_transaction(gb_main);
177    return (AW_CL)cbs;
178}
179
180
181
182
Note: See TracBrowser for help on using the browser.