ui/motif/menu.c

changeset 18
06be29a56f8b
parent 17
db95c0104937
child 21
012418e7dc90
equal deleted inserted replaced
17:db95c0104937 18:06be29a56f8b
30 #include <stdlib.h> 30 #include <stdlib.h>
31 31
32 #include "menu.h" 32 #include "menu.h"
33 #include "button.h" 33 #include "button.h"
34 #include "toolkit.h" 34 #include "toolkit.h"
35 #include "stock.h"
35 #include "../common/context.h" 36 #include "../common/context.h"
36 #include "../ui/window.h" 37 #include "../ui/window.h"
37 38
38 UcxList *menus; 39 UcxList *menus;
39 UcxList *current; 40 UcxList *current;
85 86
86 UiMenuItem *item = malloc(sizeof(UiMenuItem)); 87 UiMenuItem *item = malloc(sizeof(UiMenuItem));
87 item->item.add_to = (ui_menu_add_f)add_menuitem_widget; 88 item->item.add_to = (ui_menu_add_f)add_menuitem_widget;
88 89
89 item->label = label; 90 item->label = label;
91 item->userdata = userdata;
92 item->callback = f;
93
94 UiMenu *cm = current->data;
95 cm->items = ucx_list_append(cm->items, item);
96 }
97
98 void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) {
99 if(!current) {
100 return;
101 }
102
103 UiStMenuItem *item = malloc(sizeof(UiStMenuItem));
104 item->item.add_to = (ui_menu_add_f)add_menuitem_st_widget;
105
106 item->stockid = stockid;
90 item->userdata = userdata; 107 item->userdata = userdata;
91 item->callback = f; 108 item->callback = f;
92 109
93 UiMenu *cm = current->data; 110 UiMenu *cm = current->data;
94 cm->items = ucx_list_append(cm->items, item); 111 cm->items = ucx_list_append(cm->items, item);
209 xmPushButtonWidgetClass, 226 xmPushButtonWidgetClass,
210 parent, 227 parent,
211 args, 228 args,
212 1); 229 1);
213 XmStringFree(label); 230 XmStringFree(label);
231
232 if(mi->callback != NULL) {
233 UiEventData *event = ucx_mempool_malloc(
234 obj->ctx->mempool,
235 sizeof(UiEventData));
236 event->obj = obj;
237 event->user_data = mi->userdata;
238 event->callback = mi->callback;
239 event->value = 0;
240 XtAddCallback(
241 mitem,
242 XmNactivateCallback,
243 (XtCallbackProc)ui_push_button_callback,
244 event);
245 }
246
247 return 1;
248 }
249
250 int add_menuitem_st_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) {
251 UiStMenuItem *mi = (UiStMenuItem*)item;
252
253 UiStockItem *si = ui_get_stock_item(mi->stockid);
254 if(!si) {
255 fprintf(stderr, "UI Error: unknown stock id: %s\n", mi->stockid);
256 return 0;
257 }
258
259 int n = 0;
260 Arg args[4];
261 XmString label = XmStringCreateLocalized(si->label);
262 XmString at = NULL;
263
264 XtSetArg(args[n], XmNlabelString, label);
265 n++;
266 if(si->accelerator) {
267 XtSetArg(args[n], XmNaccelerator, si->accelerator);
268 n++;
269 }
270 if(si->accelerator_label) {
271 at = XmStringCreateLocalized(si->accelerator_label);
272 XtSetArg(args[n], XmNacceleratorText, at);
273 n++;
274 }
275
276 Widget mitem = XtCreateManagedWidget(
277 "menubutton",
278 xmPushButtonWidgetClass,
279 parent,
280 args,
281 n);
282 XmStringFree(label);
283 if(at) {
284 XmStringFree(at);
285 }
214 286
215 if(mi->callback != NULL) { 287 if(mi->callback != NULL) {
216 UiEventData *event = ucx_mempool_malloc( 288 UiEventData *event = ucx_mempool_malloc(
217 obj->ctx->mempool, 289 obj->ctx->mempool,
218 sizeof(UiEventData)); 290 sizeof(UiEventData));

mercurial