From 93f5b3fbce4ae555c6783410d55bdd394e30b63a Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Sun, 22 Aug 1999 19:14:32 +0000 Subject: [PATCH] Cleaned loads of rubbish from component bits, Add files I forget (sorry). --- pdf/xpdf/bonobo-image-x-pdf.cc | 109 +++++++++++++++++------- pdf/xpdf/gpdf.cc | 148 ++++++++++++++++----------------- 2 files changed, 151 insertions(+), 106 deletions(-) diff --git a/pdf/xpdf/bonobo-image-x-pdf.cc b/pdf/xpdf/bonobo-image-x-pdf.cc index df640eef..5c452ee6 100644 --- a/pdf/xpdf/bonobo-image-x-pdf.cc +++ b/pdf/xpdf/bonobo-image-x-pdf.cc @@ -39,6 +39,8 @@ extern "C" { #include "config.h" #include "BonoboStream.h" +#define PDF_DEBUG 0 + GBool printCommands = gFalse; CORBA_Environment ev; @@ -76,7 +78,7 @@ typedef struct { extern "C" { static void realize_drawing_areas (bed_t *bed); - static GdkPixmap *setup_pixmap (bed_t *doc, view_data_t *view, GdkWindow *window); + static void setup_pixmap (bed_t *doc, view_data_t *view, GdkWindow *window); } static void @@ -120,8 +122,8 @@ redraw_view (view_data_t *view_data, GdkRectangle *rect) static void render_page (view_data_t *view_data) { - view_data->pixmap = setup_pixmap (view_data->bed, view_data, - view_data->win); + setup_pixmap (view_data->bed, view_data, + view_data->win); view_data->bed->pdf->displayPage(view_data->out, view_data->page, view_data->zoom, 0, gTrue); @@ -133,7 +135,9 @@ redraw_view_all (view_data_t *view_data) GdkRectangle rect; g_return_if_fail (view_data != NULL); +#if PDF_DEBUG > 0 printf ("Redraw view of page %d\n", view_data->page); +#endif render_page (view_data); rect.x = 0; rect.y = 0; @@ -157,7 +161,7 @@ redraw_all (bed_t *bed) { GList *l; - for (l = bed->views; l; l = l->next){ + for (l = bed->views; l; l = l->next) { GdkRectangle rect; view_data_t *view_data = (view_data_t *)l->data; configure_size (view_data); @@ -172,16 +176,30 @@ save_image (GnomePersistStream *ps, GNOME_Stream stream, void *data) return -1; } -static void +/* + * different size ? + */ +static gboolean setup_size (bed_t *doc, view_data_t *view) { + int w, h; + gboolean same; + if (!doc || !view || !doc->pdf) { view->w = 320; view->h = 200; - return; + return FALSE; } - view->w = (int)((doc->pdf->getPageWidth (view->page) * view->zoom) / 72.0); - view->h = (int)((doc->pdf->getPageHeight (view->page) * view->zoom) / 72.0); + w = (int)((doc->pdf->getPageWidth (view->page) * view->zoom) / 72.0); + h = (int)((doc->pdf->getPageHeight (view->page) * view->zoom) / 72.0); + if (view->w == w && view->h == h) + same = TRUE; + else + same = FALSE; + view->w = w; + view->h = h; + + return same; } /* @@ -208,13 +226,17 @@ load_image_from_stream (GnomePersistStream *ps, GNOME_Stream stream, void *data) CORBA_Object_duplicate (stream, &ev); g_return_val_if_fail (ev._major == CORBA_NO_EXCEPTION, 0); +#if PDF_DEBUG > 0 printf ("Loading PDF from persiststream\n"); +#endif bed->stream = stream; BonoboStream *bs = new BonoboStream (stream); GString *st = new GString ("Bonobo.pdf"); bed->pdf = new PDFDoc (bs, st); +#if PDF_DEBUG > 0 printf ("Done load\n"); +#endif if (!(bed->pdf->isOk())) { g_warning ("Duff pdf data\n"); delete bed->pdf; @@ -255,8 +277,8 @@ extern "C" { g_free (bed); } - static GdkPixmap * - setup_pixmap (bed_t *doc, view_data_t *view, GdkWindow *window) + static void + setup_pixmap (bed_t *doc, view_data_t *view_data, GdkWindow *window) { GdkGCValues gcValues; GdkGC *strokeGC; @@ -264,21 +286,27 @@ extern "C" { int w, h; GdkPixmap *pixmap = NULL; - g_return_val_if_fail (doc != NULL, NULL); - g_return_val_if_fail (view != NULL, NULL); - g_return_val_if_fail (doc->pdf != NULL, NULL); + g_return_if_fail (doc != NULL); + g_return_if_fail (doc->pdf != NULL); + g_return_if_fail (view_data != NULL); pdf = doc->pdf; - setup_size (doc, view); + if (setup_size (doc, view_data) && + view_data->pixmap) { +#if PDF_DEBUG > 0 + printf ("No need to re-init output device\n"); +#endif + return; + } + + w = view_data->w; + h = view_data->h; - w = view->w; - h = view->h; - pixmap = gdk_pixmap_new (window, w, h, -1); - gdk_color_white (gtk_widget_get_default_colormap(), &view->paper); - view->out = new GOutputDev (pixmap, view->paper, window); + gdk_color_white (gtk_widget_get_default_colormap(), &view_data->paper); + view_data->out = new GOutputDev (pixmap, view_data->paper, window); gdk_color_white (gtk_widget_get_default_colormap (), &gcValues.foreground); gdk_color_black (gtk_widget_get_default_colormap (), &gcValues.background); @@ -292,7 +320,7 @@ extern "C" { TRUE, 0, 0, w, h); - return pixmap; + view_data->pixmap = pixmap; } static gboolean @@ -446,14 +474,9 @@ extern "C" { drawing_area_realize (GtkWidget *drawing_area, view_data_t *view_data) { g_return_if_fail (view_data != NULL); - g_return_if_fail (view_data->bed != NULL); + g_return_if_fail (drawing_area != NULL); view_data->win = gtk_widget_get_parent_window (drawing_area); - if (!view_data->bed->pdf || - !view_data->pixmap) { - g_warning ("Failed to setup pixmap"); - return; - } } static int @@ -477,7 +500,9 @@ extern "C" { gnome_view_activate_notify (view, activate); +#if PDF_DEBUG > 0 printf ("View change activation to %d\n", activate); +#endif /* * If we were just activated, we merge in our menu entries. * If we were just deactivated, we remove them. @@ -518,10 +543,14 @@ extern "C" { GdkRectangle rect; gboolean changed = FALSE; - if (!g_strcasecmp (verb_name, "nextpage")) { - changed = next_page (view_data); + if (!g_strcasecmp (verb_name, "firstpage")) { + changed = first_page (view_data); } else if (!g_strcasecmp (verb_name, "prevpage")) { changed = prev_page (view_data); + } else if (!g_strcasecmp (verb_name, "nextpage")) { + changed = next_page (view_data); + } else if (!g_strcasecmp (verb_name, "lastpage")) { + changed = last_page (view_data); } else g_warning ("Unknown verb"); @@ -543,7 +572,9 @@ view_factory (GnomeEmbeddable *embeddable, bed_t *bed = (bed_t *)data; view_data_t *view_data = g_new (view_data_t, 1); +#if PDF_DEBUG > 0 printf ("Created new bonobo object view %p\n", view_data); +#endif view_data->scale = 1.0; view_data->bed = bed; @@ -590,10 +621,14 @@ view_factory (GnomeEmbeddable *embeddable, bed->views = g_list_prepend (bed->views, view_data); /* Verb handling */ - gnome_view_register_verb (view, "NextPage", + gnome_view_register_verb (view, "FirstPage", view_switch_page, view_data); gnome_view_register_verb (view, "PrevPage", view_switch_page, view_data); + gnome_view_register_verb (view, "NextPage", + view_switch_page, view_data); + gnome_view_register_verb (view, "LastPage", + view_switch_page, view_data); return view; } @@ -609,7 +644,9 @@ embeddable_factory (GnomeEmbeddableFactory *This, void *data) if (!bed) return NULL; +#if PDF_DEBUG > 0 printf ("Created new bonobo object %p\n", bed); +#endif /* * Creates the BonoboObject server */ @@ -647,13 +684,21 @@ embeddable_factory (GnomeEmbeddableFactory *This, void *data) /* Setup some verbs */ gnome_embeddable_add_verb (embeddable, - "NextPage", - _("_Next page"), - _("goto the next page")); + "FirstPage", + _("_First page"), + _("goto the first page")); gnome_embeddable_add_verb (embeddable, "PrevPage", _("_Previous page"), _("goto the previous page")); + gnome_embeddable_add_verb (embeddable, + "NextPage", + _("_Next page"), + _("goto the next page")); + gnome_embeddable_add_verb (embeddable, + "LastPage", + _("_Last page"), + _("goto the last page")); return (GnomeObject *) embeddable; } diff --git a/pdf/xpdf/gpdf.cc b/pdf/xpdf/gpdf.cc index d77db661..37112ae7 100644 --- a/pdf/xpdf/gpdf.cc +++ b/pdf/xpdf/gpdf.cc @@ -42,7 +42,7 @@ extern "C" { #include "config.h" poptContext ctx; -gint gpdf_debug=1; +gint gpdf_debug=0; const struct poptOption gpdf_popt_options [] = { { "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0, @@ -50,6 +50,8 @@ const struct poptOption gpdf_popt_options [] = { { NULL, '\0', 0, NULL, 0 } }; +/* NB. there is a 1 to 1 Container -> Component mapping, this + is due to how much MDI sucks; unutterably */ typedef struct { GnomeContainer *container; GnomeUIHandler *uih; @@ -57,7 +59,7 @@ typedef struct { GnomeViewFrame *active_view_frame; GtkWidget *app; - GtkWidget *vbox; + GtkWidget *view_widget; } Container; typedef struct { @@ -66,8 +68,6 @@ typedef struct { GnomeClientSite *client_site; GnomeViewFrame *view_frame; GnomeObjectClient *server; - - GtkWidget *views_hbox; } Component; GList *containers = NULL; @@ -75,7 +75,7 @@ GList *containers = NULL; * Static prototypes. */ extern "C" { - static Container *container_new (void); + 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); @@ -101,7 +101,7 @@ static GnomeUIInfo container_main_menu [] = { }; extern "C" { - static void + static gboolean open_pdf (Container *container, const char *name) { GnomeObjectClient *object; @@ -110,10 +110,13 @@ extern "C" { 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 (!comp || !(object = comp->server)) { gnome_error_dialog (_("Could not launch bonobo object.")); - return; + return FALSE; } CORBA_exception_init (&ev); @@ -124,7 +127,7 @@ extern "C" { if (ev._major != CORBA_NO_EXCEPTION || persist == CORBA_OBJECT_NIL) { gnome_error_dialog ("Panic: component is well broken."); - return; + return FALSE; } stream = gnome_stream_fs_open (name, GNOME_Storage_READ); @@ -133,7 +136,7 @@ extern "C" { char *err = g_strconcat (_("Could not open "), name, NULL); gnome_error_dialog_parented (err, GTK_WINDOW(container->app)); g_free (err); - return; + return FALSE; } GNOME_PersistStream_load (persist, @@ -142,7 +145,7 @@ extern "C" { GNOME_Unknown_unref (persist, &ev); CORBA_Object_release (persist, &ev); CORBA_exception_free (&ev); -/* app->contains_pdf = TRUE; */ + return TRUE; } static void @@ -160,7 +163,7 @@ extern "C" { } static void - container_open_cmd (GtkWidget *widget, Container *app) + container_open_cmd (GtkWidget *widget, Container *container) { GtkFileSelection *fsel; gboolean accepted = FALSE; @@ -169,7 +172,7 @@ extern "C" { gtk_window_set_modal (GTK_WINDOW (fsel), TRUE); gtk_window_set_transient_for (GTK_WINDOW (fsel), - GTK_WINDOW (app->app)); + GTK_WINDOW (container->app)); /* Connect the signals for Ok and Cancel */ gtk_signal_connect (GTK_OBJECT (fsel->ok_button), "clicked", @@ -193,10 +196,11 @@ extern "C" { 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); + if (container->view_widget) /* any sort of MDI sucks :-] */ + container = container_new (fname); + else + open_pdf (container, fname); g_free (fname); } else { GtkWidget *dialog; @@ -204,7 +208,7 @@ extern "C" { GNOME_MESSAGE_BOX_ERROR, GNOME_STOCK_BUTTON_OK, NULL); gnome_dialog_set_parent (GNOME_DIALOG (dialog), - GTK_WINDOW (app->app)); + GTK_WINDOW (container->app)); gnome_dialog_run (GNOME_DIALOG (dialog)); } } @@ -352,7 +356,7 @@ extern "C" { } static void -component_add_view (Component *component) +container_set_view (Container *container, Component *component) { GnomeViewFrame *view_frame; GtkWidget *view_widget; @@ -369,15 +373,16 @@ component_add_view (Component *component) * so that it can merge menu and toolbar items when it gets * activated. */ - gnome_view_frame_set_ui_handler (view_frame, component->container->uih); + 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); - gtk_box_pack_start (GTK_BOX (component->views_hbox), view_widget, - FALSE, FALSE, 5); - + container->view_widget = view_widget; +/* 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 @@ -417,14 +422,6 @@ component_add_view (Component *component) gtk_widget_show_all (view_widget); } -static void -component_new_view_cb (GtkWidget *button, gpointer data) -{ - Component *component = (Component *) data; - - component_add_view (component); -} - static GnomeObjectClient * container_launch_component (GnomeClientSite *client_site, GnomeContainer *container, @@ -489,19 +486,6 @@ gnome_object_has_interface (GnomeObject *obj, char *interface) return FALSE; } -static void -container_create_component_frame (Container *container, Component *component, char *name) -{ - /* - * This hbox will store all the views of the component. - */ - component->views_hbox = gtk_hbox_new (FALSE, 2); - - gtk_box_pack_start (GTK_BOX (container->vbox), component->views_hbox, - TRUE, FALSE, 5); - gtk_widget_show_all (component->views_hbox); -} - extern "C" { static Component * container_activate_component (Container *container, char *component_goad_id) @@ -542,14 +526,7 @@ extern "C" { component->client_site = client_site; component->server = server; - /* - * Now we have a GnomeEmbeddable bound to our local - * ClientSite. Here we create a little on-screen box to store - * the embeddable in, when the user adds views for it. - */ - container_create_component_frame (container, component, component_goad_id); - - component_add_view (component); + container_set_view (container, component); return component; } @@ -570,8 +547,8 @@ container_create_menus (Container *container) gnome_ui_handler_menu_free_list (menu_list); } -static void -container_create (void) +static Container * +container_new (const char *fname) { Container *container; @@ -583,13 +560,8 @@ container_create (void) gtk_window_set_default_size (GTK_WINDOW (container->app), 400, 400); gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE); - container->container = gnome_container_new (); - - /* - * This is the VBox we will stuff embedded components into. - */ - container->vbox = gtk_vbox_new (FALSE, 0); - gnome_app_set_contents (GNOME_APP (container->app), container->vbox); + container->container = gnome_container_new (); + container->view_widget = NULL; /* * Create the GnomeUIHandler object which will be used to @@ -604,30 +576,58 @@ container_create (void) * Create the menus. */ container_create_menus (container); - + gtk_widget_show_all (container->app); + + 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; } int main (int argc, char **argv) { - CORBA_Environment ev; - CORBA_ORB orb; - - CORBA_exception_init (&ev); - - gnome_CORBA_init ("gnome_xpdf_viewer", "0.1", &argc, argv, 0, &ev); - - CORBA_exception_free (&ev); + CORBA_Environment ev; + CORBA_ORB orb; + char **view_files = NULL; + int i; + + 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 (); + CORBA_exception_free (&ev); - if (bonobo_init (orb, NULL, NULL) == FALSE) - g_error (_("Could not initialize Bonobo!\n")); + orb = gnome_CORBA_ORB (); - container_create (); + if (bonobo_init (orb, NULL, NULL) == FALSE) + g_error (_("Could not initialize Bonobo!\n")); - gtk_main (); + view_files = poptGetArgs (ctx); - return 0; + /* Load files */ + i = 0; + if (view_files) { + for (i = 0; view_files[i]; i++) + container_new (view_files[i]); + } + if (i == 0) + container_new (NULL); + + poptFreeContext (ctx); + + gtk_main (); + + return 0; } -- 2.43.5