source: rtems-graphics-toolkit/fltk-1.1.10/test/menubar.cxx @ 513eea1

Last change on this file since 513eea1 was 513eea1, checked in by Joel Sherrill <joel.sherrill@…>, on 01/09/10 at 22:43:24

2010-01-08 Joel Sherrill <joel.sherrill@…>

fltk 1.1.10. imported

  • ORIGIN: Updated.
  • Property mode set to 100644
File size: 7.3 KB
Line 
1//
2// "$Id$"
3//
4// Menubar test program for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2005 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_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
40void window_cb(Fl_Widget* w, void*) {
41  puts("window callback called");
42  ((Fl_Window *)w)->hide();
43}
44
45void 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
56void quit_cb(Fl_Widget*, void*) {exit(0);}
57
58Fl_Menu_Item hugemenu[100];
59
60Fl_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  {"E&mpty",0,0,0,FL_SUBMENU},
145    {0},
146  {"&Inactive", 0,      0, 0, FL_MENU_INACTIVE|FL_SUBMENU},
147    {"A very long menu item"},
148    {"A very long menu item"},
149    {0},
150  {"Invisible",0,       0, 0, FL_MENU_INVISIBLE|FL_SUBMENU},
151    {"A very long menu item"},
152    {"A very long menu item"},
153    {0},
154  {"&Huge", 0, 0, (void*)hugemenu, FL_SUBMENU_POINTER},
155  {"button",FL_F+4, 0, 0, FL_MENU_TOGGLE},
156  {0}
157};
158
159Fl_Menu_Item pulldown[] = {
160  {"Red",       FL_ALT+'r'},
161  {"Green",     FL_ALT+'g'},
162  {"Blue",      FL_ALT+'b'},
163  {"Strange",   FL_ALT+'s', 0, 0, FL_MENU_INACTIVE},
164  {"&Charm",    FL_ALT+'c'},
165  {"Truth",     FL_ALT+'t'},
166  {"Beauty",    FL_ALT+'b'},
167  {0}
168};
169
170#define WIDTH 600
171
172Fl_Menu_* menus[4];
173
174class MyWindow : public Fl_Window {
175public:
176  MyWindow(int w, int h, const char *l=0)
177  : Fl_Window(w, h, l) { }
178  int handle(int event) {
179    switch (event) {
180    case FL_ENTER:
181//      puts("ENTER"); break;
182    case FL_LEAVE:
183//      puts("LEAVE"); break;
184      break;
185    }
186//    printf("%d\n", event);
187    return Fl_Window::handle(event);
188  }
189};
190
191
192class MyButton : public Fl_Button {
193public:
194  MyButton(int x, int y,int w, int h, const char *l=0)
195  : Fl_Button(x, y, w, h, l) { }
196  int handle(int event) {
197    switch (event) {
198    case FL_ENTER:
199        puts("ENTER"); break;
200    case FL_LEAVE:
201        puts("LEAVE"); break;
202    }
203    printf("%d\n", event);
204    return Fl_Button::handle(event);
205  }
206};
207
208
209int main(int argc, char **argv) {
210  //Fl::set_color(Fl_Color(15),0,0,128);
211  for (int i=0; i<99; i++) {
212    char buf[100];
213    sprintf(buf,"item %d",i);
214    hugemenu[i].text = strdup(buf);
215  }
216  MyWindow window(WIDTH,400);
217  window.callback(window_cb);
218  Fl_Menu_Bar menubar(0,0,WIDTH,30); menubar.menu(menutable);
219  menubar.callback(test_cb);
220  menus[0] = &menubar;
221  MyButton bb(100, 125, 120, 25, "Erwinn");
222  Fl_Menu_Button mb1(100,100,120,25,"&menubutton"); mb1.menu(pulldown);
223  mb1.tooltip("this is a menu button");
224  mb1.callback(test_cb);
225  menus[1] = &mb1;
226  Fl_Choice ch(300,100,80,25,"&choice:"); ch.menu(pulldown);
227  ch.tooltip("this is a choice menu");
228  ch.callback(test_cb);
229  menus[2] = &ch;
230  Fl_Menu_Button mb(0,0,WIDTH,400,"&popup");
231  mb.type(Fl_Menu_Button::POPUP3);
232  mb.box(FL_NO_BOX);
233  mb.menu(menutable);
234  mb.remove(1); // delete the "File" submenu
235  mb.callback(test_cb);
236  menus[3] = &mb;
237  Fl_Box b(200,200,200,100,"Press right button\nfor a pop-up menu");
238  window.resizable(&mb);
239  window.size_range(300,400,0,400);
240  window.end();
241  window.show(argc, argv);
242  return Fl::run();
243}
244
245//
246// End of "$Id$".
247//
Note: See TracBrowser for help on using the repository browser.