source: branches/profile/SL/ITEMS/item_sel_list.cxx

Last change on this file was 12417, checked in by westram, 10 years ago
  • mark uses of select-callbacks (see #559)
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1// ==================================================================== //
2//                                                                      //
3//   File      : item_sel_list.cxx                                      //
4//   Purpose   : selection lists for items (ItemSelector)               //
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 "item_sel_list.h"
15
16#include <arbdbt.h>
17#include <arb_global_defs.h>
18
19#if defined(ARB_MOTIF)
20static AW_window *existing_window_creator(AW_root*, AW_window *aw_existing) {
21    return aw_existing;
22}
23#endif
24
25Itemfield_Selection::Itemfield_Selection(AW_selection_list *sellist_,
26                                         GBDATA            *gb_key_data,
27                                         long               type_filter_,
28                                         SelectedFields     field_filter_,
29                                         ItemSelector&      selector_)
30    : AW_DB_selection(sellist_, gb_key_data)
31    , type_filter(type_filter_)
32    , field_filter(field_filter_)
33    , selector(selector_)
34{
35    it_assert(&selector);
36}
37
38void Itemfield_Selection::fill() {
39    if (field_filter & SF_PSEUDO) {
40#if defined(ARB_GTK)
41        insert_default(PSEUDO_FIELD_ANY_FIELD, PSEUDO_FIELD_ANY_FIELD);
42#else // ARB_MOTIF
43        insert(PSEUDO_FIELD_ANY_FIELD, PSEUDO_FIELD_ANY_FIELD);
44#endif
45        insert(PSEUDO_FIELD_ALL_FIELDS, PSEUDO_FIELD_ALL_FIELDS);
46    }
47
48    GBDATA         *gb_key_data = get_gbd();
49    GB_transaction  ta(gb_key_data);
50
51    for (GBDATA *gb_key = GB_entry(gb_key_data, CHANGEKEY); gb_key; gb_key = GB_nextEntry(gb_key)) {
52        GBDATA *gb_key_type = GB_entry(gb_key, CHANGEKEY_TYPE);
53
54        if (shall_display_type(GB_read_int(gb_key_type))) {
55            GBDATA *gb_key_name = GB_entry(gb_key, CHANGEKEY_NAME);
56
57            if (gb_key_name) {
58                const char *name = GB_read_char_pntr(gb_key_name);
59                if (!name) {
60                    fprintf(stderr, "WARNING: can't read key name (Reason: %s)", GB_await_error());
61                    name = "<unnamedKey?>";
62                }
63
64                long       *hiddenPtr = GBT_read_int(gb_key, CHANGEKEY_HIDDEN);
65                const char *display   = 0;
66
67                if (!hiddenPtr) {               // it's an older db version w/o hidden flag -> add it
68                    GB_ERROR error = GBT_write_int(gb_key, CHANGEKEY_HIDDEN, 0); // default is "not hidden"
69                    if (error) GB_warningf("WARNING: can't create " CHANGEKEY_HIDDEN " (Reason: %s)\n", error);
70
71                    static long not_hidden = 0;
72                    hiddenPtr              = &not_hidden;
73                }
74
75                if (*hiddenPtr) {               // hidden ?
76                    if (field_filter & SF_HIDDEN) { // show hidden fields ?
77                        display = GBS_global_string("[hidden] %s", name);
78                    }
79                }
80                else display = name;
81
82                if (display) insert(display, name);
83            }
84        }
85    }
86
87    if (!get_sellist()->get_default_value()) {
88        insert_default("<no field>", NO_FIELD_SELECTED);
89    }
90}
91
92
93Itemfield_Selection *create_selection_list_on_itemfields(GBDATA         *gb_main,
94                                                         AW_window      *aws,
95                                                         const char     *varname,
96                                                         bool            fallback2default,
97                                                         long            type_filter,
98                                                         const char     *scan_xfig_label,
99                                                         const char     *rescan_xfig_label,
100                                                         ItemSelector&   selector,
101                                                         size_t          columns,
102                                                         size_t          visible_rows,
103                                                         SelectedFields  field_filter,
104                                                         const char     *popup_button_id) // @@@ button id is not needed - only causes xtra macro command
105{
106    /* show fields of a item (e.g. species, SAI, gene)
107     * 'varname'                is the awar set by the selection list
108     * 'fallback2default'       whether awar value shall be reset to default (see create_option_menu/create_selection_list)
109     * 'type_filter'            is a bitstring which controls what types are shown in the selection list
110     *                          (e.g '1<<GB_INT || 1 <<GB_STRING' enables ints and strings)
111     * 'scan_xfig_label'        is the position of the selection box (or selection button)
112     * 'rescan_xfig_label'      if not NULL, a 'RESCAN' button is added at that position
113     * 'selector'               describes the item type, for which fields are shown
114     * 'columns'/'visible_rows' specify the size of the selection list
115     * 'field_filter'           controls if pseudo-fields and/or hidden fields are added
116     * 'popup_button_id'        if not NULL, a button (with this id) is inserted.
117     *                          When clicked a popup window containing the selection list opens.
118     */
119
120    GBDATA *gb_key_data;
121    {
122        GB_transaction ta(gb_main);
123        gb_key_data = GB_search(gb_main, selector.change_key_path, GB_CREATE_CONTAINER);
124    }
125
126    AW_selection_list *sellist = 0;
127
128    if (scan_xfig_label) aws->at(scan_xfig_label);
129
130    if (popup_button_id) {
131#ifdef ARB_GTK
132        aws->button_length(columns);
133        sellist = aws->create_option_menu(varname, fallback2default);
134#else // ARB_MOTIF
135        // create HIDDEN popup window containing the selection list
136        AW_window *win_for_sellist = aws;
137        {
138            AW_window_simple *aw_popup = new AW_window_simple;
139            aw_popup->init(aws->get_root(), "SELECT_LIST_ENTRY", "SELECT AN ENTRY");
140
141            aw_popup->auto_space(10, 10);
142            aw_popup->at_newline();
143
144            aw_popup->callback((AW_CB0)AW_POPDOWN); // @@@ used as SELLIST_CLICK_CB (see #559)
145            sellist = aw_popup->create_selection_list(varname, columns, visible_rows, fallback2default);
146
147            aw_popup->at_newline();
148            aw_popup->callback((AW_CB0)AW_POPDOWN);
149            aw_popup->create_button("CLOSE", "CLOSE", "C");
150
151            aw_popup->window_fit();
152            aw_popup->recalc_pos_atShow(AW_REPOS_TO_MOUSE);
153
154            win_for_sellist = aw_popup;
155        }
156
157        // and bind hidden window popup to button
158        aws->button_length(columns);
159        aws->callback(makeCreateWindowCallback(existing_window_creator, win_for_sellist)); 
160        aws->create_button(popup_button_id, varname);
161#endif
162
163    }
164    else { // otherwise just insert the selection list at point
165        sellist = aws->create_selection_list(varname, columns, visible_rows, fallback2default);
166    }
167
168    if (rescan_xfig_label) {
169        int x, y;
170        aws->get_at_position(&x, &y);
171
172        aws->at(rescan_xfig_label);
173        aws->callback(makeWindowCallback(selector.selection_list_rescan_cb, gb_main, FIELD_UNFILTERED));
174        aws->create_button(rescan_xfig_label, "RESCAN", "R");
175
176        if (popup_button_id) aws->at(x, y); // restore 'at' position if popup_list_in_window
177    }
178
179    Itemfield_Selection *selection = new Itemfield_Selection(sellist, gb_key_data, type_filter, field_filter, selector);
180    selection->refresh();
181
182#ifdef ARB_GTK
183    if(popup_button_id) {
184        aws->update_option_menu();
185    }
186#endif
187    return selection;
188}
189
Note: See TracBrowser for help on using the repository browser.