summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-12-12 21:21:09 +0000
committerSzymon Kłos <szymon.klos@collabora.com>2021-06-18 11:31:44 +0200
commit37d894167fa94a230d82fe55a421bca220ac6691 (patch)
tree20628be3eaefba14e8c6dfa8ce0e0c436a6f4e3c /editeng
parent131f00d6ba02965f342c352c111889e437b51fd8 (diff)
weld editview menu
also squashed: lok: remove popup auto correct item The auto correct options and auto correct menu item are no longer need it. Change-Id: I26bd2d011b5665f198f18d35b8433becca904991 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107572 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117256 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/inc/helpids.h24
-rw-r--r--editeng/source/editeng/editview.cxx158
2 files changed, 80 insertions, 102 deletions
diff --git a/editeng/inc/helpids.h b/editeng/inc/helpids.h
deleted file mode 100644
index 8c4639e8951d..000000000000
--- a/editeng/inc/helpids.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-#pragma once
-
-#define HID_EDITENG_SPELLER_WORDLANGUAGE "EDITENG_HID_EDITENG_SPELLER_WORDLANGUAGE"
-#define HID_EDITENG_SPELLER_PARALANGUAGE "EDITENG_HID_EDITENG_SPELLER_PARALANGUAGE"
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx
index 636d2280dd60..b589e6130217 100644
--- a/editeng/source/editeng/editview.cxx
+++ b/editeng/source/editeng/editview.cxx
@@ -20,7 +20,6 @@
#include <memory>
#include <sal/macros.h>
-#include <vcl/builder.hxx>
#include <vcl/image.hxx>
#include <com/sun/star/i18n/WordType.hpp>
@@ -47,9 +46,7 @@
#include <eerdll2.hxx>
#include <editeng/editrids.hrc>
#include <editeng.hxx>
-#include <helpids.h>
#include <i18nlangtag/lang.h>
-#include <vcl/menu.hxx>
#include <vcl/window.hxx>
#include <editeng/acorrcfg.hxx>
#include <editeng/unolingu.hxx>
@@ -887,7 +884,7 @@ bool EditView::IsWrongSpelledWordAtPos( const Point& rPosPixel, bool bMarkIfWron
return pImpEditView->IsWrongSpelledWord( aPaM , bMarkIfWrong );
}
-static void LOKSendSpellPopupMenu(Menu* pMenu, LanguageType nGuessLangWord,
+static void LOKSendSpellPopupMenu(const weld::Menu& rMenu, LanguageType nGuessLangWord,
LanguageType nGuessLangPara, sal_uInt16 nSuggestions)
{
if (!comphelper::LibreOfficeKit::isActive())
@@ -905,13 +902,13 @@ static void LOKSendSpellPopupMenu(Menu* pMenu, LanguageType nGuessLangWord,
{
for(int i = 0; i < nSuggestions; ++i)
{
- sal_uInt16 nItemId = MN_ALTSTART + i;
- OUString sText = pMenu->GetItemText(nItemId);
+ OString sItemId = OString::number(MN_ALTSTART + i);
+ OUString sText = rMenu.get_label(sItemId);
aItemTree.put("text", sText.toUtf8().getStr());
aItemTree.put("type", "command");
OUString sCommandString = ".uno:SpellCheckApplySuggestion?ApplyRule:string=Spelling_" + sText;
aItemTree.put("command", sCommandString.toUtf8().getStr());
- aItemTree.put("enabled", pMenu->IsItemEnabled(nItemId));
+ aItemTree.put("enabled", rMenu.get_sensitive(sItemId));
aMenu.push_back(std::make_pair("", aItemTree));
aItemTree.clear();
}
@@ -925,10 +922,10 @@ static void LOKSendSpellPopupMenu(Menu* pMenu, LanguageType nGuessLangWord,
OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) );
OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) );
- aItemTree.put("text", pMenu->GetItemText(pMenu->GetItemId("ignore")).toUtf8().getStr());
+ aItemTree.put("text", rMenu.get_label("ignore").toUtf8().getStr());
aItemTree.put("type", "command");
aItemTree.put("command", ".uno:SpellCheckIgnoreAll?Type:string=Spelling");
- aItemTree.put("enabled", pMenu->IsItemEnabled(pMenu->GetItemId("ignore")));
+ aItemTree.put("enabled", rMenu.get_sensitive("ignore"));
aMenu.push_back(std::make_pair("", aItemTree));
aItemTree.clear();
@@ -936,19 +933,19 @@ static void LOKSendSpellPopupMenu(Menu* pMenu, LanguageType nGuessLangWord,
aMenu.push_back(std::make_pair("", aItemTree));
aItemTree.clear();
- aItemTree.put("text", pMenu->GetItemText(MN_WORDLANGUAGE).toUtf8().getStr());
+ aItemTree.put("text", rMenu.get_label("wordlanguage").toUtf8().getStr());
aItemTree.put("type", "command");
OUString sCommandString = ".uno:LanguageStatus?Language:string=Current_" + aTmpWord;
aItemTree.put("command", sCommandString.toUtf8().getStr());
- aItemTree.put("enabled", pMenu->IsItemEnabled(MN_WORDLANGUAGE));
+ aItemTree.put("enabled", rMenu.get_sensitive("wordlanguage"));
aMenu.push_back(std::make_pair("", aItemTree));
aItemTree.clear();
- aItemTree.put("text", pMenu->GetItemText(MN_PARALANGUAGE).toUtf8().getStr());
+ aItemTree.put("text", rMenu.get_label("paralanguage").toUtf8().getStr());
aItemTree.put("type", "command");
sCommandString = ".uno:LanguageStatus?Language:string=Paragraph_" + aTmpPara;
aItemTree.put("command", sCommandString.toUtf8().getStr());
- aItemTree.put("enabled", pMenu->IsItemEnabled(MN_PARALANGUAGE));
+ aItemTree.put("enabled", rMenu.get_sensitive("paralanguage"));
aMenu.push_back(std::make_pair("", aItemTree));
aItemTree.clear();
@@ -970,17 +967,18 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
if ( !(xSpeller.is() && pImpEditView->IsWrongSpelledWord( aPaM, true )) )
return;
- VclBuilder aBuilder(nullptr, AllSettings::GetUIRootDir(), "editeng/ui/spellmenu.ui", "");
- VclPtr<PopupMenu> aPopupMenu(aBuilder.get_menu("editviewspellmenu"));
- const sal_uInt16 nAutoCorrId = aPopupMenu->GetItemId("autocorrect");
- PopupMenu *pAutoMenu = aPopupMenu->GetPopupMenu(nAutoCorrId);
- const sal_uInt16 nInsertId = aPopupMenu->GetItemId("insert");
- PopupMenu *pInsertMenu = aPopupMenu->GetPopupMenu(nInsertId); // add word to user-dictionaries
- pInsertMenu->SetMenuFlags( MenuFlags::NoAutoMnemonics ); //! necessary to retrieve the correct dictionary names later
- const sal_uInt16 nAddId = aPopupMenu->GetItemId("add");
- const sal_uInt16 nIgnoreId = aPopupMenu->GetItemId("ignore");
- const sal_uInt16 nCheckId = aPopupMenu->GetItemId("check");
- const sal_uInt16 nAutoCorrectDlgId = aPopupMenu->GetItemId("autocorrectdlg");
+ // PaMtoEditCursor returns Logical units
+ tools::Rectangle aTempRect = pImpEditView->pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GetCursorFlags::TextOnly );
+ // GetWindowPos works in Logical units
+ aTempRect = pImpEditView->GetWindowPos(aTempRect);
+ // Convert to pixels
+ aTempRect = pImpEditView->GetOutputDevice().LogicToPixel(aTempRect);
+
+ weld::Widget* pPopupParent = pImpEditView->GetPopupParent(aTempRect);
+ std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(pPopupParent, "editeng/ui/spellmenu.ui"));
+ std::unique_ptr<weld::Menu> xPopupMenu(xBuilder->weld_menu("editviewspellmenu"));
+ std::unique_ptr<weld::Menu> xInsertMenu(xBuilder->weld_menu("insertmenu")); // add word to user-dictionaries
+ std::unique_ptr<weld::Menu> xAutoMenu(xBuilder->weld_menu("automenu"));
EditPaM aPaM2( aPaM );
aPaM2.SetIndex( aPaM2.GetIndex()+1 );
@@ -1036,23 +1034,17 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
if (nGuessLangPara == LANGUAGE_NONE)
nGuessLangPara = nGuessLangWord;
- aPopupMenu->InsertSeparator();
+ xPopupMenu->append_separator("separator1");
OUString aTmpWord( SvtLanguageTable::GetLanguageString( nGuessLangWord ) );
OUString aTmpPara( SvtLanguageTable::GetLanguageString( nGuessLangPara ) );
OUString aWordStr( EditResId( RID_STR_WORD ) );
aWordStr = aWordStr.replaceFirst( "%x", aTmpWord );
OUString aParaStr( EditResId( RID_STR_PARAGRAPH ) );
aParaStr = aParaStr.replaceFirst( "%x", aTmpPara );
- aPopupMenu->InsertItem( MN_WORDLANGUAGE, aWordStr );
- aPopupMenu->SetHelpId( MN_WORDLANGUAGE, HID_EDITENG_SPELLER_WORDLANGUAGE );
- aPopupMenu->InsertItem( MN_PARALANGUAGE, aParaStr );
- aPopupMenu->SetHelpId( MN_PARALANGUAGE, HID_EDITENG_SPELLER_PARALANGUAGE );
+ xPopupMenu->append("wordlanguage", aWordStr);
+ xPopupMenu->append("paralanguage", aParaStr);
}
- // ## Create mnemonics here
- aPopupMenu->CreateAutoMnemonics();
- aPopupMenu->SetMenuFlags(aPopupMenu->GetMenuFlags() | MenuFlags::NoAutoMnemonics);
-
// Replace suggestions...
Sequence< OUString > aAlt;
if (xSpellAlt.is())
@@ -1064,13 +1056,16 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
for ( sal_uInt16 nW = 0; nW < nWords; nW++ )
{
OUString aAlternate( pAlt[nW] );
- aPopupMenu->InsertItem( MN_ALTSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
- pAutoMenu->InsertItem( MN_AUTOSTART+nW, aAlternate, MenuItemBits::NONE, OString(), nW );
+ xPopupMenu->append(OUString::number(MN_ALTSTART + nW), aAlternate);
+ xAutoMenu->append(OUString::number(MN_AUTOSTART + nW), aAlternate);
}
- aPopupMenu->InsertSeparator(OString(), nWords);
+ xPopupMenu->append_separator("separator2");
}
else
- aPopupMenu->RemoveItem(nAutoCorrId); // delete?
+ {
+ xAutoMenu.reset();
+ xPopupMenu->remove("autocorrect");
+ }
SvtLinguConfig aCfg;
@@ -1103,11 +1098,7 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
&& (nCheckedLanguage == nActLanguage || LANGUAGE_NONE == nActLanguage )
&& (!xStor.is() || !xStor->isReadonly()) )
{
- // the extra 1 is because of the (possible) external
- // linguistic entry above
- sal_uInt16 nPos = MN_DICTSTART + i;
- pInsertMenu->InsertItem( nPos, xDicTmp->getName() );
- aDicNameSingle = xDicTmp->getName();
+ OUString sImage;
uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
if (xSvcInfo.is())
@@ -1115,26 +1106,34 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
xSvcInfo->getImplementationName()) );
if (!aDictionaryImageUrl.isEmpty() )
- {
- Image aImage( aDictionaryImageUrl );
- pInsertMenu->SetItemImage( nPos, aImage );
- }
+ sImage = aDictionaryImageUrl;
+ }
+
+ if (sImage.isEmpty())
+ {
+ xInsertMenu->append(OUString::number(MN_DICTSTART + i), xDicTmp->getName());
}
+ else
+ {
+ Image aImage(sImage);
+ ScopedVclPtr<VirtualDevice> xVirDev(pPopupParent->create_virtual_device());
+ Size aSize(aImage.GetSizePixel());
+ xVirDev->SetOutputSizePixel(aSize);
+ xVirDev->DrawImage(Point(0, 0), aImage);
+ xInsertMenu->append(OUString::number(MN_DICTSTART + i), xDicTmp->getName(), *xVirDev);
+ }
+ aDicNameSingle = xDicTmp->getName();
}
}
}
- if (pInsertMenu->GetItemCount() != 1)
- aPopupMenu->EnableItem(nAddId, false);
- if (pInsertMenu->GetItemCount() < 2)
- aPopupMenu->EnableItem(nInsertId, false);
-
- aPopupMenu->RemoveDisabledEntries( true, true );
-
- tools::Rectangle aTempRect = pImpEditView->pEditEngine->pImpEditEngine->PaMtoEditCursor( aPaM, GetCursorFlags::TextOnly );
- Point aScreenPos = pImpEditView->GetWindowPos( aTempRect.TopLeft() );
- aScreenPos = pImpEditView->GetWindow()->OutputToScreenPixel( aScreenPos );
- aTempRect = pImpEditView->GetWindow()->LogicToPixel( tools::Rectangle(aScreenPos, aTempRect.GetSize() ));
+ if (xInsertMenu->n_children() != 1)
+ xPopupMenu->remove("add");
+ if (xInsertMenu->n_children() < 2)
+ {
+ xInsertMenu.reset();
+ xPopupMenu->remove("insert");
+ }
//tdf#106123 store and restore the EditPaM around the menu Execute
//because the loss of focus in the current editeng causes writer
@@ -1143,26 +1142,26 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
EPaM aP = pImpEditView->pEditEngine->pImpEditEngine->CreateEPaM(aPaM);
EPaM aP2 = pImpEditView->pEditEngine->pImpEditEngine->CreateEPaM(aPaM2);
-
if (comphelper::LibreOfficeKit::isActive())
{
- aPopupMenu->RemoveItem(nAutoCorrId);
- aPopupMenu->RemoveItem(nAutoCorrectDlgId);
+ xPopupMenu->remove("autocorrect");
+ xPopupMenu->remove("autocorrectdlg");
// For mobile phones, send the context menu structure
const SfxViewShell* pViewShell = SfxViewShell::Current();
if (pViewShell && pViewShell->isLOKMobilePhone())
{
- LOKSendSpellPopupMenu(aPopupMenu, nGuessLangWord, nGuessLangPara, nWords);
+ LOKSendSpellPopupMenu(*xPopupMenu, nGuessLangWord, nGuessLangPara, nWords);
return;
}
}
- sal_uInt16 nId = aPopupMenu->Execute(pImpEditView->GetWindow(), aTempRect, PopupMenuFlags::NoMouseUpClose);
+
+ OString sId = xPopupMenu->popup_at_rect(pPopupParent, aTempRect);
aPaM2 = pImpEditView->pEditEngine->pImpEditEngine->CreateEditPaM(aP2);
aPaM = pImpEditView->pEditEngine->pImpEditEngine->CreateEditPaM(aP);
- if (nId == nIgnoreId)
+ if (sId == "ignore")
{
OUString aWord = pImpEditView->SpellIgnoreWord();
if ( pCallBack )
@@ -1172,9 +1171,9 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
}
SetSelection( aOldSel );
}
- else if ( ( nId == MN_WORDLANGUAGE ) || ( nId == MN_PARALANGUAGE ) )
+ else if (sId == "wordlanguage" || sId == "paralanguage")
{
- LanguageType nLangToUse = (nId == MN_WORDLANGUAGE) ? nGuessLangWord : nGuessLangPara;
+ LanguageType nLangToUse = (sId == "wordlanguage") ? nGuessLangWord : nGuessLangPara;
SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLangToUse );
SfxItemSet aAttrs = GetEditEngine()->GetEmptyItemSet();
@@ -1184,7 +1183,7 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CTL ) );
if (nScriptType == SvtScriptType::ASIAN)
aAttrs.Put( SvxLanguageItem( nLangToUse, EE_CHAR_LANGUAGE_CJK ) );
- if ( nId == MN_PARALANGUAGE )
+ if (sId == "paralanguage")
{
ESelection aSel = GetSelection();
aSel.nStartPos = 0;
@@ -1196,12 +1195,12 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
if ( pCallBack )
{
- SpellCallbackInfo aInf( ( nId == MN_WORDLANGUAGE ) ? SpellCallbackCommand::WORDLANGUAGE : SpellCallbackCommand::PARALANGUAGE );
+ SpellCallbackInfo aInf( (sId == "wordlanguage") ? SpellCallbackCommand::WORDLANGUAGE : SpellCallbackCommand::PARALANGUAGE );
pCallBack->Call( aInf );
}
SetSelection( aOldSel );
}
- else if (nId == nCheckId)
+ else if (sId == "check")
{
if ( !pCallBack )
{
@@ -1219,16 +1218,19 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
pCallBack->Call( aInf );
}
}
- else if (nId == nAutoCorrectDlgId && pCallBack)
+ else if (sId == "autocorrectdlg" && pCallBack)
{
SpellCallbackInfo aInf( SpellCallbackCommand::AUTOCORRECT_OPTIONS, OUString() );
pCallBack->Call( aInf );
}
- else if ( nId >= MN_DICTSTART || nId == nAddId)
+ else if ( sId.toInt32() >= MN_DICTSTART || sId == "add")
{
OUString aDicName;
- if (nId >= MN_DICTSTART)
- aDicName = pInsertMenu->GetItemText(nId);
+ if (sId.toInt32() >= MN_DICTSTART)
+ {
+ // strip_mnemonic is necessary to retrieve the correct dictionary name
+ aDicName = pPopupParent->strip_mnemonic(xInsertMenu->get_label(sId));
+ }
else
aDicName = aDicNameSingle;
@@ -1253,19 +1255,19 @@ void EditView::ExecuteSpellPopup( const Point& rPosPixel, Link<SpellCallbackInfo
}
SetSelection( aOldSel );
}
- else if ( nId >= MN_AUTOSTART )
+ else if ( sId.toInt32() >= MN_AUTOSTART )
{
- DBG_ASSERT(nId - MN_AUTOSTART < aAlt.getLength(), "index out of range");
- OUString aWord = pAlt[nId - MN_AUTOSTART];
+ DBG_ASSERT(sId.toInt32() - MN_AUTOSTART < aAlt.getLength(), "index out of range");
+ OUString aWord = pAlt[sId.toInt32() - MN_AUTOSTART];
SvxAutoCorrect* pAutoCorrect = SvxAutoCorrCfg::Get().GetAutoCorrect();
if ( pAutoCorrect )
pAutoCorrect->PutText( aSelected, aWord, pImpEditView->pEditEngine->pImpEditEngine->GetLanguage( aPaM2 ) );
InsertText( aWord );
}
- else if ( nId >= MN_ALTSTART ) // Replace
+ else if ( sId.toInt32() >= MN_ALTSTART ) // Replace
{
- DBG_ASSERT(nId - MN_ALTSTART < aAlt.getLength(), "index out of range");
- OUString aWord = pAlt[nId - MN_ALTSTART];
+ DBG_ASSERT(sId.toInt32() - MN_ALTSTART < aAlt.getLength(), "index out of range");
+ OUString aWord = pAlt[sId.toInt32() - MN_ALTSTART];
InsertText( aWord );
}
else