]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-page-action.c
Updated Greek translation by Papadeas Pierros
[evince.git] / shell / ev-page-action.c
index b1c61e63ed086ffc94c09e793895881bf22312ed..cc3615abf091164041f99d7d59607e9f1bdda7f7 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  *
- *  $Id$
  */
 
+#ifdef HAVE_CONFIG_H
 #include "config.h"
+#endif
+
+#include <string.h>
+#include <stdlib.h>
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
 
 #include "ev-page-action.h"
+#include "ev-page-cache.h"
 #include "ev-window.h"
 #include "ev-document-links.h"
+#include "ev-page-action-widget.h"
 #include "ev-marshal.h"
 
-#include <glib/gi18n.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtktoolitem.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkhbox.h>
-#include <string.h>
-
-typedef struct _EvPageActionWidget EvPageActionWidget;
-typedef struct _EvPageActionWidgetClass EvPageActionWidgetClass;
-struct _EvPageActionWidget
-{
-       GtkToolItem parent;
-
-       GtkWidget *entry;
-       GtkWidget *label;
-       EvPageCache *page_cache;
-       guint signal_id;
-       GtkTreeModel *filter_model;
-       GtkTreeModel *model;
-};
-
-struct _EvPageActionWidgetClass
-{
-       GtkToolItemClass parent_class;
-
-       void (* activate_link) (EvPageActionWidget *page_action,
-                               EvLink             *link);
-};
-
 struct _EvPageActionPrivate
 {
        EvPageCache *page_cache;
@@ -62,80 +42,12 @@ struct _EvPageActionPrivate
 };
 
 
-/* Widget we pass back */
-static GType ev_page_action_widget_get_type   (void);
-static void  ev_page_action_widget_init       (EvPageActionWidget      *action_widget);
-static void  ev_page_action_widget_class_init (EvPageActionWidgetClass *action_widget);
-
-#define EV_TYPE_PAGE_ACTION_WIDGET (ev_page_action_widget_get_type ())
-#define EV_PAGE_ACTION_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EV_TYPE_PAGE_ACTION_WIDGET, EvPageActionWidget))
-
-enum
-{
-       WIDGET_ACTIVATE_LINK,
-       WIDGET_N_SIGNALS
-};
-
-static guint widget_signals[WIDGET_N_SIGNALS] = {0, };
-
-G_DEFINE_TYPE (EvPageActionWidget, ev_page_action_widget, GTK_TYPE_TOOL_ITEM)
-
-static void
-ev_page_action_widget_init (EvPageActionWidget *action_widget)
-{
-
-}
-
-static void
-ev_page_action_widget_set_page_cache (EvPageActionWidget *action_widget,
-                                     EvPageCache        *page_cache)
-{
-       if (action_widget->page_cache != NULL) {
-               g_object_remove_weak_pointer (G_OBJECT (action_widget->page_cache),
-                                             (gpointer *)&action_widget->page_cache);
-               action_widget->page_cache = NULL;
-       }
-
-       if (page_cache != NULL) {
-               action_widget->page_cache = page_cache;
-               g_object_add_weak_pointer (G_OBJECT (page_cache),
-                                          (gpointer *)&action_widget->page_cache);
-       }
-}
-
-static void
-ev_page_action_widget_finalize (GObject *object)
-{
-       EvPageActionWidget *action_widget = EV_PAGE_ACTION_WIDGET (object);
-
-       ev_page_action_widget_set_page_cache (action_widget, NULL);
-}
-
-static void
-ev_page_action_widget_class_init (EvPageActionWidgetClass *class)
-{
-       GObjectClass *object_class = G_OBJECT_CLASS (class);
-
-       object_class->finalize = ev_page_action_widget_finalize;
-
-       widget_signals[WIDGET_ACTIVATE_LINK] = g_signal_new ("activate_link",
-                                              G_OBJECT_CLASS_TYPE (object_class),
-                                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                                              G_STRUCT_OFFSET (EvPageActionClass, activate_link),
-                                              NULL, NULL,
-                                              g_cclosure_marshal_VOID__OBJECT,
-                                              G_TYPE_NONE, 1,
-                                              G_TYPE_OBJECT);
-
-}
-
 static void ev_page_action_init       (EvPageAction *action);
 static void ev_page_action_class_init (EvPageActionClass *class);
 
 enum
 {
        ACTIVATE_LINK,
-       ACTIVATE_LABEL,
        N_SIGNALS
 };
 
@@ -151,9 +63,6 @@ enum {
        PROP_MODEL,
 };
 
-/* user data to set on the widget. */
-#define EPA_FILTER_MODEL_DATA "epa-filter-model"
-
 static void
 update_pages_label (EvPageActionWidget *proxy,
                    gint                page,
@@ -180,12 +89,13 @@ page_changed_cb (EvPageCache        *page_cache,
        g_assert (proxy);
        
        if (page_cache != NULL && page >= 0) {
-       
+               gchar *page_label;
+
                gtk_entry_set_width_chars (GTK_ENTRY (proxy->entry), 
                                           CLAMP (ev_page_cache_get_max_label_chars (page_cache), 
-                                          4, 12));     
+                                          6, 12));     
                
-               gchar *page_label = ev_page_cache_get_page_label (page_cache, page);
+               page_label = ev_page_cache_get_page_label (page_cache, page);
                gtk_entry_set_text (GTK_ENTRY (proxy->entry), page_label);
                gtk_editable_set_position (GTK_EDITABLE (proxy->entry), -1);
                g_free (page_label);
@@ -203,23 +113,49 @@ activate_cb (GtkWidget *entry, GtkAction *action)
        EvPageAction *page = EV_PAGE_ACTION (action);
        EvPageCache *page_cache;
        const char *text;
-       gboolean changed;
+       gchar *page_label;
+       
+       EvLinkDest *link_dest;
+       EvLinkAction *link_action;
+       EvLink *link;
+       gchar *link_text;
 
        text = gtk_entry_get_text (GTK_ENTRY (entry));
        page_cache = page->priv->page_cache;
 
-       g_signal_emit (action, signals[ACTIVATE_LABEL], 0, text, &changed);
+       
+       link_dest = ev_link_dest_new_page_label (text);
+       link_action = ev_link_action_new_dest (link_dest);
+       link_text = g_strdup_printf ("Page: %s", text);
+       link = ev_link_new (link_text, link_action);
 
-       if (!changed) {
-               /* rest the entry to the current page if we were unable to
-                * change it */
-               gchar *page_label =
-                       ev_page_cache_get_page_label (page_cache,
-                                                     ev_page_cache_get_current_page (page_cache));
-               gtk_entry_set_text (GTK_ENTRY (entry), page_label);
-               gtk_editable_set_position (GTK_EDITABLE (entry), -1);
-               g_free (page_label);
-       }
+       g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
+
+       g_object_unref (link);
+       g_free (link_text);
+       
+       /* rest the entry to the current page if we were unable to
+        * change it */
+       page_label = ev_page_cache_get_page_label (page_cache,
+                                                  ev_page_cache_get_current_page (page_cache));
+       gtk_entry_set_text (GTK_ENTRY (entry), page_label);
+       gtk_editable_set_position (GTK_EDITABLE (entry), -1);
+       g_free (page_label);
+}
+
+static gboolean page_scroll_cb(GtkWidget *widget, GdkEventScroll *event, EvPageAction* action)
+{
+       gint pageno;
+
+       pageno = ev_page_cache_get_current_page (action->priv->page_cache);
+       if ((event->direction == GDK_SCROLL_DOWN) && 
+           (pageno < ev_page_cache_get_n_pages(action->priv->page_cache) - 1))
+               pageno++;
+       if ((event->direction == GDK_SCROLL_UP) && (pageno > 0))
+               pageno--;
+       ev_page_cache_set_current_page (action->priv->page_cache, pageno);
+       
+       return TRUE;
 }
 
 static GtkWidget *
@@ -227,6 +163,7 @@ create_tool_item (GtkAction *action)
 {
        EvPageActionWidget *proxy;
        GtkWidget *hbox;
+        AtkObject *obj;
 
        proxy = g_object_new (ev_page_action_widget_get_type (), NULL);
        gtk_container_set_border_width (GTK_CONTAINER (proxy), 6); 
@@ -236,6 +173,11 @@ create_tool_item (GtkAction *action)
        gtk_box_set_spacing (GTK_BOX (hbox), 6);
 
        proxy->entry = gtk_entry_new ();
+       obj = gtk_widget_get_accessible (proxy->entry);
+        atk_object_set_name (obj, "page-label-entry");
+                
+       g_signal_connect(proxy->entry, "scroll-event",G_CALLBACK(page_scroll_cb),action);
+       gtk_widget_add_events(GTK_WIDGET(proxy->entry),GDK_BUTTON_MOTION_MASK);
        gtk_entry_set_width_chars (GTK_ENTRY (proxy->entry), 5);
        gtk_box_pack_start (GTK_BOX (hbox), proxy->entry, FALSE, FALSE, 0);
        gtk_widget_show (proxy->entry);
@@ -283,190 +225,22 @@ update_page_cache (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *pr
        proxy->signal_id = signal_id;
 }
 
-static gboolean
-build_new_tree_cb (GtkTreeModel *model,
-                  GtkTreePath  *path,
-                  GtkTreeIter  *iter,
-                  gpointer      data)
-{
-       GtkTreeModel *filter_model = GTK_TREE_MODEL (data);
-       EvLink *link;
-
-       gtk_tree_model_get (model, iter,
-                           EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-                           -1);
-
-       if (link && ev_link_get_link_type (link) == EV_LINK_TYPE_PAGE) {
-               GtkTreeIter filter_iter;
-
-               gtk_list_store_append (GTK_LIST_STORE (filter_model), &filter_iter);
-               gtk_list_store_set (GTK_LIST_STORE (filter_model), &filter_iter,
-                                   0, iter,
-                                   -1);
-       }
-       
-       return FALSE;
-}
-
-static GtkTreeModel *
-get_filter_model_from_model (GtkTreeModel *model)
-{
-       GtkTreeModel *filter_model;
-
-       filter_model =
-               (GtkTreeModel *) g_object_get_data (G_OBJECT (model), EPA_FILTER_MODEL_DATA);
-       if (filter_model == NULL) {
-               filter_model = (GtkTreeModel *) gtk_list_store_new (1, GTK_TYPE_TREE_ITER);
-
-               gtk_tree_model_foreach (model,
-                                       build_new_tree_cb,
-                                       filter_model);
-               g_object_set_data_full (G_OBJECT (model), EPA_FILTER_MODEL_DATA, filter_model, g_object_unref);
-       }
-
-       return filter_model;
-}
-
-static gboolean
-match_selected_cb (GtkEntryCompletion *completion,
-                  GtkTreeModel       *filter_model,
-                  GtkTreeIter        *filter_iter,
-                  EvPageActionWidget *proxy)
-{
-       EvLink *link;
-       GtkTreeIter *iter;
-
-       gtk_tree_model_get (filter_model, filter_iter,
-                           0, &iter,
-                           -1);
-       gtk_tree_model_get (proxy->model, iter,
-                           EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-                           -1);
-
-       g_signal_emit (proxy, signals[ACTIVATE_LINK], 0, link);
-       
-       return TRUE;
-}
-                  
-
 static void
-display_completion_text (GtkCellLayout      *cell_layout,
-                        GtkCellRenderer    *renderer,
-                        GtkTreeModel       *filter_model,
-                        GtkTreeIter        *filter_iter,
-                        EvPageActionWidget *proxy)
-{
-       EvLink *link;
-       GtkTreeIter *iter;
-
-       gtk_tree_model_get (filter_model, filter_iter,
-                           0, &iter,
-                           -1);
-       gtk_tree_model_get (proxy->model, iter,
-                           EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-                           -1);
-
-       g_object_set (renderer, "text", ev_link_get_title (link), NULL);
-}
-
-static gboolean
-match_completion (GtkEntryCompletion *completion,
-                 const gchar        *key,
-                 GtkTreeIter        *filter_iter,
-                 EvPageActionWidget *proxy)
+activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action)
 {
-       EvLink *link;
-       GtkTreeIter *iter;
-       const gchar *text = NULL;
-
-       gtk_tree_model_get (gtk_entry_completion_get_model (completion),
-                           filter_iter,
-                           0, &iter,
-                           -1);
-       gtk_tree_model_get (proxy->model, iter,
-                           EV_DOCUMENT_LINKS_COLUMN_LINK, &link,
-                           -1);
-
-
-       if (link)
-               text = ev_link_get_title (link);
-
-       if (text && key ) {
-               gchar *normalized_text;
-               gchar *normalized_key;
-               gchar *case_normalized_text;
-               gchar *case_normalized_key;
-               gboolean retval = FALSE;
-
-               normalized_text = g_utf8_normalize (text, -1, G_NORMALIZE_ALL);
-               normalized_key = g_utf8_normalize (key, -1, G_NORMALIZE_ALL);
-               case_normalized_text = g_utf8_casefold (normalized_text, -1);
-               case_normalized_key = g_utf8_casefold (normalized_key, -1);
-
-               if (strstr (case_normalized_text, case_normalized_key))
-                       retval = TRUE;
-
-               g_free (normalized_text);
-               g_free (normalized_key);
-               g_free (case_normalized_text);
-               g_free (case_normalized_key);
-
-               return retval;
-       }
-
-       return FALSE;
+       g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
 }
 
-
 static void
 update_model (EvPageAction *page, GParamSpec *pspec, EvPageActionWidget *proxy)
-{
+{      
        GtkTreeModel *model;
-       GtkTreeModel *filter_model;
 
        g_object_get (G_OBJECT (page),
                      "model", &model,
                      NULL);
-       if (model != NULL) {
-               /* Magik */
-               GtkEntryCompletion *completion;
-               GtkCellRenderer *renderer;
-
-               proxy->model = model;
-               filter_model = get_filter_model_from_model (model);
-
-               completion = gtk_entry_completion_new ();
-
-               /* popup-set-width is 2.7.0 only */
-               g_object_set (G_OBJECT (completion),
-                             "popup-set-width", FALSE,
-                             "model", filter_model,
-                             NULL);
-
-               g_signal_connect (completion, "match-selected", G_CALLBACK (match_selected_cb), proxy);
-               gtk_entry_completion_set_match_func (completion,
-                                                    (GtkEntryCompletionMatchFunc) match_completion,
-                                                    proxy, NULL);
-
-               /* Set up the layout */
-               renderer = (GtkCellRenderer *)
-                       g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
-                                     "ellipsize", PANGO_ELLIPSIZE_END,
-                                     "width_chars", 30,
-                                     NULL);
-               gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (completion), renderer, TRUE);
-               gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
-                                                   renderer,
-                                                   (GtkCellLayoutDataFunc) display_completion_text,
-                                                   proxy, NULL);
-               gtk_entry_set_completion (GTK_ENTRY (proxy->entry), completion);
-       }
-}
 
-static void
-activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action)
-{
-       g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
+       ev_page_action_widget_update_model (proxy, model);
 }
 
 static void
@@ -481,14 +255,9 @@ connect_proxy (GtkAction *action, GtkWidget *proxy)
                                  action);
                update_page_cache (EV_PAGE_ACTION (action), NULL,
                                   EV_PAGE_ACTION_WIDGET (proxy));
-               /* We only go through this whole rigmarole if we can set
-                * GtkEntryCompletion::popup-set-width, which appeared in
-                * GTK+-2.7.0 */
-               if (gtk_check_version (2, 7, 0) == NULL) {
-                       g_signal_connect_object (action, "notify::model",
-                                                G_CALLBACK (update_model),
-                                                proxy, 0);
-               }
+               g_signal_connect_object (action, "notify::model",
+                                        G_CALLBACK (update_model),
+                                        proxy, 0);
        }
 
        GTK_ACTION_CLASS (ev_page_action_parent_class)->connect_proxy (action, proxy);
@@ -569,7 +338,7 @@ ev_page_action_set_document (EvPageAction *page, EvDocument *document)
        EvPageCache *page_cache = NULL;
 
        if (document)
-               page_cache = ev_document_get_page_cache (document);
+               page_cache = ev_page_cache_get (document);
        
        g_object_set (page,
                      "page-cache", page_cache,
@@ -596,7 +365,9 @@ ev_page_action_grab_focus (EvPageAction *page_action)
                EvPageActionWidget *proxy;
 
                proxy = EV_PAGE_ACTION_WIDGET (proxies->data);
-               gtk_widget_grab_focus (proxy->entry);
+               
+               if (GTK_WIDGET_MAPPED (GTK_WIDGET (proxy)))
+                       gtk_widget_grab_focus (proxy->entry);
        }
 }
 
@@ -628,14 +399,6 @@ ev_page_action_class_init (EvPageActionClass *class)
                                               g_cclosure_marshal_VOID__OBJECT,
                                               G_TYPE_NONE, 1,
                                               G_TYPE_OBJECT);
-       signals[ACTIVATE_LABEL] = g_signal_new ("activate_label",
-                                               G_OBJECT_CLASS_TYPE (object_class),
-                                               G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                                               G_STRUCT_OFFSET (EvPageActionClass, activate_link),
-                                               NULL, NULL,
-                                               ev_marshal_BOOLEAN__STRING,
-                                               G_TYPE_BOOLEAN, 1,
-                                               G_TYPE_STRING);
 
        g_object_class_install_property (object_class,
                                         PROP_PAGE_CACHE,