File: bonobo-property-control.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (311 lines) | stat: -rw-r--r-- 8,896 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/**
 * bonobo-property-control.c: Bonobo PropertyControl implementation
 *
 * Author:
 *      Iain Holmes  <iain@helixcode.com>
 *
 * Copyright 2000 Helix Code, Inc.
 */
#include <config.h>
#include <stdio.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkmarshal.h>
#include <gtk/gtktypeutils.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-property-control.h>
#include <bonobo/bonobo-event-source.h>
#include "Bonobo.h"

struct _BonoboPropertyControlPrivate {
	BonoboPropertyControlGetControlFn get_fn;
	BonoboEventSource *event_source;

	void *closure;
	int page_count;
};

enum {
	ACTION,
	LAST_SIGNAL
};

#define PARENT_TYPE BONOBO_X_OBJECT_TYPE

static GtkObjectClass *parent_class;

static guint32 signals[LAST_SIGNAL] = { 0 };

static CORBA_long
impl_Bonobo_PropertyControl__get_pageCount (PortableServer_Servant servant,
					    CORBA_Environment *ev)
{
	BonoboObject *bonobo_object;
	BonoboPropertyControl *property_control;
	BonoboPropertyControlPrivate *priv;

	bonobo_object = bonobo_object_from_servant (servant);
	property_control = BONOBO_PROPERTY_CONTROL (bonobo_object);
	priv = property_control->priv;

	return priv->page_count;
}
       
static Bonobo_Control
impl_Bonobo_PropertyControl_getControl (PortableServer_Servant servant,
					CORBA_long pagenumber,
					CORBA_Environment *ev)
{
	BonoboObject *bonobo_object;
	BonoboPropertyControl *property_control;
	BonoboPropertyControlPrivate *priv;
	BonoboControl *control;

	bonobo_object = bonobo_object_from_servant (servant);
	property_control = BONOBO_PROPERTY_CONTROL (bonobo_object);
	priv = property_control->priv;

	if (pagenumber < 0 || pagenumber >= priv->page_count) {
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_PropertyControl_NoPage, NULL);
		return CORBA_OBJECT_NIL;
	}

	control = priv->get_fn (property_control, 
			        pagenumber,
		                priv->closure);

	if (control == NULL)
		return CORBA_OBJECT_NIL;

	return (Bonobo_Control) CORBA_Object_duplicate 
		(BONOBO_OBJREF (control), ev);
}

static void
impl_Bonobo_PropertyControl_notifyAction (PortableServer_Servant servant,
					  CORBA_long pagenumber,
					  Bonobo_PropertyControl_Action action,
					  CORBA_Environment *ev)
{
	BonoboObject *bonobo_object;
	BonoboPropertyControl *property_control;
	BonoboPropertyControlPrivate *priv;

	bonobo_object = bonobo_object_from_servant (servant);
	property_control = BONOBO_PROPERTY_CONTROL (bonobo_object);
	priv = property_control->priv;

	if (pagenumber < 0 || pagenumber >= priv->page_count) {
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_PropertyControl_NoPage, NULL);
		return;
	}
	
	gtk_signal_emit (GTK_OBJECT (bonobo_object), signals [ACTION], pagenumber, action);
}

static void
bonobo_property_control_destroy (GtkObject *object)
{
	BonoboPropertyControl *property_control;
	
	property_control = BONOBO_PROPERTY_CONTROL (object);
	if (property_control->priv == NULL)
		return;

	g_free (property_control->priv);
	property_control->priv = NULL;

	parent_class->destroy (object);
}

static void
bonobo_property_control_class_init (BonoboPropertyControlClass *klass)
{
	GtkObjectClass *object_class;
	POA_Bonobo_PropertyControl__epv *epv = &klass->epv;

	object_class = GTK_OBJECT_CLASS (klass);
	object_class->destroy = bonobo_property_control_destroy;

	signals [ACTION] = gtk_signal_new ("action",
					 GTK_RUN_FIRST, object_class->type,
					 GTK_SIGNAL_OFFSET (BonoboPropertyControlClass, action),
					 gtk_marshal_NONE__INT_INT, GTK_TYPE_NONE,
					 2, GTK_TYPE_INT, GTK_TYPE_ENUM);

	gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
				     
	parent_class = gtk_type_class (PARENT_TYPE);

	epv->_get_pageCount = impl_Bonobo_PropertyControl__get_pageCount;
	epv->getControl     = impl_Bonobo_PropertyControl_getControl;
	epv->notifyAction   = impl_Bonobo_PropertyControl_notifyAction;
}

static void
bonobo_property_control_init (BonoboPropertyControl *property_control)
{
	BonoboPropertyControlPrivate *priv;

	priv = g_new (BonoboPropertyControlPrivate, 1);
	priv->get_fn = NULL;
	priv->closure = NULL;
	priv->page_count = 0;

	property_control->priv = priv;
}

BONOBO_X_TYPE_FUNC_FULL (BonoboPropertyControl, 
			   Bonobo_PropertyControl,
			   PARENT_TYPE,
			   bonobo_property_control);

/**
 * bonobo_property_control_construct:
 * @property_control: A BonoboPropertyControl object.
 * @event_source: A BonoboEventSource object that will be aggregated onto the
 * property control.
 * @get_fn: Creation routine.
 * @closure: Data passed to closure routine.
 *
 * Initialises the BonoboPropertyControl object.
 *
 * Returns: The newly constructed BonoboPropertyControl.
 */
BonoboPropertyControl *
bonobo_property_control_construct (BonoboPropertyControl            *property_control,
				   BonoboEventSource                *event_source,
				   BonoboPropertyControlGetControlFn get_fn,
				   int                               num_pages,
				   void                             *closure)
{
	BonoboPropertyControlPrivate *priv;

	g_return_val_if_fail (BONOBO_IS_EVENT_SOURCE (event_source), NULL);
	g_return_val_if_fail (BONOBO_IS_PROPERTY_CONTROL (property_control), NULL);

	priv = property_control->priv;
	priv->get_fn = get_fn;
	priv->page_count = num_pages;
	priv->closure = closure;

	priv->event_source = event_source;
	bonobo_object_add_interface (BONOBO_OBJECT (property_control),
				     BONOBO_OBJECT (priv->event_source));

	return property_control;
}

/**
 * bonobo_property_control_new_full:
 * @get_fn: The function to be called when the getControl method is called.
 * @num_pages: The number of pages this property control has.
 * @event_source: The event source to use to emit events on.
 * @closure: The data to be passed into the @get_fn routine.
 *
 * Creates a BonoboPropertyControl object.
 *
 * Returns: A pointer to a newly created BonoboPropertyControl object.
 */
BonoboPropertyControl *
bonobo_property_control_new_full (BonoboPropertyControlGetControlFn get_fn,
				  int                               num_pages,
				  BonoboEventSource                *event_source,
				  void                             *closure)
{
	BonoboPropertyControl *property_control;

	g_return_val_if_fail (num_pages > 0, NULL);
	g_return_val_if_fail (BONOBO_IS_EVENT_SOURCE (event_source), NULL);

	property_control = gtk_type_new (bonobo_property_control_get_type ());
					
	return bonobo_property_control_construct (
		property_control, event_source, get_fn, num_pages, closure);
}

/**
 * bonobo_property_control_new:
 * @get_fn: The function to be called when the getControl method is called.
 * @num_pages: The number of pages this property control has.
 * @closure: The data to be passed into the @get_fn routine
 *
 * Creates a BonoboPropertyControl object.
 *
 * Returns: A pointer to a newly created BonoboPropertyControl object.
 */
BonoboPropertyControl *
bonobo_property_control_new (BonoboPropertyControlGetControlFn get_fn,
			     int   num_pages,
			     void *closure)
{
	BonoboEventSource *event_source;

	g_return_val_if_fail (num_pages > 0, NULL);

	event_source = bonobo_event_source_new ();

	return bonobo_property_control_new_full (
		get_fn, num_pages, event_source, closure);
}

/**
 * bonobo_property_control_changed:
 * @property_control: The BonoboPropertyControl that has changed.
 * @opt_ev: An optional CORBA_Environment for exception handling. 
 *
 * Tells the server that a value in the property control has been changed,
 * and that it should indicate this somehow.
 */
void
bonobo_property_control_changed (BonoboPropertyControl *property_control,
				 CORBA_Environment     *opt_ev)
{
	BonoboPropertyControlPrivate *priv;
	CORBA_Environment ev;
	CORBA_any any;
	CORBA_short s;

	g_return_if_fail (property_control != NULL);
	g_return_if_fail (BONOBO_IS_PROPERTY_CONTROL (property_control));

	priv = property_control->priv;

	if (opt_ev == NULL)
		CORBA_exception_init (&ev);
	else
		ev = *opt_ev;

	s = 0;
	any._type = (CORBA_TypeCode) TC_short;
	any._value = &s;

	bonobo_event_source_notify_listeners (priv->event_source,
					      BONOBO_PROPERTY_CONTROL_CHANGED,
					      &any, &ev);
	if (opt_ev == NULL && BONOBO_EX (&ev)) {
		g_warning ("ERROR: %s", CORBA_exception_id (&ev));
	}

	if (opt_ev == NULL)
		CORBA_exception_free (&ev);
}

/**
 * bonobo_property_control_get_event_source:
 * @property_control: The BonoboPropertyControl.
 * 
 * Returns the BonoboEventSource that @property_control uses.
 * Returns: A BonoboEventSource.
 */
BonoboEventSource *
bonobo_property_control_get_event_source (BonoboPropertyControl *property_control)
{
	g_return_val_if_fail (property_control != NULL, NULL);
	g_return_val_if_fail (BONOBO_IS_PROPERTY_CONTROL (property_control), NULL);

	return property_control->priv->event_source;
}