X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=shell%2Fev-window.c;h=652d435552020d6f4f1d25758cb61a9e1995c502;hb=08693866e1d7b85df9d362eb4412e94959b3948d;hp=471a45dbf7ed6c68f38c80011c306ef043d7ee83;hpb=c057cade000e7e71c7af4f34ac86c96dfd52f526;p=evince.git diff --git a/shell/ev-window.c b/shell/ev-window.c index 471a45db..652d4355 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -47,12 +47,13 @@ #include "egg-recent-view-gtk.h" #include "egg-recent-view.h" #include "egg-recent-model.h" +#include "ephy-zoom.h" +#include "ephy-zoom-action.h" #include #include #include -#include #include #include #include @@ -110,7 +111,6 @@ struct _EvWindowPrivate { char *password_uri; EvChrome chrome; - gboolean fullscreen_mode; GSource *fullscreen_timeout_source; /* recent file stuff */ @@ -127,6 +127,7 @@ static const GtkTargetEntry ev_drop_types[] = { (G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate)) #define PAGE_SELECTOR_ACTION "PageSelector" +#define ZOOM_CONTROL_ACTION "ViewZoom" #define GCONF_CHROME_TOOLBAR "/apps/evince/show_toolbar" #define GCONF_CHROME_SIDEBAR "/apps/evince/show_sidebar" @@ -136,18 +137,29 @@ static const GtkTargetEntry ev_drop_types[] = { #define SIDEBAR_DEFAULT_SIZE 132 -static void ev_window_update_fullscreen_popup (EvWindow *window); -static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec, - EvWindow *ev_window); -static void ev_window_set_page_mode (EvWindow *window, - EvWindowPageMode page_mode); -static gboolean start_loading_document (EvWindow *ev_window, - EvDocument *document, - const char *uri); -static void ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec, - EvWindow *ev_window); -static void ev_window_add_recent (EvWindow *window, const char *filename); -static void ev_window_fullscreen (EvWindow *window); +static void ev_window_update_fullscreen_popup (EvWindow *window); +static void ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, + GParamSpec *pspec, + EvWindow *ev_window); +static void ev_window_set_page_mode (EvWindow *window, + EvWindowPageMode page_mode); +static gboolean start_loading_document (EvWindow *ev_window, + EvDocument *document, + const char *uri); +static void ev_window_sizing_mode_changed_cb (EvView *view, + GParamSpec *pspec, + EvWindow *ev_window); +static void ev_window_add_recent (EvWindow *window, + const char *filename); +static void ev_window_fullscreen (EvWindow *window); +static void ev_window_unfullscreen (EvWindow *window); +static void ev_window_cmd_view_fullscreen (GtkAction *action, + EvWindow *window); +static void ev_window_run_presentation (EvWindow *window); +static void ev_window_stop_presentation (EvWindow *window); +static void ev_window_cmd_view_presentation (GtkAction *action, + EvWindow *window); + G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW) @@ -235,6 +247,21 @@ update_action_sensitivity (EvWindow *ev_window) /* Toolbar-specific actions: */ set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, has_pages); + set_action_sensitive (ev_window, ZOOM_CONTROL_ACTION, has_pages); + + if (has_pages && ev_view_get_sizing_mode (view) == EV_SIZING_FREE) { + GtkAction *action; + float zoom; + float real_zoom; + + action = gtk_action_group_get_action (ev_window->priv->action_group, + ZOOM_CONTROL_ACTION); + + real_zoom = ev_view_get_zoom (EV_VIEW (ev_window->priv->view)); + zoom = ephy_zoom_get_nearest_zoom_level (real_zoom); + + ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), zoom); + } } static void @@ -253,12 +280,17 @@ update_chrome_visibility (EvWindow *window) { EvWindowPrivate *priv = window->priv; gboolean menubar, toolbar, sidebar, findbar, statusbar, fullscreen_toolbar; + gboolean fullscreen_mode, presentation, fullscreen; + + presentation = ev_view_get_presentation (EV_VIEW (priv->view)); + fullscreen = ev_view_get_fullscreen (EV_VIEW (priv->view)); + fullscreen_mode = fullscreen || presentation; - menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !priv->fullscreen_mode; - toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0 && !priv->fullscreen_mode; - sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !priv->fullscreen_mode; + menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !fullscreen_mode; + toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0 && !fullscreen_mode; + sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !fullscreen_mode; fullscreen_toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0; - statusbar = (priv->chrome & EV_CHROME_STATUSBAR) != 0 && !priv->fullscreen_mode; + statusbar = (priv->chrome & EV_CHROME_STATUSBAR) != 0 && !fullscreen_mode; findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0; set_widget_visibility (priv->menubar, menubar); @@ -269,7 +301,7 @@ update_chrome_visibility (EvWindow *window) set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar); if (priv->fullscreen_popup != NULL) { - set_widget_visibility (priv->fullscreen_popup, priv->fullscreen_mode); + set_widget_visibility (priv->fullscreen_popup, fullscreen); } } @@ -300,6 +332,7 @@ ev_window_cmd_continuous (GtkAction *action, EvWindow *ev_window) { gboolean continuous; + ev_window_stop_presentation (ev_window); continuous = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); g_object_set (G_OBJECT (ev_window->priv->view), "continuous", continuous, @@ -312,6 +345,7 @@ ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window) { gboolean dual_page; + ev_window_stop_presentation (ev_window); dual_page = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); g_object_set (G_OBJECT (ev_window->priv->view), "dual-page", dual_page, @@ -322,6 +356,8 @@ ev_window_cmd_dual (GtkAction *action, EvWindow *ev_window) static void ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window) { + ev_window_stop_presentation (ev_window); + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_BEST_FIT); } else { @@ -333,6 +369,8 @@ ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window) static void ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window) { + ev_window_stop_presentation (ev_window); + if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FIT_WIDTH); } else { @@ -384,6 +422,16 @@ update_sizing_buttons (EvWindow *window) gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), page_width); g_signal_handlers_unblock_by_func (action, G_CALLBACK (ev_window_cmd_view_page_width), window); + + action = gtk_action_group_get_action (window->priv->action_group, + ZOOM_CONTROL_ACTION); + if (best_fit) { + ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), + EPHY_ZOOM_BEST_FIT); + } else if (page_width) { + ephy_zoom_action_set_zoom_level (EPHY_ZOOM_ACTION (action), + EPHY_ZOOM_FIT_WIDTH); + } } void @@ -497,7 +545,9 @@ static void update_document_mode (EvWindow *window, EvDocumentMode mode) { if (mode == EV_DOCUMENT_MODE_FULL_SCREEN) { - gtk_window_fullscreen (GTK_WINDOW (window)); + ev_window_fullscreen (window); + } else if (mode == EV_DOCUMENT_MODE_PRESENTATION) { + ev_window_run_presentation (window); } } @@ -692,21 +742,15 @@ void ev_window_open (EvWindow *ev_window, const char *uri) { EvDocument *document = NULL; - char *mime_type; + GType document_type; + char *mime_type = NULL; g_free (ev_window->priv->uri); ev_window->priv->uri = g_strdup (uri); - mime_type = gnome_vfs_get_mime_type (uri); - - if (mime_type == NULL) - document = NULL; - else { - GType document_type = ev_document_type_lookup (mime_type); - - if (document_type!=G_TYPE_INVALID) { - document = g_object_new (document_type, NULL); - } + document_type = ev_document_type_lookup (uri, &mime_type); + if (document_type != G_TYPE_INVALID) { + document = g_object_new (document_type, NULL); } if (document) { @@ -731,16 +775,15 @@ static void ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list) { GList *list; - gchar *uri, *mime_type; + gchar *uri; g_return_if_fail (uri_list != NULL); list = uri_list; while (list) { uri = gnome_vfs_uri_to_string (list->data, GNOME_VFS_URI_HIDE_NONE); - mime_type = gnome_vfs_get_mime_type (uri); - if (ev_document_type_lookup (mime_type)!=G_TYPE_INVALID) { + if (ev_document_type_lookup (uri, NULL) != G_TYPE_INVALID) { if (ev_window_is_empty (EV_WINDOW (ev_window))) { ev_window_open (ev_window, uri); @@ -755,7 +798,6 @@ ev_window_open_uri_list (EvWindow *ev_window, GList *uri_list) } } - g_free (mime_type); g_free (uri); list = g_list_next (list); @@ -1326,11 +1368,25 @@ ev_window_create_fullscreen_popup (EvWindow *window) return popup; } + static void -ev_window_fullscreen (EvWindow *window) +ev_window_update_fullscreen_action (EvWindow *window) { - window->priv->fullscreen_mode = TRUE; + GtkAction *action; + action = gtk_action_group_get_action (window->priv->action_group, "ViewFullscreen"); + g_signal_handlers_block_by_func + (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), + ev_view_get_fullscreen (EV_VIEW (window->priv->view))); + g_signal_handlers_unblock_by_func + (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window); +} + +static void +ev_window_fullscreen (EvWindow *window) +{ + ev_view_set_fullscreen (EV_VIEW (window->priv->view), TRUE); if (window->priv->fullscreen_popup == NULL) window->priv->fullscreen_popup = ev_window_create_fullscreen_popup (window); @@ -1351,7 +1407,8 @@ ev_window_fullscreen (EvWindow *window) fullscreen_set_timeout (window); gtk_widget_grab_focus (window->priv->view); - + ev_window_update_fullscreen_action (window); + gtk_window_fullscreen (GTK_WINDOW (window)); ev_window_update_fullscreen_popup (window); } @@ -1360,8 +1417,7 @@ ev_window_unfullscreen (EvWindow *window) { EvView *view = EV_VIEW (window->priv->view); - window->priv->fullscreen_mode = FALSE; - + ev_view_set_fullscreen (view, FALSE); g_object_set (G_OBJECT (window->priv->scrolled_window), "shadow-type", GTK_SHADOW_IN, NULL); @@ -1371,33 +1427,86 @@ ev_window_unfullscreen (EvWindow *window) g_signal_handlers_disconnect_by_func (view, (gpointer) fullscreen_motion_notify_cb, window); - - g_object_set (G_OBJECT (view), - "full-screen", FALSE, - NULL); + g_signal_handlers_disconnect_by_func (view, + (gpointer) fullscreen_leave_notify_cb, + window); + ev_window_update_fullscreen_action (window); + gtk_window_unfullscreen (GTK_WINDOW (window)); update_chrome_visibility (window); } static void ev_window_cmd_view_fullscreen (GtkAction *action, EvWindow *window) { - EvView *view; gboolean fullscreen; g_return_if_fail (EV_IS_WINDOW (window)); + ev_window_stop_presentation (window); - view = EV_VIEW (window->priv->view); fullscreen = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); - if (fullscreen) { - gtk_window_fullscreen (GTK_WINDOW (window)); + ev_window_fullscreen (window); } else { - gtk_window_unfullscreen (GTK_WINDOW (window)); + ev_window_unfullscreen (window); } +} + +static void +ev_window_update_presentation_action (EvWindow *window) +{ + GtkAction *action; + + action = gtk_action_group_get_action (window->priv->action_group, "ViewPresentation"); + g_signal_handlers_block_by_func + (action, G_CALLBACK (ev_window_cmd_view_presentation), window); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), + ev_view_get_presentation (EV_VIEW (window->priv->view))); + g_signal_handlers_unblock_by_func + (action, G_CALLBACK (ev_window_cmd_view_presentation), window); +} + +static void +ev_window_run_presentation (EvWindow *window) +{ + g_object_set (G_OBJECT (window->priv->scrolled_window), + "shadow-type", GTK_SHADOW_NONE, + NULL); + + gtk_widget_grab_focus (window->priv->view); + ev_view_set_presentation (EV_VIEW (window->priv->view), TRUE); + gtk_window_fullscreen (GTK_WINDOW (window)); + ev_window_update_presentation_action (window); + update_chrome_visibility (window); +} + +static void +ev_window_stop_presentation (EvWindow *window) +{ + if (! ev_view_get_presentation (EV_VIEW (window->priv->view))) + return; - g_object_set (G_OBJECT (view), - "full-screen", TRUE, + g_object_set (G_OBJECT (window->priv->scrolled_window), + "shadow-type", GTK_SHADOW_IN, NULL); + ev_view_set_presentation (EV_VIEW (window->priv->view), FALSE); + gtk_window_unfullscreen (GTK_WINDOW (window)); + ev_window_update_presentation_action (window); + update_chrome_visibility (window); +} + +static void +ev_window_cmd_view_presentation (GtkAction *action, EvWindow *window) +{ + gboolean presentation; + + g_return_if_fail (EV_IS_WINDOW (window)); + + presentation = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + if (presentation) { + ev_window_run_presentation (window); + } else { + ev_window_stop_presentation (window); + } } static gboolean @@ -1414,29 +1523,6 @@ ev_window_state_event (GtkWidget *widget, GdkEventWindowState *event) show); } - if (event->changed_mask & GDK_WINDOW_STATE_FULLSCREEN) { - GtkActionGroup *action_group; - GtkAction *action; - gboolean fullscreen; - - fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN; - - if (fullscreen) { - ev_window_fullscreen (window); - } else { - ev_window_unfullscreen (window); - } - - action_group = window->priv->action_group; - - action = gtk_action_group_get_action (action_group, "ViewFullscreen"); - g_signal_handlers_block_by_func - (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), fullscreen); - g_signal_handlers_unblock_by_func - (action, G_CALLBACK (ev_window_cmd_view_fullscreen), window); - } - return FALSE; } @@ -1445,11 +1531,14 @@ ev_window_focus_in_event (GtkWidget *widget, GdkEventFocus *event) { EvWindow *window = EV_WINDOW (widget); EvWindowPrivate *priv = window->priv; + gboolean fullscreen; - if (priv->fullscreen_mode) - { + g_object_get (priv->view, + "fullscreen", &fullscreen, + NULL); + + if (fullscreen) gtk_widget_show (priv->fullscreen_popup); - } return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_in_event (widget, event); } @@ -1459,11 +1548,14 @@ ev_window_focus_out_event (GtkWidget *widget, GdkEventFocus *event) { EvWindow *window = EV_WINDOW (widget); EvWindowPrivate *priv = window->priv; + gboolean fullscreen; - if (priv->fullscreen_mode) - { + g_object_get (priv->view, + "fullscreen", &fullscreen, + NULL); + + if (fullscreen) gtk_widget_hide (priv->fullscreen_popup); - } return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_out_event (widget, event); } @@ -1615,7 +1707,21 @@ ev_window_cmd_escape (GtkAction *action, EvWindow *window) if (widget && gtk_widget_get_ancestor (widget, EGG_TYPE_FIND_BAR)) { update_chrome_flag (window, EV_CHROME_FINDBAR, NULL, FALSE); } else { - gtk_window_unfullscreen (GTK_WINDOW (window)); + gboolean fullscreen; + gboolean presentation; + + g_object_get (window->priv->view, + "fullscreen", &fullscreen, + "presentation", &presentation, + NULL); + + if (fullscreen) + ev_window_unfullscreen (window); + if (presentation) + ev_window_stop_presentation (window); + + if (fullscreen && presentation) + g_warning ("Both fullscreen and presentation set somehow"); } } @@ -1795,14 +1901,17 @@ ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspe EvWindow *ev_window) { GtkAction *action; - gboolean visible; + gboolean visible, fullscreen; + g_object_get (ev_window->priv->view, + "fullscreen", &fullscreen, + NULL); visible = GTK_WIDGET_VISIBLE (ev_sidebar); /* In fullscreen mode the sidebar is not visible, * but we don't want to update the chrome */ - if (ev_window->priv->fullscreen_mode) + if (fullscreen) return; action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar"); @@ -1977,6 +2086,28 @@ find_bar_search_changed_cb (EggFindBar *find_bar, } } +static void +zoom_control_changed_cb (EphyZoomAction *action, + float zoom, + EvWindow *ev_window) +{ + EvSizingMode mode; + + g_return_if_fail (EV_IS_WINDOW (ev_window)); + + if (zoom == EPHY_ZOOM_BEST_FIT) { + mode = EV_SIZING_BEST_FIT; + } else if (zoom == EPHY_ZOOM_FIT_WIDTH) { + mode = EV_SIZING_FIT_WIDTH; + } else { + mode = EV_SIZING_FREE; + ev_view_set_zoom (EV_VIEW (ev_window->priv->view), zoom, FALSE); + } + + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), mode); + update_action_sensitivity (ev_window); +} + static void ev_window_dispose (GObject *object) { @@ -2129,8 +2260,12 @@ static const GtkActionEntry entries[] = { N_("Leave fullscreen mode"), G_CALLBACK (ev_window_cmd_leave_fullscreen) }, + /* Accellerators */ { "Escape", NULL, N_("Selection Caret"), "Escape", "", - G_CALLBACK (ev_window_cmd_escape) } + G_CALLBACK (ev_window_cmd_escape) }, + { "Slash", GTK_STOCK_FIND, NULL, "slash", + N_("Find a word or phrase in the document"), + G_CALLBACK (ev_window_cmd_edit_find) } }; /* Toggle items */ @@ -2154,6 +2289,9 @@ static const GtkToggleActionEntry toggle_entries[] = { { "ViewFullscreen", NULL, N_("_Fullscreen"), "F11", N_("Expand the window to fill the screen"), G_CALLBACK (ev_window_cmd_view_fullscreen) }, + { "ViewPresentation", NULL, N_("_Presentation"), "F12", + N_("Run document as a presentation"), + G_CALLBACK (ev_window_cmd_view_presentation) }, { "ViewBestFit", EV_STOCK_ZOOM_PAGE, N_("_Best Fit"), NULL, N_("Make the current document fill the window"), G_CALLBACK (ev_window_cmd_view_best_fit) }, @@ -2201,6 +2339,18 @@ register_custom_actions (EvWindow *window, GtkActionGroup *group) NULL); gtk_action_group_add_action (group, action); g_object_unref (action); + + action = g_object_new (EPHY_TYPE_ZOOM_ACTION, + "name", ZOOM_CONTROL_ACTION, + "label", _("Zoom"), + "stock_id", GTK_STOCK_ZOOM_IN, + "tooltip", _("Adjust the zoom level"), + "zoom", 1.0, + NULL); + g_signal_connect (action, "zoom_to_level", + G_CALLBACK (zoom_control_changed_cb), window); + gtk_action_group_add_action (group, action); + g_object_unref (action); } static void