]> Pileus Git - ~andy/gtk/blob - gtk/gtksizerequestcache.c
sizerequestcache: Move functions
[~andy/gtk] / gtk / gtksizerequestcache.c
1 /* gtksizerequest.c
2  * Copyright (C) 2007-2010 Openismus GmbH
3  *
4  * Authors:
5  *      Mathias Hasselmann <mathias@openismus.com>
6  *      Tristan Van Berkom <tristan.van.berkom@gmail.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #include <config.h>
23
24 #include "gtksizerequestcacheprivate.h"
25
26 #include <string.h>
27
28 void
29 _gtk_size_request_cache_init (SizeRequestCache *cache)
30 {
31   memset (cache, 0, sizeof (SizeRequestCache));
32 }
33
34 void
35 _gtk_size_request_cache_free (SizeRequestCache *cache)
36 {
37   _gtk_size_request_cache_clear (cache, GTK_SIZE_GROUP_HORIZONTAL);
38   _gtk_size_request_cache_clear (cache, GTK_SIZE_GROUP_VERTICAL);
39 }
40
41 void
42 _gtk_size_request_cache_clear (SizeRequestCache *cache,
43                                GtkSizeGroupMode  orientation)
44                                
45 {
46   SizeRequest **sizes;
47   gint          i;
48
49   if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
50     {
51       sizes = cache->widths;
52
53       cache->widths            = NULL;
54       cache->cached_widths     = 0;
55       cache->last_cached_width = 0;
56       cache->cached_base_width = FALSE;
57     }
58   else
59     {
60       sizes = cache->heights;
61
62       cache->heights            = NULL;
63       cache->cached_heights     = 0;
64       cache->last_cached_height = 0; 
65       cache->cached_base_height = FALSE;
66    }
67
68   if (sizes)
69     {
70       for (i = 0; i < GTK_SIZE_REQUEST_CACHED_SIZES && sizes[i] != NULL; i++)
71         g_slice_free (SizeRequest, sizes[i]);
72       
73       g_slice_free1 (sizeof (SizeRequest *) * GTK_SIZE_REQUEST_CACHED_SIZES, sizes);
74     }
75 }
76