summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gtk/Makefile.am1
-rw-r--r--gtk/gtksizerequest.c50
-rw-r--r--gtk/gtksizerequestcache.c76
-rw-r--r--gtk/gtksizerequestcacheprivate.h7
-rw-r--r--gtk/gtkwidget.c4
-rw-r--r--gtk/gtkwidgetprivate.h1
6 files changed, 89 insertions, 50 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 61d396e617..aa8145f745 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -809,6 +809,7 @@ gtk_base_c_sources = \
gtksettings.c \
gtksizegroup.c \
gtksizerequest.c \
+ gtksizerequestcache.c \
gtkshow.c \
gtkspinbutton.c \
gtkspinner.c \
diff --git a/gtk/gtksizerequest.c b/gtk/gtksizerequest.c
index 8404bd6b29..51043edb90 100644
--- a/gtk/gtksizerequest.c
+++ b/gtk/gtksizerequest.c
@@ -84,52 +84,6 @@ pop_recursion_check (GtkWidget *widget,
}
-static void
-clear_cache (SizeRequestCache *cache,
- GtkSizeGroupMode orientation)
-{
- SizeRequest **sizes;
- gint i;
-
- if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
- {
- sizes = cache->widths;
-
- cache->widths = NULL;
- cache->cached_widths = 0;
- cache->last_cached_width = 0;
- cache->cached_base_width = FALSE;
- }
- else
- {
- sizes = cache->heights;
-
- cache->heights = NULL;
- cache->cached_heights = 0;
- cache->last_cached_height = 0;
- cache->cached_base_height = FALSE;
- }
-
- if (sizes)
- {
- for (i = 0; i < GTK_SIZE_REQUEST_CACHED_SIZES && sizes[i] != NULL; i++)
- g_slice_free (SizeRequest, sizes[i]);
-
- g_slice_free1 (sizeof (SizeRequest *) * GTK_SIZE_REQUEST_CACHED_SIZES, sizes);
- }
-}
-
-void
-_gtk_widget_free_cached_sizes (GtkWidget *widget)
-{
- SizeRequestCache *cache;
-
- cache = _gtk_widget_peek_request_cache (widget);
-
- clear_cache (cache, GTK_SIZE_GROUP_HORIZONTAL);
- clear_cache (cache, GTK_SIZE_GROUP_VERTICAL);
-}
-
/* This function checks if 'request_needed' flag is present
* and resets the cache state if a request is needed for
* a given orientation.
@@ -142,10 +96,10 @@ init_cache (GtkWidget *widget)
cache = _gtk_widget_peek_request_cache (widget);
if (_gtk_widget_get_width_request_needed (widget))
- clear_cache (cache, GTK_SIZE_GROUP_HORIZONTAL);
+ _gtk_size_request_cache_clear (cache, GTK_SIZE_GROUP_HORIZONTAL);
if (_gtk_widget_get_height_request_needed (widget))
- clear_cache (cache, GTK_SIZE_GROUP_VERTICAL);
+ _gtk_size_request_cache_clear (cache, GTK_SIZE_GROUP_VERTICAL);
return cache;
}
diff --git a/gtk/gtksizerequestcache.c b/gtk/gtksizerequestcache.c
new file mode 100644
index 0000000000..d098e402f0
--- /dev/null
+++ b/gtk/gtksizerequestcache.c
@@ -0,0 +1,76 @@
+/* gtksizerequest.c
+ * Copyright (C) 2007-2010 Openismus GmbH
+ *
+ * Authors:
+ * Mathias Hasselmann <mathias@openismus.com>
+ * Tristan Van Berkom <tristan.van.berkom@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "gtksizerequestcacheprivate.h"
+
+#include <string.h>
+
+void
+_gtk_size_request_cache_init (SizeRequestCache *cache)
+{
+ memset (cache, 0, sizeof (SizeRequestCache));
+}
+
+void
+_gtk_size_request_cache_free (SizeRequestCache *cache)
+{
+ _gtk_size_request_cache_clear (cache, GTK_SIZE_GROUP_HORIZONTAL);
+ _gtk_size_request_cache_clear (cache, GTK_SIZE_GROUP_VERTICAL);
+}
+
+void
+_gtk_size_request_cache_clear (SizeRequestCache *cache,
+ GtkSizeGroupMode orientation)
+
+{
+ SizeRequest **sizes;
+ gint i;
+
+ if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
+ {
+ sizes = cache->widths;
+
+ cache->widths = NULL;
+ cache->cached_widths = 0;
+ cache->last_cached_width = 0;
+ cache->cached_base_width = FALSE;
+ }
+ else
+ {
+ sizes = cache->heights;
+
+ cache->heights = NULL;
+ cache->cached_heights = 0;
+ cache->last_cached_height = 0;
+ cache->cached_base_height = FALSE;
+ }
+
+ if (sizes)
+ {
+ for (i = 0; i < GTK_SIZE_REQUEST_CACHED_SIZES && sizes[i] != NULL; i++)
+ g_slice_free (SizeRequest, sizes[i]);
+
+ g_slice_free1 (sizeof (SizeRequest *) * GTK_SIZE_REQUEST_CACHED_SIZES, sizes);
+ }
+}
+
diff --git a/gtk/gtksizerequestcacheprivate.h b/gtk/gtksizerequestcacheprivate.h
index 143d2b0a9d..939f9cb61f 100644
--- a/gtk/gtksizerequestcacheprivate.h
+++ b/gtk/gtksizerequestcacheprivate.h
@@ -26,6 +26,7 @@
#define __GTK_SIZE_REQUEST_CACHE_PRIVATE_H__
#include <glib.h>
+#include <gtk/gtkenums.h>
G_BEGIN_DECLS
@@ -64,6 +65,12 @@ typedef struct {
guint cached_base_height : 1;
} SizeRequestCache;
+void _gtk_size_request_cache_init (SizeRequestCache *cache);
+void _gtk_size_request_cache_free (SizeRequestCache *cache);
+
+void _gtk_size_request_cache_clear (SizeRequestCache *cache,
+ GtkSizeGroupMode orientation);
+
G_END_DECLS
#endif /* __GTK_SIZE_REQUEST_CACHE_PRIVATE_H__ */
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 27353b9b26..4a5c7fd7a8 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3687,6 +3687,8 @@ gtk_widget_init (GtkWidget *widget)
*/
priv->need_compute_expand = FALSE;
+ _gtk_size_request_cache_init (&priv->requests);
+
priv->style = gtk_widget_get_default_style ();
g_object_ref (priv->style);
}
@@ -10373,7 +10375,7 @@ gtk_widget_finalize (GObject *object)
g_object_unref (priv->context);
}
- _gtk_widget_free_cached_sizes (widget);
+ _gtk_size_request_cache_free (&priv->requests);
if (g_object_is_floating (object))
g_warning ("A floating object was finalized. This means that someone\n"
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 06ba4afa5e..ca1bd24868 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -81,7 +81,6 @@ gboolean _gtk_widget_get_translation_to_window (GtkWidget *widget,
GdkWindow *window,
int *x,
int *y);
-void _gtk_widget_free_cached_sizes (GtkWidget *widget);
const gchar* _gtk_widget_get_accel_path (GtkWidget *widget,
gboolean *locked);