changeset 1948:caf71cd30ec8

Made the findbar operative again (it has tricks and workarounds)
author Jorge Arellano Cid <jcid@dillo.org>
date Tue, 15 Mar 2011 09:28:45 -0300
parents 821e6262ead9
children 09f9c91adf4b
files src/findbar.cc src/menu.cc src/ui.cc src/ui.hh src/uicmd.cc src/uicmd.hh
diffstat 6 files changed, 74 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/src/findbar.cc	Tue Mar 15 09:26:49 2011 -0300
+++ b/src/findbar.cc	Tue Mar 15 09:28:45 2011 -0300
@@ -99,14 +99,13 @@
    int gap = 2;
    int border = 2;
    int input_width = width - (2 * border + 4 * (button_width + gap));
-   int x = border;
+   int x = 0;
 
    Fl_Group::current(0);
 
    height -= 2 * border;
 
-   box(FL_PLASTIC_UP_BOX);
-   Fl_Group::hide();
+   box(FL_THIN_UP_BOX);
 
     hide_btn = new Fl_Button(x, border, 16, height, 0);
     hideImg = new Fl_Pixmap(new_s_xpm);
@@ -114,6 +113,7 @@
     x += 16 + gap;
     hide_btn->callback(hide_cb, this);
     hide_btn->clear_visible_focus();
+    hide_btn->box(FL_THIN_UP_BOX);
    add(hide_btn);
 
     i = new MyInput(x, border, input_width, height);
@@ -128,6 +128,7 @@
     next_btn->shortcut(FL_Enter);
     next_btn->callback(search_cb, this);
     next_btn->clear_visible_focus();
+    next_btn->box(FL_THIN_UP_BOX);
    add(next_btn);
 
     prev_btn= new Fl_Button(x, border, button_width, height, "Previous");
@@ -135,6 +136,7 @@
     prev_btn->shortcut(FL_SHIFT+FL_Enter);
     prev_btn->callback(searchBackwards_cb, this);
     prev_btn->clear_visible_focus();
+    prev_btn->box(FL_THIN_UP_BOX);
    add(prev_btn);
 
     check_btn = new Fl_Check_Button(x, border, 2*button_width, height,
@@ -182,7 +184,13 @@
  */
 void Findbar::show()
 {
+   BrowserWindow *bw = a_UIcmd_get_bw_by_widget(this);
+   dReturn_if (bw == NULL);
+
+   // It takes more than just calling show() to do the trick
+   //a_UIcmd_findbar_toggle(bw, 1);
    Fl_Group::show();
+
    /* select text even if already focused */
    i->take_focus();
    i->position(i->size(), 0);
@@ -193,10 +201,13 @@
  */
 void Findbar::hide()
 {
-   BrowserWindow *bw;
+   BrowserWindow *bw = a_UIcmd_get_bw_by_widget(this);
+   dReturn_if (bw == NULL);
 
+   // It takes more than just calling hide() to do the trick
    Fl_Group::hide();
-   if ((bw = a_UIcmd_get_bw_by_widget(this)))
-      a_UIcmd_findtext_reset(bw);
+   a_UIcmd_findbar_toggle(bw, 0);
+
+   a_UIcmd_findtext_reset(bw);
    a_UIcmd_focus_main_area(bw);
 }
--- a/src/menu.cc	Tue Mar 15 09:26:49 2011 -0300
+++ b/src/menu.cc	Tue Mar 15 09:28:45 2011 -0300
@@ -156,7 +156,7 @@
  */
 static void Menu_find_text_cb(Fl_Widget*, void* )
 {
-   ((UI *)popup_bw->ui)->set_findbar_visibility(1);
+   ((UI *)popup_bw->ui)->findbar_toggle(1);
 }
 
 /*
--- a/src/ui.cc	Tue Mar 15 09:26:49 2011 -0300
+++ b/src/ui.cc	Tue Mar 15 09:28:45 2011 -0300
@@ -110,7 +110,11 @@
        (k == FL_Up || k == FL_Down || k == FL_Left || k == FL_Right)) {
       return 0;
    } else if (e == FL_KEYBOARD) {
-      if (modifier == FL_CTRL) {
+      if (k == FL_Escape && modifier == 0) {
+         // Let the parent group handle this Esc key
+         return 0;
+
+      } else if (modifier == FL_CTRL) {
          if (k == 'l') {
             // Make text selected when already focused.
             position(size(), 0);
@@ -692,12 +696,13 @@
     MainIdx = TopGroup->find(Main);
  
     // Find text bar
-    //findbar = new Findbar(ui_w, 28);
-    //TopGroup->add(findbar);
-    Fl_Box *fb = new Fl_Box(0,0,0,fh, "F I N D B A R");
+    FindBarSpace = 1;
+    FindBar = new Findbar(ui_w, fh);
+    TopGroup->add(FindBar);
 
     // Status Panel
     make_status_bar(ui_w, ui_h);
+    TopGroup->add(StatusBar);
 
    TopGroup->end();
 
@@ -710,10 +715,6 @@
 
    customize(0);
 
-   // Hide findbar
-   fb->hide();
-   Main->size(Main->w(), Main->h()+fb->h());
-
    if (Panelmode) {
       //Panel->hide();
       //StatusBar->hide();
@@ -759,8 +760,10 @@
          a_UIcmd_book(a_UIcmd_get_bw_by_widget(this));
          ret = 1;
       } else if (cmd == KEYS_FIND) {
-         MSG("UI::handle  ->KEYS_FIND\n");
-         //set_findbar_visibility(1);
+         if (!FindBarSpace) {
+            findbar_toggle(1);
+         } else
+            FindBar->hide();
          ret = 1;
       } else if (cmd == KEYS_WEBSEARCH) {
          a_UIcmd_search_dialog(a_UIcmd_get_bw_by_widget(this));
@@ -1094,13 +1097,30 @@
 }
 
 /*
- * Shows or hides the findbar of this window
+ * Ajust space for the findbar (if necessary) and show or remove it
  */
-void UI::set_findbar_visibility(bool visible)
+void UI::findbar_toggle(bool add)
 {
-   if (visible) {
-      findbar->show();
-   } else {
-      findbar->hide();
+   /* WORKAROUND:
+    * This is tricky: As fltk-1.3 resizes hidden widgets (which it
+    * doesn't resize when visible!). We need to go through hoops to
+    * get the desired behaviour.
+    * Most probably this is a bug in FLTK and we have to report it.
+    */
+
+   if (add && !FindBarSpace) {
+      // show
+      Main->size(Main->w(), Main->h()-FindBar->h());
+      insert(*FindBar, StatusBar);
+      FindBar->show();
+      FindBarSpace = 1;
+   } else if (!add && FindBarSpace) {
+      // hide
+      Main->size(Main->w(), Main->h()+FindBar->h());
+      remove(FindBar);
+      FindBarSpace = 0;
    }
+
+   // Main->redraw(); is not enough
+   redraw();
 }
--- a/src/ui.hh	Tue Mar 15 09:26:49 2011 -0300
+++ b/src/ui.hh	Tue Mar 15 09:28:45 2011 -0300
@@ -127,14 +127,14 @@
    CustProgressBox *PProg, *IProg;
    Fl_Group *Panel, *Main;
    Fl_Output *StatusOutput;
+   Findbar *FindBar;
 
-   int MainIdx;
+   int FindBarSpace, MainIdx;
    // Panel customization variables
    int PanelSize, CuteColor, Small_Icons;
    int p_xpos, p_ypos, bw, bh, mh, lh, nh, fh, sh, pw, lbl;
 
    UIPanelmode Panelmode;
-   Findbar *findbar;
    int PointerOnLink;
    Fl_Button *make_button(const char *label, Fl_Image *img,
                           Fl_Image*deimg, int b_n, int start = 0);
@@ -168,7 +168,7 @@
    void paste_url();
    void set_panelmode(UIPanelmode mode);
    UIPanelmode get_panelmode();
-   void set_findbar_visibility(bool visible);
+   void findbar_toggle(bool add);
    Fl_Widget *fullscreen_button() { return FullScreen; }
    void fullscreen_toggle() { FullScreen->do_callback(); }
 
--- a/src/uicmd.cc	Tue Mar 15 09:26:49 2011 -0300
+++ b/src/uicmd.cc	Tue Mar 15 09:28:45 2011 -0300
@@ -142,7 +142,11 @@
       UI *ui = (UI*)wizard()->value();
       BrowserWindow *bw = a_UIcmd_get_bw_by_widget(ui);
       KeysCommand_t cmd = Keys::getKeyCmd();
-      if (cmd == KEYS_NOP) {
+      if (Fl::event_key() == FL_Escape) {
+         // Hide findbar if present
+         ui->findbar_toggle(0);
+         ret = 1;
+      } else if (cmd == KEYS_NOP) {
          // Do nothing
       } else if (cmd == KEYS_NEW_TAB) {
          a_UIcmd_open_url_nt(bw, NULL, 1);
@@ -435,6 +439,9 @@
    // Copy the layout pointer into the bw data
    new_bw->render_layout = (void*)layout;
 
+   // WORKAROUND: see findbar_toggle()
+   new_ui->findbar_toggle(0);
+
    return new_bw;
 }
 
@@ -1231,6 +1238,14 @@
 }
 
 /*
+ * Tell the UI to hide/show the findbar
+ */
+void a_UIcmd_findbar_toggle(BrowserWindow *bw, int on)
+{
+   BW2UI(bw)->findbar_toggle(on);
+}
+
+/*
  * Focus the rendered area.
  */
 void a_UIcmd_focus_main_area(BrowserWindow *bw)
--- a/src/uicmd.hh	Tue Mar 15 09:26:49 2011 -0300
+++ b/src/uicmd.hh	Tue Mar 15 09:28:45 2011 -0300
@@ -39,6 +39,7 @@
 void a_UIcmd_findtext_search(BrowserWindow *bw,const char *key,int case_sens,
                              int backwards);
 void a_UIcmd_findtext_reset(BrowserWindow *bw);
+void a_UIcmd_findbar_toggle(BrowserWindow *bw, int on);
 void a_UIcmd_focus_main_area(BrowserWindow *bw);
 void a_UIcmd_focus_location(void *vbw);
 void a_UIcmd_page_popup(void *vbw, bool_t has_bugs, void *v_cssUrls);