diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2020-06-02 13:47:12 +0530 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.com> | 2020-07-07 08:43:11 +0200 |
commit | 9a28558a222db9b066283ff78e71d1e5910f2569 (patch) | |
tree | e7aee5f9ffb05dd776d3a96bc233f3566e848426 /editeng | |
parent | f94fd72e87616e6c05a9ea07f21106f488234c15 (diff) |
lokit: editeng: Use 'special-positioning' data...
for computing edit-cursor messages if available. For Calc, this means
the LOK clients get edit-cursor coordinates in print-twips.
Change-Id: Ib11f3653e626ba8db7ddbc9bc2b4e071de7b705e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98121
Tested-by: Jenkins
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/impedit.cxx | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 8da3740ba6cf..efc1dee49b63 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -39,6 +39,7 @@ #include <sot/formats.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/string.hxx> +#include <sfx2/viewsh.hxx> #include <sfx2/lokhelper.hxx> #include <boost/property_tree/json_parser.hpp> @@ -1017,16 +1018,13 @@ void ImpEditView::CalcAnchorPoint() namespace { -// Build JSON message to be sent to Online -OString buildHyperlinkJSON(const OUString& sText, const OUString& sLink) +// For building JSON message to be sent to Online +boost::property_tree::ptree getHyperlinkPropTree(const OUString& sText, const OUString& sLink) { boost::property_tree::ptree aTree; aTree.put("text", sText); aTree.put("link", sLink); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree, false); - - return OString(aStream.str().c_str()).trim(); + return aTree; } } // End of anon namespace @@ -1264,6 +1262,27 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) if (comphelper::LibreOfficeKit::isActive() && mpViewShell) { Point aPos = GetCursor()->GetPos(); + boost::property_tree::ptree aMessageParams; + if (mpLOKSpecialPositioning) + { + // Sending the absolute (pure) logical coordinates of the cursor to the client is not + // enough for it to accurately reconstruct the corresponding tile-twips coordinates of the cursor. + // This is because the editeng(doc) positioning is not pixel aligned for each cell involved in the output-area + // (it better not be!). A simple solution is to send the coordinates of a point ('refpoint') in the output-area + // along with the relative position of the cursor w.r.t this chosen 'refpoint'. + + MapUnit eDevUnit = rOutDev.GetMapMode().GetMapUnit(); + tools::Rectangle aCursorRectPureLogical(aEditCursor.TopLeft(), GetCursor()->GetSize()); + // Get rectangle in window-coordinates from editeng(doc) coordinates. + aCursorRectPureLogical = mpLOKSpecialPositioning->GetWindowPos(aCursorRectPureLogical, eDevUnit); + // Lets use the editeng(doc) origin as the refpoint. + const Point aCursorOrigin = mpLOKSpecialPositioning->GetWindowPos(Point(0, 0), eDevUnit); + // Get the relative coordinates w.r.t aCursorOrigin. + aCursorRectPureLogical.Move(-aCursorOrigin.X(), -aCursorOrigin.Y()); + aMessageParams.put("relrect", aCursorRectPureLogical.toString()); + aMessageParams.put("refpoint", aCursorOrigin.toString()); + } + if (pOutWin && pOutWin->IsChart()) { const vcl::Window* pViewShellWindow = mpViewShell->GetEditWindowForActiveOLEObj(); @@ -1291,11 +1310,17 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) aRect.setWidth(0); OString sRect = aRect.toString(); - if (mpOtherShell) + aMessageParams.put("rectangle", sRect); + + SfxViewShell* pThisShell = dynamic_cast<SfxViewShell*>(mpViewShell); + SfxViewShell* pOtherShell = dynamic_cast<SfxViewShell*>(mpOtherShell); + assert(pThisShell); + + if (pOtherShell && pThisShell != pOtherShell) { // Another shell wants to know about our existing cursor. - if (mpViewShell != mpOtherShell) - mpViewShell->NotifyOtherView(mpOtherShell, LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect); + SfxLokHelper::notifyOtherView(pThisShell, pOtherShell, + LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, aMessageParams); } else { @@ -1303,12 +1328,12 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) Reference< linguistic2::XSpellChecker1 > xSpeller( pEditEngine->pImpEditEngine->GetSpeller() ); bool bIsWrong = xSpeller.is() && IsWrongSpelledWord(aPaM, /*bMarkIfWrong*/ false); - OString sHyperlink; + boost::property_tree::ptree aHyperlinkTree; if (const SvxFieldItem* pFld = GetField(aPos, nullptr, nullptr)) { if (auto pUrlField = dynamic_cast<const SvxURLField*>(pFld->GetField())) { - sHyperlink = buildHyperlinkJSON(pUrlField->GetRepresentation(), pUrlField->GetURL()); + aHyperlinkTree = getHyperlinkPropTree(pUrlField->GetRepresentation(), pUrlField->GetURL()); } } else if (GetEditSelection().HasRange()) @@ -1323,15 +1348,25 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) const SvxFieldData* pField = pFieldItem->GetField(); if ( auto pUrlField = dynamic_cast<const SvxURLField*>( pField) ) { - sHyperlink = buildHyperlinkJSON(pUrlField->GetRepresentation(), pUrlField->GetURL()); + aHyperlinkTree = getHyperlinkPropTree(pUrlField->GetRepresentation(), pUrlField->GetURL()); } } } } - SfxLokHelper::notifyVisCursorInvalidation(mpViewShell, sRect, bIsWrong, sHyperlink); if (mbBroadcastLOKViewCursor) - mpViewShell->NotifyOtherViews(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect); + SfxLokHelper::notifyOtherViews(pThisShell, + LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, aMessageParams); + + aMessageParams.put("mispelledWord", bIsWrong ? 1 : 0); + aMessageParams.add_child("hyperlink", aHyperlinkTree); + + if (comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation()) + SfxLokHelper::notifyOtherView(pThisShell, pThisShell, + LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, aMessageParams); + else + pThisShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, + aMessageParams.get<std::string>("rectangle").c_str()); } } |