[gthumb] simplified the code adding a GthAutoPaned widget
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb] simplified the code adding a GthAutoPaned widget
- Date: Wed, 16 Nov 2011 22:11:29 +0000 (UTC)
commit a6b178b697f8a998020ce66c2039fa99ada835b7
Author: Paolo Bacchilega <paobac src gnome org>
Date: Tue Nov 15 16:02:39 2011 +0100
simplified the code adding a GthAutoPaned widget
...that automatically set the position to half of its allocated size.
gthumb/Makefile.am | 2 +
gthumb/gth-auto-paned.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++
gthumb/gth-auto-paned.h | 56 ++++++++++++++++++++++++++
gthumb/gth-browser.c | 15 +------
4 files changed, 163 insertions(+), 12 deletions(-)
---
diff --git a/gthumb/Makefile.am b/gthumb/Makefile.am
index 69640bc..e200054 100644
--- a/gthumb/Makefile.am
+++ b/gthumb/Makefile.am
@@ -33,6 +33,7 @@ PUBLIC_HEADER_FILES = \
glib-utils.h \
gnome-desktop-thumbnail.h \
gsignature.h \
+ gth-auto-paned.h \
gth-async-task.h \
gth-buffer-data.h \
gth-browser.h \
@@ -156,6 +157,7 @@ gthumb_SOURCES = \
gio-utils.c \
glib-utils.c \
gsignature.c \
+ gth-auto-paned.c \
gth-async-task.c \
gth-browser.c \
gth-browser-actions-callbacks.c \
diff --git a/gthumb/gth-auto-paned.c b/gthumb/gth-auto-paned.c
new file mode 100644
index 0000000..9a9f04b
--- /dev/null
+++ b/gthumb/gth-auto-paned.c
@@ -0,0 +1,102 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <gtk/gtk.h>
+#include "gth-auto-paned.h"
+
+
+G_DEFINE_TYPE (GthAutoPaned, gth_auto_paned, GTK_TYPE_PANED)
+
+
+struct _GthAutoPanedPrivate {
+ gboolean child1_visible;
+ gboolean child2_visible;
+};
+
+
+static void
+gth_auto_paned_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GthAutoPaned *self = GTH_AUTO_PANED (widget);
+ GtkWidget *child1;
+ GtkWidget *child2;
+ gboolean reset_position;
+
+ child1 = gtk_paned_get_child1 (GTK_PANED (self));
+ child2 = gtk_paned_get_child2 (GTK_PANED (self));
+
+ reset_position = FALSE;
+ if ((self->priv->child1_visible != gtk_widget_get_visible (child1))
+ || (self->priv->child2_visible != gtk_widget_get_visible (child2)))
+ {
+ reset_position = TRUE;
+ self->priv->child1_visible = gtk_widget_get_visible (child1);
+ self->priv->child2_visible = gtk_widget_get_visible (child2);
+ }
+
+ if (reset_position) {
+ int position;
+
+ switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (self))) {
+ case GTK_ORIENTATION_HORIZONTAL:
+ position = allocation->width / 2;
+ break;
+ case GTK_ORIENTATION_VERTICAL:
+ position = allocation->height / 2;
+ break;
+ }
+ gtk_paned_set_position (GTK_PANED (self), position);
+ }
+
+ GTK_WIDGET_CLASS (gth_auto_paned_parent_class)->size_allocate (widget, allocation);
+}
+
+
+static void
+gth_auto_paned_class_init (GthAutoPanedClass *klass)
+{
+ GtkWidgetClass *widget_class;
+
+ g_type_class_add_private (klass, sizeof (GthAutoPanedPrivate));
+
+ widget_class = GTK_WIDGET_CLASS (klass);
+ widget_class->size_allocate = gth_auto_paned_size_allocate;
+}
+
+
+static void
+gth_auto_paned_init (GthAutoPaned *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_PANED, GthAutoPanedPrivate);
+ self->priv->child1_visible = FALSE;
+ self->priv->child2_visible = FALSE;
+}
+
+
+GtkWidget *
+gth_auto_paned_new (GtkOrientation orientation)
+{
+ return g_object_new (GTH_TYPE_PANED,
+ "orientation", orientation,
+ NULL);
+}
diff --git a/gthumb/gth-auto-paned.h b/gthumb/gth-auto-paned.h
new file mode 100644
index 0000000..c9f80ac
--- /dev/null
+++ b/gthumb/gth-auto-paned.h
@@ -0,0 +1,56 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+
+/*
+ * GThumb
+ *
+ * Copyright (C) 2011 Free Software Foundation, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GTH_AUTO_PANED_H
+#define GTH_AUTO_PANED_H
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GTH_TYPE_PANED (gth_auto_paned_get_type ())
+#define GTH_AUTO_PANED(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTH_TYPE_PANED, GthAutoPaned))
+#define GTH_AUTO_PANED_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTH_TYPE_PANED, GthAutoPanedClass))
+#define GTH_IS_PANED(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTH_TYPE_PANED))
+#define GTH_IS_PANED_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTH_TYPE_PANED))
+#define GTH_AUTO_PANED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTH_TYPE_PANED, GthAutoPanedClass))
+
+typedef struct _GthAutoPaned GthAutoPaned;
+typedef struct _GthAutoPanedClass GthAutoPanedClass;
+typedef struct _GthAutoPanedPrivate GthAutoPanedPrivate;
+
+struct _GthAutoPaned {
+ GtkPaned parent_instance;
+ GthAutoPanedPrivate *priv;
+};
+
+struct _GthAutoPanedClass {
+ GtkPanedClass parent_class;
+};
+
+GType gth_auto_paned_get_type (void);
+GtkWidget * gth_auto_paned_new (GtkOrientation orientation);
+
+G_END_DECLS
+
+#endif /* GTH_AUTO_PANED_H */
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 4788d3c..b01053e 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -26,6 +26,7 @@
#include "dlg-personalize-filters.h"
#include "glib-utils.h"
#include "gtk-utils.h"
+#include "gth-auto-paned.h"
#include "gth-browser.h"
#include "gth-browser-actions-callbacks.h"
#include "gth-browser-actions-entries.h"
@@ -3852,13 +3853,9 @@ _gth_browser_set_sidebar_visibility (GthBrowser *browser,
_gth_browser_set_action_active (browser, "View_Sidebar", visible);
if (visible) {
- GtkAllocation allocation;
-
gtk_widget_show (browser->priv->browser_sidebar);
gtk_paned_set_position (GTK_PANED (browser->priv->browser_container),
g_settings_get_int (browser->priv->browser_settings, PREF_BROWSER_BROWSER_SIDEBAR_WIDTH));
- gtk_widget_get_allocation (browser->priv->browser_sidebar, &allocation);
- gtk_paned_set_position (GTK_PANED (browser->priv->browser_sidebar), allocation.height / 2);
}
else
gtk_widget_hide (browser->priv->browser_sidebar);
@@ -4329,9 +4326,8 @@ gth_browser_init (GthBrowser *browser)
/* the browser sidebar */
- browser->priv->browser_sidebar = gtk_paned_new (GTK_ORIENTATION_VERTICAL);
+ browser->priv->browser_sidebar = gth_auto_paned_new (GTK_ORIENTATION_VERTICAL);
gtk_widget_set_size_request (browser->priv->browser_sidebar, g_settings_get_int (browser->priv->browser_settings, PREF_BROWSER_BROWSER_SIDEBAR_WIDTH), -1);
- gtk_widget_show (browser->priv->browser_sidebar);
gtk_paned_pack1 (GTK_PANED (browser->priv->browser_container), browser->priv->browser_sidebar, FALSE, TRUE);
/* the box that contains the location and the folder list. */
@@ -5744,13 +5740,8 @@ gth_browser_show_file_properties (GthBrowser *browser,
g_settings_set_boolean (browser->priv->browser_settings, PREF_BROWSER_PROPERTIES_VISIBLE, show);
_gth_browser_set_action_active (browser, "Browser_Properties", show);
if (show) {
- if (gth_window_get_current_page (GTH_WINDOW (browser)) != GTH_WINDOW_PAGE_UNDEFINED) {
- GtkAllocation allocation;
-
- gtk_widget_get_allocation (browser->priv->browser_sidebar, &allocation);
- gtk_paned_set_position (GTK_PANED (browser->priv->browser_sidebar), allocation.height / 2);
+ if (gth_window_get_current_page (GTH_WINDOW (browser)) != GTH_WINDOW_PAGE_UNDEFINED)
gtk_widget_show (browser->priv->file_properties);
- }
}
else
gtk_widget_hide (browser->priv->file_properties);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]