LCOV - code coverage report
Current view: top level - sw/source/ui/lingu - olmenu.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 463 0.0 %
Date: 2012-08-25 Functions: 0 9 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 1300 0.0 %

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

Generated by: LCOV version 1.10