[gthumb/ext] added ability to fit the window size to the image size
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext] added ability to fit the window size to the image size
- Date: Fri, 27 Nov 2009 19:12:19 +0000 (UTC)
commit 28684cc2a545d7886151b57ba14466b51ab01862
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Nov 27 20:10:54 2009 +0100
added ability to fit the window size to the image size
extensions/image_viewer/gth-image-viewer-page.c | 83 +++++++++++++++++++++++
extensions/image_viewer/gth-image-viewer-page.h | 1 +
gthumb/gth-window.c | 24 +++++++
gthumb/gth-window.h | 2 +
4 files changed, 110 insertions(+), 0 deletions(-)
---
diff --git a/extensions/image_viewer/gth-image-viewer-page.c b/extensions/image_viewer/gth-image-viewer-page.c
index 9de5307..46259b7 100644
--- a/extensions/image_viewer/gth-image-viewer-page.c
+++ b/extensions/image_viewer/gth-image-viewer-page.c
@@ -58,6 +58,11 @@ static const char *image_viewer_ui_info =
" <menuitem action='ImageViewer_Edit_Redo'/>"
" </placeholder>"
" </menu>"
+" <menu name='View' action='ViewMenu'>"
+" <placeholder name='View_Actions'>"
+" <menuitem action='ImageViewer_View_ShrinkWrap'/>"
+" </placeholder>"
+" </menu>"
" </menubar>"
" <toolbar name='ViewerToolBar'>"
" <placeholder name='ViewerCommands'>"
@@ -142,6 +147,14 @@ image_viewer_activate_action_edit_redo (GtkAction *action,
}
+static void
+image_viewer_activate_action_view_shrink_wrap (GtkAction *action,
+ GthImageViewerPage *self)
+{
+ gth_image_viewer_page_shrink_wrap (self);
+}
+
+
static GtkActionEntry image_viewer_action_entries[] = {
{ "ImageViewer_Edit_Undo", GTK_STOCK_UNDO,
NULL, "<control>z",
@@ -177,6 +190,11 @@ static GtkActionEntry image_viewer_action_entries[] = {
N_("Width"), "",
N_("Zoom to fit width"),
G_CALLBACK (image_viewer_activate_action_view_zoom_fit_width) },
+
+ { "ImageViewer_View_ShrinkWrap", NULL,
+ N_("_Fit Window to Image"), "<control>e",
+ N_("Resize the window to the size of the image"),
+ G_CALLBACK (image_viewer_activate_action_view_shrink_wrap) },
};
@@ -1065,3 +1083,68 @@ gth_image_viewer_page_reset (GthImageViewerPage *self)
_gth_image_viewer_page_set_pixbuf (self, last_image->image, last_image->unsaved);
}
+
+
+static int
+add_non_content_height (GthImageViewerPage *self,
+ GtkWidget *non_content)
+{
+ int height = 0;
+
+ if ((non_content != NULL) && GTK_WIDGET_VISIBLE (non_content)) {
+ GtkAllocation allocation;
+ gtk_widget_get_allocation (non_content, &allocation);
+ height = allocation.height;
+ }
+
+ return height;
+}
+
+
+void
+gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self)
+{
+ GdkPixbuf *pixbuf;
+ int width;
+ int height;
+ double ratio;
+ int other_width;
+ int other_height;
+ GdkScreen *screen;
+ int max_width;
+ int max_height;
+
+ pixbuf = gth_image_viewer_page_get_pixbuf (self);
+ if (pixbuf == NULL)
+ return;
+
+ width = gdk_pixbuf_get_width (pixbuf);
+ height = gdk_pixbuf_get_height (pixbuf);
+ ratio = (double) width / height;
+
+ other_width = 0;
+ other_height = 0;
+ other_height += add_non_content_height (self, gth_window_get_area (GTH_WINDOW (self->priv->browser), GTH_WINDOW_MENUBAR));
+ other_height += add_non_content_height (self, gth_window_get_area (GTH_WINDOW (self->priv->browser), GTH_WINDOW_TOOLBAR));
+ other_height += add_non_content_height (self, gth_window_get_area (GTH_WINDOW (self->priv->browser), GTH_WINDOW_STATUSBAR));
+ other_height += add_non_content_height (self, gth_browser_get_viewer_toolbar (self->priv->browser));
+ other_width += 2;
+ other_height += 2;
+
+ screen = gtk_widget_get_screen (GTK_WIDGET (self->priv->browser));
+ max_width = gdk_screen_get_width (screen) * 9 / 10;
+ max_height = gdk_screen_get_height (screen) * 8 / 10;
+
+ if (width + other_width > max_width) {
+ width = max_width;
+ height = width / ratio;
+ }
+
+ if (height + other_height > max_height) {
+ height = max_height;
+ width = height * ratio;
+ }
+
+ gtk_window_resize (GTK_WINDOW (self->priv->browser), width + other_width, height + other_height);
+ gth_image_viewer_set_fit_mode (GTH_IMAGE_VIEWER (self->priv->viewer), GTH_FIT_SIZE);
+}
diff --git a/extensions/image_viewer/gth-image-viewer-page.h b/extensions/image_viewer/gth-image-viewer-page.h
index 39852ee..bf28e76 100644
--- a/extensions/image_viewer/gth-image-viewer-page.h
+++ b/extensions/image_viewer/gth-image-viewer-page.h
@@ -57,6 +57,7 @@ void gth_image_viewer_page_undo (GthImageViewerPage *p
void gth_image_viewer_page_redo (GthImageViewerPage *page);
GthImageHistory * gth_image_viewer_page_get_history (GthImageViewerPage *self);
void gth_image_viewer_page_reset (GthImageViewerPage *self);
+void gth_image_viewer_page_shrink_wrap (GthImageViewerPage *self);
G_END_DECLS
diff --git a/gthumb/gth-window.c b/gthumb/gth-window.c
index 458aac4..c6965f1 100644
--- a/gthumb/gth-window.c
+++ b/gthumb/gth-window.c
@@ -60,6 +60,8 @@ gth_window_set_n_pages (GthWindow *self,
self->priv->n_pages = n_pages;
self->priv->table = gtk_table_new (4, 1, FALSE);
+ gtk_table_set_row_spacings (GTK_TABLE (self->priv->table), 0);
+ gtk_table_set_col_spacings (GTK_TABLE (self->priv->table), 0);
gtk_widget_show (self->priv->table);
gtk_container_add (GTK_CONTAINER (self), self->priv->table);
@@ -370,6 +372,28 @@ gth_window_show_only_content (GthWindow *window,
}
+GtkWidget *
+gth_window_get_area (GthWindow *window,
+ GthWindowArea area)
+{
+ switch (area) {
+ case GTH_WINDOW_MENUBAR:
+ return window->priv->menubar;
+ break;
+ case GTH_WINDOW_TOOLBAR:
+ return window->priv->toolbar;
+ break;
+ case GTH_WINDOW_STATUSBAR:
+ return window->priv->statusbar;
+ break;
+ default:
+ break;
+ }
+
+ return NULL;
+}
+
+
int
gth_window_get_n_windows (void)
{
diff --git a/gthumb/gth-window.h b/gthumb/gth-window.h
index 24b3839..f00d592 100644
--- a/gthumb/gth-window.h
+++ b/gthumb/gth-window.h
@@ -77,6 +77,8 @@ void gth_window_set_current_page (GthWindow *window,
int gth_window_get_current_page (GthWindow *window);
void gth_window_show_only_content (GthWindow *window,
gboolean only_content);
+GtkWidget * gth_window_get_area (GthWindow *window,
+ GthWindowArea area);
/**/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]