diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/bw.c | 2 | ||||
-rw-r--r-- | src/bw.h | 4 | ||||
-rw-r--r-- | src/dialog.cc | 63 | ||||
-rw-r--r-- | src/dialog.hh | 3 | ||||
-rw-r--r-- | src/dpiapi.c | 43 |
5 files changed, 85 insertions, 30 deletions
@@ -73,8 +73,6 @@ BrowserWindow *a_Bw_new(int width, int height, uint32_t xid) 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(""); @@ -60,10 +60,6 @@ struct _BrowserWindow /* 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; diff --git a/src/dialog.cc b/src/dialog.cc index 9958f8c8..d75fdf07 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -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 @@ void a_Dialog_findtext(BrowserWindow *bw) 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; +} + diff --git a/src/dialog.hh b/src/dialog.hh index 87b10d9b..2ceadc57 100644 --- a/src/dialog.hh +++ b/src/dialog.hh @@ -10,6 +10,9 @@ extern "C" { 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); diff --git a/src/dpiapi.c b/src/dpiapi.c index 68a9fa7d..cf32ed3f 100644 --- a/src/dpiapi.c +++ b/src/dpiapi.c @@ -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 @@ static char *dialog_server = NULL; /* * 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 @@ void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag) { 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 @@ void a_Dpiapi_dialog(BrowserWindow *bw, char *server, char *dpip_tag) 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); |