File: bonobo-zoomable.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 (775 lines) | stat: -rw-r--r-- 21,961 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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 *  Bonobo::Zoomable - zoomable interface for Controls.
 *
 *  Copyright (C) 2000 Eazel, Inc.
 *                2000 SuSE GmbH.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Authors: Maciej Stachowiak <mjs@eazel.com>
 *           Martin Baulig <baulig@suse.de>
 *
 */

#include <config.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-zoomable.h>
#include <bonobo/bonobo-property-bag.h>
#include <gtk/gtksignal.h>

#undef ZOOMABLE_DEBUG

static BonoboObjectClass   *bonobo_zoomable_parent_class;
static BonoboZoomableClass *bonobo_zoomable_class;

struct _BonoboZoomablePrivate {
	CORBA_float		 zoom_level;

	CORBA_float		 min_zoom_level;
	CORBA_float		 max_zoom_level;
	CORBA_boolean		 has_min_zoom_level;
	CORBA_boolean		 has_max_zoom_level;
	CORBA_boolean		 is_continuous;

	GArray                  *preferred_zoom_levels;
	GArray                  *preferred_zoom_level_names;

	Bonobo_ZoomableFrame	 zoomable_frame;
};

enum {
	SET_FRAME,
	SET_ZOOM_LEVEL,
	ZOOM_IN,
	ZOOM_OUT,
	ZOOM_TO_FIT,
	ZOOM_TO_DEFAULT,
	LAST_SIGNAL
};

enum {
	ARG_0,
	ARG_ZOOM_LEVEL,
	ARG_MIN_ZOOM_LEVEL,
	ARG_MAX_ZOOM_LEVEL,
	ARG_HAS_MIN_ZOOM_LEVEL,
	ARG_HAS_MAX_ZOOM_LEVEL,
	ARG_IS_CONTINUOUS
};

static guint signals[LAST_SIGNAL];

typedef struct {
	POA_Bonobo_Zoomable	servant;
	
	BonoboZoomable		*gtk_object;
} impl_POA_Bonobo_Zoomable;

POA_Bonobo_Zoomable__vepv bonobo_zoomable_vepv;

#define CLASS(o) BONOBO_ZOOMABLE_CLASS(GTK_OBJECT(o)->klass)

static inline BonoboZoomable *
bonobo_zoomable_from_servant (PortableServer_Servant servant)
{
	if (!BONOBO_IS_ZOOMABLE (bonobo_object_from_servant (servant)))
		return NULL;
	else
		return BONOBO_ZOOMABLE (bonobo_object_from_servant (servant));
}

static CORBA_float
impl_Bonobo_Zoomable__get_level (PortableServer_Servant  servant,
				 CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	return zoomable->priv->zoom_level;
}

static CORBA_float
impl_Bonobo_Zoomable__get_minLevel (PortableServer_Servant  servant,
				    CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	return zoomable->priv->min_zoom_level;
}

static CORBA_float
impl_Bonobo_Zoomable__get_maxLevel (PortableServer_Servant  servant,
				    CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	return zoomable->priv->max_zoom_level;
}

static CORBA_boolean
impl_Bonobo_Zoomable__get_hasMinLevel (PortableServer_Servant  servant,
				       CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	return zoomable->priv->has_min_zoom_level;
}

static CORBA_boolean
impl_Bonobo_Zoomable__get_hasMaxLevel (PortableServer_Servant  servant,
				       CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	return zoomable->priv->has_max_zoom_level;
}

static CORBA_boolean
impl_Bonobo_Zoomable__get_isContinuous (PortableServer_Servant  servant,
					CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	return zoomable->priv->is_continuous;
}

static Bonobo_ZoomLevelList *
impl_Bonobo_Zoomable__get_preferredLevels (PortableServer_Servant  servant,
					   CORBA_Environment      *ev)
{
	Bonobo_ZoomLevelList *list;
	BonoboZoomable *zoomable;
	float *zoom_levels;
	int num_zoom_levels;
	int i;

	zoomable = bonobo_zoomable_from_servant (servant);

	num_zoom_levels = zoomable->priv->preferred_zoom_levels->len;
	zoom_levels = (float *) zoomable->priv->preferred_zoom_levels->data;

	list = Bonobo_ZoomLevelList__alloc ();
	list->_maximum = zoomable->priv->preferred_zoom_levels->len;
	list->_length  = zoomable->priv->preferred_zoom_levels->len;
	list->_buffer  = CORBA_sequence_Bonobo_ZoomLevel_allocbuf (num_zoom_levels);

	for (i = 0; i < num_zoom_levels; ++i) {
		/* assigned one at a time to convert float to CORBA_float */
		list->_buffer [i] = zoom_levels [i];
	}
	
	CORBA_sequence_set_release (list, CORBA_TRUE);

	return list;
}

static Bonobo_ZoomLevelNameList *
impl_Bonobo_Zoomable__get_preferredLevelNames (PortableServer_Servant  servant,
					       CORBA_Environment      *ev)
{
	Bonobo_ZoomLevelNameList *list;
	BonoboZoomable *zoomable;
	gchar **zoom_level_names;
	int num_zoom_level_names;
	int i;

	zoomable = bonobo_zoomable_from_servant (servant);

	num_zoom_level_names = zoomable->priv->preferred_zoom_level_names->len;
	zoom_level_names = (gchar **) zoomable->priv->preferred_zoom_level_names->data;

	list = Bonobo_ZoomLevelNameList__alloc ();
	list->_maximum = zoomable->priv->preferred_zoom_level_names->len;
	list->_length  = zoomable->priv->preferred_zoom_level_names->len;
	list->_buffer  = CORBA_sequence_Bonobo_ZoomLevelName_allocbuf (num_zoom_level_names);

	for (i = 0; i < num_zoom_level_names; ++i) {
		list->_buffer [i] = CORBA_string_dup (zoom_level_names [i]);
	}

	CORBA_sequence_set_release (list, CORBA_TRUE);

	return list;
}

static void 
impl_Bonobo_Zoomable_setLevel (PortableServer_Servant  servant,
			       const CORBA_float       zoom_level,
			       CORBA_Environment      *ev)
{
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	gtk_signal_emit (GTK_OBJECT (zoomable), signals[SET_ZOOM_LEVEL], zoom_level);
}

static void
impl_Bonobo_Zoomable_zoomIn (PortableServer_Servant  servant,
			     CORBA_Environment      *ev)
{	
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_IN]);
}

static void
impl_Bonobo_Zoomable_zoomOut (PortableServer_Servant  servant,
			      CORBA_Environment      *ev)
{	
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_OUT]);
}

static void
impl_Bonobo_Zoomable_zoomFit (PortableServer_Servant  servant,
			      CORBA_Environment      *ev)
{	
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_TO_FIT]);
}

static void
impl_Bonobo_Zoomable_zoomDefault (PortableServer_Servant  servant,
				  CORBA_Environment      *ev)
{	
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);
	gtk_signal_emit (GTK_OBJECT (zoomable), signals[ZOOM_TO_DEFAULT]);
}

static void
impl_Bonobo_Zoomable_setFrame (PortableServer_Servant  servant,
			       Bonobo_ZoomableFrame    zoomable_frame,
			       CORBA_Environment      *ev)
{	
	BonoboZoomable *zoomable;

	zoomable = bonobo_zoomable_from_servant (servant);

	g_assert (zoomable->priv->zoomable_frame == CORBA_OBJECT_NIL);
	zoomable->priv->zoomable_frame = CORBA_Object_duplicate (zoomable_frame, ev);
	gtk_signal_emit (GTK_OBJECT (zoomable), signals[SET_FRAME]);
}


/**
 * bonobo_zoomable_get_epv:
 *
 * Returns: The EPV for the default BonoboZoomable implementation.  
 */
POA_Bonobo_Zoomable__epv *
bonobo_zoomable_get_epv (void)
{
	POA_Bonobo_Zoomable__epv *epv;

	epv = g_new0 (POA_Bonobo_Zoomable__epv, 1);

	epv->_get_level = impl_Bonobo_Zoomable__get_level;
	epv->_get_minLevel = impl_Bonobo_Zoomable__get_minLevel;
	epv->_get_maxLevel = impl_Bonobo_Zoomable__get_maxLevel;
	epv->_get_hasMinLevel = impl_Bonobo_Zoomable__get_hasMinLevel;
	epv->_get_hasMaxLevel = impl_Bonobo_Zoomable__get_hasMaxLevel;
	epv->_get_isContinuous = impl_Bonobo_Zoomable__get_isContinuous;
	epv->_get_preferredLevels = impl_Bonobo_Zoomable__get_preferredLevels;
	epv->_get_preferredLevelNames = impl_Bonobo_Zoomable__get_preferredLevelNames;

	epv->zoomIn      = impl_Bonobo_Zoomable_zoomIn;
	epv->zoomOut     = impl_Bonobo_Zoomable_zoomOut;
	epv->zoomFit     = impl_Bonobo_Zoomable_zoomFit;
	epv->zoomDefault = impl_Bonobo_Zoomable_zoomDefault;

	epv->setLevel = impl_Bonobo_Zoomable_setLevel;
	epv->setFrame = impl_Bonobo_Zoomable_setFrame;
	
	return epv;
}

static void
init_zoomable_corba_class (void)
{
	/* The VEPV */
	bonobo_zoomable_vepv.Bonobo_Unknown_epv  = bonobo_object_get_epv ();
	bonobo_zoomable_vepv.Bonobo_Zoomable_epv = bonobo_zoomable_get_epv ();
}

static void
marshal_NONE__FLOAT (GtkObject *object,
		      GtkSignalFunc func,
		      gpointer func_data,
		      GtkArg *args)
{
	(* (void (*)(GtkObject *, float, gpointer)) func)
		(object,
		 GTK_VALUE_FLOAT (args[0]),
		 func_data);
}

static void
bonobo_zoomable_get_arg (GtkObject* obj, GtkArg* arg, guint arg_id)
{
	BonoboZoomable *zoomable = BONOBO_ZOOMABLE (obj);
	BonoboZoomablePrivate *priv = zoomable->priv;

	switch (arg_id) {
	case ARG_ZOOM_LEVEL:
		GTK_VALUE_FLOAT(*arg) = priv->zoom_level;
		break;
	case ARG_MIN_ZOOM_LEVEL:
		GTK_VALUE_FLOAT(*arg) = priv->min_zoom_level;
		break;
	case ARG_MAX_ZOOM_LEVEL:
		GTK_VALUE_FLOAT(*arg) = priv->max_zoom_level;
		break;
	case ARG_HAS_MIN_ZOOM_LEVEL:
		GTK_VALUE_BOOL(*arg) = priv->has_min_zoom_level;
		break;
	case ARG_HAS_MAX_ZOOM_LEVEL:
		GTK_VALUE_BOOL(*arg) = priv->has_max_zoom_level;
		break;
	case ARG_IS_CONTINUOUS:
		GTK_VALUE_BOOL(*arg) = priv->is_continuous;
		break;
	default:
		g_message ("Unknown arg_id `%d'", arg_id);
		break;
	};
}

static void
bonobo_zoomable_free_preferred_zoom_level_arrays (BonoboZoomable *zoomable)
{
	int i;
	gchar **zoom_level_names;

	zoom_level_names = (gchar **) zoomable->priv->preferred_zoom_level_names->data;

	for (i = 0; i < zoomable->priv->preferred_zoom_level_names->len; ++i) {
		g_free (zoom_level_names [i]);
	}
	
	g_array_free (zoomable->priv->preferred_zoom_level_names, TRUE);
	zoomable->priv->preferred_zoom_level_names = NULL;

	g_array_free (zoomable->priv->preferred_zoom_levels, TRUE);
	zoomable->priv->preferred_zoom_levels = NULL;
}

static void
bonobo_zoomable_destroy (GtkObject *object)
{
	BonoboZoomable *zoomable;

	g_return_if_fail (BONOBO_IS_ZOOMABLE (object));

	zoomable = BONOBO_ZOOMABLE (object);

	bonobo_zoomable_free_preferred_zoom_level_arrays (zoomable);

	GTK_OBJECT_CLASS (bonobo_zoomable_parent_class)->destroy (object);
}

static void
bonobo_zoomable_finalize (GtkObject *object)
{
	BonoboZoomable *zoomable;

	g_return_if_fail (BONOBO_IS_ZOOMABLE (object));

	zoomable = BONOBO_ZOOMABLE (object);

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

	GTK_OBJECT_CLASS (bonobo_zoomable_parent_class)->finalize (object);
}

static void
bonobo_zoomable_class_init (BonoboZoomableClass *klass)
{
	GtkObjectClass *object_class;
	
	object_class = (GtkObjectClass*) klass;
	
	bonobo_zoomable_parent_class = gtk_type_class (bonobo_object_get_type ());
	bonobo_zoomable_class = klass;

	gtk_object_add_arg_type("BonoboZoomable::zoom_level",
				GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_ZOOM_LEVEL);
	gtk_object_add_arg_type("BonoboZoomable::min_zoom_level",
				GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_MIN_ZOOM_LEVEL);
	gtk_object_add_arg_type("BonoboZoomable::max_zoom_level",
				GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_MAX_ZOOM_LEVEL);
	gtk_object_add_arg_type("BonoboZoomable::has_min_zoom_level",
				GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_HAS_MIN_ZOOM_LEVEL);
	gtk_object_add_arg_type("BonoboZoomable::has_max_zoom_level",
				GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_HAS_MAX_ZOOM_LEVEL);
	gtk_object_add_arg_type("BonoboZoomable::is_continuous",
				GTK_TYPE_FLOAT, GTK_ARG_READABLE, ARG_IS_CONTINUOUS);

	signals[SET_FRAME] =
		gtk_signal_new ("set_frame",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (BonoboZoomableClass, set_frame),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	signals[SET_ZOOM_LEVEL] =
		gtk_signal_new ("set_zoom_level",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (BonoboZoomableClass, set_zoom_level),
				marshal_NONE__FLOAT,
				GTK_TYPE_NONE, 1, GTK_TYPE_FLOAT);
	signals[ZOOM_IN] = 
		gtk_signal_new ("zoom_in",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_in),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	signals[ZOOM_OUT] = 
		gtk_signal_new ("zoom_out",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_out),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	signals[ZOOM_TO_FIT] = 
		gtk_signal_new ("zoom_to_fit",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_to_fit),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);
	signals[ZOOM_TO_DEFAULT] = 
		gtk_signal_new ("zoom_to_default",
				GTK_RUN_LAST,
				object_class->type,
				GTK_SIGNAL_OFFSET (BonoboZoomableClass, zoom_to_default),
				gtk_marshal_NONE__NONE,
				GTK_TYPE_NONE, 0);

	gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);

	object_class->get_arg = bonobo_zoomable_get_arg;

	object_class->destroy = bonobo_zoomable_destroy;
	object_class->finalize = bonobo_zoomable_finalize;

	init_zoomable_corba_class ();
}

static void
bonobo_zoomable_init (BonoboZoomable *zoomable)
{
	zoomable->priv = g_new0 (BonoboZoomablePrivate, 1);

	zoomable->priv->zoom_level = 0.0;
	zoomable->priv->min_zoom_level = 0.0;
	zoomable->priv->max_zoom_level = 0.0;
	zoomable->priv->has_min_zoom_level = FALSE;
	zoomable->priv->has_max_zoom_level = FALSE;
	zoomable->priv->is_continuous = TRUE;
	zoomable->priv->preferred_zoom_levels = g_array_new (FALSE, TRUE, sizeof (float));
	zoomable->priv->preferred_zoom_level_names = g_array_new (FALSE, TRUE, sizeof (gchar *));
}

/**
 * bonobo_zoomable_get_type:
 *
 * Returns: the GtkType for a BonoboZoomable object.
 */
GtkType
bonobo_zoomable_get_type (void)
{
	static GtkType type = 0;

	if (!type) {
		GtkTypeInfo info = {
			"BonoboZoomable",
			sizeof (BonoboZoomable),
			sizeof (BonoboZoomableClass),
			(GtkClassInitFunc) bonobo_zoomable_class_init,
			(GtkObjectInitFunc) bonobo_zoomable_init,
			NULL, /* reserved 1 */
			NULL, /* reserved 2 */
			(GtkClassInitFunc) NULL
		};

		type = gtk_type_unique (bonobo_object_get_type (), &info);
	}

	return type;
}

Bonobo_Zoomable
bonobo_zoomable_corba_object_create (BonoboObject *object)
{
	POA_Bonobo_Zoomable *servant;
	CORBA_Environment ev;

	servant = (POA_Bonobo_Zoomable *) g_new0 (BonoboObjectServant, 1);
	servant->vepv = &bonobo_zoomable_vepv;

	CORBA_exception_init (&ev);

	POA_Bonobo_Zoomable__init ((PortableServer_Servant) servant, &ev);
	if (BONOBO_EX (&ev)){
                g_free (servant);
		CORBA_exception_free (&ev);
                return CORBA_OBJECT_NIL;
        }

	CORBA_exception_free (&ev);
	return (Bonobo_Zoomable) bonobo_object_activate_servant (object, servant);
}

/**
 * bonobo_zoomable_set_parameters_full:
 * 
 * This is used by the component to set new zooming parameters (and to set the
 * initial zooming parameters including the initial zoom level after creating
 * the BonoboZoomable) - for instance after loading a new file.
 *
 * If any of the zoom parameters such as the minimum or maximum zoom level has
 * changed, it is likely that the zoom level has become invalid as well - at
 * least, the container must query it in any case, so we set it here.
 * 
 * Return value: 
 **/
void
bonobo_zoomable_set_parameters_full (BonoboZoomable  *zoomable,
				     float            zoom_level,
				     float            min_zoom_level,
				     float            max_zoom_level,
				     gboolean         has_min_zoom_level,
				     gboolean         has_max_zoom_level,
				     gboolean         is_continuous,
				     float           *preferred_zoom_levels,
				     const gchar    **preferred_zoom_level_names,
				     gint             num_preferred_zoom_levels)
{
	int i;
	gchar **zoom_level_names;
	BonoboZoomable *p = zoomable; 

	g_return_if_fail (BONOBO_IS_ZOOMABLE (p));

	p->priv->zoom_level = zoom_level;
	p->priv->min_zoom_level = min_zoom_level;
	p->priv->max_zoom_level = max_zoom_level;
	p->priv->has_min_zoom_level = has_min_zoom_level;
	p->priv->has_max_zoom_level = has_max_zoom_level;
	p->priv->is_continuous = is_continuous;

	bonobo_zoomable_free_preferred_zoom_level_arrays (p);
	
	p->priv->preferred_zoom_levels = g_array_new (FALSE, TRUE, sizeof (float));
	
	if (preferred_zoom_levels) {
		g_array_append_vals (p->priv->preferred_zoom_levels,
				     preferred_zoom_levels,
				     num_preferred_zoom_levels);
	}
	
	p->priv->preferred_zoom_level_names = g_array_new (FALSE, TRUE, sizeof (gchar *));
	
	if (preferred_zoom_level_names) {
		g_array_set_size (p->priv->preferred_zoom_levels, num_preferred_zoom_levels);
		zoom_level_names = (gchar **) p->priv->preferred_zoom_level_names->data;
		for (i = 0; i < p->priv->preferred_zoom_level_names->len; ++i) {
			zoom_level_names [i] = g_strdup (preferred_zoom_level_names [i]);
		}
	}
}

/**
 * bonobo_zoomable_set_parameters:
 * 
 * This is a simple version of @bonobo_zoomable_set_parameters_full() for components
 * which support continuous zooming. It does not override any of the parameters
 * which can only be set by the _full version.
 * 
 * Return value: 
 **/
void
bonobo_zoomable_set_parameters (BonoboZoomable  *zoomable,
                                float            zoom_level,
                                float            min_zoom_level,
                                float            max_zoom_level,
                                gboolean         has_min_zoom_level,
                                gboolean         has_max_zoom_level)
{
	BonoboZoomable *p = zoomable;

	g_return_if_fail (BONOBO_IS_ZOOMABLE (p));

	p->priv->zoom_level = zoom_level;
	p->priv->min_zoom_level = min_zoom_level;
	p->priv->max_zoom_level = max_zoom_level;
	p->priv->has_min_zoom_level = has_min_zoom_level;
	p->priv->has_max_zoom_level = has_max_zoom_level;
}

/**
 * bonobo_zoomable_add_preferred_zoom_level:
 * @zoomable: the zoomable
 * @zoom_level: the new level
 * @zoom_level_name: the new level's name
 * 
 * This appends a new zoom level's name and value to the
 * internal list of these.
 **/
void
bonobo_zoomable_add_preferred_zoom_level (BonoboZoomable *zoomable,
                                          float           zoom_level,
                                          const gchar    *zoom_level_name)
{
	gchar *name;
	CORBA_float level;
	
	/* convert zoom_level to a CORBA_float */
	level = zoom_level;
	g_array_append_val (zoomable->priv->preferred_zoom_levels, level);

	name = g_strdup (zoom_level_name);
	g_array_append_val (zoomable->priv->preferred_zoom_level_names, name);
}

/**
 * bonobo_zoomable_construct:
 * @zoomable: the zoomable
 * @corba_p: the corba object reference.
 * 
 * Construct a newly created BonoboZoomable pointed to
 * by @zoomable, and associate it with @corba_p
 * 
 * Return value: a newly constructed zoomable or NULL on error
 **/
BonoboZoomable *
bonobo_zoomable_construct (BonoboZoomable	*zoomable,
			   Bonobo_Zoomable	 corba_p)
{
	BonoboZoomable *p = zoomable;

	g_return_val_if_fail (p != NULL, NULL);
	g_return_val_if_fail (BONOBO_IS_ZOOMABLE (p), NULL);
	g_return_val_if_fail (corba_p != NULL, NULL);

	bonobo_object_construct (BONOBO_OBJECT (p), corba_p);

	return p;
}

/**
 * bonobo_zoomable_new:
 * 
 * Create a new bonobo-zoomable implementing BonoboObject
 * interface.
 * 
 * Return value: 
 **/
BonoboZoomable *
bonobo_zoomable_new (void)
{
	BonoboZoomable	*p;
	Bonobo_Zoomable	 corba_p;

	p = gtk_type_new (bonobo_zoomable_get_type ());
	g_return_val_if_fail (p != NULL, NULL);

	corba_p = bonobo_zoomable_corba_object_create (BONOBO_OBJECT (p));
	if (corba_p == CORBA_OBJECT_NIL){
		bonobo_object_unref (BONOBO_OBJECT (p));
		return NULL;
	}

	return bonobo_zoomable_construct (p, corba_p);
}

/**
 * bonobo_zoomable_report_zoom_level_changed:
 *
 * @new_zoom_level: The new zoom level.
 * 
 * Reports the BonoboZoomableFrame that the zoom level has changed (but the
 * other zoom parameters are still the same).
 *
 * This is called after the component has successfully completed a zooming
 * operation - the @new_zoom_level may have been modified from what the
 * container requested to match what the component actually displays at the
 * moment.
 * 
 * Return value: 
 **/
void
bonobo_zoomable_report_zoom_level_changed (BonoboZoomable *zoomable,
					   float           new_zoom_level)
{
	CORBA_Environment ev;

	g_return_if_fail (BONOBO_IS_ZOOMABLE (zoomable));

	zoomable->priv->zoom_level = new_zoom_level;

	if (zoomable->priv->zoomable_frame == CORBA_OBJECT_NIL)
		return;

	CORBA_exception_init (&ev);
	Bonobo_ZoomableFrame_onLevelChanged (zoomable->priv->zoomable_frame,
					     zoomable->priv->zoom_level,
					     &ev);
	CORBA_exception_free (&ev);
}

/**
 * bonobo_zoomable_report_zoom_parameters_changed:
 *
 * Reports the BonoboZoomableFrame that the zoom parameters have changed;
 * this also includes the zoom level.
 *
 * On the container side (the BonoboZoomableFrame) this implies that the
 * zoom level has changed as well, so you need to query the BonoboZoomable
 * for the new zoom level as well.
 * 
 * Return value: 
 **/
void
bonobo_zoomable_report_zoom_parameters_changed (BonoboZoomable *zoomable)
{
	CORBA_Environment ev;

	g_return_if_fail (BONOBO_IS_ZOOMABLE (zoomable));

	if (zoomable->priv->zoomable_frame == CORBA_OBJECT_NIL)
		return;

	CORBA_exception_init (&ev);
	Bonobo_ZoomableFrame_onParametersChanged (zoomable->priv->zoomable_frame,
							     &ev);
	CORBA_exception_free (&ev);
}