+ static void
+ container_destroy (Container *cont)
+ {
+ containers = g_list_remove (containers, cont);
+ gtk_widget_destroy (cont->app);
+ g_free (cont);
+ if (!containers)
+ gtk_main_quit ();
+ }
+
+ static void
+ container_close_cmd (GtkWidget *widget, Container *cont)
+ {
+ container_destroy (cont);
+ }
+
+ static void
+ container_exit_cmd (void)
+ {
+ while (containers)
+ container_destroy ((Container *)containers->data);
+ }
+
+ /*
+ * Enforces the containers zoom factor.
+ */
+ static void
+ zoom_set (Container *container)
+ {
+ g_return_if_fail (container != NULL);
+ g_return_if_fail (container->component != NULL);
+
+ gnome_view_frame_set_zoom_factor (container->component->view_frame,
+ container->zoom);
+ }
+
+ static void
+ zoom_in_cmd (GtkWidget *widget, Container *container)
+ {
+ g_return_if_fail (container != NULL);
+ if (container->zoom < 180.0) {
+ container->zoom *= 1.4;
+ zoom_set (container);
+ }
+ }
+
+ static void
+ zoom_out_cmd (GtkWidget *widget, Container *container)
+ {
+ g_return_if_fail (container != NULL);
+ if (container->zoom > 10.0) {
+ container->zoom /= 1.4;
+ zoom_set (container);
+ }
+ }
+
+ static void
+ component_view_activated_cb (GnomeViewFrame *view_frame, gboolean activated, gpointer data)
+ {
+ Component *component = (Component *) data;
+ Container *container = component->container;
+
+ if (activated) {
+ /*
+ * If the View is requesting to be activated, then we
+ * check whether or not there is already an active
+ * View.
+ */
+ if (container->active_view_frame != NULL) {
+ g_warning ("View requested to be activated but there is already "
+ "an active View!\n");
+ return;
+ }
+
+ /*
+ * Otherwise, uncover it so that it can receive
+ * events, and set it as the active View.
+ */
+ gnome_view_frame_set_covered (view_frame, FALSE);
+ container->active_view_frame = view_frame;
+ } else {
+ /*
+ * If the View is asking to be deactivated, always
+ * oblige. We may have already deactivated it (see
+ * user_activation_request_cb), but there's no harm in
+ * doing it again. There is always the possibility
+ * that a View will ask to be deactivated when we have
+ * not told it to deactivate itself, and that is
+ * why we cover the view here.
+ */
+ gnome_view_frame_set_covered (view_frame, TRUE);
+
+ if (view_frame == container->active_view_frame)
+ container->active_view_frame = NULL;
+ }
+ }
+
+ static void
+ component_user_context_cb (GnomeViewFrame *view_frame, gpointer data)
+ {
+ Component *component = (Component *) data;
+ char *executed_verb;
+ GList *l;
+
+ /*
+ * See if the remote GnomeEmbeddable supports any verbs at
+ * all.
+ */
+ l = gnome_client_site_get_verbs (component->client_site);
+ if (l == NULL)
+ return;
+ gnome_client_site_free_verbs (l);
+
+ /*
+ * Popup the verb popup and execute the chosen verb. This
+ * function saves us the work of creating the menu, connecting
+ * the callback, and executing the verb on the remove
+ * GnomeView. We could implement all this functionality
+ * ourselves if we wanted.
+ */
+ executed_verb = gnome_view_frame_popup_verbs (view_frame);
+
+ g_free (executed_verb);
+ }
+}
+
+static void
+container_set_view (Container *container, Component *component)
+{
+ GnomeViewFrame *view_frame;
+ GtkWidget *view_widget;
+
+ /*
+ * Create the remote view and the local ViewFrame.
+ */
+ view_frame = gnome_client_site_new_view (component->client_site);
+ component->view_frame = view_frame;
+
+ /*
+ * Set the GnomeUIHandler for this ViewFrame. That way, the
+ * embedded component can get access to our UIHandler server
+ * so that it can merge menu and toolbar items when it gets
+ * activated.
+ */
+ gnome_view_frame_set_ui_handler (view_frame, container->uih);
+
+ /*
+ * Embed the view frame into the application.
+ */
+ view_widget = gnome_view_frame_get_wrapper (view_frame);
+ container->view_widget = view_widget;
+ container->component = component;
+
+ /*
+ * In-place activation of a component is a two-step process.
+ * After the user double clicks on the component, our signal
+ * callback (compoennt_user_activate_request_cb()) asks the
+ * component to activate itself (see
+ * gnome_view_frame_view_activate()). The component can then
+ * choose to either accept or refuse activation. When an
+ * embedded component notifies us of its decision to change
+ * its activation state, the "view_activated" signal is
+ * emitted from the view frame. It is at that point that we
+ * actually remove the cover so that events can get through.
+ */
+ gtk_signal_connect (GTK_OBJECT (view_frame), "view_activated",
+ GTK_SIGNAL_FUNC (component_view_activated_cb), component);
+
+ /*
+ * The "user_context" signal is emitted when the user right
+ * clicks on the wrapper. We use it to pop up a verb menu.
+ */
+ gtk_signal_connect (GTK_OBJECT (view_frame), "user_context",
+ GTK_SIGNAL_FUNC (component_user_context_cb), component);
+
+ /*
+ * Show the component.
+ */
+ gtk_scrolled_window_add_with_viewport (container->scroll, view_widget);
+
+ /*
+ * Activate it ( get it to merge menus etc.
+ */
+ gnome_view_frame_view_activate (view_frame);
+
+ gtk_widget_show_all (GTK_WIDGET (container->scroll));
+}
+
+static GnomeObjectClient *
+container_launch_component (GnomeClientSite *client_site,
+ GnomeContainer *container,
+ char *component_goad_id)
+{
+ GnomeObjectClient *object_server;
+
+ /*
+ * Launch the component.
+ */
+ object_server = gnome_object_activate_with_goad_id (
+ NULL, component_goad_id, GOAD_ACTIVATE_SHLIB, NULL);
+
+ if (object_server == NULL)
+ return NULL;
+
+ /*
+ * Bind it to the local ClientSite. Every embedded component
+ * has a local GnomeClientSite object which serves as a
+ * container-side point of contact for the embeddable. The
+ * container talks to the embeddable through its ClientSite
+ */
+ if (!gnome_client_site_bind_embeddable (client_site, object_server)) {
+ gnome_object_unref (GNOME_OBJECT (object_server));
+ return NULL;
+ }
+
+ /*
+ * The GnomeContainer object maintains a list of the
+ * ClientSites which it manages. Here we add the new
+ * ClientSite to that list.
+ */
+ gnome_container_add (container, GNOME_OBJECT (client_site));
+
+ return object_server;
+}
+
+/*
+ * Use query_interface to see if `obj' has `interface'.
+ */
+static gboolean
+gnome_object_has_interface (GnomeObject *obj, char *interface)