summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Cecchetti <marco.cecchetti@collabora.com>2019-10-20 13:18:51 +0200
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-12-17 11:32:33 +0100
commitdfcfdf47b5da6a11b2c3118a0f63cc48c10c2cd7 (patch)
tree831f85befc8c830f5d00a4b0cef01e343e2746e0
parent1fd65c35f9cc44d94ac10e929b9c9c4bfb8d1afc (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.cxx6
-rw-r--r--include/LibreOfficeKit/LibreOfficeKitEnums.h7
-rw-r--r--include/sfx2/lokhelper.hxx2
-rw-r--r--sfx2/source/view/lokhelper.cxx4
-rw-r--r--sw/source/core/crsr/viscrs.cxx39
5 files changed, 50 insertions, 8 deletions
diff --git a/editeng/source/editeng/impedit.cxx b/editeng/source/editeng/impedit.cxx
index 348d74bf41ff..3291e345d455 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 fb4822613724..e162620403f5 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 12a5a4bb2926..524d0b1768e3 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -338,7 +338,7 @@ 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)
{
if (DisableCallbacks::disabled())
return;
@@ -347,7 +347,7 @@ void SfxLokHelper::notifyVisCursorInvalidation(OutlinerViewShell const* pThisVie
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);
}
}