27#include <bitmaps.hlst>
47#include <rtl/string.hxx>
61#include <osl/diagnose.h>
65#include <com/sun/star/document/XDocumentLanguages.hpp>
66#include <com/sun/star/frame/XFrame.hpp>
67#include <com/sun/star/frame/XStorable.hpp>
68#include <com/sun/star/lang/XServiceInfo.hpp>
69#include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
70#include <com/sun/star/uno/Any.hxx>
71#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
72#include <com/sun/star/system/SystemShellExecute.hpp>
73#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
94 sal_uInt16 nLangItemIdStart,
95 const uno::Sequence< OUString >& aSeq,
97 std::map< sal_Int16, OUString > &rLangTable )
103 std::set< OUString > aLangItems;
105 OUString aCurLang(
aSeq[0] );
107 OUString aKeyboardLang(
aSeq[2] );
108 OUString aGuessedTextLang(
aSeq[3] );
110 if (!aCurLang.isEmpty() &&
112 aLangItems.insert( aCurLang );
132 if (!aGuessedTextLang.isEmpty())
135 aLangItems.insert( aGuessedTextLang );
139 if (!aKeyboardLang.isEmpty())
142 aLangItems.insert( aKeyboardLang );
146 uno::Reference< css::frame::XModel >
xModel;
150 uno::Reference< document::XDocumentLanguages > xDocumentLanguages(
xModel, uno::UNO_QUERY );
156 const sal_Int16 nMaxCount = 7;
157 if (xDocumentLanguages.is())
159 const uno::Sequence< lang::Locale > rLocales( xDocumentLanguages->getDocumentLanguages(
static_cast<sal_Int16
>(nScriptType), nMaxCount ) );
160 for (
const lang::Locale& rLocale : rLocales)
162 if (aLangItems.size() ==
size_t(nMaxCount))
165 aLangItems.insert( rLocale.Language );
169 sal_uInt16 nItemId = nLangItemIdStart;
170 for (
const OUString& aEntryText : aLangItems)
174 !aEntryText.isEmpty())
176 OSL_ENSURE( nLangItemIdStart <= nItemId && nItemId <= nLangItemIdStart +
MN_MAX_NUM_LANG,
177 "nItemId outside of expected range!" );
178 pPopupMenu->
InsertItem( nItemId, aEntryText, MenuItemBits::RADIOCHECK );
179 if (aEntryText == aCurLang)
184 rLangTable[ nItemId ] = aEntryText;
199 uno::Reference< linguistic2::XSpellAlternatives > xAlt,
200 const OUString &rParaText)
201 : m_aBuilder(nullptr,
AllSettings::GetUIRootDir(),
"modules/swriter/ui/spellmenu.ui",
"")
202 , m_xPopupMenu(m_aBuilder.get_menu(
u"menu"))
203 , m_nIgnoreWordId(m_xPopupMenu->GetItemId(
u"ignoreall"))
204 , m_nAddMenuId(m_xPopupMenu->GetItemId(
u"addmenu"))
205 , m_nAddId(m_xPopupMenu->GetItemId(
u"add"))
206 , m_nSpellDialogId(m_xPopupMenu->GetItemId(
u"spelldialog"))
207 , m_nCorrectMenuId(m_xPopupMenu->GetItemId(
u"correctmenu"))
208 , m_nCorrectDialogId(m_xPopupMenu->GetItemId(
u"correctdialog"))
209 , m_nLangSelectionMenuId(m_xPopupMenu->GetItemId(
u"langselection"))
210 , m_nLangParaMenuId(m_xPopupMenu->GetItemId(
u"langpara"))
211 , m_nRedlineAcceptId(m_xPopupMenu->GetItemId(
u"accept"))
212 , m_nRedlineRejectId(m_xPopupMenu->GetItemId(
u"reject"))
213 , m_nRedlineNextId(m_xPopupMenu->GetItemId(
u"next"))
214 , m_nRedlinePrevId(m_xPopupMenu->GetItemId(
u"prev"))
216 , m_xSpellAlt(
std::move(xAlt))
217 , m_bGrammarResults(false)
219 OSL_ENSURE(
m_xSpellAlt.is(),
"no spelling alternatives available");
225 css::uno::Sequence< OUString > aSuggestions;
231 sal_Int16 nStringCount =
static_cast< sal_Int16
>( aSuggestions.getLength() );
237 bool bEnable =
false;
241 OUString aSuggestionImageUrl;
243 if (bUseImagesInMenus)
245 uno::Reference< container::XNamed > xNamed(
m_xSpellAlt, uno::UNO_QUERY );
249 aImage =
Image( aSuggestionImageUrl );
257 for (sal_uInt16 i = 0;
i < nStringCount; ++
i)
259 const OUString aEntry = aSuggestions[
i ];
260 m_xPopupMenu->InsertItem(nItemId, aEntry, MenuItemBits::NONE, {},
i);
262 if (!aSuggestionImageUrl.isEmpty())
288 OUString aIgnoreSelection(
SwResId( STR_IGNORE_SELECTION ) );
294 uno::Reference< linguistic2::XLanguageGuessing > xLG =
SW_MOD()->GetLanguageGuesser();
302 if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
305 if (nGuessLangWord == LANGUAGE_NONE)
306 nGuessLangWord = nGuessLangPara;
307 if (nGuessLangPara == LANGUAGE_NONE)
308 nGuessLangPara = nGuessLangWord;
322 xDic->setActive(
true );
324 m_aDics = xDicList->getDictionaries();
326 for(
const uno::Reference< linguistic2::XDictionary >& rDic : std::as_const(
m_aDics) )
328 uno::Reference< linguistic2::XDictionary > xDicTmp = rDic;
332 uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
334 if( xDicTmp->isActive()
335 && xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
337 && (!xStor.is() || !xStor->isReadonly()) )
341 pMenu->
InsertItem( nItemId, xDicTmp->getName() );
344 if (bUseImagesInMenus)
346 uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
350 xSvcInfo->getImplementationName() ) );
351 if (!aDictionaryImageUrl.isEmpty())
353 Image aImage( aDictionaryImageUrl );
368 OUString aScriptTypesInUse( OUString::number(
static_cast<int>(pWrtSh->
GetScriptType()) ) );
371 OUString aKeyboardLang;
374 if (
nLang != LANGUAGE_DONTKNOW &&
nLang != LANGUAGE_SYSTEM)
378 OUString aCurrentLang(
"*");
380 if (
nLang != LANGUAGE_DONTKNOW)
384 uno::Sequence< OUString >
aSeq{ aCurrentLang,
397 if (bUseImagesInMenus)
409 const linguistic2::ProofreadingResult &rResult,
410 sal_Int32 nErrorInResult,
411 const uno::Sequence< OUString > &rSuggestions,
412 const OUString &rParaText )
413 : m_aBuilder(nullptr,
AllSettings::GetUIRootDir(),
"modules/swriter/ui/spellmenu.ui",
"")
414 , m_xPopupMenu(m_aBuilder.get_menu(
u"menu"))
415 , m_nIgnoreWordId(m_xPopupMenu->GetItemId(
u"ignoreall"))
416 , m_nAddMenuId(m_xPopupMenu->GetItemId(
u"addmenu"))
417 , m_nAddId(m_xPopupMenu->GetItemId(
u"add"))
418 , m_nSpellDialogId(m_xPopupMenu->GetItemId(
u"spelldialog"))
419 , m_nCorrectMenuId(m_xPopupMenu->GetItemId(
u"correctmenu"))
420 , m_nCorrectDialogId(m_xPopupMenu->GetItemId(
u"correctdialog"))
421 , m_nLangSelectionMenuId(m_xPopupMenu->GetItemId(
u"langselection"))
422 , m_nLangParaMenuId(m_xPopupMenu->GetItemId(
u"langpara"))
423 , m_nRedlineAcceptId(m_xPopupMenu->GetItemId(
u"accept"))
424 , m_nRedlineRejectId(m_xPopupMenu->GetItemId(
u"reject"))
425 , m_nRedlineNextId(m_xPopupMenu->GetItemId(
u"next"))
426 , m_nRedlinePrevId(m_xPopupMenu->GetItemId(
u"prev"))
428 , m_bGrammarResults(true)
434 OUString aMessageText( rResult.aErrors[ nErrorInResult ].aShortComment );
437 if (bUseImagesInMenus)
441 const beans::PropertyValues
aProperties = rResult.aErrors[ nErrorInResult ].aProperties;
442 for (
const auto& rProp : aProperties )
444 if ( rProp.Name ==
"FullCommentURL" )
462 if ( rSuggestions.hasElements() )
465 OUString aSuggestionImageUrl;
467 if (bUseImagesInMenus)
469 uno::Reference< lang::XServiceInfo > xInfo( rResult.xProofreader, uno::UNO_QUERY );
473 aImage =
Image( aSuggestionImageUrl );
478 for (
const OUString& aEntry : std::as_const(rSuggestions))
482 if (!aSuggestionImageUrl.isEmpty())
493 OUString aIgnoreSelection(
SwResId( STR_IGNORE_SELECTION ) );
504 uno::Reference< linguistic2::XLanguageGuessing > xLG =
SW_MOD()->GetLanguageGuesser();
511 if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
514 if (nGuessLangWord == LANGUAGE_NONE)
515 nGuessLangWord = nGuessLangPara;
516 if (nGuessLangPara == LANGUAGE_NONE)
517 nGuessLangPara = nGuessLangWord;
525 OUString aScriptTypesInUse( OUString::number(
static_cast<int>(pWrtSh->
GetScriptType()) ) );
528 OUString aKeyboardLang;
531 if (
nLang != LANGUAGE_DONTKNOW &&
nLang != LANGUAGE_SYSTEM)
535 OUString aCurrentLang(
"*");
537 if (
nLang != LANGUAGE_DONTKNOW)
541 uno::Sequence< OUString >
aSeq{ aCurrentLang,
554 if (bUseImagesInMenus)
585 for(
int i = 0;
i < aSuggestions.getLength(); ++
i)
588 OUString sCommandString =
".uno:SpellCheckApplySuggestion?ApplyRule:string=";
590 sCommandString +=
"Grammar_";
592 sCommandString +=
"Spelling_";
603 OUString sCommandString =
".uno:LanguageStatus?Language:string=Current_" + item.second;
618 OUString sCommandString =
".uno:LanguageStatus?Language:string=Paragraph_" + item.second;
635 static const sal_uInt16 pRedlineIds[] = {
643 for (sal_uInt16 nWhich : pRedlineIds)
651 for (sal_uInt16 nWhich : pRedlineIds)
674 if (
nId == USHRT_MAX)
682 OUString sApplyRule(
"");
684 sApplyRule +=
"Grammar_";
686 sApplyRule +=
"Spelling_";
706 if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
707 aOrig.endsWith(
".") &&
718 OUString aTmpStr =
SwResId(STR_START_QUOTE) +
784 uno::Reference< linguistic2::XDictionary > xDic;
787 xDic = xDicList->getDictionaryByName( aDicName );
793 uno::Reference< frame::XStorable > xSavDic( xDic, uno::UNO_QUERY );
807 uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute(
808 css::system::SystemShellExecute::create( ::comphelper::getProcessComponentContext() ) );
810 css::system::SystemShellExecuteFlags::URIS_ONLY );
812 catch (
const uno::Exception&)
814 uno::Any exc( ::cppu::getCaughtException() );
815 OUString msg( ::comphelper::anyToString( exc ) );
818 VclMessageType::Warning, VclButtonsType::Ok, msg));
819 xBox->set_title(
"Explanations");
847 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Current_LANGUAGE_NONE");
852 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Current_RESET_LANGUAGES");
867 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Paragraph_LANGUAGE_NONE");
872 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Paragraph_RESET_LANGUAGES");
PropertiesInfo aProperties
const LanguageTag & GetLanguageTag() const
const LanguageTag & GetUILanguageTag() const
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static LanguageType CheckLanguage(const OUString &rText, const css::uno::Reference< css::linguistic2::XSpellChecker1 > &xSpell, const css::uno::Reference< css::linguistic2::XLanguageGuessing > &xLangGuess, bool bIsParaText)
LanguageType getLanguageType(bool bResolveSystem=true) const
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
static css::uno::Reference< css::linguistic2::XSearchableDictionaryList > GetDictionaryList()
static css::uno::Reference< css::linguistic2::XDictionary > GetIgnoreAllList()
static css::uno::Reference< css::linguistic2::XDictionary > GetStandardDic()
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SfxDispatcher * GetDispatcher()
SfxFrame & GetFrame() const
weld::Window * GetFrameWeld() const
SfxViewFrame & GetViewFrame() const
bool GetUseImagesInMenus() const
static OUString GetLanguageString(const LanguageType eType)
static LanguageType GetLanguageType(std::u16string_view rStr)
OUString GetSpellAndGrammarContextSuggestionImage(const OUString &rServiceImplName) const
bool SetProperty(std::u16string_view rPropertyName, const css::uno::Any &rValue)
OUString GetSpellAndGrammarContextDictionaryImage(const OUString &rServiceImplName) const
SvxAutoCorrect * GetAutoCorrect()
static SvxAutoCorrCfg & Get()
bool PutText(const OUString &rShort, const OUString &rLong, LanguageType eLang)
OUString GetCursorDescr() const
Returns textual description of the current selection.
void EndAction(const bool bIdleEnd=false)
const SwAttrPool & GetAttrPool() const
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
SvtScriptType GetScriptType() const
returns the script type of the selection
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
bool Replace(const OUString &rNewStr, bool bRegExpRplc)
Replace a selected range in a TextNode by given string.
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
void AddRule(SwUndoArg eWhat, const OUString &rWith)
void GetState(SfxItemSet &)
void Execute(SfxRequest &)
Used by the UI to modify the document model.
bool Left(SwCursorSkipMode nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
void SetInsMode(bool bOn=true)
const SwView & GetView() const
Point LogicToPixel(const Point &rLogicPt) const
LanguageType GetInputLanguage() const
#define FN_REDLINE_ACCEPT_DIRECT
#define FN_REDLINE_REJECT_DIRECT
#define FN_REDLINE_NEXT_CHANGE
#define FN_REDLINE_PREV_CHANGE
#define FN_SPELL_GRAMMAR_DIALOG
constexpr OUStringLiteral HID_LINGU_REPLACE
constexpr OUStringLiteral HID_LINGU_AUTOCORR
constexpr OUStringLiteral HID_LINGU_IGNORE_SELECTION
#define LANGUAGE_DONTKNOW
Sequence< sal_Int8 > aSeq
SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
LanguageType GetCurrentLanguage(SfxItemSet const &aSet, SvtScriptType nScriptType)
DictionaryError AddEntryToDic(uno::Reference< XDictionary > const &rxDic, const OUString &rWord, bool bIsNeg, const OUString &rRplcTxt, bool bStripDot)
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
OUString GetPopupLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
void SvxPrepareAutoCorrect(OUString &rOldText, std::u16string_view rNewText)
static LanguageType nLang
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel
OUString SwResId(TranslateId aId)
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
short SvxDicError(weld::Window *pParent, linguistic::DictionaryError nError)