35 static CxList* toolbar_defaults[3]; // 0: left 1: center 2: right |
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 void uic_toolbar_init(void) { |
39 void uic_toolbar_init(void) { |
40 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
40 toolbar_items = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16); |
41 toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
41 toolbar_defaults[0] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
42 toolbar_defaults[1] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
42 toolbar_defaults[1] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
43 toolbar_defaults[2] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
43 toolbar_defaults[2] = cxLinkedListCreateSimple(CX_STORE_POINTERS); |
44 } |
44 } |
45 |
45 |
46 static char* nl_strdup(char* str) { |
46 static char* nl_strdup(const char* str) { |
47 return str ? strdup(str) : NULL; |
47 return str ? strdup(str) : NULL; |
48 } |
48 } |
49 |
49 |
50 static UiToolbarItemArgs itemargs_copy(UiToolbarItemArgs args) { |
50 static UiToolbarItemArgs itemargs_copy(UiToolbarItemArgs args) { |
51 UiToolbarItemArgs newargs; |
51 UiToolbarItemArgs newargs; |
52 newargs.label = nl_strdup(args.label); |
52 newargs.label = nl_strdup(args.label); |
53 newargs.stockid = nl_strdup(args.stockid); |
53 newargs.stockid = nl_strdup(args.stockid); |
54 newargs.icon = nl_strdup(args.icon); |
54 newargs.icon = nl_strdup(args.icon); |
55 newargs.onclick = args.onclick; |
55 newargs.onclick = args.onclick; |
56 newargs.onclickdata = args.onclickdata; |
56 newargs.onclickdata = args.onclickdata; |
57 return newargs; |
57 return newargs; |
58 } |
58 } |
59 |
59 |
60 void ui_toolbar_item_create(const char* name, UiToolbarItemArgs args) { |
60 void ui_toolbar_item_create(const char* name, UiToolbarItemArgs args) { |
61 UiToolbarItem* item = malloc(sizeof(UiToolbarItem)); |
61 UiToolbarItem* item = malloc(sizeof(UiToolbarItem)); |
62 item->item.type = UI_TOOLBAR_ITEM; |
62 item->item.type = UI_TOOLBAR_ITEM; |
63 item->args = itemargs_copy(args); |
63 item->args = itemargs_copy(args); |
64 cxMapPut(toolbar_items, name, item); |
64 cxMapPut(toolbar_items, name, item); |
65 } |
65 } |
66 |
66 |
67 |
67 |
68 static UiToolbarToggleItemArgs toggleitemargs_copy(UiToolbarToggleItemArgs args) { |
68 static UiToolbarToggleItemArgs toggleitemargs_copy(UiToolbarToggleItemArgs args) { |
69 UiToolbarToggleItemArgs newargs; |
69 UiToolbarToggleItemArgs newargs; |
70 newargs.label = nl_strdup(args.label); |
70 newargs.label = nl_strdup(args.label); |
71 newargs.stockid = nl_strdup(args.stockid); |
71 newargs.stockid = nl_strdup(args.stockid); |
72 newargs.icon = nl_strdup(args.icon); |
72 newargs.icon = nl_strdup(args.icon); |
73 newargs.varname = nl_strdup(args.varname); |
73 newargs.varname = nl_strdup(args.varname); |
74 newargs.onchange = args.onchange; |
74 newargs.onchange = args.onchange; |
75 newargs.onchangedata = args.onchangedata; |
75 newargs.onchangedata = args.onchangedata; |
76 return newargs; |
76 return newargs; |
77 } |
77 } |
78 |
78 |
79 void ui_toolbar_toggleitem_create(const char* name, UiToolbarToggleItemArgs args) { |
79 void ui_toolbar_toggleitem_create(const char* name, UiToolbarToggleItemArgs args) { |
80 UiToolbarToggleItem* item = malloc(sizeof(UiToolbarToggleItem)); |
80 UiToolbarToggleItem* item = malloc(sizeof(UiToolbarToggleItem)); |
81 item->item.type = UI_TOOLBAR_TOGGLEITEM; |
81 item->item.type = UI_TOOLBAR_TOGGLEITEM; |
82 item->args = toggleitemargs_copy(args); |
82 item->args = toggleitemargs_copy(args); |
83 cxMapPut(toolbar_items, name, item); |
83 cxMapPut(toolbar_items, name, item); |
84 } |
84 } |
85 |
85 |
86 static UiToolbarMenuArgs menuargs_copy(UiToolbarMenuArgs args) { |
86 static UiToolbarMenuArgs menuargs_copy(UiToolbarMenuArgs args) { |
87 UiToolbarMenuArgs newargs; |
87 UiToolbarMenuArgs newargs; |
88 newargs.label = nl_strdup(args.label); |
88 newargs.label = nl_strdup(args.label); |
89 newargs.stockid = nl_strdup(args.stockid); |
89 newargs.stockid = nl_strdup(args.stockid); |
90 newargs.icon = nl_strdup(args.icon); |
90 newargs.icon = nl_strdup(args.icon); |
91 return newargs; |
91 return newargs; |
92 } |
92 } |
93 |
93 |
94 UIEXPORT void ui_toolbar_menu_create(const char* name, UiToolbarMenuArgs args) { |
94 UIEXPORT void ui_toolbar_menu_create(const char* name, UiToolbarMenuArgs args) { |
95 UiToolbarMenuItem* item = malloc(sizeof(UiToolbarMenuItem)); |
95 UiToolbarMenuItem* item = malloc(sizeof(UiToolbarMenuItem)); |
96 item->item.type = UI_TOOLBAR_MENU; |
96 item->item.type = UI_TOOLBAR_MENU; |
97 memset(&item->menu, 0, sizeof(UiMenu)); |
97 memset(&item->menu, 0, sizeof(UiMenu)); |
98 item->args = menuargs_copy(args); |
98 item->args = menuargs_copy(args); |
99 |
|
100 item->end = 0; |
|
101 |
99 |
102 if (!name) { |
100 item->end = 0; |
103 // special appmenu |
|
104 ui_appmenu = item; |
|
105 } else { |
|
106 // toplevel menu |
|
107 cxMapPut(toolbar_items, name, item); |
|
108 } |
|
109 |
101 |
110 uic_add_menu_to_stack(&item->menu); |
102 if (!name) { |
|
103 // special appmenu |
|
104 ui_appmenu = item; |
|
105 } else { |
|
106 // toplevel menu |
|
107 cxMapPut(toolbar_items, name, item); |
|
108 } |
|
109 |
|
110 uic_add_menu_to_stack(&item->menu); |
111 } |
111 } |
112 |
112 |
113 |
113 |
114 CxMap* uic_get_toolbar_items(void) { |
114 CxMap* uic_get_toolbar_items(void) { |
115 return toolbar_items; |
115 return toolbar_items; |
116 } |
116 } |
117 |
117 |
118 CxList* uic_get_toolbar_defaults(enum UiToolbarPos pos) { |
118 CxList* uic_get_toolbar_defaults(enum UiToolbarPos pos) { |
119 if (pos >= 0 && pos < 3) { |
119 if (pos >= 0 && pos < 3) { |
120 return toolbar_defaults[pos]; |
120 return toolbar_defaults[pos]; |
121 } |
121 } |
|
122 return NULL; |
122 } |
123 } |
123 |
124 |
124 void ui_toolbar_add_default(const char* name, enum UiToolbarPos pos) { |
125 void ui_toolbar_add_default(const char* name, enum UiToolbarPos pos) { |
125 char* cp = strdup(name); |
126 char* cp = strdup(name); |
126 if (pos >= 0 && pos < 3) { |
127 if (pos >= 0 && pos < 3) { |
127 cxListAdd(toolbar_defaults[pos], cp); |
128 cxListAdd(toolbar_defaults[pos], cp); |
128 } |
129 } else { |
129 else { |
130 // TODO: error |
130 // TODO: error |
131 } |
131 } |
|
132 } |
132 } |
133 |
133 |
134 UiBool uic_toolbar_isenabled(void) { |
134 UiBool uic_toolbar_isenabled(void) { |
135 return toolbar_defaults[0]->size + toolbar_defaults[1]->size + toolbar_defaults[2]->size > 0; |
135 return toolbar_defaults[0]->size + toolbar_defaults[1]->size + toolbar_defaults[2]->size > 0; |
136 } |
136 } |
137 |
137 |
138 UiToolbarItemI* uic_toolbar_get_item(const char* name) { |
138 UiToolbarItemI* uic_toolbar_get_item(const char* name) { |
139 return cxMapGet(toolbar_items, name); |
139 return cxMapGet(toolbar_items, name); |
140 } |
140 } |
141 |
141 |
142 UiToolbarMenuItem* uic_get_appmenu(void) { |
142 UiToolbarMenuItem* uic_get_appmenu(void) { |
143 return ui_appmenu; |
143 return ui_appmenu; |
144 } |
144 } |