#include "ev-sidebar-links.h"
#include "ev-sidebar-thumbnails.h"
#include "ev-view.h"
-#include "ev-page-view.h"
#include "ev-password.h"
#include "ev-password-view.h"
#include "ev-print-job.h"
+#include "ev-document-thumbnails.h"
+#include "ev-document-links.h"
#include "ev-document-find.h"
#include "ev-document-security.h"
+#include "ev-job-queue.h"
#include "eggfindbar.h"
-#include "pdf-document.h"
+#include "ev-poppler.h"
#include "pixbuf-document.h"
#include "ps-document.h"
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-uri.h>
+#include <libgnomevfs/gnome-vfs-utils.h>
#include <libgnomeprintui/gnome-print-dialog.h>
#include <gconf/gconf-client.h>
#include "ev-application.h"
#include "ev-stock-icons.h"
+typedef enum {
+ EV_SIZING_BEST_FIT,
+ EV_SIZING_FIT_WIDTH,
+ EV_SIZING_FREE,
+} EvSizingMode;
+
typedef enum {
PAGE_MODE_SINGLE_PAGE,
PAGE_MODE_CONTINUOUS_PAGE,
GtkWidget *statusbar;
guint help_message_cid;
guint view_message_cid;
- GtkWidget *exit_fullscreen_popup;
- GtkWidget *exit_fullscreen_toolbar;
+ GtkWidget *fullscreen_toolbar;
+ GtkWidget *fullscreen_popup;
char *uri;
EvDocument *document;
+ EvPageCache *page_cache;
EvWindowPageMode page_mode;
/* These members are used temporarily when in PAGE_MODE_PASSWORD */
EvChrome chrome;
gboolean fullscreen_mode;
+ EvSizingMode sizing_mode;
+ GSource *fullscreen_timeout_source;
};
static GtkTargetEntry ev_drop_types[] = {
#define GCONF_CHROME_SIDEBAR "/apps/evince/show_sidebar"
#define GCONF_CHROME_STATUSBAR "/apps/evince/show_statusbar"
+#define GCONF_SIDEBAR_SIZE "/apps/evince/sidebar_size"
+#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_set_sizing_mode (EvWindow *ev_window,
+ EvSizingMode sizing_mode);
G_DEFINE_TYPE (EvWindow, ev_window, GTK_TYPE_WINDOW)
document = ev_window->priv->document;
page_mode = ev_window->priv->page_mode;
-
view = EV_VIEW (ev_window->priv->view);
/* File menu */
set_action_sensitive (ev_window, "ViewNormalSize", document!=NULL);
set_action_sensitive (ev_window, "ViewBestFit", document!=NULL);
set_action_sensitive (ev_window, "ViewPageWidth", document!=NULL);
+ set_action_sensitive (ev_window, "ViewReload", document!=NULL);
/* Go menu */
if (document) {
int n_pages;
int page;
+ page = ev_page_cache_get_current_page (ev_window->priv->page_cache);
+ n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
- page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
- n_pages = ev_document_get_n_pages (document);
-
- set_action_sensitive (ev_window, "GoPreviousPage", page > 1);
- set_action_sensitive (ev_window, "GoNextPage", page < n_pages);
- set_action_sensitive (ev_window, "GoFirstPage", page > 1);
- set_action_sensitive (ev_window, "GoLastPage", page < n_pages);
+ set_action_sensitive (ev_window, "GoPreviousPage", page > 0);
+ set_action_sensitive (ev_window, "GoNextPage", page < n_pages - 1);
+ set_action_sensitive (ev_window, "GoFirstPage", page > 0);
+ set_action_sensitive (ev_window, "GoLastPage", page < n_pages - 1);
} else {
set_action_sensitive (ev_window, "GoFirstPage", FALSE);
set_action_sensitive (ev_window, "GoPreviousPage", FALSE);
set_action_sensitive (ev_window, PAGE_SELECTOR_ACTION, document!=NULL);
}
+static void
+set_widget_visibility (GtkWidget *widget, gboolean visible)
+{
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+
+ if (visible)
+ gtk_widget_show (widget);
+ else
+ gtk_widget_hide (widget);
+}
+
static void
update_chrome_visibility (EvWindow *window)
{
EvWindowPrivate *priv = window->priv;
- gboolean menubar, toolbar, sidebar, findbar, statusbar;
+ gboolean menubar, toolbar, sidebar, findbar, statusbar, fullscreen_toolbar;
menubar = (priv->chrome & EV_CHROME_MENUBAR) != 0 && !priv->fullscreen_mode;
- toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0;
- sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0;
- findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
+ toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0 && !priv->fullscreen_mode;
+ sidebar = (priv->chrome & EV_CHROME_SIDEBAR) != 0 && !priv->fullscreen_mode;
+ fullscreen_toolbar = (priv->chrome & EV_CHROME_TOOLBAR) != 0;
statusbar = (priv->chrome & EV_CHROME_STATUSBAR) != 0 && !priv->fullscreen_mode;
+ findbar = (priv->chrome & EV_CHROME_FINDBAR) != 0;
- g_object_set (priv->menubar, "visible", menubar, NULL);
- g_object_set (priv->toolbar_dock, "visible", toolbar, NULL);
- g_object_set (priv->sidebar, "visible", sidebar, NULL);
- g_object_set (priv->find_bar, "visible", findbar, NULL);
- g_object_set (priv->statusbar, "visible", statusbar, NULL);
+ set_widget_visibility (priv->menubar, menubar);
+ set_widget_visibility (priv->toolbar_dock, toolbar);
+ set_widget_visibility (priv->sidebar, sidebar);
+ set_widget_visibility (priv->find_bar, findbar);
+ set_widget_visibility (priv->statusbar, statusbar);
+ set_widget_visibility (priv->fullscreen_toolbar, fullscreen_toolbar);
- g_object_set (priv->exit_fullscreen_toolbar, "visible", priv->fullscreen_mode, NULL);
- if (priv->exit_fullscreen_popup != NULL) {
- g_object_set (priv->exit_fullscreen_popup, "visible", !toolbar, NULL);
+ if (priv->fullscreen_popup != NULL) {
+ set_widget_visibility (priv->fullscreen_popup, priv->fullscreen_mode);
}
}
update_chrome_visibility (window);
}
+static void
+ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
+{
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_BEST_FIT);
+ } else {
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
+ }
+}
+
+static void
+ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
+{
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH);
+ } else {
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
+ }
+}
+
+static void
+update_sizing_buttons (EvWindow *window)
+{
+ GtkActionGroup *action_group = window->priv->action_group;
+ GtkAction *action;
+ gboolean best_fit, page_width;
+
+ switch (window->priv->sizing_mode) {
+ case EV_SIZING_BEST_FIT:
+ best_fit = TRUE;
+ page_width = FALSE;
+ break;
+ case EV_SIZING_FIT_WIDTH:
+ best_fit = FALSE;
+ page_width = TRUE;
+ break;
+
+ default:
+ best_fit = page_width = FALSE;
+ break;
+ }
+
+ action = gtk_action_group_get_action (action_group, "ViewBestFit");
+ g_signal_handlers_block_by_func
+ (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), best_fit);
+ g_signal_handlers_unblock_by_func
+ (action, G_CALLBACK (ev_window_cmd_view_best_fit), window);
+
+ action = gtk_action_group_get_action (action_group, "ViewPageWidth");
+ g_signal_handlers_block_by_func
+ (action, G_CALLBACK (ev_window_cmd_view_page_width), 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);
+}
+
void
ev_window_open_page (EvWindow *ev_window, int page)
{
- ev_view_set_page (EV_VIEW (ev_window->priv->view), page);
+ if (ev_window->priv->page_cache)
+ ev_page_cache_set_current_page (ev_window->priv->page_cache, page);
}
void
gboolean password_needed;
password_needed = (ev_window->priv->password_document != NULL);
-
if (document) {
- doc_title = ev_document_get_title (document);
+ doc_title = ev_page_cache_get_title (ev_window->priv->page_cache);
/* Make sure we get a valid title back */
if (doc_title) {
}
}
}
+
+ if (doc_title) {
+ char *p;
+
+ for (p = doc_title; *p; ++p) {
+ /* an '\n' byte is always ASCII, no need for UTF-8 special casing */
+ if (*p == '\n')
+ *p = ' ';
+ }
+ }
+
if (doc_title == NULL && ev_window->priv->uri) {
- doc_title = g_path_get_basename (ev_window->priv->uri);
+ char *basename;
+
+ basename = g_path_get_basename (ev_window->priv->uri);
+ doc_title = gnome_vfs_unescape_string_for_display (basename);
+ g_free (basename);
}
if (password_needed) {
g_free (title);
}
+/* This function assumes that ev_window just had ev_window->document set.
+ */
+static gboolean
+document_supports_sidebar (EvDocument *document)
+{
+ return (EV_IS_DOCUMENT_THUMBNAILS (document) && (EV_IS_DOCUMENT_LINKS (document)));
+}
+
static void
-update_total_pages (EvWindow *ev_window)
+hide_sidebar_and_actions (EvWindow *ev_window)
{
GtkAction *action;
- int pages;
+ /* Alsthough we update the hiddenness of the sidebar, we don't want to
+ * store the value */
+ g_signal_handlers_disconnect_by_func (ev_window->priv->sidebar,
+ ev_window_sidebar_visibility_changed_cb,
+ ev_window);
+ gtk_widget_hide (ev_window->priv->sidebar);
+ action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
+ gtk_action_set_sensitive (action, FALSE);
- pages = ev_document_get_n_pages (ev_window->priv->document);
- action = gtk_action_group_get_action
- (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
- ev_page_action_set_total_pages (EV_PAGE_ACTION (action), pages);
}
-/* This function assumes that ev_window just had ev_window->document set.
- */
+static void
+page_changed_cb (EvPageCache *page_cache,
+ gint page,
+ EvWindow *ev_window)
+{
+ update_action_sensitivity (ev_window);
+}
+
+
static void
ev_window_setup_document (EvWindow *ev_window)
{
EvDocument *document;
EvView *view = EV_VIEW (ev_window->priv->view);
- //EvPageView *page_view = EV_PAGE_VIEW (ev_window->priv->page_view);
EvSidebar *sidebar = EV_SIDEBAR (ev_window->priv->sidebar);
+ GtkAction *action;
document = ev_window->priv->document;
+ ev_window->priv->page_cache = ev_document_get_page_cache (ev_window->priv->document);
+ g_signal_connect (ev_window->priv->page_cache, "page-changed", G_CALLBACK (page_changed_cb), ev_window);
g_signal_connect_object (G_OBJECT (document),
"notify::title",
ev_window_set_page_mode (ev_window, PAGE_MODE_SINGLE_PAGE);
- ev_sidebar_set_document (sidebar, document);
+ if (document_supports_sidebar (document))
+ ev_sidebar_set_document (sidebar, document);
+ else
+ hide_sidebar_and_actions (ev_window);
+
ev_view_set_document (view, document);
- //ev_page_view_set_document (page_view, document);
update_window_title (document, NULL, ev_window);
- update_total_pages (ev_window);
+ action = gtk_action_group_get_action (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
+ ev_page_action_set_document (EV_PAGE_ACTION (action), document);
update_action_sensitivity (ev_window);
}
gchar *uri;
password = ev_password_dialog_get_password (password_dialog);
- if (password)
+ if (password) {
+ g_mutex_lock (EV_DOC_MUTEX);
ev_document_security_set_password (EV_DOCUMENT_SECURITY (ev_window->priv->password_document),
password);
+ g_mutex_unlock (EV_DOC_MUTEX);
+ }
g_free (password);
document = ev_window->priv->password_document;
update_window_title (ev_window->priv->password_document, NULL, ev_window);
if (ev_window->priv->password_dialog == NULL) {
- gchar *file_name;
+ gchar *basename, *file_name;
- file_name = g_path_get_basename (ev_window->priv->password_uri);
+ basename = g_path_get_basename (ev_window->priv->password_uri);
+ file_name = gnome_vfs_unescape_string_for_display (basename);
ev_window->priv->password_dialog =
ev_password_dialog_new (GTK_WIDGET (ev_window), file_name);
g_object_add_weak_pointer (G_OBJECT (ev_window->priv->password_dialog),
"response",
G_CALLBACK (password_dialog_response),
ev_window);
+ g_free (basename);
g_free (file_name);
gtk_widget_show (ev_window->priv->password_dialog);
} else {
GtkWidget *fc;
GtkFileFilter *pdf_filter, *all_filter;
gchar *uri = NULL;
+ gboolean success;
fc = gtk_file_chooser_dialog_new (
_("Save a Copy"),
!overwrite_existing_file (GTK_WINDOW (fc), uri))
continue;
*/
+
+ g_mutex_lock (EV_DOC_MUTEX);
+ success = ev_document_save (ev_window->priv->document, uri, NULL);
+ g_mutex_unlock (EV_DOC_MUTEX);
- if (ev_document_save (ev_window->priv->document, uri, NULL))
+ if (success)
break;
else
save_error_dialog (GTK_WINDOW (fc), uri);
config = gnome_print_config_default ();
job = gnome_print_job_new (config);
- print_dialog = gnome_print_dialog_new (job, _("Print"),
+ print_dialog = gnome_print_dialog_new (job, (guchar *) _("Print"),
(GNOME_PRINT_DIALOG_RANGE |
GNOME_PRINT_DIALOG_COPIES));
gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
GTK_MESSAGE_DIALOG (dialog),
_("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
gnome_print_config_get (
- config, "Settings.Engine.Backend.Driver"));
+ config, (guchar *)"Settings.Engine.Backend.Driver"));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
} else {
update_chrome_flag (ev_window, EV_CHROME_FINDBAR, NULL, TRUE);
- egg_find_bar_grab_focus (EGG_FIND_BAR (ev_window->priv->find_bar));
+ gtk_widget_grab_focus (ev_window->priv->find_bar);
}
}
static void
ev_window_update_fullscreen_popup (EvWindow *window)
{
- GtkWidget *popup = window->priv->exit_fullscreen_popup;
+ GtkWidget *popup = window->priv->fullscreen_popup;
int popup_width, popup_height;
GdkRectangle screen_rect;
+ gboolean toolbar;
g_return_if_fail (popup != NULL);
+ toolbar = (window->priv->chrome & EV_CHROME_TOOLBAR) != 0;
popup_width = popup->requisition.width;
popup_height = popup->requisition.height;
(gdk_screen_get_default (),
GTK_WIDGET (window)->window),
&screen_rect);
-
- if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
- {
+ if (toolbar) {
+ gtk_widget_set_size_request (popup,
+ screen_rect.width,
+ -1);
gtk_window_move (GTK_WINDOW (popup),
screen_rect.x,
screen_rect.y);
- }
- else
- {
- gtk_window_move (GTK_WINDOW (popup),
- screen_rect.x + screen_rect.width - popup_width,
- screen_rect.y);
+
+ } else {
+ if (gtk_widget_get_direction (popup) == GTK_TEXT_DIR_RTL)
+ {
+ gtk_window_move (GTK_WINDOW (popup),
+ screen_rect.x,
+ screen_rect.y);
+ } else {
+ gtk_window_move (GTK_WINDOW (popup),
+ screen_rect.x + screen_rect.width - popup_width,
+ screen_rect.y);
+ }
}
}
}
static void
-destroy_exit_fullscreen_popup (EvWindow *window)
+ev_window_sidebar_position_change_cb (GObject *object, GParamSpec *pspec,
+ EvWindow *ev_window)
{
- if (window->priv->exit_fullscreen_popup != NULL)
+ GConfClient *client;
+ int sidebar_size;
+
+ sidebar_size = gtk_paned_get_position (GTK_PANED (object));
+
+ client = gconf_client_get_default ();
+ gconf_client_set_int (client, GCONF_SIDEBAR_SIZE, sidebar_size, NULL);
+ g_object_unref (client);
+}
+
+static void
+destroy_fullscreen_popup (EvWindow *window)
+{
+ if (window->priv->fullscreen_popup != NULL)
{
/* FIXME multihead */
g_signal_handlers_disconnect_by_func
(gdk_screen_get_default (),
G_CALLBACK (screen_size_changed_cb), window);
- gtk_widget_destroy (window->priv->exit_fullscreen_popup);
- window->priv->exit_fullscreen_popup = NULL;
+ gtk_widget_destroy (window->priv->fullscreen_popup);
+ window->priv->fullscreen_popup = NULL;
}
}
ev_window_update_fullscreen_popup (window);
}
+static gboolean
+fullscreen_timeout_cb (gpointer data)
+{
+ EvWindow *window = EV_WINDOW (data);
+
+ g_object_set (window->priv->fullscreen_popup, "visible", FALSE, NULL);
+ ev_view_hide_cursor (EV_VIEW (window->priv->view));
+ window->priv->fullscreen_timeout_source = NULL;
+
+ return FALSE;
+}
+
static void
-ev_window_fullscreen (EvWindow *window)
+fullscreen_set_timeout (EvWindow *window)
{
- GtkWidget *popup, *button, *icon, *label, *hbox;
+ GSource *source;
- window->priv->fullscreen_mode = TRUE;
+ if (window->priv->fullscreen_timeout_source != NULL)
+ g_source_destroy (window->priv->fullscreen_timeout_source);
- g_return_if_fail (window->priv->exit_fullscreen_popup == NULL);
+ source = g_timeout_source_new (1000);
+ g_source_set_callback (source, fullscreen_timeout_cb, window, NULL);
+ g_source_attach (source, NULL);
+ window->priv->fullscreen_timeout_source = source;
+}
- popup = gtk_window_new (GTK_WINDOW_POPUP);
- window->priv->exit_fullscreen_popup = popup;
+static void
+fullscreen_clear_timeout (EvWindow *window)
+{
+ if (window->priv->fullscreen_timeout_source != NULL)
+ g_source_destroy (window->priv->fullscreen_timeout_source);
+
+ window->priv->fullscreen_timeout_source = NULL;
+ ev_view_show_cursor (EV_VIEW (window->priv->view));
+}
+
+static gboolean
+fullscreen_motion_notify_cb (GtkWidget *widget,
+ GdkEventMotion *event,
+ gpointer user_data)
+{
+ EvWindow *window = EV_WINDOW (user_data);
+
+ if (!GTK_WIDGET_VISIBLE (window->priv->fullscreen_popup)) {
+ g_object_set (window->priv->fullscreen_popup, "visible", TRUE, NULL);
+ ev_view_show_cursor (EV_VIEW (window->priv->view));
+ }
+
+ fullscreen_set_timeout (window);
+
+ return FALSE;
+}
+
+static gboolean
+fullscreen_leave_notify_cb (GtkWidget *widget,
+ GdkEventCrossing *event,
+ gpointer user_data)
+{
+ EvWindow *window = EV_WINDOW (user_data);
+
+ fullscreen_clear_timeout (window);
+
+ return FALSE;
+}
+
+static GtkWidget *
+ev_window_get_exit_fullscreen_button (EvWindow *window)
+{
+ GtkWidget *button, *icon, *label, *hbox;
button = gtk_button_new ();
g_signal_connect (button, "clicked",
G_CALLBACK (exit_fullscreen_button_clicked_cb),
window);
gtk_widget_show (button);
- gtk_container_add (GTK_CONTAINER (popup), button);
hbox = gtk_hbox_new (FALSE, 2);
gtk_widget_show (hbox);
gtk_widget_show (label);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+ return button;
+}
+
+static GtkWidget *
+ev_window_create_fullscreen_popup (EvWindow *window)
+{
+ GtkWidget *popup;
+ GtkWidget *hbox;
+ GtkWidget *button;
+
+ popup = gtk_window_new (GTK_WINDOW_POPUP);
+ hbox = gtk_hbox_new (FALSE, 0);
+ button = ev_window_get_exit_fullscreen_button (window);
+
+ gtk_container_add (GTK_CONTAINER (popup), hbox);
+ gtk_box_pack_start (GTK_BOX (hbox), window->priv->fullscreen_toolbar,
+ TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+
+ gtk_widget_show (button);
+ gtk_widget_show (hbox);
+
gtk_window_set_resizable (GTK_WINDOW (popup), FALSE);
/* FIXME multihead */
g_signal_connect (popup, "size_request",
G_CALLBACK (fullscreen_popup_size_request_cb), window);
+ return popup;
+}
+
+static void
+ev_window_fullscreen (EvWindow *window)
+{
+ window->priv->fullscreen_mode = TRUE;
+
+ if (window->priv->fullscreen_popup == NULL)
+ window->priv->fullscreen_popup
+ = ev_window_create_fullscreen_popup (window);
update_chrome_visibility (window);
+ g_object_set (G_OBJECT (window->priv->scrolled_window),
+ "shadow-type", GTK_SHADOW_NONE,
+ NULL);
+
+ g_signal_connect (window->priv->view,
+ "motion-notify-event",
+ G_CALLBACK (fullscreen_motion_notify_cb),
+ window);
+ g_signal_connect (window->priv->view,
+ "leave-notify-event",
+ G_CALLBACK (fullscreen_leave_notify_cb),
+ window);
+ fullscreen_set_timeout (window);
+
+ gtk_widget_grab_focus (window->priv->view);
+
ev_window_update_fullscreen_popup (window);
}
{
window->priv->fullscreen_mode = FALSE;
- destroy_exit_fullscreen_popup (window);
+ g_object_set (G_OBJECT (window->priv->scrolled_window),
+ "shadow-type", GTK_SHADOW_IN,
+ NULL);
+
+ fullscreen_clear_timeout (window);
+
+ g_signal_handlers_disconnect_by_func (window->priv->view,
+ (gpointer) fullscreen_motion_notify_cb,
+ window);
+
+// destroy_fullscreen_popup (window);
update_chrome_visibility (window);
}
EvWindow *window = EV_WINDOW (widget);
EvWindowPrivate *priv = window->priv;
- if (priv->exit_fullscreen_popup != NULL &&
- (priv->chrome & EV_CHROME_TOOLBAR) == 0)
+ if (priv->fullscreen_mode)
{
- gtk_widget_show (priv->exit_fullscreen_popup);
+ gtk_widget_show (priv->fullscreen_popup);
}
return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_in_event (widget, event);
EvWindow *window = EV_WINDOW (widget);
EvWindowPrivate *priv = window->priv;
- if (priv->exit_fullscreen_popup != NULL &&
- (priv->chrome & EV_CHROME_TOOLBAR) == 0)
+ if (priv->fullscreen_mode)
{
- gtk_widget_hide (priv->exit_fullscreen_popup);
+ gtk_widget_hide (priv->fullscreen_popup);
}
return GTK_WIDGET_CLASS (ev_window_parent_class)->focus_out_event (widget, event);
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
+
ev_view_zoom_in (EV_VIEW (ev_window->priv->view));
}
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE);
+
ev_view_zoom_out (EV_VIEW (ev_window->priv->view));
}
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- ev_view_normal_size (EV_VIEW (ev_window->priv->view));
+ ev_view_set_size (EV_VIEW (ev_window->priv->view), -1, -1);
}
static void
-ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window)
+ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- ev_view_best_fit (EV_VIEW (ev_window->priv->view));
+ ev_page_cache_prev_page (ev_window->priv->page_cache);
}
static void
-ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window)
+ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- ev_view_fit_width (EV_VIEW (ev_window->priv->view));
+ ev_page_cache_next_page (ev_window->priv->page_cache);
}
static void
-ev_window_cmd_go_previous_page (GtkAction *action, EvWindow *ev_window)
+ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
{
g_return_if_fail (EV_IS_WINDOW (ev_window));
- ev_view_set_page (EV_VIEW (ev_window->priv->view),
- ev_view_get_page (EV_VIEW (ev_window->priv->view)) - 1);
+ ev_page_cache_set_current_page (ev_window->priv->page_cache, 0);
}
static void
-ev_window_cmd_go_next_page (GtkAction *action, EvWindow *ev_window)
+ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
{
+ int n_pages;
+
g_return_if_fail (EV_IS_WINDOW (ev_window));
- ev_view_set_page (EV_VIEW (ev_window->priv->view),
- ev_view_get_page (EV_VIEW (ev_window->priv->view)) + 1);
+ n_pages = ev_page_cache_get_n_pages (ev_window->priv->page_cache);
+ ev_page_cache_set_current_page (ev_window->priv->page_cache, n_pages - 1);
}
static void
-ev_window_cmd_go_first_page (GtkAction *action, EvWindow *ev_window)
+ev_window_cmd_view_reload (GtkAction *action, EvWindow *ev_window)
{
- g_return_if_fail (EV_IS_WINDOW (ev_window));
+ char *uri;
+ int page;
- ev_view_set_page (EV_VIEW (ev_window->priv->view), 1);
-}
+ g_return_if_fail (EV_IS_WINDOW (ev_window));
-static void
-ev_window_cmd_go_last_page (GtkAction *action, EvWindow *ev_window)
-{
- g_return_if_fail (EV_IS_WINDOW (ev_window));
+#if 0
+ /* FIXME: uncomment when this is written.*/
+ page = ev_page_cache_get_page (ev_window->priv->page_cache);
+#else
+ page = 1;
+#endif
+ uri = g_strdup (ev_window->priv->uri);
+
+ ev_window_open (ev_window, uri);
+ ev_window_open_page (ev_window, page);
- ev_view_set_page (EV_VIEW (ev_window->priv->view), G_MAXINT);
+ g_free (uri);
}
static void
gtk_window_unfullscreen (GTK_WINDOW (window));
}
+static void
+update_view_size (EvWindow *window)
+{
+ int width, height;
+ GtkRequisition vsb_requisition;
+ int scrollbar_spacing;
+
+ width = window->priv->scrolled_window->allocation.width;
+ height = window->priv->scrolled_window->allocation.height;
+
+ /* the scrolled window has a GTK_SHADOW_IN */
+ width -= 2 * window->priv->view->style->xthickness;
+ height -= 2 * window->priv->view->style->ythickness;
+
+ if (window->priv->sizing_mode == EV_SIZING_BEST_FIT) {
+ ev_view_set_size (EV_VIEW (window->priv->view),
+ MAX (1, width), MAX (1, height));
+ } else if (window->priv->sizing_mode == EV_SIZING_FIT_WIDTH) {
+ gtk_widget_size_request (GTK_SCROLLED_WINDOW (window->priv->scrolled_window)->vscrollbar,
+ &vsb_requisition);
+ gtk_widget_style_get (window->priv->scrolled_window,
+ "scrollbar_spacing", &scrollbar_spacing,
+ NULL);
+ ev_view_set_size (EV_VIEW (window->priv->view),
+ width - vsb_requisition.width - scrollbar_spacing, -1);
+ }
+}
+
+static void
+size_allocate_cb (GtkWidget *scrolled_window,
+ GtkAllocation *allocation,
+ EvWindow *window)
+{
+ update_view_size (window);
+}
+
+static void
+ev_window_set_sizing_mode (EvWindow *ev_window,
+ EvSizingMode sizing_mode)
+{
+ GtkWidget *scrolled_window;
+
+ if (ev_window->priv->sizing_mode == sizing_mode)
+ return;
+
+ scrolled_window = ev_window->priv->scrolled_window;
+ ev_window->priv->sizing_mode = sizing_mode;
+
+ g_signal_handlers_disconnect_by_func (scrolled_window, size_allocate_cb, ev_window);
+
+ update_view_size (ev_window);
+
+ switch (sizing_mode) {
+ case EV_SIZING_BEST_FIT:
+ g_object_set (G_OBJECT (scrolled_window),
+ "hscrollbar-policy", GTK_POLICY_NEVER,
+ "vscrollbar-policy", GTK_POLICY_NEVER,
+ NULL);
+ g_signal_connect (scrolled_window, "size-allocate",
+ G_CALLBACK (size_allocate_cb),
+ ev_window);
+ break;
+ case EV_SIZING_FIT_WIDTH:
+ g_object_set (G_OBJECT (scrolled_window),
+ "hscrollbar-policy", GTK_POLICY_NEVER,
+ "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
+ NULL);
+ g_signal_connect (scrolled_window, "size-allocate",
+ G_CALLBACK (size_allocate_cb),
+ ev_window);
+ break;
+ case EV_SIZING_FREE:
+ g_object_set (G_OBJECT (scrolled_window),
+ "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
+ "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
+ NULL);
+ break;
+ }
+
+ update_sizing_buttons (ev_window);
+}
+
static void
ev_window_cmd_help_about (GtkAction *action, EvWindow *ev_window)
{
gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
}
+static void
+ev_window_sidebar_visibility_changed_cb (EvSidebar *ev_sidebar, GParamSpec *pspec,
+ EvWindow *ev_window)
+{
+ GtkAction *action;
+ gboolean visible;
+
+ 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)
+ return;
+
+ action = gtk_action_group_get_action (ev_window->priv->action_group, "ViewSidebar");
+
+ g_signal_handlers_block_by_func
+ (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window);
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
+ g_signal_handlers_unblock_by_func
+ (action, G_CALLBACK (ev_window_view_sidebar_cb), ev_window);
+
+ update_chrome_flag (ev_window, EV_CHROME_SIDEBAR,
+ GCONF_CHROME_SIDEBAR, visible);
+}
+
static void
menu_item_select_cb (GtkMenuItem *proxy, EvWindow *ev_window)
{
}
}
-static void
-update_current_page (EvWindow *ev_window,
- EvView *view)
-{
- int page;
- GtkAction *action;
- EvSidebarThumbnails *thumbs;
-
- thumbs = EV_SIDEBAR_THUMBNAILS (ev_window->priv->thumbs_sidebar);
- ev_sidebar_thumbnails_select_page (thumbs, ev_view_get_page (view));
-
- action = gtk_action_group_get_action
- (ev_window->priv->action_group, PAGE_SELECTOR_ACTION);
-
- page = ev_view_get_page (EV_VIEW (ev_window->priv->view));
- ev_page_action_set_current_page (EV_PAGE_ACTION (action), page);
-}
-
-static void
-view_page_changed_cb (EvView *view,
- EvWindow *ev_window)
-{
- update_current_page (ev_window, view);
- update_action_sensitivity (ev_window);
-}
-
static void
view_status_changed_cb (EvView *view,
GParamSpec *pspec,
if (ev_window->priv->document &&
EV_IS_DOCUMENT_FIND (ev_window->priv->document)) {
- if (visible && search_string) {
- ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document), search_string, case_sensitive);
+ if (visible && search_string && search_string[0]) {
+ g_mutex_lock (EV_DOC_MUTEX);
+ ev_document_find_begin (EV_DOCUMENT_FIND (ev_window->priv->document),
+ ev_view_get_page (EV_VIEW (ev_window->priv->view)),
+ search_string,
+ case_sensitive);
+ g_mutex_unlock (EV_DOC_MUTEX);
} else {
+ g_mutex_lock (EV_DOC_MUTEX);
ev_document_find_cancel (EV_DOCUMENT_FIND (ev_window->priv->document));
+ g_mutex_unlock (EV_DOC_MUTEX);
+
egg_find_bar_set_status_text (EGG_FIND_BAR (ev_window->priv->find_bar),
NULL);
gtk_widget_queue_draw (GTK_WIDGET (ev_window->priv->view));
priv->password_uri = NULL;
}
- destroy_exit_fullscreen_popup (window);
+ if (priv->find_bar) {
+ g_signal_handlers_disconnect_by_func
+ (window->priv->find_bar,
+ G_CALLBACK (find_bar_close_cb),
+ window);
+ priv->find_bar = NULL;
+ }
+
+ destroy_fullscreen_popup (window);
G_OBJECT_CLASS (ev_window_parent_class)->dispose (object);
}
{ "FileSaveAs", GTK_STOCK_SAVE_AS, N_("_Save a Copy..."), NULL,
N_("Save the current document with a new filename"),
G_CALLBACK (ev_window_cmd_save_as) },
- { "FilePrint", GTK_STOCK_PRINT, NULL, "<control>P",
+ { "FilePrint", GTK_STOCK_PRINT, N_("Print..."), "<control>P",
N_("Print this document"),
G_CALLBACK (ev_window_cmd_file_print) },
{ "FileCloseWindow", GTK_STOCK_CLOSE, NULL, "<control>W",
N_("Shrink the document"),
G_CALLBACK (ev_window_cmd_view_zoom_out) },
{ "ViewNormalSize", GTK_STOCK_ZOOM_100, NULL, "<control>0",
- N_("Reset the zoom level to the defaul value"),
+ N_("Reset the zoom level to the default value"),
G_CALLBACK (ev_window_cmd_view_normal_size) },
- { "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) },
- { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
- N_("Make the current document fill the window width"),
- G_CALLBACK (ev_window_cmd_view_page_width) },
+ { "ViewReload", GTK_STOCK_REFRESH, N_("_Reload"), "<control>R",
+ N_("Reload the document"),
+ G_CALLBACK (ev_window_cmd_view_reload) },
/* Go menu */
{ "GoPreviousPage", GTK_STOCK_GO_BACK, N_("_Previous Page"), "Page_Up",
G_CALLBACK (ev_window_cmd_go_last_page) },
/* Help menu */
- { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), NULL,
+ { "HelpContents", GTK_STOCK_HELP, N_("_Contents"), "F1",
N_("Display help for the viewer application"),
G_CALLBACK (ev_window_cmd_help_contents) },
{ "ViewFullscreen", NULL, N_("_Fullscreen"), "F11",
N_("Expand the window to fill the screen"),
G_CALLBACK (ev_window_cmd_view_fullscreen) },
+ { "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) },
+ { "ViewPageWidth", EV_STOCK_ZOOM_WIDTH, N_("Fit Page _Width"), NULL,
+ N_("Make the current document fill the window width"),
+ G_CALLBACK (ev_window_cmd_view_page_width) },
};
static GtkRadioActionEntry page_view_entries[] = {
PAGE_MODE_CONTINUOUS_PAGE }
};
-static void
-goto_page_cb (GtkAction *action, int page_number, EvWindow *ev_window)
-{
- EvView *view = EV_VIEW (ev_window->priv->view);
-
- if (ev_view_get_page (view) != page_number) {
- ev_view_set_page (view, page_number);
- }
-}
-
static void
drag_data_received_cb (GtkWidget *widget, GdkDragContext *context,
gint x, gint y, GtkSelectionData *selection_data,
"label", _("Page"),
"tooltip", _("Select Page"),
NULL);
- g_signal_connect (action, "goto_page",
- G_CALLBACK (goto_page_cb), window);
gtk_action_group_add_action (group, action);
g_object_unref (action);
}
static EvChrome
load_chrome (void)
{
- GConfClient *client;
- GConfValue *value;
EvChrome chrome = EV_CHROME_NORMAL;
+ GConfClient *client;
+ GConfValue *value;
client = gconf_client_get_default ();
GtkAccelGroup *accel_group;
GError *error = NULL;
GtkWidget *sidebar_widget, *toolbar_dock;
+ GConfValue *value;
+ GConfClient *client;
+ int sidebar_size;
ev_window->priv = EV_WINDOW_GET_PRIVATE (ev_window);
TRUE, TRUE, 0);
gtk_widget_show (ev_window->priv->toolbar);
- ev_window->priv->exit_fullscreen_toolbar =
- gtk_ui_manager_get_widget (ev_window->priv->ui_manager,
- "/LeaveFullscreenToolbar");
- gtk_box_pack_start (GTK_BOX (toolbar_dock),
- ev_window->priv->exit_fullscreen_toolbar,
- FALSE, FALSE, 0);
- gtk_toolbar_set_show_arrow (GTK_TOOLBAR (ev_window->priv->exit_fullscreen_toolbar),
- FALSE);
- gtk_toolbar_set_style (GTK_TOOLBAR (ev_window->priv->exit_fullscreen_toolbar),
- GTK_TOOLBAR_BOTH_HORIZ);
+ ev_window->priv->fullscreen_toolbar =
+ gtk_ui_manager_get_widget (ev_window->priv->ui_manager, "/LeaveFullscreenToolbar");
+ gtk_toolbar_set_show_arrow (GTK_TOOLBAR (ev_window->priv->fullscreen_toolbar), TRUE);
+ gtk_toolbar_set_style (GTK_TOOLBAR (ev_window->priv->fullscreen_toolbar), GTK_TOOLBAR_BOTH_HORIZ);
/* Add the main area */
ev_window->priv->hpaned = gtk_hpaned_new ();
- gtk_widget_show (ev_window->priv->hpaned);
+ g_signal_connect (ev_window->priv->hpaned,
+ "notify::position",
+ G_CALLBACK (ev_window_sidebar_position_change_cb),
+ ev_window);
+
+ sidebar_size = SIDEBAR_DEFAULT_SIZE;
+ client = gconf_client_get_default ();
+ value = gconf_client_get (client, GCONF_SIDEBAR_SIZE, NULL);
+ if (value != NULL) {
+ if (value->type == GCONF_VALUE_INT) {
+ sidebar_size = gconf_value_get_int (value);
+ }
+ gconf_value_free (value);
+ }
+ g_object_unref (client);
+ gtk_paned_set_position (GTK_PANED (ev_window->priv->hpaned), sidebar_size);
gtk_box_pack_start (GTK_BOX (ev_window->priv->main_box), ev_window->priv->hpaned,
TRUE, TRUE, 0);
-
+ gtk_widget_show (ev_window->priv->hpaned);
+
ev_window->priv->sidebar = ev_sidebar_new ();
- gtk_paned_add1 (GTK_PANED (ev_window->priv->hpaned),
- ev_window->priv->sidebar);
+ gtk_paned_pack1 (GTK_PANED (ev_window->priv->hpaned),
+ ev_window->priv->sidebar, FALSE, FALSE);
+ gtk_widget_show (ev_window->priv->sidebar);
/* Stub sidebar, for now */
sidebar_widget = ev_sidebar_links_new ();
ev_window->priv->scrolled_window =
GTK_WIDGET (g_object_new (GTK_TYPE_SCROLLED_WINDOW,
- "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
- "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
"shadow-type", GTK_SHADOW_IN,
NULL));
gtk_widget_show (ev_window->priv->scrolled_window);
gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window),
ev_window->priv->view);
- g_signal_connect (ev_window->priv->view,
- "page-changed",
- G_CALLBACK (view_page_changed_cb),
- ev_window);
g_signal_connect (ev_window->priv->view,
"notify::find-status",
G_CALLBACK (view_find_status_changed_cb),
set_chrome_actions (ev_window);
update_chrome_visibility (ev_window);
+ /* Connect sidebar signals */
+ g_signal_connect (ev_window->priv->sidebar,
+ "notify::visible",
+ G_CALLBACK (ev_window_sidebar_visibility_changed_cb),
+ ev_window);
+
/* Connect to find bar signals */
g_signal_connect (ev_window->priv->find_bar,
"previous",
g_signal_connect (G_OBJECT (ev_window), "drag_data_received",
G_CALLBACK (drag_data_received_cb), NULL);
+ /* Set it to something random to force a change */
+ ev_window->priv->sizing_mode = EV_SIZING_FREE;
+ ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH);
update_action_sensitivity (ev_window);
}