ui/motif/menu.c

Thu, 15 Feb 2024 21:33:08 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 15 Feb 2024 21:33:08 +0100
branch
newapi
changeset 262
81778b9589d0
parent 176
bc63cb601f6d
permissions
-rw-r--r--

port progressbar to new API (GTK)

0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
1 /*
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
3 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
4 * Copyright 2014 Olaf Wintermann. All rights reserved.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
5 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
6 * Redistribution and use in source and binary forms, with or without
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
7 * modification, are permitted provided that the following conditions are met:
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
8 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
9 * 1. Redistributions of source code must retain the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
10 * notice, this list of conditions and the following disclaimer.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
11 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
12 * 2. Redistributions in binary form must reproduce the above copyright
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
13 * notice, this list of conditions and the following disclaimer in the
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
14 * documentation and/or other materials provided with the distribution.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
15 *
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
26 * POSSIBILITY OF SUCH DAMAGE.
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
27 */
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
28
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
29 #include <stdio.h>
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
30 #include <stdlib.h>
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
31 #include <stdarg.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
32
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
33 #include "menu.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
34 #include "button.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
35 #include "toolkit.h"
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
36 #include "stock.h"
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
37 #include "container.h"
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
38 #include "../common/context.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
39 #include "../ui/window.h"
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
40
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
41 #include <cx/linked_list.h>
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
42 #include <cx/array_list.h>
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
43
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
44 static ui_menu_add_f createMenuItem[] = {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
45 /* UI_MENU */ add_menu_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
46 /* UI_MENU_SUBMENU */ add_menu_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
47 /* UI_MENU_ITEM */ add_menuitem_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
48 /* UI_MENU_STOCK_ITEM */ add_menuitem_st_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
49 /* UI_MENU_CHECK_ITEM */ add_checkitem_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
50 /* UI_MENU_CHECK_ITEM_NV */ add_checkitemnv_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
51 /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget,
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
52 /* UI_MENU_ITEM_LIST_NV */ NULL, // TODO
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
53 /* UI_MENU_SEPARATOR */ add_menuseparator_widget
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
54 };
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
55
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
56 // private menu functions
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
57 void ui_create_menubar(UiObject *obj) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
58 UiMenu *menus = uic_get_menu_list();
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
59 if(!menus) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
60 return;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
61 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
62
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
63 Widget menubar = XmCreateMenuBar(obj->widget, "main_list", NULL, 0);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
64 XtManageChild(menubar);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
65
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
66 UiMenu *menu = menus;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
67 int menu_index = 0;
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
68 while(menu) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
69 menu_index += add_menu_widget(menubar, menu_index, &menu->item, obj);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
70
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
71 menu = (UiMenu*)menu->item.next;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
72 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
73 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
74
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
75 int add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
76 UiMenu *menu = (UiMenu*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
77
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
78 Widget menuItem = XtVaCreateManagedWidget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
79 menu->label,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
80 xmCascadeButtonWidgetClass,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
81 parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
82 NULL);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
83 Widget m = XmVaCreateSimplePulldownMenu(parent, menu->label, i, NULL, NULL);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
84
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
85 UiMenuItemI *mi = menu->items_begin;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
86 int menu_index = 0;
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
87 while(mi) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
88 menu_index += createMenuItem[mi->type](m, menu_index, mi, obj);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
89 mi = mi->next;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
90 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
91
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
92 return 1;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
93 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
94
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
95 int add_menuitem_widget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
96 Widget parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
97 int i,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
98 UiMenuItemI *item,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
99 UiObject *obj)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
100 {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
101 UiMenuItem *mi = (UiMenuItem*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
102
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
103 Arg args[1];
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
104 XmString label = XmStringCreateLocalized(mi->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
105 XtSetArg(args[0], XmNlabelString, label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
106
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
107 Widget mitem = XtCreateManagedWidget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
108 "menubutton",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
109 xmPushButtonWidgetClass,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
110 parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
111 args,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
112 1);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
113 XmStringFree(label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
114
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
115 if(mi->callback != NULL) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
116 UiEventData *event = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
117 obj->ctx->allocator,
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
118 sizeof(UiEventData));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
119 event->obj = obj;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
120 event->userdata = mi->userdata;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
121 event->callback = mi->callback;
17
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
122 event->value = 0;
3
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
123 XtAddCallback(
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
124 mitem,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
125 XmNactivateCallback,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
126 (XtCallbackProc)ui_push_button_callback,
c1a75454b444 added toolbar
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 2
diff changeset
127 event);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
128 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
129
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
130 if(mi->groups) {
169
fe49cff3c571 refactor widget groups/document tree (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
131 uic_add_group_widget(obj->ctx, mitem, (ui_enablefunc)XtSetSensitive, mi->groups);
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
132 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
133
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
134 return 1;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
135 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
136
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
137 int add_menuitem_st_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
138 UiStMenuItem *mi = (UiStMenuItem*)item;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
139
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
140 UiStockItem *si = ui_get_stock_item(mi->stockid);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
141 if(!si) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
142 fprintf(stderr, "UI Error: unknown stock id: %s\n", mi->stockid);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
143 return 0;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
144 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
145
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
146 int n = 0;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
147 Arg args[4];
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
148 XmString label = XmStringCreateLocalized(si->label);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
149 XmString at = NULL;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
150
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
151 XtSetArg(args[n], XmNlabelString, label);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
152 n++;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
153 if(si->accelerator) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
154 XtSetArg(args[n], XmNaccelerator, si->accelerator);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
155 n++;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
156 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
157 if(si->accelerator_label) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
158 at = XmStringCreateLocalized(si->accelerator_label);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
159 XtSetArg(args[n], XmNacceleratorText, at);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
160 n++;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
161 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
162
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
163 Widget mitem = XtCreateManagedWidget(
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
164 "menubutton",
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
165 xmPushButtonWidgetClass,
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
166 parent,
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
167 args,
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
168 n);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
169 XmStringFree(label);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
170 if(at) {
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
171 XmStringFree(at);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
172 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
173
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
174 if(mi->callback != NULL) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
175 UiEventData *event = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
176 obj->ctx->allocator,
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
177 sizeof(UiEventData));
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
178 event->obj = obj;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
179 event->userdata = mi->userdata;
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
180 event->callback = mi->callback;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
181 event->value = 0;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
182 XtAddCallback(
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
183 mitem,
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
184 XmNactivateCallback,
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
185 (XtCallbackProc)ui_push_button_callback,
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
186 event);
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
187 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
188
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
189 if(mi->groups) {
169
fe49cff3c571 refactor widget groups/document tree (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 153
diff changeset
190 uic_add_group_widget(obj->ctx, mitem, (ui_enablefunc)XtSetSensitive, mi->groups);
21
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
191 }
012418e7dc90 added groups for menu items (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 18
diff changeset
192
18
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
193 return 1;
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
194 }
06be29a56f8b added menu accelerators
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 17
diff changeset
195
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
196 int add_menuseparator_widget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
197 Widget parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
198 int i,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
199 UiMenuItemI *item,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
200 UiObject *obj)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
201 {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
202 Widget s = XmCreateSeparatorGadget (parent, "menu_separator", NULL, 0);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
203 XtManageChild(s);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
204 return 1;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
205 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
206
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
207 int add_checkitem_widget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
208 Widget parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
209 int i,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
210 UiMenuItemI *item,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
211 UiObject *obj)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
212 {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
213 UiCheckItem *ci = (UiCheckItem*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
214
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
215 Arg args[3];
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
216 XmString label = XmStringCreateLocalized(ci->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
217 XtSetArg(args[0], XmNlabelString, label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
218 XtSetArg(args[1], XmNvisibleWhenOff, 1);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
219 Widget checkbox = XtCreateManagedWidget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
220 "menutogglebutton",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
221 xmToggleButtonWidgetClass,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
222 parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
223 args,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
224 2);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
225 XmStringFree(label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
226
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
227 if(ci->callback) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
228 UiEventData *event = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
229 obj->ctx->allocator,
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
230 sizeof(UiEventData));
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
231 event->obj = obj;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
232 event->userdata = ci->userdata;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
233 event->callback = ci->callback;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
234 XtAddCallback(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
235 checkbox,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
236 XmNvalueChangedCallback,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
237 (XtCallbackProc)ui_toggle_button_callback,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
238 event);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
239 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
240
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
241 return 1;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
242 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
243
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
244 int add_checkitemnv_widget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
245 Widget parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
246 int i,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
247 UiMenuItemI *item,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
248 UiObject *obj)
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
249 {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
250 UiCheckItemNV *ci = (UiCheckItemNV*)item;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
251
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
252 Arg args[3];
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
253 XmString label = XmStringCreateLocalized(ci->label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
254 XtSetArg(args[0], XmNlabelString, label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
255 XtSetArg(args[1], XmNvisibleWhenOff, 1);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
256 Widget checkbox = XtCreateManagedWidget(
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
257 "menutogglebutton",
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
258 xmToggleButtonWidgetClass,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
259 parent,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
260 args,
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
261 2);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
262 XmStringFree(label);
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
263
153
ee49d1852a5f applies value binding refactoring and text refactoring to motif implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 115
diff changeset
264 UiVar *var = uic_create_var(obj->ctx, ci->varname, UI_VAR_INTEGER);
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
265 if(var) {
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
266 UiInteger *value = var->value;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
267 value->obj = checkbox;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
268 value->get = ui_toggle_button_get;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
269 value->set = ui_toggle_button_set;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
270 value = 0;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
271 } else {
2
eeb50c534497 added support for replaceable documents
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 0
diff changeset
272 // TODO: error
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
273 }
17
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
274
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
275 return 1;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
276 }
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
277
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
278 int add_menuitem_list_widget(
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
279 Widget parent,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
280 int i,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
281 UiMenuItemI *item,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
282 UiObject *obj)
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
283 {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
284 UiMenuItemList *il = (UiMenuItemList*)item;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
285
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
286 UiActiveMenuItemList *ls = cxMalloc(
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
287 obj->ctx->allocator,
17
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
288 sizeof(UiActiveMenuItemList));
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
289
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
290 ls->object = obj;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
291 ls->menu = parent;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
292 ls->index = i;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
293 ls->oldcount = 0;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
294 ls->list = il->list;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
295 ls->callback = il->callback;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
296 ls->userdata = il->userdata;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
297
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
298 ls->list->observers = ui_add_observer(
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
299 ls->list->observers,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
300 (ui_callback)ui_update_menuitem_list,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
301 ls);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
302
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
303 ui_update_menuitem_list(NULL, ls);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
304
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
305 return 0;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
306 }
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
307
17
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
308 void ui_update_menuitem_list(UiEvent *event, UiActiveMenuItemList *list) {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
309 Arg args[4];
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
310
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
311 // remove old items
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
312 if(list->oldcount > 0) {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
313 Widget *children;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
314 int nc;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
315
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
316 XtVaGetValues(
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
317 list->menu,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
318 XmNchildren,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
319 &children,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
320 XmNnumChildren,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
321 &nc,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
322 NULL);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
323
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
324 for(int i=0;i<list->oldcount;i++) {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
325 XtDestroyWidget(children[list->index + i]);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
326 }
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
327 }
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
328
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
329 char *str = ui_list_first(list->list);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
330 if(str) {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
331 // add separator
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
332 XtSetArg(args[0], XmNpositionIndex, list->index);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
333 Widget s = XmCreateSeparatorGadget (list->menu, "menu_separator", args, 1);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
334 XtManageChild(s);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
335 }
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
336 int i = 1;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
337 while(str) {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
338 XmString label = XmStringCreateLocalized(str);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
339 XtSetArg(args[0], XmNlabelString, label);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
340 XtSetArg(args[1], XmNpositionIndex, list->index + i);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
341
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
342 Widget mitem = XtCreateManagedWidget(
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
343 "menubutton",
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
344 xmPushButtonWidgetClass,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
345 list->menu,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
346 args,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
347 2);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
348 XmStringFree(label);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
349
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
350 if(list->callback) {
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
351 // TODO: use mempool
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
352 UiEventData *event = malloc(sizeof(UiEventData));
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
353 event->obj = list->object;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
354 event->userdata = list->userdata;
17
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
355 event->callback = list->callback;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
356 event->value = i - 1;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
357
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
358 XtAddCallback(
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
359 mitem,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
360 XmNactivateCallback,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
361 (XtCallbackProc)ui_push_button_callback,
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
362 event);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
363 }
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
364
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
365 str = ui_list_next(list->list);
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
366 i++;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
367 }
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
368
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
369 list->oldcount = i;
db95c0104937 added menu item lists (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 3
diff changeset
370 }
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
371
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
372 void ui_menu_event_wrapper(Widget widget, XtPointer udata, XtPointer cdata) {
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
373 UiEventData *event = udata;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
374 UiEvent e;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
375 e.obj = event->obj;
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
376 e.window = event->obj->window;
52
25e5390cce41 added document tabview (GTK, Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 21
diff changeset
377 e.document = event->obj->ctx->document;
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
378 e.intval = 0;
98
efaae97bd95b added mouse event handler (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 76
diff changeset
379 event->callback(&e, event->userdata);
0
1f419bd32da1 added files
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff changeset
380 }
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
381
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
382
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
383 /*
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
384 * widget menu functions
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
385 */
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
386
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
387 static void ui_popup_handler(Widget widget, XtPointer data, XEvent *event, Boolean *c) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
388 Widget menu = data;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
389 XmMenuPosition(menu, (XButtonPressedEvent *)event);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
390 XtManageChild(menu);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
391
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
392 *c = FALSE;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
393 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
394
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
395 UIMENU ui_contextmenu(UiObject *obj) {
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
396 UiContainer *ct = uic_get_current_container(obj);
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
397 if(ct->current) {
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
398 return ui_contextmenu_w(obj, ct->current);
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
399 } else {
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
400 return NULL; // TODO: warn
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
401 }
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
402 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
403
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
404 UIMENU ui_contextmenu_w(UiObject *obj, UIWIDGET widget) {
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
405 UiContainer *ct = uic_get_current_container(obj);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
406
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
407 Widget menu = XmCreatePopupMenu(widget, "popup_menu", NULL, 0);
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
408 ct->menu = menu;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
409
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
410 XtAddEventHandler(widget, ButtonPressMask, FALSE, ui_popup_handler, menu);
115
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
411
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
412 return menu;
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
413 }
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
414
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
415 void ui_contextmenu_popup(UIMENU menu) {
102fc0b8fe3e improved context menus
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 98
diff changeset
416
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
417 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
418
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
419 void ui_widget_menuitem(UiObject *obj, char *label, ui_callback f, void *userdata) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
420 ui_widget_menuitem_gr(obj, label, f, userdata, -1);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
421 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
422
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
423 void ui_widget_menuitem_gr(UiObject *obj, char *label, ui_callback f, void *userdata, ...) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
424 UiContainer *ct = uic_get_current_container(obj);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
425 if(!ct->menu) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
426 return;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
427 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
428
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
429 // add groups
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
430 CxList *groups = NULL;
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
431 va_list ap;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
432 va_start(ap, userdata);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
433 int group;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
434 while((group = va_arg(ap, int)) != -1) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
435 if(!groups) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
436 groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
437 }
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
438 cxListAdd(groups, &group);
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
439 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
440 va_end(ap);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
441
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
442 // create menuitem
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
443 Arg args[4];
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
444 XmString labelstr = XmStringCreateLocalized(label);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
445 XtSetArg(args[0], XmNlabelString, labelstr);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
446
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
447 Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
448 XtManageChild(item);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
449 XmStringFree(labelstr);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
450 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
451
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
452 void ui_widget_menuitem_st(UiObject *obj, char *stockid, ui_callback f, void *userdata) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
453 ui_widget_menuitem_stgr(obj, stockid, f, userdata, -1);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
454 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
455
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
456 void ui_widget_menuitem_stgr(UiObject *obj, char *stockid, ui_callback f, void *userdata, ...) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
457 UiContainer *ct = uic_get_current_container(obj);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
458 if(!ct->menu) {
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
459 return;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
460 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
461
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
462 // add groups
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
463 CxList *groups = NULL;
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
464 va_list ap;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
465 va_start(ap, userdata);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
466 int group;
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
467 while((group = va_arg(ap, int)) != -1) {
176
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
468 if(!groups) {
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
469 groups = cxArrayListCreate(cxDefaultAllocator, NULL, sizeof(int), 16);
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
470 }
bc63cb601f6d port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 169
diff changeset
471 cxListAdd(groups, &group);
76
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
472 }
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
473 va_end(ap);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
474
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
475 // create menuitem
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
476 UiStockItem *stockItem = ui_get_stock_item(stockid);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
477 Arg args[4];
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
478 XmString labelstr = XmStringCreateLocalized(stockItem->label);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
479 XtSetArg(args[0], XmNlabelString, labelstr);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
480
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
481 Widget item = XmCreatePushButton(ct->menu, "menu_button", args, 1);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
482 XtManageChild(item);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
483 XmStringFree(labelstr);
3782827378ab added context menus (Motif)
Olaf Wintermann <olaf.wintermann@gmail.com>
parents: 52
diff changeset
484 }

mercurial