diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-10-06 18:21:25 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 1998-10-06 18:21:25 +0000 |
| commit | f9039b2ae21988783feae9b362818e7923e82d14 (patch) | |
| tree | 6d6fe3679d73448758f9794e7d4d4f6b22a4adad /test/subwindow.cxx | |
| parent | 67e89232f9ba067825a158734a09e0fa21aacbe3 (diff) | |
Initial revision
git-svn-id: file:///fltk/svn/fltk/trunk@2 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'test/subwindow.cxx')
| -rw-r--r-- | test/subwindow.cxx | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/test/subwindow.cxx b/test/subwindow.cxx new file mode 100644 index 000000000..9644b457d --- /dev/null +++ b/test/subwindow.cxx @@ -0,0 +1,107 @@ +// Test to make sure nested windows work. +// Events should be reported for enter/exit and all mouse operations +// Buttons and pop-up menu should work, indicating that mouse positions +// are being correctly translated. + +#include <stdlib.h> +#include <stdio.h> +#include <FL/Fl.H> +#include <FL/Fl_Window.H> +#include <FL/Fl_Toggle_Button.H> +#include <FL/Fl_Menu_Button.H> +#include <FL/Fl_Box.H> +#include <FL/Fl_Input.H> + +class testwindow : public Fl_Window { + int handle(int); + void draw(); +public: + testwindow(Fl_Boxtype b,int x,int y,const char *l) + : Fl_Window(x,y,l) {box(b);} + testwindow(Fl_Boxtype b,int x,int y,int w,int h,const char *l) + : Fl_Window(x,y,w,h,l) {box(b);} +}; + +void testwindow::draw() { +#ifdef DEBUG + printf("%s : draw\n",label()); +#endif + Fl_Window::draw(); +} + +class EnterExit : public Fl_Box { + int handle(int); +public: + EnterExit(int x, int y, int w, int h, const char *l) : Fl_Box(FL_BORDER_BOX,x,y,w,h,l) {} +}; + +int EnterExit::handle(int e) { + if (e == FL_ENTER) {color(FL_RED); redraw(); return 1;} + else if (e == FL_LEAVE) {color(FL_GRAY); redraw(); return 1;} + else return 0; +} + +#ifdef DEBUG +const char *eventnames[] = { +"zero", +"FL_PUSH", +"FL_RELEASE", +"FL_ENTER", +"FL_LEAVE", +"FL_DRAG", +"FL_FOCUS", +"FL_UNFOCUS", +"FL_KEYBOARD", +"9", +"FL_MOVE", +"FL_SHORTCUT", +"12", +"FL_DEACTIVATE", +"FL_ACTIVATE", +"FL_HIDE", +"FL_SHOW", +"FL_PASTE", +"FL_SELECTIONCLEAR", +}; +#endif + +Fl_Menu_Button* popup; + +int testwindow::handle(int e) { +#ifdef DEBUG + if (e != FL_MOVE) printf("%s : %s\n",label(),eventnames[e]); +#endif + if (Fl_Window::handle(e)) return 1; + // if (e==FL_PUSH) return popup->handle(e); + return 0; +} + +int main(int, char **) { + testwindow *window = + new testwindow(FL_UP_BOX,400,400,"outer"); + new Fl_Toggle_Button(310,310,80,80,"&outer"); + new EnterExit(10,310,80,80,"enterexit"); + new Fl_Input(150,310,150,25,"input:"); + (new Fl_Menu_Button(5,150,80,25,"menu&1"))->add("this|is|only|a test"); + testwindow *subwindow = + new testwindow(FL_DOWN_BOX,100,100,200,200,"inner"); + new Fl_Toggle_Button(110,110,80,80,"&inner"); + new EnterExit(10,110,80,80,"enterexit"); + (new Fl_Menu_Button(50,50,80,25,"menu&2"))->add("this|is|only|a test"); + new Fl_Input(45,80,150,25,"input:"); + subwindow->resizable(subwindow); + window->resizable(subwindow); + subwindow->end(); + (new Fl_Box(FL_NO_BOX,0,0,400,100, + "A child Fl_Window with children of it's own may " + "be useful for imbedding controls into a GL or display " + "that needs a different visual. There are bugs with the " + "origins being different between drawing and events, " + "which I hope I have solved." + )) -> align(FL_ALIGN_WRAP); + popup = new Fl_Menu_Button(0,0,400,400); + popup->type(Fl_Menu_Button::POPUP3); + popup->add("This|is|a popup|menu"); + window->show(); + return Fl::run(); +} |
