DO NOT REPLY TO THIS MESSAGE.  INSTEAD, POST ANY RESPONSES TO THE LINK BELOW.

[STR New]

I have attached a patch file that adds the ability to set the window title
on ask.h dialogs and adds the ability to set a timeout for ask.h dialogs
(so that they can conveniently be made to go away after a specified amount
of time).

Special care has been taken to make sure that all original behavior is
exactly the same when not using these features.  Care has also been taken
to match the existing coding and naming style.  The documentation has been
updated as well.

The features are used by setting global variables defined in ask.h (see
the patch file)

The patch is against fltk-2.0.x-r5777, but should apply to any recent
version.

Thanks,
  Davy Durham

Link: http://www.fltk.org/str.php?L1672
Version: 2.0-feature
diff -aur fltk-2.0.x-r5777.orig/src/message.cxx fltk-2.0.x-r5777/src/message.cxx
--- fltk-2.0.x-r5777.orig/src/message.cxx       2007-04-10 05:47:35.000000000 
-0500
+++ fltk-2.0.x-r5777/src/message.cxx    2007-05-09 23:49:22.000000000 -0500
@@ -30,6 +30,7 @@
 #include <fltk/x.h>
 
 #include <fltk/ask.h>
+#include <fltk/run.h>
 #include <fltk/ReturnButton.h>
 #include <fltk/SecretInput.h>
 #include <fltk/string.h>
@@ -69,6 +70,12 @@
   w->window()->make_exec_return(false);
 }
 
+static int timed_out;
+static void timeout_handler(void *w) {
+  timed_out = 1;
+  ((Window *)w)->make_exec_return(false);
+}
+
 #define ICON_W 50
 #define ICON_H 50
 #define BORDER_W 10
@@ -92,6 +99,8 @@
   Group* saved_current_group = Group::current();
   load_theme();
   Window window(3*BORDER_W+ICON_W+INPUT_W, 3*BORDER_H+ICON_H+BUTTON_H);
+  if(message_window_label && message_window_label[0] != 0)
+       window.copy_label(message_window_label);
   window.begin();
 
   // This keeps the icon from resizing.
@@ -178,14 +187,31 @@
   }
 
   window.end();
+
+  timed_out=0;
+  if(message_window_timeout>0) {
+    add_timeout(message_window_timeout,timeout_handler,&window);
+  }
+
   button_number = 0;
   window.exec();
+
+  if(message_window_timeout>0) {
+    remove_timeout(timeout_handler,&window);
+  }
+
   if (istr)
     window.remove(textfield); // don't destroy it yet
   Group::current(saved_current_group);
-  return button_number;
+  return timed_out ? -1 : button_number;
 }
 
+/*! Set this to change the title of message(), alert(), ask(), choice(), etc. 
windows. */
+const char* fltk::message_window_label= NULL;
+
+/*! Set this to a positive value to cause the message(), alert(), ask(), 
choice(), etc. windows to close automatically after this timeout.  If the 
timeout expires, -1 will be returned by the functions that return int. The 
timeout value is in seconds. */
+float fltk::message_window_timeout= 0;
+
 /*! You can change this string to convert fltk to a foreign language. */
 const char* fltk::no = "&No";
 /*! You can change this string to convert fltk to a foreign language. */
@@ -242,6 +268,9 @@
   "No" button and waits for the user to hit a button. The return value
   is 1 if the user hits Yes, 0 if they pick No. The enter key is a
   shortcut for Yes and ESC is a shortcut for No.
+
+  If message_window_timeout is used, then -1 will be returned if the
+  timeout expires.
 */
 int fltk::ask(const char *fmt, ...) {
   if (fltk::beep_on_dialog()) (fltk::beep(BEEP_QUESTION));
@@ -259,6 +288,9 @@
   is hit. If one of the strings begins with the special character '*'
   then the associated button will be the default which is selected
   when the enter key is pressed. ESC is a shortcut for b2.
+
+  If message_window_timeout is used, then -1 will be returned if the
+  timeout expires.
 */
 int fltk::choice(const char*fmt,const char *b0,const char *b1,const char 
*b2,...){
     if (fltk::beep_on_dialog()) (fltk::beep(fltk::BEEP_QUESTION));
@@ -283,7 +315,7 @@
                                 const char* defstr, uchar type) {
   int r = innards("?", defstr ? defstr : "", type,
                  fmt, ap, fltk::cancel, fltk::ok, 0);
-  return r ? textfield->text() : 0;
+  return r>=0 ? textfield->text() : 0;
 }
 
 /*!
@@ -293,6 +325,9 @@
   pointer is only valid until the next time fltk::input() is
   called. Due to back-compatability, the arguments to any printf
   commands in the label are after the default value.
+
+  If message_window_timeout is used, then 0 will be returned if the
+  timeout expires.
 */
 const char* fltk::input(const char *fmt, const char *defstr, ...) {
   if (fltk::beep_on_dialog()) (fltk::beep(fltk::BEEP_QUESTION));
diff -aur fltk-2.0.x-r5777.orig/fltk/ask.h fltk-2.0.x-r5777/fltk/ask.h
--- fltk-2.0.x-r5777.orig/fltk/ask.h    2006-06-14 02:43:46.000000000 -0500
+++ fltk-2.0.x-r5777/fltk/ask.h 2007-05-03 01:34:08.000000000 -0500
@@ -58,6 +58,9 @@
 extern FL_API NamedStyle* icon_style;
 extern FL_API NamedStyle* message_style;
 
+extern FL_API const char* message_window_label;
+extern FL_API float message_window_timeout;
+
 // pointers you can use to change FLTK to a foreign language:
 extern FL_API const char* no;
 extern FL_API const char* yes;
_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to