/* -*- 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 .
*/
/// @returns : the language for the selected text that is set for the /// specified attribute (script type). /// If there are more than one languages used LANGUAGE_DONTKNOW will be returned. /// @param nLangWhichId : one of /// RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE, /// @returns: the language in use for the selected text. /// 'In use' means the language(s) matching the script type(s) of the /// selected text. Or in other words, the language a spell checker would use. /// If there is more than one language LANGUAGE_DONTKNOW will be returned. // check if nScriptType includes the script type associated to nLang staticbool lcl_checkScriptType( SvtScriptType nScriptType, LanguageType nLang )
{ returnbool(nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
}
//3--UI
LanguageType rUILanguage = rAllSettings.GetUILanguageTag().getLanguageType(); if (rUILanguage != LANGUAGE_DONTKNOW)
{ if (lcl_checkScriptType(nScriptType, rUILanguage ))
aLangItems.insert( SvtLanguageTable::GetLanguageString(rUILanguage) );
}
//4--guessed language if (!aGuessedTextLang.isEmpty())
{ if (lcl_checkScriptType(nScriptType, SvtLanguageTable::GetLanguageType(aGuessedTextLang)))
aLangItems.insert( aGuessedTextLang );
}
//5--keyboard language if (!aKeyboardLang.isEmpty())
{ if (lcl_checkScriptType(nScriptType, SvtLanguageTable::GetLanguageType(aKeyboardLang)))
aLangItems.insert( aKeyboardLang );
}
//6--all languages used in current document
uno::Reference< css::frame::XModel > xModel;
uno::Reference< css::frame::XController > xController = pWrtSh->GetView().GetViewFrame().GetFrame().GetFrameInterface()->getController(); if ( xController.is() )
xModel = xController->getModel();
uno::Reference< document::XDocumentLanguages > xDocumentLanguages( xModel, uno::UNO_QUERY ); /*the description of nScriptType flags LATIN : 0x0001 ASIAN : 0x0002 COMPLEX: 0x0004
*/ const sal_Int16 nMaxCount = 7; if (xDocumentLanguages.is())
{ const uno::Sequence< lang::Locale > rLocales( xDocumentLanguages->getDocumentLanguages( static_cast<sal_Int16>(nScriptType), nMaxCount ) ); for (const lang::Locale& rLocale : rLocales)
{ if (aLangItems.size() == size_t(nMaxCount)) break; if (lcl_checkScriptType( nScriptType, SvtLanguageTable::GetLanguageType( rLocale.Language )))
aLangItems.insert( rLocale.Language );
}
}
sal_uInt16 nItemId = nLangItemIdStart; for (const OUString& aEntryText : aLangItems)
{ if (aEntryText != SvtLanguageTable::GetLanguageString( LANGUAGE_NONE ) &&
aEntryText != "*" && // multiple languages in current selection
!aEntryText.isEmpty()) // 'no language found' from language guessing
{
OSL_ENSURE( nLangItemIdStart <= nItemId && nItemId <= nLangItemIdStart + MN_MAX_NUM_LANG, "nItemId outside of expected range!" );
pPopupMenu->InsertItem( nItemId, aEntryText, MenuItemBits::RADIOCHECK ); if (aEntryText == aCurLang)
{ //make a check mark for the current language
pPopupMenu->CheckItem( nItemId );
}
rLangTable[ nItemId ] = aEntryText;
++nItemId;
}
}
uno::Reference<linguistic2::XLanguageGuessing> xLG = SwModule::get()->GetLanguageGuesser();
LanguageType nGuessLangWord = LANGUAGE_NONE;
LanguageType nGuessLangPara = LANGUAGE_NONE; if (m_xSpellAlt.is() && xLG.is())
{
nGuessLangWord = EditView::CheckLanguage( m_xSpellAlt->getWord(), ::GetSpellChecker(), xLG, false );
nGuessLangPara = EditView::CheckLanguage( rParaText, ::GetSpellChecker(), xLG, true );
} if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
{ // make sure LANGUAGE_NONE gets not used as menu entry if (nGuessLangWord == LANGUAGE_NONE)
nGuessLangWord = nGuessLangPara; if (nGuessLangPara == LANGUAGE_NONE)
nGuessLangPara = nGuessLangWord;
}
pMenu = m_xPopupMenu->GetPopupMenu(m_nAddMenuId);
pMenu->SetMenuFlags(MenuFlags::NoAutoMnemonics); //! necessary to retrieve the correct dictionary name in 'Execute' below
uno::Reference< linguistic2::XSearchableDictionaryList > xDicList( LinguMgr::GetDictionaryList() );
sal_uInt16 nItemId = MN_DICTIONARIES_START; if (xDicList.is())
{ // add the default positive dictionary to dic-list (if not already done). // This is to ensure that there is at least one dictionary to which // words could be added.
uno::Reference< linguistic2::XDictionary > xDic( LinguMgr::GetStandardDic() ); if (xDic.is())
xDic->setActive(!comphelper::LibreOfficeKit::isActive());
m_aDics = xDicList->getDictionaries();
for (const uno::Reference<linguistic2::XDictionary>& rDic : m_aDics)
{
uno::Reference< linguistic2::XDictionary > xDicTmp = rDic; if (!xDicTmp.is() || LinguMgr::GetIgnoreAllList() == xDicTmp) continue;
uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType(); if( xDicTmp->isActive()
&& xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
&& (m_nCheckedLanguage == nActLanguage || LANGUAGE_NONE == nActLanguage )
&& (!xStor.is() || !xStor->isReadonly()) )
{ // the extra 1 is because of the (possible) external // linguistic entry above
pMenu->InsertItem( nItemId, xDicTmp->getName() );
m_aDicNameSingle = xDicTmp->getName();
// get keyboard language
OUString aKeyboardLang;
SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
LanguageType nLang = rEditWin.GetInputLanguage(); if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
aKeyboardLang = SvtLanguageTable::GetLanguageString( nLang );
// get the language that is in use
OUString aCurrentLang(u"*"_ustr);
nLang = SwLangHelper::GetCurrentLanguage( *pWrtSh ); if (nLang != LANGUAGE_DONTKNOW)
aCurrentLang = SvtLanguageTable::GetLanguageString( nLang );
// build sequence for status value
uno::Sequence< OUString > aSeq{ aCurrentLang,
aScriptTypesInUse,
aKeyboardLang,
SvtLanguageTable::GetLanguageString(nGuessLangWord) };
if (bUseImagesInMenus)
m_xPopupMenu->SetItemImage(m_nSpellDialogId,
vcl::CommandInfoProvider::GetImageForCommand(u".uno:SpellingAndGrammarDialog"_ustr, xFrame));
// Add an item to show detailed infos if the FullCommentURL property is defined const beans::PropertyValues aProperties = rResult.aErrors[ nErrorInResult ].aProperties; for ( constauto& rProp : aProperties )
{ if ( rProp.Name == "FullCommentURL" )
{
uno::Any aValue = rProp.Value;
aValue >>= m_sExplanationLink;
// get keyboard language
OUString aKeyboardLang;
SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
LanguageType nLang = rEditWin.GetInputLanguage(); if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
aKeyboardLang = SvtLanguageTable::GetLanguageString( nLang );
// get the language that is in use
OUString aCurrentLang(u"*"_ustr);
nLang = SwLangHelper::GetCurrentLanguage( *pWrtSh ); if (nLang != LANGUAGE_DONTKNOW)
aCurrentLang = SvtLanguageTable::GetLanguageString( nLang );
// build sequence for status value
uno::Sequence< OUString > aSeq{ aCurrentLang,
aScriptTypesInUse,
aKeyboardLang,
SvtLanguageTable::GetLanguageString(nGuessLangWord) };
if (bUseImagesInMenus)
m_xPopupMenu->SetItemImage(m_nSpellDialogId,
vcl::CommandInfoProvider::GetImageForCommand(u".uno:SpellingAndGrammarDialog"_ustr, xFrame));
void SwSpellPopup::InitItemCommands(const css::uno::Sequence< OUString >& aSuggestions)
{ if (!comphelper::LibreOfficeKit::isActive()) return;
// None is added only for LOK, it means there is no need to execute anything
m_xPopupMenu->SetItemCommand(MN_SHORT_COMMENT, u".uno:None"_ustr);
m_xPopupMenu->SetItemCommand(m_nSpellDialogId, u".uno:SpellingAndGrammarDialog"_ustr); if(m_bGrammarResults)
m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, u".uno:SpellCheckIgnoreAll?Type:string=Grammar"_ustr); else
m_xPopupMenu->SetItemCommand(m_nIgnoreWordId, u".uno:SpellCheckIgnoreAll?Type:string=Spelling"_ustr); if(m_bGrammarResults)
m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, u".uno:SpellCheckIgnore?Type:string=Grammar"_ustr); else
m_xPopupMenu->SetItemCommand(MN_IGNORE_SELECTION, u".uno:SpellCheckIgnore?Type:string=Spelling"_ustr);
void SwSpellPopup::checkRedline()
{ // Let SwView::GetState() already has the logic on when to disable the // accept/reject and the next/prev change items, let it do the decision.
// Build an item set that contains a void item for each menu entry. The // WhichId of each item is set, so SwView may clear it. staticconst sal_uInt16 pRedlineIds[] = {
FN_REDLINE_ACCEPT_DIRECT,
FN_REDLINE_REJECT_DIRECT,
FN_REDLINE_NEXT_CHANGE,
FN_REDLINE_PREV_CHANGE
};
SwDoc *pDoc = m_pSh->GetDoc();
SfxItemSetFixed<FN_REDLINE_ACCEPT_DIRECT, FN_REDLINE_PREV_CHANGE> aSet(pDoc->GetAttrPool()); for (sal_uInt16 nWhich : pRedlineIds)
{
aSet.Put(SfxVoidItem(nWhich));
}
m_pSh->GetView().GetState(aSet);
// Enable/disable items based on if the which id of the void items are // cleared or not. for (sal_uInt16 nWhich : pRedlineIds)
{
sal_uInt16 nId(0); if (nWhich == FN_REDLINE_ACCEPT_DIRECT)
nId = m_nRedlineAcceptId; elseif (nWhich == FN_REDLINE_REJECT_DIRECT)
nId = m_nRedlineRejectId; elseif (nWhich == FN_REDLINE_NEXT_CHANGE)
nId = m_nRedlineNextId; elseif (nWhich == FN_REDLINE_PREV_CHANGE)
nId = m_nRedlinePrevId;
m_xPopupMenu->EnableItem(nId, aSet.Get(nWhich).Which() != 0);
}
}
// if original word has a trailing . (likely the end of a sentence) // and the replacement text hasn't, then add it to the replacement if (!aTmp.isEmpty() && !aOrig.isEmpty() &&
aOrig.endsWith(".") && /* !IsAlphaNumeric ??*/
!aTmp.endsWith("."))
{
aTmp += ".";
}
/* #102505# EndAction/EndUndo moved down since insertion of temporary auto correction is now undoable two and
must reside in the same undo group.*/
m_pSh->EndAction();
m_pSh->EndUndo();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.