From 9c4aa5453d1eaaa13eacb1d44e36c013be9cf3f9 Mon Sep 17 00:00:00 2001 From: Maciej Stachowiak Date: Sun, 7 May 2000 19:05:40 +0000 Subject: [PATCH] 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. --- pdf/xpdf/GNOME_PDF.oafinfo | 45 +++++++++ pdf/xpdf/GNOME_XPDF.oafinfo | 45 +++++++++ pdf/xpdf/Makefile.am | 25 ++++- pdf/xpdf/application-x-pdf.oafinfo | 45 +++++++++ pdf/xpdf/gpdf.cc | 148 ++++++----------------------- 5 files changed, 186 insertions(+), 122 deletions(-) create mode 100644 pdf/xpdf/GNOME_PDF.oafinfo create mode 100644 pdf/xpdf/GNOME_XPDF.oafinfo create mode 100644 pdf/xpdf/application-x-pdf.oafinfo diff --git a/pdf/xpdf/GNOME_PDF.oafinfo b/pdf/xpdf/GNOME_PDF.oafinfo new file mode 100644 index 00000000..b76d7d28 --- /dev/null +++ b/pdf/xpdf/GNOME_PDF.oafinfo @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pdf/xpdf/GNOME_XPDF.oafinfo b/pdf/xpdf/GNOME_XPDF.oafinfo new file mode 100644 index 00000000..b76d7d28 --- /dev/null +++ b/pdf/xpdf/GNOME_XPDF.oafinfo @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pdf/xpdf/Makefile.am b/pdf/xpdf/Makefile.am index 9074ebc3..3b2b9ae0 100644 --- a/pdf/xpdf/Makefile.am +++ b/pdf/xpdf/Makefile.am @@ -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 @@ gpdf_LDADD = \ $(GTK_LIBS) \ $(GNOME_LIBDIR) \ -lbonobo \ - $(GNOMEGNORBA_LIBS) \ + $(OBJECT_DIRECTORY_LIBS) \ $(EXTRA_GNOME_LIBS) \ $(INTLLIBS) @@ -90,7 +97,7 @@ bonobo_application_x_pdf_LDADD = \ $(GTK_LIBS) \ $(GNOME_LIBDIR) \ -lbonobo \ - $(GNOMEGNORBA_LIBS) \ + $(OBJECT_DIRECTORY_LIBS) \ $(EXTRA_GLIB_LIBS) \ $(INTLLIBS) @@ -162,8 +169,16 @@ ltk = \ 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 diff --git a/pdf/xpdf/application-x-pdf.oafinfo b/pdf/xpdf/application-x-pdf.oafinfo new file mode 100644 index 00000000..b76d7d28 --- /dev/null +++ b/pdf/xpdf/application-x-pdf.oafinfo @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pdf/xpdf/gpdf.cc b/pdf/xpdf/gpdf.cc index a7344674..a78a37e1 100644 --- a/pdf/xpdf/gpdf.cc +++ b/pdf/xpdf/gpdf.cc @@ -12,7 +12,13 @@ extern "C" { #define GString G_String #include + +#if USING_OAF +#include +#else #include +#endif + #include #include #include @@ -39,7 +45,7 @@ struct _Container { BonoboUIHandler *uih; GtkWidget *app; - GtkScrolledWindow *scroll; + GtkWidget *slot; GtkWidget *view_widget; Component *component; }; @@ -111,7 +117,12 @@ extern "C" { 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_set_view (Container *container, Component *component) 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 @@ container_set_view (Container *container, Component *component) 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 @@ container_launch_component (BonoboClientSite *client_site, /* * 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,108 +480,8 @@ extern "C" { 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_new (const char *fname) 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 @@ main (int argc, char **argv) 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")); -- 2.43.5