changeset 56:7bf5884218c4

- Bound Ctrl+Space to fullscreen toggle. - Bound preliminar find text support. - Added better pixmaps for Img On/Off icon.
author jcid
date Mon, 19 Nov 2007 18:49:54 +0100
parents a1f38544fab6
children c9113d86e232
files ChangeLog src/dialog.cc src/dialog.hh src/menu.cc src/pixmaps.h src/ui.cc src/uicmd.cc src/uicmd.hh
diffstat 8 files changed, 175 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun Nov 18 21:17:27 2007 +0100
+++ b/ChangeLog	Mon Nov 19 18:49:54 2007 +0100
@@ -40,6 +40,7 @@
  - Reimplemented html.cc using a class, removed the linkblock,
    and hooked memory-release to dw destruction.
  - Switched UI shortcuts from a global event handler to UI::handle.
+ - Bound Ctrl+Space to fullscreen toggle.
    Patches: Jorge Arellano
 +- Connected signals to <li> elements (fixes links within lists).
  - Enabled text, background-color and geometry in preferences.
@@ -57,6 +58,7 @@
  - Fixed page-popup-menu to use the stack's top URL instead of base_url.
  - Added the "static" qualifier where missing.
  - Bound "Copy link location".
+ - Bound preliminar find text support.
    Patches: place
 +- Fixed a problem with locally-installed dpis.
  - Added code for optional image loading (nice interface) very advanced!
--- a/src/dialog.cc	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/dialog.cc	Mon Nov 19 18:49:54 2007 +0100
@@ -11,22 +11,26 @@
 
 // UI dialogs
 
+#include <fltk/events.h> // for the unfortunate (temporary?) event key testing
 #include <fltk/Window.h>
 #include <fltk/ask.h>
 #include <fltk/file_chooser.h>
 #include <fltk/TextBuffer.h>
+#include <fltk/Input.h>
+#include <fltk/CheckButton.h>
 #include <fltk/ReturnButton.h>
 #include <fltk/TextDisplay.h>
 
 #include "dialog.hh"
 #include "misc.h"
+#include "uicmd.hh"
 
 using namespace fltk;
 
 /*
- * Callback for the text window dialog.
+ * Close dialog window.
  */
-void text_window_cb(Widget *, void *vwin)
+static void window_close_cb(Widget *, void *vwin)
 {
    Window *window = (Window*)vwin;
 
@@ -107,10 +111,91 @@
     td->buffer(text_buf);
 
     ReturnButton *b = new ReturnButton (0, wh-bh, ww, bh, "Close");
-    b->callback(text_window_cb, window);
+    b->callback(window_close_cb, window);
 
    window->resizable(window);
    window->end();
    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();
+
+   /*
+    * Somehow fltk even regards the first loss of focus for the
+    * window as a WHEN_ENTER_KEY_ALWAYS event.
+    */ 
+   int e = event_key();
+   if ((e != ReturnKey) && (e != LeftButton))
+      return;
+
+   if (key[0] != '\0')
+      a_UIcmd_findtext_search(tf->bw, key, case_sens);
+      
+}
+
+/*
+ * 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;
+
+   begin();
+    i = new Input(0, 0, ww, ih);
+    i->when(WHEN_ENTER_KEY_ALWAYS);
+    i->callback(findtext_search_cb, 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();
+}
--- a/src/dialog.hh	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/dialog.hh	Mon Nov 19 18:49:54 2007 +0100
@@ -1,6 +1,8 @@
 #ifndef __DIALOG_HH__
 #define __DIALOG_HH__
 
+#include "bw.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -14,7 +16,7 @@
 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
 }
--- a/src/menu.cc	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/menu.cc	Mon Nov 19 18:49:54 2007 +0100
@@ -116,7 +116,8 @@
  */
 static void Menu_find_text_cb(Widget* )
 {
-   a_UIcmd_fullscreen_toggle(popup_bw);
+// a_UIcmd_fullscreen_toggle(popup_bw);
+   a_UIcmd_findtext_dialog(popup_bw);
 }
 
 /* 
--- a/src/pixmaps.h	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/pixmaps.h	Mon Nov 19 18:49:54 2007 +0100
@@ -1497,44 +1497,44 @@
 /* XPM */
 static char * imgload_on_xpm[] = {
 "15 15 2 1",
-"       c #00000000CF3C",
-".      c #FFFFFFFFFFFF",
-" . .  .........",
-" .     ...   ..",
-" .   . ... ....",
-" . ... .. .....",
-" .....  . ..  .",
-".........  .. .",
-"..........    .",
-"...............",
-".   ...........",
-". .  .  .. ....",
-". .. .     ....",
-". .. . .  .....",
-".    . .  .....",
-"...............",
-"..............."};
+" 	c #FFFFFFFFFFFF",
+".	c #00000000CF3C",
+"               ",
+" ... .   .  .. ",
+"  .  .. .. . . ",
+"  .  . . . .   ",
+"  .  .   . . . ",
+"  .  .   . . . ",
+" ... .   .  .. ",
+"               ",
+"   ..   .   .  ",
+"  .  .  ..  .  ",
+"  .  .  . . .  ",
+"  .  .  .  ..  ",
+"  .  .  .   .  ",
+"   ..   .   .  ",
+"               "};
 
 /* XPM */
 static char * imgload_off_xpm[] = {
 "15 15 2 1",
-"       c #CF3C00000000",
-".      c #FFFFFFFFFFFF",
-" .. . .........",
-" .    ..    ...",
-" .     . ......",
-" . . . . ..  ..",
-" . ...    .. ..",
-" ........    ..",
-"...............",
-"...............",
-"...............",
-"    ..  .  ....",
-" .     ..    ..",
-" . . .... .....",
-"   .    .   ...",
-"  ..  ...   ...",
-".... .... ....."};
+" 	c #FFFFFFFFFFFF",
+".	c #CF3C00000000",
+"               ",
+" ... .   .  .. ",
+"  .  .. .. . . ",
+"  .  . . . .   ",
+"  .  .   . . . ",
+"  .  .   . . . ",
+" ... .   .  .. ",
+"               ",
+"  ..   ... ... ",
+" .  .  .   .   ",
+" .  .  ... ... ",
+" .  .  .   .   ",
+" .  .  .   .   ",
+"  ..   .   .   ",
+"               "};
 
 /* XPM */
 static char *left_i_xpm[] = {
--- a/src/ui.cc	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/ui.cc	Mon Nov 19 18:49:54 2007 +0100
@@ -673,6 +673,9 @@
          } else if (event_key() == 's') {
             a_UIcmd_search_dialog(user_data());
             ret = 1;
+         } else if (event_key() == ' ') {
+            fullscreen_cb_i();
+            ret = 1;
          }
       }
 
--- a/src/uicmd.cc	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/uicmd.cc	Mon Nov 19 18:49:54 2007 +0100
@@ -708,3 +708,43 @@
    BW2UI(bw)->fullscreen_toggle();
 }
 
+/*
+ * 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)
+{
+   Layout *l = (Layout *)bw->render_layout;
+   
+   switch (l->search(key, case_sens)) {
+      case FindtextState::RESTART:
+         a_UIcmd_set_msg(bw, "No further occurrences of \"%s\". "
+                             "Restarting from the top.", key);
+         break;
+      case FindtextState::NOT_FOUND:
+         a_UIcmd_set_msg(bw, "\"%s\" not found.", key);
+         break;
+      case FindtextState::SUCCESS:
+      default:
+         a_UIcmd_set_msg(bw, "");
+   }
+}
+
+/*
+ * Reset text search state.
+ */
+void a_UIcmd_findtext_reset(BrowserWindow *bw)
+{
+   Layout *l = (Layout *)bw->render_layout;
+   l->resetSearch();
+
+   a_UIcmd_set_msg(bw, "");
+}
+
--- a/src/uicmd.hh	Sun Nov 18 21:17:27 2007 +0100
+++ b/src/uicmd.hh	Mon Nov 19 18:49:54 2007 +0100
@@ -27,6 +27,9 @@
 void a_UIcmd_book(void *vbw);
 void a_UIcmd_add_bookmark(BrowserWindow *bw, const DilloUrl *url);
 void a_UIcmd_fullscreen_toggle(BrowserWindow *bw);
+void a_UIcmd_findtext_dialog(BrowserWindow *bw);
+void a_UIcmd_findtext_search(BrowserWindow *bw, const char *key, int case_sens);
+void a_UIcmd_findtext_reset(BrowserWindow *bw);
 void a_UIcmd_page_popup(void *vbw, const DilloUrl *url,
                         const char *bugs_txt, int prefs_load_images);
 void a_UIcmd_link_popup(void *vbw, const DilloUrl *url);