diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2019-10-20 13:18:51 +0200 |
---|---|---|
committer | Marco Cecchetti <marco.cecchetti@collabora.com> | 2019-10-21 12:42:57 +0200 |
commit | 56bf1745c7636bb04965e63de8d12bb867850391 (patch) | |
tree | 2c7726c0bc2d084f8ac0464e62c18b66bc854e69 /sw/source | |
parent | 98ca6029423eaa19cd4f163da49410310cdea8ae (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
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/crsr/viscrs.cxx | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx index 672184d863a6..2b14ffa27093 100644 --- a/sw/source/core/crsr/viscrs.cxx +++ b/sw/source/core/crsr/viscrs.cxx @@ -58,6 +58,7 @@ #include <comphelper/string.hxx> #include <paintfrm.hxx> #include <PostItMgr.hxx> +#include <SwGrammarMarkUp.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 @@ -186,7 +187,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; @@ -209,18 +211,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); } } |