1 | // ================================================================ // |
---|
2 | // // |
---|
3 | // File : AW_select.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in February 2010 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ================================================================ // |
---|
11 | |
---|
12 | #include "aw_select.hxx" |
---|
13 | #include "aw_window_Xm.hxx" |
---|
14 | #include "aw_root.hxx" |
---|
15 | #include "aw_awar.hxx" |
---|
16 | |
---|
17 | #include <Xm/List.h> |
---|
18 | |
---|
19 | // -------------------------- |
---|
20 | // AW_selection_list |
---|
21 | |
---|
22 | void AW_selection_list::selectAll() { |
---|
23 | int i; |
---|
24 | AW_selection_list_entry *lt; |
---|
25 | for (i=0, lt = list_table; lt; i++, lt = lt->next) { |
---|
26 | XmListSelectPos(select_list_widget, i, False); |
---|
27 | } |
---|
28 | if (default_select) { |
---|
29 | XmListSelectPos(select_list_widget, i, False); |
---|
30 | } |
---|
31 | } |
---|
32 | |
---|
33 | void AW_selection_list::deselectAll() { |
---|
34 | XmListDeselectAllItems(select_list_widget); |
---|
35 | } |
---|
36 | |
---|
37 | const char *AW_selection_list::get_selected_value() const { // @@@ refactor |
---|
38 | int i; |
---|
39 | AW_selection_list_entry *lt; |
---|
40 | AW_selection_list_entry *found = 0; |
---|
41 | |
---|
42 | for (i=1, lt = list_table; lt; i++, lt = lt->next) { |
---|
43 | lt->is_selected = XmListPosSelected(select_list_widget, i); |
---|
44 | if (lt->is_selected && !found) found = lt; |
---|
45 | } |
---|
46 | |
---|
47 | if (default_select) { |
---|
48 | default_select->is_selected = XmListPosSelected(select_list_widget, i); |
---|
49 | if (default_select->is_selected && !found) found = default_select; |
---|
50 | } |
---|
51 | return found ? found->value.get_string() : NULL; |
---|
52 | } |
---|
53 | |
---|
54 | const char *AW_selection_list::get_awar_value() const { |
---|
55 | return AW_root::SINGLETON->awar(variable_name)->read_char_pntr(); |
---|
56 | } |
---|
57 | |
---|
58 | void AW_selection_list::set_awar_value(const char *new_value) { |
---|
59 | AW_root::SINGLETON->awar(variable_name)->write_string(new_value); |
---|
60 | } |
---|
61 | |
---|
62 | const char *AW_selection_list::get_default_value() const { |
---|
63 | return default_select ? default_select->value.get_string() : NULL; |
---|
64 | } |
---|
65 | const char *AW_selection_list::get_default_display() const { |
---|
66 | return default_select ? default_select->get_displayed() : NULL; |
---|
67 | } |
---|
68 | |
---|
69 | |
---|
70 | size_t AW_selection_list::size() { |
---|
71 | AW_selection_list_entry *lt = list_table; |
---|
72 | size_t count = 0; |
---|
73 | |
---|
74 | while (lt) { |
---|
75 | ++count; |
---|
76 | lt = lt->next; |
---|
77 | } |
---|
78 | return count; |
---|
79 | } |
---|
80 | |
---|
81 | bool AW_selection_list::default_is_selected() const { |
---|
82 | return strcmp(get_selected_value(), get_default_value()) == 0; |
---|
83 | } |
---|
84 | |
---|
85 | // --------------------- |
---|
86 | // AW_selection |
---|
87 | |
---|
88 | void AW_selection::refresh() { |
---|
89 | get_sellist()->clear(); |
---|
90 | fill(); |
---|
91 | get_sellist()->update(); |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | // ------------------------- |
---|
96 | // AW_DB_selection |
---|
97 | |
---|
98 | static void AW_DB_selection_refresh_cb(GBDATA *, int *cl_selection, GB_CB_TYPE) { |
---|
99 | AW_DB_selection *selection = (AW_DB_selection*)cl_selection;; |
---|
100 | selection->refresh(); |
---|
101 | } |
---|
102 | |
---|
103 | AW_DB_selection::AW_DB_selection(AW_selection_list *sellist_, GBDATA *gbd_) |
---|
104 | : AW_selection(sellist_) |
---|
105 | , gbd(gbd_) |
---|
106 | { |
---|
107 | GB_transaction ta(gbd); |
---|
108 | GB_add_callback(gbd, GB_CB_CHANGED, AW_DB_selection_refresh_cb, (int*)this); |
---|
109 | } |
---|
110 | |
---|
111 | AW_DB_selection::~AW_DB_selection() { |
---|
112 | GB_transaction ta(gbd); |
---|
113 | GB_remove_callback(gbd, GB_CB_CHANGED, AW_DB_selection_refresh_cb, (int*)this); |
---|
114 | } |
---|
115 | |
---|