diff -r db95c0104937 -r 06be29a56f8b ui/motif/menu.c --- a/ui/motif/menu.c Tue Apr 01 13:47:29 2014 +0200 +++ b/ui/motif/menu.c Wed Apr 02 09:59:38 2014 +0200 @@ -32,6 +32,7 @@ #include "menu.h" #include "button.h" #include "toolkit.h" +#include "stock.h" #include "../common/context.h" #include "../ui/window.h" @@ -94,6 +95,22 @@ cm->items = ucx_list_append(cm->items, item); } +void ui_menuitem_st(char *stockid, ui_callback f, void *userdata) { + if(!current) { + return; + } + + UiStMenuItem *item = malloc(sizeof(UiStMenuItem)); + item->item.add_to = (ui_menu_add_f)add_menuitem_st_widget; + + item->stockid = stockid; + item->userdata = userdata; + item->callback = f; + + UiMenu *cm = current->data; + cm->items = ucx_list_append(cm->items, item); +} + void ui_menuseparator() { if(!current) { return; @@ -230,6 +247,61 @@ return 1; } +int add_menuitem_st_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { + UiStMenuItem *mi = (UiStMenuItem*)item; + + UiStockItem *si = ui_get_stock_item(mi->stockid); + if(!si) { + fprintf(stderr, "UI Error: unknown stock id: %s\n", mi->stockid); + return 0; + } + + int n = 0; + Arg args[4]; + XmString label = XmStringCreateLocalized(si->label); + XmString at = NULL; + + XtSetArg(args[n], XmNlabelString, label); + n++; + if(si->accelerator) { + XtSetArg(args[n], XmNaccelerator, si->accelerator); + n++; + } + if(si->accelerator_label) { + at = XmStringCreateLocalized(si->accelerator_label); + XtSetArg(args[n], XmNacceleratorText, at); + n++; + } + + Widget mitem = XtCreateManagedWidget( + "menubutton", + xmPushButtonWidgetClass, + parent, + args, + n); + XmStringFree(label); + if(at) { + XmStringFree(at); + } + + if(mi->callback != NULL) { + UiEventData *event = ucx_mempool_malloc( + obj->ctx->mempool, + sizeof(UiEventData)); + event->obj = obj; + event->user_data = mi->userdata; + event->callback = mi->callback; + event->value = 0; + XtAddCallback( + mitem, + XmNactivateCallback, + (XtCallbackProc)ui_push_button_callback, + event); + } + + return 1; +} + int add_menuseparator_widget( Widget parent, int i,