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 } |