* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id$
*/
#include "config.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/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;
-};
+#include <stdlib.h>
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);
-
-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_init (EvPageAction *action);
+static void ev_page_action_class_init (EvPageActionClass *class);
-static void
-ev_page_action_widget_class_init (EvPageActionWidgetClass *action_widget)
+enum
{
-}
-
-
+ ACTIVATE_LINK,
+ N_SIGNALS
+};
-static void ev_page_action_init (EvPageAction *action);
-static void ev_page_action_class_init (EvPageActionClass *class);
+static guint signals[N_SIGNALS] = {0, };
G_DEFINE_TYPE (EvPageAction, ev_page_action, GTK_TYPE_ACTION)
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,
gint n_pages;
n_pages = page_cache ? ev_page_cache_get_n_pages (page_cache) : 0;
- if (ev_page_cache_has_nonnumeric_page_labels (page_cache)) {
+ if (page_cache && ev_page_cache_has_nonnumeric_page_labels (page_cache)) {
label_text = g_strdup_printf (_("(%d of %d)"), page + 1, n_pages);
} else {
label_text = g_strdup_printf (_("of %d"), n_pages);
g_assert (proxy);
if (page_cache != NULL && page >= 0) {
- gchar *page_label = ev_page_cache_get_page_label (page_cache, page);
+ gchar *page_label;
+
+ gtk_entry_set_width_chars (GTK_ENTRY (proxy->entry),
+ CLAMP (ev_page_cache_get_max_label_chars (page_cache),
+ 6, 12));
+
+ 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);
+
} else {
gtk_entry_set_text (GTK_ENTRY (proxy->entry), "");
}
EvPageAction *page = EV_PAGE_ACTION (action);
EvPageCache *page_cache;
const char *text;
+ 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;
- if (! ev_page_cache_set_page_label (page_cache, text)) {
- /* 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);
- }
+
+ 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);
+
+ 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 GtkWidget *
g_signal_handler_disconnect (proxy->page_cache, proxy->signal_id);
if (page_cache != NULL) {
- signal_id = g_signal_connect (page_cache,
- "page-changed",
- G_CALLBACK (page_changed_cb),
- proxy);
+ signal_id = g_signal_connect_object (page_cache,
+ "page-changed",
+ G_CALLBACK (page_changed_cb),
+ proxy, 0);
/* Set the initial value */
page_changed_cb (page_cache,
ev_page_cache_get_current_page (page_cache),
signal_id = 0;
page_changed_cb (NULL, 0, proxy);
}
- proxy->page_cache = page_cache;
+ ev_page_action_widget_set_page_cache (proxy, page_cache);
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);
- ev_page_cache_set_link (proxy->page_cache, link);
-
- return TRUE;
-}
-
-
static void
-display_completion_text (GtkCellLayout *cell_layout,
- GtkCellRenderer *renderer,
- GtkTreeModel *filter_model,
- GtkTreeIter *filter_iter,
- EvPageActionWidget *proxy)
+activate_link_cb (EvPageActionWidget *proxy, EvLink *link, EvPageAction *action)
{
- 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);
+ g_signal_emit (action, signals[ACTIVATE_LINK], 0, link);
}
-static gboolean
-match_completion (GtkEntryCompletion *completion,
- const gchar *key,
- GtkTreeIter *filter_iter,
- EvPageActionWidget *proxy)
-{
- 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;
-}
-
-
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);
- }
+
+ ev_page_action_widget_update_model (proxy, model);
}
static void
g_signal_connect_object (action, "notify::page-cache",
G_CALLBACK (update_page_cache),
proxy, 0);
- /* 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 (proxy, "activate_link",
+ G_CALLBACK (activate_link_cb),
+ action);
+ update_page_cache (EV_PAGE_ACTION (action), NULL,
+ EV_PAGE_ACTION_WIDGET (proxy));
+ 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);
EvPageAction *page = EV_PAGE_ACTION (object);
if (page->priv->page_cache) {
- g_signal_handlers_disconnect_matched (page->priv->page_cache, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, page_changed_cb, NULL);
g_object_unref (page->priv->page_cache);
page->priv->page_cache = NULL;
}
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,
NULL);
}
+void
+ev_page_action_grab_focus (EvPageAction *page_action)
+{
+ GSList *proxies;
+
+ proxies = gtk_action_get_proxies (GTK_ACTION (page_action));
+ for (; proxies != NULL; proxies = proxies->next) {
+ EvPageActionWidget *proxy;
+
+ proxy = EV_PAGE_ACTION_WIDGET (proxies->data);
+ gtk_widget_grab_focus (proxy->entry);
+ }
+}
+
static void
ev_page_action_init (EvPageAction *page)
{
action_class->create_tool_item = create_tool_item;
action_class->connect_proxy = connect_proxy;
+ signals[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);
+
g_object_class_install_property (object_class,
PROP_PAGE_CACHE,
g_param_spec_object ("page-cache",