changeset 224:07d1e0d8463c

- Replaced the findtext dialog with an in-window widget!
author jcid
date Thu, 22 May 2008 18:31:16 +0200
parents 008bae47629e
children 3966f1f1963c
files ChangeLog src/Makefile.am src/dialog.cc src/dialog.hh src/findbar.cc src/findbar.hh src/menu.cc src/ui.cc src/ui.hh src/uicmd.cc
diffstat 10 files changed, 255 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu May 22 00:14:53 2008 +0200
+++ b/ChangeLog	Thu May 22 18:31:16 2008 +0200
@@ -154,7 +154,8 @@
 +- Added int32_t, EAI_NODATA and iconv tests for FreeBSD.
    Patch: Thomas-Martin Seck
 +- Made CTRL-l focus the location bar instead of popping up a dialog.
- - Set key bindings to its modifiers when alone only.
+ - Set key bindings with modifiers to work when alone only.
+ - Replaced the findtext dialog with an in-window widget!
    Patches: Justus Winter
 
  TODO:
--- a/src/Makefile.am	Thu May 22 00:14:53 2008 +0200
+++ b/src/Makefile.am	Thu May 22 18:31:16 2008 +0200
@@ -84,6 +84,8 @@
 	menu.cc \
 	dpiapi.c \
 	dpiapi.h \
-	pixmaps.h
+	pixmaps.h \
+	findbar.cc \
+	findbar.hh
 
 EXTRA_DIST = chg srch
--- a/src/dialog.cc	Thu May 22 00:14:53 2008 +0200
+++ b/src/dialog.cc	Thu May 22 18:31:16 2008 +0200
@@ -150,95 +150,6 @@
    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;
 
--- a/src/dialog.hh	Thu May 22 00:14:53 2008 +0200
+++ b/src/dialog.hh	Thu May 22 18:31:16 2008 +0200
@@ -21,7 +21,6 @@
 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
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/findbar.cc	Thu May 22 18:31:16 2008 +0200
@@ -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);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/findbar.hh	Thu May 22 18:31:16 2008 +0200
@@ -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__
--- a/src/menu.cc	Thu May 22 00:14:53 2008 +0200
+++ b/src/menu.cc	Thu May 22 18:31:16 2008 +0200
@@ -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_find_text_cb(Widget* )
 {
-// a_UIcmd_fullscreen_toggle(popup_bw);
-   a_UIcmd_findtext_dialog(popup_bw);
+   ((UI *)popup_bw->ui)->set_findbar_visibility(1);
 }
 
 /* 
--- a/src/ui.cc	Thu May 22 00:14:53 2008 +0200
+++ b/src/ui.cc	Thu May 22 18:31:16 2008 +0200
@@ -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 @@
 
 // Include image data
 #include "pixmaps.h"
-
 #include "uicmd.hh"
 
 /*
@@ -631,6 +630,10 @@
    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 @@
    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 @@
             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 @@
    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();
+   }
+}
--- a/src/ui.hh	Thu May 22 00:14:53 2008 +0200
+++ b/src/ui.hh	Thu May 22 18:31:16 2008 +0200
@@ -11,6 +11,8 @@
 #include <fltk/Output.h>
 #include <fltk/Image.h>
 
+#include "findbar.hh"
+
 using namespace fltk;
 
 typedef enum {
@@ -57,6 +59,7 @@
    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 @@
    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(); }
--- a/src/uicmd.cc	Thu May 22 00:14:53 2008 +0200
+++ b/src/uicmd.cc	Thu May 22 18:31:16 2008 +0200
@@ -706,14 +706,6 @@
 }
 
 /*
- * 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)