]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/closure.h
Revert partially (auto) "reformat code! now the code is only ugly on the *inside*"
[xonotic/netradiant.git] / libs / gtkutil / closure.h
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
7    GtkRadiant is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    GtkRadiant is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GtkRadiant; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20  */
21
22 #if !defined( INCLUDED_GTKUTIL_CLOSURE_H )
23 #define INCLUDED_GTKUTIL_CLOSURE_H
24
25 #include <glib-object.h>
26 #include "generic/callback.h"
27
28 inline void closure_destroy( gpointer data, GClosure* closure ){
29         delete reinterpret_cast<Callback<void()>*>( data );
30 }
31
32 inline GClosure* create_cclosure( GCallback func, const Callback<void()>& callback ){
33         return g_cclosure_new( func, new Callback<void()>( callback ), closure_destroy );
34 }
35
36 inline GValue GValue_default(){
37         GValue value;
38         value.g_type = 0;
39         return value;
40 }
41
42 inline gint object_get_int_property( GObject* object, const char* property ){
43         GValue gvalue = GValue_default();
44         g_value_init( &gvalue, G_TYPE_INT );
45         g_object_get_property( object, property, &gvalue );
46         return g_value_get_int( &gvalue );
47 }
48
49 inline void object_set_int_property( GObject* object, const char* property, gint value ){
50         GValue gvalue = GValue_default();
51         g_value_init( &gvalue, G_TYPE_INT );
52         g_value_set_int( &gvalue, value );
53         g_object_set_property( object, property, &gvalue );
54 }
55
56 inline gboolean object_get_boolean_property( GObject* object, const char* property ){
57         GValue gvalue = GValue_default();
58         g_value_init( &gvalue, G_TYPE_BOOLEAN );
59         g_object_get_property( object, property, &gvalue );
60         return g_value_get_boolean( &gvalue );
61 }
62
63 inline void object_set_boolean_property( GObject* object, const char* property, gboolean value ){
64         GValue gvalue = GValue_default();
65         g_value_init( &gvalue, G_TYPE_BOOLEAN );
66         g_value_set_boolean( &gvalue, value );
67         g_object_set_property( object, property, &gvalue );
68 }
69
70 #endif