[Xfce4-commits] <midori:master> Refactor findbar into MidoriFindbar
Christian Dywan
noreply at xfce.org
Mon Jun 21 01:54:01 CEST 2010
Updating branch refs/heads/master
to f5604f290c860a1d3445e7f696f37533562f8748 (commit)
from 2e7307b01420b945c475f215b30b6601d6b98357 (commit)
commit f5604f290c860a1d3445e7f696f37533562f8748
Author: Christian Dywan <christian at twotoasts.de>
Date: Sun Jun 20 20:13:39 2010 +0200
Refactor findbar into MidoriFindbar
The findbar still depends on the browser for knowing when to
search and to propagate focus. Behaviour did not change.
midori/midori-browser.c | 258 ++----------------------------------
toolbars/midori-findbar.c | 327 +++++++++++++++++++++++++++++++++++++++++++++
toolbars/midori-findbar.h | 57 ++++++++
3 files changed, 395 insertions(+), 247 deletions(-)
diff --git a/midori/midori-browser.c b/midori/midori-browser.c
index 0db0f51..5b26f46 100644
--- a/midori/midori-browser.c
+++ b/midori/midori-browser.c
@@ -11,10 +11,6 @@
See the file COPYING for the full license text.
*/
-#if HAVE_CONFIG_H
- #include <config.h>
-#endif
-
#include "midori-browser.h"
#include "midori-array.h"
@@ -24,6 +20,7 @@
#include "midori-locationaction.h"
#include "midori-searchaction.h"
#include "midori-stock.h"
+#include "midori-findbar.h"
#include "midori-transferbar.h"
#include "gtkiconentry.h"
@@ -55,6 +52,10 @@
#include <sqlite3.h>
#endif
+#if HAVE_CONFIG_H
+ #include <config.h>
+#endif
+
struct _MidoriBrowser
{
#if HAVE_HILDON
@@ -78,11 +79,6 @@ struct _MidoriBrowser
GtkWidget* inspector_view;
GtkWidget* find;
- GtkWidget* find_text;
- GtkToolItem* find_case;
- GtkToolItem* find_highlight;
- GtkToolItem* find_close;
- gboolean find_typing;
GtkWidget* statusbar;
GtkWidget* statusbar_contents;
@@ -212,9 +208,6 @@ midori_search_action_get_icon (KatzeItem* item,
GtkWidget* widget,
const gchar** icon_name);
-static void
-_midori_browser_find_done (MidoriBrowser* browser);
-
static gboolean
_action_menus_activate_item_alt (GtkAction* action,
KatzeItem* item,
@@ -328,7 +321,7 @@ _midori_browser_update_interface (MidoriBrowser* browser)
midori_view_can_find (view));
_action_set_sensitive (browser, "FindPrevious",
midori_view_can_find (view));
- gtk_widget_set_sensitive (GTK_WIDGET (browser->find_highlight),
+ midori_findbar_set_can_find (MIDORI_FINDBAR (browser->find),
midori_view_can_find (view));
action = gtk_action_group_get_action (browser->action_group, "ReloadStop");
@@ -1521,41 +1514,7 @@ midori_view_search_text_cb (GtkWidget* view,
gchar* typing,
MidoriBrowser* browser)
{
- const gchar* text;
- gboolean case_sensitive;
- gboolean highlight;
-
- if (typing)
- {
- gint position = -1;
-
- browser->find_typing = TRUE;
- gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
- browser->find_highlight), TRUE);
- gtk_widget_hide (GTK_WIDGET (browser->find_case));
- gtk_widget_hide (GTK_WIDGET (browser->find_highlight));
- gtk_widget_hide (GTK_WIDGET (browser->find_close));
- if (!gtk_widget_get_visible (browser->find))
- gtk_entry_set_text (GTK_ENTRY (browser->find_text), "");
- gtk_widget_show (browser->find);
- gtk_window_set_focus (GTK_WINDOW (browser), browser->find_text);
- gtk_editable_insert_text (GTK_EDITABLE (browser->find_text), typing, -1, &position);
- gtk_editable_set_position (GTK_EDITABLE (browser->find_text), -1);
- }
- if (gtk_widget_get_visible (browser->find) && !typing)
- {
- #if !HAVE_HILDON
- gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
- GTK_ICON_ENTRY_PRIMARY, (found) ? GTK_STOCK_FIND : GTK_STOCK_STOP);
- #endif
- text = gtk_entry_get_text (GTK_ENTRY (browser->find_text));
- case_sensitive = gtk_toggle_tool_button_get_active (
- GTK_TOGGLE_TOOL_BUTTON (browser->find_case));
- midori_view_mark_text_matches (MIDORI_VIEW (view), text, case_sensitive);
- highlight = gtk_toggle_tool_button_get_active (
- GTK_TOGGLE_TOOL_BUTTON (browser->find_highlight));
- midori_view_set_highlight_text_matches (MIDORI_VIEW (view), highlight);
- }
+ midori_findbar_search_text (MIDORI_FINDBAR (browser->find), view, found, typing);
}
static gboolean
@@ -2526,125 +2485,21 @@ static void
_action_find_activate (GtkAction* action,
MidoriBrowser* browser)
{
- if (gtk_widget_get_visible (browser->find))
- _midori_browser_find_done (browser);
- else
- {
- GtkWidget* view;
- const gchar* text;
-
- #if !HAVE_HILDON
- gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
- GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_FIND);
- gtk_widget_show (GTK_WIDGET (browser->find_case));
- #endif
- gtk_widget_show (GTK_WIDGET (browser->find_highlight));
- gtk_widget_show (GTK_WIDGET (browser->find_close));
- view = midori_browser_get_current_tab (browser);
- if ((text = midori_view_get_selected_text (MIDORI_VIEW (view))))
- gtk_entry_set_text (GTK_ENTRY (browser->find_text), text);
- gtk_widget_show (browser->find);
- }
-
- gtk_widget_grab_focus (GTK_WIDGET (browser->find_text));
-}
-
-static void
-_midori_browser_find (MidoriBrowser* browser,
- gboolean forward)
-{
- const gchar* text;
- gboolean case_sensitive;
- GtkWidget* view;
-
- if (!(view = midori_browser_get_current_tab (browser)))
- return;
-
- text = gtk_entry_get_text (GTK_ENTRY (browser->find_text));
- case_sensitive = gtk_toggle_tool_button_get_active (
- GTK_TOGGLE_TOOL_BUTTON (browser->find_case));
- midori_view_search_text (MIDORI_VIEW (view), text, case_sensitive, forward);
-}
-
-static void
-_midori_browser_find_done (MidoriBrowser* browser)
-{
- GtkWidget* view = midori_browser_get_current_tab (browser);
- midori_view_unmark_text_matches (MIDORI_VIEW (view));
- gtk_widget_hide (browser->find);
- browser->find_typing = FALSE;
- gtk_window_set_focus (GTK_WINDOW (browser), view);
+ midori_findbar_invoke (MIDORI_FINDBAR (browser->find));
}
static void
_action_find_next_activate (GtkAction* action,
MidoriBrowser* browser)
{
- _midori_browser_find (browser, TRUE);
-}
-
-static void
-midori_browser_find_text_changed_cb (GtkWidget* entry,
- MidoriBrowser* browser)
-{
- if (browser->find_typing)
- {
- GtkWidget* view = midori_browser_get_current_tab (browser);
- const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
- midori_view_unmark_text_matches (MIDORI_VIEW (view));
- if (g_utf8_strlen (text, -1) > 2)
- _midori_browser_find (browser, TRUE);
- }
-}
-
-static gboolean
-midori_browser_find_text_focus_out_event_cb (GtkWidget* entry,
- GdkEventFocus* event,
- MidoriBrowser* browser)
-{
- if (browser->find_typing)
- _midori_browser_find_done (browser);
- return FALSE;
+ midori_findbar_find (MIDORI_FINDBAR (browser->find), TRUE);
}
static void
_action_find_previous_activate (GtkAction* action,
MidoriBrowser* browser)
{
- _midori_browser_find (browser, FALSE);
-}
-
-static void
-_find_highlight_toggled (GtkToggleToolButton* toolitem,
- MidoriBrowser* browser)
-{
- GtkWidget* view;
- gboolean highlight;
-
- view = midori_browser_get_current_tab (browser);
- highlight = gtk_toggle_tool_button_get_active (toolitem);
- midori_view_set_highlight_text_matches (MIDORI_VIEW (view), highlight);
-}
-
-static gboolean
-midori_browser_find_key_press_event_cb (GtkWidget* toolbar,
- GdkEventKey* event,
- MidoriBrowser* browser)
-{
- if (event->keyval == GDK_Escape)
- {
- _midori_browser_find_done (browser);
- return TRUE;
- }
-
- return FALSE;
-}
-
-static void
-midori_browser_find_button_close_clicked_cb (GtkWidget* widget,
- MidoriBrowser* browser)
-{
- _midori_browser_find_done (browser);
+ midori_findbar_find (MIDORI_FINDBAR (browser->find), FALSE);
}
static void
@@ -5806,16 +5661,6 @@ midori_browser_realize_cb (GtkStyle* style,
}
static void
-midori_browser_entry_clear_icon_released_cb (GtkIconEntry* entry,
- gint icon_pos,
- gint button,
- gpointer user_data)
-{
- if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
- gtk_entry_set_text (GTK_ENTRY (entry), "");
-}
-
-static void
midori_browser_new_history_item (MidoriBrowser* browser,
KatzeItem** item)
{
@@ -6031,7 +5876,6 @@ midori_browser_init (MidoriBrowser* browser)
GtkSettings* gtk_settings;
GtkWidget* hpaned;
GtkWidget* vpaned;
- GtkToolItem* toolitem;
GtkRcStyle* rcstyle;
GtkWidget* label;
GtkWidget* scrolled;
@@ -6435,87 +6279,7 @@ midori_browser_init (MidoriBrowser* browser)
gtk_container_add (GTK_CONTAINER (scrolled), browser->inspector_view);
/* Incremental findbar */
- browser->find = gtk_toolbar_new ();
- gtk_widget_set_name (browser->find, "MidoriFindbar");
- gtk_toolbar_set_icon_size (GTK_TOOLBAR (browser->find), GTK_ICON_SIZE_MENU);
- gtk_toolbar_set_style (GTK_TOOLBAR (browser->find), GTK_TOOLBAR_BOTH_HORIZ);
- g_signal_connect (browser->find, "key-press-event",
- G_CALLBACK (midori_browser_find_key_press_event_cb), browser);
- toolitem = gtk_tool_item_new ();
- gtk_container_set_border_width (GTK_CONTAINER (toolitem), 6);
- gtk_container_add (GTK_CONTAINER (toolitem),
- /* i18n: A panel at the bottom, to search text in pages */
- gtk_label_new_with_mnemonic (_("_Inline Find:")));
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1);
- browser->find_text = gtk_icon_entry_new ();
- #if !HAVE_HILDON
- gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
- GTK_ICON_ENTRY_PRIMARY,
- GTK_STOCK_FIND);
- gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (browser->find_text),
- GTK_ICON_ENTRY_SECONDARY,
- GTK_STOCK_CLEAR);
- gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (browser->find_text),
- GTK_ICON_ENTRY_SECONDARY, TRUE);
- #endif
- g_signal_connect (browser->find_text, "icon-release",
- G_CALLBACK (midori_browser_entry_clear_icon_released_cb), NULL);
- g_signal_connect (browser->find_text, "activate",
- G_CALLBACK (_action_find_next_activate), browser);
- g_signal_connect (browser->find_text, "changed",
- G_CALLBACK (midori_browser_find_text_changed_cb), browser);
- g_signal_connect (browser->find_text, "focus-out-event",
- G_CALLBACK (midori_browser_find_text_focus_out_event_cb), browser);
- toolitem = gtk_tool_item_new ();
- gtk_container_add (GTK_CONTAINER (toolitem), browser->find_text);
- gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1);
- #if HAVE_HILDON
- browser->find_case = gtk_toggle_tool_button_new ();
- browser->find_highlight = gtk_toggle_tool_button_new ();
- #else
- toolitem = (GtkToolItem*)gtk_action_create_tool_item
- (_action_by_name (browser, "FindPrevious"));
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("Previous"));
- gtk_tool_item_set_is_important (toolitem, TRUE);
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1);
- toolitem = (GtkToolItem*)gtk_action_create_tool_item
- (_action_by_name (browser, "FindNext"));
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (toolitem), _("Next"));
- gtk_tool_item_set_is_important (toolitem, TRUE);
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1);
- browser->find_case = gtk_toggle_tool_button_new_from_stock (
- GTK_STOCK_SPELL_CHECK);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (browser->find_case), _("Match Case"));
- gtk_tool_item_set_is_important (GTK_TOOL_ITEM (browser->find_case), TRUE);
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), browser->find_case, -1);
- browser->find_highlight = gtk_toggle_tool_button_new_from_stock (
- GTK_STOCK_SELECT_ALL);
- #endif
- g_signal_connect (browser->find_highlight, "toggled",
- G_CALLBACK (_find_highlight_toggled), browser);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (browser->find_highlight),
- _("Highlight Matches"));
- gtk_tool_item_set_is_important (GTK_TOOL_ITEM (browser->find_highlight), TRUE);
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), browser->find_highlight, -1);
- toolitem = gtk_separator_tool_item_new ();
- gtk_separator_tool_item_set_draw (
- GTK_SEPARATOR_TOOL_ITEM (toolitem), FALSE);
- #if !HAVE_HILDON
- gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
- #endif
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), toolitem, -1);
- browser->find_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
- gtk_tool_button_set_label (GTK_TOOL_BUTTON (browser->find_close),
- _("Close Findbar"));
- g_signal_connect (browser->find_close, "clicked",
- G_CALLBACK (midori_browser_find_button_close_clicked_cb), browser);
- #if HAVE_OSX
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), browser->find_close, 0);
- #else
- gtk_toolbar_insert (GTK_TOOLBAR (browser->find), browser->find_close, -1);
- #endif
- sokoke_container_show_children (GTK_CONTAINER (browser->find));
+ browser->find = g_object_new (MIDORI_TYPE_FINDBAR, NULL);
#if HAVE_HILDON
hildon_window_add_toolbar (HILDON_WINDOW (browser),
GTK_TOOLBAR (browser->find));
diff --git a/toolbars/midori-findbar.c b/toolbars/midori-findbar.c
new file mode 100644
index 0000000..fa72a3a
--- /dev/null
+++ b/toolbars/midori-findbar.c
@@ -0,0 +1,327 @@
+/*
+ Copyright (C) 2008-2010 Christian Dywan <christian at twotoasts.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+#include "midori-findbar.h"
+
+#include "midori-browser.h"
+#include "gtkiconentry.h"
+#include "sokoke.h"
+
+#include <glib/gi18n.h>
+#include <gdk/gdkkeysyms.h>
+#include <gtk/gtk.h>
+
+#if HAVE_CONFIG_H
+ #include "config.h"
+#endif
+
+struct _MidoriFindbar
+{
+ GtkToolbar parent_instance;
+ GtkWidget* find_text;
+ GtkToolItem* previous;
+ GtkToolItem* next;
+ GtkToolItem* find_case;
+ GtkToolItem* find_highlight;
+ GtkToolItem* find_close;
+ gboolean find_typing;
+};
+
+struct _MidoriFindbarClass
+{
+ GtkToolbarClass parent_class;
+};
+
+G_DEFINE_TYPE (MidoriFindbar, midori_findbar, GTK_TYPE_TOOLBAR);
+
+static void
+midori_findbar_class_init (MidoriFindbarClass* class)
+{
+ /* Nothing to do */
+}
+
+static void
+midori_findbar_done (MidoriFindbar* findbar)
+{
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (findbar));
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+
+ midori_view_unmark_text_matches (MIDORI_VIEW (view));
+ gtk_widget_hide (GTK_WIDGET (findbar));
+ findbar->find_typing = FALSE;
+ gtk_window_set_focus (GTK_WINDOW (browser), view);
+}
+
+static gboolean
+midori_findbar_find_key_press_event_cb (MidoriFindbar* findbar,
+ GdkEventKey* event)
+{
+ if (event->keyval == GDK_Escape)
+ {
+ midori_findbar_done (findbar);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+midori_findbar_entry_clear_icon_released_cb (GtkIconEntry* entry,
+ gint icon_pos,
+ gint button,
+ gpointer user_data)
+{
+ if (icon_pos == GTK_ICON_ENTRY_SECONDARY)
+ gtk_entry_set_text (GTK_ENTRY (entry), "");
+}
+
+void
+midori_findbar_find (MidoriFindbar* findbar,
+ gboolean forward)
+{
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (findbar));
+ const gchar* text;
+ gboolean case_sensitive;
+ GtkWidget* view;
+
+ if (!(view = midori_browser_get_current_tab (browser)))
+ return;
+
+ text = gtk_entry_get_text (GTK_ENTRY (findbar->find_text));
+ case_sensitive = gtk_toggle_tool_button_get_active (
+ GTK_TOGGLE_TOOL_BUTTON (findbar->find_case));
+ midori_view_search_text (MIDORI_VIEW (view), text, case_sensitive, forward);
+}
+
+void
+midori_findbar_invoke (MidoriFindbar* findbar)
+{
+ if (gtk_widget_get_visible (GTK_WIDGET (findbar)))
+ midori_findbar_done (findbar);
+ else
+ {
+ MidoriBrowser* browser = midori_browser_get_for_widget (findbar->find_text);
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+ const gchar* text;
+
+ #if !HAVE_HILDON
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (findbar->find_text),
+ GTK_ICON_ENTRY_PRIMARY, GTK_STOCK_FIND);
+ gtk_widget_show (GTK_WIDGET (findbar->find_case));
+ #endif
+ gtk_widget_show (GTK_WIDGET (findbar->find_highlight));
+ gtk_widget_show (GTK_WIDGET (findbar->find_close));
+ if ((text = midori_view_get_selected_text (MIDORI_VIEW (view))))
+ gtk_entry_set_text (GTK_ENTRY (findbar->find_text), text);
+ gtk_widget_show (GTK_WIDGET (findbar));
+ }
+
+ gtk_widget_grab_focus (GTK_WIDGET (findbar->find_text));
+}
+
+static void
+midori_findbar_next_activate_cb (GtkWidget* entry,
+ MidoriFindbar* findbar)
+{
+ midori_findbar_find (findbar, TRUE);
+}
+
+static void
+midori_findbar_previous_clicked_cb (GtkWidget* entry,
+ MidoriFindbar* findbar)
+{
+ midori_findbar_find (findbar, FALSE);
+}
+
+static void
+midori_findbar_button_close_clicked_cb (GtkWidget* widget,
+ MidoriFindbar* findbar)
+{
+ midori_findbar_done (findbar);
+}
+
+static void
+midori_findbar_text_changed_cb (GtkWidget* entry,
+ MidoriFindbar* findbar)
+{
+ if (findbar->find_typing)
+ {
+ MidoriBrowser* browser = midori_browser_get_for_widget (entry);
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+ const gchar* text = gtk_entry_get_text (GTK_ENTRY (entry));
+ midori_view_unmark_text_matches (MIDORI_VIEW (view));
+ if (g_utf8_strlen (text, -1) > 2)
+ midori_findbar_find (findbar, TRUE);
+ }
+}
+
+static gboolean
+midori_findbar_text_focus_out_event_cb (GtkWidget* entry,
+ GdkEventFocus* event,
+ MidoriFindbar* findbar)
+{
+ if (findbar->find_typing)
+ midori_findbar_done (findbar);
+ return FALSE;
+}
+
+static void
+midori_findbar_highlight_toggled_cb (GtkToggleToolButton* toolitem,
+ MidoriFindbar* findbar)
+{
+ MidoriBrowser* browser = midori_browser_get_for_widget (GTK_WIDGET (findbar));
+ GtkWidget* view = midori_browser_get_current_tab (browser);
+ gboolean highlight = gtk_toggle_tool_button_get_active (toolitem);
+ midori_view_set_highlight_text_matches (MIDORI_VIEW (view), highlight);
+}
+
+static void
+midori_findbar_init (MidoriFindbar* findbar)
+{
+ GtkToolItem* toolitem;
+
+ gtk_widget_set_name (GTK_WIDGET (findbar), "MidoriFindbar");
+ gtk_toolbar_set_icon_size (GTK_TOOLBAR (findbar), GTK_ICON_SIZE_MENU);
+ gtk_toolbar_set_style (GTK_TOOLBAR (findbar), GTK_TOOLBAR_BOTH_HORIZ);
+ g_signal_connect (findbar, "key-press-event",
+ G_CALLBACK (midori_findbar_find_key_press_event_cb), NULL);
+
+ toolitem = gtk_tool_item_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (toolitem), 6);
+ gtk_container_add (GTK_CONTAINER (toolitem),
+ /* i18n: A panel at the bottom, to search text in pages */
+ gtk_label_new_with_mnemonic (_("_Inline Find:")));
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), toolitem, -1);
+ findbar->find_text = gtk_icon_entry_new ();
+ #if !HAVE_HILDON
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (findbar->find_text),
+ GTK_ICON_ENTRY_PRIMARY,
+ GTK_STOCK_FIND);
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (findbar->find_text),
+ GTK_ICON_ENTRY_SECONDARY,
+ GTK_STOCK_CLEAR);
+ gtk_icon_entry_set_icon_highlight (GTK_ICON_ENTRY (findbar->find_text),
+ GTK_ICON_ENTRY_SECONDARY, TRUE);
+ #endif
+ g_signal_connect (findbar->find_text, "icon-release",
+ G_CALLBACK (midori_findbar_entry_clear_icon_released_cb), NULL);
+ g_signal_connect (findbar->find_text, "activate",
+ G_CALLBACK (midori_findbar_next_activate_cb), findbar);
+ g_signal_connect (findbar->find_text, "changed",
+ G_CALLBACK (midori_findbar_text_changed_cb), findbar);
+ g_signal_connect (findbar->find_text, "focus-out-event",
+ G_CALLBACK (midori_findbar_text_focus_out_event_cb), findbar);
+ toolitem = gtk_tool_item_new ();
+ gtk_container_add (GTK_CONTAINER (toolitem), findbar->find_text);
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), toolitem, -1);
+ #if HAVE_HILDON
+ findbar->find_case = gtk_toggle_tool_button_new ();
+ findbar->find_highlight = gtk_toggle_tool_button_new ();
+ #else
+ findbar->previous = gtk_tool_button_new_from_stock (GTK_STOCK_GO_BACK);
+ g_signal_connect (findbar->previous, "clicked",
+ G_CALLBACK (midori_findbar_previous_clicked_cb), findbar);
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON (findbar->previous), _("Previous"));
+ gtk_tool_item_set_is_important (findbar->previous, TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), findbar->previous, -1);
+ findbar->next = gtk_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD);
+ g_signal_connect (findbar->next, "clicked",
+ G_CALLBACK (midori_findbar_next_activate_cb), findbar);
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON (findbar->next), _("Next"));
+ gtk_tool_item_set_is_important (findbar->next, TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), findbar->next, -1);
+ findbar->find_case = gtk_toggle_tool_button_new_from_stock (GTK_STOCK_SPELL_CHECK);
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON (findbar->find_case), _("Match Case"));
+ gtk_tool_item_set_is_important (GTK_TOOL_ITEM (findbar->find_case), TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), findbar->find_case, -1);
+ findbar->find_highlight = gtk_toggle_tool_button_new_from_stock (
+ GTK_STOCK_SELECT_ALL);
+ #endif
+ g_signal_connect (findbar->find_highlight, "toggled",
+ G_CALLBACK (midori_findbar_highlight_toggled_cb), findbar);
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON (findbar->find_highlight),
+ _("Highlight Matches"));
+ gtk_tool_item_set_is_important (GTK_TOOL_ITEM (findbar->find_highlight), TRUE);
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), findbar->find_highlight, -1);
+ toolitem = gtk_separator_tool_item_new ();
+ gtk_separator_tool_item_set_draw (GTK_SEPARATOR_TOOL_ITEM (toolitem), FALSE);
+ #if !HAVE_HILDON
+ gtk_tool_item_set_expand (GTK_TOOL_ITEM (toolitem), TRUE);
+ #endif
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), toolitem, -1);
+ findbar->find_close = gtk_tool_button_new_from_stock (GTK_STOCK_CLOSE);
+ gtk_tool_button_set_label (GTK_TOOL_BUTTON (findbar->find_close),
+ _("Close Findbar"));
+ g_signal_connect (findbar->find_close, "clicked",
+ G_CALLBACK (midori_findbar_button_close_clicked_cb), findbar);
+ #if HAVE_OSX
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), findbar->find_close, 0);
+ #else
+ gtk_toolbar_insert (GTK_TOOLBAR (findbar), findbar->find_close, -1);
+ #endif
+ sokoke_container_show_children (GTK_CONTAINER (findbar));
+}
+
+void
+midori_findbar_set_can_find (MidoriFindbar* findbar,
+ gboolean can_find)
+{
+ gtk_widget_set_sensitive (GTK_WIDGET (findbar->next), can_find);
+ gtk_widget_set_sensitive (GTK_WIDGET (findbar->previous), can_find);
+}
+
+void
+midori_findbar_search_text (MidoriFindbar* findbar,
+ GtkWidget* view,
+ gboolean found,
+ gchar* typing)
+{
+ const gchar* text;
+ gboolean case_sensitive;
+ gboolean highlight;
+
+ if (typing)
+ {
+ MidoriBrowser* browser = midori_browser_get_for_widget (view);
+ gint position = -1;
+
+ findbar->find_typing = TRUE;
+ gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (
+ findbar->find_highlight), TRUE);
+ gtk_widget_hide (GTK_WIDGET (findbar->find_case));
+ gtk_widget_hide (GTK_WIDGET (findbar->find_highlight));
+ gtk_widget_hide (GTK_WIDGET (findbar->find_close));
+ if (!gtk_widget_get_visible (GTK_WIDGET (findbar)))
+ gtk_entry_set_text (GTK_ENTRY (findbar->find_text), "");
+ gtk_widget_show (GTK_WIDGET (findbar));
+ gtk_window_set_focus (GTK_WINDOW (browser), findbar->find_text);
+ gtk_editable_insert_text (GTK_EDITABLE (findbar->find_text),
+ typing, -1, &position);
+ gtk_editable_set_position (GTK_EDITABLE (findbar->find_text), -1);
+ }
+ if (gtk_widget_get_visible (GTK_WIDGET (findbar)) && !typing)
+ {
+ #if !HAVE_HILDON
+ gtk_icon_entry_set_icon_from_stock (GTK_ICON_ENTRY (findbar->find_text),
+ GTK_ICON_ENTRY_PRIMARY, (found) ? GTK_STOCK_FIND : GTK_STOCK_STOP);
+ #endif
+ text = gtk_entry_get_text (GTK_ENTRY (findbar->find_text));
+ case_sensitive = gtk_toggle_tool_button_get_active (
+ GTK_TOGGLE_TOOL_BUTTON (findbar->find_case));
+ midori_view_mark_text_matches (MIDORI_VIEW (view), text, case_sensitive);
+ highlight = gtk_toggle_tool_button_get_active (
+ GTK_TOGGLE_TOOL_BUTTON (findbar->find_highlight));
+ midori_view_set_highlight_text_matches (MIDORI_VIEW (view), highlight);
+ }
+}
+
+
diff --git a/toolbars/midori-findbar.h b/toolbars/midori-findbar.h
new file mode 100644
index 0000000..fffa497
--- /dev/null
+++ b/toolbars/midori-findbar.h
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2010 Christian Dywan <christian at twotoasts.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ See the file COPYING for the full license text.
+*/
+
+#ifndef __MIDORI_FINDBAR_H__
+#define __MIDORI_FINDBAR_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define MIDORI_TYPE_FINDBAR \
+ (midori_findbar_get_type ())
+#define MIDORI_FINDBAR(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), MIDORI_TYPE_FINDBAR, MidoriFindbar))
+#define MIDORI_FINDBAR_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), MIDORI_TYPE_FINDBAR, MidoriFindbarClass))
+#define MIDORI_IS_FINDBAR(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MIDORI_TYPE_FINDBAR))
+#define MIDORI_IS_FINDBAR_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), MIDORI_TYPE_FINDBAR))
+#define MIDORI_FINDBAR_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), MIDORI_TYPE_FINDBAR, MidoriFindbarClass))
+
+typedef struct _MidoriFindbar MidoriFindbar;
+typedef struct _MidoriFindbarClass MidoriFindbarClass;
+
+GType
+midori_findbar_get_type (void);
+
+void
+midori_findbar_invoke (MidoriFindbar* findbar);
+
+void
+midori_findbar_find (MidoriFindbar* findbar,
+ gboolean forward);
+
+void
+midori_findbar_set_can_find (MidoriFindbar* findbar,
+ gboolean can_find);
+
+void
+midori_findbar_search_text (MidoriFindbar* findbar,
+ GtkWidget* view,
+ gboolean found,
+ gchar* typing);
+
+G_END_DECLS
+
+#endif /* __MIDORI_FINDBAR_H__ */
More information about the Xfce4-commits
mailing list