| 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 |  | 
|---|
| 27 | enum QUERY_ITEM_TYPE { | 
|---|
| 28 | QUERY_ITEM_SPECIES, | 
|---|
| 29 | QUERY_ITEM_ORGANISM, | 
|---|
| 30 | QUERY_ITEM_GENES, | 
|---|
| 31 | QUERY_ITEM_EXPERIMENTS, | 
|---|
| 32 | QUERY_ITEM_SAI, | 
|---|
| 33 |  | 
|---|
| 34 | QUERY_ITEM_TYPES // how many different types do we have | 
|---|
| 35 | }; | 
|---|
| 36 |  | 
|---|
| 37 | inline bool speciesOrOrganism(QUERY_ITEM_TYPE type) { | 
|---|
| 38 | return type == QUERY_ITEM_SPECIES || type == QUERY_ITEM_ORGANISM; | 
|---|
| 39 | } | 
|---|
| 40 |  | 
|---|
| 41 | enum QUERY_RANGE { | 
|---|
| 42 | QUERY_CURRENT_ITEM, | 
|---|
| 43 | QUERY_MARKED_ITEMS, | 
|---|
| 44 | QUERY_ALL_ITEMS | 
|---|
| 45 | }; | 
|---|
| 46 |  | 
|---|
| 47 | struct                            MutableItemSelector; | 
|---|
| 48 | typedef const MutableItemSelector ItemSelector; | 
|---|
| 49 |  | 
|---|
| 50 | struct MutableItemSelector { // @@@ remove AW_root arguments! | 
|---|
| 51 | QUERY_ITEM_TYPE type; | 
|---|
| 52 |  | 
|---|
| 53 | // if user selects an item in the result list, | 
|---|
| 54 | // this callback sets the appropriate AWARs | 
|---|
| 55 | // - for species: AWAR_SPECIES_NAME is changed (item_name = 'species_name') | 
|---|
| 56 | // - for genes: AWAR_GENE_NAME and AWAR_SPECIES_NAME are changed (item_name = 'species_name/gene_name') | 
|---|
| 57 |  | 
|---|
| 58 | void (*update_item_awars)(GBDATA* gb_main, AW_root *aw_root, const char *item_name); | 
|---|
| 59 | char *(*generate_item_id)(GBDATA *gb_main, GBDATA *gb_item); // @@@ remove parameter 'gb_main' | 
|---|
| 60 | GBDATA *(*find_item_by_id)(GBDATA *gb_main, const char *id); | 
|---|
| 61 | void (*selection_list_rescan_cb)(AW_window*, GBDATA *gb_main); | 
|---|
| 62 |  | 
|---|
| 63 | int item_name_length; // -1 means "unknown" (might be long) | 
|---|
| 64 |  | 
|---|
| 65 | const char *change_key_path; | 
|---|
| 66 | const char *item_name;                          // "species" or "gene" or "experiment" or "organism" | 
|---|
| 67 | const char *items_name;                         // "species" or "genes" or "experiments" or "organisms" | 
|---|
| 68 | const char *id_field;                           // e.g. "name" for species, genes | 
|---|
| 69 |  | 
|---|
| 70 | GBDATA *(*get_first_item_container)(GBDATA *, AW_root *, QUERY_RANGE); // AW_root may be NULp for QUERY_ALL_ITEMS and QUERY_MARKED_ITEMS | 
|---|
| 71 | GBDATA *(*get_next_item_container)(GBDATA *, QUERY_RANGE);             // use same QUERY_RANGE as in get_first_item_container() | 
|---|
| 72 |  | 
|---|
| 73 | GBDATA *(*get_first_item)(GBDATA *, QUERY_RANGE); | 
|---|
| 74 | GBDATA *(*get_next_item)(GBDATA *, QUERY_RANGE); | 
|---|
| 75 |  | 
|---|
| 76 | GBDATA *(*get_selected_item)(GBDATA *gb_main, AW_root *aw_root); // searches the currently selected item | 
|---|
| 77 | void (*add_selection_changed_cb)(AW_root *aw_root, const RootCallback& cb); // gets called when selected item changes | 
|---|
| 78 |  | 
|---|
| 79 | ItemSelector *parent_selector;              // selector of parent item (or NULp if item has no parents) | 
|---|
| 80 | GBDATA *(*get_parent)(GBDATA *gb_item);     // if 'parent_selector' is defined, this function returns the parent of the item | 
|---|
| 81 |  | 
|---|
| 82 | void (*trigger_display_refresh)(); // shall be called when displays shall be refreshed (e.g. tree-display for species) | 
|---|
| 83 | }; | 
|---|
| 84 |  | 
|---|
| 85 | struct MutableBoundItemSel { | 
|---|
| 86 | GBDATA        *gb_main; | 
|---|
| 87 | ItemSelector&  selector; | 
|---|
| 88 |  | 
|---|
| 89 | MutableBoundItemSel(GBDATA *gb_main_, ItemSelector& selector_) | 
|---|
| 90 | : gb_main(gb_main_), | 
|---|
| 91 | selector(selector_) | 
|---|
| 92 | { | 
|---|
| 93 | it_assert(gb_main); | 
|---|
| 94 | it_assert(&selector); | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | GBDATA *get_any_item() const; | 
|---|
| 98 |  | 
|---|
| 99 | GBDATA *get_first_item_container(AW_root *awr, QUERY_RANGE range) const { return selector.get_first_item_container(gb_main, awr, range); } | 
|---|
| 100 | GBDATA *get_next_item_container(GBDATA *gb_cont, QUERY_RANGE range) const { return selector.get_next_item_container(gb_cont, range); } | 
|---|
| 101 |  | 
|---|
| 102 | GBDATA *get_first_item(GBDATA *gb_cont, QUERY_RANGE range) const { return selector.get_first_item(gb_cont, range); } | 
|---|
| 103 | GBDATA *get_next_item(GBDATA *gb_item, QUERY_RANGE range) const { return selector.get_next_item(gb_item, range); } | 
|---|
| 104 | }; | 
|---|
| 105 |  | 
|---|
| 106 | typedef const MutableBoundItemSel BoundItemSel; | 
|---|
| 107 |  | 
|---|
| 108 | void 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); | 
|---|
| 109 |  | 
|---|
| 110 | ItemSelector& SPECIES_get_selector(); | 
|---|
| 111 | ItemSelector& ORGANISM_get_selector(); | 
|---|
| 112 | ItemSelector& SAI_get_selector(); // has reduced functionality (no change_keys defined) | 
|---|
| 113 |  | 
|---|
| 114 | #else | 
|---|
| 115 | #error items.h included twice | 
|---|
| 116 | #endif // ITEMS_H | 
|---|