summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2020-03-16 15:49:29 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2020-03-17 13:10:04 +0100
commit55e147a40a480ff08c717aa2be9cbca567f07414 (patch)
treef7f92c03c6b3b971aaeb818904a732aed6750cfe /editeng
parentc4e16b1361c887fb5c51000a7cb3da94330a79da (diff)
lok: Send spelling popup menu structure for mobile (calc and impress).
Similar to how writer behaves. Instead of using tunneling, we send the menu structure with the commands. By now this commands are not executed by the document shell of calc / impress. I'll implement that in separate commits. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90595 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com> (cherry picked from commit d7fa4fc8b64769f0d25b87ff33b8d1b8e96572d9) Change-Id: If342c83143a9a7c2ec74b99027f6d4ba8b44ef08
Diffstat (limited to 'editeng')
-rw-r--r--editeng/source/editeng/editview.cxx49
1 files changed, 48 insertions, 1 deletions
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 20a4baeaee04..621a7d3bcfff 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -64,6 +64,9 @@
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <comphelper/lok.hxx>
#include <sfx2/viewsh.hxx>
+#include <sfx2/lokhelper.hxx>
+#include <boost/property_tree/json_parser.hpp>
+#include <sfx2/dispatch.hxx>
#include <com/sun/star/lang/XServiceInfo.hpp>
@@ -849,6 +852,41 @@ bool EditView::IsWrongSpelledWordAtPos( const Point& rPosPixel, bool bMarkIfWron
return pImpEditView->IsWrongSpelledWord( aPaM , bMarkIfWrong );
}
+static void LOKSendSpellPopupMenu(Menu* pMenu, LanguageType nGuessLangWord,
+ LanguageType nGuessLangPara, sal_uInt16 nSuggestions)
+{
+ if (!comphelper::LibreOfficeKit::isActive())
+ return;
+
+ // First we need to set item commends for the context menu.
+ OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) );
+ OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) );
+
+ pMenu->SetItemCommand(pMenu->GetItemId("ignore"), ".uno:SpellCheckIgnoreAll?Type:string=Spelling");
+ pMenu->SetItemCommand(MN_WORDLANGUAGE, ".uno:LanguageStatus?Language:string=Current_" + aTmpWord);
+ pMenu->SetItemCommand(MN_PARALANGUAGE, ".uno:LanguageStatus?Language:string=Paragraph_" + aTmpPara);
+
+ for(int i = 0; i < nSuggestions; ++i)
+ {
+ sal_uInt16 nItemId = MN_ALTSTART + i;
+ OUString sCommandString = ".uno:SpellCheckApplySuggestion?ApplyRule:string=Spelling_" + pMenu->GetItemText(nItemId);
+ pMenu->SetItemCommand(nItemId, sCommandString);
+ }
+
+ // Then we generate the menu structure and send it to the client code.
+ if (SfxViewShell* pViewShell = SfxViewShell::Current())
+ {
+ boost::property_tree::ptree aMenu = SfxDispatcher::fillPopupMenu(pMenu);
+ boost::property_tree::ptree aRoot;
+ aRoot.add_child("menu", aMenu);
+
+ std::stringstream aStream;
+ boost::property_tree::write_json(aStream, aRoot, true);
+ pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CONTEXT_MENU, aStream.str().c_str());
+ return;
+ }
+}
+
void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo&,void> const * pCallBack )
{
Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) );
@@ -1033,7 +1071,16 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
if (comphelper::LibreOfficeKit::isActive())
- aPopupMenu->SetLOKNotifier(SfxViewShell::Current());
+ {
+ // For mobile, send the context menu structure
+ if (comphelper::LibreOfficeKit::isMobilePhone(SfxLokHelper::getView()))
+ {
+ LOKSendSpellPopupMenu(aPopupMenu, nGuessLangWord, nGuessLangPara, nWords);
+ return;
+ }
+ else // For desktop, we use the tunneled dialog
+ aPopupMenu->SetLOKNotifier(SfxViewShell::Current());
+ }
sal_uInt16 nId = aPopupMenu->Execute(pImpEditView->GetWindow(), aTempRect, PopupMenuFlags::NoMouseUpClose);
aPaM2 = pImpEditView->pEditEngine->pImpEditEngine->CreateEditPaM(aP2);