2 // "$Id: subwindow.cxx 8587 2011-04-14 13:04:57Z manolo $"
4 // Nested window test program for the Fast Light Tool Kit (FLTK).
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.
11 // Copyright 1998-2010 by Bill Spitzak and others.
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.
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.
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
28 // Please report all bugs and problems on the following page:
30 // http://www.fltk.org/str.php
36 #include <FL/Fl_Window.H>
37 #include <FL/Fl_Toggle_Button.H>
38 #include <FL/Fl_Menu_Button.H>
39 #include <FL/Fl_Box.H>
40 #include <FL/Fl_Input.H>
46 // Define DEBUG_POS for a subwindow positioning test. This will draw
47 // the last typed character at the cursor position, if no input widget
48 // currently has the focus.
49 // Note: The typed character is saved in the derived testwindow class,
50 // regardless of the definition of DEBUG_POS. Only drawing the character
51 // depends on this define.
54 #include <FL/fl_draw.H>
57 class EnterExit
: public Fl_Box
{
60 EnterExit(int x
, int y
, int w
, int h
, const char *l
) : Fl_Box(FL_BORDER_BOX
,x
,y
,w
,h
,l
) {}
63 int EnterExit::handle(int e
) {
64 if (e
== FL_ENTER
) {color(FL_RED
); redraw(); return 1;}
65 else if (e
== FL_LEAVE
) {color(FL_GRAY
); redraw(); return 1;}
69 class testwindow
: public Fl_Window
{
75 testwindow(Fl_Boxtype b
,int x
,int y
,const char *l
)
76 : Fl_Window(x
,y
,l
), crsr(FL_CURSOR_DEFAULT
) {box(b
); key
= 0;}
77 testwindow(Fl_Boxtype b
,int x
,int y
,int w
,int h
,const char *l
)
78 : Fl_Window(x
,y
,w
,h
,l
) {box(b
); key
= 0;}
79 void use_cursor(Fl_Cursor c
) { crsr
= c
; }
82 void testwindow::draw() {
84 printf("%s : draw\n",label());
88 if (key
) fl_draw(&key
, 1, cx
, cy
);
92 int testwindow::handle(int e
) {
94 if (e
!= FL_MOVE
) printf("%s : %s\n",label(),fl_eventnames
[e
]);
96 if (crsr
!=FL_CURSOR_DEFAULT
) {
100 cursor(FL_CURSOR_DEFAULT
);
102 if (Fl_Window::handle(e
)) return 1;
103 if (e
== FL_FOCUS
) return 1;
104 if (e
== FL_PUSH
) {Fl::focus(this); return 1;}
105 if (e
== FL_KEYBOARD
&& Fl::event_text()[0]) {
106 key
= Fl::event_text()[0];
115 Fl_Menu_Button
* popup
;
117 const char* bigmess
=
119 "this|is|only|a test"
121 "item1|item2|item3|item4|item5|"
122 "submenu/item1|submenu/item2|submenu/item3|submenu/item4|"
123 "submenu/sub/item1|submenu/sub/item2|submenu/sub/item3|"
124 "item6|item7|item8|item9|item10|"
125 "item21|item22|item23|item24|item25|"
126 "submenu/item21|submenu/item22|submenu/item23|submenu/item24|"
127 "submenu/sub/item21|submenu/sub/item22|submenu/sub/item23|"
128 "item36|item37|item38|item39|item310|"
129 "item31|item32|item33|item34|item35|"
130 "submenu/item31|submenu/item32|submenu/item33|submenu/item34|"
131 "submenu/sub/item31|submenu/sub/item32|submenu/sub/item33|"
132 "item46|item47|item48|item49|item410|"
133 "item41|item42|item43|item44|item45|"
134 "submenu/item41|submenu/item42|submenu/item43|submenu/item44|"
135 "submenu/sub/item41|submenu/sub/item42|submenu/sub/item43|"
136 "item26|item27|item28|item29|item210|"
137 "submenu2/item1|submenu2/item2|submenu2/item3|submenu2/item4|"
138 "submenu2/sub/item1|submenu2/sub/item2|submenu2/sub/item3|"
139 "item6|item7|item8|item9|item10|"
140 "item21|item22|item23|item24|item25|"
141 "submenu2/item21|submenu2/item22|submenu2/item23|submenu2/item24|"
142 "submenu2/sub/item21|submenu2/sub/item22|submenu2/sub/item23|"
143 "item36|item37|item38|item39|item310|"
144 "item31|item32|item33|item34|item35|"
145 "submenu2/item31|submenu2/item32|submenu2/item33|submenu2/item34|"
146 "submenu2/sub/item31|submenu2/sub/item32|submenu2/sub/item33|"
147 "item46|item47|item48|item49|item410|"
148 "item41|item42|item43|item44|item45|"
149 "submenu2/item41|submenu2/item42|submenu2/item43|submenu2/item44|"
150 "submenu2/sub/item41|submenu2/sub/item42|submenu2/sub/item43|"
151 "item26|item27|item28|item29|item210|"
155 int main(int argc
, char **argv
) {
157 new testwindow(FL_UP_BOX
,400,400,"outer");
158 new Fl_Toggle_Button(310,310,80,80,"&outer");
159 new EnterExit(10,310,80,80,"enterexit");
160 new Fl_Input(160,310,140,25,"input1:");
161 new Fl_Input(160,340,140,25,"input2:");
162 (new Fl_Menu_Button(5,150,80,25,"menu&1"))->add(bigmess
);
163 testwindow
*subwindow
=
164 new testwindow(FL_DOWN_BOX
,100,100,200,200,"inner");
165 new Fl_Toggle_Button(110,110,80,80,"&inner");
166 new EnterExit(10,110,80,80,"enterexit");
167 (new Fl_Menu_Button(50,20,80,25,"menu&2"))->add(bigmess
);
168 new Fl_Input(55,50,140,25,"input1:");
169 new Fl_Input(55,80,140,25,"input2:");
170 subwindow
->resizable(subwindow
);
171 window
->resizable(subwindow
);
173 subwindow
->use_cursor(FL_CURSOR_HAND
);
174 (new Fl_Box(FL_NO_BOX
,0,0,400,100,
175 "A child Fl_Window with children of its own may "
176 "be useful for imbedding controls into a GL or display "
177 "that needs a different visual. There are bugs with the "
178 "origins being different between drawing and events, "
179 "which I hope I have solved."
180 )) -> align(FL_ALIGN_WRAP
);
181 popup
= new Fl_Menu_Button(0,0,400,400);
182 popup
->type(Fl_Menu_Button::POPUP3
);
183 popup
->add("This|is|a popup|menu");
185 window
->show(argc
, argv
);
190 // End of "$Id: subwindow.cxx 8587 2011-04-14 13:04:57Z manolo $".