summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2014-09-26 23:58:05 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2014-09-26 23:58:05 +0000
commiteb1af07952d3cfbe8d00037c481e30ad72160c12 (patch)
tree212c01562a5bef43f95f85926273055af632787c
parent5899b2cc6d024b311b89a36d810dc246fd778be4 (diff)
Add Fl_Window::wait_for_expose() and test program (STR #3124).
Also modified .gitignore, svn-properties, Makefile and CMake-Files. Todo: test/twowin.cxx and test/windowfocus.cxx need to be added to ide files (MS VC++ and Xcode). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10339 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--.gitignore1
-rw-r--r--FL/Fl_Window.H4
-rw-r--r--src/Fl_Window.cxx52
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/Makefile6
-rw-r--r--test/windowfocus.cxx58
6 files changed, 121 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 8c5afaf34..b96fe35e8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -222,6 +222,7 @@
/test/valuators
/test/valuators.cxx
/test/valuators.h
+/test/windowfocus
/test/*.bck
/test/*.exe
/test/*.ilk
diff --git a/FL/Fl_Window.H b/FL/Fl_Window.H
index 4020b8a86..8e2fef7e0 100644
--- a/FL/Fl_Window.H
+++ b/FL/Fl_Window.H
@@ -486,6 +486,10 @@ public:
\see virtual void Fl_Window::show()
*/
void show(int argc, char **argv);
+
+ // Enables synchronous show(), docs in Fl_Window.cxx
+ void wait_for_expose();
+
/**
Makes the window completely fill one or more screens, without any
window manager border visible. You must use fullscreen_off() to
diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx
index 5c2f5d6d7..ba9f7fef3 100644
--- a/src/Fl_Window.cxx
+++ b/src/Fl_Window.cxx
@@ -397,6 +397,58 @@ void Fl_Window::free_icons() {
#endif
}
+/**
+ Waits for the window to be fully displayed after calling show().
+
+ Fl_Window::show() is not guaranteed to show and draw the window on
+ all platforms immediately. Instead this is done in the background;
+ particularly on X11 this will take a few messages (client server
+ roundtrips) to display the window.
+
+ Usually this small delay doesn't matter, but in some cases you may
+ want to have the window instantiated and displayed synchronously.
+
+ Currently (as of FLTK 1.3.3) this method only has an effect on X11.
+ On Windows and Mac OS X show() is always synchronous. If you want to
+ write portable code and need this synchronous show() feature, add
+ win->wait_for_expose() on all platforms, FLTK will just do the
+ right thing.
+
+ This method can be used for displaying splash screens before
+ calling Fl::run() or for having exact control over which window
+ has focus after calling show().
+
+ If the window is not shown(), this method does nothing.
+
+ \see virtual void Fl_Window::show()
+
+ Example code for displaying a window before calling Fl::run()
+
+ \code
+ Fl_Double_Window win = new Fl_Double_Window(...);
+
+ // do more window initialization here ...
+
+ win->show(); // show window
+ win->wait_for_expose(); // wait, until displayed
+ Fl::flush(); // make sure everything gets drawn
+
+ // do more initialization work that needs some time here ...
+
+ Fl::run(); // start FLTK event loop
+ \endcode
+
+ Note that the window will not be responsive until the event loop
+ is started with Fl::run().
+*/
+
+void Fl_Window::wait_for_expose() {
+ if (!shown()) return;
+ while (!i || i->wait_for_expose) {
+ Fl::wait();
+ }
+}
+
//
// End of "$Id$".
//
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 1ec27d35e..616e95777 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -118,9 +118,11 @@ CREATE_EXAMPLE(threads threads.cxx fltk)
CREATE_EXAMPLE(tile tile.cxx fltk)
CREATE_EXAMPLE(tiled_image tiled_image.cxx fltk)
CREATE_EXAMPLE(tree tree.fl fltk)
+CREATE_EXAMPLE(twowin twowin.cxx fltk)
CREATE_EXAMPLE(utf8 utf8.cxx fltk)
CREATE_EXAMPLE(valuators valuators.fl fltk)
CREATE_EXAMPLE(unittests unittests.cxx fltk)
+CREATE_EXAMPLE(windowfocus windowfocus.cxx fltk)
# OpenGL demos...
if(OPENGL_FOUND)
diff --git a/test/Makefile b/test/Makefile
index c972d7d18..f3214683c 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -93,7 +93,8 @@ CPPFILES =\
tree.cxx \
twowin.cxx \
valuators.cxx \
- utf8.cxx
+ utf8.cxx \
+ windowfocus.cxx
ALL = \
unittests$(EXEEXT) \
@@ -163,7 +164,8 @@ ALL = \
twowin$(EXEEXT) \
valuators$(EXEEXT) \
cairotest$(EXEEXT) \
- utf8$(EXEEXT)
+ utf8$(EXEEXT) \
+ windowfocus$(EXEEXT)
GLALL = \
diff --git a/test/windowfocus.cxx b/test/windowfocus.cxx
new file mode 100644
index 000000000..96173ee41
--- /dev/null
+++ b/test/windowfocus.cxx
@@ -0,0 +1,58 @@
+//
+// Cross-window show/focus test program for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2014 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// http://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+#include <FL/Fl.H>
+#include <FL/Fl_Box.H>
+#include <FL/Fl_Double_Window.H>
+#include <FL/Fl_Input.H>
+
+static Fl_Double_Window *win1, *win2;
+static Fl_Input *inp;
+
+static void popup(Fl_Widget *, void *) {
+
+ win2->position(win1->x() + win1->w(), win1->y());
+
+ win2->show();
+ win2->wait_for_expose();
+ inp->take_focus();
+}
+
+int main(int argc, char **argv) {
+
+ win1 = new Fl_Double_Window(300, 200);
+ win1->label("show() focus test");
+
+ Fl_Box *b = new Fl_Box(10, 10, 280, 130);
+ b->label("Type something to pop the subwindow up. "
+ "The focus should stay on the input, "
+ "and you should be able to continue typing.");
+ b->align(FL_ALIGN_WRAP | FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
+
+ inp = new Fl_Input(10, 150, 150, 25);
+ inp->when(FL_WHEN_CHANGED);
+ inp->callback(popup);
+
+ win1->end();
+
+ win2 = new Fl_Double_Window(300, 200);
+ win2->label("window2");
+ win2->end();
+
+ win1->show(argc,argv);
+
+ return Fl::run();
+}