Re: BonoboZoomable - BonoboZoomLevel



Hi Michael,

just committed the _full() version; here's the final patch:

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/bonobo/ChangeLog,v
retrieving revision 1.656
diff -u -u -r1.656 ChangeLog
--- ChangeLog	2000/10/19 01:04:21	1.656
+++ ChangeLog	2000/10/19 08:59:48
@@ -1,3 +1,23 @@
+2000-10-19  Martin Baulig  <baulig suse de>
+
+	* idl/bonobo-zoomable.idl (ZoomLevelName, ZoomLevelNameList): New typedefs.
+	(Zoomable): Added `preferred_zoom_level_names' attribute.
+
+	* bonobo/bonobo-zoomable.h (bonobo_zoomable_set_parameters): Renamed to
+	bonobo_zoomable_set_parameters_full().
+	(bonobo_zoomable_set_parameters_full): Added `preferred_zoom_level_names'
+	argument.
+	(bonobo_zoomable_set_parameters): New function; this is a simplified
+	version of bonobo_zoomable_set_parameters_full().
+
+	* bonobo/bonobo-zoomable.c (bonobo_zoomable_destroy): New static function.
+	(bonobo_zoomable_finalize): New static function.
+
+	* bonobo/bonobo-zoomable-frame.h
+	(bonobo_zoomable_frame_get_preferred_zoom_levels): Changed return value
+	from `float *' to a GList of float's and remove the `pnum_ret' argument.
+	(bonobo_zoomable_frame_get_preferred_zoom_level_names): New function.
+
 2000-10-18  Eskil Heyn Olsen  <eskil eazel com>
 
 	* bonobo.spec.in:
Index: bonobo/bonobo-zoomable.h
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-zoomable.h,v
retrieving revision 1.5
diff -u -u -r1.5 bonobo-zoomable.h
--- bonobo/bonobo-zoomable.h	2000/10/12 22:57:12	1.5
+++ bonobo/bonobo-zoomable.h	2000/10/19 08:59:48
@@ -75,10 +75,18 @@
 								 float		 min_zoom_level,
 								 float		 max_zoom_level,
 								 gboolean	 has_min_zoom_level,
+								 gboolean	 has_max_zoom_level);
+
+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,
-								 int		 num_preferred_zoom_levels);
+								 float          *preferred_zoom_levels,
+								 const gchar   **preferred_zoom_level_names,
+								 gint		 num_preferred_zoom_levels);
 
 void		 bonobo_zoomable_report_zoom_level_changed	(BonoboZoomable	*zoomable,
 								 float		 new_zoom_level);
Index: bonobo/bonobo-zoomable.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-zoomable.c,v
retrieving revision 1.6
diff -u -u -r1.6 bonobo-zoomable.c
--- bonobo/bonobo-zoomable.c	2000/10/12 22:57:12	1.6
+++ bonobo/bonobo-zoomable.c	2000/10/19 08:59:48
@@ -44,6 +44,7 @@
 	CORBA_boolean		 is_continuous;
 
 	Bonobo_ZoomLevel	*preferred_zoom_levels;
+	Bonobo_ZoomLevelName	*preferred_zoom_level_names;
 	int			 num_preferred_zoom_levels;
 
 	Bonobo_ZoomableFrame	 zoomable_frame;
@@ -169,6 +170,25 @@
 	return list;
 }
 
+static Bonobo_ZoomLevelNameList *
+impl_Bonobo_Zoomable__get_preferred_zoom_level_names (PortableServer_Servant  servant,
+						      CORBA_Environment      *ev)
+{
+	Bonobo_ZoomLevelNameList *list;
+	BonoboZoomable *zoomable;
+
+	zoomable = bonobo_zoomable_from_servant (servant);
+
+	list = Bonobo_ZoomLevelNameList__alloc ();
+	list->_maximum = zoomable->priv->num_preferred_zoom_levels;
+	list->_length = zoomable->priv->num_preferred_zoom_levels;
+	list->_buffer = zoomable->priv->preferred_zoom_level_names;
+	
+	/*  set_release defaults to FALSE - CORBA_sequence_set_release (list, FALSE) */ 
+
+	return list;
+}
+
 static void 
 impl_Bonobo_Zoomable_set_zoom_level (PortableServer_Servant  servant,
 				     const CORBA_float       zoom_level,
@@ -252,6 +272,7 @@
 	epv->_get_has_max_zoom_level = impl_Bonobo_Zoomable__get_has_max_zoom_level;
 	epv->_get_is_continuous = impl_Bonobo_Zoomable__get_is_continuous;
 	epv->_get_preferred_zoom_levels = impl_Bonobo_Zoomable__get_preferred_zoom_levels;
+	epv->_get_preferred_zoom_level_names = impl_Bonobo_Zoomable__get_preferred_zoom_level_names;
 
 	epv->zoom_in = impl_Bonobo_Zoomable_zoom_in;
 	epv->zoom_out = impl_Bonobo_Zoomable_zoom_out;
@@ -316,6 +337,52 @@
 }
 
 static void
+bonobo_zoomable_destroy (GtkObject *object)
+{
+	BonoboZoomable *zoomable;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (BONOBO_IS_ZOOMABLE (object));
+
+	zoomable = BONOBO_ZOOMABLE (object);
+
+	if (zoomable->priv->preferred_zoom_levels)
+		g_free (zoomable->priv->preferred_zoom_levels);
+	zoomable->priv->preferred_zoom_levels = NULL;
+
+	if (zoomable->priv->preferred_zoom_level_names) {
+		gint i;
+
+		for (i = 0; i < zoomable->priv->num_preferred_zoom_levels; i++)
+			g_free (zoomable->priv->preferred_zoom_level_names [i]);
+
+		g_free (zoomable->priv->preferred_zoom_level_names);
+	}
+
+	zoomable->priv->preferred_zoom_levels = NULL;
+	zoomable->priv->preferred_zoom_level_names = NULL;
+	zoomable->priv->num_preferred_zoom_levels = 0;
+
+	GTK_OBJECT_CLASS (bonobo_zoomable_parent_class)->destroy (object);
+}
+
+static void
+bonobo_zoomable_finalize (GtkObject *object)
+{
+	BonoboZoomable *zoomable;
+
+	g_return_if_fail (object != NULL);
+	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;
@@ -385,6 +452,9 @@
 
 	object_class->get_arg = bonobo_zoomable_get_arg;
 
+	object_class->destroy = bonobo_zoomable_destroy;
+	object_class->finalize = bonobo_zoomable_finalize;
+
 	init_zoomable_corba_class ();
 }
 
@@ -398,7 +468,7 @@
 	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 = FALSE;
+	zoomable->priv->is_continuous = TRUE;
 }
 
 /**
@@ -452,7 +522,7 @@
 }
 
 /**
- * bonobo_zoomable_set_parameters:
+ * 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
@@ -465,15 +535,16 @@
  * Return value: 
  **/
 void
-bonobo_zoomable_set_parameters (BonoboZoomable	*p,
-				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,
-				int		 num_preferred_zoom_levels)
+bonobo_zoomable_set_parameters_full (BonoboZoomable  *p,
+				     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)
 {
 	g_return_if_fail (p != NULL);
 	g_return_if_fail (BONOBO_IS_ZOOMABLE (p));
@@ -488,15 +559,58 @@
 	if (p->priv->preferred_zoom_levels) {
 		g_free (p->priv->preferred_zoom_levels);
 		p->priv->preferred_zoom_levels = NULL;
-		p->priv->num_preferred_zoom_levels = 0;
 	}
 
+	if (p->priv->preferred_zoom_level_names) {
+		g_free (p->priv->preferred_zoom_level_names);
+		p->priv->preferred_zoom_level_names = NULL;
+	}
+
+	p->priv->num_preferred_zoom_levels = num_preferred_zoom_levels;
+
+
 	if (preferred_zoom_levels) {
 		p->priv->preferred_zoom_levels = g_memdup
 			(preferred_zoom_levels,
 			 sizeof (float) * num_preferred_zoom_levels);
 		p->priv->num_preferred_zoom_levels = num_preferred_zoom_levels;
 	}
+
+	if (preferred_zoom_level_names) {
+		gint i;
+
+		p->priv->preferred_zoom_level_names = g_new0 (gchar *, num_preferred_zoom_levels+1);
+		for (i = 0; i < num_preferred_zoom_levels; i++)
+			p->priv->preferred_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  *p,
+                                float            zoom_level,
+                                float            min_zoom_level,
+                                float            max_zoom_level,
+                                gboolean         has_min_zoom_level,
+                                gboolean         has_max_zoom_level)
+{
+	g_return_if_fail (p != NULL);
+	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;
 }
 
 BonoboZoomable *
Index: bonobo/bonobo-zoomable-frame.h
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-zoomable-frame.h,v
retrieving revision 1.3
diff -u -u -r1.3 bonobo-zoomable-frame.h
--- bonobo/bonobo-zoomable-frame.h	2000/10/08 17:04:31	1.3
+++ bonobo/bonobo-zoomable-frame.h	2000/10/19 08:59:49
@@ -73,8 +73,8 @@
 gboolean	 bonobo_zoomable_frame_has_max_zoom_level		(BonoboZoomableFrame	*zframe);
 gboolean	 bonobo_zoomable_frame_is_continuous			(BonoboZoomableFrame	*zframe);
 
-float		*bonobo_zoomable_frame_get_preferred_zoom_levels	(BonoboZoomableFrame	*zframe,
-									 int			*pnum_ret);
+GList		*bonobo_zoomable_frame_get_preferred_zoom_levels	(BonoboZoomableFrame	*zframe);
+GList		*bonobo_zoomable_frame_get_preferred_zoom_level_names	(BonoboZoomableFrame	*zframe);
 
 void		 bonobo_zoomable_frame_set_zoom_level			(BonoboZoomableFrame	*zframe,
 									 float			 zoom_level);
Index: bonobo/bonobo-zoomable-frame.c
===================================================================
RCS file: /cvs/gnome/bonobo/bonobo/bonobo-zoomable-frame.c,v
retrieving revision 1.6
diff -u -u -r1.6 bonobo-zoomable-frame.c
--- bonobo/bonobo-zoomable-frame.c	2000/10/12 22:03:31	1.6
+++ bonobo/bonobo-zoomable-frame.c	2000/10/19 08:59:49
@@ -490,12 +490,12 @@
 	return retval;
 }
 
-float *
-bonobo_zoomable_frame_get_preferred_zoom_levels (BonoboZoomableFrame *zoomable_frame, int *pnum_ret)
+GList *
+bonobo_zoomable_frame_get_preferred_zoom_levels (BonoboZoomableFrame *zoomable_frame)
 {
 	CORBA_Environment ev;
 	Bonobo_ZoomLevelList *zoom_levels;
-	float *zoom_level_ptr;
+	GList *list = NULL;
 	int i;
 
 	g_return_val_if_fail (zoomable_frame != NULL, NULL);
@@ -511,21 +511,53 @@
 	}
 	CORBA_exception_free (&ev);
 
-	if (!zoom_levels)
+	if (zoom_levels == CORBA_OBJECT_NIL)
 		return NULL;
 
-	zoom_level_ptr = g_new0 (float, zoom_levels->_length+1);
+	for (i = 0; i < zoom_levels->_length; i++) {
+		float *this;
 
-	for (i = 0; i < zoom_levels->_length; ++i)
-		zoom_level_ptr [i] = zoom_levels->_buffer[i];
+		this = g_new0 (float, 1);
+		*this = zoom_levels->_buffer [i];
 
-	zoom_level_ptr [zoom_levels->_length] = 0.0;
-	if (pnum_ret)
-		*pnum_ret = zoom_levels->_length;
+		list = g_list_prepend (list, this);
+	}
 
 	CORBA_free (zoom_levels);
+
+	return g_list_reverse (list);
+}
+
+GList *
+bonobo_zoomable_frame_get_preferred_zoom_level_names (BonoboZoomableFrame *zoomable_frame)
+{
+	CORBA_Environment ev;
+	Bonobo_ZoomLevelNameList *zoom_level_names;
+	GList *list = NULL;
+	int i;
+
+	g_return_val_if_fail (zoomable_frame != NULL, NULL);
+	g_return_val_if_fail (BONOBO_IS_ZOOMABLE_FRAME (zoomable_frame), NULL);
+
+	CORBA_exception_init (&ev);
+	zoom_level_names = Bonobo_Zoomable__get_preferred_zoom_level_names (zoomable_frame->priv->zoomable, &ev);
+	if (ev._major != CORBA_NO_EXCEPTION) {
+		bonobo_object_check_env (BONOBO_OBJECT (zoomable_frame),
+					 zoomable_frame->priv->zoomable, &ev);
+		CORBA_exception_free (&ev);
+		return NULL;
+	}
+	CORBA_exception_free (&ev);
+
+	if (zoom_level_names == CORBA_OBJECT_NIL)
+		return NULL;
+
+	for (i = 0; i < zoom_level_names->_length; i++)
+		list = g_list_prepend (list, g_strdup (zoom_level_names->_buffer [i]));
+
+	CORBA_free (zoom_level_names);
 
-	return zoom_level_ptr;
+	return g_list_reverse (list);
 }
 
 void
Index: idl/bonobo-zoomable.idl
===================================================================
RCS file: /cvs/gnome/bonobo/idl/bonobo-zoomable.idl,v
retrieving revision 1.4
diff -u -u -r1.4 bonobo-zoomable.idl
--- idl/bonobo-zoomable.idl	2000/10/09 17:52:04	1.4
+++ idl/bonobo-zoomable.idl	2000/10/19 08:59:49
@@ -25,7 +25,10 @@
 module Bonobo {
 
 typedef float ZoomLevel;
+typedef string ZoomLevelName;
+
 typedef sequence<ZoomLevel> ZoomLevelList;
+typedef sequence<ZoomLevelName> ZoomLevelNameList;
 	
 /* A zoomable has the responsibility to look for this
  * interface on its Bonobo control frame and call
@@ -73,6 +76,7 @@
 	readonly attribute boolean has_max_zoom_level;
 	readonly attribute boolean is_continuous;
 	readonly attribute ZoomLevelList preferred_zoom_levels;
+	readonly attribute ZoomLevelNameList preferred_zoom_level_names;
 		
 	/* High level operations.
 	 * These can cause a change in the zoom level.
Maciej, I changed the behaviour of bonobo_zoomable_set_parameters() a bit:
now it does not override any values which are only settable by the _full()
version any longer.

This way you can use the _full() version to set all the parameters on
creation and then use the simpler version if for instance only minimum/maximum
zoom level has changed.

-- 
Martin Baulig
martin gnome org (private)
baulig suse de (work)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]