-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenubar.cxx
293 lines (269 loc) · 10.2 KB
/
menubar.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
//
// "$Id$"
//
// Menubar test program for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2006 by Bill Spitzak and others.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems on the following page:
//
// http://www.fltk.org/str.php
//
// Use compat header for Fl_Menu_Item
#include <FL/Fl_Menu_Item.H>
#include <fltk/run.h>
#include <fltk/events.h>
#include <fltk/Output.h>
#include <fltk/Box.h>
#include <fltk/Window.h>
#include <fltk/MenuBar.h>
#include <fltk/ToggleButton.h>
#include <fltk/PopupMenu.h>
#include <fltk/Choice.h>
#include <fltk/Tooltip.h>
#include <fltk/draw.h>
#include <stdio.h>
#include <stdlib.h>
#include <fltk/string.h>
#ifdef __APPLE__
#include <fltk/SystemMenuBar.h>
#endif
fltk::Window *window;
fltk::Menu* menus[4];
void test_cb(fltk::Widget* w, void*)
{
fltk::Menu* mw = (fltk::Menu*)w;
fltk::Widget* m = mw->item();
if (!m)
printf("NULL\n");
else if (m->shortcut())
printf("%s - %s\n", m->label(), fltk::key_name(m->shortcut()));
else
printf("%s\n", m->label());
if (!strcmp("item 77", m->label())) {
if (mw->find("button")) mw->replace("button", "Spitzak");
else mw->replace("Spitzak", "button");
menus[0]->redraw();
}
m->do_callback();
}
void quit_cb(fltk::Widget*, void*) { exit(0); }
Fl_Menu_Item hugemenu[100];
Fl_Menu_Item menutable[] = {
{"foo",0,0,0,FL_MENU_INACTIVE},
{"&File",0,0,0,FL_SUBMENU},
{"&Open", fltk::COMMAND+'O', 0, 0, FL_MENU_INACTIVE},
{"&Close", 0, 0},
{"&Quit", fltk::COMMAND+'Q', quit_cb, 0, fltk::MENU_DIVIDER},
{"shortcut",'A'},
{"shortcut",fltk::SHIFT+'A'},
{"shortcut",fltk::COMMAND+'A'},
{"shortcut",fltk::COMMAND+fltk::SHIFT+'A'},
{"shortcut",fltk::ACCELERATOR+'A'},
{"shortcut",fltk::ACCELERATOR+fltk::SHIFT+'A'},
{"shortcut",fltk::ACCELERATOR+fltk::COMMAND+'A'},
{"shortcut",fltk::ACCELERATOR+fltk::SHIFT+fltk::COMMAND+'A', 0,0, fltk::MENU_DIVIDER},
{"shortcut",fltk::ReturnKey},
{"shortcut",fltk::COMMAND+fltk::ReturnKey, 0,0, fltk::MENU_DIVIDER},
{"shortcut",fltk::F1Key},
{"shortcut",fltk::SHIFT+fltk::F1Key},
{"shortcut",fltk::COMMAND+fltk::F1Key},
{"shortcut",fltk::SHIFT+fltk::COMMAND+fltk::F1Key},
{"shortcut",fltk::ACCELERATOR+fltk::F1Key},
{"shortcut",fltk::ACCELERATOR+fltk::SHIFT+fltk::F1Key},
{"shortcut",fltk::ACCELERATOR+fltk::COMMAND+fltk::F1Key},
{"shortcut",fltk::ACCELERATOR+fltk::SHIFT+fltk::COMMAND+fltk::F1Key, 0,0, fltk::MENU_DIVIDER},
{"&Submenus", fltk::ACCELERATOR+'S', 0, (void*)"Submenu1", FL_SUBMENU},
{"A very long menu item"},
{"&submenu",fltk::COMMAND+'S', 0, (void*)"submenu2", FL_SUBMENU},
{"item 1"},
{"item 2"},
{"item 3"},
{"item 4"},
{0},
{"after submenu"},
{0},
{0},
{"&Edit",0,0,0,FL_SUBMENU},
{"Undo", fltk::COMMAND+'Z', 0},
{"Redo", fltk::COMMAND+'Y', 0, 0, fltk::MENU_DIVIDER},
{"Cut", fltk::COMMAND+'X', 0},
{"Copy", fltk::COMMAND+'C', 0},
{"Paste", fltk::COMMAND+'V', 0},
{"Inactive",fltk::COMMAND+'D', 0, 0, FL_MENU_INACTIVE},
{"Clear", 0, 0, 0, fltk::MENU_DIVIDER},
{"Invisible",fltk::COMMAND+'E', 0, 0, FL_MENU_INVISIBLE},
{"Preferences",0, 0},
{"Larger", '+', 0, 0},
{"Smaller", '-', 0, 0},
{0},
{"&Checkbox",0,0,0,FL_SUBMENU},
{"&Alpha", 0, 0, (void *)1, fltk::MENU_TOGGLE|FL_MENU_VALUE},
{"&Beta", 0, 0, (void *)2, fltk::MENU_TOGGLE},
{"&Gamma", 0, 0, (void *)3, fltk::MENU_TOGGLE},
{"&Delta", 0, 0, (void *)4, fltk::MENU_TOGGLE|FL_MENU_VALUE},
{"&Epsilon",0, 0, (void *)5, fltk::MENU_TOGGLE},
{"&Pi", 0, 0, (void *)6, fltk::MENU_TOGGLE},
{"&Mu", 0, 0, (void *)7, fltk::MENU_TOGGLE|fltk::MENU_DIVIDER},
{"Red", 0, 0, (void *)1, fltk::MENU_TOGGLE},
{"Black", 0, 0, (void *)1, fltk::MENU_TOGGLE|fltk::MENU_DIVIDER},
{"00", 0, 0, (void *)1, fltk::MENU_TOGGLE},
{"000", 0, 0, (void *)1, fltk::MENU_TOGGLE},
{0},
{"&Radio",0,0,0,FL_SUBMENU},
{"&Alpha", 0, 0, (void *)1, fltk::MENU_RADIO},
{"&Beta", 0, 0, (void *)2, fltk::MENU_RADIO},
{"&Gamma", 0, 0, (void *)3, fltk::MENU_RADIO},
{"&Delta", 0, 0, (void *)4, fltk::MENU_RADIO|FL_MENU_VALUE},
{"&Epsilon",0, 0, (void *)5, fltk::MENU_RADIO},
{"&Pi", 0, 0, (void *)6, fltk::MENU_RADIO},
{"&Mu", 0, 0, (void *)7, fltk::MENU_RADIO|fltk::MENU_DIVIDER},
{"Red", 0, 0, (void *)1, fltk::MENU_RADIO},
{"Black", 0, 0, (void *)1, fltk::MENU_RADIO|fltk::MENU_DIVIDER},
{"00", 0, 0, (void *)1, fltk::MENU_RADIO},
{"000", 0, 0, (void *)1, fltk::MENU_RADIO},
{0},
{"&Font",0,0,0,FL_SUBMENU},
{"Normal", 0, 0},
{"Bold", 0, 0},
{"Italic", 0, 0},
{"BoldItalic",0,0},
{"Small", 0, 0},
{"Large", 0, 0},
{"Emboss", 0, 0},
{"Engrave", 0, 0},
{"Shadow", 0, 0},
{"@->", 0, 0},
{0},
{"E&mpty",0,0,0,FL_SUBMENU},
{0},
{"&Inactive", 0, 0, 0, FL_MENU_INACTIVE|FL_SUBMENU},
{"A very long menu item"},
{"A very long menu item"},
{0},
{"Invisible",0, 0, 0, FL_MENU_INVISIBLE|FL_SUBMENU},
{"A very long menu item"},
{"A very long menu item"},
{0},
{"&Huge", 0, 0, (void*)hugemenu, FL_SUBMENU_POINTER},
// these buttons demonstrates that the menubar can be used as a "toolbar"
{"@[]"}, {"@<->"}, {"@+"},
// it would be nice if checkmarks worked, but they don't:
//{"toggle",0, 0, 0, fltk::MENU_TOGGLE},
{0}
};
Fl_Menu_Item pulldown[] = {
{"Red", fltk::ACCELERATOR+'r'},
{"Green", fltk::ACCELERATOR+'g'},
{"Blue", fltk::ACCELERATOR+'b'},
{"Strange", fltk::ACCELERATOR+'s'},
{"&Charm", fltk::ACCELERATOR+'c'},
{"Truth", fltk::ACCELERATOR+'t'},
{"Beauty", fltk::ACCELERATOR+'b'},
{0}
};
#define WIDTH 600
#define HEIGHT 22 //30 // use 25 for better Windoze look
int main(int argc, char **argv)
{
for (int i=0; i<99; i++) {
char buf[100];
sprintf(buf,"item %d",i);
hugemenu[i].text = newstring(buf);
}
fltk::Window window(WIDTH,400);
window.color(fltk::WHITE);
window.tooltip("Press right button\nfor a pop-up menu");
window.begin();
fltk::MenuBar menubar(0,0,WIDTH,HEIGHT); menubar.menu(menutable);
menubar.find("&Font/Normal")->labelfont(fltk::HELVETICA);
menubar.find("&Font/Bold")->labelfont(fltk::HELVETICA_BOLD);
menubar.find("&Font/Italic")->labelfont(fltk::HELVETICA_ITALIC);
menubar.find("&Font/BoldItalic")->labelfont(fltk::HELVETICA_BOLD_ITALIC);
menubar.find("&Font/Small")->labelsize(10);
menubar.find("&Font/Large")->labelsize(24);
menubar.find("&Font/Emboss")->labeltype(fltk::EMBOSSED_LABEL);
menubar.find("&Font/Engrave")->labeltype(fltk::ENGRAVED_LABEL);
menubar.find("&Font/Shadow")->labeltype(fltk::SHADOW_LABEL);
menubar.find("&Font/@->")->labeltype(fltk::SYMBOL_LABEL);
menubar.find("&Checkbox/Red")->labelcolor(fltk::RED); // label text red
menubar.find("&Checkbox/Red")->selection_textcolor(fltk::RED); // label text red when selected
menubar.find("&Checkbox/Red")->textcolor(fltk::RED); // check mark red
menubar.find("&Checkbox/Black")->labelcolor(fltk::BLACK);
menubar.find("&Checkbox/Black")->selection_textcolor(fltk::BLACK);
menubar.find("&Checkbox/Black")->textcolor(fltk::BLACK);
menubar.find("&Radio/Red")->labelcolor(fltk::RED);
menubar.find("&Radio/Red")->selection_textcolor(fltk::RED);
menubar.find("&Radio/Red")->textcolor(fltk::RED);
menubar.find("&Radio/Black")->labelcolor(fltk::BLACK);
menubar.find("&Radio/Black")->selection_textcolor(fltk::BLACK);
menubar.find("&Radio/Black")->textcolor(fltk::BLACK);
//menubar.find("&Huge/item 69")->deactivate();
menubar.callback(test_cb);
menubar.tooltip("This is a menu bar");
menus[0] = &menubar;
fltk::PopupMenu mb1(100,100,120,25,"&menubutton"); mb1.menu(pulldown);
mb1.callback(test_cb);
mb1.tooltip("This is a menu button");
menus[1] = &mb1;
fltk::Choice ch(300,100,90,25,"&choice:"); ch.menu(pulldown);
ch.callback(test_cb);
ch.tooltip("This is a choice");
menus[2] = &ch;
fltk::PopupMenu mb(0,25,WIDTH,400-HEIGHT/*,"&popup"*/);
mb.type(fltk::PopupMenu::POPUP3);
mb.menu(menutable);
mb.callback(test_cb);
menus[3] = &mb;
window.resizable(&mb);
window.size_range(300,20);
window.end();
window.show(argc, argv);
#ifdef __APPLE__
fltk::SystemMenuBar sysmb(0, 0, 1, 1);
sysmb.menu(menutable);
sysmb.find("&Font/Normal")->labelfont(fltk::HELVETICA);
sysmb.find("&Font/Bold")->labelfont(fltk::HELVETICA_BOLD);
sysmb.find("&Font/Italic")->labelfont(fltk::HELVETICA_ITALIC);
sysmb.find("&Font/BoldItalic")->labelfont(fltk::HELVETICA_BOLD_ITALIC);
sysmb.find("&Font/Small")->labelsize(10);
sysmb.find("&Font/Large")->labelsize(24);
sysmb.find("&Font/Emboss")->labeltype(fltk::EMBOSSED_LABEL);
sysmb.find("&Font/Engrave")->labeltype(fltk::ENGRAVED_LABEL);
sysmb.find("&Font/Shadow")->labeltype(fltk::SHADOW_LABEL);
sysmb.find("&Font/@->")->labeltype(fltk::SYMBOL_LABEL);
sysmb.find("&Checkbox/Red")->labelcolor(fltk::RED); // label text red
sysmb.find("&Checkbox/Red")->selection_textcolor(fltk::RED); // label text red when selected
sysmb.find("&Checkbox/Red")->textcolor(fltk::RED); // check mark red
sysmb.find("&Checkbox/Black")->labelcolor(fltk::BLACK);
sysmb.find("&Checkbox/Black")->selection_textcolor(fltk::BLACK);
sysmb.find("&Checkbox/Black")->textcolor(fltk::BLACK);
sysmb.find("&Radio/Red")->labelcolor(fltk::RED);
sysmb.find("&Radio/Red")->selection_textcolor(fltk::RED);
sysmb.find("&Radio/Red")->textcolor(fltk::RED);
sysmb.find("&Radio/Black")->labelcolor(fltk::BLACK);
sysmb.find("&Radio/Black")->selection_textcolor(fltk::BLACK);
sysmb.find("&Radio/Black")->textcolor(fltk::BLACK);
sysmb.callback(test_cb);
sysmb.layout();
#endif
return fltk::run();
}
//
// End of "$Id$".
//