source: tags/ms_r16q2/SL/ITEMS/items.h

Last change on this file was 14995, checked in by westram, 8 years ago
  • add a few convenience functions to MutableBoundItemSel
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1// ============================================================ //
2//                                                              //
3//   File      : items.h                                        //
4//   Purpose   :                                                //
5//                                                              //
6//   Institute of Microbiology (Technical University Munich)    //
7//   http://www.arb-home.de/                                    //
8//                                                              //
9// ============================================================ //
10
11#ifndef ITEMS_H
12#define ITEMS_H
13
14#ifndef CB_H
15#include <cb.h>
16#endif
17#ifndef ARBDB_BASE_H
18#include <arbdb_base.h>
19#endif
20#ifndef ARB_ASSERT_H
21#include <arb_assert.h>
22#endif
23
24
25#define it_assert(cond) arb_assert(cond)
26
27enum QUERY_ITEM_TYPE {
28    QUERY_ITEM_SPECIES,
29    QUERY_ITEM_GENES,
30    QUERY_ITEM_EXPERIMENTS,
31
32    QUERY_ITEM_TYPES // how many different types do we have
33};
34
35enum QUERY_RANGE {
36    QUERY_CURRENT_ITEM,
37    QUERY_MARKED_ITEMS,
38    QUERY_ALL_ITEMS
39};
40
41struct                            MutableItemSelector;
42typedef const MutableItemSelector ItemSelector;
43
44struct MutableItemSelector { // @@@ remove AW_root arguments!
45    QUERY_ITEM_TYPE type;
46
47    // if user selects an item in the result list,
48    // this callback sets the appropriate AWARs
49    // - for species: AWAR_SPECIES_NAME is changed (item_name = 'species_name')
50    // - for genes: AWAR_GENE_NAME and AWAR_SPECIES_NAME are changed (item_name = 'species_name/gene_name')
51
52    void (*update_item_awars)(GBDATA* gb_main, AW_root *aw_root, const char *item_name);
53    char *(*generate_item_id)(GBDATA *gb_main, GBDATA *gb_item); // @@@ remove parameter 'gb_main'
54    GBDATA *(*find_item_by_id)(GBDATA *gb_main, const char *id);
55    void (*selection_list_rescan_cb)(AW_window*, GBDATA *gb_main);
56
57    int item_name_length; // -1 means "unknown" (might be long)
58
59    const char *change_key_path;
60    const char *item_name;                          // "species" or "gene" or "experiment" or "organism"
61    const char *items_name;                         // "species" or "genes" or "experiments" or "organisms"
62    const char *id_field;                           // e.g. "name" for species, genes
63
64    GBDATA *(*get_first_item_container)(GBDATA *, AW_root *, QUERY_RANGE); // AW_root may be NULL for QUERY_ALL_ITEMS and QUERY_MARKED_ITEMS
65    GBDATA *(*get_next_item_container)(GBDATA *, QUERY_RANGE);             // use same QUERY_RANGE as in get_first_item_container()
66
67    GBDATA *(*get_first_item)(GBDATA *, QUERY_RANGE);
68    GBDATA *(*get_next_item)(GBDATA *, QUERY_RANGE);
69
70    GBDATA *(*get_selected_item)(GBDATA *gb_main, AW_root *aw_root); // searches the currently selected item
71    void (*add_selection_changed_cb)(AW_root *aw_root, const RootCallback& cb); // gets called when selected item changes
72
73    ItemSelector *parent_selector;              // selector of parent item (or NULL if item has no parents)
74    GBDATA *(*get_parent)(GBDATA *gb_item);     // if 'parent_selector' is defined, this function returns the parent of the item
75
76    void (*trigger_display_refresh)(); // shall be called when displays shall be refreshed (e.g. tree-display for species)
77};
78
79struct MutableBoundItemSel {
80    GBDATA        *gb_main;
81    ItemSelector&  selector;
82
83    MutableBoundItemSel(GBDATA *gb_main_, ItemSelector& selector_)
84        : gb_main(gb_main_),
85          selector(selector_)
86    {
87        it_assert(gb_main);
88        it_assert(&selector);
89    }
90
91    GBDATA *get_any_item() const;
92
93    GBDATA *get_first_item_container(AW_root *awr, QUERY_RANGE range) const { return selector.get_first_item_container(gb_main, awr, range); }
94    GBDATA *get_next_item_container(GBDATA *gb_cont, QUERY_RANGE range) const { return selector.get_next_item_container(gb_cont, range); }
95
96    GBDATA *get_first_item(GBDATA *gb_cont, QUERY_RANGE range) const { return selector.get_first_item(gb_cont, range); }
97    GBDATA *get_next_item(GBDATA *gb_item, QUERY_RANGE range) const { return selector.get_next_item(gb_item, range); }
98};
99
100typedef const MutableBoundItemSel BoundItemSel;
101
102void init_itemType_specific_window(AW_root *aw_root, class AW_window_simple *aws, const ItemSelector& itemType, const char *id, const char *title_format, bool plural = false);
103
104ItemSelector& SPECIES_get_selector();
105ItemSelector& ORGANISM_get_selector();
106
107#else
108#error items.h included twice
109#endif // ITEMS_H
Note: See TracBrowser for help on using the repository browser.