X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=pdf%2Fxpdf%2Fgpdf.cc;h=e61929442b9ec59b35c82276f145b8082308b945;hb=de00c24f934328d7b9067c931db697a7172b768d;hp=7a4963479d4eb094706d86f2d1c5fa166a67a35d;hpb=41bb7a29844698ac3c501477df902c1d95e80adb;p=evince.git diff --git a/pdf/xpdf/gpdf.cc b/pdf/xpdf/gpdf.cc index 7a496347..e6192944 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,37 +50,44 @@ const struct poptOption gpdf_popt_options [] = { { NULL, '\0', 0, NULL, 0 } }; -typedef struct { - GnomeContainer *container; - GnomeUIHandler *uih; - - GnomeViewFrame *active_view_frame; - - GtkWidget *app; - GtkWidget *vbox; -} Container; +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 { + GnomeContainer *container; + GnomeUIHandler *uih; + + GnomeViewFrame *active_view_frame; + + GtkWidget *app; + GtkWidget *view_widget; + Component *component; + gdouble zoom; +}; -typedef struct { +struct _Component { Container *container; GnomeClientSite *client_site; GnomeViewFrame *view_frame; GnomeObjectClient *server; - - GtkWidget *views_hbox; -} Component; +}; 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); static void container_exit_cmd (void); 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); } /* @@ -95,13 +102,33 @@ 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 }, + 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_END +}; + +static GnomeUIInfo container_toolbar [] = { + GNOMEUIINFO_ITEM_STOCK ( + N_("Open"), N_("Opens an existing workbook"), + container_open_cmd, GNOME_STOCK_PIXMAP_OPEN), + + GNOMEUIINFO_SEPARATOR, GNOMEUIINFO_END }; extern "C" { - static void + static gboolean open_pdf (Container *container, const char *name) { GnomeObjectClient *object; @@ -110,10 +137,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 +154,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,16 +163,18 @@ 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, (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev); + + GNOME_Unknown_unref (persist, &ev); CORBA_Object_release (persist, &ev); CORBA_exception_free (&ev); -/* app->contains_pdf = TRUE; */ + return TRUE; } static void @@ -160,7 +192,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 +201,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 +225,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 +237,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)); } } @@ -235,6 +268,35 @@ 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 component_user_activate_request_cb (GnomeViewFrame *view_frame, gpointer data) { @@ -352,7 +414,7 @@ extern "C" { } static void -component_add_view (Component *component) +container_set_view (Container *container, Component *component) { GnomeViewFrame *view_frame; GtkWidget *view_widget; @@ -360,7 +422,7 @@ component_add_view (Component *component) /* * Create the remote view and the local ViewFrame. */ - view_frame = gnome_client_site_embeddable_new_view (component->client_site); + view_frame = gnome_client_site_new_view (component->client_site); component->view_frame = view_frame; /* @@ -369,15 +431,17 @@ 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; + 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 @@ -417,29 +481,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 void -component_load_pf_cb (GtkWidget *button, gpointer data) -{ -} - -static void -component_load_ps_cb (GtkWidget *button, gpointer data) -{ -} - -static void -component_destroy_cb (GtkWidget *button, gpointer data) -{ -} - static GnomeObjectClient * container_launch_component (GnomeClientSite *client_site, GnomeContainer *container, @@ -451,7 +492,7 @@ container_launch_component (GnomeClientSite *client_site, * Launch the component. */ object_server = gnome_object_activate_with_goad_id ( - NULL, component_goad_id, 0, NULL); + NULL, component_goad_id, GOAD_ACTIVATE_SHLIB, NULL); if (object_server == NULL) return NULL; @@ -504,19 +545,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) @@ -557,14 +585,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; } @@ -586,25 +607,32 @@ container_create_menus (Container *container) } static void -container_create (void) +container_create_toolbar (Container *container) +{ + GnomeUIHandlerToolbarItem *toolbar; + + gnome_ui_handler_create_toolbar (container->uih, "pdf"); + toolbar = gnome_ui_handler_toolbar_parse_uiinfo_list_with_data (container_toolbar, container); + gnome_ui_handler_toolbar_add_list (container->uih, "/", toolbar); + gnome_ui_handler_toolbar_free_list (toolbar); +} + +static Container * +container_new (const char *fname) { Container *container; container = g_new0 (Container, 1); - container->app = gnome_app_new ("sample-container", - "Sample Bonobo Container"); + container->app = gnome_app_new ("pdf-viewer", + "GNOME PDF viewer"); + container->zoom = 43.0; 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 @@ -615,34 +643,62 @@ container_create (void) container->uih = gnome_ui_handler_new (); gnome_ui_handler_set_app (container->uih, GNOME_APP (container->app)); - /* - * Create the menus. - */ - container_create_menus (container); - + container_create_menus (container); + container_create_toolbar (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); + 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); - gnome_CORBA_init ("gnome_xpdf_viewer", "0.1", &argc, argv, 0, &ev); + CORBA_exception_free (&ev); - CORBA_exception_free (&ev); + orb = gnome_CORBA_ORB (); - orb = gnome_CORBA_ORB (); + if (bonobo_init (orb, NULL, NULL) == FALSE) + g_error (_("Could not initialize Bonobo!\n")); + bonobo_activate (); - if (bonobo_init (orb, NULL, NULL) == FALSE) - g_error (_("Could not initialize Bonobo!\n")); + view_files = poptGetArgs (ctx); - container_create (); - - gtk_main (); + /* 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); - return 0; + gtk_main (); + + return 0; } +