diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2019-10-20 13:18:51 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-05-17 10:37:02 +0200 |
commit | c8fc88ff9fe27110b462c861e504fab15dfc1243 (patch) | |
tree | 66c547b947e4c071347a16a9461e981e3f6e66a6 | |
parent | f33e367c0005b3cbb37ff59aabd2e9ea295bba0a (diff) |
lok: get spelling context menu on long press
This patch handles a new flag attached to the invalidate view cursor
message for informing the client when the text cursor is inside a
mispelled word.
This information is used for popping up the spelling context menu on a
long press event instead of the standard context menu for a selected
word.
Change-Id: I13fcbe53c83ca6eb56300a601734cdc3211e88a0
Reviewed-on: https://gerrit.libreoffice.org/85244
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r-- | editeng/source/editeng/impedit.cxx | 6 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 7 | ||||
-rw-r--r-- | include/sfx2/lokhelper.hxx | 2 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 4 | ||||
-rw-r--r-- | sw/source/core/crsr/viscrs.cxx | 39 |
5 files changed, 50 insertions, 8 deletions
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx index 5006cd620d18..575fc087e47d 100644 --- a/editeng/source/editeng/impedit.cxx +++ b/editeng/source/editeng/impedit.cxx @@ -1102,7 +1102,11 @@ void ImpEditView::ShowCursor( bool bGotoCursor, bool bForceVisCursor ) } else { - SfxLokHelper::notifyVisCursorInvalidation(mpViewShell, sRect); + // is cursor at a mispelled word ? + Reference< linguistic2::XSpellChecker1 > xSpeller( pEditEngine->pImpEditEngine->GetSpeller() ); + bool bIsWrong = xSpeller.is() && IsWrongSpelledWord(aPaM, /*bMarkIfWrong*/ false); + + SfxLokHelper::notifyVisCursorInvalidation(mpViewShell, sRect, bIsWrong); mpViewShell->NotifyOtherViews(LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect); } } diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 69cee90893db..cfb046baf8d7 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -131,7 +131,12 @@ typedef enum /** * The size and/or the position of the visible cursor changed. * - * Rectangle format is the same as LOK_CALLBACK_INVALIDATE_TILES. + * Old format is the same as LOK_CALLBACK_INVALIDATE_TILES. + * New format is a JSON with 3 elements the 'viewId' element represented by + * an integer value, a 'rectangle' element in the format "x, y, width, height", + * and a 'mispelledWord' element represented by an integer value: '1' when + * a mispelled word is at the cursor position, '0' when the word is + * not mispelled. */ LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR = 1, /** diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 0a5af99a9e45..53c6010f2a74 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -56,7 +56,7 @@ public: /// Emits a LOK_CALLBACK_INVALIDATE_TILES, but tweaks it according to setOptionalFeatures() if needed. static void notifyInvalidation(SfxViewShell const* pThisView, const OString& rPayload); /// Emits a LOK_CALLBACK_INVALIDATE_VISIBLE_CURSOR, but tweaks it according to setOptionalFeatures() if needed. - static void notifyVisCursorInvalidation(OutlinerViewShell const* pThisView, const OString& rRectangle); + static void notifyVisCursorInvalidation(OutlinerViewShell const* pThisView, const OString& rRectangle, bool bMispelledWord = false); /// Notifies all views with the given type and payload. static void notifyAllViews(int nType, const OString& rPayload); diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 68b4cfcb8159..77214fc68359 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -296,13 +296,13 @@ void SfxLokHelper::notifyDocumentSizeChangedAllViews(vcl::ITiledRenderable* pDoc } } -void SfxLokHelper::notifyVisCursorInvalidation(OutlinerViewShell const* pThisView, const OString& rRectangle) +void SfxLokHelper::notifyVisCursorInvalidation(OutlinerViewShell const* pThisView, const OString& rRectangle, bool bMispelledWord) { OString sPayload; if (comphelper::LibreOfficeKit::isViewIdForVisCursorInvalidation()) { sPayload = OStringLiteral("{ \"viewId\": \"") + OString::number(SfxLokHelper::getView()) + - "\", \"rectangle\": \"" + rRectangle + "\" }"; + "\", \"rectangle\": \"" + rRectangle + "\", \"mispelledWord\": \"" + OString::number(bMispelledWord ? 1 : 0) + "\" }"; } else { diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 5aa804d364b0..51b59ed0afe7 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -52,8 +52,10 @@ #include <comphelper/string.hxx> #include <paintfrm.hxx> #include <PostItMgr.hxx> +#include <SwGrammarMarkUp.hxx> #include <cellfrm.hxx> +#include <wrtsh.hxx> // Here static members are defined. They will get changed on alteration of the // MapMode. This is done so that on ShowCursor the same size does not have to be @@ -182,7 +184,8 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * pViewShell) m_aTextCursor.SetPos( aRect.Pos() ); bool bPostItActive = false; - if (auto pView = dynamic_cast<SwView*>(m_pCursorShell->GetSfxViewShell())) + SwView* pView = dynamic_cast<SwView*>(m_pCursorShell->GetSfxViewShell()); + if (pView) { if (SwPostItMgr* pPostItMgr = pView->GetPostItMgr()) bPostItActive = pPostItMgr->GetActiveSidebarWin() != nullptr; @@ -205,18 +208,48 @@ void SwVisibleCursor::SetPosAndShow(SfxViewShell const * pViewShell) // notify about the cursor position & size tools::Rectangle aSVRect(aRect.Pos().getX(), aRect.Pos().getY(), aRect.Pos().getX() + aRect.SSize().Width(), aRect.Pos().getY() + aRect.SSize().Height()); OString sRect = aSVRect.toString(); + + // is cursor at a mispelled word ? + bool bIsWrong = false; + if (pView) + { + const SwViewOption* pVOpt = pView->GetWrtShell().GetViewOptions(); + if(pVOpt && pVOpt->IsOnlineSpell()) + { + SwPaM* pCursor = m_pCursorShell->GetCursor(); + SwPosition aPos(*pCursor->GetPoint()); + Point aPt = aRect.Pos(); + SwCursorMoveState eTmpState(MV_SETONLYTEXT); + SwTextNode *pNode = nullptr; + if (m_pCursorShell->GetLayout()->GetCursorOfst(&aPos, aPt, &eTmpState)) + pNode = aPos.nNode.GetNode().GetTextNode(); + if (pNode && !pNode->IsInProtectSect()) + { + sal_Int32 nBegin = aPos.nContent.GetIndex(); + sal_Int32 nLen = 1; + + SwWrongList *pWrong = nullptr; + pWrong = pNode->GetWrong(); + if (!pWrong) + pWrong = pNode->GetGrammarCheck(); + if (pWrong) + bIsWrong = pWrong->InWrongWord(nBegin,nLen) && !pNode->IsSymbolAt(nBegin); + } + } + } + if (pViewShell) { if (pViewShell == m_pCursorShell->GetSfxViewShell()) { - SfxLokHelper::notifyVisCursorInvalidation(pViewShell, sRect); + SfxLokHelper::notifyVisCursorInvalidation(pViewShell, sRect, bIsWrong); } else SfxLokHelper::notifyOtherView(m_pCursorShell->GetSfxViewShell(), pViewShell, LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect); } else { - SfxLokHelper::notifyVisCursorInvalidation(m_pCursorShell->GetSfxViewShell(), sRect); + SfxLokHelper::notifyVisCursorInvalidation(m_pCursorShell->GetSfxViewShell(), sRect, bIsWrong); SfxLokHelper::notifyOtherViews(m_pCursorShell->GetSfxViewShell(), LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", sRect); } } |