ui/common/toolbar.c

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

mercurial