LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/lingu - olmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 467 0.2 %
Date: 2012-12-27 Functions: 2 11 18.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "SwRewriter.hxx"
      21             : #include "chrdlg.hrc"
      22             : #include "cmdid.h"
      23             : #include "comcore.hrc"
      24             : #include "crsskip.hxx"
      25             : #include "doc.hxx"
      26             : #include "docsh.hxx"        //CheckSpellChanges
      27             : #include "edtwin.hxx"
      28             : #include "helpid.h"
      29             : #include "hintids.hxx"
      30             : #include "langhelper.hxx"
      31             : #include "ndtxt.hxx"
      32             : #include "olmenu.hrc"
      33             : #include "olmenu.hxx"
      34             : #include "swabstdlg.hxx"
      35             : #include "swmodule.hxx"
      36             : #include "swtypes.hxx"
      37             : #include "swundo.hxx"
      38             : #include "uitool.hxx"
      39             : #include "unomid.h"
      40             : #include "view.hxx"
      41             : #include "viewopt.hxx"
      42             : #include "wrtsh.hxx"
      43             : #include "wview.hxx"
      44             : 
      45             : #include <comphelper/anytostring.hxx>
      46             : #include <comphelper/processfactory.hxx>
      47             : #include <cppuhelper/exc_hlp.hxx>
      48             : #include <editeng/acorrcfg.hxx>
      49             : #include <editeng/svxacorr.hxx>
      50             : #include <editeng/langitem.hxx>
      51             : #include <editeng/splwrap.hxx>
      52             : #include <editeng/brshitem.hxx>
      53             : #include <editeng/unolingu.hxx>
      54             : #include <i18npool/mslangid.hxx>
      55             : #include <i18npool/languagetag.hxx>
      56             : #include <linguistic/lngprops.hxx>
      57             : #include <linguistic/misc.hxx>
      58             : #include <osl/file.hxx>
      59             : #include <rtl/string.hxx>
      60             : #include <svtools/filter.hxx>
      61             : #include <sfx2/dispatch.hxx>
      62             : #include <sfx2/imagemgr.hxx>
      63             : #include <sfx2/request.hxx>
      64             : #include <sfx2/sfxdlg.hxx>
      65             : #include <svl/itemset.hxx>
      66             : #include <svl/languageoptions.hxx>
      67             : #include <svl/stritem.hxx>
      68             : #include <svtools/langtab.hxx>
      69             : #include <svx/dlgutil.hxx>
      70             : #include <unotools/lingucfg.hxx>
      71             : #include <unotools/linguprops.hxx>
      72             : #include <vcl/msgbox.hxx>
      73             : #include <vcl/settings.hxx>
      74             : #include <vcl/svapp.hxx>
      75             : #include <sal/macros.h>
      76             : 
      77             : #include <map>
      78             : 
      79             : #include <com/sun/star/container/XIndexAccess.hpp>
      80             : #include <com/sun/star/container/XNameAccess.hpp>
      81             : #include <com/sun/star/document/XDocumentLanguages.hpp>
      82             : #include <com/sun/star/frame/XModuleManager.hpp>
      83             : #include <com/sun/star/frame/XStorable.hpp>
      84             : #include <com/sun/star/i18n/ScriptType.hpp>
      85             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      86             : #include <com/sun/star/lang/XServiceInfo.hpp>
      87             : #include <com/sun/star/linguistic2/SingleProofreadingError.hpp>
      88             : #include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
      89             : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
      90             : #include <com/sun/star/uno/Any.hxx>
      91             : #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
      92             : #include <com/sun/star/system/SystemShellExecute.hpp>
      93             : #include <com/sun/star/frame/UICommandDescription.hpp>
      94             : 
      95             : 
      96             : using namespace ::com::sun::star;
      97             : using ::rtl::OUString;
      98             : 
      99             : extern void sw_CharDialog( SwWrtShell &rWrtSh, sal_Bool bUseDialog, sal_uInt16 nSlot,const SfxItemSet *pArgs, SfxRequest *pReq );
     100             : 
     101             : 
     102             : 
     103             : 
     104             : // tries to determine the language of 'rText'
     105             : //
     106           0 : static LanguageType lcl_CheckLanguage(
     107             :     const OUString &rText,
     108             :     uno::Reference< linguistic2::XSpellChecker1 > xSpell,
     109             :     uno::Reference< linguistic2::XLanguageGuessing > xLangGuess,
     110             :     sal_Bool bIsParaText )
     111             : {
     112           0 :     LanguageType  nLang = LANGUAGE_NONE;
     113           0 :     if (bIsParaText)    // check longer texts with language-guessing...
     114             :     {
     115           0 :         if (!xLangGuess.is())
     116           0 :             return nLang;
     117             : 
     118           0 :         lang::Locale aLocale( xLangGuess->guessPrimaryLanguage( rText, 0, rText.getLength()) );
     119             : 
     120             :         // get language as from "Tools/Options - Language Settings - Languages: Locale setting"
     121           0 :         LanguageType nTmpLang = Application::GetSettings().GetLanguageTag().getLanguageType();
     122             : 
     123             :         // if the result from language guessing does not provide a 'Country' part
     124             :         // try to get it by looking up the locale setting of the office.
     125             :         /* FIXME-BCP47: handle language tags */
     126           0 :         if (aLocale.Country.isEmpty())
     127             :         {
     128           0 :             lang::Locale aTmpLocale = LanguageTag( nTmpLang ).getLocale();
     129           0 :             if (aTmpLocale.Language == aLocale.Language)
     130           0 :                 nLang = nTmpLang;
     131             :         }
     132           0 :         if (nLang == LANGUAGE_NONE) // language not found by looking up the system language...
     133           0 :             nLang = LanguageTag( aLocale ).makeFallback().getLanguageType();
     134           0 :         if (nLang == LANGUAGE_SYSTEM)
     135           0 :             nLang = nTmpLang;
     136           0 :         if (nLang == LANGUAGE_DONTKNOW)
     137           0 :             nLang = LANGUAGE_NONE;
     138             :     }
     139             :     else    // check single word
     140             :     {
     141           0 :             if (!xSpell.is())
     142           0 :             return nLang;
     143             : 
     144             :         //
     145             :         // build list of languages to check
     146             :         //
     147             :         LanguageType aLangList[4];
     148           0 :         const AllSettings& rSettings  = Application::GetSettings();
     149           0 :         SvtLinguOptions aLinguOpt;
     150           0 :         SvtLinguConfig().GetOptions( aLinguOpt );
     151             :         // The default document language from "Tools/Options - Language Settings - Languages: Western"
     152           0 :         aLangList[0] = MsLangId::resolveSystemLanguageByScriptType(aLinguOpt.nDefaultLanguage, ::com::sun::star::i18n::ScriptType::LATIN);
     153             :         // The one from "Tools/Options - Language Settings - Languages: User interface"
     154           0 :         aLangList[1] = rSettings.GetUILanguageTag().getLanguageType();
     155             :         // The one from "Tools/Options - Language Settings - Languages: Locale setting"
     156           0 :         aLangList[2] = rSettings.GetLanguageTag().getLanguageType();
     157             :         // en-US
     158           0 :         aLangList[3] = LANGUAGE_ENGLISH_US;
     159             : #if OSL_DEBUG_LEVEL > 1
     160             :         lang::Locale a0( LanguageTag( aLangList[0] ).getLocale() );
     161             :         lang::Locale a1( LanguageTag( aLangList[1] ).getLocale() );
     162             :         lang::Locale a2( LanguageTag( aLangList[2] ).getLocale() );
     163             :         lang::Locale a3( LanguageTag( aLangList[3] ).getLocale() );
     164             : #endif
     165             : 
     166           0 :         sal_Int32 nCount = SAL_N_ELEMENTS(aLangList);
     167           0 :         for (sal_Int32 i = 0; i < nCount;  i++)
     168             :         {
     169           0 :             sal_Int16 nTmpLang = aLangList[i];
     170           0 :             if (nTmpLang != LANGUAGE_NONE  &&  nTmpLang != LANGUAGE_DONTKNOW)
     171             :             {
     172           0 :                 if (xSpell->hasLanguage( nTmpLang ) &&
     173           0 :                     xSpell->isValid( rText, nTmpLang, uno::Sequence< beans::PropertyValue >() ))
     174             :                 {
     175           0 :                     nLang = nTmpLang;
     176           0 :                     break;
     177             :                 }
     178             :             }
     179           0 :         }
     180             :     }
     181             : 
     182           0 :     return nLang;
     183             : }
     184             : 
     185             : 
     186             : /// @returns : the language for the selected text that is set for the
     187             : ///     specified attribute (script type).
     188             : ///     If there are more than one languages used LANGUAGE_DONTKNOW will be returned.
     189             : /// @param nLangWhichId : one of
     190             : ///     RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
     191             : /// @returns: the language in use for the selected text.
     192             : ///     'In use' means the language(s) matching the script type(s) of the
     193             : ///     selected text. Or in other words, the language a spell checker would use.
     194             : ///     If there is more than one language LANGUAGE_DONTKNOW will be returned.
     195             : // check if nScriptType includes the script type associated to nLang
     196           0 : static inline bool lcl_checkScriptType( sal_Int16 nScriptType, LanguageType nLang )
     197             : {
     198           0 :     return 0 != (nScriptType & SvtLanguageOptions::GetScriptTypeOfLanguage( nLang ));
     199             : }
     200             : 
     201           0 : void SwSpellPopup::fillLangPopupMenu(
     202             :     PopupMenu *pPopupMenu,
     203             :     sal_uInt16 nLangItemIdStart,
     204             :     uno::Sequence< OUString > aSeq,
     205             :     SwWrtShell* pWrtSh,
     206             :     std::map< sal_Int16, ::rtl::OUString > &rLangTable )
     207             : {
     208           0 :     if (!pPopupMenu)
     209           0 :         return;
     210             : 
     211           0 :     SvtLanguageTable    aLanguageTable;
     212             : 
     213             :     // set of languages to be displayed in the sub menus
     214           0 :     std::set< OUString > aLangItems;
     215             : 
     216           0 :     OUString    aCurLang( aSeq[0] );
     217           0 :     sal_uInt16      nScriptType = static_cast< sal_Int16 >(aSeq[1].toInt32());
     218           0 :     OUString    aKeyboardLang( aSeq[2] );
     219           0 :     OUString    aGuessedTextLang( aSeq[3] );
     220             : 
     221           0 :     if (!aCurLang.isEmpty() &&
     222           0 :         LANGUAGE_DONTKNOW != aLanguageTable.GetType( aCurLang ))
     223           0 :         aLangItems.insert( aCurLang );
     224             : 
     225             :     //2--System
     226           0 :     const AllSettings& rAllSettings = Application::GetSettings();
     227           0 :     LanguageType rSystemLanguage = rAllSettings.GetLanguageTag().getLanguageType();
     228           0 :     if (rSystemLanguage != LANGUAGE_DONTKNOW)
     229             :     {
     230           0 :         if (lcl_checkScriptType( nScriptType, rSystemLanguage ))
     231           0 :             aLangItems.insert( aLanguageTable.GetString(rSystemLanguage) );
     232             :     }
     233             : 
     234             :     //3--UI
     235           0 :     LanguageType rUILanguage = rAllSettings.GetUILanguageTag().getLanguageType();
     236           0 :     if (rUILanguage != LANGUAGE_DONTKNOW)
     237             :     {
     238           0 :         if (lcl_checkScriptType(nScriptType, rUILanguage ))
     239           0 :             aLangItems.insert( aLanguageTable.GetString(rUILanguage) );
     240             :     }
     241             : 
     242             :     //4--guessed language
     243           0 :     if (!aGuessedTextLang.isEmpty())
     244             :     {
     245           0 :         if (lcl_checkScriptType(nScriptType, aLanguageTable.GetType(aGuessedTextLang)))
     246           0 :             aLangItems.insert( aGuessedTextLang );
     247             :     }
     248             : 
     249             :     //5--keyboard language
     250           0 :     if (!aKeyboardLang.isEmpty())
     251             :     {
     252           0 :         if (lcl_checkScriptType(nScriptType, aLanguageTable.GetType(aKeyboardLang)))
     253           0 :             aLangItems.insert( aKeyboardLang );
     254             :     }
     255             : 
     256             :     //6--all languages used in current document
     257           0 :     uno::Reference< com::sun::star::frame::XModel > xModel;
     258           0 :     uno::Reference< com::sun::star::frame::XController > xController( pWrtSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface()->getController(), uno::UNO_QUERY );
     259           0 :     if ( xController.is() )
     260           0 :         xModel = xController->getModel();
     261           0 :     uno::Reference< document::XDocumentLanguages > xDocumentLanguages( xModel, uno::UNO_QUERY );
     262             :     /*the description of nScriptType flags
     263             :       LATIN :   0x0001
     264             :       ASIAN :   0x0002
     265             :       COMPLEX:  0x0004
     266             :     */
     267           0 :     const sal_Int16 nMaxCount = 7;
     268           0 :     if (xDocumentLanguages.is())
     269             :     {
     270           0 :         uno::Sequence< lang::Locale > rLocales( xDocumentLanguages->getDocumentLanguages( nScriptType, nMaxCount ) );
     271           0 :         if (rLocales.getLength() > 0)
     272             :         {
     273           0 :             for (sal_uInt16 i = 0; i < rLocales.getLength(); ++i)
     274             :             {
     275           0 :                 if (aLangItems.size() == (size_t)nMaxCount)
     276           0 :                     break;
     277           0 :                 const lang::Locale& rLocale = rLocales[i];
     278           0 :                 if (lcl_checkScriptType( nScriptType, aLanguageTable.GetType( rLocale.Language )))
     279           0 :                     aLangItems.insert( rLocale.Language );
     280             :             }
     281           0 :         }
     282             :     }
     283             : 
     284             : 
     285           0 :     sal_uInt16 nItemId = nLangItemIdStart;
     286           0 :     std::set< OUString >::const_iterator it;
     287           0 :     for (it = aLangItems.begin(); it != aLangItems.end(); ++it)
     288             :     {
     289           0 :         OUString aEntryTxt( *it );
     290           0 :         if (aEntryTxt != OUString( aLanguageTable.GetString( LANGUAGE_NONE ) )&&
     291           0 :             aEntryTxt != "*" && // multiple languages in current selection
     292           0 :             !aEntryTxt.isEmpty()) // 'no language found' from language guessing
     293             :         {
     294             :             OSL_ENSURE( nLangItemIdStart <= nItemId && nItemId <= nLangItemIdStart + MN_MAX_NUM_LANG,
     295             :                     "nItemId outside of expected range!" );
     296           0 :             pPopupMenu->InsertItem( nItemId, aEntryTxt, MIB_RADIOCHECK );
     297           0 :             if (aEntryTxt == aCurLang)
     298             :             {
     299             :                 //make a check mark for the current language
     300           0 :                 pPopupMenu->CheckItem( nItemId, sal_True );
     301             :             }
     302           0 :             rLangTable[ nItemId ] = aEntryTxt;
     303           0 :             ++nItemId;
     304             :         }
     305           0 :     }
     306             : 
     307           0 :     pPopupMenu->InsertItem( nLangItemIdStart + MN_NONE_OFFSET,  String(SW_RES( STR_LANGSTATUS_NONE )), MIB_RADIOCHECK );
     308           0 :     if ( aLanguageTable.GetString( LANGUAGE_NONE ) == aCurLang )
     309           0 :         pPopupMenu->CheckItem( nLangItemIdStart + MN_NONE_OFFSET, sal_True );
     310             : 
     311           0 :     pPopupMenu->InsertItem( nLangItemIdStart + MN_RESET_OFFSET, String(SW_RES( STR_RESET_TO_DEFAULT_LANGUAGE )), 0 );
     312           0 :     pPopupMenu->InsertItem( nLangItemIdStart + MN_MORE_OFFSET,  String(SW_RES( STR_LANGSTATUS_MORE )), 0 );
     313             : }
     314             : 
     315             : 
     316           0 : static Image lcl_GetImageFromPngUrl( const OUString &rFileUrl )
     317             : {
     318           0 :     Image aRes;
     319           0 :     OUString aTmp;
     320           0 :     osl::FileBase::getSystemPathFromFileURL( rFileUrl, aTmp );
     321           0 :     Graphic aGraphic;
     322           0 :     const String aFilterName( IMP_PNG );
     323           0 :     if( GRFILTER_OK == GraphicFilter::LoadGraphic( aTmp, aFilterName, aGraphic ) )
     324             :     {
     325           0 :         aRes = Image( aGraphic.GetBitmapEx() );
     326             :     }
     327           0 :     return aRes;
     328             : }
     329             : 
     330             : 
     331           0 : OUString RetrieveLabelFromCommand( const OUString& aCmdURL )
     332             : {
     333           0 :     OUString aLabel;
     334           0 :     if ( !aCmdURL.isEmpty() )
     335             :     {
     336             :         try
     337             :         {
     338             :             uno::Reference< container::XNameAccess > const xNameAccess(
     339             :                     frame::UICommandDescription::create(
     340             :                         ::comphelper::getProcessComponentContext() ),
     341           0 :                     uno::UNO_QUERY_THROW );
     342           0 :             uno::Reference< container::XNameAccess > xUICommandLabels;
     343           0 :             uno::Any a = xNameAccess->getByName( "com.sun.star.text.TextDocument" );
     344           0 :             uno::Reference< container::XNameAccess > xUICommands;
     345           0 :             a >>= xUICommandLabels;
     346           0 :             OUString aStr;
     347           0 :             uno::Sequence< beans::PropertyValue > aPropSeq;
     348           0 :             a = xUICommandLabels->getByName( aCmdURL );
     349           0 :             if ( a >>= aPropSeq )
     350             :             {
     351           0 :                 for ( sal_Int32 i = 0; i < aPropSeq.getLength(); i++ )
     352             :                 {
     353           0 :                     if ( aPropSeq[i].Name == "Name" )
     354             :                     {
     355           0 :                         aPropSeq[i].Value >>= aStr;
     356           0 :                         break;
     357             :                     }
     358             :                 }
     359             :             }
     360           0 :             aLabel = aStr;
     361             :         }
     362           0 :         catch (const uno::Exception&)
     363             :         {
     364             :         }
     365             :     }
     366             : 
     367           0 :     return aLabel;
     368             : }
     369             : 
     370             : 
     371           0 : SwSpellPopup::SwSpellPopup(
     372             :         SwWrtShell* pWrtSh,
     373             :         const uno::Reference< linguistic2::XSpellAlternatives >  &xAlt,
     374             :         const String &rParaText
     375             : )   : PopupMenu( SW_RES(MN_SPELL_POPUP) )
     376             :     , pSh( pWrtSh )
     377             :     , xSpellAlt(xAlt)
     378           0 :     , bGrammarResults(false)
     379             : {
     380             :     OSL_ENSURE(xSpellAlt.is(), "no spelling alternatives available");
     381             : 
     382           0 :     SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
     383           0 :     bool bUseImagesInMenus = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
     384             : 
     385           0 :     nCheckedLanguage = LANGUAGE_NONE;
     386           0 :     if (xSpellAlt.is())
     387             :     {
     388           0 :         nCheckedLanguage = LanguageTag( xSpellAlt->getLocale() ).getLanguageType();
     389           0 :         aSuggestions = xSpellAlt->getAlternatives();
     390             :     }
     391           0 :     sal_Int16 nStringCount = static_cast< sal_Int16 >( aSuggestions.getLength() );
     392             : 
     393           0 :     SvtLinguConfig aCfg;
     394             : 
     395           0 :     PopupMenu *pMenu = GetPopupMenu(MN_AUTOCORR);
     396           0 :     pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
     397           0 :     sal_Bool bEnable = sal_False;
     398           0 :     if( nStringCount )
     399             :     {
     400           0 :         Image aImage;
     401           0 :         OUString aSuggestionImageUrl;
     402             : 
     403           0 :         if (bUseImagesInMenus)
     404             :         {
     405           0 :             uno::Reference< container::XNamed > xNamed( xSpellAlt, uno::UNO_QUERY );
     406           0 :             if (xNamed.is())
     407             :             {
     408           0 :                 aSuggestionImageUrl = aCfg.GetSpellAndGrammarContextSuggestionImage( xNamed->getName() );
     409           0 :                 aImage = Image( lcl_GetImageFromPngUrl( aSuggestionImageUrl ) );
     410           0 :             }
     411             :         }
     412             : 
     413           0 :         InsertSeparator(0);
     414           0 :         bEnable = sal_True;
     415           0 :         sal_uInt16 nAutoCorrItemId  = MN_AUTOCORR_START;
     416           0 :         sal_uInt16 nItemId          = MN_SUGGESTION_START;
     417           0 :         for (sal_uInt16 i = 0; i < nStringCount; ++i)
     418             :         {
     419           0 :             const String aEntry = aSuggestions[ i ];
     420           0 :             InsertItem( nItemId, aEntry, 0, i );
     421           0 :             SetHelpId( nItemId, HID_LINGU_REPLACE);
     422           0 :             if (!aSuggestionImageUrl.isEmpty())
     423           0 :                 SetItemImage( nItemId, aImage );
     424             : 
     425           0 :             pMenu->InsertItem( nAutoCorrItemId, aEntry );
     426           0 :             pMenu->SetHelpId( nAutoCorrItemId, HID_LINGU_AUTOCORR);
     427             : 
     428           0 :             ++nAutoCorrItemId;
     429           0 :             ++nItemId;
     430           0 :         }
     431             :     }
     432             : 
     433           0 :     OUString aIgnoreSelection( String( SW_RES( STR_IGNORE_SELECTION ) ) );
     434           0 :     OUString aSpellingAndGrammar = RetrieveLabelFromCommand( ".uno:SpellingAndGrammarDialog" );
     435           0 :     SetItemText( MN_SPELLING_DLG, aSpellingAndGrammar );
     436           0 :     sal_uInt16 nItemPos = GetItemPos( MN_IGNORE_WORD );
     437           0 :     InsertItem( MN_IGNORE_SELECTION, aIgnoreSelection, 0, nItemPos );
     438           0 :     SetHelpId( MN_IGNORE_SELECTION, HID_LINGU_IGNORE_SELECTION);
     439             : 
     440           0 :     EnableItem( MN_AUTOCORR, bEnable );
     441             : 
     442           0 :     uno::Reference< linguistic2::XLanguageGuessing > xLG = SW_MOD()->GetLanguageGuesser();
     443           0 :     nGuessLangWord = LANGUAGE_NONE;
     444           0 :     nGuessLangPara = LANGUAGE_NONE;
     445           0 :     if (xSpellAlt.is() && xLG.is())
     446             :     {
     447           0 :         nGuessLangWord = lcl_CheckLanguage( xSpellAlt->getWord(), ::GetSpellChecker(), xLG, sal_False );
     448           0 :         nGuessLangPara = lcl_CheckLanguage( rParaText, ::GetSpellChecker(), xLG, sal_True );
     449             :     }
     450           0 :     if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
     451             :     {
     452             :         // make sure LANGUAGE_NONE gets not used as menu entry
     453           0 :         if (nGuessLangWord == LANGUAGE_NONE)
     454           0 :             nGuessLangWord = nGuessLangPara;
     455           0 :         if (nGuessLangPara == LANGUAGE_NONE)
     456           0 :             nGuessLangPara = nGuessLangWord;
     457             :     }
     458             : 
     459           0 :     pMenu = GetPopupMenu(MN_ADD_TO_DIC);
     460           0 :     pMenu->SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);     //! necessary to retrieve the correct dictionary name in 'Execute' below
     461           0 :     uno::Reference< linguistic2::XDictionaryList >    xDicList( SvxGetDictionaryList() );
     462           0 :     sal_uInt16 nItemId = MN_DICTIONARIES_START;
     463           0 :     if (xDicList.is())
     464             :     {
     465             :         // add the default positive dictionary to dic-list (if not already done).
     466             :         // This is to ensure that there is at least one dictionary to which
     467             :         // words could be added.
     468           0 :         uno::Reference< linguistic2::XDictionary >  xDic( SvxGetOrCreatePosDic( xDicList ) );
     469           0 :         if (xDic.is())
     470           0 :             xDic->setActive( sal_True );
     471             : 
     472           0 :         aDics = xDicList->getDictionaries();
     473           0 :         const uno::Reference< linguistic2::XDictionary >  *pDic = aDics.getConstArray();
     474           0 :         sal_uInt16 nDicCount = static_cast< sal_uInt16 >(aDics.getLength());
     475             : 
     476           0 :         for( sal_uInt16 i = 0; i < nDicCount; i++ )
     477             :         {
     478           0 :             uno::Reference< linguistic2::XDictionary >  xDicTmp( pDic[i], uno::UNO_QUERY );
     479           0 :             if (!xDicTmp.is() || SvxGetIgnoreAllList() == xDicTmp)
     480           0 :                 continue;
     481             : 
     482           0 :             uno::Reference< frame::XStorable > xStor( xDicTmp, uno::UNO_QUERY );
     483           0 :             LanguageType nActLanguage = LanguageTag( xDicTmp->getLocale() ).getLanguageType();
     484           0 :             if( xDicTmp->isActive()
     485           0 :                 &&  xDicTmp->getDictionaryType() != linguistic2::DictionaryType_NEGATIVE
     486             :                 && (nCheckedLanguage == nActLanguage || LANGUAGE_NONE == nActLanguage )
     487           0 :                 && (!xStor.is() || !xStor->isReadonly()) )
     488             :             {
     489             :                 // the extra 1 is because of the (possible) external
     490             :                 // linguistic entry above
     491           0 :                 pMenu->InsertItem( nItemId, xDicTmp->getName() );
     492           0 :                 aDicNameSingle = xDicTmp->getName();
     493             : 
     494           0 :                 if (bUseImagesInMenus)
     495             :                 {
     496           0 :                     uno::Reference< lang::XServiceInfo > xSvcInfo( xDicTmp, uno::UNO_QUERY );
     497           0 :                     if (xSvcInfo.is())
     498             :                     {
     499             :                         OUString aDictionaryImageUrl( aCfg.GetSpellAndGrammarContextDictionaryImage(
     500           0 :                                 xSvcInfo->getImplementationName() ) );
     501           0 :                         if (!aDictionaryImageUrl.isEmpty())
     502             :                         {
     503           0 :                             Image aImage( lcl_GetImageFromPngUrl( aDictionaryImageUrl ) );
     504           0 :                             pMenu->SetItemImage( nItemId, aImage );
     505           0 :                         }
     506           0 :                     }
     507             :                 }
     508             : 
     509           0 :                 ++nItemId;
     510             :             }
     511           0 :         }
     512             :     }
     513           0 :     EnableItem( MN_ADD_TO_DIC, ((nItemId - MN_DICTIONARIES_START) > 1)?sal_True:sal_False );
     514           0 :     EnableItem( MN_ADD_TO_DIC_SINGLE, ((nItemId - MN_DICTIONARIES_START) == 1)?sal_True:sal_False );
     515             : 
     516             :     //ADD NEW LANGUAGE MENU ITEM
     517             :     ///////////////////////////////////////////////////////////////////////////
     518           0 :     String aScriptTypesInUse( String::CreateFromInt32( pWrtSh->GetScriptType() ) );
     519           0 :     SvtLanguageTable aLanguageTable;
     520             : 
     521             :     // get keyboard language
     522           0 :     String aKeyboardLang;
     523           0 :     LanguageType nLang = LANGUAGE_DONTKNOW;
     524           0 :     SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
     525           0 :     nLang = rEditWin.GetInputLanguage();
     526           0 :     if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
     527           0 :         aKeyboardLang = aLanguageTable.GetString( nLang );
     528             : 
     529             :     // get the language that is in use
     530           0 :     String aCurrentLang = rtl::OUString("*");
     531           0 :     nLang = SwLangHelper::GetCurrentLanguage( *pWrtSh );
     532           0 :     if (nLang != LANGUAGE_DONTKNOW)
     533           0 :         aCurrentLang = aLanguageTable.GetString( nLang );
     534             : 
     535             :     // build sequence for status value
     536           0 :     uno::Sequence< OUString > aSeq( 4 );
     537           0 :     aSeq[0] = aCurrentLang;
     538           0 :     aSeq[1] = aScriptTypesInUse;
     539           0 :     aSeq[2] = aKeyboardLang;
     540           0 :     aSeq[3] = aLanguageTable.GetString(nGuessLangWord);
     541             : 
     542           0 :     pMenu = GetPopupMenu(MN_SET_LANGUAGE_SELECTION);
     543           0 :     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_SELECTION_START, aSeq, pWrtSh, aLangTable_Text );
     544           0 :     EnableItem( MN_SET_LANGUAGE_SELECTION, true );
     545             : 
     546           0 :     pMenu = GetPopupMenu(MN_SET_LANGUAGE_PARAGRAPH);
     547           0 :     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_PARAGRAPH_START, aSeq, pWrtSh, aLangTable_Paragraph );
     548           0 :     EnableItem( MN_SET_LANGUAGE_PARAGRAPH, true );
     549             : 
     550           0 :     if (bUseImagesInMenus)
     551             :     {
     552           0 :         uno::Reference< frame::XFrame > xFrame = pWrtSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface();
     553           0 :         Image rImg = ::GetImage( xFrame, ".uno:SpellingAndGrammarDialog", sal_False );
     554           0 :         SetItemImage( MN_SPELLING_DLG, rImg );
     555             :     }
     556             : 
     557             :     //////////////////////////////////////////////////////////////////////////////////
     558             : 
     559           0 :     RemoveDisabledEntries( sal_True, sal_True );
     560           0 : }
     561             : 
     562             : 
     563             : 
     564           0 : SwSpellPopup::SwSpellPopup(
     565             :     SwWrtShell *pWrtSh,
     566             :     const linguistic2::ProofreadingResult &rResult,
     567             :     sal_Int32 nErrorInResult,
     568             :     const uno::Sequence< OUString > &rSuggestions,
     569             :     const String &rParaText ) :
     570             : PopupMenu( SW_RES(MN_SPELL_POPUP) ),
     571             : pSh( pWrtSh ),
     572             : xGrammarResult( rResult ),
     573             : aSuggestions( rSuggestions ),
     574             : sExplanationLink( ),
     575             : bGrammarResults( true ),
     576           0 : aInfo16( SW_RES(IMG_INFO_16) )
     577             : {
     578           0 :     nCheckedLanguage = LanguageTag( rResult.aLocale ).getLanguageType();
     579           0 :     nGrammarError = nErrorInResult;
     580           0 :     bool bUseImagesInMenus = Application::GetSettings().GetStyleSettings().GetUseImagesInMenus();
     581             : 
     582           0 :     sal_uInt16 nPos = 0;
     583           0 :     OUString aMessageText( rResult.aErrors[ nErrorInResult ].aShortComment );
     584           0 :     InsertSeparator( nPos++ );
     585           0 :     InsertItem( MN_SHORT_COMMENT, aMessageText, MIB_NOSELECT, nPos++ );
     586           0 :     if (bUseImagesInMenus)
     587           0 :         SetItemImage( MN_SHORT_COMMENT, aInfo16 );
     588             : 
     589             :     // Add an item to show detailled infos if the FullCommentURL property is defined
     590           0 :     beans::PropertyValues  aProperties = rResult.aErrors[ nErrorInResult ].aProperties;
     591             :     {
     592           0 :         sal_Int32 i = 0;
     593           0 :         while ( sExplanationLink.isEmpty() && i < aProperties.getLength() )
     594             :         {
     595           0 :             if ( aProperties[i].Name == "FullCommentURL" )
     596             :             {
     597           0 :                 uno::Any aValue = aProperties[i].Value;
     598           0 :                 aValue >>= sExplanationLink;
     599             :             }
     600           0 :             ++i;
     601             :         }
     602             :     }
     603             : 
     604           0 :     if ( !sExplanationLink.isEmpty( ) )
     605             :     {
     606           0 :         InsertItem( MN_EXPLANATION_LINK, String( SW_RES( STR_EXPLANATION_LINK ) ), MIB_TEXT | MIB_HELP, nPos++ );
     607             :     }
     608             : 
     609           0 :     SetMenuFlags(MENU_FLAG_NOAUTOMNEMONICS);
     610             : 
     611           0 :     InsertSeparator( nPos++ );
     612           0 :     sal_Int32 nStringCount = aSuggestions.getLength();
     613           0 :     if ( nStringCount )     // suggestions available...
     614             :     {
     615           0 :         Image aImage;
     616           0 :         OUString aSuggestionImageUrl;
     617             : 
     618           0 :         if (bUseImagesInMenus)
     619             :         {
     620           0 :             uno::Reference< lang::XServiceInfo > xInfo( rResult.xProofreader, uno::UNO_QUERY );
     621           0 :             if (xInfo.is())
     622             :             {
     623           0 :                 aSuggestionImageUrl = SvtLinguConfig().GetSpellAndGrammarContextSuggestionImage( xInfo->getImplementationName() );
     624           0 :                 aImage = Image( lcl_GetImageFromPngUrl( aSuggestionImageUrl ) );
     625           0 :             }
     626             :         }
     627             : 
     628           0 :         sal_uInt16 nItemId = MN_SUGGESTION_START;
     629           0 :         for (sal_uInt16 i = 0;  i < nStringCount;  ++i)
     630             :         {
     631           0 :             const String aEntry = aSuggestions[ i ];
     632           0 :             InsertItem( nItemId, aEntry, 0, nPos++ );
     633           0 :             SetHelpId( nItemId, HID_LINGU_REPLACE );
     634           0 :             if (!aSuggestionImageUrl.isEmpty())
     635           0 :                 SetItemImage( nItemId, aImage );
     636             : 
     637           0 :             ++nItemId;
     638           0 :         }
     639           0 :         InsertSeparator( nPos++ );
     640             :     }
     641             : 
     642           0 :     OUString aIgnoreSelection( String( SW_RES( STR_IGNORE_SELECTION ) ) );
     643           0 :     OUString aSpellingAndGrammar = RetrieveLabelFromCommand( ".uno:SpellingAndGrammarDialog" );
     644           0 :     SetItemText( MN_SPELLING_DLG, aSpellingAndGrammar );
     645           0 :     sal_uInt16 nItemPos = GetItemPos( MN_IGNORE_WORD );
     646           0 :     InsertItem( MN_IGNORE_SELECTION, aIgnoreSelection, 0, nItemPos );
     647           0 :     SetHelpId( MN_IGNORE_SELECTION, HID_LINGU_IGNORE_SELECTION);
     648             : 
     649           0 :     EnableItem( MN_AUTOCORR, false );
     650             : 
     651           0 :     uno::Reference< linguistic2::XLanguageGuessing > xLG = SW_MOD()->GetLanguageGuesser();
     652           0 :     nGuessLangWord = LANGUAGE_NONE;
     653           0 :     nGuessLangPara = LANGUAGE_NONE;
     654           0 :     if (xLG.is())
     655             :     {
     656           0 :         nGuessLangPara = lcl_CheckLanguage( rParaText, ::GetSpellChecker(), xLG, sal_True );
     657             :     }
     658           0 :     if (nGuessLangWord != LANGUAGE_NONE || nGuessLangPara != LANGUAGE_NONE)
     659             :     {
     660             :         // make sure LANGUAGE_NONE gets not used as menu entry
     661           0 :         if (nGuessLangWord == LANGUAGE_NONE)
     662           0 :             nGuessLangWord = nGuessLangPara;
     663           0 :         if (nGuessLangPara == LANGUAGE_NONE)
     664           0 :             nGuessLangPara = nGuessLangWord;
     665             :     }
     666             : 
     667           0 :     EnableItem( MN_IGNORE_WORD, false );
     668           0 :     EnableItem( MN_ADD_TO_DIC, false );
     669           0 :     EnableItem( MN_ADD_TO_DIC_SINGLE, false );
     670             : 
     671             :     //ADD NEW LANGUAGE MENU ITEM
     672             :     ///////////////////////////////////////////////////////////////////////////
     673           0 :     String aScriptTypesInUse( String::CreateFromInt32( pWrtSh->GetScriptType() ) );
     674           0 :     SvtLanguageTable aLanguageTable;
     675             : 
     676             :     // get keyboard language
     677           0 :     String aKeyboardLang;
     678           0 :     LanguageType nLang = LANGUAGE_DONTKNOW;
     679           0 :     SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
     680           0 :     nLang = rEditWin.GetInputLanguage();
     681           0 :     if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
     682           0 :         aKeyboardLang = aLanguageTable.GetString( nLang );
     683             : 
     684             :     // get the language that is in use
     685           0 :     String aCurrentLang = rtl::OUString("*");
     686           0 :     nLang = SwLangHelper::GetCurrentLanguage( *pWrtSh );
     687           0 :     if (nLang != LANGUAGE_DONTKNOW)
     688           0 :         aCurrentLang = aLanguageTable.GetString( nLang );
     689             : 
     690             :     // build sequence for status value
     691           0 :     uno::Sequence< OUString > aSeq( 4 );
     692           0 :     aSeq[0] = aCurrentLang;
     693           0 :     aSeq[1] = aScriptTypesInUse;
     694           0 :     aSeq[2] = aKeyboardLang;
     695           0 :     aSeq[3] = aLanguageTable.GetString(nGuessLangWord);
     696             : 
     697           0 :     PopupMenu *pMenu = GetPopupMenu(MN_SET_LANGUAGE_SELECTION);
     698           0 :     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_SELECTION_START, aSeq, pWrtSh, aLangTable_Text );
     699           0 :     EnableItem( MN_SET_LANGUAGE_SELECTION, true );
     700             : 
     701           0 :     pMenu = GetPopupMenu(MN_SET_LANGUAGE_PARAGRAPH);
     702           0 :     fillLangPopupMenu( pMenu, MN_SET_LANGUAGE_PARAGRAPH_START, aSeq, pWrtSh, aLangTable_Paragraph );
     703           0 :     EnableItem( MN_SET_LANGUAGE_PARAGRAPH, true );
     704             : 
     705           0 :     if (bUseImagesInMenus)
     706             :     {
     707           0 :         uno::Reference< frame::XFrame > xFrame = pWrtSh->GetView().GetViewFrame()->GetFrame().GetFrameInterface();
     708           0 :         Image rImg = ::GetImage( xFrame, ".uno:SpellingAndGrammarDialog", sal_False );
     709           0 :         SetItemImage( MN_SPELLING_DLG, rImg );
     710             :     }
     711             : 
     712             :     //////////////////////////////////////////////////////////////////////////////////
     713             : 
     714           0 :     RemoveDisabledEntries( sal_True, sal_True );
     715           0 : }
     716             : 
     717             : 
     718           0 : sal_uInt16  SwSpellPopup::Execute( const Rectangle& rWordPos, Window* pWin )
     719             : {
     720           0 :     sal_uInt16 nRet = PopupMenu::Execute(pWin, pWin->LogicToPixel(rWordPos));
     721           0 :     Execute( nRet );
     722           0 :     return nRet;
     723             : }
     724             : 
     725           0 : void SwSpellPopup::Execute( sal_uInt16 nId )
     726             : {
     727           0 :     if (nId == USHRT_MAX)
     728           0 :         return;
     729             : 
     730           0 :     if (/*bGrammarResults && */nId == MN_SHORT_COMMENT)
     731           0 :         return;     // nothing to do since it is the error message (short comment)
     732             : 
     733           0 :     if ((MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ||
     734             :         (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END))
     735             :     {
     736             :         sal_Int32 nAltIdx = (MN_SUGGESTION_START <= nId && nId <= MN_SUGGESTION_END) ?
     737           0 :                 nId - MN_SUGGESTION_START : nId - MN_AUTOCORR_START;
     738             :         OSL_ENSURE( 0 <= nAltIdx && nAltIdx < aSuggestions.getLength(), "index out of range" );
     739           0 :         if (0 <= nAltIdx && nAltIdx < aSuggestions.getLength() && (bGrammarResults || xSpellAlt.is()))
     740             :         {
     741           0 :             sal_Bool bOldIns = pSh->IsInsMode();
     742           0 :             pSh->SetInsMode( sal_True );
     743             : 
     744           0 :             String aTmp( aSuggestions[ nAltIdx ] );
     745           0 :             String aOrig( bGrammarResults ? OUString() : xSpellAlt->getWord() );
     746             : 
     747             :             // if orginal word has a trailing . (likely the end of a sentence)
     748             :             // and the replacement text hasn't, then add it to the replacement
     749           0 :             if (aTmp.Len() && aOrig.Len() &&
     750           0 :                 '.' == aOrig.GetChar( aOrig.Len() - 1) && /* !IsAlphaNumeric ??*/
     751           0 :                 '.' != aTmp.GetChar( aTmp.Len() - 1))
     752             :             {
     753           0 :                 aTmp += '.';
     754             :             }
     755             : 
     756             :             // #111827#
     757           0 :             SwRewriter aRewriter;
     758             : 
     759           0 :             aRewriter.AddRule(UndoArg1, pSh->GetCrsrDescr());
     760           0 :             aRewriter.AddRule(UndoArg2, String(SW_RES(STR_YIELDS)));
     761             : 
     762           0 :             String aTmpStr( SW_RES(STR_START_QUOTE) );
     763           0 :             aTmpStr += aTmp;
     764           0 :             aTmpStr += String(SW_RES(STR_END_QUOTE));
     765           0 :             aRewriter.AddRule(UndoArg3, aTmpStr);
     766             : 
     767           0 :             pSh->StartUndo(UNDO_UI_REPLACE, &aRewriter);
     768           0 :             pSh->StartAction();
     769           0 :             pSh->DelLeft();
     770             : 
     771           0 :             pSh->Insert( aTmp );
     772             : 
     773             :             /* #102505# EndAction/EndUndo moved down since insertion
     774             :                of temporary auto correction is now undoable two and
     775             :                must reside in the same undo group.*/
     776             : 
     777             :             // record only if it's NOT already present in autocorrection
     778           0 :             SvxAutoCorrect* pACorr = SvxAutoCorrCfg::Get().GetAutoCorrect();
     779             : 
     780           0 :             String aOrigWord( bGrammarResults ? OUString() : xSpellAlt->getWord() ) ;
     781           0 :             String aNewWord( aSuggestions[ nAltIdx ] );
     782           0 :             SvxPrepareAutoCorrect( aOrigWord, aNewWord );
     783             : 
     784           0 :             if (MN_AUTOCORR_START <= nId && nId <= MN_AUTOCORR_END)
     785           0 :                 pACorr->PutText( aOrigWord, aNewWord, nCheckedLanguage );
     786             : 
     787             :             /* #102505# EndAction/EndUndo moved down since insertion
     788             :                of temporary auto correction is now undoable two and
     789             :                must reside in the same undo group.*/
     790           0 :             pSh->EndAction();
     791           0 :             pSh->EndUndo();
     792             : 
     793           0 :             pSh->SetInsMode( bOldIns );
     794           0 :         }
     795             :     }
     796           0 :     else if (nId == MN_SPELLING_DLG)
     797             :     {
     798           0 :         if (bGrammarResults)
     799             :         {
     800           0 :             SvtLinguConfig().SetProperty( A2OU( UPN_IS_GRAMMAR_INTERACTIVE ), uno::makeAny( sal_True ));
     801             :         }
     802           0 :         pSh->Left(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
     803             :         {
     804           0 :             uno::Reference<linguistic2::XDictionaryList> xDictionaryList( SvxGetDictionaryList() );
     805           0 :             SvxDicListChgClamp aClamp( xDictionaryList );
     806           0 :             pSh->GetView().GetViewFrame()->GetDispatcher()->
     807           0 :                 Execute( FN_SPELL_GRAMMAR_DIALOG, SFX_CALLMODE_ASYNCHRON );
     808             :         }
     809             :     }
     810           0 :     else if (nId == MN_IGNORE_SELECTION)
     811             :     {
     812           0 :         SwPaM *pPaM = pSh->GetCrsr();
     813           0 :         if (pPaM) {
     814           0 :             if (bGrammarResults) {
     815             :                 try
     816             :                 {
     817           0 :                     xGrammarResult.xProofreader->ignoreRule(
     818           0 :                         xGrammarResult.aErrors[ nGrammarError ].aRuleIdentifier,
     819           0 :                             xGrammarResult.aLocale );
     820             :                 }
     821           0 :                 catch( const uno::Exception& )
     822             :                 {
     823             :                 }
     824             :             }
     825           0 :             pSh->IgnoreGrammarErrorAt( *pPaM );
     826             :         }
     827             :     }
     828           0 :     else if (nId == MN_IGNORE_WORD)
     829             :     {
     830           0 :         uno::Reference< linguistic2::XDictionary > xDictionary( SvxGetIgnoreAllList(), uno::UNO_QUERY );
     831             :         linguistic::AddEntryToDic( xDictionary,
     832           0 :                 xSpellAlt->getWord(), sal_False, aEmptyStr, LANGUAGE_NONE );
     833             :     }
     834           0 :     else if ((MN_DICTIONARIES_START <= nId && nId <= MN_DICTIONARIES_END) || nId == MN_ADD_TO_DIC_SINGLE)
     835             :     {
     836           0 :             OUString aWord( xSpellAlt->getWord() );
     837           0 :             String aDicName;
     838             : 
     839           0 :             if (MN_DICTIONARIES_START <= nId && nId <= MN_DICTIONARIES_END)
     840             :             {
     841           0 :                 PopupMenu *pMenu = GetPopupMenu(MN_ADD_TO_DIC);
     842           0 :                 aDicName = pMenu->GetItemText(nId);
     843             :             }
     844             :             else
     845           0 :                 aDicName = aDicNameSingle;
     846             : 
     847           0 :             uno::Reference< linguistic2::XDictionary >      xDic;
     848           0 :             uno::Reference< linguistic2::XDictionaryList >  xDicList( SvxGetDictionaryList() );
     849           0 :             if (xDicList.is())
     850           0 :                 xDic = xDicList->getDictionaryByName( aDicName );
     851             : 
     852           0 :             if (xDic.is())
     853             :             {
     854           0 :                 sal_Int16 nAddRes = linguistic::AddEntryToDic( xDic, aWord, sal_False, aEmptyStr, LANGUAGE_NONE );
     855             :                 // save modified user-dictionary if it is persistent
     856           0 :                 uno::Reference< frame::XStorable >  xSavDic( xDic, uno::UNO_QUERY );
     857           0 :                 if (xSavDic.is())
     858           0 :                     xSavDic->store();
     859             : 
     860           0 :                 if (DIC_ERR_NONE != nAddRes
     861           0 :                     && !xDic->getEntry( aWord ).is())
     862             :                 {
     863             :                     SvxDicError(
     864           0 :                         &pSh->GetView().GetViewFrame()->GetWindow(),
     865           0 :                         nAddRes );
     866           0 :                 }
     867           0 :             }
     868             :     }
     869           0 :     else if ( nId == MN_EXPLANATION_LINK && !sExplanationLink.isEmpty() )
     870             :     {
     871             :         try
     872             :         {
     873             :             uno::Reference< com::sun::star::system::XSystemShellExecute > xSystemShellExecute(
     874           0 :                 com::sun::star::system::SystemShellExecute::create( ::comphelper::getProcessComponentContext() ) );
     875           0 :             xSystemShellExecute->execute( sExplanationLink, rtl::OUString(),
     876           0 :                     com::sun::star::system::SystemShellExecuteFlags::URIS_ONLY );
     877             :         }
     878           0 :         catch (const uno::Exception&)
     879             :         {
     880           0 :             uno::Any exc( ::cppu::getCaughtException() );
     881           0 :             rtl::OUString msg( ::comphelper::anyToString( exc ) );
     882           0 :             const SolarMutexGuard guard;
     883           0 :             ErrorBox aErrorBox( NULL, WB_OK, msg );
     884           0 :             aErrorBox.SetText( rtl::OUString::createFromAscii( "Explanations" ) );
     885           0 :             aErrorBox.Execute();
     886             :         }
     887             :     }
     888             :     else
     889             :     {
     890             :         // Set language for selection or for paragraph...
     891             : 
     892           0 :         SfxItemSet aCoreSet( pSh->GetView().GetPool(),
     893             :                     RES_CHRATR_LANGUAGE,        RES_CHRATR_LANGUAGE,
     894             :                     RES_CHRATR_CJK_LANGUAGE,    RES_CHRATR_CJK_LANGUAGE,
     895             :                     RES_CHRATR_CTL_LANGUAGE,    RES_CHRATR_CTL_LANGUAGE,
     896           0 :                     0 );
     897           0 :         String aNewLangTxt;
     898             : 
     899           0 :         if (MN_SET_LANGUAGE_SELECTION_START <= nId && nId <= MN_SET_LANGUAGE_SELECTION_END)
     900             :         {
     901             :             //Set language for current selection
     902           0 :             aNewLangTxt = aLangTable_Text[nId];
     903           0 :             SwLangHelper::SetLanguage( *pSh, aNewLangTxt, true, aCoreSet );
     904             :         }
     905           0 :         else if (nId == MN_SET_SELECTION_NONE)
     906             :         {
     907             :             //Set Language_None for current selection
     908           0 :             SwLangHelper::SetLanguage_None( *pSh, true, aCoreSet );
     909             :         }
     910           0 :         else if (nId == MN_SET_SELECTION_RESET)
     911             :         {
     912             :             //reset languages for current selection
     913           0 :             SwLangHelper::ResetLanguages( *pSh, true );
     914             :         }
     915           0 :         else if (nId == MN_SET_SELECTION_MORE)
     916             :         {
     917             :             //Open Format/Character Dialog
     918           0 :             sw_CharDialog( *pSh, true, nId, 0, 0 );
     919             :         }
     920           0 :         else if (MN_SET_LANGUAGE_PARAGRAPH_START <= nId && nId <= MN_SET_LANGUAGE_PARAGRAPH_END)
     921             :         {
     922             :             //Set language for current paragraph
     923           0 :             aNewLangTxt = aLangTable_Paragraph[nId];
     924           0 :             pSh->Push();        // save cursor
     925           0 :             SwLangHelper::SelectCurrentPara( *pSh );
     926           0 :             SwLangHelper::SetLanguage( *pSh, aNewLangTxt, true, aCoreSet );
     927           0 :             pSh->Pop( sal_False );  // restore cursor
     928             :         }
     929           0 :         else if (nId == MN_SET_PARA_NONE)
     930             :         {
     931             :             //Set Language_None for current paragraph
     932           0 :             pSh->Push();        // save cursor
     933           0 :             SwLangHelper::SelectCurrentPara( *pSh );
     934           0 :             SwLangHelper::SetLanguage_None( *pSh, true, aCoreSet );
     935           0 :             pSh->Pop( sal_False );  // restore cursor
     936             :         }
     937           0 :         else if (nId == MN_SET_PARA_RESET)
     938             :         {
     939             :             //reset languages for current paragraph
     940           0 :             pSh->Push();        // save cursor
     941           0 :             SwLangHelper::SelectCurrentPara( *pSh );
     942           0 :             SwLangHelper::ResetLanguages( *pSh, true );
     943           0 :             pSh->Pop( sal_False );  // restore cursor
     944             :         }
     945           0 :         else if (nId == MN_SET_PARA_MORE)
     946             :         {
     947           0 :             pSh->Push();        // save cursor
     948           0 :             SwLangHelper::SelectCurrentPara( *pSh );
     949             :             //Open Format/Character Dialog
     950           0 :             sw_CharDialog( *pSh, true, nId, 0, 0 );
     951           0 :             pSh->Pop( sal_False );  // restore cursor
     952           0 :         }
     953             :     }
     954             : 
     955           0 :     pSh->EnterStdMode();
     956          30 : }
     957             : 
     958             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10