135360
From fd9d67a7ad8b68399b5866406bd934829297a8d3 Mon Sep 17 00:00:00 2001
135360
From: Jan Holesovsky <kendy@collabora.com>
135360
Date: Sat, 1 Aug 2015 02:13:47 +0200
135360
Subject: [PATCH 086/398] LOK: Implement parts for Writer too.
135360
135360
In Writer, the meaning of 'parts' is a bit different than in Calc or Impress.
135360
In Writer, the parts mean pages, and the document does not give a completely
135360
different view, the cursor just jumps to the given page.
135360
135360
It is up to the client to follow the cursor appropriately to have the desired
135360
effect.
135360
135360
Change-Id: I56b3264e0340cd639bdabfa92b74b52bd1f391a5
135360
(cherry picked from commit 512b782cf466a19ed77d818fa660e1a0dc74fc35)
135360
---
135360
 .../qa/gtktiledviewer/gtktiledviewer.cxx           |  8 ++++
135360
 libreofficekit/source/gtk/lokdocview.cxx           | 18 +++++++++
135360
 sw/inc/unotxdoc.hxx                                |  8 ++++
135360
 sw/inc/viscrs.hxx                                  |  3 ++
135360
 sw/source/core/crsr/viscrs.cxx                     | 12 ++++++
135360
 sw/source/uibase/uno/unotxdoc.cxx                  | 44 ++++++++++++++++++++++
135360
 6 files changed, 93 insertions(+)
135360
135360
diff --git a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
index a3999c09b29a..3399087cb6db 100644
135360
--- a/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
+++ b/libreofficekit/qa/gtktiledviewer/gtktiledviewer.cxx
135360
@@ -358,6 +358,13 @@ static void populatePartSelector()
135360
                               lok_doc_view_get_part( LOK_DOC_VIEW(pDocView) ) );
135360
 }
135360
 
135360
+static void signalSize(LOKDocView* /*pLOKDocView*/, gpointer /*pData*/)
135360
+{
135360
+    g_bPartSelectorBroadcast = false;
135360
+    populatePartSelector();
135360
+    g_bPartSelectorBroadcast = true;
135360
+}
135360
+
135360
 static void changePart( GtkWidget* pSelector, gpointer /* pItem */ )
135360
 {
135360
     int nPart = gtk_combo_box_get_active( GTK_COMBO_BOX(pSelector) );
135360
@@ -566,6 +573,7 @@ int main( int argc, char* argv[] )
135360
     g_signal_connect(pDocView, "command-changed", G_CALLBACK(signalCommand), NULL);
135360
     g_signal_connect(pDocView, "search-not-found", G_CALLBACK(signalSearch), NULL);
135360
     g_signal_connect(pDocView, "part-changed", G_CALLBACK(signalPart), NULL);
135360
+    g_signal_connect(pDocView, "size-changed", G_CALLBACK(signalSize), NULL);
135360
     g_signal_connect(pDocView, "hyperlink-clicked", G_CALLBACK(signalHyperlink), NULL);
135360
 
135360
 
135360
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
135360
index cb77aa4097d0..bdae55fc54e0 100644
135360
--- a/libreofficekit/source/gtk/lokdocview.cxx
135360
+++ b/libreofficekit/source/gtk/lokdocview.cxx
135360
@@ -114,6 +114,7 @@ enum
135360
     COMMAND_CHANGED,
135360
     SEARCH_NOT_FOUND,
135360
     PART_CHANGED,
135360
+    SIZE_CHANGED,
135360
     HYPERLINK_CLICKED,
135360
 
135360
     LAST_SIGNAL
135360
@@ -581,6 +582,8 @@ callback (gpointer pData)
135360
         gtk_widget_set_size_request(GTK_WIDGET(pDocView),
135360
                                     twipToPixel(priv->m_nDocumentWidthTwips, priv->m_fZoom),
135360
                                     twipToPixel(priv->m_nDocumentHeightTwips, priv->m_fZoom));
135360
+
135360
+        g_signal_emit(pDocView, doc_view_signals[SIZE_CHANGED], 0, NULL);
135360
     }
135360
     break;
135360
     case LOK_CALLBACK_SET_PART:
135360
@@ -1707,6 +1710,21 @@ static void lok_doc_view_class_init (LOKDocViewClass* pClass)
135360
                      G_TYPE_INT);
135360
 
135360
     /**
135360
+     * LOKDocView::size-changed:
135360
+     * @pDocView: the #LOKDocView on which the signal is emitted
135360
+     * @aCommand: NULL, we just notify that want to notify the UI elements that are interested.
135360
+     */
135360
+    doc_view_signals[SIZE_CHANGED] =
135360
+        g_signal_new("size-changed",
135360
+                     G_TYPE_FROM_CLASS(pGObjectClass),
135360
+                     G_SIGNAL_RUN_FIRST,
135360
+                     0,
135360
+                     NULL, NULL,
135360
+                     g_cclosure_marshal_VOID__VOID,
135360
+                     G_TYPE_NONE, 1,
135360
+                     G_TYPE_INT);
135360
+
135360
+    /**
135360
      * LOKDocView::hyperlinked-clicked:
135360
      * @pDocView: the #LOKDocView on which the signal is emitted
135360
      * @aHyperlink: the URI which the application should handle
135360
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
135360
index c90a852ac8ee..9f0b03b3af38 100644
135360
--- a/sw/inc/unotxdoc.hxx
135360
+++ b/sw/inc/unotxdoc.hxx
135360
@@ -407,6 +407,14 @@ public:
135360
                             long nTileHeight ) SAL_OVERRIDE;
135360
     /// @see vcl::ITiledRenderable::getDocumentSize().
135360
     virtual Size getDocumentSize() SAL_OVERRIDE;
135360
+    /// @see vcl::ITiledRenderable::setPart().
135360
+    virtual void setPart(int nPart) SAL_OVERRIDE;
135360
+    /// @see vcl::ITiledRenderable::getParts().
135360
+    virtual int getParts() SAL_OVERRIDE;
135360
+    /// @see vcl::ITiledRenderable::getPart().
135360
+    virtual int getPart() SAL_OVERRIDE;
135360
+    /// @see vcl::ITiledRenderable::getPartName().
135360
+    virtual OUString getPartName(int nPart) SAL_OVERRIDE;
135360
     /// @see vcl::ITiledRenderable::initializeForTiledRendering().
135360
     virtual void initializeForTiledRendering() SAL_OVERRIDE;
135360
     /// @see vcl::ITiledRenderable::registerCallback().
135360
diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx
135360
index 159fb2ffbc41..525b551b9867 100644
135360
--- a/sw/inc/viscrs.hxx
135360
+++ b/sw/inc/viscrs.hxx
135360
@@ -43,6 +43,9 @@ class SwVisCrsr
135360
     vcl::Cursor m_aTextCrsr;
135360
     const SwCrsrShell* m_pCrsrShell;
135360
 
135360
+    /// For LibreOfficeKit only - remember what page we were at the last time.
135360
+    sal_uInt16 m_nPageLastTime;
135360
+
135360
     void _SetPosAndShow();
135360
 
135360
 public:
135360
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
135360
index 3e92ce5ef4e5..e0d32cc86e11 100644
135360
--- a/sw/source/core/crsr/viscrs.cxx
135360
+++ b/sw/source/core/crsr/viscrs.cxx
135360
@@ -67,6 +67,7 @@ MapMode* SwSelPaintRects::s_pMapMode = 0;
135360
 // Starting from here: classes / methods for the non-text-cursor
135360
 SwVisCrsr::SwVisCrsr( const SwCrsrShell * pCShell )
135360
     : m_pCrsrShell( pCShell )
135360
+    , m_nPageLastTime(0)
135360
 {
135360
     pCShell->GetWin()->SetCursor( &m_aTextCrsr );
135360
     m_bIsVisible = m_aTextCrsr.IsVisible();
135360
@@ -179,6 +180,17 @@ void SwVisCrsr::_SetPosAndShow()
135360
 
135360
     if (m_pCrsrShell->isTiledRendering())
135360
     {
135360
+        // notify about page number change (if that happened)
135360
+        sal_uInt16 nPage, nVirtPage;
135360
+        const_cast<SwCrsrShell*>(m_pCrsrShell)->GetPageNum(nPage, nVirtPage);
135360
+        if (nPage != m_nPageLastTime)
135360
+        {
135360
+            m_nPageLastTime = nPage;
135360
+            OString aPayload = OString::number(nPage - 1);
135360
+            m_pCrsrShell->libreOfficeKitCallback(LOK_CALLBACK_SET_PART, aPayload.getStr());
135360
+        }
135360
+
135360
+        // notify about the cursor position & size
135360
         Rectangle aSVRect(aRect.Pos().getX(), aRect.Pos().getY(), aRect.Pos().getX() + aRect.SSize().Width(), aRect.Pos().getY() + aRect.SSize().Height());
135360
         OString sRect = aSVRect.toString();
135360
         m_pCrsrShell->libreOfficeKitCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
135360
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
135360
index 450650d26c13..0dbde54f9144 100644
135360
--- a/sw/source/uibase/uno/unotxdoc.cxx
135360
+++ b/sw/source/uibase/uno/unotxdoc.cxx
135360
@@ -3154,6 +3154,50 @@ Size SwXTextDocument::getDocumentSize()
135360
                 aDocSize.Height() + 2L * DOCUMENTBORDER);
135360
 }
135360
 
135360
+void SwXTextDocument::setPart(int nPart)
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
135360
+    if (!pWrtShell)
135360
+        return;
135360
+
135360
+    pWrtShell->GotoPage(nPart + 1, true);
135360
+}
135360
+
135360
+int SwXTextDocument::getParts()
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
135360
+    if (!pWrtShell)
135360
+        return 0;
135360
+
135360
+    return pWrtShell->GetPageCnt();
135360
+}
135360
+
135360
+int SwXTextDocument::getPart()
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
135360
+    if (!pWrtShell)
135360
+        return 0;
135360
+
135360
+    sal_uInt16 nPage, nLogPage;
135360
+    OUString sDisplay;
135360
+    pWrtShell->GetPageNumber(-1, pWrtShell->IsCrsrVisible(), nPage, nLogPage, sDisplay);
135360
+
135360
+    return nPage - 1;
135360
+}
135360
+
135360
+OUString SwXTextDocument::getPartName(int nPart)
135360
+{
135360
+    SolarMutexGuard aGuard;
135360
+
135360
+    return OUString(SW_RES(STR_PAGE)) + OUString::number(nPart + 1);
135360
+}
135360
+
135360
 void SwXTextDocument::initializeForTiledRendering()
135360
 {
135360
     SolarMutexGuard aGuard;
135360
-- 
135360
2.12.0
135360