[patch] modified a_Dialog_choice5 to accept any number alternatives

[email protected]
Newsgroups gmane.comp.web.dillo.devel
Message-ID <20130105225748.GA13666@darkstar>
-5 LOC, nothing is changed visually

_______________________________________________
Dillo-dev mailing list
[email protected]
http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
dialog.patch (text/plain, 7.6 KB)
# HG changeset patch
# Parent eae7e07e4cc4f404d293a316774064e8796a2615

diff -r eae7e07e4cc4 src/dialog.cc
--- a/src/dialog.cc
+++ b/src/dialog.cc
@@ -36,7 +36,7 @@
  */
 static int input_answer;
 static char *input_str = NULL;
-static int choice5_answer;
+static int choice_answer;
 
 
 /*
@@ -321,91 +321,88 @@
 
 /*--------------------------------------------------------------------------*/
 
-static void choice5_cb(Fl_Widget *button, void *number)
+static void choice_cb(Fl_Widget *button, void *number)
 {
-  choice5_answer = VOIDP2INT(number);
-  _MSG("choice5_cb: %d\n", choice5_answer);
+  choice_answer = VOIDP2INT(number);
+  _MSG("choice_cb: %d\n", choice_answer);
   button->window()->hide();
 }
 
 /*
- * Make a question-dialog with a question and up to five alternatives.
- * (if less alternatives, non used parameters must be NULL).
+ * Make a question-dialog with a question and alternatives.
+ * Last parameter must be NULL.
  *
- * Return value: 0 = dialog was cancelled, 1-5 = selected alternative.
+ * Return value: 0 = dialog was cancelled, >0 = selected alternative.
  */
-int a_Dialog_choice5(const char *title, const char *msg,
-                     const char *alt1, const char *alt2, const char *alt3,
-                     const char *alt4, const char *alt5)
+int a_Dialog_choice(const char *title, const char *msg, ...)
 {
-   choice5_answer = 0;
+   va_list ap;
+   int i, n;
 
-   int ww = 440, wh = 120, bw = 50, bh = 45, ih = 50, nb = 0;
-   const char *txt[7];
+   if (title == NULL || *title == '\0')
+      title = "Dillo: Choice";
 
-   if (!(title && *title))
-      title = "Dillo: Choice";
-   if (!msg)
-      msg = "";
+   va_start(ap, msg);
+   for (n = 0; va_arg(ap, char *) != NULL; n++);
+   va_end(ap);
 
-   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)
-      ;
+   if (n == 0) {
+      MSG_ERR("Dialog_choice: no alternatives.\n");
+      return 0;
+   }
 
-   if (!nb) {
-      MSG_ERR("a_Dialog_choice5: No choices.\n");
-      return choice5_answer;
-   }
-   ww = 140 + nb*(bw+10);
+   int gap = 8;
+   int ww = 140 + n * 60, wh = 120;
+   int bw = (ww - gap) / n - gap, bh = 45;
+   int ih = 50;
 
-   Fl_Window *window = new Fl_Window(ww,wh,title);
+   Fl_Window *window = new Fl_Window(ww, wh, title);
    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(10, (wh-bh-ih)/2, 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_Group *ib = new Fl_Group(0, 0, window->w(), window->h());
+   ib->begin();
+   window->resizable(ib);
 
-    Fl_Box *box = new Fl_Box(60,0,ww-60,wh-bh, msg);
-    box->labelfont(FL_HELVETICA);
-    box->labelsize(14);
-    box->align(FL_ALIGN_WRAP);
+   /* '?' Icon */
+   Fl_Box *o = new Fl_Box(10, (wh - bh - ih) / 2, 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_Button *b;
-    int xpos = 0, gap = 8;
-    bw = (ww - gap)/nb - gap;
-    xpos += gap;
-    for (int i=1; i <= nb; ++i) {
-       b = new EnterButton(xpos, wh-bh, bw, bh, txt[i]);
-       b->align(FL_ALIGN_WRAP|FL_ALIGN_CLIP);
-       b->box(FL_UP_BOX);
-       b->callback(choice5_cb, INT2VOIDP(i));
-       xpos += bw + gap;
-       /* TODO: set focus to the *-prefixed alternative */
-    }
+   if (msg != NULL){
+      Fl_Box *box = new Fl_Box(60, 0, ww - 60, wh - bh, msg);
+      box->labelfont(FL_HELVETICA);
+      box->labelsize(14);
+      box->align(FL_ALIGN_WRAP);
+   }
+
+   int xpos = gap;
+   va_start(ap, msg);
+   for (i = 1; i <= n; i++) {
+      Fl_Button *b = new EnterButton(xpos, wh - bh, bw, bh, va_arg(ap, char *));
+      b->align(FL_ALIGN_WRAP | FL_ALIGN_CLIP);
+      b->box(FL_UP_BOX);
+      b->callback(choice_cb, INT2VOIDP(i));
+      xpos += bw + gap;
+      /* TODO: set focus to the *-prefixed alternative */
+   }
+   va_end(ap);
    window->end();
 
    window->show();
    while (window->shown())
       Fl::wait();
-   _MSG("a_Dialog_choice5 answer = %d\n", choice5_answer);
+   _MSG("Dialog_choice answer = %d\n", answer);
    delete window;
 
-   return choice5_answer;
+   return choice_answer;
 }
 
-
 /*--------------------------------------------------------------------------*/
 static void Dialog_user_password_cb(Fl_Widget *button, void *)
 {
diff -r eae7e07e4cc4 src/dialog.hh
--- a/src/dialog.hh
+++ b/src/dialog.hh
@@ -9,9 +9,7 @@
                                void *vp);
 
 void a_Dialog_msg(const char *title, const char *msg);
-int a_Dialog_choice5(const char *title, const char *msg,
-                     const char *alt1, const char *alt2, const char *alt3,
-                     const char *alt4, const char *alt5);
+int a_Dialog_choice(const char *title, const char *msg, ...);
 int a_Dialog_user_password(const char *title, const char *msg,
                            UserPasswordCB cb, void *vp);
 const char *a_Dialog_input(const char *title, const char *msg);
diff -r eae7e07e4cc4 src/dpiapi.c
--- a/src/dpiapi.c
+++ b/src/dpiapi.c
@@ -69,8 +69,8 @@
    alt4 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt4");
    alt5 = a_Dpip_get_attr_l(dpip_tag, dpip_tag_len, "alt5");
 
-   ret = a_Dialog_choice5(title, msg, alt1, alt2, alt3, alt4, alt5);
-   /* As choice5 is modal, call the callback function directly. */
+   ret = a_Dialog_choice(title, msg, alt1, alt2, alt3, alt4, alt5, NULL);
+   /* As choice is modal, call the callback function directly. */
    Dpiapi_dialog_answer_cb(bw, ret);
 
    dFree(alt1); dFree(alt2); dFree(alt3); dFree(alt4); dFree(alt5);
diff -r eae7e07e4cc4 src/nav.c
--- a/src/nav.c
+++ b/src/nav.c
@@ -487,9 +487,9 @@
          confirmed = 1;
       } else if (URL_FLAGS(h_url) & URL_Post) {
          /* Attempt to repost data, let's confirm... */
-         choice = a_Dialog_choice5("Dillo: Repost form?",
-                                   "Repost form data?",
-                                   "No", "Yes", "Cancel", NULL, NULL);
+         choice = a_Dialog_choice("Dillo: Repost form?",
+                                  "Repost form data?",
+                                  "No", "Yes", "Cancel", NULL);
          confirmed = (choice == 2);  /* "Yes" */
       }
 
diff -r eae7e07e4cc4 src/uicmd.cc
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -502,9 +502,9 @@
    }
       
    if (prefs.show_quit_dialog && ntabs > 1)
-      choice = a_Dialog_choice5("Dillo: Close window?",
-                                "Window contains more than one tab.",
-                                "Close", "Cancel", NULL, NULL, NULL);
+      choice = a_Dialog_choice("Dillo: Close window?",
+                               "Window contains more than one tab.",
+                               "Close", "Cancel", NULL);
    if (choice == 1)
       while (ntabs-- > 0)
          a_UIcmd_close_bw(a_UIcmd_get_bw_by_widget(tabs->wizard()->value()));
@@ -643,9 +643,9 @@
    int choice = 1;
 
    if (prefs.show_quit_dialog && a_Bw_num() > 1)
-      choice = a_Dialog_choice5("Dillo: Quit?",
-                                "More than one open tab or window.",
-                                "Quit", "Cancel", NULL, NULL, NULL);
+      choice = a_Dialog_choice("Dillo: Quit?",
+                               "More than one open tab or window.",
+                               "Quit", "Cancel", NULL);
    if (choice == 1)
       while ((bw = a_Bw_get(0)))
          a_UIcmd_close_bw((void*)bw);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.