Sun, 15 Dec 2024 11:59:30 +0100
implement motif menu/menu item
0 | 1 | /* |
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
3 | * | |
4 | * Copyright 2014 Olaf Wintermann. All rights reserved. | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are met: | |
8 | * | |
9 | * 1. Redistributions of source code must retain the above copyright | |
10 | * notice, this list of conditions and the following disclaimer. | |
11 | * | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * | |
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | |
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
26 | * POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #include <stdio.h> | |
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 | 32 | |
33 | #include "menu.h" | |
34 | #include "button.h" | |
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 | 38 | #include "../common/context.h" |
416
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
39 | #include "../common/menu.h" |
0 | 40 | #include "../ui/window.h" |
41 | ||
176
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
42 | #include <cx/linked_list.h> |
bc63cb601f6d
port motif code to ucx 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
169
diff
changeset
|
43 | #include <cx/array_list.h> |
0 | 44 | |
416
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
45 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
46 | static ui_menu_add_f createMenuItem[] = { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
47 | /* UI_MENU */ add_menu_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
48 | /* UI_MENU_ITEM */ add_menuitem_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
49 | /* UI_MENU_CHECK_ITEM */ add_checkitem_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
50 | /* UI_MENU_RADIO_ITEM */ add_radioitem_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
51 | /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
52 | /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
53 | /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
54 | /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
55 | }; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
56 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
57 | void ui_create_menubar(UiObject *obj, Widget window) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
58 | UiMenu *menus_begin = uic_get_menu_list(); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
59 | if(!menus_begin) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
60 | return; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
61 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
62 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
63 | Widget menubar = XmCreateMenuBar(window, "menubar", NULL, 0); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
64 | XtManageChild(menubar); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
65 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
66 | UiMenu *ls = menus_begin; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
67 | while(ls) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
68 | UiMenu *menu = ls; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
69 | add_menu_widget(menubar, 0, &menu->item, obj); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
70 | ls = (UiMenu*)ls->item.next; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
71 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
72 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
73 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
74 | void ui_add_menu_items(Widget parent, int i, UiMenu *menu, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
75 | UiMenuItemI *it = menu->items_begin; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
76 | int index = 0; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
77 | while(it) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
78 | createMenuItem[it->type](parent, index, it, obj); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
79 | it = it->next; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
80 | index++; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
81 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
82 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
83 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
84 | void add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
85 | UiMenu *menu = (UiMenu*)item; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
86 | Arg args[4]; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
87 | int n = 0; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
88 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
89 | XmString s = NULL; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
90 | if(menu->label) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
91 | s = XmStringCreateLocalized((char*)menu->label); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
92 | XtSetArg(args[n], XmNlabelString, s); n++; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
93 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
94 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
95 | Widget submenu = XmVaCreateSimplePulldownMenu(parent, "menu_pulldown", i, NULL, NULL); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
96 | XtSetArg(args[n], XmNsubMenuId, submenu); n++; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
97 | Widget menuItem = XtCreateManagedWidget( |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
98 | "menuitem", |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
99 | xmCascadeButtonWidgetClass, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
100 | parent, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
101 | args, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
102 | n); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
103 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
104 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
105 | if(s) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
106 | XmStringFree(s); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
107 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
108 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
109 | ui_add_menu_items(submenu, i, menu, obj); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
110 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
111 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
112 | void add_menuitem_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
113 | UiMenuItem *it = (UiMenuItem*)item; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
114 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
115 | XmString s = NULL; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
116 | Arg args[4]; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
117 | int n = 0; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
118 | if(it->label) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
119 | s = XmStringCreateLocalized((char*)it->label); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
120 | XtSetArg(args[n], XmNlabelString, s); n++; |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
121 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
122 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
123 | Widget mitem = XtCreateManagedWidget( |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
124 | "menubutton", |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
125 | xmPushButtonWidgetClass, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
126 | parent, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
127 | args, |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
128 | n); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
129 | if(s) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
130 | XmStringFree(s); |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
131 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
132 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
133 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
134 | void add_menuseparator_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
135 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
136 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
137 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
138 | void add_checkitem_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
139 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
140 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
141 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
142 | void add_radioitem_widget(Widget p, int index, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
143 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
144 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
145 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
146 | void add_checkitemnv_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
147 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
148 | } |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
149 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
150 | void add_menuitem_list_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
151 | |
89ad8467c39f
implement motif menu/menu item
Olaf Winermann <olaf.wintermann@gmail.com>
parents:
406
diff
changeset
|
152 | } |