Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/browser-plugin/plugin.cpp
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marcopg@litl.com>2009-03-13 20:59:34 (GMT)
committer Marco Pesenti Gritti <marcopg@litl.com>2010-07-27 22:04:20 (GMT)
commit4ef6544ecca1803b48985882b1e0e769257b1c93 (patch)
tree077df329af00d4b715a19d261646ff8d8c11c6d5 /browser-plugin/plugin.cpp
parent487906672b11fc7b81a049daf4d8f7b028d9fa02 (diff)
Add a browser plugin implementation.
Diffstat (limited to 'browser-plugin/plugin.cpp')
-rw-r--r--browser-plugin/plugin.cpp179
1 files changed, 179 insertions, 0 deletions
diff --git a/browser-plugin/plugin.cpp b/browser-plugin/plugin.cpp
new file mode 100644
index 0000000..40db488
--- /dev/null
+++ b/browser-plugin/plugin.cpp
@@ -0,0 +1,179 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ * Copyright (C) 2009 litl, LLC
+ *
+ * Evince 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 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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 "evince-view.h"
+#include "plugin.h"
+#include "scriptable.h"
+
+Plugin::Plugin (NPP instance)
+{
+ mInstance = instance;
+ mWindow = 0;
+ mScriptableObject = NULL;
+
+ mScrolledWindow = gtk_scrolled_window_new (NULL, NULL);
+
+ mView = ev_view_new ();
+ g_signal_connect (G_OBJECT (mView),
+ "notify::sizing-mode",
+ G_CALLBACK (Plugin::SizingModeCallback),
+ reinterpret_cast<void*>(this));
+
+ /* FIXME should be set automatically in EvView. It seem to be currently
+ used only to calculate the minimum and maximux allowed zoom level. */
+ ev_view_set_screen_dpi (EV_VIEW(mView), 96);
+
+ gtk_container_add (GTK_CONTAINER(mScrolledWindow), mView);
+ gtk_widget_show (mView);
+
+ UpdateSizingMode ();
+}
+
+Plugin::~Plugin ()
+{
+}
+
+void
+Plugin::ZoomIn ()
+{
+ ev_view_set_sizing_mode (EV_VIEW (mView), EV_SIZING_FREE);
+ ev_view_zoom_in (EV_VIEW (mView));
+}
+
+void
+Plugin::ZoomOut ()
+{
+ ev_view_set_sizing_mode (EV_VIEW (mView), EV_SIZING_FREE);
+ ev_view_zoom_out (EV_VIEW (mView));
+}
+
+void
+Plugin::FindNext (const char *text)
+{
+}
+
+void
+Plugin::FindPrevious (const char *text)
+{
+}
+
+void
+Plugin::SetWindow (GdkNativeWindow window)
+{
+ if (mWindow != 0) {
+ return;
+ }
+
+ mWindow = window;
+
+ GtkWidget *plug = gtk_plug_new (window);
+ gtk_container_add (GTK_CONTAINER (plug), mScrolledWindow);
+ gtk_widget_show (mScrolledWindow);
+
+ gtk_widget_show (plug);
+}
+
+void
+Plugin::Load (const char *fname)
+{
+ GError *error = NULL;
+
+ GFile *file = g_file_new_for_path (fname);
+ char *uri = g_file_get_uri (file);
+ g_object_unref (file);
+
+ /* FIXME display loading error in the UI */
+
+ EvDocument *document = ev_document_factory_get_document (uri, &error);
+ if (error) {
+ g_warning ("Cannot create document for %s", uri);
+ g_error_free (error);
+ return;
+ }
+
+ ev_view_set_document (EV_VIEW (mView), document);
+
+ ev_document_load (document, uri, &error);
+ if (error) {
+ g_warning ("Cannot load %s", uri);
+ g_error_free (error);
+ return;
+ }
+
+ g_free (uri);
+}
+
+NPObject *
+Plugin::GetScriptableNPObject ()
+{
+ if (!mScriptableObject) {
+ mScriptableObject = NPN_CreateObject (
+ mInstance, GET_NPOBJECT_CLASS (ScriptablePluginObject));
+ }
+
+ if (mScriptableObject) {
+ NPN_RetainObject (mScriptableObject);
+ }
+
+ return mScriptableObject;
+}
+
+void
+Plugin::UpdateSizingMode ()
+{
+ EvSizingMode sizingMode;
+
+ g_signal_handlers_disconnect_by_func (
+ mView, (gpointer)ev_view_update_view_size, mScrolledWindow);
+
+ g_object_get (G_OBJECT (mView),
+ "sizing-mode", &sizingMode,
+ NULL);
+
+ if (sizingMode != EV_SIZING_FREE)
+ ev_view_update_view_size (EV_VIEW (mView),
+ GTK_SCROLLED_WINDOW (mScrolledWindow));
+
+ switch (sizingMode) {
+ case EV_SIZING_BEST_FIT:
+ case EV_SIZING_FIT_WIDTH:
+ g_object_set (G_OBJECT (mScrolledWindow),
+ "hscrollbar-policy", GTK_POLICY_NEVER,
+ "vscrollbar-policy", GTK_POLICY_ALWAYS,
+ NULL);
+ g_signal_connect (mView, "zoom_invalid",
+ G_CALLBACK (ev_view_update_view_size),
+ mScrolledWindow);
+ break;
+
+ case EV_SIZING_FREE:
+ g_object_set (G_OBJECT (mScrolledWindow),
+ "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
+ "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
+ NULL);
+ break;
+ }
+}
+
+void
+Plugin::SizingModeCallback (EvView *view, GParamSpec *pspec, gpointer data)
+{
+ Plugin *plugin = reinterpret_cast<Plugin*> (data);
+ plugin->UpdateSizingMode ();
+}