diff options
Diffstat (limited to 'src/dialog.cc')
-rw-r--r-- | src/dialog.cc | 202 |
1 files changed, 103 insertions, 99 deletions
diff --git a/src/dialog.cc b/src/dialog.cc index 47af9921..c932118e 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -13,50 +13,27 @@ #include <math.h> // for rint() -#include <fltk/Window.h> -#include <fltk/ask.h> -#include <fltk/file_chooser.h> -#include <fltk/TextBuffer.h> -#include <fltk/ReturnButton.h> -#include <fltk/TextDisplay.h> -#include <fltk/HighlightButton.h> -#include <fltk/WordwrapOutput.h> -#include <fltk/Input.h> -#include <fltk/SecretInput.h> +#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_Output.H> +#include <FL/Fl_Input.H> +#include <FL/Fl_Secret_Input.H> #include "msg.h" #include "dialog.hh" #include "misc.h" #include "prefs.h" -using namespace fltk; - -/* - * Close dialog window. - */ -static void window_close_cb(Widget *, void *vwin) -{ - delete (Window*)vwin; -} - /* * Display a message in a popup window. */ void a_Dialog_msg(const char *msg) { - message("%s", msg); -} - -/* - * Offer a three choice dialog. - * The option string that begins with "*" is the default. - * - * Return: 0, 1 or 2 (esc = 2, window close = 2) - */ -int a_Dialog_choice3(const char *msg, - const char *b0, const char *b1, const char *b2) -{ - return choice(msg, b0, b1, b2); + fl_message("%s", msg); } /* @@ -64,7 +41,7 @@ int a_Dialog_choice3(const char *msg, */ const char *a_Dialog_input(const char *msg) { - return input("%s", "", msg); + return fl_input("%s", "", msg); } /* @@ -72,7 +49,7 @@ const char *a_Dialog_input(const char *msg) */ const char *a_Dialog_passwd(const char *msg) { - return password("%s", "", msg); + return fl_password("%s", "", msg); } /* @@ -83,7 +60,7 @@ const char *a_Dialog_passwd(const char *msg) const char *a_Dialog_save_file(const char *msg, const char *pattern, const char *fname) { - return file_chooser(msg, pattern, fname); + return fl_file_chooser(msg, pattern, fname); } /* @@ -111,69 +88,78 @@ char *a_Dialog_open_file(const char *msg, const char *pattern, const char *fname) { const char *fc_name; -/* - static int icons_loaded = 0; - if (!icons_loaded) - FileIcon::load_system_icons(); -*/ - fc_name = file_chooser(msg, pattern, fname); + + fc_name = fl_file_chooser(msg, pattern, fname); return (fc_name) ? a_Misc_escape_chars(fc_name, "% ") : NULL; } /* + * Close text window. + */ +static void text_window_close_cb(Fl_Widget *, void *vtd) +{ + Fl_Text_Display *td = (Fl_Text_Display *)vtd; + Fl_Text_Buffer *buf = td->buffer(); + + delete (Fl_Window*)td->window(); + delete buf; +} + +/* * Show a new window with the provided text */ void a_Dialog_text_window(const char *txt, const char *title) { - //int wh = 600, ww = 650, bh = 30; int wh = prefs.height, ww = prefs.width, bh = 30; - int lines, line_num_width; - Font *textfont = font(prefs.font_monospace, 0); +// Font *textfont = font(prefs.font_monospace, 0); - Window *window = new Window(ww, wh, title ? title : "Untitled"); - window->callback(window_close_cb, window); - window->begin(); + Fl_Window *window = new Fl_Window(ww, wh, title ? title : "Dillo text"); + Fl_Group::current(0); - TextDisplay *td = new TextDisplay(0,0,ww, wh-bh); - td->buffer()->text(txt); + Fl_Text_Buffer *buf = new Fl_Text_Buffer(); + buf->text(txt); + Fl_Text_Display *td = new Fl_Text_Display(0,0,ww, wh-bh); + td->buffer(buf); + +#if 0 +PORT1.3 if (textfont) td->textfont(textfont); td->textsize((int) rint(13.0 * prefs.font_factor)); fltk::setfont(td->textfont(), td->textsize()); - - lines = td->total_lines(); - line_num_width = 2; - while (lines /= 10) - ++line_num_width; - line_num_width = (int)(line_num_width * fltk::getwidth("0")); - td->linenumber_width(line_num_width); +#else + td->textfont(FL_COURIER); + td->textsize((int) rint(13.0 * prefs.font_factor)); +#endif /* enable wrapping lines; text uses entire width of window */ td->wrap_mode(true, false); - /* WORKAROUND: FLTK may not display all the lines without this */ - td->resize(ww+1,wh-bh); + window->add(td); - ReturnButton *b = new ReturnButton (0, wh-bh, ww, bh, "Close"); - b->callback(window_close_cb, window); + Fl_Return_Button *b = new Fl_Return_Button (0, wh-bh, ww, bh, "Close"); + b->callback(text_window_close_cb, td); + window->add(b); + window->callback(text_window_close_cb, td); window->resizable(td); - window->end(); window->show(); } /*--------------------------------------------------------------------------*/ static int choice5_answer; -static void choice5_cb(Widget *button, void *number) +static void choice5_cb(Fl_Widget *button, void *number) { choice5_answer = VOIDP2INT(number); _MSG("choice5_cb: %d\n", choice5_answer); - button->window()->make_exec_return(true); + button->window()->hide(); } /* - * Make a question-dialog with a question and some alternatives. + * Make a question-dialog with a question and up to five alternatives. + * (if less alternatives, non used parameters must be NULL). + * * Return value: 0 = dialog was cancelled, 1-5 = selected alternative. */ int a_Dialog_choice5(const char *QuestionTxt, @@ -182,42 +168,54 @@ int a_Dialog_choice5(const char *QuestionTxt, { choice5_answer = 0; - int ww = 440, wh = 150, bw = 50, bh = 45, nb = 0; + int ww = 440, wh = 120, bw = 50, bh = 45, ih = 50, 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) ; + for (int i=1; txt[i]; ++i, ++nb); + ww = 140 + nb*(bw+10); - Window *window = new Window(ww,wh,"Choice5"); + Fl_Window *window = new Fl_Window(ww,wh,"Choice5"); window->begin(); - Group* ib = new Group(0,0,window->w(),window->h()); + Fl_Group* ib = new Fl_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); + /* '?' 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_Box *box = new Fl_Box(60,0,ww-60,wh-bh, QuestionTxt); + box->labelfont(FL_HELVETICA); box->labelsize(14); + box->align(FL_ALIGN_WRAP); - HighlightButton *b; + Fl_Button *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 = new Fl_Button(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 */ } window->end(); - //window->hotspot(box); - window->exec(); - delete window; - _MSG("Choice5 answer = %d\n", choice5_answer); + window->show(); + while (window->shown()) + Fl::wait(); + _MSG("a_Dialog_choice5 answer = %d\n", choice5_answer); return choice5_answer; } @@ -227,11 +225,14 @@ int a_Dialog_choice5(const char *QuestionTxt, /* * ret: 0 = Cancel, 1 = OK */ -static void Dialog_user_password_cb(Widget *button, void *vIntPtr) +static void Dialog_user_password_cb(Fl_Widget *button, void *vIntPtr) { +#if 0 +PORT1.3 int ret = VOIDP2INT(vIntPtr); _MSG("Dialog_user_password_cb: %d\n", ret); button->window()->make_exec_return(ret); +#endif } /* @@ -241,43 +242,45 @@ static void Dialog_user_password_cb(Widget *button, void *vIntPtr) */ int a_Dialog_user_password(const char *message, UserPasswordCB cb, void *vp) { - int ok, + int ok = 0, window_w = 300, window_h = 280, input_x = 80, input_w = 200, input_h = 30, button_y = 230, button_h = 30; - Window *window = - new Window(window_w,window_h,"User/Password"); + Fl_Window *window = + new Fl_Window(window_w,window_h,"User/Password"); window->begin(); /* message */ - WordwrapOutput *message_output = - new WordwrapOutput(20,20,window_w-40,100); - message_output->box(DOWN_BOX); - message_output->text(message); - message_output->textfont(HELVETICA_BOLD_ITALIC); + Fl_Output *message_output = + new Fl_Output(20,20,window_w-40,100); + /* BUG type() not tested */ + message_output->type(FL_NORMAL_OUTPUT | FL_INPUT_WRAP); + message_output->box(FL_DOWN_BOX); + message_output->value(message); + message_output->textfont(FL_HELVETICA_BOLD_ITALIC); message_output->textsize(14); /* inputs */ - Input *user_input = - new Input(input_x,140,input_w,input_h,"User"); + Fl_Input *user_input = + new Fl_Input(input_x,140,input_w,input_h,"User"); user_input->labelsize(14); user_input->textsize(14); - SecretInput *password_input = - new SecretInput(input_x,180,input_w,input_h,"Password"); + Fl_Secret_Input *password_input = + new Fl_Secret_Input(input_x,180,input_w,input_h,"Password"); password_input->labelsize(14); password_input->textsize(14); /* "OK" button */ - Button *ok_button = - new Button(200,button_y,50,button_h,"OK"); + Fl_Button *ok_button = + new Fl_Button(200,button_y,50,button_h,"OK"); ok_button->labelsize(14); ok_button->callback(Dialog_user_password_cb); ok_button->user_data(INT2VOIDP(1)); /* "Cancel" button */ - Button *cancel_button = - new Button(50,button_y,100,button_h,"Cancel"); + Fl_Button *cancel_button = + new Fl_Button(50,button_y,100,button_h,"Cancel"); cancel_button->labelsize(14); cancel_button->callback(Dialog_user_password_cb); cancel_button->user_data(INT2VOIDP(0)); @@ -285,7 +288,8 @@ int a_Dialog_user_password(const char *message, UserPasswordCB cb, void *vp) window->end(); window->size_range(window_w,window_h,window_w,window_h); window->resizable(window); - +#if 0 +PORT1.3 if ((ok = window->exec())) { /* call the callback */ const char *user, *password; @@ -294,7 +298,7 @@ int a_Dialog_user_password(const char *message, UserPasswordCB cb, void *vp) _MSG("a_Dialog_user_passwd: ok = %d\n", ok); (*cb)(user, password, vp); } - +#endif delete window; return ok; |