[Libreoffice-commits] core.git: include/sfx2 sfx2/source sw/inc sw/source
Miklos Vajna
vmiklos at collabora.co.uk
Wed Aug 31 17:19:21 UTC 2016
include/sfx2/lokhelper.hxx | 2 ++
include/sfx2/viewsh.hxx | 2 ++
sfx2/source/view/lokhelper.cxx | 26 +++++++++++++++-----------
sfx2/source/view/viewsh.cxx | 9 ++++++---
sw/inc/crsrsh.hxx | 3 +++
sw/inc/view.hxx | 2 ++
sw/inc/viscrs.hxx | 4 ++--
sw/source/core/crsr/crsrsh.cxx | 5 +++++
sw/source/core/crsr/viscrs.cxx | 18 ++++++++++++++----
sw/source/uibase/uiview/viewprt.cxx | 5 +++++
10 files changed, 56 insertions(+), 20 deletions(-)
New commits:
commit 7167c2b6548830b82280f2f3943d445e9afd6f5e
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Wed Aug 31 17:19:13 2016 +0200
sfx2 lok: introduce SfxViewShell::NotifyCursor()
It allows removing the hide/show cursor hack in
SfxViewShell::registerLibreOfficeKitViewCallback() introduced in commit
4d211384f048b689f20e46d4d586f342b110cb5c (sfx2 lok: fix missing view
cursors in a new view, 2016-06-20), and instead let the application code
in sw/sc/sd implement the best way to show existing cursors in a new
view.
This way the per-app cleanup of view cursors introduced in commit
bc9b4fd4c83af3532204237157821d4884c42d8e (lok::Document::destroyView:
clean up view cursors/selections, 2016-07-15) has matching per-app init
code.
This commit just adds the API + adapts existing sw code to use it, sc/sd
still has to be implemented.
Based on a patch by Marco Cecchetti, thanks!
Change-Id: I38510fa4962f405b1b96a79024206c9e7f33cad2
Reviewed-on: https://gerrit.libreoffice.org/28557
Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
Tested-by: Jenkins <ci at libreoffice.org>
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index e7dfed4..852aa79 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -32,6 +32,8 @@ public:
/// Invoke the LOK callback of all views except pThisView, with a payload of rKey-rPayload.
static void notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload);
+ /// Same as notifyOtherViews(), but works on a selected "other" view, not on all of them.
+ static void notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload);
};
#endif
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index d20d4e3..1c7266a 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -342,6 +342,8 @@ public:
sal_uInt32 GetViewShellId() const override;
/// See OutlinerViewShell::NotifyOtherViews().
void NotifyOtherViews(int nType, const OString& rKey, const OString& rPayload) override;
+ /// Ask this view to send its cursor position to pViewShell.
+ virtual void NotifyCursor(SfxViewShell* /*pViewShell*/) const;
};
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 7a23e1b..c5fb171 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -92,6 +92,19 @@ std::size_t SfxLokHelper::getViews()
return rViewArr.size();
}
+void SfxLokHelper::notifyOtherView(SfxViewShell* pThisView, SfxViewShell* pOtherView, int nType, const OString& rKey, const OString& rPayload)
+{
+ boost::property_tree::ptree aTree;
+ aTree.put("viewId", SfxLokHelper::getView(pThisView));
+ aTree.put(rKey.getStr(), rPayload.getStr());
+ aTree.put("part", pThisView->getPart());
+ aTree.put(rKey.getStr(), rPayload.getStr());
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aTree);
+ OString aPayload = aStream.str().c_str();
+ pOtherView->libreOfficeKitViewCallback(nType, aPayload.getStr());
+}
+
void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OString& rKey, const OString& rPayload)
{
if (SfxLokHelper::getViews() <= 1)
@@ -101,17 +114,8 @@ void SfxLokHelper::notifyOtherViews(SfxViewShell* pThisView, int nType, const OS
while (pViewShell)
{
if (pViewShell != pThisView)
- {
- boost::property_tree::ptree aTree;
- aTree.put("viewId", SfxLokHelper::getView(pThisView));
- aTree.put(rKey.getStr(), rPayload.getStr());
- aTree.put("part", pThisView->getPart());
- aTree.put(rKey.getStr(), rPayload.getStr());
- std::stringstream aStream;
- boost::property_tree::write_json(aStream, aTree);
- OString aPayload = aStream.str().c_str();
- pViewShell->libreOfficeKitViewCallback(nType, aPayload.getStr());
- }
+ notifyOtherView(pThisView, pViewShell, nType, rKey, rPayload);
+
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index f2d8e48..710c9cb 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -1462,12 +1462,11 @@ void SfxViewShell::registerLibreOfficeKitViewCallback(LibreOfficeKitCallback pCa
pImpl->m_pLibreOfficeKitViewCallback = pCallback;
pImpl->m_pLibreOfficeKitViewData = pData;
- // Ask other views to send their cursor position to the new view.
+ // Ask other views to tell us about their cursors.
SfxViewShell* pViewShell = SfxViewShell::GetFirst();
while (pViewShell)
{
- pViewShell->ShowCursor(false);
- pViewShell->ShowCursor();
+ pViewShell->NotifyCursor(this);
pViewShell = SfxViewShell::GetNext(*pViewShell);
}
}
@@ -1495,6 +1494,10 @@ void SfxViewShell::libreOfficeKitViewCallback(int nType, const char* pPayload) c
pImpl->m_pLibreOfficeKitViewCallback(nType, pPayload, pImpl->m_pLibreOfficeKitViewData);
}
+void SfxViewShell::NotifyCursor(SfxViewShell* /*pViewShell*/) const
+{
+}
+
void SfxViewShell::setTiledSearching(bool bTiledSearching)
{
pImpl->m_bTiledSearching = bTiledSearching;
diff --git a/sw/inc/crsrsh.hxx b/sw/inc/crsrsh.hxx
index dbe62d6..82671bf 100644
--- a/sw/inc/crsrsh.hxx
+++ b/sw/inc/crsrsh.hxx
@@ -842,6 +842,9 @@ public:
virtual void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
/// Implementation of lok::Document::getPartPageRectangles() for Writer.
OUString getPageRectangles();
+
+ /// See SwView::NotifyCursor().
+ void NotifyCursor(SfxViewShell* pViewShell) const;
};
// Cursor Inlines:
diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index dbae9ad..76d1a34 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -648,6 +648,8 @@ public:
void dumpAsXml(struct _xmlTextWriter* pWriter) const override;
void SetRedlineAuthor(const OUString& rAuthor);
const OUString& GetRedlineAuthor();
+ /// See SfxViewShell::NotifyCursor().
+ void NotifyCursor(SfxViewShell* pViewShell) const override;
};
inline long SwView::GetXScroll() const
diff --git a/sw/inc/viscrs.hxx b/sw/inc/viscrs.hxx
index cd7204d..3635048 100644
--- a/sw/inc/viscrs.hxx
+++ b/sw/inc/viscrs.hxx
@@ -29,6 +29,7 @@
class SwCursorShell;
class SwShellCursor;
class SwTextInputField;
+class SfxViewShell;
// From here classes/methods for non-text cursor.
@@ -46,8 +47,6 @@ class SwVisibleCursor
/// For LibreOfficeKit only - remember what page we were at the last time.
sal_uInt16 m_nPageLastTime;
- void SetPosAndShow();
-
public:
SwVisibleCursor( const SwCursorShell * pCShell );
~SwVisibleCursor();
@@ -57,6 +56,7 @@ public:
bool IsVisible() const { return m_bIsVisible; }
void SetDragCursor( bool bFlag = true ) { m_bIsDragCursor = bFlag; }
+ void SetPosAndShow(SfxViewShell* pViewShell);
};
// From here classes/methods for selections.
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 1c24eb6..0e15778 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1217,6 +1217,11 @@ OUString SwCursorShell::getPageRectangles()
return OUString::fromUtf8(comphelper::string::join("; ", v).getStr());
}
+void SwCursorShell::NotifyCursor(SfxViewShell* pViewShell) const
+{
+ m_pVisibleCursor->SetPosAndShow(pViewShell);
+}
+
/// go to the next SSelection
bool SwCursorShell::GoNextCursor()
{
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 3cb2021..d2e0fb3 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -95,7 +95,7 @@ void SwVisibleCursor::Show()
// display at all?
if( m_pCursorShell->VisArea().IsOver( m_pCursorShell->m_aCharRect ) || comphelper::LibreOfficeKit::isActive() )
- SetPosAndShow();
+ SetPosAndShow(nullptr);
}
}
@@ -110,7 +110,7 @@ void SwVisibleCursor::Hide()
}
}
-void SwVisibleCursor::SetPosAndShow()
+void SwVisibleCursor::SetPosAndShow(SfxViewShell* pViewShell)
{
SwRect aRect;
long nTmpY = m_pCursorShell->m_aCursorHeight.getY();
@@ -199,8 +199,18 @@ void SwVisibleCursor::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_pCursorShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
- SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+ if (pViewShell)
+ {
+ if (pViewShell == m_pCursorShell->GetSfxViewShell())
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+ else
+ SfxLokHelper::notifyOtherView(m_pCursorShell->GetSfxViewShell(), pViewShell, LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+ }
+ else
+ {
+ m_pCursorShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, sRect.getStr());
+ SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect);
+ }
}
if ( !m_pCursorShell->IsCursorReadonly() || m_pCursorShell->GetViewOptions()->IsSelectionInReadonly() )
diff --git a/sw/source/uibase/uiview/viewprt.cxx b/sw/source/uibase/uiview/viewprt.cxx
index 9a0abf6..44b472b 100644
--- a/sw/source/uibase/uiview/viewprt.cxx
+++ b/sw/source/uibase/uiview/viewprt.cxx
@@ -279,6 +279,11 @@ const OUString& SwView::GetRedlineAuthor()
return m_pViewImpl->m_sRedlineAuthor;
}
+void SwView::NotifyCursor(SfxViewShell* pViewShell) const
+{
+ m_pWrtShell->NotifyCursor(pViewShell);
+}
+
// Create page printer/additions for SwView and SwPagePreview
VclPtr<SfxTabPage> CreatePrintOptionsPage( vcl::Window *pParent,
More information about the Libreoffice-commits
mailing list