You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
7.2KB

  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. #include <FL/Fl.H>
  28. #include <FL/Fl_Box.H>
  29. #include <FL/Fl_Double_Window.H>
  30. #include <FL/Fl_Menu_Bar.H>
  31. #include <FL/Fl_Toggle_Button.H>
  32. #include <FL/Fl_Menu_Button.H>
  33. #include <FL/Fl_Choice.H>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include "../src/flstring.h"
  37. #include <FL/fl_draw.H>
  38. void window_cb(Fl_Widget* w, void*) {
  39. puts("window callback called");
  40. ((Fl_Double_Window *)w)->hide();
  41. }
  42. void test_cb(Fl_Widget* w, void*) {
  43. Fl_Menu_* mw = (Fl_Menu_*)w;
  44. const Fl_Menu_Item* m = mw->mvalue();
  45. if (!m)
  46. printf("NULL\n");
  47. else if (m->shortcut())
  48. printf("%s - %s\n", m->label(), fl_shortcut_label(m->shortcut()));
  49. else
  50. printf("%s\n", m->label());
  51. }
  52. void quit_cb(Fl_Widget*, void*) {exit(0);}
  53. Fl_Menu_Item hugemenu[100];
  54. Fl_Menu_Item menutable[] = {
  55. {"foo",0,0,0,FL_MENU_INACTIVE},
  56. {"&File",0,0,0,FL_SUBMENU},
  57. {"&Open", FL_ALT+'o', 0, 0, FL_MENU_INACTIVE},
  58. {"&Close", 0, 0},
  59. {"&Quit", FL_ALT+'q', quit_cb, 0, FL_MENU_DIVIDER},
  60. {"shortcut",'a'},
  61. {"shortcut",FL_SHIFT+'a'},
  62. {"shortcut",FL_CTRL+'a'},
  63. {"shortcut",FL_CTRL+FL_SHIFT+'a'},
  64. {"shortcut",FL_ALT+'a'},
  65. {"shortcut",FL_ALT+FL_SHIFT+'a'},
  66. {"shortcut",FL_ALT+FL_CTRL+'a'},
  67. {"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+'a', 0,0, FL_MENU_DIVIDER},
  68. {"shortcut",'\r'/*FL_Enter*/},
  69. {"shortcut",FL_CTRL+FL_Enter, 0,0, FL_MENU_DIVIDER},
  70. {"shortcut",FL_F+1},
  71. {"shortcut",FL_SHIFT+FL_F+1},
  72. {"shortcut",FL_CTRL+FL_F+1},
  73. {"shortcut",FL_SHIFT+FL_CTRL+FL_F+1},
  74. {"shortcut",FL_ALT+FL_F+1},
  75. {"shortcut",FL_ALT+FL_SHIFT+FL_F+1},
  76. {"shortcut",FL_ALT+FL_CTRL+FL_F+1},
  77. {"shortcut",FL_ALT+FL_SHIFT+FL_CTRL+FL_F+1, 0,0, FL_MENU_DIVIDER},
  78. {"&Submenus", FL_ALT+'S', 0, (void*)"Submenu1", FL_SUBMENU},
  79. {"A very long menu item"},
  80. {"&submenu",FL_CTRL+'S', 0, (void*)"submenu2", FL_SUBMENU},
  81. {"item 1"},
  82. {"item 2"},
  83. {"item 3"},
  84. {"item 4"},
  85. {0},
  86. {"after submenu"},
  87. {0},
  88. {0},
  89. {"&Edit",FL_F+2,0,0,FL_SUBMENU},
  90. {"Undo", FL_ALT+'z', 0},
  91. {"Redo", FL_ALT+'r', 0, 0, FL_MENU_DIVIDER},
  92. {"Cut", FL_ALT+'x', 0},
  93. {"Copy", FL_ALT+'c', 0},
  94. {"Paste", FL_ALT+'v', 0},
  95. {"Inactive",FL_ALT+'d', 0, 0, FL_MENU_INACTIVE},
  96. {"Clear", 0, 0, 0, FL_MENU_DIVIDER},
  97. {"Invisible",FL_ALT+'e', 0, 0, FL_MENU_INVISIBLE},
  98. {"Preferences",0, 0},
  99. {"Size", 0, 0},
  100. {0},
  101. {"&Checkbox",FL_F+3,0,0,FL_SUBMENU},
  102. {"&Alpha", FL_F+2, 0, (void *)1, FL_MENU_TOGGLE},
  103. {"&Beta", 0, 0, (void *)2, FL_MENU_TOGGLE},
  104. {"&Gamma", 0, 0, (void *)3, FL_MENU_TOGGLE},
  105. {"&Delta", 0, 0, (void *)4, FL_MENU_TOGGLE|FL_MENU_VALUE},
  106. {"&Epsilon",0, 0, (void *)5, FL_MENU_TOGGLE},
  107. {"&Pi", 0, 0, (void *)6, FL_MENU_TOGGLE},
  108. {"&Mu", 0, 0, (void *)7, FL_MENU_TOGGLE|FL_MENU_DIVIDER},
  109. {"Red", 0, 0, (void *)1, FL_MENU_TOGGLE, 0, 0, 0, 1},
  110. {"Black", 0, 0, (void *)1, FL_MENU_TOGGLE|FL_MENU_DIVIDER},
  111. {"00", 0, 0, (void *)1, FL_MENU_TOGGLE},
  112. {"000", 0, 0, (void *)1, FL_MENU_TOGGLE},
  113. {0},
  114. {"&Radio",0,0,0,FL_SUBMENU},
  115. {"&Alpha", 0, 0, (void *)1, FL_MENU_RADIO},
  116. {"&Beta", 0, 0, (void *)2, FL_MENU_RADIO},
  117. {"&Gamma", 0, 0, (void *)3, FL_MENU_RADIO},
  118. {"&Delta", 0, 0, (void *)4, FL_MENU_RADIO|FL_MENU_VALUE},
  119. {"&Epsilon",0, 0, (void *)5, FL_MENU_RADIO},
  120. {"&Pi", 0, 0, (void *)6, FL_MENU_RADIO},
  121. {"&Mu", 0, 0, (void *)7, FL_MENU_RADIO|FL_MENU_DIVIDER},
  122. {"Red", 0, 0, (void *)1, FL_MENU_RADIO},
  123. {"Black", 0, 0, (void *)1, FL_MENU_RADIO|FL_MENU_DIVIDER},
  124. {"00", 0, 0, (void *)1, FL_MENU_RADIO},
  125. {"000", 0, 0, (void *)1, FL_MENU_RADIO},
  126. {0},
  127. {"&Font",0,0,0,FL_SUBMENU /*, 0, FL_BOLD, 20*/},
  128. {"Normal", 0, 0, 0, 0, 0, 0, 14},
  129. {"Bold", 0, 0, 0, 0, 0, FL_BOLD, 14},
  130. {"Italic", 0, 0, 0, 0, 0, FL_ITALIC, 14},
  131. {"BoldItalic",0,0,0, 0, 0, FL_BOLD+FL_ITALIC, 14},
  132. {"Small", 0, 0, 0, 0, 0, FL_BOLD+FL_ITALIC, 10},
  133. {"Emboss", 0, 0, 0, 0, FL_EMBOSSED_LABEL},
  134. {"Engrave", 0, 0, 0, 0, FL_ENGRAVED_LABEL},
  135. {"Shadow", 0, 0, 0, 0, FL_SHADOW_LABEL},
  136. {"@->", 0, 0, 0, 0, FL_SYMBOL_LABEL},
  137. {0},
  138. {"&International",0,0,0,FL_SUBMENU},
  139. {"Sharp Ess",0x0000df},
  140. {"A Umlaut",0x0000c4},
  141. {"a Umlaut",0x0000e4},
  142. {"Euro currency",FL_COMMAND+0x0020ac},
  143. {"the &\xc3\xbc Umlaut"}, // &uuml;
  144. {"the capital &\xc3\x9c"}, // &Uuml;
  145. {"convert \xc2\xa5 to &\xc2\xa3"}, // Yen to GBP
  146. {"convert \xc2\xa5 to &\xe2\x82\xac"}, // Yen to Euro
  147. {"Hangul character Sios &\xe3\x85\x85"},
  148. {"Hangul character Cieuc", 0x003148},
  149. {0},
  150. {"E&mpty",0,0,0,FL_SUBMENU},
  151. {0},
  152. {"&Inactive", 0, 0, 0, FL_MENU_INACTIVE|FL_SUBMENU},
  153. {"A very long menu item"},
  154. {"A very long menu item"},
  155. {0},
  156. {"Invisible",0, 0, 0, FL_MENU_INVISIBLE|FL_SUBMENU},
  157. {"A very long menu item"},
  158. {"A very long menu item"},
  159. {0},
  160. {"&Huge", 0, 0, (void*)hugemenu, FL_SUBMENU_POINTER},
  161. {"button",FL_F+4, 0, 0, FL_MENU_TOGGLE},
  162. {0}
  163. };
  164. Fl_Menu_Item pulldown[] = {
  165. {"Red", FL_ALT+'r'},
  166. {"Green", FL_ALT+'g'},
  167. {"Blue", FL_ALT+'b'},
  168. {"Strange", FL_ALT+'s', 0, 0, FL_MENU_INACTIVE},
  169. {"&Charm", FL_ALT+'c'},
  170. {"Truth", FL_ALT+'t'},
  171. {"Beauty", FL_ALT+'b'},
  172. {0}
  173. };
  174. #define WIDTH 700
  175. Fl_Menu_* menus[4];
  176. int main(int argc, char **argv) {
  177. //Fl::set_color(Fl_Color(15),0,0,128);
  178. for (int i=0; i<99; i++) {
  179. char buf[100];
  180. sprintf(buf,"item %d",i);
  181. hugemenu[i].text = strdup(buf);
  182. }
  183. Fl_Double_Window window(WIDTH,400);
  184. window.callback(window_cb);
  185. Fl_Menu_Bar menubar(0,0,WIDTH,30); menubar.menu(menutable);
  186. menubar.callback(test_cb);
  187. menus[0] = &menubar;
  188. Fl_Menu_Button mb1(100,100,120,25,"&menubutton"); mb1.menu(pulldown);
  189. mb1.tooltip("this is a menu button");
  190. mb1.callback(test_cb);
  191. menus[1] = &mb1;
  192. Fl_Choice ch(300,100,80,25,"&choice:"); ch.menu(pulldown);
  193. ch.tooltip("this is a choice menu");
  194. ch.callback(test_cb);
  195. menus[2] = &ch;
  196. Fl_Menu_Button mb(0,0,WIDTH,400,"&popup");
  197. mb.type(Fl_Menu_Button::POPUP3);
  198. mb.box(FL_NO_BOX);
  199. mb.menu(menutable);
  200. mb.remove(1); // delete the "File" submenu
  201. mb.callback(test_cb);
  202. menus[3] = &mb;
  203. Fl_Box b(200,200,200,100,"Press right button\nfor a pop-up menu");
  204. window.resizable(&mb);
  205. window.size_range(300,400,0,400);
  206. window.end();
  207. window.show(argc, argv);
  208. return Fl::run();
  209. }
  210. //
  211. // End of "$Id: menubar.cxx 7903 2010-11-28 21:06:39Z matt $".
  212. //