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 "container.h" |
38 #include "../common/context.h" |
38 #include "../common/context.h" |
|
39 #include "../common/menu.h" |
39 #include "../ui/window.h" |
40 #include "../ui/window.h" |
40 |
41 |
41 #include <cx/linked_list.h> |
42 #include <cx/linked_list.h> |
42 #include <cx/array_list.h> |
43 #include <cx/array_list.h> |
43 |
44 |
|
45 |
|
46 static ui_menu_add_f createMenuItem[] = { |
|
47 /* UI_MENU */ add_menu_widget, |
|
48 /* UI_MENU_ITEM */ add_menuitem_widget, |
|
49 /* UI_MENU_CHECK_ITEM */ add_checkitem_widget, |
|
50 /* UI_MENU_RADIO_ITEM */ add_radioitem_widget, |
|
51 /* UI_MENU_ITEM_LIST */ add_menuitem_list_widget, |
|
52 /* UI_MENU_CHECKITEM_LIST */ add_menuitem_list_widget, |
|
53 /* UI_MENU_RADIOITEM_LIST */ add_menuitem_list_widget, |
|
54 /* UI_MENU_SEPARATOR */ add_menuseparator_widget |
|
55 }; |
|
56 |
|
57 void ui_create_menubar(UiObject *obj, Widget window) { |
|
58 UiMenu *menus_begin = uic_get_menu_list(); |
|
59 if(!menus_begin) { |
|
60 return; |
|
61 } |
|
62 |
|
63 Widget menubar = XmCreateMenuBar(window, "menubar", NULL, 0); |
|
64 XtManageChild(menubar); |
|
65 |
|
66 UiMenu *ls = menus_begin; |
|
67 while(ls) { |
|
68 UiMenu *menu = ls; |
|
69 add_menu_widget(menubar, 0, &menu->item, obj); |
|
70 ls = (UiMenu*)ls->item.next; |
|
71 } |
|
72 } |
|
73 |
|
74 void ui_add_menu_items(Widget parent, int i, UiMenu *menu, UiObject *obj) { |
|
75 UiMenuItemI *it = menu->items_begin; |
|
76 int index = 0; |
|
77 while(it) { |
|
78 createMenuItem[it->type](parent, index, it, obj); |
|
79 it = it->next; |
|
80 index++; |
|
81 } |
|
82 } |
|
83 |
|
84 void add_menu_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { |
|
85 UiMenu *menu = (UiMenu*)item; |
|
86 Arg args[4]; |
|
87 int n = 0; |
|
88 |
|
89 XmString s = NULL; |
|
90 if(menu->label) { |
|
91 s = XmStringCreateLocalized((char*)menu->label); |
|
92 XtSetArg(args[n], XmNlabelString, s); n++; |
|
93 } |
|
94 |
|
95 Widget submenu = XmVaCreateSimplePulldownMenu(parent, "menu_pulldown", i, NULL, NULL); |
|
96 XtSetArg(args[n], XmNsubMenuId, submenu); n++; |
|
97 Widget menuItem = XtCreateManagedWidget( |
|
98 "menuitem", |
|
99 xmCascadeButtonWidgetClass, |
|
100 parent, |
|
101 args, |
|
102 n); |
|
103 |
|
104 |
|
105 if(s) { |
|
106 XmStringFree(s); |
|
107 } |
|
108 |
|
109 ui_add_menu_items(submenu, i, menu, obj); |
|
110 } |
|
111 |
|
112 void add_menuitem_widget(Widget parent, int i, UiMenuItemI *item, UiObject *obj) { |
|
113 UiMenuItem *it = (UiMenuItem*)item; |
|
114 |
|
115 XmString s = NULL; |
|
116 Arg args[4]; |
|
117 int n = 0; |
|
118 if(it->label) { |
|
119 s = XmStringCreateLocalized((char*)it->label); |
|
120 XtSetArg(args[n], XmNlabelString, s); n++; |
|
121 } |
|
122 |
|
123 Widget mitem = XtCreateManagedWidget( |
|
124 "menubutton", |
|
125 xmPushButtonWidgetClass, |
|
126 parent, |
|
127 args, |
|
128 n); |
|
129 if(s) { |
|
130 XmStringFree(s); |
|
131 } |
|
132 } |
|
133 |
|
134 void add_menuseparator_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
|
135 |
|
136 } |
|
137 |
|
138 void add_checkitem_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
|
139 |
|
140 } |
|
141 |
|
142 void add_radioitem_widget(Widget p, int index, UiMenuItemI *item, UiObject *obj) { |
|
143 |
|
144 } |
|
145 |
|
146 void add_checkitemnv_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
|
147 |
|
148 } |
|
149 |
|
150 void add_menuitem_list_widget(Widget p, int i, UiMenuItemI *item, UiObject *obj) { |
|
151 |
|
152 } |