*
* Author:
* Michael Meeks <michael@imaginator.com>
- *
*/
#include <stdio.h>
#include <stdlib.h>
extern "C" {
#define GString G_String
#include <gnome.h>
-#include <libgnorba/gnorba.h>
+
+#include <liboaf/liboaf.h>
+
#include <gdk/gdkprivate.h>
#include <gdk/gdkx.h>
-#include <bonobo/gnome-bonobo.h>
+#include <bonobo.h>
#undef GString
}
-#include <sys/stat.h>
-#include <unistd.h>
-#include "gtypes.h"
-#include "GString.h"
-#include "parseargs.h"
-#include "gfile.h"
-#include "gmem.h"
-#include "Object.h"
-#include "Stream.h"
-#include "Array.h"
-#include "Dict.h"
-#include "XRef.h"
-#include "Catalog.h"
-#include "Page.h"
-#include "Link.h"
-#include "PDFDoc.h"
-#include "GOutputDev.h"
-#include "PSOutputDev.h"
-#include "TextOutputDev.h"
-#include "Params.h"
-#include "Error.h"
#include "config.h"
#include "bonobo-application-x-pdf.h"
/* NB. there is a 1 to 1 Container -> Component mapping, this
is due to how much MDI sucks; unutterably */
struct _Container {
- GnomeContainer *container;
- GnomeUIHandler *uih;
+ BonoboItemContainer *container;
+ BonoboUIComponent *ui_component;
- GnomeViewFrame *active_view_frame;
-
- GtkWidget *app;
- GtkScrolledWindow *scroll;
- GtkWidget *view_widget;
- Component *component;
+ GtkWidget *app;
+ GtkWidget *slot;
+ GtkWidget *view_widget;
+ Component *component;
};
struct _Component {
Container *container;
- GnomeClientSite *client_site;
- GnomeViewFrame *view_frame;
- GnomeObjectClient *server;
+ BonoboClientSite *client_site;
+ BonoboViewFrame *view_frame;
+ BonoboObjectClient *server;
};
GList *containers = NULL;
static void container_close_cmd (GtkWidget *widget, Container *container);
static void container_exit_cmd (void);
static void container_about_cmd (GtkWidget *widget, Container *container);
+ static void container_dump_cmd (GtkWidget *widget, Container *container);
static Component *container_activate_component (Container *container, char *component_goad_id);
}
/*
* The menus.
*/
-static GnomeUIInfo container_file_menu [] = {
- GNOMEUIINFO_MENU_OPEN_ITEM (container_open_cmd, NULL),
- GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_MENU_CLOSE_ITEM(container_close_cmd, NULL),
- GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_MENU_EXIT_ITEM (container_exit_cmd, NULL),
- GNOMEUIINFO_END
-};
+BonoboUIVerb verbs [] = {
+ BONOBO_UI_UNSAFE_VERB ("FileOpen", container_open_cmd),
+ BONOBO_UI_UNSAFE_VERB ("FileClose", container_close_cmd),
+ BONOBO_UI_UNSAFE_VERB ("FileExit", container_exit_cmd),
-static GnomeUIInfo container_help_menu [] = {
- GNOMEUIINFO_MENU_ABOUT_ITEM(container_about_cmd, NULL),
- GNOMEUIINFO_END
-};
-
-static GnomeUIInfo container_main_menu [] = {
- GNOMEUIINFO_MENU_FILE_TREE (container_file_menu),
- GNOMEUIINFO_MENU_HELP_TREE (container_help_menu),
- GNOMEUIINFO_END
-};
+ BONOBO_UI_UNSAFE_VERB ("HelpAbout", container_about_cmd),
-static GnomeUIInfo container_toolbar [] = {
- GNOMEUIINFO_ITEM_STOCK (
- N_("Open"), N_("Opens an existing workbook"),
- container_open_cmd, GNOME_STOCK_PIXMAP_OPEN),
+ BONOBO_UI_UNSAFE_VERB ("DebugDumpXml", container_dump_cmd),
- GNOMEUIINFO_SEPARATOR,
- GNOMEUIINFO_END
+ BONOBO_UI_VERB_END
};
+
extern "C" {
static gboolean
open_pdf (Container *container, const char *name)
{
- GnomeObjectClient *object;
- GnomeStream *stream;
- GNOME_PersistStream persist;
+ BonoboObjectClient *object;
+ BonoboStream *stream;
+ Bonobo_PersistStream persist;
Component *comp;
CORBA_Environment ev;
g_return_val_if_fail (container != NULL, FALSE);
g_return_val_if_fail (container->view_widget == NULL, FALSE);
- comp = container_activate_component (container, "bonobo-object:application-x-pdf");
+ comp = container_activate_component (
+ container, "OAFIID:GNOME_XPDF_Embeddable");
+
if (!comp || !(object = comp->server)) {
gnome_error_dialog (_("Could not launch bonobo object."));
return FALSE;
}
CORBA_exception_init (&ev);
- persist = GNOME_Unknown_query_interface (
- gnome_object_corba_objref (GNOME_OBJECT (object)),
- "IDL:GNOME/PersistStream:1.0", &ev);
+ persist = Bonobo_Unknown_queryInterface (
+ bonobo_object_corba_objref (BONOBO_OBJECT (object)),
+ "IDL:Bonobo/PersistStream:1.0", &ev);
if (ev._major != CORBA_NO_EXCEPTION ||
persist == CORBA_OBJECT_NIL) {
- gnome_error_dialog ("Panic: component is well broken.");
+ gnome_error_dialog ("Panic: component doesn't implement PersistStream.");
return FALSE;
}
- stream = gnome_stream_fs_open (name, GNOME_Storage_READ);
+ stream = bonobo_stream_open (BONOBO_IO_DRIVER_FS, name, Bonobo_Storage_READ, 0);
if (stream == NULL) {
char *err = g_strconcat (_("Could not open "), name, NULL);
return FALSE;
}
- GNOME_PersistStream_load (persist,
- (GNOME_Stream) gnome_object_corba_objref (GNOME_OBJECT (stream)), &ev);
+ Bonobo_PersistStream_load (persist,
+ (Bonobo_Stream) bonobo_object_corba_objref (BONOBO_OBJECT (stream)),
+ "application/pdf",
+ &ev);
- GNOME_Unknown_unref (persist, &ev);
+ Bonobo_Unknown_unref (persist, &ev);
CORBA_Object_release (persist, &ev);
CORBA_exception_free (&ev);
-/* gnome_view_frame_view_do_verb (comp->view_frame, "ZoomFit"); */
+/* bonobo_view_frame_view_do_verb (comp->view_frame, "ZoomFit"); */
return TRUE;
}
component_destroy (Component *component)
{
CORBA_Environment ev;
+ Container *container;
g_return_if_fail (component != NULL);
CORBA_exception_init (&ev);
-
+
+ /* Kill merged menus et al. */
+ bonobo_view_frame_view_deactivate (component->view_frame);
+
+ container = component->container;
+ gtk_widget_destroy (container->view_widget);
+ container->view_widget = NULL;
+
if (component->server)
- GNOME_Unknown_unref (
- gnome_object_corba_objref (GNOME_OBJECT (component->server)), &ev);
+ Bonobo_Unknown_unref (
+ bonobo_object_corba_objref (BONOBO_OBJECT (component->server)), &ev);
component->server = NULL;
CORBA_exception_free (&ev);
+
+ g_free (component);
}
static void
if (!containers)
gtk_main_quit ();
}
+
+ static void
+ container_close (Container *cont)
+ {
+ g_return_if_fail (g_list_find (containers, cont) != NULL);
+
+ if (cont->component) {
+ component_destroy (cont->component);
+ cont->component = NULL;
+ } else
+ container_destroy (cont);
+ }
+
static void
container_close_cmd (GtkWidget *widget, Container *cont)
{
- container_destroy (cont);
+ container_close (cont);
}
static int
container_destroy ((Container *)containers->data);
}
+static void
+container_dump_cmd (GtkWidget *widget, Container *container)
+{
+ bonobo_window_dump (BONOBO_WINDOW(container->app), "on demand");
+}
static void
container_about_cmd (GtkWidget *widget, Container *container)
{
GtkWidget *about;
- int i;
const gchar *authors[] = {
N_("Derek B. Noonburg, main author"),
};
#ifdef ENABLE_NLS
+ int i;
+
for (i = 0; authors[i] != NULL; i++)
authors [i] = _(authors [i]);
#endif
- about = gnome_about_new (_("GPDF"), VERSION,
+ about = gnome_about_new (_("GPDF"), xpdfVersion,
_("(C) 1996-1999 Derek B. Noonburg."),
authors, NULL, NULL);
static void
container_set_view (Container *container, Component *component)
{
- GnomeViewFrame *view_frame;
+ BonoboViewFrame *view_frame;
GtkWidget *view_widget;
/*
* Create the remote view and the local ViewFrame.
*/
- view_frame = gnome_client_site_new_view (component->client_site);
- component->view_frame = view_frame;
+ view_frame = bonobo_client_site_new_view (
+ component->client_site,
+ bonobo_ui_component_get_container (container->ui_component));
- /*
- * Set the GnomeUIHandler for this ViewFrame. That way, the
- * embedded component can get access to our UIHandler server
- * so that it can merge menu and toolbar items when it gets
- * activated.
- */
- gnome_view_frame_set_ui_handler (view_frame, container->uih);
+ component->view_frame = view_frame;
/*
* Embed the view frame into the application.
*/
- view_widget = gnome_view_frame_get_wrapper (view_frame);
+ view_widget = bonobo_view_frame_get_wrapper (view_frame);
+ bonobo_wrapper_set_visibility (BONOBO_WRAPPER (view_widget), FALSE);
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. )
*/
- gnome_view_frame_view_activate (view_frame);
+ 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 GnomeObjectClient *
-container_launch_component (GnomeClientSite *client_site,
- GnomeContainer *container,
- char *component_goad_id)
+static BonoboObjectClient *
+container_launch_component (BonoboClientSite *client_site,
+ BonoboItemContainer *container,
+ char *component_goad_id)
{
- GnomeObjectClient *object_server;
+ BonoboObjectClient *object_server;
/*
* Launch the component.
*/
- object_server = gnome_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;
/*
* Bind it to the local ClientSite. Every embedded component
- * has a local GnomeClientSite object which serves as a
+ * has a local BonoboClientSite object which serves as a
* container-side point of contact for the embeddable. The
* container talks to the embeddable through its ClientSite
*/
- if (!gnome_client_site_bind_embeddable (client_site, object_server)) {
- gnome_object_unref (GNOME_OBJECT (object_server));
+ if (!bonobo_client_site_bind_embeddable (client_site, object_server)) {
+ bonobo_object_unref (BONOBO_OBJECT (object_server));
return NULL;
}
- /*
- * The GnomeContainer object maintains a list of the
- * ClientSites which it manages. Here we add the new
- * ClientSite to that list.
- */
- gnome_container_add (container, GNOME_OBJECT (client_site));
-
return object_server;
}
container_activate_component (Container *container, char *component_goad_id)
{
Component *component;
- GnomeClientSite *client_site;
- GnomeObjectClient *server;
+ BonoboClientSite *client_site;
+ BonoboObjectClient *server;
/*
* The ClientSite is the container-side point of contact for
* the Embeddable. So there is a one-to-one correspondence
- * between GnomeClientSites and GnomeEmbeddables. */
- client_site = gnome_client_site_new (container->container);
+ * between BonoboClientSites and BonoboEmbeddables. */
+ client_site = bonobo_client_site_new (container->container);
/*
- * A GnomeObjectClient is a simple wrapper for a remote
- * GnomeObject (a server supporting GNOME::Unknown).
+ * A BonoboObjectClient is a simple wrapper for a remote
+ * BonoboObject (a server supporting Bonobo::Unknown).
*/
server = container_launch_component (client_site, container->container,
component_goad_id);
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) {
- gnome_view_frame_view_do_verb (component->view_frame, VERB_FIRST);
- return TRUE;
- } else if (event->keyval == GDK_End) {
- gnome_view_frame_view_do_verb (component->view_frame, VERB_LAST);
- return TRUE;
- } else if (event->keyval == GDK_Page_Down ||
- event->keyval == GDK_Next) {
- gnome_view_frame_view_do_verb (component->view_frame, VERB_NEXT);
- return TRUE;
- } else if (event->keyval == GDK_Page_Up ||
- event->keyval == GDK_Prior) {
- gnome_view_frame_view_do_verb (component->view_frame, VERB_PREV);
- return TRUE;
- } else if (event->keyval == GDK_plus ||
- event->keyval == GDK_equal) {
- gnome_view_frame_view_do_verb (component->view_frame, VERB_Z_IN);
- } else if (event->keyval == GDK_underscore ||
- event->keyval == GDK_minus) {
- gnome_view_frame_view_do_verb (component->view_frame, VERB_Z_OUT);
- }
- return FALSE;
- }
-}
-
-static void
-container_create_menus (Container *container)
-{
- GnomeUIHandlerMenuItem *menu_list;
-
- gnome_ui_handler_create_menubar (container->uih);
-
- /*
- * Create the basic menus out of UIInfo structures.
- */
- menu_list = gnome_ui_handler_menu_parse_uiinfo_list_with_data (container_main_menu, container);
- gnome_ui_handler_menu_add_list (container->uih, "/", menu_list);
- gnome_ui_handler_menu_free_list (menu_list);
-}
-
-static void
-container_create_toolbar (Container *container)
-{
- GnomeUIHandlerToolbarItem *toolbar;
-
- gnome_ui_handler_create_toolbar (container->uih, "pdf");
- toolbar = gnome_ui_handler_toolbar_parse_uiinfo_list_with_data (container_toolbar, container);
- gnome_ui_handler_toolbar_add_list (container->uih, "/pdf/", toolbar);
- gnome_ui_handler_toolbar_free_list (toolbar);
}
static Container *
{ "text/uri-list", 0, 0 },
};
static gint n_drag_types = sizeof (drag_types) / sizeof (drag_types [0]);
+ BonoboUIContainer *ui_container;
container = g_new0 (Container, 1);
- container->app = gnome_app_new ("pdf-viewer",
+ container->app = bonobo_window_new ("pdf-viewer",
"GNOME PDF viewer");
gtk_drag_dest_set (container->app,
gtk_signal_connect (GTK_OBJECT(container->app),
"drag_data_received",
- GTK_SIGNAL_FUNC(filenames_dropped), (gpointer)container);
+ GTK_SIGNAL_FUNC(filenames_dropped),
+ (gpointer)container);
gtk_window_set_default_size (GTK_WINDOW (container->app), 600, 600);
gtk_window_set_policy (GTK_WINDOW (container->app), TRUE, TRUE, FALSE);
- container->container = gnome_container_new ();
+ container->container = bonobo_item_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);
+
+ bonobo_window_set_contents (BONOBO_WINDOW(container->app),
+ GTK_WIDGET (container->slot));
+ gtk_widget_show_all (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);
- /*
- * Create the GnomeUIHandler object which will be used to
- * create the container's menus and toolbars. The UIHandler
- * also creates a CORBA server which embedded components use
- * to do menu/toolbar merging.
- */
- container->uih = gnome_ui_handler_new ();
- gnome_ui_handler_set_app (container->uih, GNOME_APP (container->app));
+ ui_container = bonobo_ui_container_new ();
+ bonobo_ui_container_set_win (ui_container, BONOBO_WINDOW(container->app));
+
+ container->ui_component = bonobo_ui_component_new ("gpdf");
+ bonobo_ui_component_set_container (
+ container->ui_component,
+ bonobo_object_corba_objref (BONOBO_OBJECT (ui_container)));
+
+ bonobo_ui_component_add_verb_list_with_data (
+ container->ui_component, verbs, container);
- container_create_menus (container);
- container_create_toolbar (container);
+ bonobo_ui_util_set_ui (container->ui_component, DATADIR, "gpdf-ui.xml", "gpdf");
- gtk_widget_show_all (container->app);
+ gtk_widget_show (container->app);
+
+ containers = g_list_append (containers, container);
if (fname)
if (!open_pdf (container, fname)) {
return NULL;
}
- containers = g_list_append (containers, container);
-
- gtk_widget_show_all (container->app);
+ gtk_widget_show (container->app);
return container;
}
{
CORBA_Environment ev;
CORBA_ORB orb;
- char **view_files = NULL;
+ const char **view_files = NULL;
gboolean loaded;
int i;
CORBA_exception_init (&ev);
- 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);
+ 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);
- orb = gnome_CORBA_ORB ();
+ CORBA_exception_free (&ev);
if (bonobo_init (orb, NULL, NULL) == FALSE)
g_error (_("Could not initialize Bonobo!\n"));