diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/dialog.cc | 89 | ||||
-rw-r--r-- | src/dialog.hh | 1 | ||||
-rw-r--r-- | src/findbar.cc | 188 | ||||
-rw-r--r-- | src/findbar.hh | 38 | ||||
-rw-r--r-- | src/menu.cc | 4 | ||||
-rw-r--r-- | src/ui.cc | 21 | ||||
-rw-r--r-- | src/ui.hh | 4 | ||||
-rw-r--r-- | src/uicmd.cc | 8 |
9 files changed, 253 insertions, 104 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 7107916c..c427152e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -84,6 +84,8 @@ dillo_fltk_SOURCES = \ menu.cc \ dpiapi.c \ dpiapi.h \ - pixmaps.h + pixmaps.h \ + findbar.cc \ + findbar.hh EXTRA_DIST = chg srch diff --git a/src/dialog.cc b/src/dialog.cc index 66bccc61..b9954d1f 100644 --- a/src/dialog.cc +++ b/src/dialog.cc @@ -150,95 +150,6 @@ void a_Dialog_text_window(const char *txt, const char *title) window->show(); } -/* - * Dialog to find text in page. - */ -class TextFinder : public Window { -public: - TextFinder(int ww, int wh, BrowserWindow *bw); - BrowserWindow *bw; - Input *i; - CheckButton *cb; - ReturnButton *findb; - Button *clrb; - Button *clsb; -}; - -/* - * Find next occurrence of input key - */ -static void findtext_search_cb(Widget *, void *vtf) -{ - TextFinder *tf = (TextFinder *)vtf; - const char *key = tf->i->value(); - bool case_sens = tf->cb->value(); - - if (key[0] != '\0') - a_UIcmd_findtext_search(tf->bw, key, case_sens); - -} - -/* - * Find next occurrence of input key - */ -static void findtext_search_cb2(Widget *widget, void *vtf) -{ - /* - * Somehow fltk even regards the first loss of focus for the - * window as a WHEN_ENTER_KEY_ALWAYS event. - */ - if (event_key() == ReturnKey) - findtext_search_cb(widget, vtf); -} - -/* - * Reset search state - */ -static void findtext_clear_cb(Widget *, void *vtf) -{ - TextFinder *tf = (TextFinder *)vtf; - tf->i->value(""); - a_UIcmd_findtext_reset(tf->bw); -} - -/* - * Construct text search window - */ -TextFinder::TextFinder(int ww, int wh, BrowserWindow *bw) : - Window(ww, wh, "unwanted title") -{ - int button_width = 70, ih = 35, bh = 30, gap = 10; - - this->bw = bw; - callback(window_close_cb, this); - - begin(); - i = new Input(0, 0, ww, ih); - i->when(WHEN_ENTER_KEY_ALWAYS); - i->callback(findtext_search_cb2, this); - - cb = new CheckButton(0, ih, ww, wh-ih-bh, "Case-sensitive"); - - findb = new ReturnButton(gap, wh-bh, button_width, bh, "Find"); - findb->callback(findtext_search_cb, this); - - clrb = new Button(button_width+2*gap, wh-bh, button_width, bh, "Clear"); - clrb->callback(findtext_clear_cb, this); - - clsb = new Button(2*button_width+3*gap, wh-bh, button_width, bh, "Close"); - clsb->callback(window_close_cb, this); - end(); - - hotspot(i); // place input widget beneath the cursor -} - -void a_Dialog_findtext(BrowserWindow *bw) -{ - TextFinder *tf = new TextFinder(250, 90, bw); - tf->show(); -} - - /*--------------------------------------------------------------------------*/ static int choice5_answer; diff --git a/src/dialog.hh b/src/dialog.hh index de189175..98852a2d 100644 --- a/src/dialog.hh +++ b/src/dialog.hh @@ -21,7 +21,6 @@ const char *a_Dialog_select_file(const char *msg, char *a_Dialog_open_file(const char *msg, const char *pattern, const char *fname); void a_Dialog_text_window(const char *txt, const char *title); -void a_Dialog_findtext(BrowserWindow *bw); #ifdef __cplusplus } diff --git a/src/findbar.cc b/src/findbar.cc new file mode 100644 index 00000000..e2a02c51 --- /dev/null +++ b/src/findbar.cc @@ -0,0 +1,188 @@ +/* + * File: findbar.cc + * + * Copyright (C) 2005-2007 Jorge Arellano Cid <jcid@dillo.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + */ + +#include <fltk/xpmImage.h> +#include <fltk/events.h> +#include "findbar.hh" + +#include "msg.h" +#include "pixmaps.h" +#include "uicmd.hh" +#include "bw.h" +#include "ui.hh" + +/* + * Local sub class + * (Used to handle escape in the findbar, may also avoid some shortcuts). + */ +class MyInput : public Input { +public: + MyInput (int x, int y, int w, int h, const char* l=0) : + Input(x,y,w,h,l) {}; + int handle(int e); +}; + +int MyInput::handle(int e) +{ + _MSG("findbar NewInput::handle()\n"); + int ret = 1, k = event_key(); + unsigned modifier = event_state() & (SHIFT | CTRL | ALT | META); + if (modifier == 0) { + if (e == KEY && k == EscapeKey) { + _MSG("findbar NewInput: catched EscapeKey\n"); + ret = 0; + } + } + if (ret) + ret = Input::handle(e); + return ret; +}; + +/* + * Find next occurrence of input key + */ +static void findbar_search_cb(Widget *, void *vfb) +{ + Findbar *fb = (Findbar *)vfb; + const char *key = fb->i->value(); + bool case_sens = fb->cb->value(); + + if (key[0] != '\0') + a_UIcmd_findtext_search((BrowserWindow *) fb->ui->user_data(), + key, case_sens); +} + +/* + * Find next occurrence of input key + */ +static void findbar_search_cb2(Widget *widget, void *vfb) +{ + /* + * Somehow fltk even regards the first loss of focus for the + * window as a WHEN_ENTER_KEY_ALWAYS event. + */ + if (event_key() == ReturnKey) + findbar_search_cb(widget, vfb); +} + +/* + * Reset search state + */ +static void findbar_clear_cb(Widget *, void *vfb) +{ + Findbar *fb = (Findbar *)vfb; + fb->i->value(""); + a_UIcmd_findtext_reset((BrowserWindow *) fb->ui->user_data()); +} + +/* + * Hide the search bar + */ +static void findbar_hide_cb(Widget *, void *vfb) +{ + ((Findbar *)vfb)->hide(); +} + +/* + * Construct text search bar + */ +Findbar::Findbar(int width, int height, UI *ui) : + Group(0, 0, width, height) +{ + int button_width = 70; + int gap = 2; + int border = 2; + int input_width = width - (2 * border + 3 * (button_width + gap)); + int x = border; + height -= 2 * border; + + this->ui = ui; + this->hide(); + + begin(); + hidebutton = new HighlightButton(x, border, 16, height, 0); + hidebutton->image(new xpmImage(new_s_xpm)); + hidebutton->tooltip("Hide"); + x += 16 + gap; + hidebutton->callback(findbar_hide_cb, this); + + i = new MyInput(x, border, input_width, height); + x += input_width + gap; + resizable(i); + i->color(206); + i->when(WHEN_ENTER_KEY_ALWAYS); + i->callback(findbar_search_cb2, this); + + // todo: search previous would be nice + findb = new HighlightButton(x, border, button_width, height, "&Next"); + x += button_width + gap; + findb->tooltip("Find next occurence of the search phrase"); + findb->add_shortcut(ReturnKey); + findb->add_shortcut(KeypadEnter); + findb->callback(findbar_search_cb, this); + + /* + * I don't consider this button too useful, but feel free to + * reenable it (make sure to adjust the input_width above + * + * clrb = new Button(x, border, button_width, height, "Clear"); + * x += button_width + gap; + * clrb->callback(findbar_clear_cb, this); + */ + + cb = new CheckButton(x, border, 2*button_width, height, "Case-sensitive"); + x += 2 * button_width + gap; + + end(); +} + +/* + * Handle events. Used to catch EscapeKey events. + */ +int Findbar::handle(int event) +{ + int ret = 0; + int k = event_key(); + unsigned modifier = event_state() & (SHIFT | CTRL | ALT | META); + + if (modifier == 0 && k == EscapeKey) { + hide(); + ret = 1; + } + + if (ret == 0) + ret = Group::handle(event); + + return ret; +} + +/* + * Show the findbar and focus the input field + */ +void Findbar::show() +{ + Group::show(); + /* select text even if already focused */ + i->take_focus(); + i->position(i->size(), 0); +} + +/* + * Hide the findbar and reset the search state + */ +void Findbar::hide() +{ + BrowserWindow *bw; + + Group::hide(); + if ((bw = (BrowserWindow *) ui->user_data())) + a_UIcmd_findtext_reset(bw); +} diff --git a/src/findbar.hh b/src/findbar.hh new file mode 100644 index 00000000..096025e5 --- /dev/null +++ b/src/findbar.hh @@ -0,0 +1,38 @@ +#ifndef __FINDBAR_HH__ +#define __FINDBAR_HH__ + +//#include <fltk/Window.h> +#include <fltk/Widget.h> +#include <fltk/HighlightButton.h> +#include <fltk/Button.h> +#include <fltk/Input.h> +#include <fltk/Group.h> +#include <fltk/CheckButton.h> +#include <fltk/ReturnButton.h> + +// simple declaration to avoid circular include +class UI; + +using namespace fltk; + +/* + * Searchbar to find text in page. + */ +class Findbar : public Group { + HighlightButton *findb; + Button *clrb; + HighlightButton *hidebutton; + +public: + /* the callback functions need those */ + UI *ui; + Input *i; + CheckButton *cb; + + Findbar(int width, int height, UI *ui); + int handle(int event); + void show(); + void hide(); +}; + +#endif // __FINDBAR_HH__ diff --git a/src/menu.cc b/src/menu.cc index dba66980..8eea34c4 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -23,6 +23,7 @@ #include "uicmd.hh" #include "history.h" #include "html.hh" +#include "ui.hh" // for (UI *) using namespace fltk; @@ -116,8 +117,7 @@ static void Menu_add_bookmark_cb(Widget* ) */ static void Menu_find_text_cb(Widget* ) { -// a_UIcmd_fullscreen_toggle(popup_bw); - a_UIcmd_findtext_dialog(popup_bw); + ((UI *)popup_bw->ui)->set_findbar_visibility(1); } /* @@ -19,7 +19,7 @@ #include <fltk/damage.h> #include <fltk/xpmImage.h> #include <fltk/MultiImage.h> -#include <fltk/events.h> // for mouse buttons +#include <fltk/events.h> // for mouse buttons and keys #include <fltk/InvisibleBox.h> #include <fltk/PopupMenu.h> #include <fltk/Item.h> @@ -33,7 +33,6 @@ using namespace fltk; // Include image data #include "pixmaps.h" - #include "uicmd.hh" /* @@ -631,6 +630,10 @@ UI::UI(int win_w, int win_h, const char* label, const UI *cur_ui) : TopGroup->resizable(Main); MainIdx = TopGroup->find(Main); + // Find text bar + findbar = new Findbar(win_w, 30, this); + TopGroup->add(findbar); + // Status Panel StatusPanel = new Group(0, 0, win_w, s_h, 0); // Status box @@ -642,6 +645,7 @@ UI::UI(int win_w, int win_h, const char* label, const UI *cur_ui) : Status->box(THIN_DOWN_BOX); Status->clear_click_to_focus(); Status->clear_tab_to_focus(); + Status->color(GRAY80); StatusPanel->add(Status); //Status->throw_focus(); @@ -723,7 +727,7 @@ int UI::handle(int event) a_UIcmd_book(user_data()); ret = 1; } else if (k == 'f') { - a_UIcmd_findtext_dialog((BrowserWindow*) user_data()); + set_findbar_visibility(1); ret = 1; } else if (k == 'l') { if (Panelmode == UI_HIDDEN) { @@ -1055,3 +1059,14 @@ void UI::paste_url() paste(*Clear, false); } +/* + * Shows or hides the findbar of this window + */ +void UI::set_findbar_visibility(bool visible) +{ + if (visible) { + findbar->show(); + } else { + findbar->hide(); + } +} @@ -11,6 +11,8 @@ #include <fltk/Output.h> #include <fltk/Image.h> +#include "findbar.hh" + using namespace fltk; typedef enum { @@ -57,6 +59,7 @@ class UI : public fltk::Window { int xpos, bw, bh, fh, lh, lbl; UIPanelmode Panelmode; + Findbar *findbar; PackedGroup *make_toolbar(int tw, int th); PackedGroup *make_location(); @@ -87,6 +90,7 @@ public: void paste_url(); void set_panelmode(UIPanelmode mode); UIPanelmode get_panelmode(); + void set_findbar_visibility(bool visible); Widget *fullscreen_button() { return FullScreen; } void fullscreen_toggle() { FullScreen->do_callback(); } diff --git a/src/uicmd.cc b/src/uicmd.cc index aef6ea55..74f23404 100644 --- a/src/uicmd.cc +++ b/src/uicmd.cc @@ -706,14 +706,6 @@ void a_UIcmd_fullscreen_toggle(BrowserWindow *bw) } /* - * Open the text search dialog. - */ -void a_UIcmd_findtext_dialog(BrowserWindow *bw) -{ - a_Dialog_findtext(bw); -} - -/* * Search for next occurrence of key. */ void a_UIcmd_findtext_search(BrowserWindow *bw, const char *key, int case_sens) |