From d1ea99306a17df5403be282a9f9afd57b03a2a70 Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Mon, 16 Mar 2020 15:49:29 +0100 Subject: lok: Send spelling popup menu structure for mobile (calc and impress). MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. Change-Id: If342c83143a9a7c2ec74b99027f6d4ba8b44ef08 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90595 Tested-by: Jenkins Reviewed-by: Tamás Zolnai --- editeng/source/editeng/editview.cxx | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'editeng/source') diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index 9ada4292ba12..bc339115d790 100644 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -69,6 +69,9 @@ #include #include #include +#include +#include +#include #include @@ -845,6 +848,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 const * pCallBack ) { Point aPos ( pImpEditView->GetWindow()->PixelToLogic( rPosPixel ) ); @@ -1029,7 +1067,16 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, LinkSetLOKNotifier(SfxViewShell::Current()); + { + // For mobile, send the context menu structure + if (comphelper::LibreOfficeKit::isMobile(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); -- cgit