diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dialog.cc | 96 | ||||
-rw-r--r-- | src/dialog.hh | 4 | ||||
-rw-r--r-- | src/dpiapi.c | 4 | ||||
-rw-r--r-- | src/nav.c | 6 | ||||
-rw-r--r-- | src/uicmd.cc | 16 |
5 files changed, 60 insertions, 66 deletions
diff --git a/src/dialog.cc b/src/dialog.cc index 83b9ed8b..484eebc4 100644 --- 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,54 +321,50 @@ void a_Dialog_text_window(const char *title, const char *txt) /*--------------------------------------------------------------------------*/ -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 && *title)) + if (title == NULL || *title == '\0') title = "Dillo: Choice"; - if (!msg) - msg = ""; - - 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 (!nb) { - MSG_ERR("a_Dialog_choice5: No choices.\n"); - return choice5_answer; + + va_start(ap, msg); + for (n = 0; va_arg(ap, char *) != NULL; n++); + va_end(ap); + + if (n == 0) { + MSG_ERR("Dialog_choice: no alternatives.\n"); + return 0; } - ww = 140 + nb*(bw+10); - Fl_Window *window = new Fl_Window(ww,wh,title); + 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); window->set_modal(); window->begin(); - Fl_Group* ib = new Fl_Group(0,0,window->w(),window->h()); + 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); + 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); @@ -376,36 +372,36 @@ int a_Dialog_choice5(const char *title, const char *msg, o->labelcolor(FL_BLUE); o->label("?"); o->show(); - - 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); - - 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); + + 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(choice5_cb, INT2VOIDP(i)); + 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 *) { @@ -443,7 +439,7 @@ int a_Dialog_user_password(const char *title, const char *msg, fl_font(msg_box->labelfont(), msg_box->labelsize()); msg_w -= 6; /* The label doesn't fill the entire box. */ - fl_measure(msg_box->label(), msg_w, msg_h, 0); /* fl_measure wraps at msg_w */ + fl_measure(msg_box->label(), msg_w, msg_h, 0); // fl_measure wraps at msg_w msg_box->size(msg_box->w(), msg_h); window->add(msg_box); diff --git a/src/dialog.hh b/src/dialog.hh index 8b3bc1b7..0a489590 100644 --- a/src/dialog.hh +++ b/src/dialog.hh @@ -9,9 +9,7 @@ typedef void (*UserPasswordCB)(const char *user, const char *password, 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 --git a/src/dpiapi.c b/src/dpiapi.c index d8980a17..4cdde96e 100644 --- a/src/dpiapi.c +++ b/src/dpiapi.c @@ -69,8 +69,8 @@ void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag) 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); @@ -487,9 +487,9 @@ static void Nav_reload_callback(void *data) 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 --git a/src/uicmd.cc b/src/uicmd.cc index 0a1510d2..be2359da 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -503,9 +503,9 @@ static void win_cb (Fl_Widget *w, void *cb_data) { } 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())); @@ -644,9 +644,9 @@ void a_UIcmd_close_all_bw(void *) 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); @@ -890,8 +890,8 @@ static int UIcmd_save_file_check(const char *name) dStr_sprintf(ds, "The file:\n %s (%d Bytes)\nalready exists. What do we do?", name, (int)ss.st_size); - ch = a_Dialog_choice5("Dillo Save: File exists!", ds->str, - "Abort", "Continue", "Rename", NULL, NULL); + ch = a_Dialog_choice("Dillo Save: File exists!", ds->str, + "Abort", "Continue", "Rename", NULL); dStr_free(ds, 1); return ch; } else { |