ui/motif/menu.c

changeset 76
3782827378ab
parent 52
25e5390cce41
child 98
efaae97bd95b
equal deleted inserted replaced
75:efe2f65bea17 76:3782827378ab
32 32
33 #include "menu.h" 33 #include "menu.h"
34 #include "button.h" 34 #include "button.h"
35 #include "toolkit.h" 35 #include "toolkit.h"
36 #include "stock.h" 36 #include "stock.h"
37 #include "container.h"
37 #include "../common/context.h" 38 #include "../common/context.h"
38 #include "../ui/window.h" 39 #include "../ui/window.h"
39 40
40 UcxList *menus; 41 UcxList *menus;
41 UcxList *current; 42 UcxList *current;
523 e.window = event->obj->window; 524 e.window = event->obj->window;
524 e.document = event->obj->ctx->document; 525 e.document = event->obj->ctx->document;
525 e.intval = 0; 526 e.intval = 0;
526 event->callback(&e, event->user_data); 527 event->callback(&e, event->user_data);
527 } 528 }
529
530
531 /*
532 * widget menu functions
533 */
534
535 static void ui_popup_handler(Widget widget, XtPointer data, XEvent *event, Boolean *c) {
536 Widget menu = data;
537 XmMenuPosition(menu, (XButtonPressedEvent *)event);
538 XtManageChild(menu);
539
540 *c = FALSE;
541 }
542
543 void ui_contextmenu(UiObject *obj) {
544 UiContainer *ct = uic_get_current_container(obj);
545 ui_contextmenu_w(obj, ct->current);
546 }
547
548 void ui_contextmenu_w(UiObject *obj, UIWIDGET widget) {
549 UiContainer *ct = uic_get_current_container(obj);
550
551 Widget menu = XmCreatePopupMenu(ct->current, "popup_menu", NULL, 0);
552 ct->menu = menu;
553
554 XtAddEventHandler(widget, ButtonPressMask, FALSE, ui_popup_handler, menu);
555 }
556
557 void ui_widget_menuitem(UiObject *obj, char *label, ui_callback f, void *userdata) {
558 ui_widget_menuitem_gr(obj, label, f, userdata, -1);
559 }
560
561 void ui_widget_menuitem_gr(UiObject *obj, char *label, ui_callback f, void *userdata, ...) {
562 UiContainer *ct = uic_get_current_container(obj);
563 if(!ct->menu) {
564 return;
565 }
566
567 // add groups
568 UcxList *groups = NULL;
569 va_list ap;
570 va_start(ap, userdata);
571 int group;
572 while((group = va_arg(ap, int)) != -1) {
573 ucx_list_append(groups, (void*)(intptr_t)group);
574 }
575 va_end(ap);
576
577 // create menuitem
578 Arg args[4];
579 XmString labelstr = XmStringCreateLocalized(label);
580 XtSetArg(args[0], XmNlabelString, labelstr);
581
582 Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1);
583 XtManageChild(item);
584 XmStringFree(labelstr);
585 }
586
587 void ui_widget_menuitem_st(UiObject *obj, char *stockid, ui_callback f, void *userdata) {
588 ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1);
589 }
590
591 void ui_widget_menuitem_stgr(UiObject *obj, char *stockid, ui_callback f, void *userdata, ...) {
592 UiContainer *ct = uic_get_current_container(obj);
593 if(!ct->menu) {
594 return;
595 }
596
597 // add groups
598 UcxList *groups = NULL;
599 va_list ap;
600 va_start(ap, userdata);
601 int group;
602 while((group = va_arg(ap, int)) != -1) {
603 ucx_list_append(groups, (void*)(intptr_t)group);
604 }
605 va_end(ap);
606
607 // create menuitem
608 UiStockItem *stockItem = ui_get_stock_item(stockid);
609 Arg args[4];
610 XmString labelstr = XmStringCreateLocalized(stockItem->label);
611 XtSetArg(args[0], XmNlabelString, labelstr);
612
613 Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1);
614 XtManageChild(item);
615 XmStringFree(labelstr);
616 }

mercurial