[Nautilus-list] gpdf OAFization and bugfixing patch



The following patch for the xpdf module makes it possible to compile
gpdf for OAF support and makes a number of changes to fix bugs and
make the pdf component usable as a nautilus view (mainly allowing
loading through the PerisistStream when there are Views that are not
yet realized, and moving scrolling and keyboard support from the
container to the component).


The following (nautilus-specific or general) issues remain:

* The toolbar merging does not work for nautilus (it expects a toolbar
  named `pdf').

* The menu merging uses odd menu names, items and positioning; they
  could be made more consistent w/ other components.

* There is no right-click menu.

* Does not work with the nautilus zoom control (although you can zoom
  using the relevant menu entries, or using '+'/'=' or '-'/'_' with
  the keyboard.

* You can't reload through the PersistStream into an existing
  component. That is bogus and inconsistent with other components.

I am going to add these to the Eazel bug tracker since I plan to fix
them all myself sooner or later. I will cc michael helixcode com on
the bugzilla entries.

I have to add that the way this renders documents is kind of ugly. Is
there any way to get nice fonts and some antialiasing here?

Also, I didn't test if PDF links do anything useful because I couldn't
find a PDF that I know for sure to have links.

And finally, the code is kind of messy and badly needs some more
refactoring love.


Here is the patch and ChangeLog entry. I will apply Monday morning EST
if I hear no objections. I'd be more patient but we (Eazel) need this
for a demo. Eazel folks, if you want to try this before Monday just
check out the xpdf module and apply the patch locally.


2000-05-07  Maciej Stachowiak  <mjs eazel com>

	Work with OAF and fix various bugs:
	
	* configure.in, aclocal.m4: Detect when Bonobo is built with OAF
	support, and if so use OAF.
	* xpdf/Makefile.am: When using OAF, link against OAF and install
	oafinfo file.
	* xpdf/gpdf.cc: Include oaf headers when using OAF.
	(openpdf): Use OAFIID to activate the component when using OAF.
	(container_set_view), (container_launch_component),
	(container_new): Put the view in an EventBox, not a
	ScrolledWindow; the component now handles scrolling itself.
	(key_press_event_cb): Removed; key press handling moved to
	component.
	(main): Initialize OAF instead of GOAD when using OAF.
	* xpdf/bonobo-application-x-pdf.cc: Include OAF headers when using
	OAF.
	(redraw_view): Handle the case where we are loading before the
	view is realized by connecting to the "realize" signal handler
	and deferring redrawing until then in that case.
	(real_redraw_view): Function to do the real redrawing.
	(load_pdf_from_stream): Don't call `realize_mainbox' directly, let
	`real_redraw_view' do it.
	(key_press_event_cb): In response to various key bindings, scroll
	the view, navigate pages, or zoom in/out.
	(button_press_event_cb): Grab the keyboard focus on a press of
	button 1.
	(view_create_menus): Rename menus to be more standard, and provide
	accelerators for menus and items.
	(realize_mainbox): Get window ourselves if we have to.
	(view_factory): Put the view in a scrolled window so scrolling can
	be handled by the component itself. Connect to "key_press" and
	"button_press" for keyboard and focus handling. Set the
	GTK_CAN_FOCUS flag for the main view widget.
	(init_bonobo_application_x_pdf_factory, init_server_factory): Use
	OAF when appropriate.

	* xpdf/application-x-pdf.oafinfo: New file, OAF activation record.


Index: aclocal.m4
===================================================================
RCS file: /cvs/gnome/xpdf/aclocal.m4,v
retrieving revision 1.7
diff -u -r1.7 aclocal.m4
--- aclocal.m4	2000/02/28 21:05:11	1.7
+++ aclocal.m4	2000/05/07 09:27:19
@@ -757,6 +757,10 @@
 		AC_SUBST(GNOME_APPLETS_LIBS)
 		GNOME_APPLETS_LIBS=`$GNOME_CONFIG --libs-only-l applets`
 		AC_MSG_RESULT($GNOME_APPLETS_LIBS);;
+	      docklets)
+		AC_SUBST(GNOME_DOCKLETS_LIBS)
+		GNOME_DOCKLETS_LIBS=`$GNOME_CONFIG --libs-only-l docklets`
+		AC_MSG_RESULT($GNOME_DOCKLETS_LIBS);;
 	      capplet)
 		AC_SUBST(GNOME_CAPPLET_LIBS)
 		GNOME_CAPPLET_LIBS=`$GNOME_CONFIG --libs-only-l capplet`
Index: configure.in
===================================================================
RCS file: /cvs/gnome/xpdf/configure.in,v
retrieving revision 1.11
diff -u -r1.11 configure.in
--- configure.in	2000/02/25 19:59:50	1.11
+++ configure.in	2000/05/07 09:27:19
@@ -189,6 +189,41 @@
 	AC_MSG_RESULT(not found)
 fi
 
+dnl Whether to use OAF
+
+AC_MSG_CHECKING(if Bonobo uses OAF)
+if ( gnome-config --libs bonobo | grep oaf ) > /dev/null 2>&1 ; then
+	enable_oaf="yes"
+else
+	enable_oaf="no"
+fi
+
+AC_MSG_RESULT("$enable_oaf")
+
+if test "x$enable_oaf" = "xyes"; then
+        AC_PATH_PROG(OAF_CONFIG,oaf-config,no)
+        if test x$OAF_CONFIG = xno; then
+                AC_MSG_ERROR("You enabled OAF support but oaf-config was not found")
+        else
+                OAF_LIBS=`$OAF_CONFIG --libs`
+                OAF_CFLAGS=`$OAF_CONFIG --cflags`
+                GNORBA_LIBNAME=
+        fi
+else
+        OAF_LIBS=
+        OAF_CFLAGS=
+        GNORBA_LIBNAME=gnorba
+fi
+
+AC_SUBST(OAF_LIBS)
+AC_SUBST(OAF_CFLAGS)
+
+AM_CONDITIONAL(USING_OAF, test "x$enable_oaf" = "xyes")
+
+if test "x$enable_oaf" = "xyes"; then
+	AC_DEFINE(USING_OAF)
+fi
+
 EXTRA_GNOME_LIBS=`gnome-config   --libs   gnomeui print $bonobo`
 EXTRA_GNOME_CFLAGS=`gnome-config --cflags gnomeui print $bonobo`
 
Index: xpdf/Makefile.am
===================================================================
RCS file: /cvs/gnome/xpdf/xpdf/Makefile.am,v
retrieving revision 1.17
diff -u -r1.17 Makefile.am
--- xpdf/Makefile.am	2000/02/25 19:56:55	1.17
+++ xpdf/Makefile.am	2000/05/07 09:27:19
@@ -1,3 +1,10 @@
+
+if USING_OAF
+OBJECT_DIRECTORY_LIBS=$(OAF_LIBS) $(GNOMEUI_LIBS)
+else
+OBJECT_DIRECTORY_LIBS=$(GNOMEGNORBA_LIBS)
+endif
+
 INCLUDES =					\
 	-I$(top_srcdir)/goo			\
 	-I$(top_srcdir)/ltk			\
@@ -70,7 +77,7 @@
 	$(GTK_LIBS)		\
 	$(GNOME_LIBDIR)		\
 	-lbonobo		\
-	$(GNOMEGNORBA_LIBS)	\
+	$(OBJECT_DIRECTORY_LIBS) \
 	$(EXTRA_GNOME_LIBS)	\
 	$(INTLLIBS)
 
@@ -90,7 +97,7 @@
 	$(GTK_LIBS)			\
 	$(GNOME_LIBDIR)			\
 	-lbonobo			\
-	$(GNOMEGNORBA_LIBS)		\
+	$(OBJECT_DIRECTORY_LIBS)	\
 	$(EXTRA_GLIB_LIBS)		\
 	$(INTLLIBS)
 
@@ -162,8 +169,16 @@
 	xpdf-top.ltk	\
 	xpdf.ltk
 
-gnorbadir = $(sysconfdir)/CORBA/servers
-gnorba_DATA = application-x-pdf.gnorba
+goaddir = $(sysconfdir)/CORBA/servers
+oafdir = $(datadir)/oaf
+
+if USING_OAF
+oaf_DATA = $(OAF_FILES)
+else
+goad_DATA = $(GOAD_FILES)
+endif
 
-EXTRA_DIST = $(bitmaps) ChangeLog $(ltk) $(gnorba_DATA) config.h
+GOAD_FILES = application-x-pdf.gnorba
+OAF_FILES = application-x-pdf.oafinfo
 
+EXTRA_DIST = $(bitmaps) ChangeLog $(ltk) $(GOAD_FILES) $(OAF_FILES) config.h
Index: xpdf/application-x-pdf.oafinfo
===================================================================
RCS file: application-x-pdf.oafinfo
diff -N application-x-pdf.oafinfo
--- /dev/null	Tue May  5 16:32:27 1998
+++ application-x-pdf.oafinfo	Sun May  7 05:27:19 2000
@@ -0,0 +1,45 @@
+<oaf_info>
+
+<oaf_server iid="OAFIID:gpdf_component_factory:5d6d2e89-b73a-4898-b24a-79b896926f12"
+            type="exe"
+            location="bonobo-application-x-pdf">
+
+	<oaf_attribute name="repo_ids" type="stringv">
+		<item value="IDL:GNOME/GenericFactory:1.0"/>
+	</oaf_attribute>
+
+	<oaf_attribute name="description" type="string"
+	               value="application/x-pdf bonobo object factory"/>
+	<oaf_attribute name="name" type="string"
+	               value="PDF document viewer factory"/>
+
+</oaf_server>
+
+<oaf_server iid="OAFIID:gpdf_componet:892f2727-e2ec-423c-91ad-6f7b75fec6c8"
+            type="factory"
+            location="OAFIID:gpdf_component_factory:5d6d2e89-b73a-4898-b24a-79b896926f12">
+
+	<oaf_attribute name="repo_ids" type="stringv">
+		<item value="IDL:Bonobo/Embeddable:1.0"/>
+		<item value="IDL:Bonobo/Unknown:1.0"/>
+		<item value="IDL:Bonobo/PersistStream:1.0"/>
+		<item value="IDL:Bonobo/Persist:1.0"/>
+	</oaf_attribute>
+
+	<oaf_attribute name="description" type="string"
+	               value="application/x-pdf bonobo object"/>
+	<oaf_attribute name="name" type="string"
+	               value="PDF document viewer"/>
+
+	<oaf_attribute name="bonobo:editable" type="boolean" value="true"/>
+	<oaf_attribute name="bonobo:supported_mime_types" type="stringv">
+	<item value="application/x-pdf"/>
+	<item value="application/pdf"/>
+	</oaf_attribute>
+
+	<oaf_attribute name="nautilus:view_as_name" type="string"
+	               value="PDF Document"/>
+
+</oaf_server>
+
+</oaf_info>
Index: xpdf/bonobo-application-x-pdf.cc
===================================================================
RCS file: /cvs/gnome/xpdf/xpdf/bonobo-application-x-pdf.cc,v
retrieving revision 1.15
diff -u -r1.15 bonobo-application-x-pdf.cc
--- xpdf/bonobo-application-x-pdf.cc	2000/02/28 21:05:11	1.15
+++ xpdf/bonobo-application-x-pdf.cc	2000/05/07 09:27:20
@@ -13,7 +13,11 @@
 extern "C" {
 #define GString G_String
 #include <gnome.h>
+#if USING_OAF
+#include <liboaf/liboaf.h>
+#else
 #include <libgnorba/gnorba.h>
+#endif
 #include <bonobo.h>
 #include "gtkgesture.h"
 #undef  GString 
@@ -50,7 +54,7 @@
 /*
  * Our embeddable factory
  */
-static BonoboEmbeddableFactory *factory;
+static BonoboGenericFactory *factory;
 	
 /* This lock protects the global PDF 'xref' variable */
 GMutex       *xref_lock;
@@ -76,6 +80,7 @@
   GtkGestureHandler    *gh;
   bed_t *bed;
 
+  GtkWidget            *scrolled_window;
   GtkWidget            *mainbox;
   GtkPixmap            *pixmap;
   GdkWindow            *win;
@@ -105,7 +110,11 @@
 
 extern "C" {
   static void realize_mainbox (BonoboView *view, gpointer dummy);
+  static void real_redraw_view (GtkWidget *widget, BonoboView *view);
   static void setup_pixmap (bed_t *doc, view_data_t *view, GdkWindow *window);
+  static void view_switch_page (BonoboView *view, const char *verb_name, void *user_data);
+  static void view_zoom_verb (BonoboView *view, const char *verb_name, void *user_data);
+
 }
 
 static void
@@ -147,13 +156,22 @@
   gtk_widget_queue_draw (GTK_WIDGET (view_data->mainbox));
 }
 
-
 static void
 redraw_view (BonoboView *view, gpointer ptr)
 {
-  view_data_t *view_data = (view_data_t *)
+  view_data_t *view_data;
+    
+  view_data = (view_data_t *)
     gtk_object_get_data (GTK_OBJECT (view), "view_data");
-  redraw_view_all (view_data);
+
+  if (!GTK_WIDGET_REALIZED (view_data->mainbox)) {
+    gtk_signal_connect (GTK_OBJECT (view_data->mainbox), 
+			"realize", 
+			GTK_SIGNAL_FUNC (real_redraw_view), 
+			view);
+  } else {
+    real_redraw_view (view_data->mainbox, view);
+  }
 }
 
 static int
@@ -281,8 +299,6 @@
 	}
 	xref_do_unlock (bed);
 
-	bonobo_embeddable_foreach_view (bed->embeddable, realize_mainbox,
-					NULL);
 	bonobo_embeddable_foreach_view (bed->embeddable, redraw_view,
 					(gpointer)bed);
 
@@ -292,6 +308,119 @@
 
 extern "C" {
 
+
+  static gint
+  button_press_event_cb (GtkWidget *widget, GdkEventButton *event, view_data_t *view_data)
+  {
+    if (event->button == 1) {
+      gtk_widget_grab_focus (widget);
+    }
+  }
+
+  /*
+   * GtkWidget key_press method override
+   *
+   * Scrolls the window on keypress
+   */
+
+  static gint
+  key_press_event_cb (GtkWidget *widget, GdkEventKey *event, view_data_t *view_data)
+  {
+    float          delta;
+    GtkAdjustment *adj;
+  
+    switch (event->keyval) {
+      /*
+       * Scrolling the view.
+       */
+
+      case GDK_Up:
+       adj = gtk_scrolled_window_get_vadjustment 
+	 (GTK_SCROLLED_WINDOW (view_data->scrolled_window));
+       
+       if (event->state & GDK_CONTROL_MASK)
+	 delta = adj->step_increment * 3;
+       else
+	 delta = adj->step_increment;
+       
+       adj->value = CLAMP (adj->value - delta,
+			   adj->lower, adj->upper - adj->page_size);
+       
+       gtk_adjustment_value_changed (adj);
+       break;
+    case GDK_Down:
+      adj = gtk_scrolled_window_get_vadjustment
+	(GTK_SCROLLED_WINDOW (view_data->scrolled_window));
+      
+      if (event->state & GDK_CONTROL_MASK)
+	delta = adj->step_increment * 3;
+      else
+	delta = adj->step_increment;
+      
+      adj->value = CLAMP (adj->value + delta,
+			  adj->lower, adj->upper - adj->page_size);
+      gtk_adjustment_value_changed (adj);
+      break;
+    case GDK_Left:
+      adj = gtk_scrolled_window_get_hadjustment 
+	(GTK_SCROLLED_WINDOW (view_data->scrolled_window));
+      
+      if (event->state & GDK_CONTROL_MASK)
+	delta = adj->step_increment * 3;
+      else
+	delta = adj->step_increment;
+      
+      adj->value = CLAMP (adj->value - delta,
+			  adj->lower, adj->upper - adj->page_size);
+      gtk_adjustment_value_changed (adj);
+      break;
+    case GDK_Right:
+      adj = gtk_scrolled_window_get_hadjustment
+	(GTK_SCROLLED_WINDOW (view_data->scrolled_window));
+      
+      if (event->state & GDK_CONTROL_MASK)
+	delta = adj->step_increment * 3;
+      else
+	delta = adj->step_increment;
+      
+      adj->value = CLAMP (adj->value + delta,
+			  adj->lower, adj->upper - adj->page_size);
+      gtk_adjustment_value_changed (adj);
+      break;
+
+    /*
+     * Various shortcuts mapped to verbs.
+     */
+      
+    case GDK_Home:
+      view_switch_page (view_data->view, VERB_FIRST, view_data); 
+      break;
+    case GDK_End:
+      view_switch_page (view_data->view, VERB_LAST, view_data); 
+      break;
+    case GDK_Page_Down:
+      view_switch_page (view_data->view, VERB_NEXT, view_data); 
+      break;
+    case GDK_Page_Up:
+      view_switch_page (view_data->view, VERB_PREV, view_data); 
+      break;
+    case GDK_plus:
+    case GDK_equal:
+      view_zoom_verb (view_data->view, VERB_Z_IN, view_data);
+      break;
+    case GDK_underscore:
+    case GDK_minus:
+      view_zoom_verb (view_data->view, VERB_Z_OUT, view_data);
+      break;
+    default:
+      return FALSE;
+    }
+    
+    /* Avoid doing keyboard navigation if we handle this event. */
+    gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event");
+    return TRUE;
+  }
+
   static void
   destroy_view (BonoboView *view, view_data_t *view_data)
   {
@@ -513,59 +642,59 @@
   bonobo_ui_handler_set_container (uih, remote_uih);
 
   bonobo_ui_handler_menu_new_subtree (uih, "/Zoom",
-				      N_("Zoom"),
+				      N_("_Zoom"),
 				      N_("Change the size of the page"), 1,
 				      BONOBO_UI_HANDLER_PIXMAP_NONE, NULL,
 				      0, (GdkModifierType)0);
 
   bonobo_ui_handler_menu_new_item (uih, "/Zoom/" VERB_Z_FIT,
-				   N_("Fit page"), N_("Expand to largest size"), -1,
+				   N_("_Fit page"), N_("Expand to largest size"), -1,
 				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
 				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_zoom_fit_cb,
 				   (gpointer)view_data);
 				 
-  bonobo_ui_handler_menu_new_item (uih, "/Zoom/" VERB_Z_IN,
-				   N_("Enlarge"), N_("Expand to a larger size"), -1,
+  bonobo_ui_handler_menu_new_item (uih, "/Zoom/" VERB_Z_OUT,
+				   N_("Zoom _In"), N_("Shrink to a smaller size"), -1,
 				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
-				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_enlarge_cb,
+				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_shrink_cb,
 				   (gpointer)view_data);
 				 
-  bonobo_ui_handler_menu_new_item (uih, "/Zoom/" VERB_Z_OUT,
-				   N_("Shrink"), N_("Shrink to a smaller size"), -1,
+  bonobo_ui_handler_menu_new_item (uih, "/Zoom/" VERB_Z_IN,
+				   N_("Zoom _Out"), N_("Expand to a larger size"), -1,
 				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
-				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_shrink_cb,
+				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_enlarge_cb,
 				   (gpointer)view_data);
 				 
   bonobo_ui_handler_menu_new_subtree (uih, "/Page",
-				     N_("Page..."),
+				     N_("_Page"),
 				     N_("Set the currently displayed page"), 1,
 				     BONOBO_UI_HANDLER_PIXMAP_NONE, NULL,
 				     0, (GdkModifierType)0);
 
   bonobo_ui_handler_menu_new_item (uih, "/Page/First",
-				   N_("First"), N_("View the first page"), -1,
+				   N_("_First"), N_("View the first page"), -1,
 				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
 				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_first_cb,
 				   (gpointer)view_data);
+
+  bonobo_ui_handler_menu_new_item (uih, "/Page/Last",
+				   N_("_Last"), N_("View the last page"), -1,
+				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
+				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_last_cb,
+				   (gpointer)view_data);
 				 
   bonobo_ui_handler_menu_new_item (uih, "/Page/Prev",
-				  N_("Previous"), N_("View the previous page"), -1,
+				  N_("_Previous"), N_("View the previous page"), -1,
 				  BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
 				  (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_prev_cb,
 				   (gpointer)view_data);
 				 
   bonobo_ui_handler_menu_new_item (uih, "/Page/Next",
-				   N_("Next"), N_("View the next page"), -1,
+				   N_("_Next"), N_("View the next page"), -1,
 				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
 				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_next_cb,
 				   (gpointer)view_data);
 				 
-  bonobo_ui_handler_menu_new_item (uih, "/Page/Last",
-				   N_("Last"), N_("View the last page"), -1,
-				   BONOBO_UI_HANDLER_PIXMAP_NONE, NULL, 0,
-				   (GdkModifierType)0, (BonoboUIHandlerCallbackFunc)page_last_cb,
-				   (gpointer)view_data);
-  
   bonobo_ui_handler_toolbar_new_item (uih, "/pdf/First", 
 				      N_("First"), N_("View the first page"), -1,
 				      BONOBO_UI_HANDLER_PIXMAP_STOCK, (char *)GNOME_STOCK_PIXMAP_FIRST,
@@ -652,6 +781,9 @@
   {
     view_data_t *view_data = (view_data_t *)
       gtk_object_get_data (GTK_OBJECT (view), "view_data");
+
+    view_data->win = gtk_widget_get_parent_window (view_data->mainbox);
+
     g_return_if_fail (view_data->win);
 /*      view_zoom_verb (NULL, VERB_Z_FIT, view_data); Need something better ! */
     render_page (view_data);
@@ -659,6 +791,19 @@
   }
 
   static void
+  real_redraw_view (GtkWidget *widget, BonoboView *view)
+  {
+    view_data_t *view_data;
+    
+    realize_mainbox (view, NULL);
+    
+    view_data = (view_data_t *)
+      gtk_object_get_data (GTK_OBJECT (view), "view_data");
+    redraw_view_all (view_data); 
+  }
+
+
+  static void
   view_switch_page (BonoboView *view, const char *verb_name, void *user_data)
   {
     view_data_t  *view_data = (view_data_t *) user_data;
@@ -719,12 +864,34 @@
 	view_data->zoom   = 86.0;
 	view_data->page   = 1;
 
+	view_data->scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+
+	gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW  (view_data->scrolled_window), 
+					GTK_POLICY_AUTOMATIC,
+					GTK_POLICY_AUTOMATIC);
+
+	gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (view_data->scrolled_window),
+					       view_data->mainbox);
+
+	GTK_OBJECT_SET_FLAGS (GTK_OBJECT (view_data->mainbox), GTK_CAN_FOCUS);
+
+	gtk_signal_connect  (GTK_OBJECT (view_data->mainbox), 
+			     "button_press_event",
+			     GTK_SIGNAL_FUNC (button_press_event_cb), 
+			     view_data);
+
+	gtk_signal_connect  (GTK_OBJECT (view_data->mainbox), 
+			     "key_press_event",
+			     GTK_SIGNAL_FUNC (key_press_event_cb), 
+			     view_data);
+
 	gtk_signal_connect (
 		GTK_OBJECT (view_data->mainbox),
 		"realize",
 		GTK_SIGNAL_FUNC (mainbox_realize), view_data);
+
+        gtk_widget_show_all (view_data->scrolled_window);
 
-        gtk_widget_show (view_data->mainbox);
 	view_data->gh  = gtk_gesture_handler_new (GTK_WIDGET (view_data->mainbox));
 	gtk_gesture_add_callback (view_data->gh, "012",
 				  GTK_GESTURE_FUNC (gesture_page_event_cb),
@@ -747,7 +914,7 @@
 				  view_data, (char *)VERB_Z_OUT);
 
 	/* View data is destroyed by the container */
-        view = bonobo_view_new (view_data->mainbox);
+        view = bonobo_view_new (view_data->scrolled_window);
 	gtk_object_set_data (GTK_OBJECT (view), "view_data", view_data);
 	gtk_signal_connect  (GTK_OBJECT (view), "activate",
 			     GTK_SIGNAL_FUNC (view_activate), view_data);
@@ -774,7 +941,7 @@
 }
 
 static BonoboObject *
-embeddable_factory (BonoboEmbeddableFactory *This, void *data)
+embeddable_factory (BonoboGenericFactory *This, void *data)
 {
 	BonoboEmbeddable *embeddable;
 	BonoboPersistStream *stream;
@@ -850,9 +1017,15 @@
 static gboolean
 init_bonobo_application_x_pdf_factory (void)
 {
+#if USING_OAF
+	factory = bonobo_embeddable_factory_new (
+		"OAFIID:gpdf_component_factory:5d6d2e89-b73a-4898-b24a-79b896926f12",
+		embeddable_factory, NULL);
+#else
 	factory = bonobo_embeddable_factory_new (
 		"bonobo-object-factory:application-x-pdf",
 		embeddable_factory, NULL);
+#endif
 
 	if (factory == NULL)
 		return FALSE;
@@ -867,10 +1040,17 @@
 
   CORBA_exception_init (&ev);
 
+#if USING_OAF
+  gnome_init_with_popt_table("PDFViewer", "0.0.1",
+			     argc, argv,
+			     oaf_popt_options, 0, NULL); 
+  oaf_init (argc, argv);
+#else
   gnome_CORBA_init_with_popt_table (
     "bonobo-application-x-pdf", "1.0",
     &argc, argv, NULL, 0, NULL, GNORBA_INIT_SERVER_FUNC, &ev);
-  
+#endif  
+
   if (bonobo_init (CORBA_OBJECT_NIL, CORBA_OBJECT_NIL, CORBA_OBJECT_NIL) == FALSE)
     g_error (_("I could not initialize Bonobo"));
 
Index: xpdf/gpdf.cc
===================================================================
RCS file: /cvs/gnome/xpdf/xpdf/gpdf.cc,v
retrieving revision 1.45
diff -u -r1.45 gpdf.cc
--- xpdf/gpdf.cc	2000/03/10 17:23:00	1.45
+++ xpdf/gpdf.cc	2000/05/07 09:27:20
@@ -12,7 +12,13 @@
 extern "C" {
 #define GString G_String
 #include <gnome.h>
+
+#if USING_OAF
+#include <liboaf/liboaf.h>
+#else
 #include <libgnorba/gnorba.h>
+#endif
+
 #include <gdk/gdkprivate.h>
 #include <gdk/gdkx.h>
 #include <bonobo.h>
@@ -39,7 +45,7 @@
   BonoboUIHandler    *uih;
   
   GtkWidget	    *app;
-  GtkScrolledWindow *scroll;
+  GtkWidget	    *slot;
   GtkWidget	    *view_widget;
   Component         *component;
 };
@@ -111,7 +117,12 @@
     g_return_val_if_fail (container != NULL, FALSE);
     g_return_val_if_fail (container->view_widget == NULL, FALSE);
 
+#if USING_OAF
+    comp = container_activate_component (container, "OAFIID:gpdf_componet:892f2727-e2ec-423c-91ad-6f7b75fec6c8");
+
+#else
     comp = container_activate_component (container, "bonobo-object:application-x-pdf");
+#endif
     if (!comp || !(object = comp->server)) {
       gnome_error_dialog (_("Could not launch bonobo object."));
       return FALSE;
@@ -349,10 +360,7 @@
 	container->view_widget = view_widget;
 	container->component   = component;
 
-	/*
-	 * Show the component.
-	 */
-	gtk_scrolled_window_add_with_viewport (container->scroll, view_widget);
+	gtk_container_add (GTK_CONTAINER (container->slot), view_widget);
 
 	/*
 	 * Activate it ( get it to merge menus etc. )
@@ -360,7 +368,7 @@
 	bonobo_view_frame_view_activate (view_frame);
 	bonobo_view_frame_set_covered   (view_frame, FALSE);
 
-	gtk_widget_show_all (GTK_WIDGET (container->scroll));
+	gtk_widget_show_all (GTK_WIDGET (container->slot));
 }
 
 static BonoboObjectClient *
@@ -373,8 +381,7 @@
 	/*
 	 * Launch the component.
 	 */
-	object_server = bonobo_object_activate_with_goad_id (
-		NULL, component_goad_id, GOAD_ACTIVATE_SHLIB, NULL);
+	object_server = bonobo_object_activate (component_goad_id, 0);
 
 	if (object_server == NULL)
 		return NULL;
@@ -473,109 +480,9 @@
       tmp_list = g_list_next (tmp_list);
     }
   }
-  
-  /*
-   * GtkWidget key_press method override
-   *
-   * Scrolls the window on keypress
-   */
-  static gint
-  key_press_event_cb (GtkWidget *widget, GdkEventKey *event)
-  {
-    Container *container = (Container *) gtk_object_get_data (GTK_OBJECT (widget), "container_data");
-    Component *component;
-    GtkScrolledWindow *win;
-    float              delta;
-
-    g_return_val_if_fail (container != NULL, FALSE);
-
-    win       = container->scroll;
-    component = container->component;
-    if (component == NULL || win == NULL)
-      return FALSE;
 
-    /*
-     * Scrolling the view.
-     */
-    if (event->keyval == GDK_Up) {
-      GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (win);
+}  
 
-      if (event->state & GDK_CONTROL_MASK)
-	delta = adj->step_increment * 3;
-      else
-	delta = adj->step_increment;
-
-      adj->value = CLAMP (adj->value - delta,
-			  adj->lower, adj->upper - adj->page_size);
-
-      gtk_adjustment_value_changed (adj);
-      return TRUE;
-    } else if (event->keyval == GDK_Down) {
-      GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment (win);
-
-      if (event->state & GDK_CONTROL_MASK)
-	delta = adj->step_increment * 3;
-      else
-	delta = adj->step_increment;
-
-      adj->value = CLAMP (adj->value + delta,
-			  adj->lower, adj->upper - adj->page_size);
-      gtk_adjustment_value_changed (adj);
-      return TRUE;
-    } else if (event->keyval == GDK_Left) {
-      GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment (win);
-
-      if (event->state & GDK_CONTROL_MASK)
-	delta = adj->step_increment * 3;
-      else
-	delta = adj->step_increment;
-
-      adj->value = CLAMP (adj->value - delta,
-			  adj->lower, adj->upper - adj->page_size);
-      gtk_adjustment_value_changed (adj);
-      return TRUE;
-    } else if (event->keyval == GDK_Right) {
-      GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment (win);
-
-      if (event->state & GDK_CONTROL_MASK)
-	delta = adj->step_increment * 3;
-      else
-	delta = adj->step_increment;
-
-      adj->value = CLAMP (adj->value + delta,
-			  adj->lower, adj->upper - adj->page_size);
-      gtk_adjustment_value_changed (adj);
-      return TRUE;
-
-      /*
-       * Various shortcuts mapped to verbs.
-       */
-
-    } else if (event->keyval == GDK_Home) {
-      bonobo_view_frame_view_do_verb (component->view_frame, VERB_FIRST);
-      return TRUE;
-    } else if (event->keyval == GDK_End) {
-      bonobo_view_frame_view_do_verb (component->view_frame, VERB_LAST);
-      return TRUE;
-    } else if (event->keyval == GDK_Page_Down ||
-	       event->keyval == GDK_Next) {
-      bonobo_view_frame_view_do_verb (component->view_frame, VERB_NEXT);
-      return TRUE;
-    } else if (event->keyval == GDK_Page_Up ||
-	       event->keyval == GDK_Prior) {
-      bonobo_view_frame_view_do_verb (component->view_frame, VERB_PREV);
-      return TRUE;
-    } else if (event->keyval == GDK_plus ||
-	       event->keyval == GDK_equal) {
-      bonobo_view_frame_view_do_verb (component->view_frame, VERB_Z_IN);
-    } else if (event->keyval == GDK_underscore ||
-	       event->keyval == GDK_minus) {
-      bonobo_view_frame_view_do_verb (component->view_frame, VERB_Z_OUT);
-    }    
-    return FALSE;
-  }
-}
-
 static void
 container_create_menus (Container *container)
 {
@@ -632,14 +539,12 @@
 
 	container->container   = bonobo_container_new ();
 	container->view_widget = NULL;
-	container->scroll = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
-	gtk_scrolled_window_set_policy (container->scroll, GTK_POLICY_ALWAYS,
-					GTK_POLICY_ALWAYS);
-	gnome_app_set_contents (GNOME_APP (container->app), GTK_WIDGET (container->scroll));
+	container->slot = gtk_event_box_new ();
+	gtk_widget_show (container->slot);
+
+	gnome_app_set_contents (GNOME_APP (container->app), GTK_WIDGET (container->slot));
 
 	gtk_object_set_data (GTK_OBJECT (container->app), "container_data", container);
-	gtk_signal_connect  (GTK_OBJECT (container->app), "key_press_event",
-			     GTK_SIGNAL_FUNC (key_press_event_cb), NULL);
 	gtk_signal_connect  (GTK_OBJECT (container->app), "delete_event",
 			     GTK_SIGNAL_FUNC (container_destroy_cb), container);
 
@@ -681,14 +586,23 @@
   
   CORBA_exception_init (&ev);
   
+
+#if USING_OAF
+  gnomelib_register_popt_table (oaf_popt_options, "OAF");
+  gnome_init_with_popt_table("PDFViewer", "0.0.1",
+			     argc, argv,
+			     gpdf_popt_options, 0, &ctx); 
+  orb = oaf_init (argc, argv);
+#else
   gnome_CORBA_init_with_popt_table ("PDFViewer", "0.0.1",
 				    &argc, argv,
 				    gpdf_popt_options, 0, &ctx,
 				    GNORBA_INIT_SERVER_FUNC, &ev);
 
-  CORBA_exception_free (&ev);
-
   orb = gnome_CORBA_ORB ();
+#endif
+
+  CORBA_exception_free (&ev);
 
   if (bonobo_init (orb, NULL, NULL) == FALSE)
     g_error (_("Could not initialize Bonobo!\n"));





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]