]> Pileus Git - ~andy/gtk/blob - gtk/gtksizerequestcache.c
sizerequestcache: Make clear_cache clear all the cache
[~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 static void
35 free_sizes (SizeRequest **sizes)
36 {
37   gint i;
38
39   for (i = 0; i < GTK_SIZE_REQUEST_CACHED_SIZES && sizes[i] != NULL; i++)
40     g_slice_free (SizeRequest, sizes[i]);
41       
42   g_slice_free1 (sizeof (SizeRequest *) * GTK_SIZE_REQUEST_CACHED_SIZES, sizes);
43 }
44
45 void
46 _gtk_size_request_cache_free (SizeRequestCache *cache)
47 {
48   if (cache->widths)
49     free_sizes (cache->widths);
50   if (cache->heights)
51     free_sizes (cache->heights);
52 }
53
54 void
55 _gtk_size_request_cache_clear (SizeRequestCache *cache)
56                                
57 {
58   _gtk_size_request_cache_free (cache);
59   _gtk_size_request_cache_init (cache);
60 }
61