changeset 171:d6eefa9091ee

- Implemented a_Dialog_choice5(). May be used by dpis and dillo.
author jcid
date Fri, 11 Apr 2008 00:05:19 +0200
parents 6d579cf5dbb2
children 765db4e71128
files ChangeLog src/bw.c src/bw.h src/dialog.cc src/dialog.hh src/dpiapi.c
diffstat 6 files changed, 86 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 10 14:54:37 2008 +0200
+++ b/ChangeLog	Fri Apr 11 00:05:19 2008 +0200
@@ -49,6 +49,7 @@
  - Added a text placeholder: "[IMG]" for img_off mode.
  - Fixed a SEGFAULT bug in http.c (handling of web->url).
  - Fixed handling of #anchors with repush, and other operations.
+ - Implemented a_Dialog_choice5(). May be used by dpis and dillo.
    Patches: Jorge Arellano Cid
 +- Connected signals to <li> elements (fixes links within lists).
  - Enabled text, background-color, panel_size, geometry, fullscreen,
--- a/src/bw.c	Thu Apr 10 14:54:37 2008 +0200
+++ b/src/bw.c	Fri Apr 11 00:05:19 2008 +0200
@@ -73,8 +73,6 @@
    bw->PageUrls = dList_new(8);
    bw->Docs = dList_new(8);
 
-   bw->question_dialog_data = NULL;
-
    bw->num_page_bugs = 0;
    bw->page_bugs = dStr_new("");
 
--- a/src/bw.h	Thu Apr 10 14:54:37 2008 +0200
+++ b/src/bw.h	Fri Apr 11 00:05:19 2008 +0200
@@ -60,10 +60,6 @@
    /* flag for button sens idle function */
    int sens_idle_up;
 
-   /* TODO: remove me */
-   void *question_dialog_data;
-   void *question_dialog_answer;
-
    /* TODO: maybe this fits better in the linkblock.
     * Although having it here avoids having a signal for handling it. */
    int num_page_bugs;
--- a/src/dialog.cc	Thu Apr 10 14:54:37 2008 +0200
+++ b/src/dialog.cc	Fri Apr 11 00:05:19 2008 +0200
@@ -22,7 +22,9 @@
 #include <fltk/CheckButton.h>
 #include <fltk/ReturnButton.h>
 #include <fltk/TextDisplay.h>
+#include <fltk/HighlightButton.h>
 
+#include "msg.h"
 #include "dialog.hh"
 #include "misc.h"
 #include "uicmd.hh"
@@ -222,3 +224,64 @@
    TextFinder *tf = new TextFinder(250, 90, bw);
    tf->show();
 }
+
+
+/*--------------------------------------------------------------------------*/
+static int choice5_answer;
+
+void choice5_cb(Widget *button, void *number)
+{
+  choice5_answer = (int)number;
+  _MSG("choice5_cb: %d\n", choice5_answer);
+  button->window()->make_exec_return(true);
+}
+
+/*
+ * Make a question-dialog with a question and some alternatives.
+ * Return value: 0 = dialog was cancelled, 1-5 = selected alternative.
+ */
+int a_Dialog_choice5(const char *QuestionTxt,
+                     const char *alt1, const char *alt2, const char *alt3,
+                     const char *alt4, const char *alt5)
+{
+   choice5_answer = 0;
+
+   int ww = 440, wh = 150, bw = 50, bh = 45, nb = 0;
+   const char *txt[7];
+
+   txt[0] = txt[6] = NULL;
+   txt[1] = alt1; txt[2] = alt2; txt[3] = alt3;
+   txt[4] = alt4; txt[5] = alt5;
+   for (int i=1; txt[i]; ++i, ++nb);
+
+   Window *window = new Window(ww,wh,"Choice5");
+   window->begin();
+    Group* ib = new Group(0,0,window->w(),window->h());
+    ib->begin();
+    window->resizable(ib);
+
+    Widget *box = new Widget(0,0,ww,wh-bh, QuestionTxt);
+    box->box(DOWN_BOX);
+    box->labelfont(HELVETICA_BOLD_ITALIC);
+    box->labelsize(14);
+
+    HighlightButton *b;
+    int xpos = 0, gap = 8;
+    bw = (ww - gap)/nb - gap;
+    xpos += gap;
+    for (int i=1; i <= nb; ++i) {
+       b = new HighlightButton(xpos, wh-bh, bw, bh, txt[i]);
+       b->align(ALIGN_WRAP|ALIGN_CLIP);
+       b->box(UP_BOX);
+       b->callback(choice5_cb, (void*)i);
+       xpos += bw + gap;
+    }
+   window->end();
+
+   window->exec();
+   window->destroy();
+   _MSG("Choice5 answer = %d\n", choice5_answer);
+
+   return choice5_answer;
+}
+
--- a/src/dialog.hh	Thu Apr 10 14:54:37 2008 +0200
+++ b/src/dialog.hh	Fri Apr 11 00:05:19 2008 +0200
@@ -10,6 +10,9 @@
 void a_Dialog_msg(const char *msg);
 int a_Dialog_choice3(const char *msg,
                      const char *b0, const char *b1, const char *b2);
+int a_Dialog_choice5(const char *QuestionTxt,
+                     const char *alt1, const char *alt2, const char *alt3,
+                     const char *alt4, const char *alt5);
 const char *a_Dialog_input(const char *msg);
 const char *a_Dialog_save_file(const char *msg,
                                const char *pattern, const char *fname);
--- a/src/dpiapi.c	Thu Apr 10 14:54:37 2008 +0200
+++ b/src/dpiapi.c	Fri Apr 11 00:05:19 2008 +0200
@@ -15,6 +15,7 @@
 #include "bw.h"
 #include "capi.h"
 #include "dpiapi.h"  /* for prototypes */
+#include "dialog.hh"
 #include "../dpip/dpip.h"
 
 
@@ -29,24 +30,18 @@
 /*
  * Generic callback function for dpip dialogs.
  */
-//static void Dpiapi_dialog_answer_cb(BrowserWindow *bw)
-//{
-//   DialogAnswer *answer = bw->question_dialog_answer;
-//   char *cmd, numstr[16];
-//
-//   /* make dpip tag with the answer */
-//   snprintf(numstr, 16, "%d", answer->alt_num);
-//   cmd = a_Dpip_build_cmd("cmd=%s to_cmd=%s msg=%s",
-//                          "answer", "dialog", numstr);
-//
-//   /* Send answer */
-//   a_Capi_dpi_send_cmd(NULL, bw, cmd, dialog_server, 0);
-//
-//   /* cleanup */
-//   bw->question_dialog_data = NULL;
-//   dFree(answer->tthis);
-//   bw->question_dialog_answer = NULL;
-//}
+static void Dpiapi_dialog_answer_cb(BrowserWindow *bw, int answer)
+{
+   char *cmd, numstr[16];
+
+   /* make dpip tag with the answer */
+   snprintf(numstr, 16, "%d", answer);
+   cmd = a_Dpip_build_cmd("cmd=%s to_cmd=%s msg=%s",
+                          "answer", "dialog", numstr);
+
+   /* Send answer */
+   a_Capi_dpi_send_cmd(NULL, bw, cmd, dialog_server, 0);
+}
 
 /*
  * Process a dpip "dialog" command from any dpi.
@@ -55,9 +50,10 @@
 {
    char *question, *alt1, *alt2, *alt3, *alt4, *alt5;
    size_t dpip_tag_len;
+   int ret;
 
-   MSG("a_Dpiapi_dialog:\n");
-   MSG("  dpip_tag: %s\n", dpip_tag);
+   _MSG("a_Dpiapi_dialog:\n");
+   _MSG("  dpip_tag: %s\n", dpip_tag);
 
    /* set the module scoped variable */
    dialog_server = server;
@@ -71,10 +67,9 @@
    alt4 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt4");
    alt5 = a_Dpip_get_attr(dpip_tag, dpip_tag_len, "alt5");
 
-   //a_Dialog_question5(
-   //   bw, question, TRUE,
-   //   alt1, alt2, alt3, alt4, alt5,
-   //   Dpiapi_dialog_answer_cb);
+   ret = a_Dialog_choice5(question, alt1, alt2, alt3, alt4, alt5);
+   /* As choice5 is modal, call the callback function directly. */
+   Dpiapi_dialog_answer_cb(bw, ret);
 
    dFree(alt1); dFree(alt2); dFree(alt3); dFree(alt4); dFree(alt5);
    dFree(question);