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 | |
---|
18 | static GBDATA *get_first_SAI_data(GBDATA *gb_main, AW_root *, QUERY_RANGE) { |
---|
19 | return GBT_get_SAI_data(gb_main); |
---|
20 | } |
---|
21 | static GBDATA *get_next_SAI_data(GBDATA *, QUERY_RANGE) { |
---|
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 | } |
---|
28 | static GBDATA* get_selected_SAI(GBDATA *gb_main, AW_root *aw_root) { |
---|
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 = { |
---|
72 | QUERY_ITEM_SAI, |
---|
73 | select_SAI, |
---|
74 | get_SAI_id, |
---|
75 | find_SAI_by_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", |
---|
82 | get_first_SAI_data, |
---|
83 | get_next_SAI_data, |
---|
84 | get_first_SAI, |
---|
85 | get_next_SAI, |
---|
86 | get_selected_SAI, |
---|
87 | add_selected_SAI_changed_cb, |
---|
88 | NULp, NULp, |
---|
89 | refresh_displayed_SAI, |
---|
90 | }; |
---|
91 | |
---|
92 | ItemSelector& SAI_get_selector() { return ITEM_sai; } |
---|
93 | |
---|