22 #include <strings.hrc>
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;
147 if ( xController.is() )
148 xModel = xController->getModel();
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 ];
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( 4 );
384 aSeq[0] = aCurrentLang;
385 aSeq[1] = aScriptTypesInUse;
386 aSeq[2] = aKeyboardLang;
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(
"menu"))
415 , m_nIgnoreWordId(m_xPopupMenu->GetItemId(
"ignoreall"))
416 , m_nAddMenuId(m_xPopupMenu->GetItemId(
"addmenu"))
417 , m_nAddId(m_xPopupMenu->GetItemId(
"add"))
418 , m_nSpellDialogId(m_xPopupMenu->GetItemId(
"spelldialog"))
419 , m_nCorrectMenuId(m_xPopupMenu->GetItemId(
"correctmenu"))
420 , m_nCorrectDialogId(m_xPopupMenu->GetItemId(
"correctdialog"))
421 , m_nLangSelectionMenuId(m_xPopupMenu->GetItemId(
"langselection"))
422 , m_nLangParaMenuId(m_xPopupMenu->GetItemId(
"langpara"))
423 , m_nRedlineAcceptId(m_xPopupMenu->GetItemId(
"accept"))
424 , m_nRedlineRejectId(m_xPopupMenu->GetItemId(
"reject"))
425 , m_nRedlineNextId(m_xPopupMenu->GetItemId(
"next"))
426 , m_nRedlinePrevId(m_xPopupMenu->GetItemId(
"prev"))
428 , m_sExplanationLink()
429 , m_bGrammarResults(true)
435 OUString aMessageText( rResult.aErrors[ nErrorInResult ].aShortComment );
438 if (bUseImagesInMenus)
442 const beans::PropertyValues
aProperties = rResult.aErrors[ nErrorInResult ].aProperties;
443 for (
const auto& rProp : aProperties )
445 if ( rProp.Name ==
"FullCommentURL" )
463 if ( rSuggestions.hasElements() )
466 OUString aSuggestionImageUrl;
468 if (bUseImagesInMenus)
470 uno::Reference< lang::XServiceInfo > xInfo( rResult.xProofreader, uno::UNO_QUERY );
474 aImage =
Image( aSuggestionImageUrl );
479 for (
const OUString& aEntry : std::as_const(rSuggestions))
483 if (!aSuggestionImageUrl.isEmpty())
494 OUString aIgnoreSelection(
SwResId( STR_IGNORE_SELECTION ) );
505 uno::Reference< linguistic2::XLanguageGuessing > xLG =
SW_MOD()->GetLanguageGuesser();
512 if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
515 if (nGuessLangWord == LANGUAGE_NONE)
516 nGuessLangWord = nGuessLangPara;
517 if (nGuessLangPara == LANGUAGE_NONE)
518 nGuessLangPara = nGuessLangWord;
526 OUString aScriptTypesInUse( OUString::number( static_cast<int>(pWrtSh->
GetScriptType()) ) );
529 OUString aKeyboardLang;
532 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
536 OUString aCurrentLang(
"*");
538 if (nLang != LANGUAGE_DONTKNOW)
542 uno::Sequence< OUString >
aSeq( 4 );
543 aSeq[0] = aCurrentLang;
544 aSeq[1] = aScriptTypesInUse;
545 aSeq[2] = aKeyboardLang;
556 if (bUseImagesInMenus)
587 for(
int i = 0;
i < aSuggestions.getLength(); ++
i)
590 OUString sCommandString =
".uno:SpellCheckApplySuggestion?ApplyRule:string=";
592 sCommandString +=
"Grammar_";
594 sCommandString +=
"Spelling_";
605 OUString sCommandString =
".uno:LanguageStatus?Language:string=Current_" + item.second;
620 OUString sCommandString =
".uno:LanguageStatus?Language:string=Paragraph_" + item.second;
637 static const sal_uInt16 pRedlineIds[] = {
645 for (sal_uInt16 nWhich : pRedlineIds)
653 for (sal_uInt16 nWhich : pRedlineIds)
684 OUString sApplyRule(
"");
686 sApplyRule +=
"Grammar_";
688 sApplyRule +=
"Spelling_";
708 if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
709 aOrig.endsWith(
".") &&
720 OUString aTmpStr =
SwResId(STR_START_QUOTE) +
740 pACorr->
PutText( aOrigWord, aNewWord, m_nCheckedLanguage );
786 uno::Reference< linguistic2::XDictionary > xDic;
789 xDic = xDicList->getDictionaryByName( aDicName );
795 uno::Reference< frame::XStorable > xSavDic( xDic, uno::UNO_QUERY );
809 uno::Reference< css::system::XSystemShellExecute > xSystemShellExecute(
812 css::system::SystemShellExecuteFlags::URIS_ONLY );
814 catch (
const uno::Exception&)
820 VclMessageType::Warning, VclButtonsType::Ok, msg));
821 xBox->set_title(
"Explanations");
849 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Current_LANGUAGE_NONE");
854 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Current_RESET_LANGUAGES");
869 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Paragraph_LANGUAGE_NONE");
874 SfxStringItem aLangString(SID_LANGUAGE_STATUS,
"Paragraph_RESET_LANGUAGES");
SfxViewFrame * GetViewFrame() const
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 * >())
static SvxAutoCorrCfg & Get()
const LanguageTag & GetUILanguageTag() const
#define HID_LINGU_AUTOCORR
LanguageType getLanguageType(bool bResolveSystem=true) const
SfxDispatcher * GetDispatcher()
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
Reference< XFrame > xFrame
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
static css::uno::Reference< css::linguistic2::XDictionary > GetStandardDic()
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
#define HID_LINGU_IGNORE_SELECTION
OUString GetCursorDescr() const
Returns textual description of the current selection.
static LanguageType nLang
Used by the UI to modify the document model.
const SwView & GetView() const
Reference< XController > xController
PropertiesInfo aProperties
Any SAL_CALL getCaughtException()
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static LanguageType GetLanguageType(std::u16string_view rStr)
SfxFrame & GetFrame() const
static css::uno::Reference< css::linguistic2::XSearchableDictionaryList > GetDictionaryList()
OUString GetSpellAndGrammarContextDictionaryImage(const OUString &rServiceImplName) const
static SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
static css::uno::Reference< css::linguistic2::XDictionary > GetIgnoreAllList()
const LanguageTag & GetLanguageTag() const
OUString GetPopupLabelForCommand(const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
short SvxDicError(weld::Window *pParent, linguistic::DictionaryError nError)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
#define FN_REDLINE_ACCEPT_DIRECT
SvtScriptType GetScriptType() const
returns the script type of the selection
OUString GetModuleIdentifier(const Reference< frame::XFrame > &rxFrame)
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
SvxAutoCorrect * GetAutoCorrect()
#define FN_REDLINE_PREV_CHANGE
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
void AddRule(SwUndoArg eWhat, const OUString &rWith)
#define LANGUAGE_DONTKNOW
void SvxPrepareAutoCorrect(OUString &rOldText, const OUString &rNewText)
OUString SwResId(const char *pId)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
Point LogicToPixel(const Point &rLogicPt) const
OUString GetSpellAndGrammarContextSuggestionImage(const OUString &rServiceImplName) const
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
Sequence< beans::PropertyValue > GetCommandProperties(const OUString &rsCommandName, const OUString &rsModuleName)
void SetInsMode(bool bOn=true)
bool PutText(const OUString &rShort, const OUString &rLong, LanguageType eLang)
#define FN_SPELL_GRAMMAR_DIALOG
weld::Window * GetFrameWeld() const
bool Left(sal_uInt16 nMode, bool bSelect, sal_uInt16 nCount, bool bBasicCall, bool bVisual=false)
bool GetUseImagesInMenus() const
DictionaryError AddEntryToDic(uno::Reference< XDictionary > const &rxDic, const OUString &rWord, bool bIsNeg, const OUString &rRplcTxt, bool bStripDot)
const o3tl::enumarray< SvxAdjust, unsigned short > aSvxToUnoAdjust USHRT_MAX
#define FN_REDLINE_NEXT_CHANGE
#define HID_LINGU_REPLACE
bool SetProperty(const OUString &rPropertyName, const css::uno::Any &rValue)
void Execute(SfxRequest &)
Reference< XComponentContext > getProcessComponentContext()
Sequence< sal_Int8 > aSeq
LanguageType GetCurrentLanguage(SfxItemSet const &aSet, SvtScriptType nScriptType)
static LanguageType CheckLanguage(const OUString &rText, const css::uno::Reference< css::linguistic2::XSpellChecker1 > &xSpell, const css::uno::Reference< css::linguistic2::XLanguageGuessing > &xLangGuess, bool bIsParaText)
static OUString GetLanguageString(const LanguageType eType)
const sal_uInt16 CRSR_SKIP_CHARS
Reference< XModel > xModel
const SfxPoolItem * Execute(sal_uInt16 nSlot, SfxCallMode nCall=SfxCallMode::SLOT, const SfxPoolItem **pArgs=nullptr, sal_uInt16 nModi=0, const SfxPoolItem **pInternalArgs=nullptr)
LanguageType GetInputLanguage() const
#define FN_REDLINE_REJECT_DIRECT
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
const SwAttrPool & GetAttrPool() const
bool Replace(const OUString &rNewStr, bool bRegExpRplc)
Replace a selected range in a TextNode by given string.
OUString anyToString(uno::Any const &value)
void EndAction(const bool bIdleEnd=false)
void GetState(SfxItemSet &)