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