/* Copyright (C) 2004 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with the Gnome Library; see the file COPYING.LIB. If not,
+ * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Library General Public License as
-published by the Free Software Foundation; either version 2 of the
-License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-Library General Public License for more details.
-
-You should have received a copy of the GNU Library General Public
-License along with the Gnome Library; see the file COPYING.LIB. If not,
-write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
-*/
-
-#include <config.h>
+#include "config.h"
-#include "eggfindbar.h"
+#include <string.h>
#include <glib/gi18n.h>
-#include <gtk/gtkhbox.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtkcheckbutton.h>
-#include <gtk/gtkvseparator.h>
-#include <gtk/gtkstock.h>
-#include <gtk/gtklabel.h>
+#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
-#include <gtk/gtkbindings.h>
-#include <string.h>
+#include "eggfindbar.h"
struct _EggFindBarPrivate
{
gchar *search_string;
- GtkWidget *hbox;
+
+ GtkToolItem *next_button;
+ GtkToolItem *previous_button;
+ GtkToolItem *status_separator;
+ GtkToolItem *status_item;
+ GtkToolItem *case_button;
+
GtkWidget *find_entry;
- GtkWidget *next_button;
- GtkWidget *previous_button;
- GtkWidget *case_button;
- GtkWidget *status_separator;
GtkWidget *status_label;
+
gulong set_focus_handler;
guint case_sensitive : 1;
};
#define EGG_FIND_BAR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EGG_TYPE_FIND_BAR, EggFindBarPrivate))
-
-enum
- {
+enum {
PROP_0,
PROP_SEARCH_STRING,
PROP_CASE_SENSITIVE
- };
+};
static void egg_find_bar_finalize (GObject *object);
static void egg_find_bar_get_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
-static void egg_find_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition);
-static void egg_find_bar_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
static void egg_find_bar_show (GtkWidget *widget);
static void egg_find_bar_hide (GtkWidget *widget);
static void egg_find_bar_grab_focus (GtkWidget *widget);
-G_DEFINE_TYPE (EggFindBar, egg_find_bar, GTK_TYPE_BIN);
+G_DEFINE_TYPE (EggFindBar, egg_find_bar, GTK_TYPE_TOOLBAR);
enum
{
NEXT,
PREVIOUS,
CLOSE,
+ SCROLL,
LAST_SIGNAL
};
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
- GtkBinClass *bin_class;
GtkBindingSet *binding_set;
egg_find_bar_parent_class = g_type_class_peek_parent (klass);
object_class = (GObjectClass *)klass;
widget_class = (GtkWidgetClass *)klass;
- bin_class = (GtkBinClass *)klass;
object_class->set_property = egg_find_bar_set_property;
object_class->get_property = egg_find_bar_get_property;
object_class->finalize = egg_find_bar_finalize;
- widget_class->size_request = egg_find_bar_size_request;
- widget_class->size_allocate = egg_find_bar_size_allocate;
widget_class->show = egg_find_bar_show;
widget_class->hide = egg_find_bar_hide;
+
widget_class->grab_focus = egg_find_bar_grab_focus;
find_bar_signals[NEXT] =
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0);
+ find_bar_signals[SCROLL] =
+ g_signal_new ("scroll",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (EggFindBarClass, scroll),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__ENUM,
+ G_TYPE_NONE, 1,
+ GTK_TYPE_SCROLL_TYPE);
/**
* EggFindBar:search_string:
g_object_class_install_property (object_class,
PROP_SEARCH_STRING,
g_param_spec_string ("search_string",
- _("Search string"),
- _("The name of the string to be found"),
+ "Search string",
+ "The name of the string to be found",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_CASE_SENSITIVE,
g_param_spec_boolean ("case_sensitive",
- _("Case sensitive"),
- _("TRUE for a case sensitive search"),
+ "Case sensitive",
+ "TRUE for a case sensitive search",
FALSE,
G_PARAM_READWRITE));
/* Style properties */
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boxed ("all_matches_color",
- _("Highlight color"),
- _("Color of highlight for all matches"),
+ "Highlight color",
+ "Color of highlight for all matches",
GDK_TYPE_COLOR,
G_PARAM_READABLE));
gtk_widget_class_install_style_property (widget_class,
g_param_spec_boxed ("current_match_color",
- _("Current color"),
- _("Color of highlight for the current match"),
+ "Current color",
+ "Color of highlight for the current match",
GDK_TYPE_COLOR,
G_PARAM_READABLE));
gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
"close", 0);
+
+ gtk_binding_entry_add_signal (binding_set, GDK_Up, 0,
+ "scroll", 1,
+ GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_BACKWARD);
+ gtk_binding_entry_add_signal (binding_set, GDK_Down, 0,
+ "scroll", 1,
+ GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_FORWARD);
+ gtk_binding_entry_add_signal (binding_set, GDK_Page_Up, 0,
+ "scroll", 1,
+ GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_BACKWARD);
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Up, 0,
+ "scroll", 1,
+ GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_BACKWARD);
+ gtk_binding_entry_add_signal (binding_set, GDK_Page_Down, 0,
+ "scroll", 1,
+ GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_FORWARD);
+ gtk_binding_entry_add_signal (binding_set, GDK_KP_Page_Down, 0,
+ "scroll", 1,
+ GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_FORWARD);
}
static void
void *data)
{
EggFindBar *find_bar = EGG_FIND_BAR (data);
- EggFindBarPrivate *priv = (EggFindBarPrivate *)find_bar->priv;
- /* We activate the "next" button here so we'll get a nice
- animation */
- gtk_widget_activate (priv->next_button);
+ if (find_bar->priv->search_string != NULL)
+ egg_find_bar_emit_next (find_bar);
}
static void
text = g_strdup (gtk_entry_get_text (entry));
egg_find_bar_set_search_string (find_bar, text);
-
+
g_free (text);
}
while (widget != NULL && widget != wbar)
{
- widget = widget->parent;
+ widget = gtk_widget_get_parent (widget);
}
/* if widget == bar, the new focus widget is in the bar, so we
{
EggFindBarPrivate *priv;
GtkWidget *label;
- GtkWidget *separator;
- GtkWidget *image_back;
- GtkWidget *image_forward;
+ GtkWidget *alignment;
+ GtkWidget *box;
+ GtkToolItem *item;
+ GtkWidget *arrow;
/* Data */
priv = EGG_FIND_BAR_GET_PRIVATE (find_bar);
- find_bar->priv = priv;
-
+
+ find_bar->priv = priv;
priv->search_string = NULL;
- /* Widgets */
- gtk_widget_push_composite_child ();
- priv->hbox = gtk_hbox_new (FALSE, 6);
- gtk_container_set_border_width (GTK_CONTAINER (priv->hbox), 3);
+ gtk_toolbar_set_style (GTK_TOOLBAR (find_bar), GTK_TOOLBAR_BOTH_HORIZ);
+
+ /* Find: |_____| */
+ item = gtk_tool_item_new ();
+ box = gtk_hbox_new (FALSE, 12);
+
+ alignment = gtk_alignment_new (0.0, 0.5, 1.0, 0.0);
+ gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 2, 2);
- label = gtk_label_new_with_mnemonic (_("F_ind:"));
- separator = gtk_vseparator_new ();
+ label = gtk_label_new_with_mnemonic (_("Find:"));
priv->find_entry = gtk_entry_new ();
+ gtk_entry_set_width_chars (GTK_ENTRY (priv->find_entry), 32);
+ gtk_entry_set_max_length (GTK_ENTRY (priv->find_entry), 512);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->find_entry);
- priv->previous_button = gtk_button_new_with_mnemonic (_("_Previous"));
- gtk_button_set_focus_on_click (GTK_BUTTON (priv->previous_button), FALSE);
- priv->next_button = gtk_button_new_with_mnemonic (_("_Next"));
- gtk_button_set_focus_on_click (GTK_BUTTON (priv->next_button), FALSE);
-
- image_back = gtk_image_new_from_stock (GTK_STOCK_GO_BACK,
- GTK_ICON_SIZE_BUTTON);
- image_forward = gtk_image_new_from_stock (GTK_STOCK_GO_FORWARD,
- GTK_ICON_SIZE_BUTTON);
-
- gtk_button_set_image (GTK_BUTTON (priv->previous_button),
- image_back);
- gtk_button_set_image (GTK_BUTTON (priv->next_button),
- image_forward);
-
- priv->case_button = gtk_check_button_new_with_mnemonic (_("C_ase Sensitive"));
-
- priv->status_separator = gtk_vseparator_new ();
-
+ /* Prev */
+ arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
+ priv->previous_button = gtk_tool_button_new (arrow, Q_("Find Pre_vious"));
+ gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->previous_button), TRUE);
+ gtk_tool_item_set_is_important (priv->previous_button, TRUE);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (priv->previous_button),
+ _("Find previous occurrence of the search string"));
+
+ /* Next */
+ arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
+ priv->next_button = gtk_tool_button_new (arrow, Q_("Find Ne_xt"));
+ gtk_tool_button_set_use_underline (GTK_TOOL_BUTTON (priv->next_button), TRUE);
+ gtk_tool_item_set_is_important (priv->next_button, TRUE);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (priv->next_button),
+ _("Find next occurrence of the search string"));
+
+ /* Separator*/
+ priv->status_separator = gtk_separator_tool_item_new();
+
+ /* Case button */
+ priv->case_button = gtk_toggle_tool_button_new ();
+ g_object_set (G_OBJECT (priv->case_button), "label", _("C_ase Sensitive"), NULL);
+ gtk_tool_item_set_is_important (priv->case_button, TRUE);
+ gtk_widget_set_tooltip_text (GTK_WIDGET (priv->case_button),
+ _("Toggle case sensitive search"));
+
+ /* Status */
+ priv->status_item = gtk_tool_item_new();
+ gtk_tool_item_set_expand (priv->status_item, TRUE);
priv->status_label = gtk_label_new (NULL);
gtk_label_set_ellipsize (GTK_LABEL (priv->status_label),
PANGO_ELLIPSIZE_END);
gtk_misc_set_alignment (GTK_MISC (priv->status_label), 0.0, 0.5);
-
-#if 0
- {
- GtkWidget *button_label;
- /* This hack doesn't work because GtkCheckButton doesn't pass the
- * larger size allocation to the label, it always gives the label
- * its exact request. If you un-ifdef this, set the box back
- * on case_button to TRUE, TRUE below
- */
- button_label = gtk_bin_get_child (GTK_BIN (priv->case_button));
- gtk_label_set_ellipsize (GTK_LABEL (button_label),
- PANGO_ELLIPSIZE_END);
- }
-#endif
-
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- label, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->find_entry, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->previous_button, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->next_button, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- separator, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->case_button, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->status_separator, FALSE, FALSE, 0);
- gtk_box_pack_start (GTK_BOX (priv->hbox),
- priv->status_label, TRUE, TRUE, 0);
-
- gtk_container_add (GTK_CONTAINER (find_bar), priv->hbox);
-
- gtk_widget_show (priv->hbox);
- gtk_widget_show (priv->find_entry);
- gtk_widget_show (priv->previous_button);
- gtk_widget_show (priv->next_button);
- gtk_widget_show (separator);
- gtk_widget_show (label);
- gtk_widget_show (image_back);
- gtk_widget_show (image_forward);
- /* don't show status separator/label until they are set */
- gtk_widget_pop_composite_child ();
g_signal_connect (priv->find_entry, "changed",
G_CALLBACK (entry_changed_callback),
g_signal_connect (priv->case_button, "toggled",
G_CALLBACK (case_sensitive_toggled_callback),
find_bar);
+
+ gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box), priv->find_entry, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (alignment), box);
+ gtk_container_add (GTK_CONTAINER (item), alignment);
+ gtk_toolbar_insert (GTK_TOOLBAR (find_bar), item, -1);
+ gtk_toolbar_insert (GTK_TOOLBAR (find_bar), priv->previous_button, -1);
+ gtk_toolbar_insert (GTK_TOOLBAR (find_bar), priv->next_button, -1);
+ gtk_toolbar_insert (GTK_TOOLBAR (find_bar), priv->case_button, -1);
+ gtk_toolbar_insert (GTK_TOOLBAR (find_bar), priv->status_separator, -1);
+ gtk_container_add (GTK_CONTAINER (priv->status_item), priv->status_label);
+ gtk_toolbar_insert (GTK_TOOLBAR (find_bar), priv->status_item, -1);
+
+ /* don't show status separator/label until they are set */
+
+ gtk_widget_show_all (GTK_WIDGET (item));
+ gtk_widget_show_all (GTK_WIDGET (priv->next_button));
+ gtk_widget_show_all (GTK_WIDGET (priv->previous_button));
+ gtk_widget_show (priv->status_label);
}
static void
}
}
-static void
-egg_find_bar_size_request (GtkWidget *widget,
- GtkRequisition *requisition)
-{
- GtkBin *bin = GTK_BIN (widget);
- GtkRequisition child_requisition;
- if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
- {
- gtk_widget_size_request (bin->child, &child_requisition);
-
- *requisition = child_requisition;
- }
- else
- {
- requisition->width = 0;
- requisition->height = 0;
- }
-}
-
-static void
-egg_find_bar_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation)
-{
- GtkBin *bin = GTK_BIN (widget);
-
- widget->allocation = *allocation;
-
- if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
- gtk_widget_size_allocate (bin->child, allocation);
-}
-
static void
egg_find_bar_show (GtkWidget *widget)
{
(old && search_string &&
strcmp (old, search_string) != 0))
{
+ gboolean not_empty;
+
priv->search_string = g_strdup (search_string);
g_free (old);
priv->search_string ?
priv->search_string :
"");
-
+
+ not_empty = (search_string == NULL) ? FALSE : TRUE;
+
+ gtk_widget_set_sensitive (GTK_WIDGET (find_bar->priv->next_button), not_empty);
+ gtk_widget_set_sensitive (GTK_WIDGET (find_bar->priv->previous_button), not_empty);
+
g_object_notify (G_OBJECT (find_bar),
"search_string");
}
priv = (EggFindBarPrivate *)find_bar->priv;
- if (text == NULL || *text == '\0')
- {
- gtk_widget_hide (priv->status_label);
- gtk_widget_hide (priv->status_separator);
- gtk_label_set_text (GTK_LABEL (priv->status_label), NULL);
- }
- else
- {
- gtk_label_set_text (GTK_LABEL (priv->status_label), text);
- gtk_widget_show (priv->status_label);
- gtk_widget_show (priv->status_separator);
- }
+ gtk_label_set_text (GTK_LABEL (priv->status_label), text);
+ g_object_set (priv->status_separator, "visible", text != NULL && *text != '\0', NULL);
+ g_object_set (priv->status_item, "visible", text != NULL && *text !='\0', NULL);
}