Added new files resulting from directory restructuring.
[pspp-builds.git] / lib / gtksheet / gtkextra.c
1 /* gtkextra
2  * Copyright 1999-2001 Adrian E. Feiguin <feiguin@ifir.edu.ar>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <string.h>
21 #include <gtk/gtk.h>
22 #include "gtkextrafeatures.h"
23 #include <gobject/gvaluecollector.h>
24
25 const guint gtkextra_major_version = GTKEXTRA_MAJOR_VERSION;
26 const guint gtkextra_minor_version = GTKEXTRA_MINOR_VERSION;
27 const guint gtkextra_micro_version = GTKEXTRA_MICRO_VERSION;
28 const guint gtkextra_binary_age = GTKEXTRA_BINARY_AGE;
29 const guint gtkextra_interface_age = GTKEXTRA_INTERFACE_AGE;
30
31 gchar * 
32 gtkextra_check_version (guint required_major,
33                         guint required_minor,
34                         guint required_micro)
35 {
36   if (required_major > GTKEXTRA_MAJOR_VERSION)
37     return "GtkExtra version too old (major mismatch)";
38   if (required_major < GTKEXTRA_MAJOR_VERSION)
39     return "GtkExtra version too new (major mismatch)";
40   if (required_minor > GTKEXTRA_MINOR_VERSION)
41     return "GtkExtra version too old (minor mismatch)";
42   if (required_minor < GTKEXTRA_MINOR_VERSION)
43     return "GtkExtra version too new (minor mismatch)";
44   if (required_micro < GTKEXTRA_MICRO_VERSION - GTKEXTRA_BINARY_AGE)
45     return "GtkExtra version too new (micro mismatch)";
46   if (required_micro > GTKEXTRA_MICRO_VERSION)
47     return "GtkExtra version too old (micro mismatch)";
48   return NULL;
49 }
50
51 /*
52 void
53 _gtkextra_signal_test(GtkObject *object, guint signal_id, gint arg1, gint arg2, gboolean *default_ret)
54 {
55   gboolean result;
56   GValue ret = { 0, };
57   GValue instance_and_param[3] = { { 0, }, {0, }, {0, } };
58
59   g_value_init(instance_and_param + 0, GTK_OBJECT_TYPE(object));
60   g_value_set_instance(instance_and_param + 0, G_OBJECT(object));
61
62   g_value_init(instance_and_param + 1, G_TYPE_INT);
63   g_value_set_int(instance_and_param + 1, arg1);
64
65   g_value_init(instance_and_param + 2, G_TYPE_INT);
66   g_value_set_int(instance_and_param + 2, arg2);
67
68   g_value_init(&ret, G_TYPE_BOOLEAN);
69   g_value_set_boolean(&ret, *default_ret);
70
71   g_signal_emitv(instance_and_param, signal_id, 0, &ret);
72   *default_ret = g_value_get_boolean(&ret);
73
74   g_value_unset(instance_and_param + 0);
75   g_value_unset(instance_and_param + 1);
76   g_value_unset(instance_and_param + 2);
77 }
78 */
79
80 void
81 _gtkextra_signal_emit(GtkObject *object, guint signal_id, ...)
82 {
83   gboolean *result;
84   GValue ret = { 0, };
85   GValue instance_and_params [10] = { {0, }, };
86   va_list var_args;
87   GSignalQuery query;
88   gchar *error;
89   int i;
90
91   va_start (var_args, signal_id);
92
93   g_value_init(instance_and_params + 0, GTK_OBJECT_TYPE(object));
94   g_value_set_instance (instance_and_params + 0, G_OBJECT(object));
95
96   g_signal_query(signal_id, &query);
97
98   for (i = 0; i < query.n_params; i++)
99     {
100       gboolean static_scope = query.param_types[i]&~G_SIGNAL_TYPE_STATIC_SCOPE;
101       g_value_init(instance_and_params + i + 1, query.param_types[i]);
102
103
104       G_VALUE_COLLECT (instance_and_params + i + 1,
105                        var_args,
106                        static_scope ? G_VALUE_NOCOPY_CONTENTS : 0,
107                        &error);
108
109       if (error)
110         {
111           g_warning ("%s: %s", G_STRLOC, error);
112           g_free (error);
113           while (i-- > 0)
114             g_value_unset (instance_and_params + i);
115
116           va_end (var_args);
117           return;
118         }
119   
120
121     }
122
123   g_value_init(&ret, query.return_type);
124   result = va_arg(var_args,gboolean *);
125   g_value_set_boolean(&ret, *result);    
126   g_signal_emitv(instance_and_params, signal_id, 0, &ret);
127   *result = g_value_get_boolean(&ret);    
128   g_value_unset (&ret);
129
130   for (i = 0; i < query.n_params; i++)
131     g_value_unset (instance_and_params + 1 + i);
132   g_value_unset (instance_and_params + 0);
133
134   va_end (var_args);
135 }