Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--pdf/xpdf/Makefile.am2
-rw-r--r--pdf/xpdf/pdf-document.c142
-rw-r--r--pdf/xpdf/pdf-document.cc252
-rw-r--r--shell/Makefile.am1
-rw-r--r--shell/dummy.cc7
-rw-r--r--shell/ev-view.c20
7 files changed, 288 insertions, 147 deletions
diff --git a/ChangeLog b/ChangeLog
index b77e0ea..48320e8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Tue Dec 21 21:58:56 2004 Owen Taylor <otaylor@redhat.com>
+
+ * pdf/xpdf/pdf-document.cc shell/ev-view.c: Hook things up
+ a bit, it works! (sort of)
+
+ * pdf/xpdf/Makefile.am pdf/xpdf/pdf-document.cc:
+ Move to .cc since we need to use C++ in the implementation.
+
+ * shell/dummy.cc: Add a CC file to force evince
+ to be linked as a C++ program.
+
Tue Dec 21 21:07:55 2004 Owen Taylor <otaylor@redhat.com>
* shell/ev-view.[ch]: Start of content-area widget.
diff --git a/pdf/xpdf/Makefile.am b/pdf/xpdf/Makefile.am
index 2d2216c..7c1b643 100644
--- a/pdf/xpdf/Makefile.am
+++ b/pdf/xpdf/Makefile.am
@@ -111,7 +111,7 @@ test_gdk_output_dev_LDADD = \
$(GTK_LIBS)
libpdfdocument_la_SOURCES = \
- pdf-document.c \
+ pdf-document.cc \
pdf-document.h
libpdfdocument_la_LIBADD = \
diff --git a/pdf/xpdf/pdf-document.c b/pdf/xpdf/pdf-document.c
deleted file mode 100644
index 81ad89c..0000000
--- a/pdf/xpdf/pdf-document.c
+++ /dev/null
@@ -1,142 +0,0 @@
-/* pdfdocument.h: Implementation of EvDocument for PDF
- * Copyright (C) 2004, Red Hat, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-#include "pdf-document.h"
-
-typedef struct _PdfDocumentClass PdfDocumentClass;
-
-#define PDF_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDF_TYPE_DOCUMENT, PdfDocumentClass))
-#define PDF_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDF_TYPE_DOCUMENT))
-#define PDF_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDF_TYPE_DOCUMENT, PdfDocumentClass))
-
-struct _PdfDocumentClass
-{
- GObjectClass parent_class;
-};
-
-struct _PdfDocument
-{
- GObject parent_instance;
-
- GdkRectangle page_rect;
- GdkDrawable *target;
-
-};
-
-static void pdf_document_document_iface_init (EvDocumentIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
- { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
- pdf_document_document_iface_init) });
-
-
-static gboolean
-pdf_document_load (EvDocument *document,
- const char *uri,
- GError **error)
-{
- return TRUE;
-}
-
-static int
-pdf_document_get_n_pages (EvDocument *document)
-{
- return 1;
-}
-
-static void
-pdf_document_set_page (EvDocument *document,
- int page)
-{
-}
-
-static void
-pdf_document_set_target (EvDocument *document,
- GdkDrawable *target)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- if (pdf_document->target != target) {
- if (pdf_document->target)
- g_object_unref (pdf_document->target);
-
- pdf_document->target = target;
-
- if (pdf_document->target)
- g_object_ref (pdf_document->target);
- }
-}
-
-static void
-pdf_document_set_page_rect (EvDocument *document,
- int x,
- int y,
- int width,
- int height)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (document);
-
- pdf_document->page_rect.x = x;
- pdf_document->page_rect.y = y;
- pdf_document->page_rect.width = width;
- pdf_document->page_rect.height = height;
-}
-
-static void
-pdf_document_render (EvDocument *document,
- int clip_x,
- int clip_y,
- int clip_width,
- int clip_height)
-{
-}
-
-static void
-pdf_document_finalize (GObject *object)
-{
- PdfDocument *pdf_document = PDF_DOCUMENT (object);
-
- if (pdf_document->target)
- g_object_unref (pdf_document->target);
-
-}
-
-static void
-pdf_document_class_init (PdfDocumentClass *class)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (class);
-
- gobject_class->finalize = pdf_document_finalize;
-}
-
-static void
-pdf_document_document_iface_init (EvDocumentIface *iface)
-{
- iface->load = pdf_document_load;
- iface->get_n_pages = pdf_document_get_n_pages;
- iface->set_page = pdf_document_set_page;
- iface->set_target = pdf_document_set_target;
- iface->set_page_rect = pdf_document_set_page_rect;
- iface->render = pdf_document_render;
-}
-
-static void
-pdf_document_init (PdfDocument *document)
-{
-}
-
diff --git a/pdf/xpdf/pdf-document.cc b/pdf/xpdf/pdf-document.cc
new file mode 100644
index 0000000..6078f96
--- /dev/null
+++ b/pdf/xpdf/pdf-document.cc
@@ -0,0 +1,252 @@
+/* pdfdocument.h: Implementation of EvDocument for PDF
+ * Copyright (C) 2004, Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "gpdf-g-switch.h"
+#include "pdf-document.h"
+#include "gpdf-g-switch.h"
+
+#include "GlobalParams.h"
+#include "GDKSplashOutputDev.h"
+#include "PDFDoc.h"
+
+typedef struct _PdfDocumentClass PdfDocumentClass;
+
+#define PDF_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PDF_TYPE_DOCUMENT, PdfDocumentClass))
+#define PDF_IS_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PDF_TYPE_DOCUMENT))
+#define PDF_DOCUMENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PDF_TYPE_DOCUMENT, PdfDocumentClass))
+
+struct _PdfDocumentClass
+{
+ GObjectClass parent_class;
+};
+
+struct _PdfDocument
+{
+ GObject parent_instance;
+
+ int page;
+ GdkRectangle page_rect;
+ GdkDrawable *target;
+
+ GDKSplashOutputDev *out;
+ PDFDoc *doc;
+
+};
+
+static void pdf_document_document_iface_init (EvDocumentIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (PdfDocument, pdf_document, G_TYPE_OBJECT,
+ { G_IMPLEMENT_INTERFACE (EV_TYPE_DOCUMENT,
+ pdf_document_document_iface_init) });
+
+
+static gboolean
+pdf_document_load (EvDocument *document,
+ const char *uri,
+ GError **error)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ PDFDoc *newDoc;
+ int err;
+ char *filename;
+ GString *filename_g;
+
+ if (!globalParams) {
+ globalParams = new GlobalParams("/etc/xpdfrc");
+ globalParams->setupBaseFonts(NULL);
+ }
+
+ filename = g_filename_from_uri (uri, NULL, error);
+ if (!filename)
+ return FALSE;
+
+ filename_g = new GString (filename);
+ g_free (filename);
+
+ // open the PDF file
+ newDoc = new PDFDoc(filename_g, 0, 0);
+
+ delete filename_g;
+
+ if (!newDoc->isOk()) {
+ err = newDoc->getErrorCode();
+ delete newDoc;
+
+ /* FIXME: Add a real error enum to EvDocument */
+ g_set_error (error, G_FILE_ERROR,
+ G_FILE_ERROR_FAILED,
+ "Failed to load document (error %d) '%s'\n",
+ err,
+ uri);
+
+ return FALSE;
+ }
+
+ if (pdf_document->doc)
+ delete pdf_document->doc;
+ pdf_document->doc = newDoc;
+
+ if (pdf_document->out) {
+ pdf_document->out->startDoc(pdf_document->doc->getXRef());
+ pdf_document->doc->displayPage (pdf_document->out, 1, 72, 72, 0, gTrue, gTrue);
+ }
+
+ return TRUE;
+}
+
+static int
+pdf_document_get_n_pages (EvDocument *document)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+ if (pdf_document->doc)
+ return pdf_document->doc->getNumPages();
+ else
+ return 1;
+}
+
+static void
+pdf_document_set_page (EvDocument *document,
+ int page)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+ pdf_document->page = page;
+}
+
+static void
+redraw_callback (void *data)
+{
+ /* Need to hook up through a EvDocument callback? */
+}
+
+static void
+pdf_document_set_target (EvDocument *document,
+ GdkDrawable *target)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+ if (pdf_document->target != target) {
+ if (pdf_document->target)
+ g_object_unref (pdf_document->target);
+
+ pdf_document->target = target;
+
+ if (pdf_document->target)
+ g_object_ref (pdf_document->target);
+
+ if (pdf_document->out)
+ delete pdf_document->out;
+
+ if (pdf_document->target) {
+ pdf_document->out = new GDKSplashOutputDev (gdk_drawable_get_screen (pdf_document->target),
+ redraw_callback, (void*) document);
+
+ if (pdf_document->doc) {
+ pdf_document->out->startDoc(pdf_document->doc->getXRef());
+ pdf_document->doc->displayPage (pdf_document->out, 1, 72, 72, 0, gTrue, gTrue);
+ }
+ }
+ }
+}
+
+static void
+pdf_document_set_page_rect (EvDocument *document,
+ int x,
+ int y,
+ int width,
+ int height)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+
+ pdf_document->page_rect.x = x;
+ pdf_document->page_rect.y = y;
+ pdf_document->page_rect.width = width;
+ pdf_document->page_rect.height = height;
+}
+
+static void
+pdf_document_render (EvDocument *document,
+ int clip_x,
+ int clip_y,
+ int clip_width,
+ int clip_height)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (document);
+ GdkRectangle page;
+ GdkRectangle draw;
+
+ if (!pdf_document->target)
+ return;
+
+ page.x = 0;
+ page.y = 0;
+ page.width = pdf_document->out->getBitmapWidth();
+ page.height = pdf_document->out->getBitmapHeight();
+
+ draw.x = clip_x;
+ draw.y = clip_y;
+ draw.width = clip_width;
+ draw.height = clip_height;
+
+ if (gdk_rectangle_intersect (&page, &draw, &draw))
+ pdf_document->out->redraw (draw.x, draw.y,
+ pdf_document->target,
+ draw.x, draw.y,
+ draw.width, draw.height);
+}
+
+static void
+pdf_document_finalize (GObject *object)
+{
+ PdfDocument *pdf_document = PDF_DOCUMENT (object);
+
+ if (pdf_document->target)
+ g_object_unref (pdf_document->target);
+
+ if (pdf_document->out)
+ delete pdf_document->out;
+ if (pdf_document->doc)
+ delete pdf_document->doc;
+
+}
+
+static void
+pdf_document_class_init (PdfDocumentClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = pdf_document_finalize;
+}
+
+static void
+pdf_document_document_iface_init (EvDocumentIface *iface)
+{
+ iface->load = pdf_document_load;
+ iface->get_n_pages = pdf_document_get_n_pages;
+ iface->set_page = pdf_document_set_page;
+ iface->set_target = pdf_document_set_target;
+ iface->set_page_rect = pdf_document_set_page_rect;
+ iface->render = pdf_document_render;
+}
+
+static void
+pdf_document_init (PdfDocument *document)
+{
+}
+
diff --git a/shell/Makefile.am b/shell/Makefile.am
index e764e3a..48aa917 100644
--- a/shell/Makefile.am
+++ b/shell/Makefile.am
@@ -13,6 +13,7 @@ INCLUDES= \
bin_PROGRAMS=evince
evince_SOURCES= \
+ dummy.cc \
eggfindbar.c \
eggfindbar.h \
ev-application.c \
diff --git a/shell/dummy.cc b/shell/dummy.cc
new file mode 100644
index 0000000..645049d
--- /dev/null
+++ b/shell/dummy.cc
@@ -0,0 +1,7 @@
+/* This file is just here to fake automake into linking evince as a C++ app
+ */
+
+void evince_cpp_stub_dummy (void)
+{
+}
+
diff --git a/shell/ev-view.c b/shell/ev-view.c
index 70b50e0..9fbc81a 100644
--- a/shell/ev-view.c
+++ b/shell/ev-view.c
@@ -223,8 +223,9 @@ ev_view_realize (GtkWidget *widget)
gdk_window_set_user_data (view->bin_window, widget);
gdk_window_show (view->bin_window);
- attributes.event_mask = GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_BUTTON_MOTION_MASK | GDK_EXPOSURE_MASK;
-
+ if (view->document)
+ ev_document_set_target (view->document, view->bin_window);
+
update_window_backgrounds (view);
}
@@ -233,10 +234,13 @@ ev_view_unrealize (GtkWidget *widget)
{
EvView *view = EV_VIEW (widget);
+ if (view->document)
+ ev_document_set_target (view->document, NULL);
+
gdk_window_set_user_data (view->bin_window, NULL);
gdk_window_destroy (view->bin_window);
view->bin_window = NULL;
-
+
GTK_WIDGET_CLASS (ev_view_parent_class)->unrealize (widget);
}
@@ -258,7 +262,12 @@ static void
expose_bin_window (GtkWidget *widget,
GdkEventExpose *event)
{
- /* EvView *view = EV_VIEW (widget); */
+ EvView *view = EV_VIEW (widget);
+
+ if (view->document)
+ ev_document_render (view->document,
+ event->area.x, event->area.y,
+ event->area.width, event->area.height);
}
static gboolean
@@ -417,6 +426,9 @@ ev_view_set_document (EvView *view,
if (view->document)
g_object_ref (view->document);
+ if (GTK_WIDGET_REALIZED (view))
+ ev_document_set_target (view->document, view->bin_window);
+
gtk_widget_queue_resize (GTK_WIDGET (view));
}
}