X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=inline;f=pdf%2Fxpdf%2Fgpdf.cc;h=e9a6f8410e8ab0f460cc90d22387bbccfcec204a;hb=4d3649a5c59f18447a0550c85d83b2976d9fdf6c;hp=ba956e437d5ee59d6f7203a3a681656289d7eb4e;hpb=0a493d7b95ccfb0303844ad72c55918688a0123c;p=evince.git diff --git a/pdf/xpdf/gpdf.cc b/pdf/xpdf/gpdf.cc index ba956e43..e9a6f841 100644 --- a/pdf/xpdf/gpdf.cc +++ b/pdf/xpdf/gpdf.cc @@ -3,7 +3,6 @@ * * Author: * Michael Meeks - * */ #include #include @@ -12,34 +11,20 @@ extern "C" { #define GString G_String #include + +#if USING_OAF +#include +#else #include +#endif + #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" poptContext ctx; gint gpdf_debug=0; @@ -55,23 +40,21 @@ 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 { - GnomeContainer *container; - GnomeUIHandler *uih; + BonoboContainer *container; + BonoboUIHandler *uih; - GnomeViewFrame *active_view_frame; - - GtkWidget *app; - GtkWidget *view_widget; - Component *component; - gdouble zoom; + GtkWidget *app; + GtkWidget *slot; + GtkWidget *view_widget; + Component *component; }; struct _Component { Container *container; - GnomeClientSite *client_site; - GnomeViewFrame *view_frame; - GnomeObjectClient *server; + BonoboClientSite *client_site; + BonoboViewFrame *view_frame; + BonoboObjectClient *server; }; GList *containers = NULL; @@ -84,10 +67,8 @@ extern "C" { 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 Component *container_activate_component (Container *container, char *component_goad_id); - static void zoom_in_cmd (GtkWidget *widget, Container *container); - static void zoom_out_cmd (GtkWidget *widget, Container *container); - static void zoom_set (Container *container); } /* @@ -102,19 +83,14 @@ static GnomeUIInfo container_file_menu [] = { GNOMEUIINFO_END }; -static GnomeUIInfo container_menu_zoom [] = { - { GNOME_APP_UI_ITEM, N_("_Zoom in"), - N_("Increase the size of objects in the PDF"), - zoom_in_cmd }, - { GNOME_APP_UI_ITEM, N_("_Zoom out"), - N_("Decrease the size of objects in the PDF"), - zoom_out_cmd }, +static GnomeUIInfo container_help_menu [] = { + GNOMEUIINFO_MENU_ABOUT_ITEM(container_about_cmd, NULL), GNOMEUIINFO_END }; static GnomeUIInfo container_main_menu [] = { GNOMEUIINFO_MENU_FILE_TREE (container_file_menu), - { GNOME_APP_UI_SUBTREE, N_("_Zoom"), NULL, container_menu_zoom }, + GNOMEUIINFO_MENU_HELP_TREE (container_help_menu), GNOMEUIINFO_END }; @@ -131,33 +107,38 @@ extern "C" { static gboolean open_pdf (Container *container, const char *name) { - GnomeObjectClient *object; - GnomeStream *stream; - GNOME_PersistStream persist; + 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, "bonobo-object:image-x-pdf"); +#if USING_OAF + comp = container_activate_component (container, "OAFIID:gpdf_component:892f2727-e2ec-423c-91ad-6f7b75fec6c8"); + +#else + comp = container_activate_component (container, "bonobo-object:application-x-pdf"); +#endif if (!comp || !(object = comp->server)) { gnome_error_dialog (_("Could not launch bonobo object.")); return FALSE; } CORBA_exception_init (&ev); - persist = GNOME_Unknown_query_interface ( - gnome_object_corba_objref (GNOME_OBJECT (object)), - "IDL:GNOME/PersistStream:1.0", &ev); + persist = Bonobo_Unknown_query_interface ( + 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 is well broken."); + gnome_error_dialog ("Panic: component doesn't implement PersistStream."); return FALSE; } - stream = gnome_stream_fs_open (name, GNOME_Storage_READ); + stream = bonobo_stream_fs_open (name, Bonobo_Storage_READ); if (stream == NULL) { char *err = g_strconcat (_("Could not open "), name, NULL); @@ -166,14 +147,16 @@ extern "C" { return FALSE; } - GNOME_PersistStream_load (persist, - (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev); + Bonobo_PersistStream_load (persist, + (Bonobo_Stream) bonobo_object_corba_objref (BONOBO_OBJECT (stream)), + "application/pdf", + &ev); - - - GNOME_Unknown_unref (persist, &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; } @@ -228,8 +211,10 @@ extern "C" { char *fname = g_strdup (name); if (container->view_widget) /* any sort of MDI sucks :-] */ container = container_new (fname); - else - open_pdf (container, fname); + else { + if (!open_pdf (container, fname)) + container_destroy (container); + } g_free (fname); } else { GtkWidget *dialog; @@ -245,20 +230,76 @@ extern "C" { 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); - gtk_widget_destroy (cont->app); + 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 @@ -268,300 +309,122 @@ extern "C" { 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); - container->zoom *= 1.4; - zoom_set (container); - } - - static void - zoom_out_cmd (GtkWidget *widget, Container *container) - { - g_return_if_fail (container != NULL); - container->zoom /= 1.4; - zoom_set (container); - } +static void +container_about_cmd (GtkWidget *widget, Container *container) +{ + 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; - static void - component_user_activate_request_cb (GnomeViewFrame *view_frame, gpointer data) - { - Component *component = (Component *) data; - Container *container = component->container; - - /* - * If there is a - * If there is already an active View, deactivate it. - */ - if (container->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 (container->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 (container->active_view_frame != NULL) - gnome_view_frame_set_covered (container->active_view_frame, TRUE); - - container->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. - */ - gnome_view_frame_view_activate (view_frame); - } + for (i = 0; authors[i] != NULL; i++) + authors [i] = _(authors [i]); +#endif - 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; - } - } + about = gnome_about_new (_("GPDF"), xpdfVersion, + _("(C) 1996-1999 Derek B. Noonburg."), + authors, NULL, 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); - } + gnome_dialog_set_parent (GNOME_DIALOG (about), GTK_WINDOW (container->app)); + gnome_dialog_set_close (GNOME_DIALOG (about), TRUE); + gtk_widget_show (about); +} } static void container_set_view (Container *container, Component *component) { - GnomeViewFrame *view_frame; + BonoboViewFrame *view_frame; GtkWidget *view_widget; /* * Create the remote view and the local ViewFrame. */ - view_frame = gnome_client_site_new_view (component->client_site); + view_frame = bonobo_client_site_new_view (component->client_site, + bonobo_object_corba_objref (BONOBO_OBJECT ( + container->uih))); 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); + 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; -/* gtk_box_pack_start (GTK_BOX (container->app), view_widget, - FALSE, FALSE, 5);*/ - gnome_app_set_contents (GNOME_APP (container->app), view_widget); - /* - * The "user_activate" signal will be emitted when the user - * double clicks on the "cover". The cover is a transparent - * window which sits on top of the component and keeps any - * events (mouse, keyboard) from reaching it. When the user - * double clicks on the cover, the container (that's us) - * can choose to activate the component. - */ - gtk_signal_connect (GTK_OBJECT (view_frame), "user_activate", - GTK_SIGNAL_FUNC (component_user_activate_request_cb), 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); + gtk_container_add (GTK_CONTAINER (container->slot), view_widget); /* - * The "user_context" signal is emitted when the user right - * clicks on the wrapper. We use it to pop up a verb menu. + * Activate it ( get it to merge menus etc. ) */ - gtk_signal_connect (GTK_OBJECT (view_frame), "user_context", - GTK_SIGNAL_FUNC (component_user_context_cb), component); + bonobo_view_frame_view_activate (view_frame); + bonobo_view_frame_set_covered (view_frame, FALSE); - /* - * Show the component. - */ - gtk_widget_show_all (view_widget); + gtk_widget_show_all (GTK_WIDGET (container->slot)); } -static GnomeObjectClient * -container_launch_component (GnomeClientSite *client_site, - GnomeContainer *container, +static BonoboObjectClient * +container_launch_component (BonoboClientSite *client_site, + BonoboContainer *container, char *component_goad_id) { - GnomeObjectClient *object_server; + BonoboObjectClient *object_server; /* * Launch the component. */ - object_server = gnome_object_activate_with_goad_id ( - NULL, component_goad_id, 0, NULL); + object_server = bonobo_object_activate (component_goad_id, 0); if (object_server == NULL) return NULL; /* * Bind it to the local ClientSite. Every embedded component - * has a local GnomeClientSite object which serves as a + * 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 (!gnome_client_site_bind_embeddable (client_site, object_server)) { - gnome_object_unref (GNOME_OBJECT (object_server)); + if (!bonobo_client_site_bind_embeddable (client_site, object_server)) { + bonobo_object_unref (BONOBO_OBJECT (object_server)); return NULL; } /* - * The GnomeContainer object maintains a list of the + * The BonoboContainer 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)); + bonobo_container_add (container, BONOBO_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) -{ - CORBA_Environment ev; - CORBA_Object requested_interface; - - CORBA_exception_init (&ev); - - requested_interface = GNOME_Unknown_query_interface ( - gnome_object_corba_objref (obj), interface, &ev); - - CORBA_exception_free (&ev); - - if (!CORBA_Object_is_nil(requested_interface, &ev) && - ev._major == CORBA_NO_EXCEPTION) - { - /* Get rid of the interface we've been passed */ - CORBA_Object_release (requested_interface, &ev); - return TRUE; - } - - return FALSE; -} - extern "C" { static Component * container_activate_component (Container *container, char *component_goad_id) { Component *component; - GnomeClientSite *client_site; - GnomeObjectClient *server; + 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 GnomeClientSites and GnomeEmbeddables. */ - client_site = gnome_client_site_new (container->container); + * between BonoboClientSites and BonoboEmbeddables. */ + client_site = bonobo_client_site_new (container->container); /* - * A GnomeObjectClient is a simple wrapper for a remote - * GnomeObject (a server supporting GNOME::Unknown). + * 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); @@ -589,73 +452,125 @@ extern "C" { 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 container_create_menus (Container *container) { - GnomeUIHandlerMenuItem *menu_list; + BonoboUIHandlerMenuItem *menu_list; - gnome_ui_handler_create_menubar (container->uih); + bonobo_ui_handler_create_menubar (container->uih); /* * Create the basic menus out of UIInfo structures. */ - menu_list = gnome_ui_handler_menu_parse_uiinfo_list_with_data (container_main_menu, container); - gnome_ui_handler_menu_add_list (container->uih, "/", menu_list); - gnome_ui_handler_menu_free_list (menu_list); + menu_list = bonobo_ui_handler_menu_parse_uiinfo_list_with_data (container_main_menu, container); + bonobo_ui_handler_menu_add_list (container->uih, "/", menu_list); + bonobo_ui_handler_menu_free_list (menu_list); } static void container_create_toolbar (Container *container) { - GnomeUIHandlerToolbarItem *toolbar; + BonoboUIHandlerToolbarItem *toolbar; - gnome_ui_handler_create_toolbar (container->uih, "pdf"); - toolbar = gnome_ui_handler_toolbar_parse_uiinfo_list (container->uih, container_toolbar); - gnome_ui_handler_toolbar_add_list (container->uih, "/", toolbar); - gnome_ui_handler_toolbar_free_list (toolbar); + bonobo_ui_handler_create_toolbar (container->uih, "pdf"); + toolbar = bonobo_ui_handler_toolbar_parse_uiinfo_list_with_data (container_toolbar, container); + bonobo_ui_handler_toolbar_add_list (container->uih, "/pdf/", toolbar); + bonobo_ui_handler_toolbar_free_list (toolbar); } static Container * container_new (const char *fname) { Container *container; - + static GtkTargetEntry drag_types[] = + { + { "text/uri-list", 0, 0 }, + }; + static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types [0]); + container = g_new0 (Container, 1); - container->app = gnome_app_new ("pdf-viewer", - "GNOME PDF viewer"); - container->zoom = 43.0; + container->app = gnome_app_new ("pdf-viewer", + "GNOME PDF viewer"); + + gtk_drag_dest_set (container->app, + GTK_DEST_DEFAULT_ALL, + drag_types, n_drag_types, + GDK_ACTION_COPY); - gtk_window_set_default_size (GTK_WINDOW (container->app), 400, 400); + gtk_signal_connect (GTK_OBJECT(container->app), + "drag_data_received", + GTK_SIGNAL_FUNC(filenames_dropped), + (gpointer)container); + + gtk_window_set_default_size (GTK_WINDOW (container->app), 600, 600); gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE); - container->container = gnome_container_new (); + container->container = bonobo_container_new (); container->view_widget = NULL; + container->slot = gtk_event_box_new (); + gtk_widget_show (container->slot); + + gnome_app_set_contents (GNOME_APP (container->app), GTK_WIDGET (container->slot)); + + 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); /* - * Create the GnomeUIHandler object which will be used to + * Create the BonoboUIHandler object which will be used to * create the container's menus and toolbars. The UIHandler * also creates a CORBA server which embedded components use * to do menu/toolbar merging. */ - container->uih = gnome_ui_handler_new (); - gnome_ui_handler_set_app (container->uih, GNOME_APP (container->app)); + container->uih = bonobo_ui_handler_new (); + bonobo_ui_handler_set_app (container->uih, GNOME_APP (container->app)); container_create_menus (container); container_create_toolbar (container); gtk_widget_show_all (container->app); + containers = g_list_append (containers, container); + if (fname) if (!open_pdf (container, fname)) { container_destroy (container); return NULL; } - containers = g_list_append (containers, container); - gtk_widget_show_all (container->app); return container; @@ -665,20 +580,30 @@ int main (int argc, char **argv) { CORBA_Environment ev; - CORBA_ORB orb; - char **view_files = NULL; - int i; + CORBA_ORB orb; + const char **view_files = NULL; + gboolean loaded; + int i; CORBA_exception_init (&ev); + +#if USING_OAF + 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); +#else gnome_CORBA_init_with_popt_table ("PDFViewer", "0.0.1", &argc, argv, gpdf_popt_options, 0, &ctx, GNORBA_INIT_SERVER_FUNC, &ev); - CORBA_exception_free (&ev); - orb = gnome_CORBA_ORB (); +#endif + + CORBA_exception_free (&ev); if (bonobo_init (orb, NULL, NULL) == FALSE) g_error (_("Could not initialize Bonobo!\n")); @@ -688,11 +613,16 @@ main (int argc, char **argv) /* Load files */ i = 0; + loaded = FALSE; if (view_files) { for (i = 0; view_files[i]; i++) - container_new (view_files[i]); + if (container_new (view_files[i])) { + loaded = TRUE; + while (gtk_events_pending ()) + gtk_main_iteration (); + } } - if (i == 0) + if ((i == 0) || !loaded) container_new (NULL); poptFreeContext (ctx); @@ -701,4 +631,3 @@ main (int argc, char **argv) return 0; } -