ui/common/toolbar.c

changeset 789
d70799b3333e
parent 594
fc854e0ab924
child 791
c83b9acfa316
equal deleted inserted replaced
788:27f126f6e361 789:d70799b3333e
31 31
32 #include <string.h> 32 #include <string.h>
33 33
34 static CxMap* toolbar_items; 34 static CxMap* toolbar_items;
35 35
36 static CxList* toolbar_defaults[3]; // 0: left 1: center 2: right 36 static CxList* toolbar_defaults[8]; // 0: left 1: center 2: right
37 37
38 static UiToolbarMenuItem* ui_appmenu; 38 static UiToolbarMenuItem* ui_appmenu;
39 39
40 40
41 void uic_toolbar_init(void) { 41 void uic_toolbar_init(void) {
42 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); 42 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
43 toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS); 43 for(int i=0;i<8;i++) {
44 toolbar_defaults[1] = cxLinkedListCreateSimple(CX_STORE_POINTERS); 44 toolbar_defaults[i] = cxLinkedListCreateSimple(CX_STORE_POINTERS);
45 toolbar_defaults[2] = cxLinkedListCreateSimple(CX_STORE_POINTERS); 45 }
46 } 46 }
47 47
48 static char* nl_strdup(const char* str) { 48 static char* nl_strdup(const char* str) {
49 return str ? strdup(str) : NULL; 49 return str ? strdup(str) : NULL;
50 } 50 }
118 CxMap* uic_get_toolbar_items(void) { 118 CxMap* uic_get_toolbar_items(void) {
119 return toolbar_items; 119 return toolbar_items;
120 } 120 }
121 121
122 CxList* uic_get_toolbar_defaults(enum UiToolbarPos pos) { 122 CxList* uic_get_toolbar_defaults(enum UiToolbarPos pos) {
123 if (pos >= 0 && pos < 3) { 123 if (pos >= 0 && pos < 8) {
124 return toolbar_defaults[pos]; 124 return toolbar_defaults[pos];
125 } 125 }
126 return NULL; 126 return NULL;
127 } 127 }
128 128
129 void ui_toolbar_add_default(const char* name, enum UiToolbarPos pos) { 129 void ui_toolbar_add_default(const char* name, enum UiToolbarPos pos) {
130 char* cp = strdup(name); 130 char* cp = strdup(name);
131 if (pos >= 0 && pos < 3) { 131 if (pos >= 0 && pos < 8) {
132 cxListAdd(toolbar_defaults[pos], cp); 132 cxListAdd(toolbar_defaults[pos], cp);
133 } else { 133 } else {
134 // TODO: error 134 fprintf(stderr, "Error: illegal toolbar position: %d\n", (int)pos);
135 } 135 }
136 } 136 }
137 137
138 UiBool uic_toolbar_isenabled(void) { 138 UiBool uic_toolbar_isenabled(void) {
139 return cxListSize(toolbar_defaults[0]) + cxListSize(toolbar_defaults[1]) + cxListSize(toolbar_defaults[2]) > 0; 139 size_t size = 0;
140 for(int i=0;i<8;i++) {
141 size += cxListSize(toolbar_defaults[i]);
142 }
143 return size > 0;
140 } 144 }
141 145
142 UiToolbarItemI* uic_toolbar_get_item(const char* name) { 146 UiToolbarItemI* uic_toolbar_get_item(const char* name) {
143 return cxMapGet(toolbar_items, name); 147 return cxMapGet(toolbar_items, name);
144 } 148 }

mercurial