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 /sw | |
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>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/core/crsr/viscrs.cxx | 39 |
1 files changed, 36 insertions, 3 deletions
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); } } |