30 |
30 |
31 #include <string.h> |
31 #include <string.h> |
32 |
32 |
33 static CxMap* toolbar_items; |
33 static CxMap* toolbar_items; |
34 |
34 |
35 static CxList* toolbar_defaults; |
35 static CxList* toolbar_defaults[3]; // 0: left 1: center 2: right |
36 |
36 |
37 static UiToolbarMenuItem* ui_appmenu; |
37 static UiToolbarMenuItem* ui_appmenu; |
38 |
38 |
39 |
|
40 void uic_toolbar_init(void) { |
39 void uic_toolbar_init(void) { |
41 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
40 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
42 toolbar_defaults = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
41 toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
|
42 toolbar_defaults[1] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
|
43 toolbar_defaults[2] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
43 } |
44 } |
44 |
45 |
45 static char* nl_strdup(char* str) { |
46 static char* nl_strdup(char* str) { |
46 return str ? strdup(str) : NULL; |
47 return str ? strdup(str) : NULL; |
47 } |
48 } |
112 |
113 |
113 CxMap* uic_get_toolbar_items(void) { |
114 CxMap* uic_get_toolbar_items(void) { |
114 return toolbar_items; |
115 return toolbar_items; |
115 } |
116 } |
116 |
117 |
117 CxList* uic_get_toolbar_defaults(void) { |
118 CxList* uic_get_toolbar_defaults(enum UiToolbarPos pos) { |
118 return toolbar_defaults; |
119 if (pos >= 0 && pos < 3) { |
|
120 return toolbar_defaults[pos]; |
|
121 } |
119 } |
122 } |
120 |
123 |
121 void ui_toolbar_add_default(const char* name) { |
124 void ui_toolbar_add_default(const char* name, enum UiToolbarPos pos) { |
122 char* cp = strdup(name); |
125 char* cp = strdup(name); |
123 cxListAdd(toolbar_defaults, cp); |
126 if (pos >= 0 && pos < 3) { |
|
127 cxListAdd(toolbar_defaults[pos], cp); |
|
128 } |
|
129 else { |
|
130 // TODO: error |
|
131 } |
124 } |
132 } |
125 |
133 |
126 UiBool uic_toolbar_isenabled(void) { |
134 UiBool uic_toolbar_isenabled(void) { |
127 return toolbar_defaults->size > 0; |
135 return toolbar_defaults[0]->size + toolbar_defaults[1]->size + toolbar_defaults[2]->size > 0; |
128 } |
136 } |
129 |
137 |
130 UiToolbarItemI* uic_toolbar_get_item(const char* name) { |
138 UiToolbarItemI* uic_toolbar_get_item(const char* name) { |
131 return cxMapGet(toolbar_items, name); |
139 return cxMapGet(toolbar_items, name); |
132 } |
140 } |