source: tags/old_import_filter/WINDOW/aw_select.hxx

Last change on this file was 8764, checked in by westram, 12 years ago
  • renamed refresh-functions for option_menu, toggle_field and selection_list
File size: 6.6 KB
Line 
1// ================================================================ //
2//                                                                  //
3//   File      : aw_select.hxx                                      //
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#ifndef AW_SELECT_HXX
13#define AW_SELECT_HXX
14
15#ifndef AW_WINDOW_HXX
16#include <aw_window.hxx>
17#endif
18#ifndef ARBDB_H
19#include <arbdb.h>
20#endif
21#ifndef AW_SCALAR_HXX
22#include "aw_scalar.hxx"
23#endif
24
25// cppcheck-suppress noConstructor
26class AW_selection_list_entry : virtual Noncopyable {
27    char      *displayed;
28
29public:
30    // @@@ make members private
31    AW_scalar  value;
32    bool is_selected;                                // internal use only
33    AW_selection_list_entry *next;
34
35    template<typename T>
36    AW_selection_list_entry(const char *display, T val)
37        : displayed(copy_string_for_display(display)),
38          value(val),
39          is_selected(false),
40          next(NULL)
41    {}
42    ~AW_selection_list_entry() { free(displayed); }
43
44    static char *copy_string_for_display(const char *str);
45
46    template<typename T>
47    void set_value(T val) { value = AW_scalar(val); }
48
49    const char *get_displayed() const { return displayed; }
50    void set_displayed(const char *displayed_) { freeset(displayed, copy_string_for_display(displayed_)); }
51};
52
53class AW_selection_list {
54    AW_selection_list_entry *get_entry_at(int index);
55   
56public:
57    AW_selection_list(const char *variable_namei, int variable_typei, Widget select_list_widgeti);
58
59    char             *variable_name;
60    AW_VARIABLE_TYPE  variable_type;
61    Widget            select_list_widget;
62
63    AW_selection_list_entry *list_table;
64    AW_selection_list_entry *last_of_list_table;
65    AW_selection_list_entry *default_select;
66    AW_selection_list      *next;
67
68    // ******************** real public ***************
69   
70    void selectAll();
71    void deselectAll();
72
73    size_t size();
74
75    void insert(const char *displayed, const char *value);
76    void insert_default(const char *displayed, const char *value);
77    void insert(const char *displayed, int32_t value);
78    void insert_default(const char *displayed, int32_t value);
79    void insert(const char *displayed, GBDATA *pointer);
80    void insert_default(const char *displayed, GBDATA *pointer);
81
82    void init_from_array(const CharPtrArray& entries, const char *defaultEntry);
83   
84    void update();
85    void refresh(); 
86
87    void sort(bool backward, bool case_sensitive); // uses displayed value!
88   
89    // ---------------------------------------------------
90    // the following functions work for string awars only:
91
92    const char *get_awar_value() const;
93    void set_awar_value(const char *new_value);
94
95    const char *get_default_value() const;
96    const char *get_default_display() const;
97
98    void select_default() { set_awar_value(get_default_value()); }
99
100    const char *get_selected_value() const; // may differ from get_awar_value() if default is selected (returns value passed to insert_default_selection)
101
102    int get_index_of(const char *searched_value);
103    int get_index_of_displayed(const char *displayed);
104    int get_index_of_selected();
105
106    const char *get_value_at(int index);
107
108    void select_element_at(int wanted_index);
109    void move_selection(int offset);
110
111    bool default_is_selected() const;
112
113    void delete_element_at(int index);
114    void delete_value(const char *value);
115    void clear(bool clear_default = true); 
116
117    void move_content_to(AW_selection_list *target_list);
118
119    void to_array(StrArray& array, bool values);
120    GB_HASH *to_hash(bool case_sens);
121    char *get_content_as_string(long number_of_lines); // displayed content (e.g. for printing)
122
123    // save/load:
124    void set_file_suffix(const char *suffix);
125    GB_ERROR load(const char *filename);
126    GB_ERROR save(const char *filename, long number_of_lines);
127};
128
129class AW_selection_list_iterator {
130    AW_selection_list_entry *entry;
131public:
132    AW_selection_list_iterator(AW_selection_list *sellist)
133        : entry(sellist->list_table)
134    {}
135    AW_selection_list_iterator(AW_selection_list *sellist, int index)
136        : entry(sellist->list_table)
137    {
138        forward(index);
139    }
140
141    operator bool() const { return entry; }
142
143    const char *get_displayed() { return entry ? entry->get_displayed() : NULL; }
144    const char *get_value() { return entry ? entry->value.get_string() : NULL; }
145
146    void set_displayed(const char *disp) { aw_assert(entry); entry->set_displayed(disp); }
147    void set_value(const char *val) { aw_assert(entry); entry->set_value(val); }
148
149    void forward(size_t offset) {
150        while (offset--) ++(*this);
151    }
152    AW_selection_list_iterator& operator++() {
153        if (entry) entry = entry->next;
154        return *this;
155    }
156};
157
158class AW_selection : virtual Noncopyable {
159    //! a AW_selection_list which knows how to fill itself
160    // (clients can't modify)
161
162    AW_selection_list *sellist;
163
164    virtual void fill() = 0;
165
166protected: 
167    void insert(const char *displayed, const char *value) { sellist->insert(displayed, value); }
168    void insert_default(const char *displayed, const char *value) { sellist->insert_default(displayed, value); }
169
170    void insert(const char *displayed, int32_t value) { sellist->insert(displayed, value); }
171    void insert_default(const char *displayed, int32_t value) { sellist->insert_default(displayed, value); }
172
173public:
174    AW_selection(AW_selection_list *sellist_) : sellist(sellist_) {}
175    virtual ~AW_selection() {}
176
177    void refresh();
178    AW_selection_list *get_sellist() { return sellist; }
179   
180    void get_values(StrArray& intoArray) { get_sellist()->to_array(intoArray, true); }
181    void get_displayed(StrArray& intoArray) { get_sellist()->to_array(intoArray, false); }
182};
183
184
185class AW_DB_selection : public AW_selection { // derived from a Noncopyable
186    GBDATA *gbd;                                    // root container of data displayed in selection list
187public:
188    AW_DB_selection(AW_selection_list *sellist_, GBDATA *gbd_);
189    virtual ~AW_DB_selection();
190   
191    GBDATA *get_gbd() { return gbd; }
192    GBDATA *get_gb_main() { return GB_get_root(gbd); }
193};
194void AW_DB_selection_refresh_cb(GBDATA *, AW_DB_selection *);
195
196
197#else
198#error aw_select.hxx included twice
199#endif // AW_SELECT_HXX
Note: See TracBrowser for help on using the repository browser.