ARB
SAIs.cxx
Go to the documentation of this file.
1 // ========================================================= //
2 // //
3 // File : SAIs.cxx //
4 // Purpose : ItemSelector for SAIs //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in Oct 21 //
7 // http://www.arb-home.de/ //
8 // //
9 // ========================================================= //
10 
11 #include "item_sel_list.h"
12 
13 #include <arbdbt.h>
14 #include <aw_root.hxx>
15 #include <aw_awars.hxx>
16 
17 
19  return GBT_get_SAI_data(gb_main);
20 }
22  return NULp; // there is only ONE 'extended_data'
23 }
24 
25 static void select_SAI(GBDATA*, AW_root *aw_root, const char *item_name) {
26  aw_root->awar(AWAR_SAI_NAME)->write_string(item_name);
27 }
29  const char *SAI_name = aw_root->awar(AWAR_SAI_NAME)->read_char_pntr();
30  return SAI_name[0] ? GBT_find_SAI(gb_main, SAI_name) : NULp;
31 }
32 static void add_selected_SAI_changed_cb(AW_root *aw_root, const RootCallback& cb) {
33  aw_root->awar(AWAR_SAI_NAME)->add_callback(cb);
34 }
35 
36 static char* get_SAI_id(GBDATA *, GBDATA *gb_sai) {
37  GBDATA *gb_name = GB_entry(gb_sai, "name");
38  if (!gb_name) return NULp; // sai w/o name -> skip
39  return GB_read_as_string(gb_name);
40 }
41 
42 static GBDATA *find_SAI_by_id(GBDATA *gb_main, const char *id) {
43  return GBT_find_SAI(gb_main, id); // id is 'name' field
44 }
45 
46 static GBDATA *get_first_SAI(GBDATA *gb_SAI_data, QUERY_RANGE range) {
47  GBDATA *gb_first = NULp;
48  switch (range) {
49  case QUERY_ALL_ITEMS: gb_first = GBT_first_SAI_rel_SAI_data(gb_SAI_data); break;
50  case QUERY_MARKED_ITEMS: gb_first = GB_first_marked(gb_SAI_data, "extended"); break;
51  case QUERY_CURRENT_ITEM: gb_first = get_selected_SAI(GB_get_root(gb_SAI_data), AW_root::SINGLETON); break;
52  }
53  return gb_first;
54 }
55 static GBDATA *get_next_SAI(GBDATA *gb_prev, QUERY_RANGE range) {
56  GBDATA *gb_next = NULp;
57  switch (range) {
58  case QUERY_ALL_ITEMS: gb_next = GBT_next_SAI(gb_prev); break;
59  case QUERY_MARKED_ITEMS: {
60  gb_assert(GB_has_key(gb_prev, "extended"));
61  gb_next = GB_next_marked(gb_prev, "extended");
62  break;
63  }
64  case QUERY_CURRENT_ITEM: gb_next = NULp; break;
65  }
66  return gb_next;
67 }
68 static void refresh_displayed_SAI() {
69 }
70 
71 static struct MutableItemSelector ITEM_sai = {
73  select_SAI,
74  get_SAI_id,
76  NULp, // no fields selectable
77  -1, // length of 'name' is unknown
78  NULp, // no changekeys defined for SAI
79  "SAI",
80  "SAIs",
81  "name",
88  NULp, NULp,
90 };
91 
93 
static void select_SAI(GBDATA *, AW_root *aw_root, const char *item_name)
Definition: SAIs.cxx:25
static char * get_SAI_id(GBDATA *, GBDATA *gb_sai)
Definition: SAIs.cxx:36
static void add_selected_SAI_changed_cb(AW_root *aw_root, const RootCallback &cb)
Definition: SAIs.cxx:32
char * GB_read_as_string(GBDATA *gbd)
Definition: arbdb.cxx:1054
static GBDATA * find_SAI_by_id(GBDATA *gb_main, const char *id)
Definition: SAIs.cxx:42
#define cb(action)
static GBDATA * get_next_SAI(GBDATA *gb_prev, QUERY_RANGE range)
Definition: SAIs.cxx:55
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
GBDATA * GBT_find_SAI(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:177
const char * read_char_pntr() const
Definition: AW_awar.cxx:171
static AW_root * SINGLETON
Definition: aw_root.hxx:102
static void refresh_displayed_SAI()
Definition: SAIs.cxx:68
GBDATA * GB_get_root(GBDATA *gbd)
Definition: arbdb.cxx:1734
ItemSelector & SAI_get_selector()
Definition: SAIs.cxx:92
GBDATA * GBT_first_SAI_rel_SAI_data(GBDATA *gb_sai_data)
Definition: aditem.cxx:159
#define AWAR_SAI_NAME
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
bool GB_has_key(GBDATA *gbd, const char *key)
Definition: arbdb.cxx:1701
static GBDATA * get_next_SAI_data(GBDATA *, QUERY_RANGE)
Definition: SAIs.cxx:21
QUERY_RANGE
Definition: items.h:41
GBDATA * GBT_next_SAI(GBDATA *gb_sai)
Definition: aditem.cxx:166
static GBDATA * get_selected_SAI(GBDATA *gb_main, AW_root *aw_root)
Definition: SAIs.cxx:28
#define gb_assert(cond)
Definition: arbdbt.h:11
GBDATA * GB_next_marked(GBDATA *gbd, const char *keystring)
Definition: adquery.cxx:670
static GBDATA * get_first_SAI(GBDATA *gb_SAI_data, QUERY_RANGE range)
Definition: SAIs.cxx:46
#define NULp
Definition: cxxforward.h:97
GB_ERROR write_string(const char *aw_string)
GBDATA * GB_first_marked(GBDATA *gbd, const char *keystring)
Definition: adquery.cxx:655
GBDATA * gb_main
Definition: adname.cxx:33
GBDATA * GBT_get_SAI_data(GBDATA *gb_main)
Definition: aditem.cxx:154
static GBDATA * get_first_SAI_data(GBDATA *gb_main, AW_root *, QUERY_RANGE)
Definition: SAIs.cxx:18
static struct MutableItemSelector ITEM_sai
Definition: SAIs.cxx:71
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334