27#include <bitmaps.hlst>
46#include <rtl/string.hxx>
60#include <osl/diagnose.h>
64#include <com/sun/star/document/XDocumentLanguages.hpp>
65#include <com/sun/star/frame/XFrame.hpp>
66#include <com/sun/star/frame/XStorable.hpp>
67#include <com/sun/star/lang/XServiceInfo.hpp>
68#include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
69#include <com/sun/star/uno/Any.hxx>
70#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
71#include <com/sun/star/system/SystemShellExecute.hpp>
72#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
93 sal_uInt16 nLangItemIdStart,
94 const uno::Sequence< OUString >& aSeq,
96 std::map< sal_Int16, OUString > &rLangTable )
102 std::set< OUString > aLangItems;
104 OUString aCurLang(
aSeq[0] );
106 OUString aKeyboardLang(
aSeq[2] );
107 OUString aGuessedTextLang(
aSeq[3] );
109 if (!aCurLang.isEmpty() &&
111 aLangItems.insert( aCurLang );
131 if (!aGuessedTextLang.isEmpty())
134 aLangItems.insert( aGuessedTextLang );
138 if (!aKeyboardLang.isEmpty())
141 aLangItems.insert( aKeyboardLang );
145 uno::Reference< css::frame::XModel >
xModel;
149 uno::Reference< document::XDocumentLanguages > xDocumentLanguages(
xModel, uno::UNO_QUERY );
155 const sal_Int16 nMaxCount = 7;
156 if (xDocumentLanguages.is())
158 const uno::Sequence< lang::Locale > rLocales( xDocumentLanguages->getDocumentLanguages(
static_cast<sal_Int16
>(nScriptType), nMaxCount ) );
159 for (
const lang::Locale& rLocale : rLocales)
161 if (aLangItems.size() ==
size_t(nMaxCount))
164 aLangItems.insert( rLocale.Language );
168 sal_uInt16 nItemId = nLangItemIdStart;
169 for (
const OUString& aEntryText : aLangItems)
173 !aEntryText.isEmpty())
175 OSL_ENSURE( nLangItemIdStart <= nItemId && nItemId <= nLangItemIdStart +
MN_MAX_NUM_LANG,
176 "nItemId outside of expected range!" );
177 pPopupMenu->
InsertItem( nItemId, aEntryText, MenuItemBits::RADIOCHECK );
178 if (aEntryText == aCurLang)
183 rLangTable[ nItemId ] = aEntryText;
198 const uno::Reference< linguistic2::XSpellAlternatives > &xAlt,
199 const OUString &rParaText)
200 : m_aBuilder(nullptr,
AllSettings::GetUIRootDir(),
"modules/swriter/ui/spellmenu.ui",
"")
201 , m_xPopupMenu(m_aBuilder.get_menu(
"menu"))
202 , m_nIgnoreWordId(m_xPopupMenu->GetItemId(
"ignoreall"))
203 , m_nAddMenuId(m_xPopupMenu->GetItemId(
"addmenu"))
204 , m_nAddId(m_xPopupMenu->GetItemId(
"add"))
205 , m_nSpellDialogId(m_xPopupMenu->GetItemId(
"spelldialog"))
206 , m_nCorrectMenuId(m_xPopupMenu->GetItemId(
"correctmenu"))
207 , m_nCorrectDialogId(m_xPopupMenu->GetItemId(
"correctdialog"))
208 , m_nLangSelectionMenuId(m_xPopupMenu->GetItemId(
"langselection"))
209 , m_nLangParaMenuId(m_xPopupMenu->GetItemId(
"langpara"))
210 , m_nRedlineAcceptId(m_xPopupMenu->GetItemId(
"accept"))
211 , m_nRedlineRejectId(m_xPopupMenu->GetItemId(
"reject"))
212 , m_nRedlineNextId(m_xPopupMenu->GetItemId(
"next"))
213 , m_nRedlinePrevId(m_xPopupMenu->GetItemId(
"prev"))
216 , m_bGrammarResults(false)
218 OSL_ENSURE(
m_xSpellAlt.is(),
"no spelling alternatives available");
224 css::uno::Sequence< OUString > aSuggestions;
230 sal_Int16 nStringCount =
static_cast< sal_Int16
>( aSuggestions.getLength() );
236 bool bEnable =
false;
240 OUString aSuggestionImageUrl;
242 if (bUseImagesInMenus)
244 uno::Reference< container::XNamed > xNamed(
m_xSpellAlt, uno::UNO_QUERY );
248 aImage =
Image( aSuggestionImageUrl );
256 for (sal_uInt16 i = 0;
i < nStringCount; ++
i)
258 const OUString aEntry = aSuggestions[
i ];
259 m_xPopupMenu->InsertItem(nItemId, aEntry, MenuItemBits::NONE, OString(), i);
261 if (!aSuggestionImageUrl.isEmpty())
287 OUString aIgnoreSelection(
SwResId( STR_IGNORE_SELECTION ) );
293 uno::Reference< linguistic2::XLanguageGuessing > xLG =
SW_MOD()->GetLanguageGuesser();
301 if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
304 if (nGuessLangWord == LANGUAGE_NONE)
305 nGuessLangWord = nGuessLangPara;
306 if (nGuessLangPara == LANGUAGE_NONE)
307 nGuessLangPara = nGuessLangWord;
321 xDic->setActive(
true );
323 m_aDics = xDicList->getDictionaries();
325 for(
const uno::Reference< linguistic2::XDictionary >& rDic : std::as_const(
m_aDics) )
327 uno::Reference< linguistic2::XDictionary > xDicTmp = rDic;
331 uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
333 if( xDicTmp->isActive()
334 && xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
336 && (!xStor.is() || !xStor->isReadonly()) )
340 pMenu->
InsertItem( nItemId, xDicTmp->getName() );
343 if (bUseImagesInMenus)
345 uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
349 xSvcInfo->getImplementationName() ) );
350 if (!aDictionaryImageUrl.isEmpty())
352 Image aImage( aDictionaryImageUrl );
367 OUString aScriptTypesInUse( OUString::number(
static_cast<int>(pWrtSh->
GetScriptType()) ) );
370 OUString aKeyboardLang;
373 if (
nLang != LANGUAGE_DONTKNOW &&
nLang != LANGUAGE_SYSTEM)
377 OUString aCurrentLang(
"*");
379 if (
nLang != LANGUAGE_DONTKNOW)
383 uno::Sequence< OUString >
aSeq{ aCurrentLang,
396 if (bUseImagesInMenus)
408 const linguistic2::ProofreadingResult &rResult,
409 sal_Int32 nErrorInResult,
410 const uno::Sequence< OUString > &rSuggestions,
411 const OUString &rParaText )
412 : m_aBuilder(nullptr,
AllSettings::GetUIRootDir(),
"modules/swriter/ui/spellmenu.ui",
"")
413 , m_xPopupMenu(m_aBuilder.get_menu(
"menu"))
414 , m_nIgnoreWordId(m_xPopupMenu->GetItemId(
"ignoreall"))
415 , m_nAddMenuId(m_xPopupMenu->GetItemId(
"addmenu"))
416 , m_nAddId(m_xPopupMenu->GetItemId(
"add"))
417 , m_nSpellDialogId(m_xPopupMenu->GetItemId(
"spelldialog"))
418 , m_nCorrectMenuId(m_xPopupMenu->GetItemId(
"correctmenu"))
419 , m_nCorrectDialogId(m_xPopupMenu->GetItemId(
"correctdialog"))
420 , m_nLangSelectionMenuId(m_xPopupMenu->GetItemId(
"langselection"))
421 , m_nLangParaMenuId(m_xPopupMenu->GetItemId(
"langpara"))
422 , m_nRedlineAcceptId(m_xPopupMenu->GetItemId(
"accept"))
423 , m_nRedlineRejectId(m_xPopupMenu->GetItemId(
"reject"))
424 , m_nRedlineNextId(m_xPopupMenu->GetItemId(
"next"))
425 , m_nRedlinePrevId(m_xPopupMenu->GetItemId(
"prev"))
427 , m_bGrammarResults(true)
433 OUString aMessageText( rResult.aErrors[ nErrorInResult ].aShortComment );
436 if (bUseImagesInMenus)
440 const beans::PropertyValues
aProperties = rResult.aErrors[ nErrorInResult ].aProperties;
441 for (
const auto& rProp : aProperties )
443 if ( rProp.Name ==
"FullCommentURL" )
461 if ( rSuggestions.hasElements() )
464 OUString aSuggestionImageUrl;
466 if (bUseImagesInMenus)
468 uno::Reference< lang::XServiceInfo > xInfo( rResult.xProofreader, uno::UNO_QUERY );
472 aImage =
Image( aSuggestionImageUrl );
477 for (
const OUString& aEntry : std::as_const(rSuggestions))
479 m_xPopupMenu->InsertItem(nItemId, aEntry, MenuItemBits::NONE, OString(), nPos++);
481 if (!aSuggestionImageUrl.isEmpty())
492 OUString aIgnoreSelection(
SwResId( STR_IGNORE_SELECTION ) );
503 uno::Reference< linguistic2::XLanguageGuessing > xLG =
SW_MOD()->GetLanguageGuesser();
510 if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
513 if (nGuessLangWord == LANGUAGE_NONE)
514 nGuessLangWord = nGuessLangPara;
515 if (nGuessLangPara == LANGUAGE_NONE)
516 nGuessLangPara = nGuessLangWord;
524 OUString aScriptTypesInUse( OUString::number(
static_cast<int>(pWrtSh->
GetScriptType()) ) );
527 OUString aKeyboardLang;
530 if (
nLang != LANGUAGE_DONTKNOW &&
nLang != LANGUAGE_SYSTEM)
534 OUString aCurrentLang(
"*");
536 if (
nLang != LANGUAGE_DONTKNOW)
540 uno::Sequence< OUString >
aSeq{ aCurrentLang,
553 if (bUseImagesInMenus)
584 for(
int i = 0;
i < aSuggestions.getLength(); ++
i)
587 OUString sCommandString =
".uno:SpellCheckApplySuggestion?ApplyRule:string=";
589 sCommandString +=
"Grammar_";
591 sCommandString +=
"Spelling_";
602 OUString sCommandString =
".uno:LanguageStatus?Language:string=Current_" + item.second;
617 OUString sCommandString =
".uno:LanguageStatus?Language:string=Paragraph_" + item.second;
634 static const sal_uInt16 pRedlineIds[] = {
642 for (sal_uInt16 nWhich : pRedlineIds)
650 for (sal_uInt16 nWhich : pRedlineIds)
673 if (
nId == USHRT_MAX)
681 OUString sApplyRule(
"");
683 sApplyRule +=
"Grammar_";
685 sApplyRule +=
"Spelling_";
705 if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
706 aOrig.endsWith(
".") &&
717 OUString aTmpStr =
SwResId(STR_START_QUOTE) +
783 uno::Reference< linguistic2::XDictionary > xDic;
786 xDic = xDicList->getDictionaryByName( aDicName );
792 uno::Reference< frame::XStorable > xSavDic( xDic, uno::UNO_QUERY );
806 uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute(
807 css::system::SystemShellExecute::create( ::comphelper::getProcessComponentContext() ) );
809 css::system::SystemShellExecuteFlags::URIS_ONLY );
811 catch (
const uno::Exception&)
813 uno::Any exc( ::cppu::getCaughtException() );
814 OUString msg( ::comphelper::anyToString( exc ) );
817 VclMessageType::Warning, VclButtonsType::Ok, msg));
818 xBox->set_title(
"Explanations");
846 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Current_LANGUAGE_NONE");
851 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Current_RESET_LANGUAGES");
866 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Paragraph_LANGUAGE_NONE");
871 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, bool bMobile=false)
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(sal_uInt16 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 OStringLiteral HID_LINGU_IGNORE_SELECTION
constexpr OStringLiteral HID_LINGU_REPLACE
constexpr OStringLiteral HID_LINGU_AUTOCORR
#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, const OUString &rNewText)
static LanguageType nLang
Reference< XController > xController
Reference< XFrame > xFrame
Reference< XModel > xModel
const sal_uInt16 CRSR_SKIP_CHARS
OUString SwResId(TranslateId aId)
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
short SvxDicError(weld::Window *pParent, linguistic::DictionaryError nError)