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.

192 lines
6.2KB

  1. //
  2. // "$Id: subwindow.cxx 8587 2011-04-14 13:04:57Z manolo $"
  3. //
  4. // Nested window test program for the Fast Light Tool Kit (FLTK).
  5. //
  6. // Test to make sure nested windows work.
  7. // Events should be reported for enter/exit and all mouse operations
  8. // Buttons and pop-up menu should work, indicating that mouse positions
  9. // are being correctly translated.
  10. //
  11. // Copyright 1998-2010 by Bill Spitzak and others.
  12. //
  13. // This library is free software; you can redistribute it and/or
  14. // modify it under the terms of the GNU Library General Public
  15. // License as published by the Free Software Foundation; either
  16. // version 2 of the License, or (at your option) any later version.
  17. //
  18. // This library is distributed in the hope that it will be useful,
  19. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  21. // Library General Public License for more details.
  22. //
  23. // You should have received a copy of the GNU Library General Public
  24. // License along with this library; if not, write to the Free Software
  25. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
  26. // USA.
  27. //
  28. // Please report all bugs and problems on the following page:
  29. //
  30. // http://www.fltk.org/str.php
  31. //
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <FL/Fl.H>
  35. #include <FL/Fl_Window.H>
  36. #include <FL/Fl_Toggle_Button.H>
  37. #include <FL/Fl_Menu_Button.H>
  38. #include <FL/Fl_Box.H>
  39. #include <FL/Fl_Input.H>
  40. #ifdef DEBUG
  41. #include <FL/names.h>
  42. #endif
  43. // Define DEBUG_POS for a subwindow positioning test. This will draw
  44. // the last typed character at the cursor position, if no input widget
  45. // currently has the focus.
  46. // Note: The typed character is saved in the derived testwindow class,
  47. // regardless of the definition of DEBUG_POS. Only drawing the character
  48. // depends on this define.
  49. #ifdef DEBUG_POS
  50. #include <FL/fl_draw.H>
  51. #endif
  52. class EnterExit : public Fl_Box {
  53. int handle(int);
  54. public:
  55. EnterExit(int x, int y, int w, int h, const char *l) : Fl_Box(FL_BORDER_BOX,x,y,w,h,l) {}
  56. };
  57. int EnterExit::handle(int e) {
  58. if (e == FL_ENTER) {color(FL_RED); redraw(); return 1;}
  59. else if (e == FL_LEAVE) {color(FL_GRAY); redraw(); return 1;}
  60. else return 0;
  61. }
  62. class testwindow : public Fl_Window {
  63. int handle(int);
  64. void draw();
  65. int cx, cy; char key;
  66. Fl_Cursor crsr;
  67. public:
  68. testwindow(Fl_Boxtype b,int x,int y,const char *l)
  69. : Fl_Window(x,y,l), crsr(FL_CURSOR_DEFAULT) {box(b); key = 0;}
  70. testwindow(Fl_Boxtype b,int x,int y,int w,int h,const char *l)
  71. : Fl_Window(x,y,w,h,l) {box(b); key = 0;}
  72. void use_cursor(Fl_Cursor c) { crsr = c; }
  73. };
  74. void testwindow::draw() {
  75. #ifdef DEBUG
  76. printf("%s : draw\n",label());
  77. #endif
  78. Fl_Window::draw();
  79. #ifdef DEBUG_POS
  80. if (key) fl_draw(&key, 1, cx, cy);
  81. #endif
  82. }
  83. int testwindow::handle(int e) {
  84. #ifdef DEBUG
  85. if (e != FL_MOVE) printf("%s : %s\n",label(),fl_eventnames[e]);
  86. #endif
  87. if (crsr!=FL_CURSOR_DEFAULT) {
  88. if (e == FL_ENTER)
  89. cursor(crsr);
  90. if (e == FL_LEAVE)
  91. cursor(FL_CURSOR_DEFAULT);
  92. }
  93. if (Fl_Window::handle(e)) return 1;
  94. if (e == FL_FOCUS) return 1;
  95. if (e == FL_PUSH) {Fl::focus(this); return 1;}
  96. if (e == FL_KEYBOARD && Fl::event_text()[0]) {
  97. key = Fl::event_text()[0];
  98. cx = Fl::event_x();
  99. cy = Fl::event_y();
  100. redraw();
  101. return 1;
  102. }
  103. return 0;
  104. }
  105. Fl_Menu_Button* popup;
  106. const char* bigmess =
  107. #if 1
  108. "this|is|only|a test"
  109. #else
  110. "item1|item2|item3|item4|item5|"
  111. "submenu/item1|submenu/item2|submenu/item3|submenu/item4|"
  112. "submenu/sub/item1|submenu/sub/item2|submenu/sub/item3|"
  113. "item6|item7|item8|item9|item10|"
  114. "item21|item22|item23|item24|item25|"
  115. "submenu/item21|submenu/item22|submenu/item23|submenu/item24|"
  116. "submenu/sub/item21|submenu/sub/item22|submenu/sub/item23|"
  117. "item36|item37|item38|item39|item310|"
  118. "item31|item32|item33|item34|item35|"
  119. "submenu/item31|submenu/item32|submenu/item33|submenu/item34|"
  120. "submenu/sub/item31|submenu/sub/item32|submenu/sub/item33|"
  121. "item46|item47|item48|item49|item410|"
  122. "item41|item42|item43|item44|item45|"
  123. "submenu/item41|submenu/item42|submenu/item43|submenu/item44|"
  124. "submenu/sub/item41|submenu/sub/item42|submenu/sub/item43|"
  125. "item26|item27|item28|item29|item210|"
  126. "submenu2/item1|submenu2/item2|submenu2/item3|submenu2/item4|"
  127. "submenu2/sub/item1|submenu2/sub/item2|submenu2/sub/item3|"
  128. "item6|item7|item8|item9|item10|"
  129. "item21|item22|item23|item24|item25|"
  130. "submenu2/item21|submenu2/item22|submenu2/item23|submenu2/item24|"
  131. "submenu2/sub/item21|submenu2/sub/item22|submenu2/sub/item23|"
  132. "item36|item37|item38|item39|item310|"
  133. "item31|item32|item33|item34|item35|"
  134. "submenu2/item31|submenu2/item32|submenu2/item33|submenu2/item34|"
  135. "submenu2/sub/item31|submenu2/sub/item32|submenu2/sub/item33|"
  136. "item46|item47|item48|item49|item410|"
  137. "item41|item42|item43|item44|item45|"
  138. "submenu2/item41|submenu2/item42|submenu2/item43|submenu2/item44|"
  139. "submenu2/sub/item41|submenu2/sub/item42|submenu2/sub/item43|"
  140. "item26|item27|item28|item29|item210|"
  141. #endif
  142. ;
  143. int main(int argc, char **argv) {
  144. testwindow *window =
  145. new testwindow(FL_UP_BOX,400,400,"outer");
  146. new Fl_Toggle_Button(310,310,80,80,"&outer");
  147. new EnterExit(10,310,80,80,"enterexit");
  148. new Fl_Input(160,310,140,25,"input1:");
  149. new Fl_Input(160,340,140,25,"input2:");
  150. (new Fl_Menu_Button(5,150,80,25,"menu&1"))->add(bigmess);
  151. testwindow *subwindow =
  152. new testwindow(FL_DOWN_BOX,100,100,200,200,"inner");
  153. new Fl_Toggle_Button(110,110,80,80,"&inner");
  154. new EnterExit(10,110,80,80,"enterexit");
  155. (new Fl_Menu_Button(50,20,80,25,"menu&2"))->add(bigmess);
  156. new Fl_Input(55,50,140,25,"input1:");
  157. new Fl_Input(55,80,140,25,"input2:");
  158. subwindow->resizable(subwindow);
  159. window->resizable(subwindow);
  160. subwindow->end();
  161. subwindow->use_cursor(FL_CURSOR_HAND);
  162. (new Fl_Box(FL_NO_BOX,0,0,400,100,
  163. "A child Fl_Window with children of its own may "
  164. "be useful for imbedding controls into a GL or display "
  165. "that needs a different visual. There are bugs with the "
  166. "origins being different between drawing and events, "
  167. "which I hope I have solved."
  168. )) -> align(FL_ALIGN_WRAP);
  169. popup = new Fl_Menu_Button(0,0,400,400);
  170. popup->type(Fl_Menu_Button::POPUP3);
  171. popup->add("This|is|a popup|menu");
  172. popup->add(bigmess);
  173. window->show(argc, argv);
  174. return Fl::run();
  175. }
  176. //
  177. // End of "$Id: subwindow.cxx 8587 2011-04-14 13:04:57Z manolo $".
  178. //