// gpdf.cc
//
// Copyright 1996 Derek B. Noonburg
-// Copyright 1999 Miguel de Icaza
// Copyright 1999 Michael Meeks.
+// Copyright 1999 Miguel de Icaza
//
//========================================================================
gint gpdf_debug;
poptContext ctx;
+struct DOC_ROOT {
+ GString *title;
+ PDFDoc *pdf;
+ GtkWidget *toplevel;
+ GtkWidget *table;
+ GnomeAppBar *appbar;
+ GtkDrawingArea *area;
+ GdkVisual *visual;
+ GdkPixmap *pixmap;
+ OutputDev *out;
+ GdkColor paper;
+};
+
+
+static void
+crummy_cmd (GtkWidget *widget, DOC_ROOT *tmp)
+{
+ printf ("Crummy\n");
+}
+
+
const struct poptOption gpdf_popt_options [] = {
{ "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0,
N_("Enables some debugging functions"), N_("LEVEL") },
};
+static GnomeUIInfo dummy_menu [] = {
+ { GNOME_APP_UI_ITEM, N_("_dummy"),
+ N_("What a dummy!"), crummy_cmd },
+ GNOMEUIINFO_END
+};
+
+static GnomeUIInfo main_menu [] = {
+ { GNOME_APP_UI_SUBTREE, N_("_Dummy"), NULL, dummy_menu },
+ GNOMEUIINFO_END
+};
+
//------------------------------------------------------------------------
// loadFile / displayPage
//------------------------------------------------------------------------
-static GBool loadFile(GString *fileName) {
- GString *title;
- PDFDoc *newDoc;
+static gint
+doc_config_event (GtkWidget *widget, DOC_ROOT *doc)
+{
+ if (!doc)
+ return TRUE;
+
+ if (doc->pixmap)
+ gdk_pixmap_unref(doc->pixmap);
+
+ doc->pixmap = gdk_pixmap_new(widget->window,
+ widget->allocation.width,
+ widget->allocation.height,
+ -1);
+ gdk_draw_rectangle (doc->pixmap,
+ widget->style->white_gc,
+ TRUE,
+ 0, 0,
+ widget->allocation.width,
+ widget->allocation.height);
+ return TRUE;
+}
+
+static gint
+doc_redraw_event (GtkWidget *widget, DOC_ROOT *doc)
+{
+/* Redraw the screen from the backing pixmap */
+
+ gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
+ doc->out = new GOutputDev (doc->pixmap, doc->paper);
+
+ doc->pdf->displayPage(doc->out, 1, 1, 0, gTrue);
+
+/* gdk_draw_pixmap(widget->window,
+ widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
+ doc->pixmap,
+ event->area.x, event->area.y,
+ event->area.x, event->area.y,
+ event->area.width, event->area.height);*/
+
+ return FALSE;
+}
+
+static GBool
+loadFile(GString *fileName)
+{
+ DOC_ROOT *doc = new DOC_ROOT();
char s[20];
char *p;
- // busy cursor
- if (win)
- win->setBusyCursor(gTrue);
-
// open PDF file
- newDoc = new PDFDoc(fileName);
- if (!newDoc->isOk()) {
- delete newDoc;
- if (win)
- win->setBusyCursor(gFalse);
+ doc->pdf = new PDFDoc(fileName);
+ if (!doc->pdf->isOk()) {
+ delete doc->pdf;
+ delete doc;
return gFalse;
}
- // replace old document
- if (doc)
- delete doc;
- doc = newDoc;
-
- // nothing displayed yet
- page = -99;
+ doc->toplevel = gnome_app_new ("gpdf", "gpdf");
+ gtk_window_set_policy(GTK_WINDOW(doc->toplevel), 1, 1, 0);
+ gtk_window_set_default_size (GTK_WINDOW(doc->toplevel), 600, 400);
+ doc->table = GTK_WIDGET (gtk_table_new (0, 0, 0));
+ doc->appbar = GNOME_APPBAR (gnome_appbar_new (FALSE, TRUE,
+ GNOME_PREFERENCES_USER));
+ gnome_app_set_statusbar (GNOME_APP (doc->toplevel),
+ GTK_WIDGET (doc->appbar));
+ gnome_app_set_contents (GNOME_APP (doc->toplevel), doc->table);
+ gnome_app_create_menus_with_data (GNOME_APP (doc->toplevel), main_menu, doc);
+ gnome_app_install_menu_hints(GNOME_APP (doc->toplevel), main_menu);
+
+ doc->pixmap = NULL;
+ doc->area = GTK_DRAWING_AREA (gtk_drawing_area_new ());
+ gtk_signal_connect (GTK_OBJECT (doc->area), "expose_event",
+ (GtkSignalFunc) doc_redraw_event, NULL);
+ gtk_signal_connect (GTK_OBJECT(doc->area),"configure_event",
+ (GtkSignalFunc) doc_config_event, NULL);
+
+ gtk_table_attach (GTK_TABLE (doc->table), GTK_WIDGET (doc->area),
+ 0, 1, 1, 2,
+ GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND,
+ 0, 0);
+
+ gtk_widget_show_all (doc->toplevel);
- // init PostScript output params
- if (psFileName)
- delete psFileName;
- if (defPSFileName) {
- psFileName = defPSFileName->copy();
- } else {
- p = fileName->getCString() + fileName->getLength() - 4;
- if (!strcmp(p, ".pdf") || !strcmp(p, ".PDF"))
- psFileName = new GString(fileName->getCString(),
- fileName->getLength() - 4);
- else
- psFileName = fileName->copy();
- psFileName->append(".ps");
- }
- psFirstPage = 1;
- psLastPage = doc->getNumPages();
-
- // set up title, number-of-pages display; back to normal cursor
- if (win) {
- title = new GString("xpdf: ");
- title->append(fileName);
- win->setTitle(title);
- sprintf(s, "of %d", doc->getNumPages());
- numPagesLabel->setText(s);
- win->setBusyCursor(gFalse);
- }
-
- // done
return gTrue;
}
-static void displayPage(int page1, int zoom1, int rotate1) {
+/*static void displayPage(int page1, int zoom1, int rotate1) {
char s[20];
// check for document
// back to regular cursor
win->setBusyCursor(gFalse);
-}
+ }*/
int
main (int argc, char *argv [])
"gpdf", "0.1", argc, argv,
gpdf_popt_options, 0, &ctx);
+ initParams (xpdfConfigFile); /* Init font path */
+
view_files = poptGetArgs (ctx);
/* Load files */
if (view_files) {
poptFreeContext (ctx);
+ freeParams();
+
gtk_main ();
/* Destroy files */