[Libreoffice-commits] core.git: 42 commits - comphelper/source desktop/qa desktop/README.vars desktop/source framework/source include/comphelper include/LibreOfficeKit include/sfx2 include/vcl libreofficekit/qa libreofficekit/source sfx2/Library_sfx.mk sfx2/source sw/inc sw/qa sw/source

Miklos Vajna vmiklos at collabora.co.uk
Sun Sep 20 22:31:02 PDT 2015


 comphelper/source/misc/lok.cxx                      |   12 
 desktop/README.vars                                 |   16 
 desktop/qa/desktop_lib/test_desktop_lib.cxx         |   32 -
 desktop/source/lib/init.cxx                         |   72 ++
 framework/source/helper/statusindicator.cxx         |    2 
 include/LibreOfficeKit/LibreOfficeKit.h             |   19 
 include/LibreOfficeKit/LibreOfficeKit.hxx           |   50 +
 include/LibreOfficeKit/LibreOfficeKitGtk.h          |    2 
 include/comphelper/lok.hxx                          |    5 
 include/sfx2/lokhelper.hxx                          |   34 +
 include/sfx2/viewsh.hxx                             |    7 
 include/vcl/ITiledRenderable.hxx                    |    2 
 libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx |  537 ++++++++++++--------
 libreofficekit/source/gtk/lokdocview.cxx            |  131 +++-
 sfx2/Library_sfx.mk                                 |    1 
 sfx2/source/view/lokhelper.cxx                      |   83 +++
 sfx2/source/view/viewimp.hxx                        |    3 
 sfx2/source/view/viewsh.cxx                         |   14 
 sw/inc/crsrsh.hxx                                   |    2 
 sw/inc/viewsh.hxx                                   |    3 
 sw/qa/extras/tiledrendering/tiledrendering.cxx      |    4 
 sw/source/core/crsr/crsrsh.cxx                      |   34 +
 sw/source/core/crsr/viscrs.cxx                      |   34 -
 sw/source/core/text/xmldump.cxx                     |   10 
 sw/source/core/view/viewsh.cxx                      |    6 
 sw/source/uibase/docvw/edtwin.cxx                   |   10 
 26 files changed, 856 insertions(+), 269 deletions(-)

New commits:
commit 32f419fee5f9df4facb7a9b3ec910471d2a20247
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Sep 18 14:32:53 2015 +0200

    sw: implement per-view LOK_CALLBACK_CURSOR_VISIBLE
    
    Change-Id: I4e00679547997cfb3dafe603b908f055011a3b30

diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 38e584a..06aed4f 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -23,6 +23,7 @@
 #include <hintids.hxx>
 #include <svx/svdmodel.hxx>
 #include <editeng/frmdiritem.hxx>
+#include <sfx2/viewsh.hxx>
 #include <SwSmartTagMgr.hxx>
 #include <doc.hxx>
 #include <rootfrm.hxx>
@@ -62,6 +63,7 @@
 #include <comcore.hrc>
 #include <IDocumentLayoutAccess.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
 
 using namespace com::sun::star;
 using namespace util;
@@ -2109,8 +2111,13 @@ void SwCrsrShell::ShowCrsr()
         m_bSVCrsrVis = true;
         m_pCurCrsr->SetShowTextInputFieldOverlay( true );
 
-        if (isTiledRendering())
-            libreOfficeKitCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(true).getStr());
+        if (comphelper::LibreOfficeKit::isActive())
+        {
+            if (comphelper::LibreOfficeKit::isViewCallback())
+                GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(true).getStr());
+            else
+                libreOfficeKitCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(true).getStr());
+        }
 
         UpdateCrsr();
     }
@@ -2126,8 +2133,13 @@ void SwCrsrShell::HideCrsr()
         m_pCurCrsr->SetShowTextInputFieldOverlay( false );
         m_pVisCrsr->Hide();
 
-        if (isTiledRendering())
-            libreOfficeKitCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(false).getStr());
+        if (comphelper::LibreOfficeKit::isActive())
+        {
+            if (comphelper::LibreOfficeKit::isViewCallback())
+                GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(false).getStr());
+            else
+                libreOfficeKitCallback(LOK_CALLBACK_CURSOR_VISIBLE, OString::boolean(false).getStr());
+        }
     }
 }
 
commit 1a83f30ebe2c56b00804ce774537b34f1049be84
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Sep 18 14:29:18 2015 +0200

    sw: implement per-view LOK_CALLBACK_TEXT_SELECTION
    
    Also:
    
    - let the unit test set the global LOK flag, as sw code now depends on
      that
    - in framework, don't return early after emitting the LOK status
      indicator callback, otherwise CppunitTest_sw_tiledrendering shows how
      sw LOK callbacks are missing
    
    Change-Id: I0c4ac12f2ef5118d29afd131676bcb27d5db7746

diff --git a/framework/source/helper/statusindicator.cxx b/framework/source/helper/statusindicator.cxx
index 5c9dafc..ce8310a 100644
--- a/framework/source/helper/statusindicator.cxx
+++ b/framework/source/helper/statusindicator.cxx
@@ -43,7 +43,6 @@ void SAL_CALL StatusIndicator::start(const OUString& sText ,
         m_nLastCallbackPercent = -1;
 
         comphelper::LibreOfficeKit::statusIndicatorStart();
-        return;
     }
 
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
@@ -60,7 +59,6 @@ void SAL_CALL StatusIndicator::end()
     if (comphelper::LibreOfficeKit::isActive())
     {
         comphelper::LibreOfficeKit::statusIndicatorFinish();
-        return;
     }
 
     css::uno::Reference< css::task::XStatusIndicatorFactory > xFactory(m_xFactory);
diff --git a/sw/qa/extras/tiledrendering/tiledrendering.cxx b/sw/qa/extras/tiledrendering/tiledrendering.cxx
index 07dd7e3..e7ab149 100644
--- a/sw/qa/extras/tiledrendering/tiledrendering.cxx
+++ b/sw/qa/extras/tiledrendering/tiledrendering.cxx
@@ -383,6 +383,8 @@ void SwTiledRenderingTest::testSearchViewArea()
 void SwTiledRenderingTest::testSearchTextFrame()
 {
 #if !defined(WNT) && !defined(MACOSX)
+    comphelper::LibreOfficeKit::setActive();
+
     SwXTextDocument* pXTextDocument = createDoc("search.odt");
     pXTextDocument->registerCallback(&SwTiledRenderingTest::callback, this);
     uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence(
@@ -393,6 +395,8 @@ void SwTiledRenderingTest::testSearchTextFrame()
     comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
     // This was empty: nothing was highlighted after searching for 'TextFrame'.
     CPPUNIT_ASSERT(!m_aTextSelection.isEmpty());
+
+    comphelper::LibreOfficeKit::setActive(false);
 #endif
 }
 
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index cd47acc..01a2da7 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -361,7 +361,7 @@ void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
         // talks about "the" cursor at the moment. As long as that's true,
         // don't say anything about the Writer cursor till a draw object is
         // being edited.
-        if (GetShell()->isTiledRendering() && !pView->GetTextEditObject())
+        if (comphelper::LibreOfficeKit::isActive() && !pView->GetTextEditObject())
         {
             if (!empty())
             {
@@ -377,12 +377,18 @@ void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
                 if (aStartRect.HasArea())
                 {
                     OString sRect = aStartRect.SVRect().toString();
-                    GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_START, sRect.getStr());
+                    if (comphelper::LibreOfficeKit::isViewCallback())
+                        GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_START, sRect.getStr());
+                    else
+                        GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_START, sRect.getStr());
                 }
                 if (aEndRect.HasArea())
                 {
                     OString sRect = aEndRect.SVRect().toString();
-                    GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, sRect.getStr());
+                    if (comphelper::LibreOfficeKit::isViewCallback())
+                        GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION_END, sRect.getStr());
+                    else
+                        GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION_END, sRect.getStr());
                 }
             }
 
@@ -396,7 +402,12 @@ void SwSelPaintRects::Show(std::vector<OString>* pSelectionRectangles)
             }
             OString sRect = ss.str().c_str();
             if (!pSelectionRectangles)
-                GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
+            {
+                if (comphelper::LibreOfficeKit::isViewCallback())
+                    GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
+                else
+                    GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
+            }
             else
                 pSelectionRectangles->push_back(sRect);
         }
@@ -593,7 +604,7 @@ void SwShellCrsr::Show()
             pShCrsr->SwSelPaintRects::Show(&aSelectionRectangles);
     }
 
-    if (GetShell()->isTiledRendering())
+    if (comphelper::LibreOfficeKit::isActive())
     {
         std::stringstream ss;
         bool bFirst = true;
@@ -609,7 +620,10 @@ void SwShellCrsr::Show()
             ss << rSelectionRectangle.getStr();
         }
         OString sRect = ss.str().c_str();
-        GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
+        if (comphelper::LibreOfficeKit::isViewCallback())
+            GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
+        else
+            GetShell()->libreOfficeKitCallback(LOK_CALLBACK_TEXT_SELECTION, sRect.getStr());
     }
 }
 
commit af29b2b57cc07490cc36ff02d5ff3f3844e7c102
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Sep 18 11:14:58 2015 +0200

    gtktiledviewer: fix leftover import progressbar in createView()
    
    Change-Id: Ia71e80c521cdc6a8e4df52e51e063a44a0dd53df

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index bb60ff1..8686b00 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -194,12 +194,13 @@ static void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/)
 }
 
 /// Common initialization, regardless if it's just a new view or a full init.
-static void setupWidgetAndCreateWindow(GtkWidget* pDocView)
+static TiledWindow& setupWidgetAndCreateWindow(GtkWidget* pDocView)
 {
     setupDocView(pDocView);
     TiledWindow aWindow;
     aWindow.m_pDocView = pDocView;
-    createWindow(aWindow);
+    GtkWidget* pWindow = createWindow(aWindow);
+    return lcl_getTiledWindow(pWindow);
 }
 
 /// Creates a new view, i.e. no LOK init or document load.
@@ -208,7 +209,9 @@ static void createView(GtkWidget* pButton, gpointer /*pItem*/)
     TiledWindow& rWindow = lcl_getTiledWindow(pButton);
     GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView));
 
-    setupWidgetAndCreateWindow(pDocView);
+    TiledWindow& rNewWindow = setupWidgetAndCreateWindow(pDocView);
+    // Hide status bar that contains the unused progress bar.
+    gtk_widget_hide(rNewWindow.m_pStatusBar);
 }
 
 /// Creates a new model, i.e. LOK init and document load, one view implicitly.
commit 43b2103f932c92374e2ba2ab0ec1006582a0f646
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Sep 18 10:58:24 2015 +0200

    gtktiledviewer: don't crash on opening non-existing files
    
    Change-Id: Ic48adaf038e8fbcc86a94b5e351d2f963fcfcd16

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index b16993b..bb60ff1 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -554,8 +554,20 @@ static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpo
 
     if (!lok_doc_view_open_document_finish(pDocView, res, &error))
     {
-        g_warning ("Error occurred while opening the document : %s", error->message);
-        g_error_free (error);
+        GtkDialogFlags eFlags = GTK_DIALOG_DESTROY_WITH_PARENT;
+        GtkWidget* pDialog = gtk_message_dialog_new(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(pDocView))),
+                                                    eFlags,
+                                                    GTK_MESSAGE_ERROR,
+                                                    GTK_BUTTONS_CLOSE,
+                                                    "Error occurred while opening the document: '%s'",
+                                                    error->message);
+        gtk_dialog_run(GTK_DIALOG(pDialog));
+        gtk_widget_destroy(pDialog);
+
+        g_error_free(error);
+        gtk_widget_destroy(GTK_WIDGET(pDocView));
+        gtk_main_quit();
+        return;
     }
 
     populatePartSelector(pDocView);
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 85dc29b..82233cf 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1225,9 +1225,7 @@ openDocumentInThread (gpointer data)
     priv->m_pDocument = priv->m_pOffice->pClass->documentLoad( priv->m_pOffice, priv->m_aDocPath );
     if ( !priv->m_pDocument )
     {
-        // FIXME: should have a GError parameter and populate it.
         char *pError = priv->m_pOffice->pClass->getError( priv->m_pOffice );
-        fprintf( stderr, "Error opening document '%s'\n", pError );
         g_task_return_new_error(task, 0, 0, "%s", pError);
     }
     else
commit de244205f2287263ee9013cf37108186aed531cf
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Sep 18 08:31:36 2015 +0200

    desktop: document a number of environment variables
    
    Change-Id: Ie33f8b2f8d2a65fbdb7f4f3caaeee8f0f046cba5

diff --git a/desktop/README.vars b/desktop/README.vars
new file mode 100644
index 0000000..b84a270
--- /dev/null
+++ b/desktop/README.vars
@@ -0,0 +1,16 @@
+Environment variables in desktop:
+
+General
+-------
+
+DISPLAY - X11 display to use.
+OOO_DISABLE_RECOVERY - Disables the recovery dialog.
+OOO_EXIT_POST_STARTUP - Exit right after startup, for profiling purposes.
+SAL_DISABLE_USERMIGRATION - Disable automatic conversion of old user configurations.
+SAL_USE_VCLPLUGIN - Which VCL plugin to use instead of the auto-detected one.
+
+LibreOfficeKit
+--------------
+
+LOK_DEBUG - Draw a small red rectangle in the top left corner so that it's easy to see where a new tile begins.
+LOK_VIEW_CALLBACK - Use incomplete per-view callbacks instead of a single one.
commit 5c2811d682c6e623f3b2613df3119987c0c79c12
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 17:19:49 2015 +0200

    sw: implement per-view LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR
    
    Change-Id: Ib4c1caede94d3eac372a3605c430bbbd353755f3

diff --git a/sw/inc/viewsh.hxx b/sw/inc/viewsh.hxx
index d1bf9ca..500f552 100644
--- a/sw/inc/viewsh.hxx
+++ b/sw/inc/viewsh.hxx
@@ -442,7 +442,7 @@ public:
                           { return mpCareWindow ? mpCareWindow.get() : CareChildWin(rVSh); }
     static vcl::Window*   CareChildWin(SwViewShell& rVSh);
 
-    inline SfxViewShell   *GetSfxViewShell() { return mpSfxViewShell; }
+    inline SfxViewShell   *GetSfxViewShell() const { return mpSfxViewShell; }
     inline void           SetSfxViewShell(SfxViewShell *pNew) { mpSfxViewShell = pNew; }
 
     // Selection of  Draw Engine has been changed.
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index a6a8957..cd47acc 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -54,6 +54,7 @@
 #include <memory>
 
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
 #include <paintfrm.hxx>
 
 // Here static members are defined. They will get changed on alteration of the
@@ -178,7 +179,7 @@ void SwVisCrsr::_SetPosAndShow()
 
     m_aTextCrsr.SetPos( aRect.Pos() );
 
-    if (m_pCrsrShell->isTiledRendering())
+    if (comphelper::LibreOfficeKit::isActive())
     {
         // notify about page number change (if that happened)
         sal_uInt16 nPage, nVirtPage;
@@ -193,7 +194,10 @@ void SwVisCrsr::_SetPosAndShow()
         // notify about the cursor position & size
         Rectangle aSVRect(aRect.Pos().getX(), aRect.Pos().getY(), aRect.Pos().getX() + aRect.SSize().Width(), aRect.Pos().getY() + aRect.SSize().Height());
         OString sRect = aSVRect.toString();
-        m_pCrsrShell->libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+        if (comphelper::LibreOfficeKit::isViewCallback())
+            m_pCrsrShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+        else
+            m_pCrsrShell->libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
     }
 
     if ( !m_pCrsrShell->IsCrsrReadonly()  || m_pCrsrShell->GetViewOptions()->IsSelectionInReadonly() )
commit b20de6c5cfad2a48c4b35b7111b3d6ea285de061
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 15:42:16 2015 +0200

    sfx2: adapt comment to reality
    
    Change-Id: I9dd2934eaa7b479460c3a2dc7d2d51ce5c767a9f

diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index 70f3931..ca5090f 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -318,7 +318,7 @@ public:
     SAL_DLLPRIVATE void TakeFrameOwnership_Impl();
     SAL_DLLPRIVATE bool ExecKey_Impl(const KeyEvent& aKey);
 
-    /// The actual implementation of the lok::Document::registerViewCallback() API.
+    /// The actual per-view implementation of lok::Document::registerCallback().
     void registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCallback, void* pLibreOfficeKitData);
     /// Invokes the registered callback, if there are any.
     void libreOfficeKitViewCallback(int nType, const char* pPayload) const;
commit b8a54763f4f66538f13b6c0e13045e5cb3167ca4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 15:39:19 2015 +0200

    lok::Document: register callback in the view, if requested
    
    With this, a postKeyEvent() in one view properly results in one
    LOK_CALLBACK_INVALIDATE_TILES per view, at least in Writer.
    
    Change-Id: Ia0a9a00ea5a98c38f3d399208b9ef028f3036f79

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0aadc3b..d86a84e 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -53,6 +53,8 @@
 #include <sfx2/msgpool.hxx>
 #include <sfx2/dispatch.hxx>
 #include <sfx2/lokhelper.hxx>
+#include <sfx2/viewfrm.hxx>
+#include <sfx2/viewsh.hxx>
 #include <svx/svxids.hrc>
 #include <vcl/svapp.hxx>
 #include <vcl/svpforlokit.hxx>
@@ -813,14 +815,22 @@ static void doc_registerCallback(LibreOfficeKitDocument* pThis,
                                 LibreOfficeKitCallback pCallback,
                                 void* pData)
 {
-    ITiledRenderable* pDoc = getTiledRenderable(pThis);
-    if (!pDoc)
+    if (comphelper::LibreOfficeKit::isViewCallback())
     {
-        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
-        return;
+        if (SfxViewShell* pViewShell = SfxViewFrame::Current()->GetViewShell())
+            pViewShell->registerLibreOfficeKitViewCallback(pCallback, pData);
     }
+    else
+    {
+        ITiledRenderable* pDoc = getTiledRenderable(pThis);
+        if (!pDoc)
+        {
+            gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
+            return;
+        }
 
-    pDoc->registerCallback(pCallback, pData);
+        pDoc->registerCallback(pCallback, pData);
+    }
 }
 
 static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nCharCode, int nKeyCode)
commit b0f04d1ba273cc94989a5079f957117433076a9b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 11:44:53 2015 +0200

    sw: implement per-view LOK_CALLBACK_INVALIDATE_TILES
    
    Change-Id: Id839dc076824e69fe07386c83bf21fc4c7ce2b8e

diff --git a/sw/source/uibase/docvw/edtwin.cxx b/sw/source/uibase/docvw/edtwin.cxx
index d7852e4..49e5273 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -69,6 +69,7 @@
 #include <basegfx/polygon/b2dpolygon.hxx>
 
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
+#include <comphelper/lok.hxx>
 
 #include <editeng/acorrcfg.hxx>
 #include <SwSmartTagMgr.hxx>
@@ -6223,8 +6224,13 @@ void SwEditWin::LogicInvalidate(const Rectangle* pRectangle)
     else
         sRectangle = pRectangle->toString();
 
-    if ( m_rView.GetWrtShellPtr() )
-        m_rView.GetWrtShell().libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
+    if (comphelper::LibreOfficeKit::isViewCallback())
+        m_rView.libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
+    else
+    {
+        if (m_rView.GetWrtShellPtr())
+            m_rView.GetWrtShell().libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_TILES, sRectangle.getStr());
+    }
 }
 
 void SwEditWin::LogicMouseButtonDown(const MouseEvent& rMouseEvent)
commit 1704221067e2bc6ba26eaa83573d29964b413a34
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 10:59:13 2015 +0200

    comphelper: add LibreOfficeKit::set/isViewCallback()
    
    Change-Id: Iad0b2ee419327daf478f3ddda2378effe0184067

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index a6abd2a..279ec65 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -17,6 +17,8 @@ namespace LibreOfficeKit
 
 static bool g_bActive(false);
 
+static bool g_bViewCallback(false);
+
 void setActive(bool bActive)
 {
     g_bActive = bActive;
@@ -27,6 +29,16 @@ bool isActive()
     return g_bActive;
 }
 
+void setViewCallback(bool bViewCallback)
+{
+    g_bViewCallback = bViewCallback;
+}
+
+bool isViewCallback()
+{
+    return g_bViewCallback;
+}
+
 static void (*pStatusIndicatorCallback)(void *data, statusIndicatorCallbackType type, int percent)(nullptr);
 static void *pStatusIndicatorCallbackData(nullptr);
 
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index c4301fd..0aadc3b 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1189,6 +1189,10 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
         return 1;
 
     comphelper::LibreOfficeKit::setActive();
+
+    static bool bViewCallback = getenv("LOK_VIEW_CALLBACK");
+    comphelper::LibreOfficeKit::setViewCallback(bViewCallback);
+
     comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
 
     if (pUserProfilePath)
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 79fa115..2cc38c6 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -36,6 +36,11 @@ COMPHELPER_DLLPUBLIC void setStatusIndicatorCallback(void (*callback)(void *data
 // Check whether the code is running as invoked through LibreOfficeKit.
 COMPHELPER_DLLPUBLIC bool isActive();
 
+/// Check whether clients register a callback for each view.
+COMPHELPER_DLLPUBLIC bool isViewCallback();
+/// Set whether clients register a callback for each view.
+COMPHELPER_DLLPUBLIC void setViewCallback(bool bViewCallback);
+
 // Status indicator handling. Even if in theory there could be several status indicators active at
 // the same time, in practice there is only one at a time, so we don't handle any identification of
 // status indicator in this API.
commit c74ccac7cd94eba052d21cf74e03e214d58942e4
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 10:58:56 2015 +0200

    sfx2: add SfxViewShell::libreOfficeKitViewCallback()
    
    This is similar to the existing LOK callback, the difference is that the
    existing one assumes there is only one SfxViewShell instance at the same
    time.
    
    This newer callback is precisely per-view, so model notifications can
    invoke all view callbacks, while view notifications can invoke only the
    callback of the relevant view.
    
    This is just the framework, all actual client code has to be still
    ported over (and then the existing callback can be removed).
    
    Change-Id: I3d8f27740c69fcf6ffbbdce12db2ea088321493d

diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index e88203d..70f3931 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -39,6 +39,8 @@
 #include <o3tl/typed_flags_set.hxx>
 #include <vcl/vclptr.hxx>
 #include <sfx2/tabdlg.hxx>
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKitTypes.h>
 
 class SfxBaseController;
 class Size;
@@ -315,6 +317,11 @@ public:
     SAL_DLLPRIVATE void TakeOwnership_Impl();
     SAL_DLLPRIVATE void TakeFrameOwnership_Impl();
     SAL_DLLPRIVATE bool ExecKey_Impl(const KeyEvent& aKey);
+
+    /// The actual implementation of the lok::Document::registerViewCallback() API.
+    void registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCallback, void* pLibreOfficeKitData);
+    /// Invokes the registered callback, if there are any.
+    void libreOfficeKitViewCallback(int nType, const char* pPayload) const;
 };
 
 
diff --git a/sfx2/source/view/viewimp.hxx b/sfx2/source/view/viewimp.hxx
index 4900593..b832b15 100644
--- a/sfx2/source/view/viewimp.hxx
+++ b/sfx2/source/view/viewimp.hxx
@@ -64,6 +64,9 @@ struct SfxViewShell_Impl
 
     mutable SfxInPlaceClientList* mpIPClientList;
 
+    LibreOfficeKitCallback m_pLibreOfficeKitViewCallback;
+    void* m_pLibreOfficeKitViewData;
+
     explicit SfxViewShell_Impl(SfxViewShellFlags const nFlags);
     ~SfxViewShell_Impl();
 
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 62ed8bd..2b9ac3d 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -309,6 +309,8 @@ SfxViewShell_Impl::SfxViewShell_Impl(SfxViewShellFlags const nFlags)
 ,   m_nFamily(0xFFFF)   // undefined, default set by TemplateDialog
 ,   m_pController(0)
 ,   mpIPClientList(NULL)
+,   m_pLibreOfficeKitViewCallback(0)
+,   m_pLibreOfficeKitViewData(0)
 {}
 
 SfxViewShell_Impl::~SfxViewShell_Impl()
@@ -1631,6 +1633,18 @@ bool SfxViewShell::ExecKey_Impl(const KeyEvent& aKey)
     return pImp->m_xAccExec->execute(aKey.GetKeyCode());
 }
 
+void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCallback, void* pData)
+{
+    pImp->m_pLibreOfficeKitViewCallback = pCallback;
+    pImp->m_pLibreOfficeKitViewData = pData;
+}
+
+void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) const
+{
+    if (pImp->m_pLibreOfficeKitViewCallback)
+        pImp->m_pLibreOfficeKitViewCallback(nType, pPayload, pImp->m_pLibreOfficeKitViewData);
+}
+
 bool SfxViewShell::KeyInput( const KeyEvent &rKeyEvent )
 
 /*  [Description]
commit 714257af17f74f8bcb5acceaebb0d0f4b3be3231
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Sep 17 09:30:09 2015 +0200

    SfxLokHelper::setView: check if view is already current
    
    Change-Id: I9cf3a4887774657e0e205114688b088fc11c6822

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 646715e..f3731e7 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -45,6 +45,9 @@ void SfxLokHelper::setView(size_t nId)
         return;
 
     SfxViewShell* pViewShell = rViewArr[nId];
+    if (pViewShell->GetViewFrame() == SfxViewFrame::Current())
+        return;
+
     if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
         pViewFrame->MakeActive_Impl(false);
 }
commit d3446bc860e2e41adbee5ad6c49f12991dd9087b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 14:46:39 2015 +0200

    lokdocview: set view before calling lok::Document member functions
    
    getTextSelection() is still to be done, but has to be moved to the
    widget first.
    
    Change-Id: I780a31f1dbce38b2b7398bfdacbbc1c40881229d

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 97ae136..4c3e1fa 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -158,7 +158,7 @@ struct _LibreOfficeKitDocumentClass
     /// @see lok::Document::resetSelection
     void (*resetSelection) (LibreOfficeKitDocument* pThis);
 
-    /// @see lok::Document:getStyles
+    /// @see lok::Document::getCommandValues().
     char* (*getCommandValues) (LibreOfficeKitDocument* pThis, const char* pCommand);
 
     /// @see lok::Document::createView().
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index ee9ab9f..85dc29b 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -391,6 +391,7 @@ static gboolean postDocumentLoad(gpointer pData)
     LOKDocView* pLOKDocView = static_cast<LOKDocView*>(pData);
     LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument);
     priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView);
     priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
@@ -1101,6 +1102,7 @@ lok_doc_view_signal_motion (GtkWidget* pWidget, GdkEventMotion* pEvent)
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
     GdkPoint aPoint;
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     if (priv->m_bInDragMiddleHandle)
     {
         g_info("lcl_signalMotion: dragging the middle handle");
@@ -1183,6 +1185,7 @@ setGraphicSelectionInThread(gpointer data)
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->setGraphicSelection(priv->m_pDocument,
                                                    pLOEvent->m_nSetGraphicSelectionType,
                                                    pLOEvent->m_nSetGraphicSelectionX,
@@ -1243,6 +1246,7 @@ setPartInThread(gpointer data)
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
     int nPart = pLOEvent->m_nPart;
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->setPart( priv->m_pDocument, nPart );
 }
 
@@ -1255,6 +1259,7 @@ setPartmodeInThread(gpointer data)
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
     int nPartMode = pLOEvent->m_nPartMode;
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->setPartMode( priv->m_pDocument, nPartMode );
 }
 
@@ -1273,6 +1278,7 @@ setEditInThread(gpointer data)
     else if (priv->m_bEdit && !bEdit)
     {
         g_info("lok_doc_view_set_edit: leaving edit mode");
+        priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
         priv->m_pDocument->pClass->resetSelection(priv->m_pDocument);
     }
     priv->m_bEdit = bEdit;
@@ -1288,6 +1294,7 @@ postCommandInThread (gpointer data)
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->postUnoCommand(priv->m_pDocument, pLOEvent->m_pCommand, pLOEvent->m_pArguments);
 }
 
@@ -1316,6 +1323,7 @@ paintTileInThread (gpointer data)
     aTileRectangle.x = pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom) * pLOEvent->m_nPaintTileY;
     aTileRectangle.y = pixelToTwip(nTileSizePixels, pLOEvent->m_fPaintTileZoom) * pLOEvent->m_nPaintTileX;
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     g_test_timer_start();
     priv->m_pDocument->pClass->paintTile(priv->m_pDocument,
                                          pBuffer,
@@ -1974,6 +1982,7 @@ SAL_DLLPUBLIC_EXPORT int
 lok_doc_view_get_parts (LOKDocView* pDocView)
 {
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     return priv->m_pDocument->pClass->getParts( priv->m_pDocument );
 }
 
@@ -1981,6 +1990,7 @@ SAL_DLLPUBLIC_EXPORT int
 lok_doc_view_get_part (LOKDocView* pDocView)
 {
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     return priv->m_pDocument->pClass->getPart( priv->m_pDocument );
 }
 
@@ -2002,6 +2012,7 @@ SAL_DLLPUBLIC_EXPORT char*
 lok_doc_view_get_part_name (LOKDocView* pDocView, int nPart)
 {
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     return priv->m_pDocument->pClass->getPartName( priv->m_pDocument, nPart );
 }
 
commit 42844c2a8b614efa3bb7cd4f2525ce05a8647d20
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 14:31:49 2015 +0200

    Add missing lok::Document::setPartMode() wrapper
    
    Change-Id: I5dd5f0cfb8b34621b18a35be682249e042d9b173

diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index fc025ae..97ae136 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -93,10 +93,7 @@ struct _LibreOfficeKitDocumentClass
     char* (*getPartName) (LibreOfficeKitDocument* pThis,
                           int nPart);
 
-    /** Sets mode of the current part.
-     *
-     * @param nMode - element from the LibreOfficeKitPartMode enum.
-     */
+    /// @see lok::Document::setPartMode().
     void (*setPartMode) (LibreOfficeKitDocument* pThis,
                          int nMode);
 
@@ -118,6 +115,7 @@ struct _LibreOfficeKitDocumentClass
     /// @see lok::Document::initializeForRendering().
     void (*initializeForRendering) (LibreOfficeKitDocument* pThis);
 
+    /// @see lok::Document::registerCallback().
     void (*registerCallback) (LibreOfficeKitDocument* pThis,
                               LibreOfficeKitCallback pCallback,
                               void* pData);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 45ace9d..7f96e19 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -94,6 +94,11 @@ public:
         return mpDoc->pClass->getPartName(mpDoc, nPart);
     }
 
+    inline void setPartMode(int nMode)
+    {
+        mpDoc->pClass->setPartMode(mpDoc, nMode);
+    }
+
     /**
      * Renders a subset of the document to a pre-allocated buffer.
      *
commit c9ebc92a1ebd48ad96ee5ca527c250489cb4ec27
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 14:28:00 2015 +0200

    LOK: allow postMouseEvent() in multiple views
    
    Change-Id: Iafb08cb44a96dbc03d12367d21b4120063bd0222

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 25f1c48..ee9ab9f 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1197,6 +1197,7 @@ postMouseEventInThread(gpointer data)
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->postMouseEvent(priv->m_pDocument,
                                               pLOEvent->m_nPostMouseEventType,
                                               pLOEvent->m_nPostMouseEventX,
commit a04b31c9facb08a8e38b79480b9a73bd2693cb9e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 14:14:04 2015 +0200

    LOK: make getViews() be a member function of Document
    
    Just to be consistent, as all other view-related member functions are
    there, too.
    
    No real impact, as only the unit test uses this so far, and it always
    works with a single document.
    
    Change-Id: I46f1ed8265ab95017986ab45c1b510e961192241

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 7ad8127..0cd88ce 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -134,10 +134,10 @@ void DesktopLOKTest::testGetFonts()
 void DesktopLOKTest::testCreateView()
 {
     LibLODocument_Impl* pDocument = loadDoc("blank_text.odt");
-    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
+    CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument));
 
     int nId = pDocument->m_pDocumentClass->createView(pDocument);
-    CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
+    CPPUNIT_ASSERT_EQUAL(2, pDocument->m_pDocumentClass->getViews(pDocument));
 
     // Make sure the created view is the active one, then switch to the old
     // one.
@@ -146,7 +146,7 @@ void DesktopLOKTest::testCreateView()
     CPPUNIT_ASSERT_EQUAL(0, pDocument->m_pDocumentClass->getView(pDocument));
 
     pDocument->m_pDocumentClass->destroyView(pDocument, nId);
-    CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
+    CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getViews(pDocument));
     closeDoc();
 }
 
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0548ea3..c4301fd 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -251,6 +251,7 @@ static int doc_createView(LibreOfficeKitDocument* pThis);
 static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
 static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
 static int doc_getView(LibreOfficeKitDocument* pThis);
+static int doc_getViews(LibreOfficeKitDocument* pThis);
 
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
     mxComponent( xComponent )
@@ -286,6 +287,7 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
         m_pDocumentClass->destroyView = doc_destroyView;
         m_pDocumentClass->setView = doc_setView;
         m_pDocumentClass->getView = doc_getView;
+        m_pDocumentClass->getViews = doc_getViews;
 
         gDocumentClass = m_pDocumentClass;
     }
@@ -313,8 +315,6 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions  (LibreOfficeKit* pThi
 static void                    lo_registerCallback (LibreOfficeKit* pThis,
                                                     LibreOfficeKitCallback pCallback,
                                                     void* pData);
-static int lo_getViews(LibreOfficeKit* pThis);
-
 struct LibLibreOffice_Impl : public _LibreOfficeKit
 {
     OUString maLastExceptionMsg;
@@ -337,7 +337,6 @@ struct LibLibreOffice_Impl : public _LibreOfficeKit
             m_pOfficeClass->getError = lo_getError;
             m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
             m_pOfficeClass->registerCallback = lo_registerCallback;
-            m_pOfficeClass->getViews = lo_getViews;
 
             gOfficeClass = m_pOfficeClass;
         }
@@ -455,11 +454,6 @@ static void lo_registerCallback (LibreOfficeKit* pThis,
     pLib->mpCallbackData = pData;
 }
 
-static int lo_getViews(LibreOfficeKit* /*pThis*/)
-{
-    return SfxLokHelper::getViews();
-}
-
 static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const char* pFormat, const char* pFilterOptions)
 {
     LibLODocument_Impl* pDocument = static_cast<LibLODocument_Impl*>(pThis);
@@ -1074,6 +1068,13 @@ static int doc_getView(LibreOfficeKitDocument* /*pThis*/)
     return SfxLokHelper::getView();
 }
 
+static int doc_getViews(LibreOfficeKitDocument* /*pThis*/)
+{
+    SolarMutexGuard aGuard;
+
+    return SfxLokHelper::getViews();
+}
+
 static char* lo_getError (LibreOfficeKit *pThis)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 18f4b3e..fc025ae 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -54,9 +54,6 @@ struct _LibreOfficeKitClass
     void (*registerCallback) (LibreOfficeKit* pThis,
                               LibreOfficeKitCallback pCallback,
                               void* pData);
-
-    /// @see lok::Office::getViews().
-    int (*getViews) (LibreOfficeKit* pThis);
 #endif
 };
 
@@ -174,6 +171,8 @@ struct _LibreOfficeKitDocumentClass
     void (*setView) (LibreOfficeKitDocument* pThis, int nId);
     /// @see lok::Document::getView().
     int (*getView) (LibreOfficeKitDocument* pThis);
+    /// @see lok::Document::getViews().
+    int (*getViews) (LibreOfficeKitDocument* pThis);
 #endif // LOK_USE_UNSTABLE_API
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index f5821b7..45ace9d 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -294,6 +294,14 @@ public:
     {
         return mpDoc->pClass->getView(mpDoc);
     }
+
+    /**
+     * Get number of views of this document.
+     */
+    inline int getViews()
+    {
+        return mpDoc->pClass->getViews(mpDoc);
+    }
 #endif // LOK_USE_UNSTABLE_API
 };
 
@@ -340,16 +348,6 @@ public:
     {
         return mpThis->pClass->getError(mpThis);
     }
-
-#ifdef LOK_USE_UNSTABLE_API
-    /**
-     * Get number of total views.
-     */
-    inline int getViews()
-    {
-        return mpThis->pClass->getViews(mpThis);
-    }
-#endif
 };
 
 /// Factory method to create a lok::Office instance.
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 5051622..99f2076 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -25,9 +25,8 @@ public:
     static void setView(size_t nId);
     /// Get the currently active view.
     static size_t getView();
-
-    /// Total number of view shells.
-    static int getViews();
+    /// Get the number of views of the current object shell.
+    static size_t getViews();
 };
 
 #endif
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 0beb06d..646715e 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -62,10 +62,19 @@ size_t SfxLokHelper::getView()
     return 0;
 }
 
-int SfxLokHelper::getViews()
+size_t SfxLokHelper::getViews()
 {
+    size_t nRet = 0;
+
+    SfxObjectShell* pObjectShell = SfxViewFrame::Current()->GetObjectShell();
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
-    return rViewArr.size();
+    for (size_t i = 0; i < rViewArr.size(); ++i)
+    {
+        if (rViewArr[i]->GetObjectShell() == pObjectShell)
+            ++nRet;
+    }
+
+    return nRet;
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit f2e55ea10676d14c6564696a0648c0edbe4bd36d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 12:30:25 2015 +0200

    gtktiledviewer: use setView() before postKeyEvent()
    
    Also in SfxLokHelper::setView() set the current view shell directly,
    GetFocus() in VCL may be a NOP for hidden windows.
    
    With this, the Writer layout dump shows that two Gtk windows can have
    different cursor positions correctly.
    
    Change-Id: I81890c1d8ad7972f1194db3d5f2e9d8a39fc2f87

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 271625f..25f1c48 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -106,6 +106,9 @@ struct _LOKDocViewPrivate
     /// If we are in the middle of a drag of a graphic selection handle.
     gboolean m_bInDragGraphicHandles[8];
     ///@}
+
+    /// View ID, returned by createView() or 0 by default.
+    int m_nViewId;
 };
 
 enum
@@ -240,6 +243,7 @@ postKeyEventInThread(gpointer data)
     LOKDocViewPrivate *priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private (pDocView));
     LOEvent* pLOEvent = static_cast<LOEvent*>(g_task_get_task_data(task));
 
+    priv->m_pDocument->pClass->setView(priv->m_pDocument, priv->m_nViewId);
     priv->m_pDocument->pClass->postKeyEvent(priv->m_pDocument,
                                             pLOEvent->m_nKeyEvent,
                                             pLOEvent->m_nCharCode,
@@ -1847,18 +1851,19 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
     return GTK_WIDGET (g_initable_new (LOK_TYPE_DOC_VIEW, cancellable, error, "lopath", pPath, NULL));
 }
 
-SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pLOKDocView)
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pOldLOKDocView)
 {
-    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
-    GtkWidget* pDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
-                                                    "lopath", priv->m_aLOPath, "lopointer", priv->m_pOffice, "docpointer", priv->m_pDocument, NULL));
+    LOKDocViewPrivate* pOldPriv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pOldLOKDocView));
+    GtkWidget* pNewDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
+                                                       "lopath", pOldPriv->m_aLOPath, "lopointer", pOldPriv->m_pOffice, "docpointer", pOldPriv->m_pDocument, NULL));
 
     // No documentLoad(), just a createView().
-    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pDocView));
-    pDocument->pClass->createView(pDocument);
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pNewDocView));
+    LOKDocViewPrivate* pNewPriv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(LOK_DOC_VIEW(pNewDocView)));
+    pNewPriv->m_nViewId = pDocument->pClass->createView(pDocument);
 
-    postDocumentLoad(pDocView);
-    return pDocView;
+    postDocumentLoad(pNewDocView);
+    return pNewDocView;
 }
 
 /**
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index f53d2b3..0beb06d 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -46,7 +46,7 @@ void SfxLokHelper::setView(size_t nId)
 
     SfxViewShell* pViewShell = rViewArr[nId];
     if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
-        pViewFrame->GetWindow().GrabFocus();
+        pViewFrame->MakeActive_Impl(false);
 }
 
 size_t SfxLokHelper::getView()
commit 8cb6094447041b7fbe29bd5584b5daf9babb5cad
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 10:32:34 2015 +0200

    Use SfxViewFrame::Current()
    
    Allows getting rid of vcl::ITiledRenderable::getCurrentViewShell(),
    which would do the same, just not implemented outside Writer.
    
    Change-Id: Id26ceca560fb9002dc2d5c740c411b9c4a149523

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index fd33297..0548ea3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1046,19 +1046,11 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
     }
 }
 
-static int doc_createView(LibreOfficeKitDocument* pThis)
+static int doc_createView(LibreOfficeKitDocument* /*pThis*/)
 {
     SolarMutexGuard aGuard;
 
-    ITiledRenderable* pDoc = getTiledRenderable(pThis);
-    if (!pDoc)
-    {
-        gImpl->maLastExceptionMsg = "Document doesn't support tiled rendering";
-        return -1;
-    }
-
-    SfxViewShell* pViewShell = pDoc->getCurrentViewShell();
-    return SfxLokHelper::createView(pViewShell);
+    return SfxLokHelper::createView();
 }
 
 static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index a05cd5d..5051622 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -17,8 +17,8 @@ class SfxViewShell;
 class SFX2_DLLPUBLIC SfxLokHelper
 {
 public:
-    /// Create a new view shell for pViewShell's object shell.
-    static int createView(SfxViewShell* pViewShell);
+    /// Create a new view shell from the current view frame.
+    static int createView();
     /// Destroy a view shell from the global shell list.
     static void destroyView(size_t nId);
     /// Set a view shell as current one.
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index a31d808..6639745 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -16,8 +16,6 @@
 #include <tools/gen.hxx>
 #include <vcl/virdev.hxx>
 
-class SfxViewShell;
-
 namespace vcl
 {
 
@@ -141,12 +139,6 @@ public:
      * @see lok::Document::resetSelection().
      */
     virtual void resetSelection() = 0;
-
-    /// Get the currently active view shell of the document.
-    virtual SfxViewShell* getCurrentViewShell()
-    {
-        return 0;
-    }
 };
 
 } // namespace vcl
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 0aea6db..f53d2b3 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -15,9 +15,9 @@
 
 #include <shellimpl.hxx>
 
-int SfxLokHelper::createView(SfxViewShell* pViewShell)
+int SfxLokHelper::createView()
 {
-    SfxViewFrame* pViewFrame = pViewShell->GetViewFrame();
+    SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     SfxRequest aRequest(pViewFrame, SID_NEWWINDOW);
     pViewFrame->ExecView_Impl(aRequest);
 
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 0ca6e5b..8306b83 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -428,8 +428,6 @@ public:
     virtual void setGraphicSelection(int nType, int nX, int nY) SAL_OVERRIDE;
     /// @see vcl::ITiledRenderable::resetSelection().
     virtual void resetSelection() SAL_OVERRIDE;
-    /// @see vcl::ITiledRenderable::getCurrentViewShell().
-    virtual SfxViewShell* getCurrentViewShell() SAL_OVERRIDE;
 
     // ::com::sun::star::tiledrendering::XTiledRenderable
     virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception) SAL_OVERRIDE;
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 6192b5d..ab5b828 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -3400,11 +3400,6 @@ void SwXTextDocument::resetSelection()
     pWrtShell->ResetSelect(0, false);
 }
 
-SfxViewShell* SwXTextDocument::getCurrentViewShell()
-{
-    return pDocShell->GetView();
-}
-
 void SAL_CALL SwXTextDocument::paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception)
 {
     SystemGraphicsData aData;
commit 46588c42a546d4517b773853856b9c8f8c2e5ece
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 09:30:41 2015 +0200

    lok::Document: add get/setView()
    
    Change-Id: Ic3bce8f01d7e048e853c063c4bce1255845c60d0

diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index 6baaa32..7ad8127 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -139,6 +139,12 @@ void DesktopLOKTest::testCreateView()
     int nId = pDocument->m_pDocumentClass->createView(pDocument);
     CPPUNIT_ASSERT_EQUAL(2, SfxLokHelper::getViews());
 
+    // Make sure the created view is the active one, then switch to the old
+    // one.
+    CPPUNIT_ASSERT_EQUAL(1, pDocument->m_pDocumentClass->getView(pDocument));
+    pDocument->m_pDocumentClass->setView(pDocument, 0);
+    CPPUNIT_ASSERT_EQUAL(0, pDocument->m_pDocumentClass->getView(pDocument));
+
     pDocument->m_pDocumentClass->destroyView(pDocument, nId);
     CPPUNIT_ASSERT_EQUAL(1, SfxLokHelper::getViews());
     closeDoc();
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 15ab2e7..fd33297 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -249,6 +249,8 @@ static char* doc_getCommandValues(LibreOfficeKitDocument* pThis, const char* pCo
 
 static int doc_createView(LibreOfficeKitDocument* pThis);
 static void doc_destroyView(LibreOfficeKitDocument* pThis, int nId);
+static void doc_setView(LibreOfficeKitDocument* pThis, int nId);
+static int doc_getView(LibreOfficeKitDocument* pThis);
 
 LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XComponent> &xComponent) :
     mxComponent( xComponent )
@@ -282,6 +284,8 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
 
         m_pDocumentClass->createView = doc_createView;
         m_pDocumentClass->destroyView = doc_destroyView;
+        m_pDocumentClass->setView = doc_setView;
+        m_pDocumentClass->getView = doc_getView;
 
         gDocumentClass = m_pDocumentClass;
     }
@@ -1064,6 +1068,20 @@ static void doc_destroyView(LibreOfficeKitDocument* /*pThis*/, int nId)
     SfxLokHelper::destroyView(nId);
 }
 
+static void doc_setView(LibreOfficeKitDocument* /*pThis*/, int nId)
+{
+    SolarMutexGuard aGuard;
+
+    SfxLokHelper::setView(nId);
+}
+
+static int doc_getView(LibreOfficeKitDocument* /*pThis*/)
+{
+    SolarMutexGuard aGuard;
+
+    return SfxLokHelper::getView();
+}
+
 static char* lo_getError (LibreOfficeKit *pThis)
 {
     LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 7f41d13..18f4b3e 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -170,6 +170,10 @@ struct _LibreOfficeKitDocumentClass
     int (*createView) (LibreOfficeKitDocument* pThis);
     /// @see lok::Document::destroyView().
     void (*destroyView) (LibreOfficeKitDocument* pThis, int nId);
+    /// @see lok::Document::setView().
+    void (*setView) (LibreOfficeKitDocument* pThis, int nId);
+    /// @see lok::Document::getView().
+    int (*getView) (LibreOfficeKitDocument* pThis);
 #endif // LOK_USE_UNSTABLE_API
 };
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 3e1a0ac..f5821b7 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -269,13 +269,31 @@ public:
     }
 
     /**
-     * Destroy a view of an existring document.
+     * Destroy a view of an existing document.
      * @param nId a view ID, returned by createView().
      */
     void destroyView(int nId)
     {
         mpDoc->pClass->destroyView(mpDoc, nId);
     }
+
+    /**
+     * Set an existing view of an existing document as current.
+     * @param nId a view ID, returned by createView().
+     */
+    void setView(int nId)
+    {
+        mpDoc->pClass->setView(mpDoc, nId);
+    }
+
+    /**
+     * Get the current view.
+     * @return a view ID, previously returned by createView().
+     */
+    int getView()
+    {
+        return mpDoc->pClass->getView(mpDoc);
+    }
 #endif // LOK_USE_UNSTABLE_API
 };
 
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index b57cb7d..a05cd5d 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -21,6 +21,10 @@ public:
     static int createView(SfxViewShell* pViewShell);
     /// Destroy a view shell from the global shell list.
     static void destroyView(size_t nId);
+    /// Set a view shell as current one.
+    static void setView(size_t nId);
+    /// Get the currently active view.
+    static size_t getView();
 
     /// Total number of view shells.
     static int getViews();
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 557478a..0aea6db 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -38,6 +38,30 @@ void SfxLokHelper::destroyView(size_t nId)
     pViewFrame->Exec_Impl(aRequest);
 }
 
+void SfxLokHelper::setView(size_t nId)
+{
+    SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+    if (nId > rViewArr.size() - 1)
+        return;
+
+    SfxViewShell* pViewShell = rViewArr[nId];
+    if (SfxViewFrame* pViewFrame = pViewShell->GetViewFrame())
+        pViewFrame->GetWindow().GrabFocus();
+}
+
+size_t SfxLokHelper::getView()
+{
+    SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
+    SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+    for (size_t i = 0; i < rViewArr.size(); ++i)
+    {
+        if (rViewArr[i]->GetViewFrame() == pViewFrame)
+            return i;
+    }
+    assert(false);
+    return 0;
+}
+
 int SfxLokHelper::getViews()
 {
     SfxViewShellArr_Impl& rViewArr = SfxGetpApp()->GetViewShells_Impl();
commit 855e1bac1d5155352706c7d849942f5dc453c67d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Wed Sep 16 09:22:17 2015 +0200

    gtktiledviewer: add setupWidgetAndCreateWindow() to avoid copy&paste
    
    Change-Id: Ibbbaaa1c148cfd4578ad37e0f99b62ab885a1a83

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 74a4649..b16993b 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -79,6 +79,7 @@ static std::map<GtkWidget*, TiledWindow> g_aWindows;
 
 static void setupDocView(GtkWidget* pDocView);
 static GtkWidget* createWindow(TiledWindow& rWindow);
+static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpointer userdata);
 
 static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget)
 {
@@ -192,17 +193,34 @@ static void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/)
     }
 }
 
-/// Calls lok::Document::createView().
-static void createView(GtkWidget* pButton, gpointer /*pItem*/)
+/// Common initialization, regardless if it's just a new view or a full init.
+static void setupWidgetAndCreateWindow(GtkWidget* pDocView)
 {
-    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
-    GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView));
     setupDocView(pDocView);
     TiledWindow aWindow;
     aWindow.m_pDocView = pDocView;
     createWindow(aWindow);
 }
 
+/// Creates a new view, i.e. no LOK init or document load.
+static void createView(GtkWidget* pButton, gpointer /*pItem*/)
+{
+    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+    GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView));
+
+    setupWidgetAndCreateWindow(pDocView);
+}
+
+/// Creates a new model, i.e. LOK init and document load, one view implicitly.
+static void createModelAndView(const char* pLOPath, const char* pDocPath)
+{
+    GtkWidget* pDocView = lok_doc_view_new(pLOPath, 0, 0);
+
+    setupWidgetAndCreateWindow(pDocView);
+
+    lok_doc_view_open_document(LOK_DOC_VIEW(pDocView), pDocPath, 0, openDocumentCallback, pDocView);
+}
+
 /// Our GtkClipboardGetFunc implementation for HTML.
 static void htmlGetFunc(GtkClipboard* /*pClipboard*/, GtkSelectionData* pSelectionData, guint /*info*/, gpointer pUserData)
 {
@@ -751,12 +769,7 @@ int main( int argc, char* argv[] )
 
     gtk_init( &argc, &argv );
 
-    GtkWidget* pDocView = lok_doc_view_new(argv[1], NULL, NULL);
-    setupDocView(pDocView);
-    TiledWindow aWindow;
-    aWindow.m_pDocView = pDocView;
-    createWindow(aWindow);
-    lok_doc_view_open_document(LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView);
+    createModelAndView(argv[1], argv[2]);
 
     gtk_main();
 
commit b3498e9fcdc895853564d13173075bebc7407ef2
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 15:41:46 2015 +0200

    lokdocview: set up the widget in all windows
    
    With this finally the number of GTK+ windows always match the number
    returned by SfxLokHelper::getViews().
    
    Change-Id: Ia45bef7dea86b80cfac00e2ad7c1a16d7f5b507b

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index ff9b2cd..271625f 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -1850,8 +1850,15 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
 SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pLOKDocView)
 {
     LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
-    return GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
-                                     "lopath", priv->m_aLOPath, "lopointer", priv->m_pOffice, "docpointer", priv->m_pDocument, NULL));
+    GtkWidget* pDocView = GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
+                                                    "lopath", priv->m_aLOPath, "lopointer", priv->m_pOffice, "docpointer", priv->m_pDocument, NULL));
+
+    // No documentLoad(), just a createView().
+    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(LOK_DOC_VIEW(pDocView));
+    pDocument->pClass->createView(pDocument);
+
+    postDocumentLoad(pDocView);
+    return pDocView;
 }
 
 /**
commit e6e5c248e52524ddaddc6d1a2627f10f169d0167
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 15:36:51 2015 +0200

    lokdocview: avoid GTK+ calls in openDocumentInThread()
    
    GTK+ calls should be made from the main thread.
    
    Change-Id: Idcfa46d427d6e35fc544246a691bafc72f75a74c

diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index b185de3..ff9b2cd 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -143,6 +143,7 @@ enum
 static guint doc_view_signals[LAST_SIGNAL] = { 0 };
 
 static void lok_doc_view_initable_iface_init (GInitableIface *iface);
+static void callbackWorker (int nType, const char* pPayload, void* pData);
 
 SAL_DLLPUBLIC_EXPORT GType lok_doc_view_get_type();
 #ifdef __GNUC__
@@ -380,6 +381,37 @@ static gboolean queueDraw(gpointer pData)
     return G_SOURCE_REMOVE;
 }
 
+/// Set up LOKDocView after the document is loaded, invoked on the main thread by openDocumentInThread() running in a thread.
+static gboolean postDocumentLoad(gpointer pData)
+{
+    LOKDocView* pLOKDocView = static_cast<LOKDocView*>(pData);
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
+
+    priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument);
+    priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pLOKDocView);
+    priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
+    g_timeout_add(600, handleTimeout, pLOKDocView);
+
+    float zoom = priv->m_fZoom;
+    long nDocumentWidthTwips = priv->m_nDocumentWidthTwips;
+    long nDocumentHeightTwips = priv->m_nDocumentHeightTwips;
+    long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom);
+    long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom);
+    // Total number of columns in this document.
+    guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
+
+
+    priv->m_aTileBuffer = TileBuffer(priv->m_pDocument,
+                                     nColumns);
+    gtk_widget_set_size_request(GTK_WIDGET(pLOKDocView),
+                                nDocumentWidthPixels,
+                                nDocumentHeightPixels);
+    gtk_widget_set_can_focus(GTK_WIDGET(pLOKDocView), TRUE);
+    gtk_widget_grab_focus(GTK_WIDGET(pLOKDocView));
+
+    return G_SOURCE_REMOVE;
+}
+
 /// Implementation of the global callback handler, invoked by globalCallback();
 static gboolean
 globalCallback (gpointer pData)
@@ -617,8 +649,7 @@ callback (gpointer pData)
     return G_SOURCE_REMOVE;
 }
 
-static void
-callbackWorker (int nType, const char* pPayload, void* pData)
+static void callbackWorker (int nType, const char* pPayload, void* pData)
 {
     LOKDocView* pDocView = LOK_DOC_VIEW (pData);
 
@@ -1193,27 +1224,7 @@ openDocumentInThread (gpointer data)
     }
     else
     {
-        priv->m_pDocument->pClass->initializeForRendering(priv->m_pDocument);
-        priv->m_pDocument->pClass->registerCallback(priv->m_pDocument, callbackWorker, pDocView);
-        priv->m_pDocument->pClass->getDocumentSize(priv->m_pDocument, &priv->m_nDocumentWidthTwips, &priv->m_nDocumentHeightTwips);
-        g_timeout_add(600, handleTimeout, pDocView);
-
-        float zoom = priv->m_fZoom;
-        long nDocumentWidthTwips = priv->m_nDocumentWidthTwips;
-        long nDocumentHeightTwips = priv->m_nDocumentHeightTwips;
-        long nDocumentWidthPixels = twipToPixel(nDocumentWidthTwips, zoom);
-        long nDocumentHeightPixels = twipToPixel(nDocumentHeightTwips, zoom);
-        // Total number of columns in this document.
-        guint nColumns = ceil((double)nDocumentWidthPixels / nTileSizePixels);
-
-
-        priv->m_aTileBuffer = TileBuffer(priv->m_pDocument,
-                                         nColumns);
-        gtk_widget_set_size_request(GTK_WIDGET(pDocView),
-                                    nDocumentWidthPixels,
-                                    nDocumentHeightPixels);
-        gtk_widget_set_can_focus(GTK_WIDGET(pDocView), TRUE);
-        gtk_widget_grab_focus(GTK_WIDGET(pDocView));
+        gdk_threads_add_idle(postDocumentLoad, pDocView);
         g_task_return_boolean (task, true);
     }
 }
commit c1d72145314be0e53d5f93e3b639715c9fbba8b0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 15:22:53 2015 +0200

    gtktiledviewer: set up a new GtkWindow for a new view
    
    Change-Id: I9dcb5871c231a49bcd65a1187df6c3c81f92bd55

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 47d349b..74a4649 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -77,6 +77,9 @@ public:
 
 static std::map<GtkWidget*, TiledWindow> g_aWindows;
 
+static void setupDocView(GtkWidget* pDocView);
+static GtkWidget* createWindow(TiledWindow& rWindow);
+
 static TiledWindow& lcl_getTiledWindow(GtkWidget* pWidget)
 {
     GtkWidget* pToplevel = gtk_widget_get_toplevel(pWidget);
@@ -193,9 +196,11 @@ static void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/)
 static void createView(GtkWidget* pButton, gpointer /*pItem*/)
 {
     TiledWindow& rWindow = lcl_getTiledWindow(pButton);
-    LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
-    LibreOfficeKitDocument* pDocument = lok_doc_view_get_document(pLOKDocView);
-    pDocument->pClass->createView(pDocument);
+    GtkWidget* pDocView = lok_doc_view_new_from_widget(LOK_DOC_VIEW(rWindow.m_pDocView));
+    setupDocView(pDocView);
+    TiledWindow aWindow;
+    aWindow.m_pDocView = pDocView;
+    createWindow(aWindow);
 }
 
 /// Our GtkClipboardGetFunc implementation for HTML.
commit 8d8a8e1a2ea26df6d676495af7f017baa071153d
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 15:05:51 2015 +0200

    gtktiledviewer: factor out setupDocView() from main()
    
    Change-Id: Iac803f03267859c11f0f9090346b09b90c115b76

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index bdba91c..47d349b 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -717,6 +717,21 @@ static GtkWidget* createWindow(TiledWindow& rWindow)
     return pWindow;
 }
 
+/// Common setup for DocView (regardless if it's just a new view or a document to be loaded).
+static void setupDocView(GtkWidget* pDocView)
+{
+#if GLIB_CHECK_VERSION(2,40,0)
+    g_assert_nonnull(pDocView);
+#endif
+    g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
+    g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
+    g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
+    g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
+    g_signal_connect(pDocView, "size-changed", G_CALLBACK(signalSize), NULL);
+    g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
+    g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), NULL);
+}
+
 int main( int argc, char* argv[] )
 {
     if( argc < 3 ||
@@ -731,19 +746,8 @@ int main( int argc, char* argv[] )
 
     gtk_init( &argc, &argv );
 
-    // Docview
-    GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
-#if GLIB_CHECK_VERSION(2,40,0)
-    g_assert_nonnull(pDocView);
-#endif
-    g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
-    g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
-    g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
-    g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
-    g_signal_connect(pDocView, "size-changed", G_CALLBACK(signalSize), NULL);
-    g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
-    g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), NULL);
-
+    GtkWidget* pDocView = lok_doc_view_new(argv[1], NULL, NULL);
+    setupDocView(pDocView);
     TiledWindow aWindow;
     aWindow.m_pDocView = pDocView;
     createWindow(aWindow);
commit 2b69ce33edaed9eaa018821180a00d563ad1ba18
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 14:51:06 2015 +0200

    gtktiledviewer: factor out createWindow() from main()
    
    Change-Id: Ib7ccd2192247805205b65e5e8da67bcc826f4d31

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index fbd2bc3..bdba91c 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -547,70 +547,58 @@ static void openDocumentCallback (GObject* source_object, GAsyncResult* res, gpo
     gtk_widget_hide(rWindow.m_pStatusBar);
 }
 
-int main( int argc, char* argv[] )
+/// Creates the GtkWindow that has main widget as children and registers it in the window map.
+static GtkWidget* createWindow(TiledWindow& rWindow)
 {
-    if( argc < 3 ||
-        ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
-        return help();
-
-    if ( argv[1][0] != '/' )
-    {
-        fprintf(stderr, "Absolute path required to libreoffice install\n");
-        return 1;
-    }
-
-    gtk_init( &argc, &argv );
-
-    GtkWidget *pWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
-    TiledWindow aWindow;
-    gtk_window_set_title( GTK_WINDOW(pWindow), "LibreOfficeKit GTK Tiled Viewer" );
+    GtkWidget *pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+    gtk_window_set_title(GTK_WINDOW(pWindow), "LibreOfficeKit GTK Tiled Viewer");
     gtk_window_set_default_size(GTK_WINDOW(pWindow), 1024, 768);
-    g_signal_connect( pWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL );
+    g_signal_connect(pWindow, "destroy", G_CALLBACK(gtk_main_quit), 0);
 
-    aWindow.m_pVBox = gtk_box_new( GTK_ORIENTATION_VERTICAL, 0 );
-    gtk_container_add( GTK_CONTAINER(pWindow), aWindow.m_pVBox );
+    rWindow.m_pVBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
+    gtk_container_add(GTK_CONTAINER(pWindow), rWindow.m_pVBox);
 
     // Toolbar
     GtkWidget* pToolbar = gtk_toolbar_new();
-    gtk_toolbar_set_style( GTK_TOOLBAR(pToolbar), GTK_TOOLBAR_ICONS );
+    gtk_toolbar_set_style(GTK_TOOLBAR(pToolbar), GTK_TOOLBAR_ICONS);
 
-    GtkToolItem* pZoomIn = gtk_tool_button_new( NULL, NULL );
+    GtkToolItem* pZoomIn = gtk_tool_button_new(NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pZoomIn), "zoom-in-symbolic");
     gtk_tool_item_set_tooltip_text(pZoomIn, "Zoom In");
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pZoomIn, 0);
-    g_signal_connect( G_OBJECT(pZoomIn), "clicked", G_CALLBACK(changeZoom), NULL );
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pZoomIn, 0);
+    g_signal_connect(G_OBJECT(pZoomIn), "clicked", G_CALLBACK(changeZoom), NULL);
 
-    GtkToolItem* pZoom1 = gtk_tool_button_new( NULL, NULL );
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pZoom1), "zoom-original-symbolic");
+    GtkToolItem* pZoom1 = gtk_tool_button_new(NULL, NULL);
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(pZoom1), "zoom-original-symbolic");
     gtk_tool_item_set_tooltip_text(pZoom1, "Normal Size");
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pZoom1, -1);
-    g_signal_connect( G_OBJECT(pZoom1), "clicked", G_CALLBACK(changeZoom), NULL );
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pZoom1, -1);
+    g_signal_connect(G_OBJECT(pZoom1), "clicked", G_CALLBACK(changeZoom), NULL);
 
-    GtkToolItem* pZoomOut = gtk_tool_button_new( NULL, NULL );
+    GtkToolItem* pZoomOut = gtk_tool_button_new(NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pZoomOut), "zoom-out-symbolic");
     gtk_tool_item_set_tooltip_text(pZoomOut, "Zoom Out");
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pZoomOut, -1);
-    g_signal_connect( G_OBJECT(pZoomOut), "clicked", G_CALLBACK(changeZoom), NULL );
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pZoomOut, -1);
+    g_signal_connect(G_OBJECT(pZoomOut), "clicked", G_CALLBACK(changeZoom), NULL);
 
     GtkToolItem* pSeparator1 = gtk_separator_tool_item_new();
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator1, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pSeparator1, -1);
 
     GtkToolItem* pPartSelectorToolItem = gtk_tool_item_new();
     GtkWidget* pComboBox = gtk_combo_box_text_new();
-    gtk_container_add( GTK_CONTAINER(pPartSelectorToolItem), pComboBox );
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartSelectorToolItem, -1 );
+    gtk_container_add(GTK_CONTAINER(pPartSelectorToolItem), pComboBox);
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pPartSelectorToolItem, -1);
 
-    aWindow.m_pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox);
+    rWindow.m_pPartSelector = GTK_COMBO_BOX_TEXT(pComboBox);
 
     GtkToolItem* pSeparator2 = gtk_separator_tool_item_new();
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pSeparator2, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pSeparator2, -1);
 
     GtkToolItem* pPartModeSelectorToolItem = gtk_tool_item_new();
-    aWindow.m_pPartModeComboBox = gtk_combo_box_text_new();
-    gtk_container_add(GTK_CONTAINER(pPartModeSelectorToolItem), aWindow.m_pPartModeComboBox);
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), pPartModeSelectorToolItem, -1 );
+    rWindow.m_pPartModeComboBox = gtk_combo_box_text_new();
+    gtk_container_add(GTK_CONTAINER(pPartModeSelectorToolItem), rWindow.m_pPartModeComboBox);
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pPartModeSelectorToolItem, -1);
 
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
 
     // Cut, copy & paste.
     GtkToolItem* pCopyButton = gtk_tool_button_new( NULL, NULL);
@@ -621,7 +609,7 @@ int main( int argc, char* argv[] )
     gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
 
     GtkToolItem* pEnableEditing = gtk_toggle_tool_button_new();
-    aWindow.m_pEnableEditing = pEnableEditing;
+    rWindow.m_pEnableEditing = pEnableEditing;
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pEnableEditing), "insert-text-symbolic");
     gtk_tool_item_set_tooltip_text(pEnableEditing, "Edit");
     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pEnableEditing, -1);
@@ -639,77 +627,115 @@ int main( int argc, char* argv[] )
     gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), pNewViewButton, -1);
     g_signal_connect(G_OBJECT(pNewViewButton), "clicked", G_CALLBACK(createView), NULL);
 
-    gtk_toolbar_insert( GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
-
-    aWindow.m_pBold = gtk_toggle_tool_button_new();
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pBold), "format-text-bold-symbolic");
-    gtk_tool_item_set_tooltip_text(aWindow.m_pBold, "Bold");
-    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pBold, -1);
-    g_signal_connect(G_OBJECT(aWindow.m_pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
-    lcl_registerToolItem(aWindow, aWindow.m_pBold, ".uno:Bold");
-
-    aWindow.m_pItalic = gtk_toggle_tool_button_new();
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pItalic), "format-text-italic-symbolic");
-    gtk_tool_item_set_tooltip_text(aWindow.m_pItalic, "Italic");
-    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pItalic, -1);
-    g_signal_connect(G_OBJECT(aWindow.m_pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
-    lcl_registerToolItem(aWindow, aWindow.m_pItalic, ".uno:Italic");
-
-    aWindow.m_pUnderline = gtk_toggle_tool_button_new();
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (aWindow.m_pUnderline), "format-text-underline-symbolic");
-    gtk_tool_item_set_tooltip_text(aWindow.m_pUnderline, "Underline");
-    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pUnderline, -1);
-    g_signal_connect(G_OBJECT(aWindow.m_pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
-    lcl_registerToolItem(aWindow, aWindow.m_pUnderline, ".uno:Underline");
-
-    aWindow.m_pStrikethrough = gtk_toggle_tool_button_new ();
-    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(aWindow.m_pStrikethrough), "format-text-strikethrough-symbolic");
-    gtk_tool_item_set_tooltip_text(aWindow.m_pStrikethrough, "Strikethrough");
-    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), aWindow.m_pStrikethrough, -1);
-    g_signal_connect(G_OBJECT(aWindow.m_pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
-    lcl_registerToolItem(aWindow, aWindow.m_pStrikethrough, ".uno:Strikeout");
-
-    gtk_box_pack_start( GTK_BOX(aWindow.m_pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), gtk_separator_tool_item_new(), -1);
+
+    rWindow.m_pBold = gtk_toggle_tool_button_new();
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pBold), "format-text-bold-symbolic");
+    gtk_tool_item_set_tooltip_text(rWindow.m_pBold, "Bold");
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), rWindow.m_pBold, -1);
+    g_signal_connect(G_OBJECT(rWindow.m_pBold), "toggled", G_CALLBACK(toggleToolItem), NULL);
+    lcl_registerToolItem(rWindow, rWindow.m_pBold, ".uno:Bold");
+
+    rWindow.m_pItalic = gtk_toggle_tool_button_new();
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (rWindow.m_pItalic), "format-text-italic-symbolic");
+    gtk_tool_item_set_tooltip_text(rWindow.m_pItalic, "Italic");
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), rWindow.m_pItalic, -1);
+    g_signal_connect(G_OBJECT(rWindow.m_pItalic), "toggled", G_CALLBACK(toggleToolItem), NULL);
+    lcl_registerToolItem(rWindow, rWindow.m_pItalic, ".uno:Italic");
+
+    rWindow.m_pUnderline = gtk_toggle_tool_button_new();
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (rWindow.m_pUnderline), "format-text-underline-symbolic");
+    gtk_tool_item_set_tooltip_text(rWindow.m_pUnderline, "Underline");
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), rWindow.m_pUnderline, -1);
+    g_signal_connect(G_OBJECT(rWindow.m_pUnderline), "toggled", G_CALLBACK(toggleToolItem), NULL);
+    lcl_registerToolItem(rWindow, rWindow.m_pUnderline, ".uno:Underline");
+
+    rWindow.m_pStrikethrough = gtk_toggle_tool_button_new ();
+    gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON(rWindow.m_pStrikethrough), "format-text-strikethrough-symbolic");
+    gtk_tool_item_set_tooltip_text(rWindow.m_pStrikethrough, "Strikethrough");
+    gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), rWindow.m_pStrikethrough, -1);
+    g_signal_connect(G_OBJECT(rWindow.m_pStrikethrough), "toggled", G_CALLBACK(toggleToolItem), NULL);
+    lcl_registerToolItem(rWindow, rWindow.m_pStrikethrough, ".uno:Strikeout");
+
+    gtk_box_pack_start(GTK_BOX(rWindow.m_pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
 
     // Findbar
-    aWindow.m_pFindbar = gtk_toolbar_new();
-    gtk_toolbar_set_style(GTK_TOOLBAR(aWindow.m_pFindbar), GTK_TOOLBAR_ICONS);
+    rWindow.m_pFindbar = gtk_toolbar_new();
+    gtk_toolbar_set_style(GTK_TOOLBAR(rWindow.m_pFindbar), GTK_TOOLBAR_ICONS);
 
     GtkToolItem* pFindbarClose = gtk_tool_button_new( NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarClose), "window-close-symbolic");
-    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarClose, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarClose, -1);
     g_signal_connect(G_OBJECT(pFindbarClose), "clicked", G_CALLBACK(toggleFindbar), NULL);
 
     GtkToolItem* pEntryContainer = gtk_tool_item_new();
-    aWindow.m_pFindbarEntry = gtk_entry_new();
-    gtk_container_add(GTK_CONTAINER(pEntryContainer), aWindow.m_pFindbarEntry);
-    g_signal_connect(aWindow.m_pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
-    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pEntryContainer, -1);
+    rWindow.m_pFindbarEntry = gtk_entry_new();
+    gtk_container_add(GTK_CONTAINER(pEntryContainer), rWindow.m_pFindbarEntry);
+    g_signal_connect(rWindow.m_pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
+    gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pEntryContainer, -1);
 
     GtkToolItem* pFindbarNext = gtk_tool_button_new( NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarNext), "go-down-symbolic");
-    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarNext, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarNext, -1);
     g_signal_connect(G_OBJECT(pFindbarNext), "clicked", G_CALLBACK(signalSearchNext), NULL);
 
     GtkToolItem* pFindbarPrev = gtk_tool_button_new( NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarPrev), "go-up-symbolic");
-    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarPrev, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarPrev, -1);
     g_signal_connect(G_OBJECT(pFindbarPrev), "clicked", G_CALLBACK(signalSearchPrev), NULL);
 
     GtkToolItem* pFindbarLabelContainer = gtk_tool_item_new();
-    aWindow.m_pFindbarLabel = gtk_label_new("");
-    gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), aWindow.m_pFindbarLabel);
-    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarLabelContainer, -1);
+    rWindow.m_pFindbarLabel = gtk_label_new("");
+    gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), rWindow.m_pFindbarLabel);
+    gtk_toolbar_insert(GTK_TOOLBAR(rWindow.m_pFindbar), pFindbarLabelContainer, -1);
+
+    gtk_box_pack_end(GTK_BOX(rWindow.m_pVBox), rWindow.m_pFindbar, FALSE, FALSE, 0);
+
+    // Scrolled window for DocView
+    rWindow.m_pScrolledWindow = gtk_scrolled_window_new(0, 0);
+    gtk_widget_set_hexpand(rWindow.m_pScrolledWindow, TRUE);
+    gtk_widget_set_vexpand(rWindow.m_pScrolledWindow, TRUE);
+    gtk_container_add(GTK_CONTAINER(rWindow.m_pVBox), rWindow.m_pScrolledWindow);
 
-    gtk_box_pack_end(GTK_BOX(aWindow.m_pVBox), aWindow.m_pFindbar, FALSE, FALSE, 0);
+    gtk_container_add(GTK_CONTAINER(rWindow.m_pScrolledWindow), rWindow.m_pDocView);
+
+    GtkWidget* pProgressBar = gtk_progress_bar_new ();
+    g_signal_connect(rWindow.m_pDocView, "load-changed", G_CALLBACK(loadChanged), pProgressBar);
+
+    GtkWidget* pStatusBar = gtk_statusbar_new();
+    rWindow.m_pStatusBar = pStatusBar;
+    gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, pStatusBar);
+    gtk_container_add (GTK_CONTAINER(rWindow.m_pVBox), pStatusBar);
+    gtk_container_add (GTK_CONTAINER(pStatusBar), pProgressBar);
+    gtk_widget_set_hexpand(pProgressBar, true);
+
+    gtk_widget_show_all(pWindow);
+    // Hide the findbar by default.
+    gtk_widget_hide(rWindow.m_pFindbar);
+
+    g_aWindows[pWindow] = rWindow;
+    return pWindow;
+}
+
+int main( int argc, char* argv[] )
+{
+    if( argc < 3 ||
+        ( argc > 1 && ( !strcmp( argv[1], "--help" ) || !strcmp( argv[1], "-h" ) ) ) )
+        return help();
+
+    if ( argv[1][0] != '/' )
+    {
+        fprintf(stderr, "Absolute path required to libreoffice install\n");
+        return 1;
+    }
+
+    gtk_init( &argc, &argv );
 
     // Docview
     GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
-    aWindow.m_pDocView = pDocView;
 #if GLIB_CHECK_VERSION(2,40,0)
     g_assert_nonnull(pDocView);
 #endif
-
     g_signal_connect(pDocView, "edit-changed", G_CALLBACK(signalEdit), NULL);
     g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
     g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
@@ -718,32 +744,10 @@ int main( int argc, char* argv[] )
     g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
     g_signal_connect(pDocView, "cursor-changed", G_CALLBACK(cursorChanged), NULL);
 
-
-    // Scrolled window for DocView
-    aWindow.m_pScrolledWindow = gtk_scrolled_window_new(0, 0);
-    gtk_widget_set_hexpand (aWindow.m_pScrolledWindow, TRUE);
-    gtk_widget_set_vexpand (aWindow.m_pScrolledWindow, TRUE);
-    gtk_container_add(GTK_CONTAINER(aWindow.m_pVBox), aWindow.m_pScrolledWindow);
-
-    gtk_container_add(GTK_CONTAINER(aWindow.m_pScrolledWindow), pDocView);
-
-    GtkWidget* pProgressBar = gtk_progress_bar_new ();
-    g_signal_connect(pDocView, "load-changed", G_CALLBACK(loadChanged), pProgressBar);
-
-    GtkWidget* pStatusBar = gtk_statusbar_new ();
-    aWindow.m_pStatusBar = pStatusBar;
-    gtk_container_forall(GTK_CONTAINER(pStatusBar), removeChildrenFromStatusbar, pStatusBar);
-    gtk_container_add (GTK_CONTAINER(aWindow.m_pVBox), pStatusBar);
-    gtk_container_add (GTK_CONTAINER(pStatusBar), pProgressBar);
-    gtk_widget_set_hexpand(pProgressBar, true);
-
-    gtk_widget_show_all( pWindow );
-    // Hide the findbar by default.
-    gtk_widget_hide(aWindow.m_pFindbar);
-
-    g_aWindows[pWindow] = aWindow;
-
-    lok_doc_view_open_document( LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView );
+    TiledWindow aWindow;
+    aWindow.m_pDocView = pDocView;
+    createWindow(aWindow);
+    lok_doc_view_open_document(LOK_DOC_VIEW(pDocView), argv[2], NULL, openDocumentCallback, pDocView);
 
     gtk_main();
 
commit 4fd59356cb09e89324e8cd8ec84eef22a4c2031b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 14:23:53 2015 +0200

    lokdocview: allow not calling documentLoad()
    
    Change-Id: I2ff57c4be11cd3908bc951ebf572a2c02e2c4585

diff --git a/include/LibreOfficeKit/LibreOfficeKitGtk.h b/include/LibreOfficeKit/LibreOfficeKitGtk.h
index 01009fb..f17925b 100644
--- a/include/LibreOfficeKit/LibreOfficeKitGtk.h
+++ b/include/LibreOfficeKit/LibreOfficeKitGtk.h
@@ -44,6 +44,8 @@ GtkWidget*                     lok_doc_view_new                    (const gchar*
                                                                     GCancellable *cancellable,
                                                                     GError **error);
 
+GtkWidget*                     lok_doc_view_new_from_widget        (LOKDocView* pDocView);
+
 void                           lok_doc_view_open_document          (LOKDocView* pDocView,
                                                                     const gchar* pPath,
                                                                     GCancellable* cancellable,
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 4448026..b185de3 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -127,7 +127,9 @@ enum
     PROP_0,
 
     PROP_LO_PATH,
+    PROP_LO_POINTER,
     PROP_DOC_PATH,
+    PROP_DOC_POINTER,
     PROP_EDITABLE,
     PROP_LOAD_PROGRESS,
     PROP_ZOOM,
@@ -1388,9 +1390,15 @@ static void lok_doc_view_set_property (GObject* object, guint propId, const GVal
     case PROP_LO_PATH:
         priv->m_aLOPath = g_value_dup_string (value);
         break;
+    case PROP_LO_POINTER:
+        priv->m_pOffice = static_cast<LibreOfficeKit*>(g_value_get_pointer(value));
+        break;
     case PROP_DOC_PATH:
         priv->m_aDocPath = g_value_dup_string (value);
         break;
+    case PROP_DOC_POINTER:
+        priv->m_pDocument = static_cast<LibreOfficeKitDocument*>(g_value_get_pointer(value));
+        break;
     case PROP_EDITABLE:
         lok_doc_view_set_edit (pDocView, g_value_get_boolean (value));
         break;
@@ -1418,9 +1426,15 @@ static void lok_doc_view_get_property (GObject* object, guint propId, GValue *va
     case PROP_LO_PATH:
         g_value_set_string (value, priv->m_aLOPath);
         break;
+    case PROP_LO_POINTER:
+        g_value_set_pointer(value, priv->m_pOffice);
+        break;
     case PROP_DOC_PATH:
         g_value_set_string (value, priv->m_aDocPath);
         break;
+    case PROP_DOC_POINTER:
+        g_value_set_pointer(value, priv->m_pDocument);
+        break;
     case PROP_EDITABLE:
         g_value_set_boolean (value, priv->m_bEdit);
         break;
@@ -1531,6 +1545,20 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
                                                        | G_PARAM_CONSTRUCT_ONLY)));
 
     /**
+     * LOKDocView:lopointer:
+     *
+     * A LibreOfficeKit* in case lok_init() is already called
+     * previously.
+     */
+    g_object_class_install_property (pGObjectClass,
+          PROP_LO_POINTER,
+          g_param_spec_pointer("lopointer",
+                              "LO Pointer",
+                              "A LibreOfficeKit* from lok_init()",
+                              static_cast<GParamFlags>(G_PARAM_READWRITE
+                                                       | G_PARAM_CONSTRUCT_ONLY)));
+
+    /**
      * LOKDocView:docpath:
      *
      * The path of the document that is currently being viewed.
@@ -1544,6 +1572,19 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
                               static_cast<GParamFlags>(G_PARAM_READWRITE)));
 
     /**
+     * LOKDocView:docpointer:
+     *
+     * A LibreOfficeKitDocument* in case documentLoad() is already called
+     * previously.
+     */
+    g_object_class_install_property (pGObjectClass,
+          PROP_DOC_POINTER,
+          g_param_spec_pointer("docpointer",
+                              "Document Pointer",
+                              "A LibreOfficeKitDocument* from documentLoad()",
+                              static_cast<GParamFlags>(G_PARAM_READWRITE)));
+
+    /**
      * LOKDocView:editable:
      *
      * Whether the document loaded inside of #LOKDocView is editable or not.
@@ -1795,6 +1836,13 @@ lok_doc_view_new (const gchar* pPath, GCancellable *cancellable, GError **error)
     return GTK_WIDGET (g_initable_new (LOK_TYPE_DOC_VIEW, cancellable, error, "lopath", pPath, NULL));
 }
 
+SAL_DLLPUBLIC_EXPORT GtkWidget* lok_doc_view_new_from_widget(LOKDocView* pLOKDocView)
+{
+    LOKDocViewPrivate* priv = static_cast<LOKDocViewPrivate*>(lok_doc_view_get_instance_private(pLOKDocView));
+    return GTK_WIDGET(g_initable_new(LOK_TYPE_DOC_VIEW, /*cancellable=*/0, /*error=*/0,
+                                     "lopath", priv->m_aLOPath, "lopointer", priv->m_pOffice, "docpointer", priv->m_pDocument, NULL));
+}
+
 /**
  * lok_doc_view_open_document_finish:
  * @pDocView: The #LOKDocView instance
commit d51e3f7877afe62b68071a694438d2d6722bb406
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 12:53:24 2015 +0200

    gtktiledviewer: allow findbar in multiple windows
    
    With this, all previously global data is now stored per-window in the
    g_aWindows map.
    
    Change-Id: I45b4449ee7d516106ea0b039d1af97db49edf759

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index d09bb69..fbd2bc3 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,10 +30,6 @@ static int help()
     return 1;
 }
 
-static GtkWidget* pFindbar;
-static GtkWidget* pFindbarEntry;
-static GtkWidget* pFindbarLabel;
-
 /// Represents all the state that is specific to one GtkWindow of this app.
 class TiledWindow
 {
@@ -54,6 +50,9 @@ public:
     GtkWidget* m_pPartModeComboBox;
     /// Should the part selector avoid calling lok::Document::setPart()?
     bool m_bPartSelectorBroadcast;
+    GtkWidget* m_pFindbar;
+    GtkWidget* m_pFindbarEntry;
+    GtkWidget* m_pFindbarLabel;
 
     TiledWindow()
         : m_pDocView(0),
@@ -68,7 +67,10 @@ public:
         m_pVBox(0),
         m_pPartSelector(0),
         m_pPartModeComboBox(0),
-        m_bPartSelectorBroadcast(true)
+        m_bPartSelectorBroadcast(true),
+        m_pFindbar(0),
+        m_pFindbarEntry(0),
+        m_pFindbarLabel(0)
     {
     }
 };
@@ -173,16 +175,17 @@ static void toggleEditing(GtkWidget* pButton, gpointer /*pItem*/)
 }
 
 /// Toggle the visibility of the findbar.
-static void toggleFindbar(GtkWidget* /*pButton*/, gpointer /*pItem*/)
+static void toggleFindbar(GtkWidget* pButton, gpointer /*pItem*/)
 {
-    if (gtk_widget_get_visible(pFindbar))
+    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+    if (gtk_widget_get_visible(rWindow.m_pFindbar))
     {
-        gtk_widget_hide(pFindbar);
+        gtk_widget_hide(rWindow.m_pFindbar);
     }
     else
     {
-        gtk_widget_show_all(pFindbar);
-        gtk_widget_grab_focus(pFindbarEntry);
+        gtk_widget_show_all(rWindow.m_pFindbar);
+        gtk_widget_grab_focus(rWindow.m_pFindbarEntry);
     }
 }
 
@@ -245,10 +248,11 @@ static void doCopy(GtkWidget* pButton, gpointer /*pItem*/)
 }
 
 
-/// Searches for the next or previous text of pFindbarEntry.
+/// Searches for the next or previous text of TiledWindow::m_pFindbarEntry.
 static void doSearch(GtkWidget* pButton, bool bBackwards)
 {
-    GtkEntry* pEntry = GTK_ENTRY(pFindbarEntry);
+    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
+    GtkEntry* pEntry = GTK_ENTRY(rWindow.m_pFindbarEntry);
     const char* pText = gtk_entry_get_text(pEntry);
     boost::property_tree::ptree aTree;
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.SearchString/type", '/'), "string");
@@ -256,7 +260,6 @@ static void doSearch(GtkWidget* pButton, bool bBackwards)
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/type", '/'), "boolean");
     aTree.put(boost::property_tree::ptree::path_type("SearchItem.Backward/value", '/'), bBackwards);
 
-    TiledWindow& rWindow = lcl_getTiledWindow(pButton);
     LOKDocView* pLOKDocView = LOK_DOC_VIEW(rWindow.m_pDocView);
     GdkRectangle aArea;
     getVisibleAreaTwips(rWindow.m_pDocView, &aArea);
@@ -286,7 +289,8 @@ static void signalSearchPrev(GtkWidget* pButton, gpointer /*pItem*/)
 /// Handles the key-press-event of the search entry widget.
 static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer /*pData*/)
 {
-    gtk_label_set_text(GTK_LABEL(pFindbarLabel), "");
+    TiledWindow& rWindow = lcl_getTiledWindow(pWidget);
+    gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), "");
     switch(pEvent->keyval)
     {
         case GDK_KEY_Return:
@@ -298,7 +302,7 @@ static gboolean signalFindbar(GtkWidget* pWidget, GdkEventKey* pEvent, gpointer
         case GDK_KEY_Escape:
         {
             // Hide the findbar.
-            gtk_widget_hide(pFindbar);
+            gtk_widget_hide(rWindow.m_pFindbar);
             return TRUE;
         }
     }
@@ -351,9 +355,10 @@ static void loadChanged(LOKDocView* /*pLOKDocView*/, gdouble fValue, gpointer pD
 }
 
 /// LOKDocView found no search matches -> set the search label accordingly.
-static void signalSearch(LOKDocView* /*pLOKDocView*/, char* /*pPayload*/, gpointer /*pData*/)
+static void signalSearch(LOKDocView* pLOKDocView, char* /*pPayload*/, gpointer /*pData*/)
 {
-    gtk_label_set_text(GTK_LABEL(pFindbarLabel), "Search key not found");
+    TiledWindow& rWindow = lcl_getTiledWindow(GTK_WIDGET(pLOKDocView));
+    gtk_label_set_text(GTK_LABEL(rWindow.m_pFindbarLabel), "Search key not found");
 }
 
 
@@ -667,36 +672,36 @@ int main( int argc, char* argv[] )
     gtk_box_pack_start( GTK_BOX(aWindow.m_pVBox), pToolbar, FALSE, FALSE, 0 ); // Adds to top.
 
     // Findbar
-    pFindbar = gtk_toolbar_new();
-    gtk_toolbar_set_style(GTK_TOOLBAR(pFindbar), GTK_TOOLBAR_ICONS);
+    aWindow.m_pFindbar = gtk_toolbar_new();
+    gtk_toolbar_set_style(GTK_TOOLBAR(aWindow.m_pFindbar), GTK_TOOLBAR_ICONS);
 
     GtkToolItem* pFindbarClose = gtk_tool_button_new( NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarClose), "window-close-symbolic");
-    gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarClose, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarClose, -1);
     g_signal_connect(G_OBJECT(pFindbarClose), "clicked", G_CALLBACK(toggleFindbar), NULL);
 
     GtkToolItem* pEntryContainer = gtk_tool_item_new();
-    pFindbarEntry = gtk_entry_new();
-    gtk_container_add(GTK_CONTAINER(pEntryContainer), pFindbarEntry);
-    g_signal_connect(pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
-    gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pEntryContainer, -1);
+    aWindow.m_pFindbarEntry = gtk_entry_new();
+    gtk_container_add(GTK_CONTAINER(pEntryContainer), aWindow.m_pFindbarEntry);
+    g_signal_connect(aWindow.m_pFindbarEntry, "key-press-event", G_CALLBACK(signalFindbar), 0);
+    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pEntryContainer, -1);
 
     GtkToolItem* pFindbarNext = gtk_tool_button_new( NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarNext), "go-down-symbolic");
-    gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarNext, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarNext, -1);
     g_signal_connect(G_OBJECT(pFindbarNext), "clicked", G_CALLBACK(signalSearchNext), NULL);
 
     GtkToolItem* pFindbarPrev = gtk_tool_button_new( NULL, NULL);
     gtk_tool_button_set_icon_name(GTK_TOOL_BUTTON (pFindbarPrev), "go-up-symbolic");
-    gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarPrev, -1);
+    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarPrev, -1);
     g_signal_connect(G_OBJECT(pFindbarPrev), "clicked", G_CALLBACK(signalSearchPrev), NULL);
 
     GtkToolItem* pFindbarLabelContainer = gtk_tool_item_new();
-    pFindbarLabel = gtk_label_new("");
-    gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), pFindbarLabel);
-    gtk_toolbar_insert(GTK_TOOLBAR(pFindbar), pFindbarLabelContainer, -1);
+    aWindow.m_pFindbarLabel = gtk_label_new("");
+    gtk_container_add(GTK_CONTAINER(pFindbarLabelContainer), aWindow.m_pFindbarLabel);
+    gtk_toolbar_insert(GTK_TOOLBAR(aWindow.m_pFindbar), pFindbarLabelContainer, -1);
 
-    gtk_box_pack_end(GTK_BOX(aWindow.m_pVBox), pFindbar, FALSE, FALSE, 0);
+    gtk_box_pack_end(GTK_BOX(aWindow.m_pVBox), aWindow.m_pFindbar, FALSE, FALSE, 0);
 
     // Docview
     GtkWidget* pDocView = lok_doc_view_new (argv[1], NULL, NULL);
@@ -734,7 +739,7 @@ int main( int argc, char* argv[] )
 
     gtk_widget_show_all( pWindow );
     // Hide the findbar by default.
-    gtk_widget_hide(pFindbar);
+    gtk_widget_hide(aWindow.m_pFindbar);
 
     g_aWindows[pWindow] = aWindow;
 
commit d8bf31e129c4e791bfb02c8d0ccbaedb53d9b300
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Sep 15 12:45:58 2015 +0200

    gtktiledviewer: allow part selector in multiple windows
    
    Change-Id: Ib31fca3d8b4119704fb1a5c3cee885e7c239c247

diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
index 58001ad..d09bb69 100644
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
@@ -30,11 +30,6 @@ static int help()
     return 1;
 }
 
-static GtkWidget* pVBox;
-static GtkComboBoxText* pPartSelector;
-static GtkWidget* pPartModeComboBox;
-/// Should the part selector avoid calling lok::Document::setPart()?
-static bool g_bPartSelectorBroadcast = true;

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list