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 |