static void
matecomponent_stream_cache_flush (MateComponentStreamCache *stream, 
			   int                index,
			   CORBA_Environment *ev)
{
	long i, end, pos;
	
	end = index < 0 ? SC_CACHE_SIZE : index + 1;

	for (i = index < 0 ? 0 : index; i < end; i++) {
		if (((index < 0) || (index == i)) &&
		    stream->priv->cache [i].valid &&
		    stream->priv->cache [i].dirty) {
			pos = SC_TAG_POS (stream->priv->cache [i].tag);
			
			MateComponent_Stream_seek (stream->priv->cs, pos,
					    MateComponent_Stream_SeekSet, ev);
			if (MATECOMPONENT_EX (ev))
				continue;

			matecomponent_stream_client_write (stream->priv->cs,
			        stream->priv->cache [i].buf,
						    SC_PAGE_SIZE, ev);
			if (!MATECOMPONENT_EX (ev))
				stream->priv->cache [i].dirty = FALSE;
		}
	}
}
void
matecomponent_event_source_client_remove_listener (MateComponent_Unknown     object,
					    MateComponent_Listener    listener,
					    CORBA_Environment *opt_ev)
{
	MateComponent_Unknown     es;
	CORBA_Environment *ev, temp_ev;

	g_return_if_fail (object != CORBA_OBJECT_NIL);
       
	if (!opt_ev) {
		CORBA_exception_init (&temp_ev);
		ev = &temp_ev;
	} else
		ev = opt_ev;

	es = MateComponent_Unknown_queryInterface (object, 
	        "IDL:MateComponent/EventSource:1.0", ev);

	if (!MATECOMPONENT_EX (ev) && es) {

		MateComponent_EventSource_removeListener (es, listener, ev);

		MateComponent_Unknown_unref (es, ev);
	}

	if (!opt_ev) {
		if (MATECOMPONENT_EX (ev)) {
			char *text = matecomponent_exception_get_text (ev);
			g_warning ("remove_listener failed '%s'", text);
			g_free (text);
		}
		CORBA_exception_free (ev);
	}
}
MateComponent_Listener
matecomponent_event_source_client_add_listener_full (MateComponent_Unknown     object,
					      GClosure          *event_callback,
					      const char        *opt_mask,
					      CORBA_Environment *opt_ev)
{
	MateComponentListener    *listener = NULL;
	MateComponent_Listener    corba_listener = CORBA_OBJECT_NIL;
	MateComponent_Unknown     es;
	CORBA_Environment *ev, temp_ev;

	g_return_val_if_fail (event_callback != NULL, CORBA_OBJECT_NIL);
	
	if (!opt_ev) {
		ev = &temp_ev;
		CORBA_exception_init (ev);
	} else
		ev = opt_ev;

	es = MateComponent_Unknown_queryInterface (object, 
		"IDL:MateComponent/EventSource:1.0", ev);

	if (MATECOMPONENT_EX (ev) || !es)
		goto add_listener_end;

	if (!(listener = matecomponent_listener_new_closure (event_callback)))
		goto add_listener_end;

	corba_listener = MATECOMPONENT_OBJREF (listener);
	
	if (opt_mask)
		MateComponent_EventSource_addListenerWithMask (
			es, corba_listener, opt_mask, ev);
	else 
		MateComponent_EventSource_addListener (
			es, corba_listener, ev);

	corba_listener = CORBA_Object_duplicate (corba_listener, ev);

	matecomponent_object_unref (MATECOMPONENT_OBJECT (listener));

	matecomponent_object_release_unref (es, ev);

 add_listener_end:

	if (!opt_ev) {
		if (MATECOMPONENT_EX (ev)) {
			char *text = matecomponent_exception_get_text (ev);
			g_warning ("add_listener failed '%s'", text);
			g_free (text);
		}
		CORBA_exception_free (ev);
	}

	return corba_listener;
} 
MateComponent_Unknown
matecomponent_moniker_cache_resolve (MateComponentMoniker               *moniker,
			      const MateComponent_ResolveOptions *options,
			      const CORBA_char            *requested_interface,
			      CORBA_Environment           *ev)
{
	MateComponent_Moniker parent;
	MateComponentStream *stream;
	MateComponent_Stream in_stream;

	if (!strcmp (requested_interface, "IDL:MateComponent/Stream:1.0")) {

		parent = matecomponent_moniker_get_parent (moniker, ev);

		if (MATECOMPONENT_EX (ev) || parent == CORBA_OBJECT_NIL)
			return CORBA_OBJECT_NIL;
	
		in_stream = MateComponent_Moniker_resolve (parent, options, 
						    "IDL:MateComponent/Stream:1.0",
						    ev);

		if (MATECOMPONENT_EX (ev) || in_stream == CORBA_OBJECT_NIL) {
			matecomponent_object_release_unref (parent, NULL);
			return CORBA_OBJECT_NIL;
		}

		matecomponent_object_release_unref (parent, ev);

		if (MATECOMPONENT_EX (ev))
			return CORBA_OBJECT_NIL;
	       
		stream = matecomponent_stream_cache_create (in_stream, ev);

		if (MATECOMPONENT_EX (ev) || stream == CORBA_OBJECT_NIL) {
			matecomponent_object_release_unref (in_stream, NULL);
			return CORBA_OBJECT_NIL;
		}

		matecomponent_object_release_unref (in_stream, ev);

		if (MATECOMPONENT_EX (ev))
			return CORBA_OBJECT_NIL;
	      
		return CORBA_Object_duplicate (MATECOMPONENT_OBJREF (stream), ev);
	}

	return CORBA_OBJECT_NIL; /* use the extender */
}
/**
 * matecomponent_property_control_changed:
 * @property_control: The MateComponentPropertyControl 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
matecomponent_property_control_changed (MateComponentPropertyControl *property_control,
				 CORBA_Environment     *opt_ev)
{
	MateComponentPropertyControlPrivate *priv;
	CORBA_Environment ev;
	CORBA_any any;
	CORBA_short s;

	g_return_if_fail (property_control != NULL);
	g_return_if_fail (MATECOMPONENT_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_CORBA_short;
	any._value = &s;

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

	if (opt_ev == NULL)
		CORBA_exception_free (&ev);
}
/**
 * matecomponent_control_get_ambient_properties:
 * @control: A #MateComponentControl which is bound to a remote
 * #MateComponentControlFrame.
 * @opt_ev: an optional exception environment
 *
 * Returns: A #MateComponent_PropertyBag bound to the bag of ambient
 * properties associated with this #Control's #ControlFrame.
 */
MateComponent_PropertyBag
matecomponent_control_get_ambient_properties (MateComponentControl     *control,
				       CORBA_Environment *opt_ev)
{
	MateComponent_ControlFrame frame;
	MateComponent_PropertyBag pbag;
	CORBA_Environment *ev = NULL, tmp_ev;

	g_return_val_if_fail (MATECOMPONENT_IS_CONTROL (control), NULL);

	frame = control->priv->frame;

	if (frame == CORBA_OBJECT_NIL)
		return NULL;

	if (opt_ev)
		ev = opt_ev;
	else {
		CORBA_exception_init (&tmp_ev);
		ev = &tmp_ev;
	}

	pbag = MateComponent_ControlFrame_getAmbientProperties (
		frame, ev);

	if (MATECOMPONENT_EX (ev)) {
		if (!opt_ev)
			CORBA_exception_free (&tmp_ev);
		pbag = CORBA_OBJECT_NIL;
	}

	return pbag;
}
/** 
 * matecomponent_stream_cache_create:
 * @cs: a reference to the stream we want to cache
 * @opt_ev: an optional environment
 *
 * Returns a new MateComponentStream object
 */
MateComponentObject *
matecomponent_stream_cache_create (MateComponent_Stream      cs,
			    CORBA_Environment *opt_ev)
{
	MateComponentStreamCache *stream;
	CORBA_Environment  ev, *my_ev;

	matecomponent_return_val_if_fail (cs != NULL, NULL, opt_ev);

	if (!(stream = g_object_new (matecomponent_stream_cache_get_type (), NULL))) {
		if (opt_ev)
			matecomponent_exception_set (opt_ev, ex_MateComponent_Storage_IOError);
		return NULL;
	}
	
	if (!opt_ev) {
		CORBA_exception_init (&ev);
		my_ev = &ev;
	} else
		my_ev = opt_ev;

	stream->priv->cs = matecomponent_object_dup_ref (cs, my_ev);

	if (MATECOMPONENT_EX (my_ev)) {
		if (!opt_ev)
			CORBA_exception_free (&ev);
		matecomponent_object_unref (MATECOMPONENT_OBJECT (stream));
		return NULL;
	}

	if (!opt_ev)
		CORBA_exception_free (&ev);

	return (MateComponentObject *) stream;
}
/**
 * matecomponent_zoomable_frame_bind_to_zoomable:
 * @zoomable_frame: A MateComponentZoomableFrame object.
 * @zoomable: The CORBA object for the MateComponentZoomable embedded
 * in this MateComponentZoomableFrame.
 *
 * Associates @zoomable with this @zoomable_frame.
 */
void
matecomponent_zoomable_frame_bind_to_zoomable (MateComponentZoomableFrame *zoomable_frame,
					MateComponent_Zoomable      zoomable,
					CORBA_Environment   *opt_ev)
{
	CORBA_Environment *ev, temp_ev;

	g_return_if_fail (zoomable != CORBA_OBJECT_NIL);
	g_return_if_fail (MATECOMPONENT_IS_ZOOMABLE_FRAME (zoomable_frame));

	if (zoomable_frame->priv->zoomable != CORBA_OBJECT_NIL)
		CORBA_Object_release (zoomable_frame->priv->zoomable, NULL);

	zoomable_frame->priv->zoomable = CORBA_Object_duplicate (zoomable, NULL);

	if (!opt_ev) {
		CORBA_exception_init (&temp_ev);
		ev = &temp_ev;
	} else
		ev = opt_ev;

	MateComponent_Zoomable_setFrame (zoomable, MATECOMPONENT_OBJREF (zoomable_frame), ev);

	if (MATECOMPONENT_EX (ev))
		matecomponent_object_check_env (MATECOMPONENT_OBJECT (zoomable_frame), zoomable, ev);

	if (!opt_ev)
		CORBA_exception_free (&temp_ev);
}
MateCanvasItem* get_circle(MateCanvasGroup* group)
{
        CORBA_Object server;
        MateCanvasItem *item;
        CORBA_Environment ev;
  
        CORBA_exception_init (&ev);
  
        server = matecomponent_activation_activate_from_id ("OAFIID:CircleItem", 
                0, NULL, &ev);
  
        if (server == CORBA_OBJECT_NIL || MATECOMPONENT_EX (&ev))
        {
                g_warning (_("Could activate Circle: '%s'"),
                              matecomponent_exception_get_text (&ev));
                CORBA_exception_free(&ev);
                exit(0);
        }
        g_print("Got circle component connect.\n");

        item = mate_canvas_item_new (group, matecomponent_canvas_item_get_type (),
                "corba_factory", server, NULL);
  
        /* I think this tells the object it is OK to exit.
           Probably want to call this when I close.
           or matecomponent_object_release_unref(server, &ev)
        CORBA_Object_release(server, &ev);*/
        matecomponent_object_release_unref(server, &ev);
        CORBA_exception_free(&ev);

        return item;
}
/**
 * matecomponent_control_get_remote_ui_container:
 * @control: A MateComponentControl object which is associated with a remote
 * ControlFrame.
 * @opt_ev: an optional exception environment
 *
 * Returns: The MateComponent_UIContainer CORBA server for the remote MateComponentControlFrame.
 */
MateComponent_UIContainer
matecomponent_control_get_remote_ui_container (MateComponentControl     *control,
					CORBA_Environment *opt_ev)
{
	CORBA_Environment  tmp_ev, *ev;
	MateComponent_UIContainer ui_container;

	g_return_val_if_fail (MATECOMPONENT_IS_CONTROL (control), CORBA_OBJECT_NIL);

	g_return_val_if_fail (control->priv->frame != CORBA_OBJECT_NIL,
			      CORBA_OBJECT_NIL);

	if (!opt_ev) {
		CORBA_exception_init (&tmp_ev);
		ev = &tmp_ev;
	} else
		ev = opt_ev;

	ui_container = MateComponent_ControlFrame_getUIContainer (control->priv->frame, ev);

	matecomponent_object_check_env (MATECOMPONENT_OBJECT (control), control->priv->frame, ev);

	if (MATECOMPONENT_EX (ev))
		ui_container = CORBA_OBJECT_NIL;

	if (!opt_ev)
		CORBA_exception_free (&tmp_ev);

	return ui_container;
}
static void
cache_write (PortableServer_Servant     servant, 
	     const MateComponent_Stream_iobuf *buffer,
	     CORBA_Environment         *ev)
{
	MateComponentStreamCache *stream = MATECOMPONENT_STREAM_CACHE (
		matecomponent_object (servant));
	long tag, bytes_written = 0;
	int index, offset, bc;
	
	while (bytes_written < buffer->_length) {
		index = SC_CACHE_INDEX (stream->priv->pos);
		offset = SC_BLOCK_OFFSET (stream->priv->pos);
		tag = SC_CACHE_TAG (stream->priv->pos);

		if (stream->priv->cache [index].valid &&
		    stream->priv->cache [index].tag == tag) {
			bc = SC_PAGE_SIZE - offset;
			if (bc > buffer->_length) 
				bc = buffer->_length;
			memcpy (stream->priv->cache [index].buf + offset,
				buffer->_buffer + bytes_written, bc);
			bytes_written += bc;
			stream->priv->pos += bc;
			stream->priv->cache [index].dirty = TRUE;
		} else {
			matecomponent_stream_cache_load (stream, tag, ev);
			if (MATECOMPONENT_EX (ev))
				break;
		}
	}
}
GList *
matecomponent_zoomable_frame_get_preferred_zoom_level_names (MateComponentZoomableFrame *zoomable_frame)
{
	CORBA_Environment ev;
	MateComponent_ZoomLevelNameList *zoom_level_names;
	GList *list = NULL;
	int i;

	g_return_val_if_fail (MATECOMPONENT_IS_ZOOMABLE_FRAME (zoomable_frame), NULL);

	CORBA_exception_init (&ev);

	zoom_level_names = MateComponent_Zoomable__get_preferredLevelNames (
		zoomable_frame->priv->zoomable, &ev);

	if (MATECOMPONENT_EX (&ev)) {
		matecomponent_object_check_env (MATECOMPONENT_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 g_list_reverse (list);
}
static void
matecomponent_stream_cache_load (MateComponentStreamCache *stream, 
			  long               tag,
			  CORBA_Environment *ev)
{
	MateComponent_Stream_iobuf *iobuf;
	long pos, index;

	pos = SC_TAG_POS (tag);
	index = SC_CACHE_INDEX (pos);

	matecomponent_stream_cache_flush (stream, index, ev);
	if (MATECOMPONENT_EX (ev))
		return;

	MateComponent_Stream_seek (stream->priv->cs, pos, MateComponent_Stream_SeekSet, ev);
	if (MATECOMPONENT_EX (ev))
		return;

	MateComponent_Stream_read (stream->priv->cs, SC_PAGE_SIZE, &iobuf, ev);
	if (MATECOMPONENT_EX (ev))
		return;
	
	if (iobuf->_length < SC_PAGE_SIZE) /* eof  - fill with zero */
		memset (stream->priv->cache [index].buf + iobuf->_length, 0,
			SC_PAGE_SIZE - iobuf->_length);
				
	if ((pos + iobuf->_length) > stream->priv->size)
		stream->priv->size = pos + iobuf->_length;

	memcpy (stream->priv->cache [index].buf, iobuf->_buffer, 
		iobuf->_length);
	
	stream->priv->cache [index].valid = TRUE;
	stream->priv->cache [index].dirty = FALSE;
	stream->priv->cache [index].tag = tag;

	CORBA_free (iobuf);
}
MateComponent_Unknown
matecomponent_moniker_oaf_resolve (MateComponentMoniker               *moniker,
			    const MateComponent_ResolveOptions *options,
			    const CORBA_char            *requested_interface,
			    CORBA_Environment           *ev)
{
	MateComponent_Moniker       parent;
	MateComponent_Unknown       object;
	
	parent = matecomponent_moniker_get_parent (moniker, ev);

	if (ev->_major != CORBA_NO_EXCEPTION)
		return CORBA_OBJECT_NIL;
	
	if (parent != CORBA_OBJECT_NIL) {
		matecomponent_object_release_unref (parent, ev);

#ifdef G_ENABLE_DEBUG
		g_warning ("wierd; oafid moniker with a parent; strange");
#endif
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_MateComponent_Moniker_InterfaceNotFound, NULL);
		return CORBA_OBJECT_NIL;
	}

	object = matecomponent_activation_activate_from_id (
		(char *) matecomponent_moniker_get_name_full (moniker), 0, NULL, ev);

	if (MATECOMPONENT_EX (ev)) {
		if (ev->_major == CORBA_USER_EXCEPTION) {
			if (strcmp (ev->_id, ex_MateComponent_GeneralError)) {
				CORBA_exception_free (ev);

				matecomponent_exception_general_error_set (
					ev, NULL, _("Exception activating '%s'"),
					matecomponent_moniker_get_name_full (moniker));
			}
		}
		return CORBA_OBJECT_NIL;

	} else if (object == CORBA_OBJECT_NIL) {

		matecomponent_exception_general_error_set (
			ev, NULL, _("Failed to activate '%s'"),
			matecomponent_moniker_get_name_full (moniker));

		return CORBA_OBJECT_NIL;
	}

	return matecomponent_moniker_util_qi_return (object, requested_interface, ev);
}
static void
setup_options (void)
{
	MateComponent_ServerInfoList *applets;
	CORBA_Environment      env;
	int                    i;
	char                  *prefs_dir;
	char                  *unique_key;
	ComboItem             *applet_items;
	int                    applet_nb;

	CORBA_exception_init (&env);

	applets = matecomponent_activation_query (
			"has (repo_ids, 'IDL:MATE/Vertigo/MatePanelAppletShell:1.0')",
			NULL, &env);

	if (MATECOMPONENT_EX (&env))
		g_error (_("query returned exception %s\n"), MATECOMPONENT_EX_REPOID (&env));

	CORBA_exception_free (&env);

	applet_nb = applets->_length;
	applet_items = g_new0 (ComboItem, applet_nb);

	for (i = 0; i < applet_nb; i++) {
		MateComponent_ServerInfo *info;

		info = &applets->_buffer [i];

		applet_items[i].name = info->iid;
		applet_items[i].value = info->iid;
	}

	setup_combo (applet_combo, applet_items, NULL, applet_nb, TRUE);
	g_free (applet_items);
	CORBA_free (applets);

	setup_combo (size_combo, size_items, "Size",
		     G_N_ELEMENTS (size_items), FALSE);
	setup_combo (orient_combo, orient_items, "Orientation",
		     G_N_ELEMENTS (orient_items), FALSE);

	unique_key = mateconf_unique_key ();
	prefs_dir = g_strdup_printf ("/tmp/%s", unique_key);
	g_free (unique_key);
	gtk_entry_set_text (GTK_ENTRY (prefs_dir_entry), prefs_dir);
	g_free (prefs_dir);
}
static void
mate_panel_applet_frame_matecomponent_popup_menu (MatePanelAppletFrame *frame,
				      guint             button,
				      guint32           timestamp)
{
	MatePanelAppletFrameMateComponent *matecomponent_frame = MATE_PANEL_APPLET_FRAME_MATECOMPONENT (frame);
	CORBA_Environment env;

	CORBA_exception_init (&env);

	MATE_Vertigo_MatePanelAppletShell_popup_menu (matecomponent_frame->priv->applet_shell,
						   button, timestamp, &env);
	if (MATECOMPONENT_EX (&env))
		g_warning ("Exception from popup_menu '%s'\n", env._id);

	CORBA_exception_free (&env);
}
static gchar *
get_stream_type (MateComponent_Stream stream, CORBA_Environment *ev)
{
	MateComponent_StorageInfo *info;
	gchar              *type;

	g_return_val_if_fail (stream != CORBA_OBJECT_NIL, NULL);

	info = MateComponent_Stream_getInfo (stream, MateComponent_FIELD_CONTENT_TYPE, ev);
	
	if (MATECOMPONENT_EX (ev))
		return NULL;

	type = g_strdup (info->content_type);

	CORBA_free (info);

	return type;
}
float
matecomponent_zoomable_frame_get_max_zoom_level (MateComponentZoomableFrame *zoomable_frame)
{
	CORBA_Environment ev;
	float retval;

	g_return_val_if_fail (MATECOMPONENT_IS_ZOOMABLE_FRAME (zoomable_frame), 0.0);
	g_return_val_if_fail (zoomable_frame->priv->zoomable != CORBA_OBJECT_NIL, 0.0);

	CORBA_exception_init (&ev);
	retval = MateComponent_Zoomable__get_maxLevel (zoomable_frame->priv->zoomable, &ev);
	if (MATECOMPONENT_EX (&ev))
		retval = 0.0;
	matecomponent_object_check_env (MATECOMPONENT_OBJECT (zoomable_frame),
				 zoomable_frame->priv->zoomable, &ev);
	CORBA_exception_free (&ev);

	return retval;
}
gboolean
matecomponent_zoomable_frame_is_continuous (MateComponentZoomableFrame *zoomable_frame)
{
	CORBA_Environment ev;
	gboolean retval;

	g_return_val_if_fail (MATECOMPONENT_IS_ZOOMABLE_FRAME (zoomable_frame), FALSE);
	g_return_val_if_fail (zoomable_frame->priv->zoomable != CORBA_OBJECT_NIL, FALSE);

	CORBA_exception_init (&ev);
	retval = MateComponent_Zoomable__get_isContinuous (zoomable_frame->priv->zoomable, &ev);
	if (MATECOMPONENT_EX (&ev))
		retval = FALSE;
	matecomponent_object_check_env (MATECOMPONENT_OBJECT (zoomable_frame),
				 zoomable_frame->priv->zoomable, &ev);
	CORBA_exception_free (&ev);

	return retval;
}
static long
matecomponent_stream_cache_read (MateComponentStreamCache *stream, 
			  long               count, 
			  char              *buffer,
			  CORBA_Environment *ev)
{
	long tag, bytes_read = 0;
	int index, offset, bc, d;

	while (bytes_read < count) {
		index = SC_CACHE_INDEX (stream->priv->pos);
		offset = SC_BLOCK_OFFSET (stream->priv->pos);
		tag = SC_CACHE_TAG (stream->priv->pos);

		if ((stream->priv->pos < stream->priv->size) &&
		    stream->priv->cache [index].valid &&
		    stream->priv->cache [index].tag == tag) {
			bc = SC_PAGE_SIZE - offset;

			if ((bytes_read + bc) > count)
				bc = count - bytes_read;

			if ((d = (stream->priv->pos + bc) - 
			     stream->priv->size) > 0)
				bc -= d;
			if (!bc)
				return bytes_read;

			memcpy (buffer + bytes_read, 
				stream->priv->cache [index].buf + offset, bc);
			bytes_read += bc;
			stream->priv->pos += bc;
		} else {
			matecomponent_stream_cache_load (stream, tag, ev);
			if (MATECOMPONENT_EX (ev))
				break;
			if (stream->priv->pos >= stream->priv->size)
				break;
		}
	}

	return bytes_read;
}
/**
 * matecomponent_control_set_transient_for:
 * @control: a control with associated control frame
 * @window: a window upon which to set the transient window.
 * 
 *   Attempts to make the @window transient for the toplevel
 * of any associated controlframe the MateComponentControl may have.
 **/
void
matecomponent_control_set_transient_for (MateComponentControl     *control,
				  GtkWindow         *window,
				  CORBA_Environment *opt_ev)
{
	CORBA_char         *id;
	GdkDisplay         *display;
	GdkWindow          *win;
	GdkNativeWindow    window_id;
	CORBA_Environment  *ev = NULL, tmp_ev;
	MateComponent_ControlFrame frame;
	gpointer            local_win;

	g_return_if_fail (GTK_IS_WINDOW (window));
	g_return_if_fail (MATECOMPONENT_IS_CONTROL (control));

	/* FIXME: special case the local case !
	 * we can only do this if set_transient is virtualized
	 * and thus we can catch it in MateComponentSocket and chain up
	 * again if we are embedded inside an embedded thing. */

	frame = control->priv->frame;

	if (frame == CORBA_OBJECT_NIL)
		return;

	if (opt_ev)
		ev = opt_ev;
	else {
		CORBA_exception_init (&tmp_ev);
		ev = &tmp_ev;
	}

	id = MateComponent_ControlFrame_getToplevelId (frame, ev);
	g_return_if_fail (!MATECOMPONENT_EX (ev) && id != NULL);

	window_id = matecomponent_control_x11_from_window_id (id);

#ifdef TRANSIENT_DEBUG
	g_warning ("Got id '%s' -> %d", id, window_id);
#endif
	CORBA_free (id);

	display = gtk_widget_get_display (GTK_WIDGET (window));

#if defined (GDK_WINDOWING_X11)
	local_win = gdk_xid_table_lookup_for_display (display, window_id);
#elif defined (GDK_WINDOWING_WIN32)
	local_win = gdk_win32_handle_table_lookup (window_id);
#endif
	if (local_win == NULL)
		win = gdk_window_foreign_new_for_display (display, window_id);
	else {
		win = GDK_WINDOW (local_win);
		g_object_ref (win);
	}
	g_return_if_fail (win != NULL);

	window_set_transient_for_gdk (window, win);

	if (!opt_ev)
		CORBA_exception_free (&tmp_ev);
}
示例#22
0
static void
xfapplet_applet_activated (MateComponent_Unknown object, CORBA_Environment *ev, gpointer data)
{
	GtkWidget		*bw, *child = NULL;
	CORBA_Object		 control;
	CORBA_Environment	 corba_ev;
	MateComponentControlFrame	*frame;
	MateComponentUIComponent	*uic;
	MateComponent_PropertyBag	 prop_bag;
	XfAppletPlugin		*xap = (XfAppletPlugin*) data;
	gchar			*error;

	if (MATECOMPONENT_EX (ev) || object == CORBA_OBJECT_NIL) {
		error = matecomponent_exception_get_text (ev);
		CORBA_exception_free (ev);
		g_warning ("Failed to load applet '%s' (can't get CORBA object): %s\n", xap->iid, error);
		xfapplet_applet_load_failed (xap);
		xfapplet_cleanup_current (xap);
		g_free (error);
		return;
	}
	
	control = CORBA_Object_duplicate (object, NULL);
	bw = matecomponent_widget_new_control_from_objref (object, CORBA_OBJECT_NIL);
	matecomponent_object_release_unref (object, NULL);
	if (!bw) {
		g_warning ("Failed to load applet '%s' (can't get matecomponent widget)\n", xap->iid);
		xfapplet_applet_load_failed (xap);
		xfapplet_cleanup_current (xap);
		return;
	}
	
	frame = matecomponent_widget_get_control_frame (MATECOMPONENT_WIDGET (bw));
	if (!frame) {
		g_warning ("Failed to load applet '%s' (can't get control frame)\n", xap->iid);
		gtk_object_sink (GTK_OBJECT (bw));
		xfapplet_applet_load_failed (xap);
		xfapplet_cleanup_current (xap);
		return;
	}
	
	CORBA_exception_init (&corba_ev);
	prop_bag = matecomponent_control_frame_get_control_property_bag (frame, &corba_ev);
	if (prop_bag == NULL || MATECOMPONENT_EX (&corba_ev)) {
		error = matecomponent_exception_get_text (&corba_ev);
		CORBA_exception_free (&corba_ev);
		g_warning ("Failed to load applet '%s' (can't get property bag): %s\n", xap->iid, error);
		gtk_object_sink (GTK_OBJECT (bw));
		xfapplet_applet_load_failed (xap);
		xfapplet_cleanup_current (xap);
		g_free (error);
		return;
	}
	
        uic = matecomponent_control_frame_get_popup_component (frame, &corba_ev);
	if (uic == NULL || MATECOMPONENT_EX (&corba_ev)) {
		error = matecomponent_exception_get_text (&corba_ev);
		CORBA_exception_free (&corba_ev);
		g_warning ("Failed to load applet '%s' (can't get popup component): %s\n", xap->iid, error);
		gtk_object_sink (GTK_OBJECT (bw));
		xfapplet_applet_load_failed (xap);
		xfapplet_cleanup_current (xap);
		g_free (error);
		return;
	}
		
	matecomponent_ui_component_freeze (uic, CORBA_OBJECT_NIL);
	xfce_textdomain ("xfce4-panel", LIBXFCE4PANEL_LOCALE_DIR, "UTF-8");
	matecomponent_ui_util_set_ui (uic, PKGDATADIR "/ui", "XFCE_Panel_Popup.xml", "xfce4-xfapplet-plugin", &corba_ev);
	if (MATECOMPONENT_EX (&corba_ev)) {
		error = matecomponent_exception_get_text (&corba_ev);
		CORBA_exception_free (&corba_ev);
		g_warning ("Failed to load applet '%s' (can't set ui): %s\n", xap->iid, error);
		gtk_object_sink (GTK_OBJECT (bw));
		xfapplet_applet_load_failed (xap);
		xfapplet_cleanup_current (xap);
		g_free (error);
		return;
	}
	xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");
	xfapplet_setup_menu_items (xap->plugin, uic);
	matecomponent_ui_component_thaw (uic, CORBA_OBJECT_NIL);

	gtk_widget_show (bw);

	if (xap->configured)
		xfapplet_unload_applet (xap);

	xap->object = control;
	xap->uic = uic;
	xap->prop_bag = prop_bag;
	MateCORBA_small_listen_for_broken (object, G_CALLBACK (xfapplet_connection_broken), xap);

	child = xfapplet_get_plugin_child (xap->plugin);
	if (child)
		gtk_widget_destroy (child);

	gtk_container_add (GTK_CONTAINER(xap->plugin), bw);
	xap->configured = TRUE;

	if (!xfapplet_save_configuration (xap))
		g_warning ("Failed to save XfApplet configuration.\n");
}