#include "config.h"
#include "BonoboStream.h"
+#define PDF_DEBUG 0
+
GBool printCommands = gFalse;
CORBA_Environment ev;
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
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);
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;
{
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);
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;
}
/*
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;
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;
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);
TRUE, 0, 0,
w, h);
- return pixmap;
+ view_data->pixmap = pixmap;
}
static gboolean
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
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.
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");
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;
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;
}
if (!bed)
return NULL;
+#if PDF_DEBUG > 0
printf ("Created new bonobo object %p\n", bed);
+#endif
/*
* Creates the BonoboObject server
*/
/* 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;
}
#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,
{ 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;
GnomeViewFrame *active_view_frame;
GtkWidget *app;
- GtkWidget *vbox;
+ GtkWidget *view_widget;
} Container;
typedef struct {
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);
};
extern "C" {
- static void
+ static gboolean
open_pdf (Container *container, const char *name)
{
GnomeObjectClient *object;
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);
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);
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_Unknown_unref (persist, &ev);
CORBA_Object_release (persist, &ev);
CORBA_exception_free (&ev);
-/* app->contains_pdf = TRUE; */
+ return TRUE;
}
static void
}
static void
- container_open_cmd (GtkWidget *widget, Container *app)
+ container_open_cmd (GtkWidget *widget, Container *container)
{
GtkFileSelection *fsel;
gboolean accepted = FALSE;
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",
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;
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));
}
}
}
static void
-component_add_view (Component *component)
+container_set_view (Container *container, Component *component)
{
GnomeViewFrame *view_frame;
GtkWidget *view_widget;
* 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
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,
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)
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;
}
gnome_ui_handler_menu_free_list (menu_list);
}
-static void
-container_create (void)
+static Container *
+container_new (const char *fname)
{
Container *container;
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
* 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;
}