//
//========================================================================
-
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
double zoom = 86.0;
gint page = 2;
-#define DOC_KEY "xpdf_doc_key"
+#define DOC_ROOT_TAG "xpdf_doc_root"
struct DOC_ROOT {
GString *title;
PDFDoc *pdf;
+ Catalog *cat;
GtkDrawingArea *area;
GtkPixmap *pixmap;
OutputDev *out;
GladeXML *gui;
};
+GList *documents = NULL;
+
const struct poptOption gpdf_popt_options [] = {
{ "debug", '\0', POPT_ARG_INT, &gpdf_debug, 0,
N_("Enables some debugging functions"), N_("LEVEL") },
{ NULL, '\0', 0, NULL, 0 }
};
+extern "C" {
+ static void connect_signals (DOC_ROOT *doc);
+}
+
//------------------------------------------------------------------------
// loadFile / displayPage
//------------------------------------------------------------------------
-static void
-get_page_geom (int *w, int *h, Page *p)
-{
- double pw = p->getWidth();
- double ph = p->getHeight();
-
- *w = 612;
- *h = 792;
-
- if (!p)
- return;
-
- *w = (int)((pw * zoom)/72.0 + 28.0);
- *h = (int)((ph * zoom)/72.0 + 56.0);
-}
-
-static GdkPixmap *
+static GtkPixmap *
setup_pixmap (DOC_ROOT *doc, GdkWindow *window)
{
GdkGCValues gcValues;
int w, h;
GdkPixmap *pixmap = NULL;
- if (pixmap)
- gdk_pixmap_unref(pixmap);
-
- Catalog *cat = pdf->getCatalog();
- get_page_geom (&w, &h, cat->getPage (page));
+ w = (int)((pdf->getPageWidth (page) * zoom) / 72.0);
+ h = (int)((pdf->getPageHeight (page) * zoom) / 72.0);
pixmap = gdk_pixmap_new (window, w, h, -1);
- gtk_widget_set_usize (GTK_WIDGET (doc->scroll), w, h);
- printf ("Creating pixmap of size %d %d\n", w, h);
gdk_color_white (gtk_widget_get_default_colormap(), &doc->paper);
doc->out = new GOutputDev (pixmap, doc->paper, window);
gdk_draw_rectangle (pixmap, strokeGC,
TRUE, 0, 0,
w, h);
- return pixmap;
+
+ return GTK_PIXMAP (gtk_pixmap_new (pixmap, NULL));
}
-/*static gint
-doc_config_event (GtkWidget *widget, void *ugly)
+static void
+show_page (DOC_ROOT *doc, gint page)
{
- DOC_ROOT *doc;
+ doc->pdf->displayPage(doc->out, page, zoom, 0, gTrue);
+}
- doc = (DOC_ROOT *)gtk_object_get_data (GTK_OBJECT (widget), DOC_KEY);
-
- g_return_val_if_fail (doc, FALSE);
+/*static void displayPage(int page1, int zoom1, int rotate1) {
+ char s[20];
- return TRUE;
-}
+ // check for document
+ if (!doc)
+ return;
-static gint
-doc_redraw_event (GtkWidget *widget, GdkEventExpose *event)
-{
- DOC_ROOT *doc;
-
- g_return_val_if_fail (widget != NULL, FALSE);
-
- doc = (DOC_ROOT *)gtk_object_get_data (GTK_OBJECT (widget), DOC_KEY);
-
- g_return_val_if_fail (doc != NULL, FALSE);
-
- if (doc->out && doc->pdf) {
-#if DEV_DEBUG > 0
- printf ("There are %d pages\n", doc->pdf->getNumPages());
-#endif
-
- doc->pdf->displayPage(doc->out, 1, 86, 0, gTrue);
- gdk_draw_pixmap(widget->window,
- widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
- doc->pixmap,
- 0, 0,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
- } else
- printf ("Null pointer error %p %p\n", doc->out, doc->pdf);
-
- return FALSE;
-}*/
+ // busy cursor
+ if (win)
+ win->setBusyCursor(gTrue);
+
+ // new page/zoom/rotate values
+ page = page1;
+ zoom = zoom1;
+ rotate = rotate1;
+
+ // initialize mouse-related stuff
+ linkAction = NULL;
+ win->setDefaultCursor();
+ linkLabel->setText(NULL);
+ selectXMin = selectXMax = 0;
+ selectYMin = selectYMax = 0;
+ lastDragLeft = lastDragTop = gTrue;
+
+ // draw the page
+ doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
+ layoutCbk(win);
+
+ // update page number display
+ sprintf(s, "%d", page);
+ pageNumText->setText(s);
+
+ // back to regular cursor
+ win->setBusyCursor(gFalse);
+ }*/
static PDFDoc *
getPDF (GString *fname)
return pdf;
}
-
-static GBool
-loadPDF(GString *fileName)
+static DOC_ROOT *
+doc_root_new (GString *fileName)
{
DOC_ROOT *doc = new DOC_ROOT();
GtkVBox *pane;
- GtkAdjustment *hadj, *vadj;
- GdkPixmap *pix;
// open PDF file
doc->pdf = getPDF (fileName);
if (!doc->pdf) {
delete doc;
- return gFalse;
+ return NULL;
}
doc->gui = glade_xml_new (GPDF_GLADE_DIR "/gpdf.glade", NULL);
printf ("Couldn't find " GPDF_GLADE_DIR "/gpdf.glade\n");
delete doc->pdf;
delete doc;
- return gFalse;
+ return NULL;
}
-/* glade_xml_signal_autoconnect (doc->gui);*/
-
- pix = setup_pixmap (doc, gtk_widget_get_parent_window (GTK_WIDGET (pane)));
- doc->pixmap = GTK_PIXMAP (gtk_pixmap_new (pix, NULL));
+
+ connect_signals (doc);
+
+ gtk_object_set_data (GTK_OBJECT (doc->mainframe), DOC_ROOT_TAG, doc);
+
+ doc->pixmap = setup_pixmap (doc, gtk_widget_get_parent_window (GTK_WIDGET (pane)));
doc->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
gtk_scrolled_window_set_policy (doc->scroll, GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
- doc->pdf->displayPage(doc->out, page, zoom, 0, gTrue);
+ show_page (doc, page);
gtk_scrolled_window_add_with_viewport (doc->scroll, GTK_WIDGET (doc->pixmap));
gtk_box_pack_start (GTK_BOX (pane), GTK_WIDGET (doc->scroll), TRUE, TRUE, 0);
gtk_widget_show_all (doc->mainframe);
- return gTrue;
-}
-/*static void displayPage(int page1, int zoom1, int rotate1) {
- char s[20];
+ documents = g_list_append (documents, doc);
- // check for document
- if (!doc)
- return;
-
- // busy cursor
- if (win)
- win->setBusyCursor(gTrue);
+ return doc;
+}
- // new page/zoom/rotate values
- page = page1;
- zoom = zoom1;
- rotate = rotate1;
+static void
+doc_root_destroy (DOC_ROOT *doc)
+{
+ gtk_widget_destroy (doc->mainframe);
+ gtk_object_destroy (GTK_OBJECT (doc->gui));
+
+ documents = g_list_remove (documents, doc);
+ if (g_list_length (documents) == 0)
+ gtk_main_quit ();
+ delete (doc);
+}
- // initialize mouse-related stuff
- linkAction = NULL;
- win->setDefaultCursor();
- linkLabel->setText(NULL);
- selectXMin = selectXMax = 0;
- selectYMin = selectYMax = 0;
- lastDragLeft = lastDragTop = gTrue;
+//------------------------------------------------------------------------
+// Signal handlers
+//------------------------------------------------------------------------
- // draw the page
- doc->displayPage(out, page, zoomDPI[zoom - minZoom], rotate, gTrue);
- layoutCbk(win);
+extern "C" {
+ void
+ do_close (GtkWidget *menuitem, DOC_ROOT *doc)
+ {
+ doc_root_destroy (doc);
+ }
- // update page number display
- sprintf(s, "%d", page);
- pageNumText->setText(s);
+ void
+ do_exit (GtkWidget *menuitem, DOC_ROOT *doc)
+ {
+ GList *l;
+ while ((l=documents))
+ doc_root_destroy ((DOC_ROOT *)l->data);
+ }
- // back to regular cursor
- win->setBusyCursor(gFalse);
- }*/
+ static void
+ do_about_box (GtkWidget *w, DOC_ROOT *doc)
+ {
+ GladeXML *gui = glade_xml_new (GPDF_GLADE_DIR "/about.glade", NULL);
+ g_return_if_fail (gui);
+ GtkWidget *wi = glade_xml_get_widget (gui, "about_box");
+ g_return_if_fail (wi);
+ gtk_widget_show (wi);
+ gtk_object_destroy (GTK_OBJECT (gui));
+ }
-extern "C" {
- void
- on_close_activate (GtkWidget *window, void *data)
+ static void
+ simple_connect (DOC_ROOT *doc, const char *name, GtkSignalFunc func)
{
- printf ("Bye...");
- gtk_widget_destroy (window);
+ GtkWidget *w;
+ w = glade_xml_get_widget (doc->gui, name);
+ gtk_signal_connect (GTK_OBJECT (w), "activate", func, doc);
}
+
+ static void
+ connect_signals (DOC_ROOT *doc)
+ {
+ simple_connect (doc, "about_menu", GTK_SIGNAL_FUNC (do_about_box));
+ simple_connect (doc, "close_menu", GTK_SIGNAL_FUNC (do_close));
+ simple_connect (doc, "exit_menu", GTK_SIGNAL_FUNC (do_exit));
+ }
}
int
if (view_files) {
for (i = 0; view_files[i]; i++) {
GString *name = new GString (view_files[i]);
- if (!name || !loadPDF (name))
+ if (!name || !doc_root_new (name))
printf ("Error loading '%s'\n", view_files[i]);
}
} else {
<widget>
<class>GtkMenuItem</class>
- <name>file1</name>
+ <name>file_menu</name>
<stock_item>GNOMEUIINFO_MENU_FILE_TREE</stock_item>
<widget>
<class>GtkMenu</class>
- <name>file1_menu</name>
+ <name>file_menu_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>open1</name>
- <signal>
- <name>activate</name>
- <handler>on_open1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>open_menu</name>
<stock_item>GNOMEUIINFO_MENU_OPEN_ITEM</stock_item>
</widget>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>close</name>
- <signal>
- <name>activate</name>
- <handler>on_close_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 23:33:35 GMT</last_modification_time>
- </signal>
+ <name>close_menu</name>
<stock_item>GNOMEUIINFO_MENU_CLOSE_ITEM</stock_item>
</widget>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>print1</name>
- <signal>
- <name>activate</name>
- <handler>on_print1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>print_menu</name>
<stock_item>GNOMEUIINFO_MENU_PRINT_ITEM</stock_item>
</widget>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>print_setup1</name>
- <signal>
- <name>activate</name>
- <handler>on_print_setup1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>print_setup_menu</name>
<stock_item>GNOMEUIINFO_MENU_PRINT_SETUP_ITEM</stock_item>
</widget>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>exit1</name>
- <signal>
- <name>activate</name>
- <handler>on_exit1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>exit_menu</name>
<stock_item>GNOMEUIINFO_MENU_EXIT_ITEM</stock_item>
</widget>
</widget>
<widget>
<class>GtkMenuItem</class>
- <name>edit1</name>
+ <name>edit_menu</name>
<stock_item>GNOMEUIINFO_MENU_EDIT_TREE</stock_item>
<widget>
<class>GtkMenu</class>
- <name>edit1_menu</name>
+ <name>edit_menu_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>replace1</name>
- <signal>
- <name>activate</name>
- <handler>on_replace1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>replace_menu</name>
<stock_item>GNOMEUIINFO_MENU_FIND_ITEM</stock_item>
</widget>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>find_again1</name>
- <signal>
- <name>activate</name>
- <handler>on_find_again1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>find_again_menu</name>
<stock_item>GNOMEUIINFO_MENU_FIND_AGAIN_ITEM</stock_item>
</widget>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>properties1</name>
- <signal>
- <name>activate</name>
- <handler>on_properties1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>properties_menu</name>
<stock_item>GNOMEUIINFO_MENU_PROPERTIES_ITEM</stock_item>
</widget>
</widget>
<widget>
<class>GtkMenuItem</class>
- <name>view1</name>
+ <name>view_menu</name>
<stock_item>GNOMEUIINFO_MENU_VIEW_TREE</stock_item>
<widget>
<class>GtkMenu</class>
- <name>view1_menu</name>
+ <name>view_menu_menu</name>
<widget>
<class>GtkMenuItem</class>
- <name>larger1</name>
- <signal>
- <name>activate</name>
- <handler>on_larger1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:20:39 GMT</last_modification_time>
- </signal>
+ <name>larger_menu</name>
<label>Larger</label>
<right_justify>False</right_justify>
</widget>
<widget>
<class>GtkMenuItem</class>
- <name>smaller1</name>
- <signal>
- <name>activate</name>
- <handler>on_smaller1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:21:07 GMT</last_modification_time>
- </signal>
+ <name>smaller_menu</name>
<label>smaller</label>
<right_justify>False</right_justify>
</widget>
<widget>
<class>GtkMenuItem</class>
- <name>settings1</name>
+ <name>settings_menu</name>
<stock_item>GNOMEUIINFO_MENU_SETTINGS_TREE</stock_item>
<widget>
<class>GtkMenu</class>
- <name>settings1_menu</name>
+ <name>settings_menu_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>preferences1</name>
- <signal>
- <name>activate</name>
- <handler>on_preferences1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>preferences_menu</name>
<stock_item>GNOMEUIINFO_MENU_PREFERENCES_ITEM</stock_item>
</widget>
</widget>
<widget>
<class>GtkMenuItem</class>
- <name>help1</name>
+ <name>help_menu</name>
<stock_item>GNOMEUIINFO_MENU_HELP_TREE</stock_item>
<widget>
<class>GtkMenu</class>
- <name>help1_menu</name>
+ <name>help_menu_menu</name>
<widget>
<class>GtkPixmapMenuItem</class>
- <name>about1</name>
- <signal>
- <name>activate</name>
- <handler>on_about1_activate</handler>
- <last_modification_time>Sun, 01 Aug 1999 03:04:00 GMT</last_modification_time>
- </signal>
+ <name>about_menu</name>
<stock_item>GNOMEUIINFO_MENU_ABOUT_ITEM</stock_item>
</widget>
</widget>