X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Feggfindbar.c;h=f26237217d1eb5c4e8413c2c1a75504af6ae1fc3;hb=3ef022d148c7ddb762bb7ec483ef218d907bf143;hp=3a42ef6fcd838096d56aafe18e69e6d636ce8619;hpb=6b8fbfe2f3acb42e9dba650fcb1172c8aa02ba16;p=evince.git diff --git a/shell/eggfindbar.c b/shell/eggfindbar.c index 3a42ef6f..f2623721 100644 --- a/shell/eggfindbar.c +++ b/shell/eggfindbar.c @@ -1,60 +1,55 @@ /* 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 +#include "config.h" -#include "eggfindbar.h" +#include #include -#include -#include -#include -#include -#include -#include +#include #include -#include -#include +#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, @@ -65,21 +60,18 @@ static void egg_find_bar_set_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 }; @@ -90,24 +82,21 @@ egg_find_bar_class_init (EggFindBarClass *klass) { 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] = @@ -134,6 +123,15 @@ egg_find_bar_class_init (EggFindBarClass *klass) 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: @@ -145,8 +143,8 @@ egg_find_bar_class_init (EggFindBarClass *klass) 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)); @@ -159,32 +157,36 @@ egg_find_bar_class_init (EggFindBarClass *klass) 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"), - 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"), - GDK_TYPE_COLOR, - G_PARAM_READABLE)); - g_type_class_add_private (object_class, sizeof (EggFindBarPrivate)); binding_set = gtk_binding_set_by_class (klass); - gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0, + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Escape, 0, "close", 0); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Up, 0, + "scroll", 1, + GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_BACKWARD); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Down, 0, + "scroll", 1, + GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_STEP_FORWARD); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Up, 0, + "scroll", 1, + GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_BACKWARD); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Up, 0, + "scroll", 1, + GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_BACKWARD); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Page_Down, 0, + "scroll", 1, + GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_FORWARD); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Page_Down, 0, + "scroll", 1, + GTK_TYPE_SCROLL_TYPE, GTK_SCROLL_PAGE_FORWARD); } static void @@ -232,12 +234,9 @@ entry_activate_callback (GtkEntry *entry, 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 */ if (find_bar->priv->search_string != NULL) - gtk_widget_activate (priv->next_button); + egg_find_bar_emit_next (find_bar); } static void @@ -266,7 +265,7 @@ set_focus_cb (GtkWidget *window, 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 @@ -283,98 +282,67 @@ egg_find_bar_init (EggFindBar *find_bar) { 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); - label = gtk_label_new_with_mnemonic (_("F_ind:")); - separator = gtk_vseparator_new (); + /* 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 (_("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); - gtk_widget_set_sensitive (GTK_WIDGET (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); - gtk_widget_set_sensitive (GTK_WIDGET (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), @@ -391,6 +359,25 @@ egg_find_bar_init (EggFindBar *find_bar) 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 @@ -449,37 +436,6 @@ egg_find_bar_get_property (GObject *object, } } -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) { @@ -688,61 +644,6 @@ egg_find_bar_get_case_sensitive (EggFindBar *find_bar) return priv->case_sensitive; } -static void -get_style_color (EggFindBar *find_bar, - const char *style_prop_name, - GdkColor *color) -{ - GdkColor *style_color; - - gtk_widget_ensure_style (GTK_WIDGET (find_bar)); - gtk_widget_style_get (GTK_WIDGET (find_bar), - "color", &style_color, NULL); - if (style_color) - { - *color = *style_color; - gdk_color_free (style_color); - } -} - -/** - * egg_find_bar_get_all_matches_color: - * - * Gets the color to use to highlight all the - * known matches. - * - * Since: 2.6 - */ -void -egg_find_bar_get_all_matches_color (EggFindBar *find_bar, - GdkColor *color) -{ - GdkColor found_color = { 0, 0, 0, 0x0f0f }; - - get_style_color (find_bar, "all_matches_color", &found_color); - - *color = found_color; -} - -/** - * egg_find_bar_get_current_match_color: - * - * Gets the color to use to highlight the match - * we're currently on. - * - * Since: 2.6 - */ -void -egg_find_bar_get_current_match_color (EggFindBar *find_bar, - GdkColor *color) -{ - GdkColor found_color = { 0, 0, 0, 0xffff }; - - get_style_color (find_bar, "current_match_color", &found_color); - - *color = found_color; -} - /** * egg_find_bar_set_status_text: * @@ -763,16 +664,7 @@ egg_find_bar_set_status_text (EggFindBar *find_bar, 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); }