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