ui/common/toolbar.c

branch
newapi
changeset 207
93b9f502cb88
parent 205
b1ac0dd1d38b
child 226
4eef1d49f794
equal deleted inserted replaced
206:7ebc5a747c6f 207:93b9f502cb88
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;
36
37 static UiToolbarMenuItem* ui_appmenu;
38
36 39
37 void uic_toolbar_init(void) { 40 void uic_toolbar_init(void) {
38 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); 41 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
39 toolbar_defaults = cxLinkedListCreateSimple(CX_STORE_POINTERS); 42 toolbar_defaults = cxLinkedListCreateSimple(CX_STORE_POINTERS);
40 } 43 }
77 item->item.type = UI_TOOLBAR_TOGGLEITEM; 80 item->item.type = UI_TOOLBAR_TOGGLEITEM;
78 item->args = toggleitemargs_copy(args); 81 item->args = toggleitemargs_copy(args);
79 cxMapPut(toolbar_items, name, item); 82 cxMapPut(toolbar_items, name, item);
80 } 83 }
81 84
85 static UiToolbarMenuArgs menuargs_copy(UiToolbarMenuArgs args) {
86 UiToolbarMenuArgs newargs;
87 newargs.label = nl_strdup(args.label);
88 newargs.stockid = nl_strdup(args.stockid);
89 newargs.icon = nl_strdup(args.icon);
90 return newargs;
91 }
92
93 UIEXPORT void ui_toolbar_menu_create(const char* name, UiToolbarMenuArgs args) {
94 UiToolbarMenuItem* item = malloc(sizeof(UiToolbarMenuItem));
95 item->item.type = UI_TOOLBAR_MENU;
96 memset(&item->menu, 0, sizeof(UiMenu));
97 item->args = menuargs_copy(args);
98
99 item->end = 0;
100
101 if (!name) {
102 // special appmenu
103 ui_appmenu = item;
104 } else {
105 // toplevel menu
106 cxMapPut(toolbar_items, name, item);
107 }
108
109 uic_add_menu_to_stack(&item->menu);
110 }
111
82 112
83 CxMap* uic_get_toolbar_items(void) { 113 CxMap* uic_get_toolbar_items(void) {
84 return toolbar_items; 114 return toolbar_items;
85 } 115 }
86 116
98 } 128 }
99 129
100 UiToolbarItemI* uic_toolbar_get_item(const char* name) { 130 UiToolbarItemI* uic_toolbar_get_item(const char* name) {
101 return cxMapGet(toolbar_items, name); 131 return cxMapGet(toolbar_items, name);
102 } 132 }
133
134 UiToolbarMenuItem* uic_get_appmenu(void) {
135 return ui_appmenu;
136 }

mercurial