changeset 2108:67e81478d275

Replaced fl_input() with a custom dialog * avoids sound bell, allows customization (e.g. widgets, keyboard)
author Jorge Arellano Cid <jcid@dillo.org>
date Mo, 27 Jun 2011 20:31:29 -0400
parents a4188b1ca1b2
children 86cc8fe82da0
files dpi/downloads.cc src/dialog.cc
diffstat 2 files changed, 78 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/dpi/downloads.cc	Mo Jun 27 20:59:28 2011 +0000
+++ b/dpi/downloads.cc	Mo Jun 27 20:31:29 2011 -0400
@@ -31,7 +31,6 @@
 
 #include <FL/Fl.H>
 #include <FL/fl_draw.H>
-#include <FL/fl_ask.H>
 #include <FL/Fl_File_Chooser.H>
 #include <FL/Fl_Window.H>
 #include <FL/Fl_Widget.H>
--- a/src/dialog.cc	Mo Jun 27 20:59:28 2011 +0000
+++ b/src/dialog.cc	Mo Jun 27 20:31:29 2011 -0400
@@ -14,11 +14,11 @@
 #include <math.h> // for rint()
 
 #include <FL/Fl_Window.H>
-#include <FL/fl_ask.H>
 #include <FL/Fl_File_Chooser.H>
 #include <FL/Fl_Return_Button.H>
 #include <FL/Fl_Text_Display.H>
 #include <FL/Fl_Button.H>
+#include <FL/Fl_Return_Button.H>
 #include <FL/Fl_Output.H>
 #include <FL/Fl_Input.H>
 #include <FL/Fl_Secret_Input.H>
@@ -29,6 +29,14 @@
 #include "prefs.h"
 
 /*
+ * Local Data
+ */
+static int input_answer;
+static char *input_str = NULL;
+static int choice5_answer;
+
+
+/*
  * Display a message in a popup window.
  */
 void a_Dialog_msg(const char *msg)
@@ -36,12 +44,80 @@
    fl_message("%s", msg);
 }
 
+
+/*
+ * Callback for a_Dialog_input()
+ */
+static void input_cb(Fl_Widget *button, void *number)
+{
+  input_answer = VOIDP2INT(number);
+  button->window()->hide();
+}
+
 /*
  * Dialog for one line of Input with a message.
+ * avoids the sound bell in fl_input(), and allows customization
+ *
+ * Return value: string on success, NULL upon Cancel or Close window
  */
 const char *a_Dialog_input(const char *msg)
 {
-   return fl_input("%s", "", msg);
+   int ww = 450, wh = 130, gap = 10, ih = 60, bw = 80, bh = 30;
+
+   input_answer = 0;
+
+   Fl_Window *window = new Fl_Window(ww,wh,"Ask");
+   window->set_modal();
+   window->begin();
+    Fl_Group* ib = new Fl_Group(0,0,window->w(),window->h());
+    ib->begin();
+    window->resizable(ib);
+
+    /* '?' Icon */
+    Fl_Box* o = new Fl_Box(gap, gap, ih, ih);
+    o->box(FL_THIN_UP_BOX);
+    o->labelfont(FL_TIMES_BOLD);
+    o->labelsize(34);
+    o->color(FL_WHITE);
+    o->labelcolor(FL_BLUE);
+    o->label("?");
+    o->show();
+
+    Fl_Box *box = new Fl_Box(ih+2*gap,gap,ww-(ih+3*gap),ih/2, msg);
+    box->labelfont(FL_HELVETICA);
+    box->labelsize(14);
+    box->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP|FL_ALIGN_WRAP);
+
+    Fl_Input *input_wid = new Fl_Input(ih+2*gap,gap+ih/2+gap,ww-(ih+3*gap),24);
+    input_wid->labelsize(14);
+    input_wid->textsize(14);
+
+    int xpos = ww-2*(gap+bw), ypos = ih+3*gap;
+    Fl_Return_Button *rb = new Fl_Return_Button(xpos, ypos, bw, bh, "OK");
+    rb->align(FL_ALIGN_INSIDE|FL_ALIGN_CLIP);
+    rb->box(FL_UP_BOX);
+    rb->callback(input_cb, INT2VOIDP(1));
+
+    xpos = ww-(gap+bw);
+    Fl_Button *b = new Fl_Button(xpos, ypos, bw, bh, "Cancel");
+    b->align(FL_ALIGN_INSIDE|FL_ALIGN_CLIP);
+    b->box(FL_UP_BOX);
+    b->callback(input_cb, INT2VOIDP(2));
+
+   window->end();
+
+   window->show();
+   while (window->shown())
+      Fl::wait();
+   _MSG("a_Dialog_input answer = %d\n", input_answer);
+   if (input_answer == 1) {
+      /* we have a string, save it */
+      dFree(input_str);
+      input_str = dStrdup(input_wid->value());
+   }
+   delete window;
+
+   return (input_answer == 1) ? input_str : NULL;
 }
 
 /*
@@ -135,7 +211,6 @@
 }
 
 /*--------------------------------------------------------------------------*/
-static int choice5_answer;
 
 static void choice5_cb(Fl_Widget *button, void *number)
 {