X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2Fgpdf.cc;h=aa44c4eb83c86a32794b101fcd38331f256a05e9;hb=11c2610a62f60a0394c0eea0fede081d9fd678bd;hp=f0237c76646302dfb62b5eb74595884147053c28;hpb=1a49446c08faaab930d3a36bc002b566eadb1ebc;p=evince.git diff --git a/pdf/xpdf/gpdf.cc b/pdf/xpdf/gpdf.cc index f0237c76..aa44c4eb 100644 --- a/pdf/xpdf/gpdf.cc +++ b/pdf/xpdf/gpdf.cc @@ -1,15 +1,9 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * test-container.c + * PDF viewer Bonobo container. * - * A simple program to act as a test container for embeddable - * components. - * - * Authors: - * Nat Friedman (nat@gnome-support.com) - * Miguel de Icaza (miguel@gnu.org) + * Author: + * Michael Meeks */ - #include #include #include @@ -17,39 +11,19 @@ extern "C" { #define GString G_String #include -#include + +#include + #include #include -#include +#include #undef GString } -#include -#include -#include "gtypes.h" -#include "GString.h" -#include "parseargs.h" -#include "gfile.h" -#include "gmem.h" -#include "Object.h" -#include "Stream.h" -#include "Array.h" -#include "Dict.h" -#include "XRef.h" -#include "Catalog.h" -#include "Page.h" -#include "Link.h" -#include "PDFDoc.h" -#include "GOutputDev.h" -#include "PSOutputDev.h" -#include "TextOutputDev.h" -#include "Params.h" -#include "Error.h" #include "config.h" +#include "bonobo-application-x-pdf.h" -CORBA_Environment ev; -CORBA_ORB orb; poptContext ctx; -gint gpdf_debug=1; +gint gpdf_debug=0; const struct poptOption gpdf_popt_options [] = { { "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0, @@ -57,449 +31,549 @@ const struct poptOption gpdf_popt_options [] = { { NULL, '\0', 0, NULL, 0 } }; +typedef struct _Component Component; +typedef struct _Container Container; +/* NB. there is a 1 to 1 Container -> Component mapping, this + is due to how much MDI sucks; unutterably */ +struct _Container { + BonoboItemContainer *container; + BonoboUIComponent *ui_component; + + GtkWidget *app; + GtkWidget *slot; + GtkWidget *view_widget; + Component *component; +}; + +struct _Component { + Container *container; + + BonoboClientSite *client_site; + BonoboViewFrame *view_frame; + BonoboObjectClient *server; +}; + +GList *containers = NULL; /* - * A handle to some Embeddables and their ClientSites so we can add - * views to existing components. + * Static prototypes. */ -GnomeObjectClient *text_obj; -GnomeClientSite *text_client_site; - -GnomeObjectClient *image_png_obj; -GnomeClientSite *image_client_site; +extern "C" { + static Container *container_new (const char *fname); + static void container_destroy (Container *cont); + static void container_open_cmd (GtkWidget *widget, Container *container); + static void container_close_cmd (GtkWidget *widget, Container *container); + static void container_exit_cmd (void); + static void container_about_cmd (GtkWidget *widget, Container *container); + static void container_dump_cmd (GtkWidget *widget, Container *container); + static Component *container_activate_component (Container *container, char *component_goad_id); +} /* - * The currently active view. We keep track of this - * so we can deactivate it when a new view is activated. + * The menus. */ -GnomeViewFrame *active_view_frame; +BonoboUIVerb verbs [] = { + BONOBO_UI_UNSAFE_VERB ("FileOpen", container_open_cmd), + BONOBO_UI_UNSAFE_VERB ("FileClose", container_close_cmd), + BONOBO_UI_UNSAFE_VERB ("FileExit", container_exit_cmd), -char *server_goadid = "gnome_xpdf_viewer"; + BONOBO_UI_UNSAFE_VERB ("HelpAbout", container_about_cmd), -typedef struct { - GtkWidget *app; - GnomeContainer *container; - GtkWidget *box; - GnomeUIHandler *uih; - gboolean contains_pdf; -} Application; + BONOBO_UI_UNSAFE_VERB ("DebugDumpXml", container_dump_cmd), -/* List of applications */ -GList *apps = NULL; + BONOBO_UI_VERB_END +}; -static Application * application_new (void); + +extern "C" { + static gboolean + open_pdf (Container *container, const char *name) + { + BonoboObjectClient *object; + BonoboStream *stream; + Bonobo_PersistStream persist; + Component *comp; + CORBA_Environment ev; + + g_return_val_if_fail (container != NULL, FALSE); + g_return_val_if_fail (container->view_widget == NULL, FALSE); + + comp = container_activate_component ( + container, "OAFIID:GNOME_XPDF_Embeddable"); + + if (!comp || !(object = comp->server)) { + gnome_error_dialog (_("Could not launch bonobo object.")); + return FALSE; + } + + CORBA_exception_init (&ev); + persist = Bonobo_Unknown_queryInterface ( + bonobo_object_corba_objref (BONOBO_OBJECT (object)), + "IDL:Bonobo/PersistStream:1.0", &ev); + + if (ev._major != CORBA_NO_EXCEPTION || + persist == CORBA_OBJECT_NIL) { + gnome_error_dialog ("Panic: component doesn't implement PersistStream."); + return FALSE; + } + + stream = bonobo_stream_open (BONOBO_IO_DRIVER_FS, name, Bonobo_Storage_READ, 0); + + if (stream == NULL) { + char *err = g_strconcat (_("Could not open "), name, NULL); + gnome_error_dialog_parented (err, GTK_WINDOW(container->app)); + g_free (err); + return FALSE; + } + + Bonobo_PersistStream_load (persist, + (Bonobo_Stream) bonobo_object_corba_objref (BONOBO_OBJECT (stream)), + "application/pdf", + &ev); + + Bonobo_Unknown_unref (persist, &ev); + CORBA_Object_release (persist, &ev); + CORBA_exception_free (&ev); + +/* bonobo_view_frame_view_do_verb (comp->view_frame, "ZoomFit"); */ + return TRUE; + } + + static void + set_ok (GtkWidget *widget, gboolean *dialog_result) + { + *dialog_result = TRUE; + gtk_main_quit (); + } + + static guint + file_dialog_delete_event (GtkWidget *widget, GdkEventAny *event) + { + gtk_main_quit (); + return TRUE; + } + + static void + container_open_cmd (GtkWidget *widget, Container *container) + { + GtkFileSelection *fsel; + gboolean accepted = FALSE; + + fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Load file"))); + gtk_window_set_modal (GTK_WINDOW (fsel), TRUE); + + gtk_window_set_transient_for (GTK_WINDOW (fsel), + GTK_WINDOW (container->app)); + + /* Connect the signals for Ok and Cancel */ + gtk_signal_connect (GTK_OBJECT (fsel->ok_button), "clicked", + GTK_SIGNAL_FUNC (set_ok), &accepted); + gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked", + GTK_SIGNAL_FUNC (gtk_main_quit), NULL); + gtk_window_set_position (GTK_WINDOW (fsel), GTK_WIN_POS_MOUSE); + + /* + * Make sure that we quit the main loop if the window is destroyed + */ + gtk_signal_connect (GTK_OBJECT (fsel), "delete_event", + GTK_SIGNAL_FUNC (file_dialog_delete_event), NULL); + + /* Run the dialog */ + gtk_widget_show (GTK_WIDGET (fsel)); + gtk_grab_add (GTK_WIDGET (fsel)); + gtk_main (); + + if (accepted) { + char *name = gtk_file_selection_get_filename (fsel); + + if (name [strlen (name)-1] != '/') { + char *fname = g_strdup (name); + if (container->view_widget) /* any sort of MDI sucks :-] */ + container = container_new (fname); + else { + if (!open_pdf (container, fname)) + container_destroy (container); + } + g_free (fname); + } else { + GtkWidget *dialog; + dialog = gnome_message_box_new ("Can't open a directory", + GNOME_MESSAGE_BOX_ERROR, + GNOME_STOCK_BUTTON_OK, NULL); + gnome_dialog_set_parent (GNOME_DIALOG (dialog), + GTK_WINDOW (container->app)); + gnome_dialog_run (GNOME_DIALOG (dialog)); + } + } + + gtk_widget_destroy (GTK_WIDGET (fsel)); + } + + static void + component_destroy (Component *component) + { + CORBA_Environment ev; + Container *container; + g_return_if_fail (component != NULL); + + CORBA_exception_init (&ev); + + /* Kill merged menus et al. */ + bonobo_view_frame_view_deactivate (component->view_frame); + + container = component->container; + gtk_widget_destroy (container->view_widget); + container->view_widget = NULL; + + if (component->server) + Bonobo_Unknown_unref ( + bonobo_object_corba_objref (BONOBO_OBJECT (component->server)), &ev); + component->server = NULL; + + CORBA_exception_free (&ev); + + g_free (component); + } + + static void + container_destroy (Container *cont) + { + g_return_if_fail (g_list_find (containers, cont) != NULL); + + containers = g_list_remove (containers, cont); + if (cont->app) + gtk_widget_destroy (cont->app); + cont->app = NULL; + + if (cont->component) + component_destroy (cont->component); + cont->component = NULL; + + g_free (cont); + + if (!containers) + gtk_main_quit (); + } + + static void + container_close (Container *cont) + { + g_return_if_fail (g_list_find (containers, cont) != NULL); + + if (cont->component) { + component_destroy (cont->component); + cont->component = NULL; + } else + container_destroy (cont); + } + + + static void + container_close_cmd (GtkWidget *widget, Container *cont) + { + container_close (cont); + } + + static int + container_destroy_cb (GtkWidget *widget, GdkEvent *event, Container *cont) + { + container_destroy (cont); + return 1; + } + + static void + container_exit_cmd (void) + { + while (containers) + container_destroy ((Container *)containers->data); + } static void -application_destroy (Application *app) +container_dump_cmd (GtkWidget *widget, Container *container) { - apps = g_list_remove (apps, app); - gtk_widget_destroy (app->app); - g_free (app); - if (!apps) - gtk_main_quit (); + bonobo_window_dump (BONOBO_WINDOW(container->app), "on demand"); } static void -applications_destroy () +container_about_cmd (GtkWidget *widget, Container *container) { - while (apps) - application_destroy ((Application *)apps->data); + GtkWidget *about; + + const gchar *authors[] = { + N_("Derek B. Noonburg, main author"), + N_("Michael Meeks, GNOME port maintainer."), + N_("Miguel de Icaza."), + N_("Nat Friedman."), + NULL + }; + +#ifdef ENABLE_NLS + int i; + + for (i = 0; authors[i] != NULL; i++) + authors [i] = _(authors [i]); +#endif + + about = gnome_about_new (_("GPDF"), xpdfVersion, + _("(C) 1996-1999 Derek B. Noonburg."), + authors, NULL, NULL); + + gnome_dialog_set_parent (GNOME_DIALOG (about), GTK_WINDOW (container->app)); + gnome_dialog_set_close (GNOME_DIALOG (about), TRUE); + gtk_widget_show (about); } - -static GnomeObjectClient * -launch_server (GnomeClientSite *client_site, GnomeContainer *container, char *goadid) -{ - GnomeObjectClient *object_server; - - gnome_container_add (container, GNOME_OBJECT (client_site)); - - printf ("Launching...\n"); - object_server = gnome_object_activate_with_goad_id (NULL, goadid, GOAD_ACTIVATE_SHLIB, NULL); - printf ("Return: %p\n", object_server); - if (!object_server){ - g_warning (_("Can not activate object_server\n")); - return NULL; - } - - if (!gnome_client_site_bind_embeddable (client_site, object_server)){ - g_warning (_("Can not bind object server to client_site\n")); - return NULL; - } - - return object_server; } -static GnomeObjectClient * -launch_server_moniker (GnomeClientSite *client_site, GnomeContainer *container, char *moniker) +static void +container_set_view (Container *container, Component *component) { - GnomeObjectClient *object_server; - - gnome_container_add (container, GNOME_OBJECT (client_site)); - - printf ("Launching moniker %s...\n", moniker); - object_server = gnome_object_activate (moniker, GOAD_ACTIVATE_SHLIB); - printf ("Return: %p\n", object_server); - if (!object_server){ - g_warning (_("Can not activate object_server\n")); - return NULL; - } - - if (!gnome_client_site_bind_embeddable (client_site, object_server)){ - g_warning (_("Can not bind object server to client_site\n")); - return NULL; - } - - return object_server; -} + BonoboViewFrame *view_frame; + GtkWidget *view_widget; -/* - * This function is called when the user double clicks on a View in - * order to activate it. - */ -static gint -user_activation_request_cb (GnomeViewFrame *view_frame) -{ /* - * If there is already an active View, deactivate it. - */ - if (active_view_frame != NULL) { - /* - * This just sends a notice to the embedded View that - * it is being deactivated. We will also forcibly - * cover it so that it does not receive any Gtk - * events. - */ - gnome_view_frame_view_deactivate (active_view_frame); - - /* - * Here we manually cover it if it hasn't acquiesced. - * If it has consented to be deactivated, then it will - * already have notified us that it is inactive, and - * we will have covered it and set active_view_frame - * to NULL. Which is why this check is here. - */ - if (active_view_frame != NULL) - gnome_view_frame_set_covered (active_view_frame, TRUE); - - active_view_frame = NULL; - } - - /* - * Activate the View which the user clicked on. This just - * sends a request to the embedded View to activate itself. - * When it agrees to be activated, it will notify its - * ViewFrame, and our view_activated_cb callback will be - * called. - * - * We do not uncover the View here, because it may not wish to - * be activated, and so we wait until it notifies us that it - * has been activated to uncover it. + * Create the remote view and the local ViewFrame. */ - gnome_view_frame_view_activate (view_frame); - - return FALSE; -} - -/* - * Gets called when the View notifies the ViewFrame that it would like - * to be activated or deactivated. - */ -static gint -view_activated_cb (GnomeViewFrame *view_frame, gboolean activated) -{ - - if (activated) { - /* - * If the View is requesting to be activated, then we - * check whether or not there is already an active - * View. - */ - if (active_view_frame != NULL) { - g_warning ("View requested to be activated but there is already " - "an active View!\n"); - return FALSE; - } - - /* - * Otherwise, uncover it so that it can receive - * events, and set it as the active View. - */ - gnome_view_frame_set_covered (view_frame, FALSE); - 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 == active_view_frame) - active_view_frame = NULL; - } - - return FALSE; -} - -static GnomeViewFrame * -add_view (Application *app, - GnomeClientSite *client_site, GnomeObjectClient *server) -{ - GnomeViewFrame *view_frame; - GtkWidget *view_widget; - - view_frame = gnome_client_site_embeddable_new_view (client_site); - - gtk_signal_connect (GTK_OBJECT (view_frame), "user_activate", - GTK_SIGNAL_FUNC (user_activation_request_cb), NULL); - gtk_signal_connect (GTK_OBJECT (view_frame), "view_activated", - GTK_SIGNAL_FUNC (view_activated_cb), NULL); - - gnome_view_frame_set_ui_handler (view_frame, app->uih); - - view_widget = gnome_view_frame_get_wrapper (view_frame); + view_frame = bonobo_client_site_new_view ( + component->client_site, + bonobo_ui_component_get_container (container->ui_component)); - gtk_box_pack_start (GTK_BOX (app->box), view_widget, TRUE, TRUE, 0); - gtk_widget_show_all (app->box); + component->view_frame = view_frame; - return view_frame; -} /* add_view */ + /* + * Embed the view frame into the application. + */ + view_widget = bonobo_view_frame_get_wrapper (view_frame); + bonobo_wrapper_set_visibility (BONOBO_WRAPPER (view_widget), FALSE); + container->view_widget = view_widget; + container->component = component; -static GnomeObjectClient * -add_cmd (Application *app, char *server_goadid, - GnomeClientSite **client_site) -{ - GnomeObjectClient *server; - - *client_site = gnome_client_site_new (app->container); + gtk_container_add (GTK_CONTAINER (container->slot), view_widget); - server = launch_server (*client_site, app->container, server_goadid); - if (server == NULL) - return NULL; + /* + * Activate it ( get it to merge menus etc. ) + */ + bonobo_view_frame_view_activate (view_frame); + bonobo_view_frame_set_covered (view_frame, FALSE); - add_view (app, *client_site, server); - return server; + gtk_widget_show_all (GTK_WIDGET (container->slot)); } -static void -open_pdf (Application *app, const char *name) +static BonoboObjectClient * +container_launch_component (BonoboClientSite *client_site, + BonoboItemContainer *container, + char *component_goad_id) { - GnomeObjectClient *object; - GnomeStream *stream; - GNOME_PersistStream persist; - - object = add_cmd (app, "bonobo-object:image-x-pdf", &image_client_site); - if (object == NULL) { - gnome_error_dialog (_("Could not launch bonobo object.")); - return; - } - - image_png_obj = object; + BonoboObjectClient *object_server; - persist = GNOME_Unknown_query_interface ( - gnome_object_corba_objref (GNOME_OBJECT (object)), - "IDL:GNOME/PersistStream:1.0", &ev); + /* + * Launch the component. + */ + object_server = bonobo_object_activate (component_goad_id, 0); - if (ev._major != CORBA_NO_EXCEPTION || - persist == CORBA_OBJECT_NIL) { - gnome_error_dialog ("Panic: component is well broken."); - return; - } - - stream = gnome_stream_fs_open (name, GNOME_Storage_READ); + if (object_server == NULL) + return NULL; - if (stream == NULL) { - char *err = g_strconcat (_("Could not open "), name, NULL); - gnome_error_dialog_parented (err, GTK_WINDOW(app->app)); - g_free (err); - return; + /* + * Bind it to the local ClientSite. Every embedded component + * has a local BonoboClientSite object which serves as a + * container-side point of contact for the embeddable. The + * container talks to the embeddable through its ClientSite + */ + if (!bonobo_client_site_bind_embeddable (client_site, object_server)) { + bonobo_object_unref (BONOBO_OBJECT (object_server)); + return NULL; } - - GNOME_PersistStream_load (persist, - (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev); - GNOME_Unknown_unref (persist, &ev); - CORBA_Object_release (persist, &ev); - app->contains_pdf = TRUE; -} - -static void -set_ok (GtkWidget *widget, gboolean *dialog_result) -{ - *dialog_result = TRUE; - gtk_main_quit (); + return object_server; } -static guint -file_dialog_delete_event (GtkWidget *widget, GdkEventAny *event) -{ - gtk_main_quit (); - return TRUE; +extern "C" { + static Component * + container_activate_component (Container *container, char *component_goad_id) + { + Component *component; + BonoboClientSite *client_site; + BonoboObjectClient *server; + + /* + * The ClientSite is the container-side point of contact for + * the Embeddable. So there is a one-to-one correspondence + * between BonoboClientSites and BonoboEmbeddables. */ + client_site = bonobo_client_site_new (container->container); + + /* + * A BonoboObjectClient is a simple wrapper for a remote + * BonoboObject (a server supporting Bonobo::Unknown). + */ + server = container_launch_component (client_site, container->container, + component_goad_id); + if (server == NULL) { + char *error_msg; + + error_msg = g_strdup_printf (_("Could not launch Embeddable %s!"), + component_goad_id); + gnome_warning_dialog (error_msg); + g_free (error_msg); + + return NULL; + } + + /* + * Create the internal data structure which we will use to + * keep track of this component. + */ + component = g_new0 (Component, 1); + component->container = container; + component->client_site = client_site; + component->server = server; + + container_set_view (container, component); + + return component; + } + + static void + filenames_dropped (GtkWidget * widget, + GdkDragContext *context, + gint x, + gint y, + GtkSelectionData *selection_data, + guint info, + guint time, + Container *container) + { + GList *names, *tmp_list; + + names = gnome_uri_list_extract_filenames ((char *)selection_data->data); + tmp_list = names; + + while (tmp_list) { + const char *fname = (const char *)tmp_list->data; + + if (fname) { + if (container->view_widget) + container = container_new (fname); + else + open_pdf (container, fname); + } + + tmp_list = g_list_next (tmp_list); + } + } } -static void -file_open_cmd (GtkWidget *widget, Application *app) +static Container * +container_new (const char *fname) { - GtkFileSelection *fsel; - gboolean accepted = FALSE; - - fsel = GTK_FILE_SELECTION (gtk_file_selection_new (_("Load file"))); - gtk_window_set_modal (GTK_WINDOW (fsel), TRUE); - - gtk_window_set_transient_for (GTK_WINDOW (fsel), - GTK_WINDOW (app->app)); + Container *container; + static GtkTargetEntry drag_types[] = + { + { "text/uri-list", 0, 0 }, + }; + static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types [0]); + BonoboUIContainer *ui_container; + + container = g_new0 (Container, 1); - /* Connect the signals for Ok and Cancel */ - gtk_signal_connect (GTK_OBJECT (fsel->ok_button), "clicked", - GTK_SIGNAL_FUNC (set_ok), &accepted); - gtk_signal_connect (GTK_OBJECT (fsel->cancel_button), "clicked", - GTK_SIGNAL_FUNC (gtk_main_quit), NULL); - gtk_window_set_position (GTK_WINDOW (fsel), GTK_WIN_POS_MOUSE); + container->app = bonobo_window_new ("pdf-viewer", + "GNOME PDF viewer"); - /* - * Make sure that we quit the main loop if the window is destroyed - */ - gtk_signal_connect (GTK_OBJECT (fsel), "delete_event", - GTK_SIGNAL_FUNC (file_dialog_delete_event), NULL); - - /* Run the dialog */ - gtk_widget_show (GTK_WIDGET (fsel)); - gtk_grab_add (GTK_WIDGET (fsel)); - gtk_main (); - - if (accepted) { - char *name = gtk_file_selection_get_filename (fsel); - - if (name [strlen (name)-1] != '/') { - if (app->contains_pdf) - app = application_new (); - char *fname = g_strdup (name); - open_pdf (app, fname); - g_free (fname); - } else { - GtkWidget *dialog; - dialog = gnome_message_box_new ("Can't open a directory", - GNOME_MESSAGE_BOX_ERROR, - GNOME_STOCK_BUTTON_OK, NULL); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), - GTK_WINDOW (app->app)); - gnome_dialog_run (GNOME_DIALOG (dialog)); - } - } + gtk_drag_dest_set (container->app, + GTK_DEST_DEFAULT_ALL, + drag_types, n_drag_types, + GDK_ACTION_COPY); - gtk_widget_destroy (GTK_WIDGET (fsel)); -} + gtk_signal_connect (GTK_OBJECT(container->app), + "drag_data_received", + GTK_SIGNAL_FUNC(filenames_dropped), + (gpointer)container); -static void -close_cmd (GtkWidget *widget, Application *app) -{ - application_destroy (app); -} + gtk_window_set_default_size (GTK_WINDOW (container->app), 600, 600); + gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE); -static void -exit_cmd (void) -{ - applications_destroy (); -} + container->container = bonobo_item_container_new (); + container->view_widget = NULL; + container->slot = gtk_event_box_new (); + gtk_widget_show (container->slot); -static GnomeUIInfo container_file_menu [] = { - GNOMEUIINFO_MENU_OPEN_ITEM (file_open_cmd, NULL), - GNOMEUIINFO_SEPARATOR, - GNOMEUIINFO_MENU_CLOSE_ITEM(close_cmd, NULL), - GNOMEUIINFO_SEPARATOR, - GNOMEUIINFO_MENU_EXIT_ITEM (exit_cmd, NULL), - GNOMEUIINFO_END -}; + bonobo_window_set_contents (BONOBO_WINDOW(container->app), + GTK_WIDGET (container->slot)); + gtk_widget_show_all (container->slot); -static GnomeUIInfo container_main_menu [] = { - GNOMEUIINFO_MENU_FILE_TREE (container_file_menu), - GNOMEUIINFO_END -}; + gtk_object_set_data (GTK_OBJECT (container->app), "container_data", container); + gtk_signal_connect (GTK_OBJECT (container->app), "delete_event", + GTK_SIGNAL_FUNC (container_destroy_cb), container); -static Application * -application_new (void) -{ - Application *app; - GnomeUIHandlerMenuItem *menu_list; + ui_container = bonobo_ui_container_new (); + bonobo_ui_container_set_win (ui_container, BONOBO_WINDOW(container->app)); - app = g_new0 (Application, 1); - app->app = gnome_app_new ("gpdf", - "GNOME PDF viewer"); - app->container = GNOME_CONTAINER (gnome_container_new ()); - app->contains_pdf = FALSE; + container->ui_component = bonobo_ui_component_new ("gpdf"); + bonobo_ui_component_set_container ( + container->ui_component, + bonobo_object_corba_objref (BONOBO_OBJECT (ui_container))); - app->box = gtk_vbox_new (FALSE, 0); - gtk_widget_show (app->box); - gnome_app_set_contents (GNOME_APP (app->app), app->box); + bonobo_ui_component_add_verb_list_with_data ( + container->ui_component, verbs, container); - /* - * Create the menus. - */ - app->uih = gnome_ui_handler_new (); + bonobo_ui_util_set_ui (container->ui_component, DATADIR, "gpdf-ui.xml", "gpdf"); - gnome_ui_handler_set_app (app->uih, GNOME_APP (app->app)); - gnome_ui_handler_create_menubar (app->uih); + gtk_widget_show (container->app); - menu_list = gnome_ui_handler_menu_parse_uiinfo_list_with_data (container_main_menu, app); - gnome_ui_handler_menu_add_list (app->uih, "/", menu_list); - gnome_ui_handler_menu_free_list (menu_list); + containers = g_list_append (containers, container); -/* gnome_ui_handler_create_toolbar (app->uih, "Common"); - gnome_ui_handler_toolbar_new_item (app->uih, - "/Common/item 1", - "Container-added Item 1", "I am the container. Hear me roar.", - 0, GNOME_UI_HANDLER_PIXMAP_NONE, NULL, 0, 0, - NULL, NULL);*/ + if (fname) + if (!open_pdf (container, fname)) { + container_destroy (container); + return NULL; + } - gtk_widget_show (app->app); + gtk_widget_show (container->app); - apps = g_list_append (apps, app); - return app; + return container; } int -main (int argc, char *argv []) +main (int argc, char **argv) { - Application *app; - char **view_files = NULL; - - if (argc != 1){ - server_goadid = argv [1]; - } - - CORBA_exception_init (&ev); - - gnome_CORBA_init_with_popt_table ("PDFViewer", "0.0.1", - &argc, argv, - gpdf_popt_options, 0, &ctx, - GNORBA_INIT_SERVER_FUNC, &ev); - orb = gnome_CORBA_ORB (); - - if (bonobo_init (orb, NULL, NULL) == FALSE) - g_error (_("Can not bonobo_init\n")); - - app = application_new (); - - view_files = poptGetArgs (ctx); - - /* Load files */ - if (view_files) { - int i; - for (i = 0; view_files[i]; i++) { - if (app->contains_pdf) - app = application_new (); - open_pdf (app, view_files[i]); - } - } - - poptFreeContext (ctx); - - gtk_main (); - - CORBA_exception_free (&ev); + CORBA_Environment ev; + CORBA_ORB orb; + const char **view_files = NULL; + gboolean loaded; + int i; + + CORBA_exception_init (&ev); + + + gnomelib_register_popt_table (oaf_popt_options, "OAF"); + gnome_init_with_popt_table("PDFViewer", "0.0.1", + argc, argv, + gpdf_popt_options, 0, &ctx); + orb = oaf_init (argc, argv); + + CORBA_exception_free (&ev); + + if (bonobo_init (orb, NULL, NULL) == FALSE) + g_error (_("Could not initialize Bonobo!\n")); + bonobo_activate (); + + view_files = poptGetArgs (ctx); + + /* Load files */ + i = 0; + loaded = FALSE; + if (view_files) { + for (i = 0; view_files[i]; i++) + if (container_new (view_files[i])) { + loaded = TRUE; + while (gtk_events_pending ()) + gtk_main_iteration (); + } + } + if ((i == 0) || !loaded) + container_new (NULL); + + poptFreeContext (ctx); + + gtk_main (); - return 0; + return 0; }