1
// ==================================================================== //
3
// File : AWT_item_sel_list.cxx //
4
// Purpose : selection lists for items (ad_item_selector) //
7
// Coded by Ralf Westram (coder@reallysoft.de) in May 2005 //
8
// Copyright Department of Microbiology (Technical University Munich) //
10
// Visit our web site at: http://www.arb-home.de/ //
12
// ==================================================================== //
16
#include <aw_awars.hxx>
19
#include "awtlocal.hxx"
20
#include "awt_item_sel_list.hxx"
24
static AW_window *awt_existing_window(AW_window *, AW_CL cl1, AW_CL) {
25
return (AW_window*)cl1;
28
static void populate_selection_list_on_scandb_cb(GBDATA *dummy, struct adawcbstruct *cbs)
31
gb_key_data = GB_search(cbs->gb_main, cbs->selector->change_key_path, GB_CREATE_CONTAINER);
34
cbs->aws->clear_selection_list(cbs->id);
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);
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
45
GBDATA *gb_key_name = GB_entry(gb_key,CHANGEKEY_NAME);
46
if (!gb_key_name) continue; // key w/o name -> don't show
48
const char *name = GB_read_char_pntr(gb_key_name);
50
fprintf(stderr, "WARNING: can't read key name (Reason: %s)", GB_await_error());
51
name = "<unnamedKey?>";
54
long *hiddenPtr = GBT_read_int(gb_key, CHANGEKEY_HIDDEN);
55
const char *display = 0;
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"
60
GB_warningf("WARNING: can't create " CHANGEKEY_HIDDEN " (Reason: %s)\n", error);
63
static long not_hidden = 0;;
64
hiddenPtr = ¬_hidden;
67
if (*hiddenPtr) { // hidden ?
68
if (cbs->include_hidden_fields) { // show hidden fields ?
69
display = GBS_global_string("[hidden] %s", name);
74
if (display) cbs->aws->insert_selection(cbs->id, display, name);
77
cbs->aws->insert_default_selection( cbs->id, "????", "----" );
78
cbs->aws->update_selection_list( cbs->id );
82
AW_CL awt_create_selection_list_on_scandb(GBDATA *gb_main,
86
const char *scan_xfig_label,
87
const char *rescan_xfig_label,
88
const ad_item_selector *selector,
91
awt_selected_fields field_filter,
92
const char *popup_button_id)
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.
108
AW_selection_list *id = 0;
110
AW_window *win_for_sellist = aws;
112
GB_push_transaction(gb_main);
114
if (scan_xfig_label) aws->at(scan_xfig_label);
116
if (popup_button_id) {
117
// create HIDDEN popup window containing the selection list
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);
123
aw_popup->auto_space(10, 10);
124
aw_popup->at_newline();
126
aw_popup->callback((AW_CB0)AW_POPDOWN);
127
id = aw_popup->create_selection_list(varname, 0, "", columns, visible_rows);
129
aw_popup->at_newline();
130
aw_popup->callback((AW_CB0)AW_POPDOWN);
131
aw_popup->create_button("CLOSE", "CLOSE", "C");
133
aw_popup->window_fit();
135
win_for_sellist = aw_popup;
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);
144
else { // otherwise just insert the selection list at point
145
id = aws->create_selection_list(varname,0,"",columns,visible_rows); // 20,10);
148
struct adawcbstruct *cbs = new adawcbstruct;
149
memset(cbs, 0, sizeof(*cbs));
151
cbs->aws = win_for_sellist;
152
cbs->awr = win_for_sellist->get_root();
153
cbs->gb_main = gb_main;
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;
160
if (rescan_xfig_label) {
162
aws->get_at_position(&x, &y);
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");
168
if (popup_button_id) aws->at(x, y); // restore 'at' position if popup_list_in_window
171
populate_selection_list_on_scandb_cb(0,cbs);
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);
176
GB_pop_transaction(gb_main);