1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
---|
2 | * |
---|
3 | * Bonobo::Zoomable - zoomable interface for Controls. |
---|
4 | * |
---|
5 | * Copyright (C) 2000 Eazel, Inc. |
---|
6 | * 2000 SuSE GmbH. |
---|
7 | * |
---|
8 | * This library is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU Lesser 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 | * Lesser General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU Lesser General Public |
---|
19 | * License along with this library; if not, write to the Free |
---|
20 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | * |
---|
22 | * Authors: Maciej Stachowiak <mjs@eazel.com> |
---|
23 | * Martin Baulig <baulig@suse.de> |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | #include <config.h> |
---|
28 | #include <bonobo/bonobo-exception.h> |
---|
29 | #include <bonobo/bonobo-zoomable.h> |
---|
30 | #include <bonobo/bonobo-property-bag.h> |
---|
31 | #include <gtk/gtksignal.h> |
---|
32 | |
---|
33 | #undef ZOOMABLE_DEBUG |
---|
34 | |
---|
35 | static BonoboObjectClass *bonobo_zoomable_parent_class; |
---|
36 | static BonoboZoomableClass *bonobo_zoomable_class; |
---|
37 | |
---|
38 | struct _BonoboZoomablePrivate { |
---|
39 | CORBA_float zoom_level; |
---|
40 | |
---|
41 | CORBA_float min_zoom_level; |
---|
42 | CORBA_float max_zoom_level; |
---|
43 | CORBA_boolean has_min_zoom_level; |
---|
44 | CORBA_boolean has_max_zoom_level; |
---|
45 | CORBA_boolean is_continuous; |
---|
46 | |
---|
47 | GArray *preferred_zoom_levels; |
---|
48 | GArray *preferred_zoom_level_names; |
---|
49 | |
---|
50 | Bonobo_ZoomableFrame zoomable_frame; |
---|
51 | }; |
---|
52 | |
---|
53 | enum { |
---|
54 | SET_FRAME, |
---|
55 | SET_ZOOM_LEVEL, |
---|
56 | ZOOM_IN, |
---|
57 | ZOOM_OUT, |
---|
58 | ZOOM_TO_FIT, |
---|
59 | ZOOM_TO_DEFAULT, |
---|
60 | LAST_SIGNAL |
---|
61 | }; |
---|
62 | |
---|
63 | enum { |
---|
64 | ARG_0, |
---|
65 | ARG_ZOOM_LEVEL, |
---|
66 | ARG_MIN_ZOOM_LEVEL, |
---|
67 | ARG_MAX_ZOOM_LEVEL, |
---|
68 | ARG_HAS_MIN_ZOOM_LEVEL, |
---|
69 | ARG_HAS_MAX_ZOOM_LEVEL, |
---|
70 | ARG_IS_CONTINUOUS |
---|
71 | }; |
---|
72 | |
---|
73 | static guint signals[LAST_SIGNAL]; |
---|
74 | |
---|
75 | typedef struct { |
---|
76 | POA_Bonobo_Zoomable servant; |
---|
77 | |
---|
78 | BonoboZoomable *gtk_object; |
---|
79 | } impl_POA_Bonobo_Zoomable; |
---|
80 | |
---|
81 | POA_Bonobo_Zoomable__vepv bonobo_zoomable_vepv; |
---|
82 | |
---|
83 | #define CLASS(o) BONOBO_ZOOMABLE_CLASS(GTK_OBJECT(o)->klass) |
---|
84 | |
---|
85 | static inline BonoboZoomable * |
---|
86 | bonobo_zoomable_from_servant (PortableServer_Servant servant) |
---|
87 | { |
---|
88 | if (!BONOBO_IS_ZOOMABLE (bonobo_object_from_servant (servant))) |
---|
89 | return NULL; |
---|
90 | else |
---|
91 | return BONOBO_ZOOMABLE (bonobo_object_from_servant (servant)); |
---|
92 | } |
---|
93 | |
---|
94 | static CORBA_float |
---|
95 | impl_Bonobo_Zoomable__get_level (PortableServer_Servant servant, |
---|
96 | CORBA_Environment *ev) |
---|
97 | { |
---|
98 | BonoboZoomable *zoomable; |
---|
99 | |
---|
100 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
101 | return zoomable->priv->zoom_level; |
---|
102 | } |
---|
103 | |
---|
104 | static CORBA_float |
---|
105 | impl_Bonobo_Zoomable__get_minLevel (PortableServer_Servant servant, |
---|
106 | CORBA_Environment *ev) |
---|
107 | { |
---|
108 | BonoboZoomable *zoomable; |
---|
109 | |
---|
110 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
111 | return zoomable->priv->min_zoom_level; |
---|
112 | } |
---|
113 | |
---|
114 | static CORBA_float |
---|
115 | impl_Bonobo_Zoomable__get_maxLevel (PortableServer_Servant servant, |
---|
116 | CORBA_Environment *ev) |
---|
117 | { |
---|
118 | BonoboZoomable *zoomable; |
---|
119 | |
---|
120 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
121 | return zoomable->priv->max_zoom_level; |
---|
122 | } |
---|
123 | |
---|
124 | static CORBA_boolean |
---|
125 | impl_Bonobo_Zoomable__get_hasMinLevel (PortableServer_Servant servant, |
---|
126 | CORBA_Environment *ev) |
---|
127 | { |
---|
128 | BonoboZoomable *zoomable; |
---|
129 | |
---|
130 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
131 | return zoomable->priv->has_min_zoom_level; |
---|
132 | } |
---|
133 | |
---|
134 | static CORBA_boolean |
---|
135 | impl_Bonobo_Zoomable__get_hasMaxLevel (PortableServer_Servant servant, |
---|
136 | CORBA_Environment *ev) |
---|
137 | { |
---|
138 | BonoboZoomable *zoomable; |
---|
139 | |
---|
140 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
141 | return zoomable->priv->has_max_zoom_level; |
---|
142 | } |
---|
143 | |
---|
144 | static CORBA_boolean |
---|
145 | impl_Bonobo_Zoomable__get_isContinuous (PortableServer_Servant servant, |
---|
146 | CORBA_Environment *ev) |
---|
147 | { |
---|
148 | BonoboZoomable *zoomable; |
---|
149 | |
---|
150 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
151 | return zoomable->priv->is_continuous; |
---|
152 | } |
---|
153 | |
---|
154 | static Bonobo_ZoomLevelList * |
---|
155 | impl_Bonobo_Zoomable__get_preferredLevels (PortableServer_Servant servant, |
---|
156 | CORBA_Environment *ev) |
---|
157 | { |
---|
158 | Bonobo_ZoomLevelList *list; |
---|
159 | BonoboZoomable *zoomable; |
---|
160 | float *zoom_levels; |
---|
161 | int num_zoom_levels; |
---|
162 | int i; |
---|
163 | |
---|
164 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
165 | |
---|
166 | num_zoom_levels = zoomable->priv->preferred_zoom_levels->len; |
---|
167 | zoom_levels = (float *) zoomable->priv->preferred_zoom_levels->data; |
---|
168 | |
---|
169 | list = Bonobo_ZoomLevelList__alloc (); |
---|
170 | list->_maximum = zoomable->priv->preferred_zoom_levels->len; |
---|
171 | list->_length = zoomable->priv->preferred_zoom_levels->len; |
---|
172 | list->_buffer = CORBA_sequence_Bonobo_ZoomLevel_allocbuf (num_zoom_levels); |
---|
173 | |
---|
174 | for (i = 0; i < num_zoom_levels; ++i) { |
---|
175 | /* assigned one at a time to convert float to CORBA_float */ |
---|
176 | list->_buffer [i] = zoom_levels [i]; |
---|
177 | } |
---|
178 | |
---|
179 | CORBA_sequence_set_release (list, CORBA_TRUE); |
---|
180 | |
---|
181 | return list; |
---|
182 | } |
---|
183 | |
---|
184 | static Bonobo_ZoomLevelNameList * |
---|
185 | impl_Bonobo_Zoomable__get_preferredLevelNames (PortableServer_Servant servant, |
---|
186 | CORBA_Environment *ev) |
---|
187 | { |
---|
188 | Bonobo_ZoomLevelNameList *list; |
---|
189 | BonoboZoomable *zoomable; |
---|
190 | gchar **zoom_level_names; |
---|
191 | int num_zoom_level_names; |
---|
192 | int i; |
---|
193 | |
---|
194 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
195 | |
---|
196 | num_zoom_level_names = zoomable->priv->preferred_zoom_level_names->len; |
---|
197 | zoom_level_names = (gchar **) zoomable->priv->preferred_zoom_level_names->data; |
---|
198 | |
---|
199 | list = Bonobo_ZoomLevelNameList__alloc (); |
---|
200 | list->_maximum = zoomable->priv->preferred_zoom_level_names->len; |
---|
201 | list->_length = zoomable->priv->preferred_zoom_level_names->len; |
---|
202 | list->_buffer = CORBA_sequence_Bonobo_ZoomLevelName_allocbuf (num_zoom_level_names); |
---|
203 | |
---|
204 | for (i = 0; i < num_zoom_level_names; ++i) { |
---|
205 | list->_buffer [i] = CORBA_string_dup (zoom_level_names [i]); |
---|
206 | } |
---|
207 | |
---|
208 | CORBA_sequence_set_release (list, CORBA_TRUE); |
---|
209 | |
---|
210 | return list; |
---|
211 | } |
---|
212 | |
---|
213 | static void |
---|
214 | impl_Bonobo_Zoomable_setLevel (PortableServer_Servant servant, |
---|
215 | const CORBA_float zoom_level, |
---|
216 | CORBA_Environment *ev) |
---|
217 | { |
---|
218 | BonoboZoomable *zoomable; |
---|
219 | |
---|
220 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
221 | gtk_signal_emit (GTK_OBJECT (zoomable), signals[SET_ZOOM_LEVEL], zoom_level); |
---|
222 | } |
---|
223 | |
---|
224 | static void |
---|
225 | impl_Bonobo_Zoomable_zoomIn (PortableServer_Servant servant, |
---|
226 | CORBA_Environment *ev) |
---|
227 | { |
---|
228 | BonoboZoomable *zoomable; |
---|
229 | |
---|
230 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
231 | gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_IN]); |
---|
232 | } |
---|
233 | |
---|
234 | static void |
---|
235 | impl_Bonobo_Zoomable_zoomOut (PortableServer_Servant servant, |
---|
236 | CORBA_Environment *ev) |
---|
237 | { |
---|
238 | BonoboZoomable *zoomable; |
---|
239 | |
---|
240 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
241 | gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_OUT]); |
---|
242 | } |
---|
243 | |
---|
244 | static void |
---|
245 | impl_Bonobo_Zoomable_zoomFit (PortableServer_Servant servant, |
---|
246 | CORBA_Environment *ev) |
---|
247 | { |
---|
248 | BonoboZoomable *zoomable; |
---|
249 | |
---|
250 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
251 | gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_TO_FIT]); |
---|
252 | } |
---|
253 | |
---|
254 | static void |
---|
255 | impl_Bonobo_Zoomable_zoomDefault (PortableServer_Servant servant, |
---|
256 | CORBA_Environment *ev) |
---|
257 | { |
---|
258 | BonoboZoomable *zoomable; |
---|
259 | |
---|
260 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
261 | gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_TO_DEFAULT]); |
---|
262 | } |
---|
263 | |
---|
264 | static void |
---|
265 | impl_Bonobo_Zoomable_setFrame (PortableServer_Servant servant, |
---|
266 | Bonobo_ZoomableFrame zoomable_frame, |
---|
267 | CORBA_Environment *ev) |
---|
268 | { |
---|
269 | BonoboZoomable *zoomable; |
---|
270 | |
---|
271 | zoomable = bonobo_zoomable_from_servant (servant); |
---|
272 | |
---|
273 | g_assert (zoomable->priv->zoomable_frame == CORBA_OBJECT_NIL); |
---|
274 | zoomable->priv->zoomable_frame = CORBA_Object_duplicate (zoomable_frame, ev); |
---|
275 | gtk_signal_emit (GTK_OBJECT (zoomable), signals[SET_FRAME]); |
---|
276 | } |
---|
277 | |
---|
278 | |
---|
279 | /** |
---|
280 | * bonobo_zoomable_get_epv: |
---|
281 | * |
---|
282 | * Returns: The EPV for the default BonoboZoomable implementation. |
---|
283 | */ |
---|
284 | POA_Bonobo_Zoomable__epv * |
---|
285 | bonobo_zoomable_get_epv (void) |
---|
286 | { |
---|
287 | POA_Bonobo_Zoomable__epv *epv; |
---|
288 | |
---|
289 | epv = g_new0 (POA_Bonobo_Zoomable__epv, 1); |
---|
290 | |
---|
291 | epv->_get_level = impl_Bonobo_Zoomable__get_level; |
---|
292 | epv->_get_minLevel = impl_Bonobo_Zoomable__get_minLevel; |
---|
293 | epv->_get_maxLevel = impl_Bonobo_Zoomable__get_maxLevel; |
---|
294 | epv->_get_hasMinLevel = impl_Bonobo_Zoomable__get_hasMinLevel; |
---|
295 | epv->_get_hasMaxLevel = impl_Bonobo_Zoomable__get_hasMaxLevel; |
---|
296 | epv->_get_isContinuous = impl_Bonobo_Zoomable__get_isContinuous; |
---|
297 | epv->_get_preferredLevels = impl_Bonobo_Zoomable__get_preferredLevels; |
---|
298 | epv->_get_preferredLevelNames = impl_Bonobo_Zoomable__get_preferredLevelNames; |
---|
299 | |
---|
300 | epv->zoomIn = impl_Bonobo_Zoomable_zoomIn; |
---|
301 | epv->zoomOut = impl_Bonobo_Zoomable_zoomOut; |
---|
302 | epv->zoomFit = impl_Bonobo_Zoomable_zoomFit; |
---|
303 | epv->zoomDefault = impl_Bonobo_Zoomable_zoomDefault; |
---|
304 | |
---|
305 | epv->setLevel = impl_Bonobo_Zoomable_setLevel; |
---|
306 | epv->setFrame = impl_Bonobo_Zoomable_setFrame; |
---|
307 | |
---|
308 | return epv; |
---|
309 | } |
---|
310 | |
---|
311 | static void |
---|
312 | init_zoomable_corba_class (void) |
---|
313 | { |
---|
314 | /* The VEPV */ |
---|
315 | bonobo_zoomable_vepv.Bonobo_Unknown_epv = bonobo_object_get_epv (); |
---|
316 | bonobo_zoomable_vepv.Bonobo_Zoomable_epv = bonobo_zoomable_get_epv (); |
---|
317 | } |
---|
318 | |
---|
319 | static void |
---|
320 | marshal_NONE__FLOAT (GtkObject *object, |
---|
321 | GtkSignalFunc func, |
---|
322 | gpointer func_data, |
---|
323 | GtkArg *args) |
---|
324 | { |
---|
325 | (* (void (*)(GtkObject *, float, gpointer)) func) |
---|
326 | (object, |
---|
327 | GTK_VALUE_FLOAT (args[0]), |
---|
328 | func_data); |
---|
329 | } |
---|
330 | |
---|
331 | static void |
---|
332 | bonobo_zoomable_get_arg (GtkObject* obj, GtkArg* arg, guint arg_id) |
---|
333 | { |
---|
334 | BonoboZoomable *zoomable = BONOBO_ZOOMABLE (obj); |
---|
335 | BonoboZoomablePrivate *priv = zoomable->priv; |
---|
336 | |
---|
337 | switch (arg_id) { |
---|
338 | case ARG_ZOOM_LEVEL: |
---|
339 | GTK_VALUE_FLOAT(*arg) = priv->zoom_level; |
---|
340 | break; |
---|
341 | case ARG_MIN_ZOOM_LEVEL: |
---|
342 | GTK_VALUE_FLOAT(*arg) = priv->min_zoom_level; |
---|
343 | break; |
---|
344 | case ARG_MAX_ZOOM_LEVEL: |
---|
345 | GTK_VALUE_FLOAT(*arg) = priv->max_zoom_level; |
---|
346 | break; |
---|
347 | case ARG_HAS_MIN_ZOOM_LEVEL: |
---|
348 | GTK_VALUE_BOOL(*arg) = priv->has_min_zoom_level; |
---|
349 | break; |
---|
350 | case ARG_HAS_MAX_ZOOM_LEVEL: |
---|
351 | GTK_VALUE_BOOL(*arg) = priv->has_max_zoom_level; |
---|
352 | break; |
---|
353 | case ARG_IS_CONTINUOUS: |
---|
354 | GTK_VALUE_BOOL(*arg) = priv->is_continuous; |
---|
355 | break; |
---|
356 | default: |
---|
357 | g_message ("Unknown arg_id `%d'", arg_id); |
---|
358 | break; |
---|
359 | }; |
---|
360 | } |
---|
361 | |
---|
362 | static void |
---|
363 | bonobo_zoomable_free_preferred_zoom_level_arrays (BonoboZoomable *zoomable) |
---|
364 | { |
---|
365 | int i; |
---|
366 | gchar **zoom_level_names; |
---|
367 | |
---|
368 | zoom_level_names = (gchar **) zoomable->priv->preferred_zoom_level_names->data; |
---|
369 | |
---|
370 | for (i = 0; i < zoomable->priv->preferred_zoom_level_names->len; ++i) { |
---|
371 | g_free (zoom_level_names [i]); |
---|
372 | } |
---|
373 | |
---|
374 | g_array_free (zoomable->priv->preferred_zoom_level_names, TRUE); |
---|
375 | zoomable->priv->preferred_zoom_level_names = NULL; |
---|
376 | |
---|
377 | g_array_free (zoomable->priv->preferred_zoom_levels, TRUE); |
---|
378 | zoomable->priv->preferred_zoom_levels = NULL; |
---|
379 | } |
---|
380 | |
---|
381 | static void |
---|
382 | bonobo_zoomable_destroy (GtkObject *object) |
---|
383 | { |
---|
384 | BonoboZoomable *zoomable; |
---|
385 | |
---|
386 | g_return_if_fail (BONOBO_IS_ZOOMABLE (object)); |
---|
387 | |
---|
388 | zoomable = BONOBO_ZOOMABLE (object); |
---|
389 | |
---|
390 | bonobo_zoomable_free_preferred_zoom_level_arrays (zoomable); |
---|
391 | |
---|
392 | GTK_OBJECT_CLASS (bonobo_zoomable_parent_class)->destroy (object); |
---|
393 | } |
---|
394 | |
---|
395 | static void |
---|
396 | bonobo_zoomable_finalize (GtkObject *object) |
---|
397 | { |
---|
398 | BonoboZoomable *zoomable; |
---|
399 | |
---|
400 | g_return_if_fail (BONOBO_IS_ZOOMABLE (object)); |
---|
401 | |
---|
402 | zoomable = BONOBO_ZOOMABLE (object); |
---|
403 | |
---|
404 | g_free (zoomable->priv); |
---|
405 | zoomable->priv = NULL; |
---|
406 | |
---|
407 | GTK_OBJECT_CLASS (bonobo_zoomable_parent_class)->finalize (object); |
---|
408 | } |
---|
409 | |
---|
410 | static void |
---|
411 | bonobo_zoomable_class_init (BonoboZoomableClass *klass) |
---|
412 | { |
---|
413 | GtkObjectClass *object_class; |
---|
414 | |
---|
415 | object_class = (GtkObjectClass*) klass; |
---|
416 | |
---|
417 | bonobo_zoomable_parent_class = gtk_type_class (bonobo_object_get_type ()); |
---|
418 | bonobo_zoomable_class = klass; |
---|
419 | |
---|
420 | gtk_object_add_arg_type("BonoboZoomable::zoom_level", |
---|
421 | GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_ZOOM_LEVEL); |
---|
422 | gtk_object_add_arg_type("BonoboZoomable::min_zoom_level", |
---|
423 | GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_MIN_ZOOM_LEVEL); |
---|
424 | gtk_object_add_arg_type("BonoboZoomable::max_zoom_level", |
---|
425 | GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_MAX_ZOOM_LEVEL); |
---|
426 | gtk_object_add_arg_type("BonoboZoomable::has_min_zoom_level", |
---|
427 | GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_HAS_MIN_ZOOM_LEVEL); |
---|
428 | gtk_object_add_arg_type("BonoboZoomable::has_max_zoom_level", |
---|
429 | GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_HAS_MAX_ZOOM_LEVEL); |
---|
430 | gtk_object_add_arg_type("BonoboZoomable::is_continuous", |
---|
431 | GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_IS_CONTINUOUS); |
---|
432 | |
---|
433 | signals[SET_FRAME] = |
---|
434 | gtk_signal_new ("set_frame", |
---|
435 | GTK_RUN_LAST, |
---|
436 | object_class->type, |
---|
437 | GTK_SIGNAL_OFFSET (BonoboZoomableClass, set_frame), |
---|
438 | gtk_marshal_NONE__NONE, |
---|
439 | GTK_TYPE_NONE, 0); |
---|
440 | signals[SET_ZOOM_LEVEL] = |
---|
441 | gtk_signal_new ("set_zoom_level", |
---|
442 | GTK_RUN_LAST, |
---|
443 | object_class->type, |
---|
444 | GTK_SIGNAL_OFFSET (BonoboZoomableClass, set_zoom_level), |
---|
445 | marshal_NONE__FLOAT, |
---|
446 | GTK_TYPE_NONE, 1, GTK_TYPE_FLOAT); |
---|
447 | signals[ZOOM_IN] = |
---|
448 | gtk_signal_new ("zoom_in", |
---|
449 | GTK_RUN_LAST, |
---|
450 | object_class->type, |
---|
451 | GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_in), |
---|
452 | gtk_marshal_NONE__NONE, |
---|
453 | GTK_TYPE_NONE, 0); |
---|
454 | signals[ZOOM_OUT] = |
---|
455 | gtk_signal_new ("zoom_out", |
---|
456 | GTK_RUN_LAST, |
---|
457 | object_class->type, |
---|
458 | GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_out), |
---|
459 | gtk_marshal_NONE__NONE, |
---|
460 | GTK_TYPE_NONE, 0); |
---|
461 | signals[ZOOM_TO_FIT] = |
---|
462 | gtk_signal_new ("zoom_to_fit", |
---|
463 | GTK_RUN_LAST, |
---|
464 | object_class->type, |
---|
465 | GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_to_fit), |
---|
466 | gtk_marshal_NONE__NONE, |
---|
467 | GTK_TYPE_NONE, 0); |
---|
468 | signals[ZOOM_TO_DEFAULT] = |
---|
469 | gtk_signal_new ("zoom_to_default", |
---|
470 | GTK_RUN_LAST, |
---|
471 | object_class->type, |
---|
472 | GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_to_default), |
---|
473 | gtk_marshal_NONE__NONE, |
---|
474 | GTK_TYPE_NONE, 0); |
---|
475 | |
---|
476 | gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); |
---|
477 | |
---|
478 | object_class->get_arg = bonobo_zoomable_get_arg; |
---|
479 | |
---|
480 | object_class->destroy = bonobo_zoomable_destroy; |
---|
481 | object_class->finalize = bonobo_zoomable_finalize; |
---|
482 | |
---|
483 | init_zoomable_corba_class (); |
---|
484 | } |
---|
485 | |
---|
486 | static void |
---|
487 | bonobo_zoomable_init (BonoboZoomable *zoomable) |
---|
488 | { |
---|
489 | zoomable->priv = g_new0 (BonoboZoomablePrivate, 1); |
---|
490 | |
---|
491 | zoomable->priv->zoom_level = 0.0; |
---|
492 | zoomable->priv->min_zoom_level = 0.0; |
---|
493 | zoomable->priv->max_zoom_level = 0.0; |
---|
494 | zoomable->priv->has_min_zoom_level = FALSE; |
---|
495 | zoomable->priv->has_max_zoom_level = FALSE; |
---|
496 | zoomable->priv->is_continuous = TRUE; |
---|
497 | zoomable->priv->preferred_zoom_levels = g_array_new (FALSE, TRUE, sizeof (float)); |
---|
498 | zoomable->priv->preferred_zoom_level_names = g_array_new (FALSE, TRUE, sizeof (gchar *)); |
---|
499 | } |
---|
500 | |
---|
501 | /** |
---|
502 | * bonobo_zoomable_get_type: |
---|
503 | * |
---|
504 | * Returns: the GtkType for a BonoboZoomable object. |
---|
505 | */ |
---|
506 | GtkType |
---|
507 | bonobo_zoomable_get_type (void) |
---|
508 | { |
---|
509 | static GtkType type = 0; |
---|
510 | |
---|
511 | if (!type) { |
---|
512 | GtkTypeInfo info = { |
---|
513 | "BonoboZoomable", |
---|
514 | sizeof (BonoboZoomable), |
---|
515 | sizeof (BonoboZoomableClass), |
---|
516 | (GtkClassInitFunc) bonobo_zoomable_class_init, |
---|
517 | (GtkObjectInitFunc) bonobo_zoomable_init, |
---|
518 | NULL, /* reserved 1 */ |
---|
519 | NULL, /* reserved 2 */ |
---|
520 | (GtkClassInitFunc) NULL |
---|
521 | }; |
---|
522 | |
---|
523 | type = gtk_type_unique (bonobo_object_get_type (), &info); |
---|
524 | } |
---|
525 | |
---|
526 | return type; |
---|
527 | } |
---|
528 | |
---|
529 | Bonobo_Zoomable |
---|
530 | bonobo_zoomable_corba_object_create (BonoboObject *object) |
---|
531 | { |
---|
532 | POA_Bonobo_Zoomable *servant; |
---|
533 | CORBA_Environment ev; |
---|
534 | |
---|
535 | servant = (POA_Bonobo_Zoomable *) g_new0 (BonoboObjectServant, 1); |
---|
536 | servant->vepv = &bonobo_zoomable_vepv; |
---|
537 | |
---|
538 | CORBA_exception_init (&ev); |
---|
539 | |
---|
540 | POA_Bonobo_Zoomable__init ((PortableServer_Servant) servant, &ev); |
---|
541 | if (BONOBO_EX (&ev)){ |
---|
542 | g_free (servant); |
---|
543 | CORBA_exception_free (&ev); |
---|
544 | return CORBA_OBJECT_NIL; |
---|
545 | } |
---|
546 | |
---|
547 | CORBA_exception_free (&ev); |
---|
548 | return (Bonobo_Zoomable) bonobo_object_activate_servant (object, servant); |
---|
549 | } |
---|
550 | |
---|
551 | /** |
---|
552 | * bonobo_zoomable_set_parameters_full: |
---|
553 | * |
---|
554 | * This is used by the component to set new zooming parameters (and to set the |
---|
555 | * initial zooming parameters including the initial zoom level after creating |
---|
556 | * the BonoboZoomable) - for instance after loading a new file. |
---|
557 | * |
---|
558 | * If any of the zoom parameters such as the minimum or maximum zoom level has |
---|
559 | * changed, it is likely that the zoom level has become invalid as well - at |
---|
560 | * least, the container must query it in any case, so we set it here. |
---|
561 | * |
---|
562 | * Return value: |
---|
563 | **/ |
---|
564 | void |
---|
565 | bonobo_zoomable_set_parameters_full (BonoboZoomable *zoomable, |
---|
566 | float zoom_level, |
---|
567 | float min_zoom_level, |
---|
568 | float max_zoom_level, |
---|
569 | gboolean has_min_zoom_level, |
---|
570 | gboolean has_max_zoom_level, |
---|
571 | gboolean is_continuous, |
---|
572 | float *preferred_zoom_levels, |
---|
573 | const gchar **preferred_zoom_level_names, |
---|
574 | gint num_preferred_zoom_levels) |
---|
575 | { |
---|
576 | int i; |
---|
577 | gchar **zoom_level_names; |
---|
578 | BonoboZoomable *p = zoomable; |
---|
579 | |
---|
580 | g_return_if_fail (BONOBO_IS_ZOOMABLE (p)); |
---|
581 | |
---|
582 | p->priv->zoom_level = zoom_level; |
---|
583 | p->priv->min_zoom_level = min_zoom_level; |
---|
584 | p->priv->max_zoom_level = max_zoom_level; |
---|
585 | p->priv->has_min_zoom_level = has_min_zoom_level; |
---|
586 | p->priv->has_max_zoom_level = has_max_zoom_level; |
---|
587 | p->priv->is_continuous = is_continuous; |
---|
588 | |
---|
589 | bonobo_zoomable_free_preferred_zoom_level_arrays (p); |
---|
590 | |
---|
591 | p->priv->preferred_zoom_levels = g_array_new (FALSE, TRUE, sizeof (float)); |
---|
592 | |
---|
593 | if (preferred_zoom_levels) { |
---|
594 | g_array_append_vals (p->priv->preferred_zoom_levels, |
---|
595 | preferred_zoom_levels, |
---|
596 | num_preferred_zoom_levels); |
---|
597 | } |
---|
598 | |
---|
599 | p->priv->preferred_zoom_level_names = g_array_new (FALSE, TRUE, sizeof (gchar *)); |
---|
600 | |
---|
601 | if (preferred_zoom_level_names) { |
---|
602 | g_array_set_size (p->priv->preferred_zoom_levels, num_preferred_zoom_levels); |
---|
603 | zoom_level_names = (gchar **) p->priv->preferred_zoom_level_names->data; |
---|
604 | for (i = 0; i < p->priv->preferred_zoom_level_names->len; ++i) { |
---|
605 | zoom_level_names [i] = g_strdup (preferred_zoom_level_names [i]); |
---|
606 | } |
---|
607 | } |
---|
608 | } |
---|
609 | |
---|
610 | /** |
---|
611 | * bonobo_zoomable_set_parameters: |
---|
612 | * |
---|
613 | * This is a simple version of @bonobo_zoomable_set_parameters_full() for components |
---|
614 | * which support continuous zooming. It does not override any of the parameters |
---|
615 | * which can only be set by the _full version. |
---|
616 | * |
---|
617 | * Return value: |
---|
618 | **/ |
---|
619 | void |
---|
620 | bonobo_zoomable_set_parameters (BonoboZoomable *zoomable, |
---|
621 | float zoom_level, |
---|
622 | float min_zoom_level, |
---|
623 | float max_zoom_level, |
---|
624 | gboolean has_min_zoom_level, |
---|
625 | gboolean has_max_zoom_level) |
---|
626 | { |
---|
627 | BonoboZoomable *p = zoomable; |
---|
628 | |
---|
629 | g_return_if_fail (BONOBO_IS_ZOOMABLE (p)); |
---|
630 | |
---|
631 | p->priv->zoom_level = zoom_level; |
---|
632 | p->priv->min_zoom_level = min_zoom_level; |
---|
633 | p->priv->max_zoom_level = max_zoom_level; |
---|
634 | p->priv->has_min_zoom_level = has_min_zoom_level; |
---|
635 | p->priv->has_max_zoom_level = has_max_zoom_level; |
---|
636 | } |
---|
637 | |
---|
638 | /** |
---|
639 | * bonobo_zoomable_add_preferred_zoom_level: |
---|
640 | * @zoomable: the zoomable |
---|
641 | * @zoom_level: the new level |
---|
642 | * @zoom_level_name: the new level's name |
---|
643 | * |
---|
644 | * This appends a new zoom level's name and value to the |
---|
645 | * internal list of these. |
---|
646 | **/ |
---|
647 | void |
---|
648 | bonobo_zoomable_add_preferred_zoom_level (BonoboZoomable *zoomable, |
---|
649 | float zoom_level, |
---|
650 | const gchar *zoom_level_name) |
---|
651 | { |
---|
652 | gchar *name; |
---|
653 | CORBA_float level; |
---|
654 | |
---|
655 | /* convert zoom_level to a CORBA_float */ |
---|
656 | level = zoom_level; |
---|
657 | g_array_append_val (zoomable->priv->preferred_zoom_levels, level); |
---|
658 | |
---|
659 | name = g_strdup (zoom_level_name); |
---|
660 | g_array_append_val (zoomable->priv->preferred_zoom_level_names, name); |
---|
661 | } |
---|
662 | |
---|
663 | /** |
---|
664 | * bonobo_zoomable_construct: |
---|
665 | * @zoomable: the zoomable |
---|
666 | * @corba_p: the corba object reference. |
---|
667 | * |
---|
668 | * Construct a newly created BonoboZoomable pointed to |
---|
669 | * by @zoomable, and associate it with @corba_p |
---|
670 | * |
---|
671 | * Return value: a newly constructed zoomable or NULL on error |
---|
672 | **/ |
---|
673 | BonoboZoomable * |
---|
674 | bonobo_zoomable_construct (BonoboZoomable *zoomable, |
---|
675 | Bonobo_Zoomable corba_p) |
---|
676 | { |
---|
677 | BonoboZoomable *p = zoomable; |
---|
678 | |
---|
679 | g_return_val_if_fail (p != NULL, NULL); |
---|
680 | g_return_val_if_fail (BONOBO_IS_ZOOMABLE (p), NULL); |
---|
681 | g_return_val_if_fail (corba_p != NULL, NULL); |
---|
682 | |
---|
683 | bonobo_object_construct (BONOBO_OBJECT (p), corba_p); |
---|
684 | |
---|
685 | return p; |
---|
686 | } |
---|
687 | |
---|
688 | /** |
---|
689 | * bonobo_zoomable_new: |
---|
690 | * |
---|
691 | * Create a new bonobo-zoomable implementing BonoboObject |
---|
692 | * interface. |
---|
693 | * |
---|
694 | * Return value: |
---|
695 | **/ |
---|
696 | BonoboZoomable * |
---|
697 | bonobo_zoomable_new (void) |
---|
698 | { |
---|
699 | BonoboZoomable *p; |
---|
700 | Bonobo_Zoomable corba_p; |
---|
701 | |
---|
702 | p = gtk_type_new (bonobo_zoomable_get_type ()); |
---|
703 | g_return_val_if_fail (p != NULL, NULL); |
---|
704 | |
---|
705 | corba_p = bonobo_zoomable_corba_object_create (BONOBO_OBJECT (p)); |
---|
706 | if (corba_p == CORBA_OBJECT_NIL){ |
---|
707 | bonobo_object_unref (BONOBO_OBJECT (p)); |
---|
708 | return NULL; |
---|
709 | } |
---|
710 | |
---|
711 | return bonobo_zoomable_construct (p, corba_p); |
---|
712 | } |
---|
713 | |
---|
714 | /** |
---|
715 | * bonobo_zoomable_report_zoom_level_changed: |
---|
716 | * |
---|
717 | * @new_zoom_level: The new zoom level. |
---|
718 | * |
---|
719 | * Reports the BonoboZoomableFrame that the zoom level has changed (but the |
---|
720 | * other zoom parameters are still the same). |
---|
721 | * |
---|
722 | * This is called after the component has successfully completed a zooming |
---|
723 | * operation - the @new_zoom_level may have been modified from what the |
---|
724 | * container requested to match what the component actually displays at the |
---|
725 | * moment. |
---|
726 | * |
---|
727 | * Return value: |
---|
728 | **/ |
---|
729 | void |
---|
730 | bonobo_zoomable_report_zoom_level_changed (BonoboZoomable *zoomable, |
---|
731 | float new_zoom_level) |
---|
732 | { |
---|
733 | CORBA_Environment ev; |
---|
734 | |
---|
735 | g_return_if_fail (BONOBO_IS_ZOOMABLE (zoomable)); |
---|
736 | |
---|
737 | zoomable->priv->zoom_level = new_zoom_level; |
---|
738 | |
---|
739 | if (zoomable->priv->zoomable_frame == CORBA_OBJECT_NIL) |
---|
740 | return; |
---|
741 | |
---|
742 | CORBA_exception_init (&ev); |
---|
743 | Bonobo_ZoomableFrame_onLevelChanged (zoomable->priv->zoomable_frame, |
---|
744 | zoomable->priv->zoom_level, |
---|
745 | &ev); |
---|
746 | CORBA_exception_free (&ev); |
---|
747 | } |
---|
748 | |
---|
749 | /** |
---|
750 | * bonobo_zoomable_report_zoom_parameters_changed: |
---|
751 | * |
---|
752 | * Reports the BonoboZoomableFrame that the zoom parameters have changed; |
---|
753 | * this also includes the zoom level. |
---|
754 | * |
---|
755 | * On the container side (the BonoboZoomableFrame) this implies that the |
---|
756 | * zoom level has changed as well, so you need to query the BonoboZoomable |
---|
757 | * for the new zoom level as well. |
---|
758 | * |
---|
759 | * Return value: |
---|
760 | **/ |
---|
761 | void |
---|
762 | bonobo_zoomable_report_zoom_parameters_changed (BonoboZoomable *zoomable) |
---|
763 | { |
---|
764 | CORBA_Environment ev; |
---|
765 | |
---|
766 | g_return_if_fail (BONOBO_IS_ZOOMABLE (zoomable)); |
---|
767 | |
---|
768 | if (zoomable->priv->zoomable_frame == CORBA_OBJECT_NIL) |
---|
769 | return; |
---|
770 | |
---|
771 | CORBA_exception_init (&ev); |
---|
772 | Bonobo_ZoomableFrame_onParametersChanged (zoomable->priv->zoomable_frame, |
---|
773 | &ev); |
---|
774 | CORBA_exception_free (&ev); |
---|
775 | } |
---|