[gnome-web-photo/webkit] Add max-height property to PhotoOffscreenWindow
- From: Vincent Untz <vuntz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-web-photo/webkit] Add max-height property to PhotoOffscreenWindow
- Date: Wed, 16 Feb 2011 16:29:20 +0000 (UTC)
commit 7e65ee0773d7d356f3403f3f1feff6a8d1f6c4d5
Author: Vincent Untz <vuntz gnome org>
Date: Wed Feb 16 12:06:07 2011 +0100
Add max-height property to PhotoOffscreenWindow
src/photo-offscreen-window.c | 116 +++++++++++++++++++++++++++++++++++++++---
src/photo-offscreen-window.h | 12 ++++-
2 files changed, 119 insertions(+), 9 deletions(-)
---
diff --git a/src/photo-offscreen-window.c b/src/photo-offscreen-window.c
index 1448d64..21eb693 100644
--- a/src/photo-offscreen-window.c
+++ b/src/photo-offscreen-window.c
@@ -22,57 +22,136 @@
#include "config.h"
#include <glib.h>
+#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include "photo-offscreen-window.h"
-/* Value to keep in sync with the one from cairo:
- * MAX_IMAGE_SIZE in cairo-image-surface.c */
-#define MAX_SIZE 32767
-
/* This is a GtkOffscreenWindow with a maximum height.
* See comment above gtk_widget_set_size_request() call to understand why we
* need this. */
+enum {
+ PROP_MAX_HEIGHT = 1
+};
+
+struct _PhotoOffscreenWindowPrivate
+{
+ guint max_height;
+};
+
G_DEFINE_TYPE (PhotoOffscreenWindow, photo_offscreen_window, GTK_TYPE_OFFSCREEN_WINDOW)
+static void
+photo_offscreen_window_set_property (GObject *obj,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ PhotoOffscreenWindow *window = PHOTO_OFFSCREEN_WINDOW (obj);
+
+ switch (property_id)
+ {
+ case PROP_MAX_HEIGHT:
+ photo_offscreen_window_set_max_height (window, g_value_get_uint (value));
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
+ break;
+ }
+}
+
+static void
+photo_offscreen_window_get_property (GObject *obj,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ PhotoOffscreenWindow *window = PHOTO_OFFSCREEN_WINDOW (obj);
+
+ switch (property_id)
+ {
+ case PROP_MAX_HEIGHT:
+ g_value_set_uint (value, window->priv->max_height);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
+ break;
+ }
+}
+
#ifdef HAVE_GNOME3
static void
photo_offscreen_window_get_preferred_height (GtkWidget *widget,
gint *minimum,
gint *natural)
{
+ PhotoOffscreenWindow *window = PHOTO_OFFSCREEN_WINDOW (widget);
+
GTK_WIDGET_CLASS (photo_offscreen_window_parent_class)->get_preferred_height (widget, minimum, natural);
- *minimum = MIN (*minimum, MAX_SIZE);
- *natural = MIN (*natural, MAX_SIZE);
+ if (window->priv->max_height > 0) {
+ *minimum = MIN (*minimum, window->priv->max_height);
+ *natural = MIN (*natural, window->priv->max_height);
+ }
}
#else
static void
photo_offscreen_window_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
+ PhotoOffscreenWindow *window = PHOTO_OFFSCREEN_WINDOW (widget);
+
GTK_WIDGET_CLASS (photo_offscreen_window_parent_class)->size_request (widget, requisition);
- requisition->height = MIN (requisition->height, MAX_SIZE);
+ if (window->priv->max_height > 0)
+ requisition->height = MIN (requisition->height, window->priv->max_height);
}
#endif
static void
photo_offscreen_window_class_init (PhotoOffscreenWindowClass *class)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+ GParamSpec *pspec;
+
+ object_class->set_property = photo_offscreen_window_set_property;
+ object_class->get_property = photo_offscreen_window_get_property;
#ifdef HAVE_GNOME3
widget_class->get_preferred_height = photo_offscreen_window_get_preferred_height;
#else
widget_class->size_request = photo_offscreen_window_size_request;
#endif
+
+ /**
+ * PhotoOffscreenWindow:max-height:
+ *
+ * The #PhotoOffscreenWindow:max-height property determines the maximum
+ * height of the offscreen window. This can be useful if widgets inside the
+ * offscreen window get too large.
+ *
+ * Usual offscreen windows have no maximum height; a maximum height of 0 will
+ * keep this behavior.
+ */
+ pspec =
+ g_param_spec_uint ("max-height",
+ _("Maximum height"),
+ _("Maximum height of the offscreen window"),
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS);
+ g_object_class_install_property (object_class, PROP_MAX_HEIGHT, pspec);
+
+
+ g_type_class_add_private (class, sizeof (PhotoOffscreenWindowPrivate));
}
static void
photo_offscreen_window_init (PhotoOffscreenWindow *window)
{
+ window->priv = G_TYPE_INSTANCE_GET_PRIVATE (window, PHOTO_TYPE_OFFSCREEN_WINDOW,
+ PhotoOffscreenWindowPrivate);
}
GtkWidget *
@@ -80,3 +159,26 @@ photo_offscreen_window_new (void)
{
return g_object_new (photo_offscreen_window_get_type (), NULL);
}
+
+void
+photo_offscreen_window_set_max_height (PhotoOffscreenWindow *window,
+ guint max_height)
+{
+ g_return_if_fail (PHOTO_IS_OFFSCREEN_WINDOW (window));
+
+ if (window->priv->max_height == max_height)
+ return;
+
+ window->priv->max_height = max_height;
+ g_object_notify (G_OBJECT (window), "max-height");
+
+ gtk_widget_queue_resize (GTK_WIDGET (window));
+}
+
+guint
+photo_offscreen_window_get_max_height (PhotoOffscreenWindow *window)
+{
+ g_return_val_if_fail (PHOTO_IS_OFFSCREEN_WINDOW (window), 0);
+
+ return window->priv->max_height;
+}
diff --git a/src/photo-offscreen-window.h b/src/photo-offscreen-window.h
index 5b85b4f..68c8fe8 100644
--- a/src/photo-offscreen-window.h
+++ b/src/photo-offscreen-window.h
@@ -33,12 +33,16 @@ G_BEGIN_DECLS
#define PHOTO_IS_OFFSCREEN_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PHOTO_TYPE_OFFSCREEN_WINDOW))
#define PHOTO_OFFSCREEN_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PHOTO_TYPE_OFFSCREEN_WINDOW, PhotoOffscreenWindowClass))
-typedef struct _PhotoOffscreenWindow PhotoOffscreenWindow;
-typedef struct _PhotoOffscreenWindowClass PhotoOffscreenWindowClass;
+typedef struct _PhotoOffscreenWindow PhotoOffscreenWindow;
+typedef struct _PhotoOffscreenWindowClass PhotoOffscreenWindowClass;
+typedef struct _PhotoOffscreenWindowPrivate PhotoOffscreenWindowPrivate;
struct _PhotoOffscreenWindow
{
GtkOffscreenWindow parent_object;
+
+ /*< private >*/
+ PhotoOffscreenWindowPrivate *priv;
};
struct _PhotoOffscreenWindowClass
@@ -50,6 +54,10 @@ GType photo_offscreen_window_get_type (void) G_GNUC_CONST;
GtkWidget *photo_offscreen_window_new (void);
+void photo_offscreen_window_set_max_height (PhotoOffscreenWindow *window,
+ guint max_height);
+guint photo_offscreen_window_get_max_height (PhotoOffscreenWindow *window);
+
G_END_DECLS
#endif /* _PHOTO_OFFSCREEN_WINDOW_H_ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]