1 | // |
---|
2 | // "$Id: menubar.cxx 7903 2010-11-28 21:06:39Z matt $" |
---|
3 | // |
---|
4 | // Menubar test program for the Fast Light Tool Kit (FLTK). |
---|
5 | // |
---|
6 | // Copyright 1998-2010 by Bill Spitzak and others. |
---|
7 | // |
---|
8 | // This library is free software; you can redistribute it and/or |
---|
9 | // modify it under the terms of the GNU Library General Public |
---|
10 | // License as published by the Free Software Foundation; either |
---|
11 | // version 2 of the License, or (at your option) any later version. |
---|
12 | // |
---|
13 | // This library is distributed in the hope that it will be useful, |
---|
14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | // Library General Public License for more details. |
---|
17 | // |
---|
18 | // You should have received a copy of the GNU Library General Public |
---|
19 | // License along with this library; if not, write to the Free Software |
---|
20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
21 | // USA. |
---|
22 | // |
---|
23 | // Please report all bugs and problems on the following page: |
---|
24 | // |
---|
25 | // http://www.fltk.org/str.php |
---|
26 | // |
---|
27 | |
---|
28 | #include <FL/Fl.H> |
---|
29 | #include <FL/Fl_Box.H> |
---|
30 | #include <FL/Fl_Double_Window.H> |
---|
31 | #include <FL/Fl_Menu_Bar.H> |
---|
32 | #include <FL/Fl_Toggle_Button.H> |
---|
33 | #include <FL/Fl_Menu_Button.H> |
---|
34 | #include <FL/Fl_Choice.H> |
---|
35 | #include <stdio.h> |
---|
36 | #include <stdlib.h> |
---|
37 | #include "../src/flstring.h" |
---|
38 | #include <FL/fl_draw.H> |
---|
39 | |
---|
40 | void window_cb(Fl_Widget* w, void*) { |
---|
41 | puts("window callback called"); |
---|
42 | ((Fl_Double_Window *)w)->hide(); |
---|
43 | } |
---|
44 | |
---|
45 | void test_cb(Fl_Widget* w, void*) { |
---|
46 | Fl_Menu_* mw = (Fl_Menu_*)w; |
---|
47 | const Fl_Menu_Item* m = mw->mvalue(); |
---|
48 | if (!m) |
---|
49 | printf("NULL\n"); |
---|
50 | else if (m->shortcut()) |
---|
51 | printf("%s - %s\n", m->label(), fl_shortcut_label(m->shortcut())); |
---|
52 | else |
---|
53 | printf("%s\n", m->label()); |
---|
54 | } |
---|
55 | |
---|
56 | void quit_cb(Fl_Widget*, void*) {exit(0);} |
---|
57 | |
---|
58 | Fl_Menu_Item hugemenu[100]; |
---|
59 | |
---|
60 | Fl_Menu_Item menutable[] = { |
---|
61 | {"foo",0,0,0,FL_MENU_INACTIVE}, |
---|
62 | {"&File",0,0,0,FL_SUBMENU}, |
---|
63 | {"&Open", FL_ALT+'o', 0, 0, FL_MENU_INACTIVE}, |
---|
64 | {"&Close", 0, 0}, |
---|
65 | {"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER}, |
---|
66 | {"shortcut",'a'}, |
---|
67 | {"shortcut",FL_SHIFT+'a'}, |
---|
68 | {"shortcut",FL_CTRL+'a'}, |
---|
69 | {"shortcut",FL_CTRL+FL_SHIFT+'a'}, |
---|
70 | {"shortcut",FL_ALT+'a'}, |
---|
71 | {"shortcut",FL_ALT+FL_SHIFT+'a'}, |
---|
72 | {"shortcut",FL_ALT+FL_CTRL+'a'}, |
---|
73 | {"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+'a', 0,0, FL_MENU_DIVIDER}, |
---|
74 | {"shortcut",'\r'/*FL_Enter*/}, |
---|
75 | {"shortcut",FL_CTRL+FL_Enter, 0,0, FL_MENU_DIVIDER}, |
---|
76 | {"shortcut",FL_F+1}, |
---|
77 | {"shortcut",FL_SHIFT+FL_F+1}, |
---|
78 | {"shortcut",FL_CTRL+FL_F+1}, |
---|
79 | {"shortcut",FL_SHIFT+FL_CTRL+FL_F+1}, |
---|
80 | {"shortcut",FL_ALT+FL_F+1}, |
---|
81 | {"shortcut",FL_ALT+FL_SHIFT+FL_F+1}, |
---|
82 | {"shortcut",FL_ALT+FL_CTRL+FL_F+1}, |
---|
83 | {"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+FL_F+1, 0,0, FL_MENU_DIVIDER}, |
---|
84 | {"&Submenus", FL_ALT+'S', 0, (void*)"Submenu1", FL_SUBMENU}, |
---|
85 | {"A very long menu item"}, |
---|
86 | {"&submenu",FL_CTRL+'S', 0, (void*)"submenu2", FL_SUBMENU}, |
---|
87 | {"item 1"}, |
---|
88 | {"item 2"}, |
---|
89 | {"item 3"}, |
---|
90 | {"item 4"}, |
---|
91 | {0}, |
---|
92 | {"after submenu"}, |
---|
93 | {0}, |
---|
94 | {0}, |
---|
95 | {"&Edit",FL_F+2,0,0,FL_SUBMENU}, |
---|
96 | {"Undo", FL_ALT+'z', 0}, |
---|
97 | {"Redo", FL_ALT+'r', 0, 0, FL_MENU_DIVIDER}, |
---|
98 | {"Cut", FL_ALT+'x', 0}, |
---|
99 | {"Copy", FL_ALT+'c', 0}, |
---|
100 | {"Paste", FL_ALT+'v', 0}, |
---|
101 | {"Inactive",FL_ALT+'d', 0, 0, FL_MENU_INACTIVE}, |
---|
102 | {"Clear", 0, 0, 0, FL_MENU_DIVIDER}, |
---|
103 | {"Invisible",FL_ALT+'e', 0, 0, FL_MENU_INVISIBLE}, |
---|
104 | {"Preferences",0, 0}, |
---|
105 | {"Size", 0, 0}, |
---|
106 | {0}, |
---|
107 | {"&Checkbox",FL_F+3,0,0,FL_SUBMENU}, |
---|
108 | {"&Alpha", FL_F+2, 0, (void *)1, FL_MENU_TOGGLE}, |
---|
109 | {"&Beta", 0, 0, (void *)2, FL_MENU_TOGGLE}, |
---|
110 | {"&Gamma", 0, 0, (void *)3, FL_MENU_TOGGLE}, |
---|
111 | {"&Delta", 0, 0, (void *)4, FL_MENU_TOGGLE|FL_MENU_VALUE}, |
---|
112 | {"&Epsilon",0, 0, (void *)5, FL_MENU_TOGGLE}, |
---|
113 | {"&Pi", 0, 0, (void *)6, FL_MENU_TOGGLE}, |
---|
114 | {"&Mu", 0, 0, (void *)7, FL_MENU_TOGGLE|FL_MENU_DIVIDER}, |
---|
115 | {"Red", 0, 0, (void *)1, FL_MENU_TOGGLE, 0, 0, 0, 1}, |
---|
116 | {"Black", 0, 0, (void *)1, FL_MENU_TOGGLE|FL_MENU_DIVIDER}, |
---|
117 | {"00", 0, 0, (void *)1, FL_MENU_TOGGLE}, |
---|
118 | {"000", 0, 0, (void *)1, FL_MENU_TOGGLE}, |
---|
119 | {0}, |
---|
120 | {"&Radio",0,0,0,FL_SUBMENU}, |
---|
121 | {"&Alpha", 0, 0, (void *)1, FL_MENU_RADIO}, |
---|
122 | {"&Beta", 0, 0, (void *)2, FL_MENU_RADIO}, |
---|
123 | {"&Gamma", 0, 0, (void *)3, FL_MENU_RADIO}, |
---|
124 | {"&Delta", 0, 0, (void *)4, FL_MENU_RADIO|FL_MENU_VALUE}, |
---|
125 | {"&Epsilon",0, 0, (void *)5, FL_MENU_RADIO}, |
---|
126 | {"&Pi", 0, 0, (void *)6, FL_MENU_RADIO}, |
---|
127 | {"&Mu", 0, 0, (void *)7, FL_MENU_RADIO|FL_MENU_DIVIDER}, |
---|
128 | {"Red", 0, 0, (void *)1, FL_MENU_RADIO}, |
---|
129 | {"Black", 0, 0, (void *)1, FL_MENU_RADIO|FL_MENU_DIVIDER}, |
---|
130 | {"00", 0, 0, (void *)1, FL_MENU_RADIO}, |
---|
131 | {"000", 0, 0, (void *)1, FL_MENU_RADIO}, |
---|
132 | {0}, |
---|
133 | {"&Font",0,0,0,FL_SUBMENU /*, 0, FL_BOLD, 20*/}, |
---|
134 | {"Normal", 0, 0, 0, 0, 0, 0, 14}, |
---|
135 | {"Bold", 0, 0, 0, 0, 0, FL_BOLD, 14}, |
---|
136 | {"Italic", 0, 0, 0, 0, 0, FL_ITALIC, 14}, |
---|
137 | {"BoldItalic",0,0,0, 0, 0, FL_BOLD+FL_ITALIC, 14}, |
---|
138 | {"Small", 0, 0, 0, 0, 0, FL_BOLD+FL_ITALIC, 10}, |
---|
139 | {"Emboss", 0, 0, 0, 0, FL_EMBOSSED_LABEL}, |
---|
140 | {"Engrave", 0, 0, 0, 0, FL_ENGRAVED_LABEL}, |
---|
141 | {"Shadow", 0, 0, 0, 0, FL_SHADOW_LABEL}, |
---|
142 | {"@->", 0, 0, 0, 0, FL_SYMBOL_LABEL}, |
---|
143 | {0}, |
---|
144 | {"&International",0,0,0,FL_SUBMENU}, |
---|
145 | {"Sharp Ess",0x0000df}, |
---|
146 | {"A Umlaut",0x0000c4}, |
---|
147 | {"a Umlaut",0x0000e4}, |
---|
148 | {"Euro currency",FL_COMMAND+0x0020ac}, |
---|
149 | {"the &\xc3\xbc Umlaut"}, // ü |
---|
150 | {"the capital &\xc3\x9c"}, // Ü |
---|
151 | {"convert \xc2\xa5 to &\xc2\xa3"}, // Yen to GBP |
---|
152 | {"convert \xc2\xa5 to &\xe2\x82\xac"}, // Yen to Euro |
---|
153 | {"Hangul character Sios &\xe3\x85\x85"}, |
---|
154 | {"Hangul character Cieuc", 0x003148}, |
---|
155 | {0}, |
---|
156 | {"E&mpty",0,0,0,FL_SUBMENU}, |
---|
157 | {0}, |
---|
158 | {"&Inactive", 0, 0, 0, FL_MENU_INACTIVE|FL_SUBMENU}, |
---|
159 | {"A very long menu item"}, |
---|
160 | {"A very long menu item"}, |
---|
161 | {0}, |
---|
162 | {"Invisible",0, 0, 0, FL_MENU_INVISIBLE|FL_SUBMENU}, |
---|
163 | {"A very long menu item"}, |
---|
164 | {"A very long menu item"}, |
---|
165 | {0}, |
---|
166 | {"&Huge", 0, 0, (void*)hugemenu, FL_SUBMENU_POINTER}, |
---|
167 | {"button",FL_F+4, 0, 0, FL_MENU_TOGGLE}, |
---|
168 | {0} |
---|
169 | }; |
---|
170 | |
---|
171 | Fl_Menu_Item pulldown[] = { |
---|
172 | {"Red", FL_ALT+'r'}, |
---|
173 | {"Green", FL_ALT+'g'}, |
---|
174 | {"Blue", FL_ALT+'b'}, |
---|
175 | {"Strange", FL_ALT+'s', 0, 0, FL_MENU_INACTIVE}, |
---|
176 | {"&Charm", FL_ALT+'c'}, |
---|
177 | {"Truth", FL_ALT+'t'}, |
---|
178 | {"Beauty", FL_ALT+'b'}, |
---|
179 | {0} |
---|
180 | }; |
---|
181 | |
---|
182 | #define WIDTH 700 |
---|
183 | |
---|
184 | Fl_Menu_* menus[4]; |
---|
185 | |
---|
186 | int main(int argc, char **argv) { |
---|
187 | //Fl::set_color(Fl_Color(15),0,0,128); |
---|
188 | for (int i=0; i<99; i++) { |
---|
189 | char buf[100]; |
---|
190 | sprintf(buf,"item %d",i); |
---|
191 | hugemenu[i].text = strdup(buf); |
---|
192 | } |
---|
193 | Fl_Double_Window window(WIDTH,400); |
---|
194 | window.callback(window_cb); |
---|
195 | Fl_Menu_Bar menubar(0,0,WIDTH,30); menubar.menu(menutable); |
---|
196 | menubar.callback(test_cb); |
---|
197 | menus[0] = &menubar; |
---|
198 | Fl_Menu_Button mb1(100,100,120,25,"&menubutton"); mb1.menu(pulldown); |
---|
199 | mb1.tooltip("this is a menu button"); |
---|
200 | mb1.callback(test_cb); |
---|
201 | menus[1] = &mb1; |
---|
202 | Fl_Choice ch(300,100,80,25,"&choice:"); ch.menu(pulldown); |
---|
203 | ch.tooltip("this is a choice menu"); |
---|
204 | ch.callback(test_cb); |
---|
205 | menus[2] = &ch; |
---|
206 | Fl_Menu_Button mb(0,0,WIDTH,400,"&popup"); |
---|
207 | mb.type(Fl_Menu_Button::POPUP3); |
---|
208 | mb.box(FL_NO_BOX); |
---|
209 | mb.menu(menutable); |
---|
210 | mb.remove(1); // delete the "File" submenu |
---|
211 | mb.callback(test_cb); |
---|
212 | menus[3] = &mb; |
---|
213 | Fl_Box b(200,200,200,100,"Press right button\nfor a pop-up menu"); |
---|
214 | window.resizable(&mb); |
---|
215 | window.size_range(300,400,0,400); |
---|
216 | window.end(); |
---|
217 | window.show(argc, argv); |
---|
218 | return Fl::run(); |
---|
219 | } |
---|
220 | |
---|
221 | // |
---|
222 | // End of "$Id: menubar.cxx 7903 2010-11-28 21:06:39Z matt $". |
---|
223 | // |
---|