LCOV - code coverage report
Current view: top level - sw/source/ui/shells - langhelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 36 263 13.7 %
Date: 2012-08-25 Functions: 4 16 25.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 28 424 6.6 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <string.h>
      31                 :            : 
      32                 :            : #include <vcl/window.hxx>
      33                 :            : 
      34                 :            : #include <wrtsh.hxx>
      35                 :            : #include <doc.hxx>
      36                 :            : #include <docary.hxx>
      37                 :            : #include <charfmt.hxx>
      38                 :            : 
      39                 :            : #include <sfx2/bindings.hxx>
      40                 :            : #include <sfx2/dispatch.hxx>
      41                 :            : #include <sfx2/request.hxx>
      42                 :            : #include <editeng/eeitem.hxx>
      43                 :            : #include <editeng/editeng.hxx>
      44                 :            : #include <editeng/editdata.hxx>
      45                 :            : #include <editeng/outliner.hxx>
      46                 :            : #include <editeng/editview.hxx>
      47                 :            : #include <editeng/scripttypeitem.hxx>
      48                 :            : #include <editeng/langitem.hxx>
      49                 :            : 
      50                 :            : #include <svl/languageoptions.hxx>
      51                 :            : #include <svtools/langtab.hxx>
      52                 :            : #include <svl/slstitm.hxx>
      53                 :            : #include <svl/stritem.hxx>
      54                 :            : 
      55                 :            : #include <ndtxt.hxx>
      56                 :            : #include <pam.hxx>
      57                 :            : #include <view.hxx>
      58                 :            : #include <viewopt.hxx>
      59                 :            : 
      60                 :            : #include "swabstdlg.hxx"
      61                 :            : 
      62                 :            : #include <vcl/msgbox.hxx>
      63                 :            : 
      64                 :            : #include <langhelper.hxx>
      65                 :            : 
      66                 :            : using namespace ::com::sun::star;
      67                 :            : 
      68                 :            : namespace SwLangHelper
      69                 :            : {
      70                 :            : 
      71                 :          0 :     sal_uInt16 GetLanguageStatus( OutlinerView* pOLV, SfxItemSet& rSet )
      72                 :            :     {
      73         [ #  # ]:          0 :         ESelection aSelection = pOLV->GetSelection();
      74                 :          0 :         EditView& rEditView=pOLV->GetEditView();
      75         [ #  # ]:          0 :         EditEngine* pEditEngine=rEditView.GetEditEngine();
      76                 :            : 
      77                 :            :         // the value of used script types
      78         [ #  # ]:          0 :         const sal_uInt16 nScriptType =pOLV->GetSelectedScriptType();
      79         [ #  # ]:          0 :         String aScriptTypesInUse( String::CreateFromInt32( nScriptType ) );//pEditEngine->GetScriptType(aSelection)
      80                 :            : 
      81         [ #  # ]:          0 :         SvtLanguageTable aLangTable;
      82                 :            : 
      83                 :            :         // get keyboard language
      84         [ #  # ]:          0 :         String aKeyboardLang;
      85                 :          0 :         LanguageType nLang = LANGUAGE_DONTKNOW;
      86                 :            : 
      87         [ #  # ]:          0 :         Window* pWin = rEditView.GetWindow();
      88         [ #  # ]:          0 :         if(pWin)
      89         [ #  # ]:          0 :             nLang = pWin->GetInputLanguage();
      90 [ #  # ][ #  # ]:          0 :         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
      91 [ #  # ][ #  # ]:          0 :             aKeyboardLang = aLangTable.GetString( nLang );
      92                 :            : 
      93                 :            :         // get the language that is in use
      94         [ #  # ]:          0 :         String aCurrentLang = rtl::OUString("*");
      95         [ #  # ]:          0 :         SfxItemSet aSet(pOLV->GetAttribs());
      96 [ #  # ][ #  # ]:          0 :         nLang = SwLangHelper::GetCurrentLanguage( aSet,nScriptType );
                 [ #  # ]
      97         [ #  # ]:          0 :         if (nLang != LANGUAGE_DONTKNOW)
      98 [ #  # ][ #  # ]:          0 :             aCurrentLang = aLangTable.GetString( nLang );
      99                 :            : 
     100                 :            :         // build sequence for status value
     101         [ #  # ]:          0 :         uno::Sequence< ::rtl::OUString > aSeq( 4 );
     102 [ #  # ][ #  # ]:          0 :         aSeq[0] = aCurrentLang;
     103 [ #  # ][ #  # ]:          0 :         aSeq[1] = aScriptTypesInUse;
     104 [ #  # ][ #  # ]:          0 :         aSeq[2] = aKeyboardLang;
     105 [ #  # ][ #  # ]:          0 :         aSeq[3] = SwLangHelper::GetTextForLanguageGuessing( pEditEngine, aSelection );
         [ #  # ][ #  # ]
     106                 :            : 
     107                 :            :         // set sequence as status value
     108         [ #  # ]:          0 :         SfxStringListItem aItem( SID_LANGUAGE_STATUS );
     109         [ #  # ]:          0 :         aItem.SetStringList( aSeq );
     110         [ #  # ]:          0 :         rSet.Put( aItem, SID_LANGUAGE_STATUS );
     111 [ #  # ][ #  # ]:          0 :         return 0;
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     112                 :            :     }
     113                 :            : 
     114                 :          0 :     bool SetLanguageStatus( OutlinerView* pOLV, SfxRequest &rReq, SwView &rView, SwWrtShell &rSh )
     115                 :            :     {
     116                 :          0 :         bool bRestoreSelection = false;
     117         [ #  # ]:          0 :         SfxItemSet aEditAttr(pOLV->GetAttribs());
     118         [ #  # ]:          0 :         ESelection   aSelection  = pOLV->GetSelection();
     119                 :          0 :         EditView   & rEditView   = pOLV->GetEditView();
     120         [ #  # ]:          0 :         EditEngine * pEditEngine = rEditView.GetEditEngine();
     121                 :            : 
     122                 :            :         // get the language
     123         [ #  # ]:          0 :         String aNewLangTxt;
     124                 :            : 
     125 [ #  # ][ #  # ]:          0 :         SFX_REQUEST_ARG( rReq, pItem, SfxStringItem, SID_LANGUAGE_STATUS , sal_False );
     126         [ #  # ]:          0 :         if (pItem)
     127         [ #  # ]:          0 :             aNewLangTxt = pItem->GetValue();
     128                 :            : 
     129                 :            :         //!! Remember the view frame right now...
     130                 :            :         //!! (call to GetView().GetViewFrame() will break if the
     131                 :            :         //!! SwTextShell got destroyed meanwhile.)
     132                 :          0 :         SfxViewFrame *pViewFrame = rView.GetViewFrame();
     133                 :            : 
     134 [ #  # ][ #  # ]:          0 :         if (aNewLangTxt.EqualsAscii( "*" ))
     135                 :            :         {
     136                 :            :             // open the dialog "Tools/Options/Language Settings - Language"
     137         [ #  # ]:          0 :             SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
     138         [ #  # ]:          0 :             if (pFact)
     139                 :            :             {
     140         [ #  # ]:          0 :                 VclAbstractDialog* pDlg = pFact->CreateVclDialog( rView.GetWindow(), SID_LANGUAGE_OPTIONS );
     141         [ #  # ]:          0 :                 pDlg->Execute();
     142 [ #  # ][ #  # ]:          0 :                 delete pDlg;
     143                 :            :             }
     144                 :            :         }
     145                 :            :         else
     146                 :            :         {
     147                 :            :             // setting the new language...
     148         [ #  # ]:          0 :             if (aNewLangTxt.Len() > 0)
     149                 :            :             {
     150                 :          0 :                 const rtl::OUString aSelectionLangPrefix("Current_");
     151                 :          0 :                 const rtl::OUString aParagraphLangPrefix("Paragraph_");
     152                 :          0 :                 const rtl::OUString aDocumentLangPrefix("Default_");
     153         [ #  # ]:          0 :                 const String aStrNone( rtl::OUString("LANGUAGE_NONE") );
     154         [ #  # ]:          0 :                 const String aStrResetLangs( rtl::OUString("RESET_LANGUAGES") );
     155                 :            : 
     156                 :          0 :                 xub_StrLen nPos = 0;
     157                 :          0 :                 bool bForSelection = true;
     158                 :          0 :                 bool bForParagraph = false;
     159 [ #  # ][ #  # ]:          0 :                 if (STRING_NOTFOUND != (nPos = aNewLangTxt.Search( aSelectionLangPrefix, 0 )))
         [ #  # ][ #  # ]
     160                 :            :                 {
     161                 :            :                     // ... for the current selection
     162 [ #  # ][ #  # ]:          0 :                     aNewLangTxt = aNewLangTxt.Erase( nPos, aSelectionLangPrefix.getLength() );
     163                 :          0 :                     bForSelection = true;
     164                 :            :                 }
     165 [ #  # ][ #  # ]:          0 :                 else if (STRING_NOTFOUND != (nPos = aNewLangTxt.Search( aParagraphLangPrefix , 0 )))
         [ #  # ][ #  # ]
     166                 :            :                 {
     167                 :            :                     // ... for the current paragraph language
     168 [ #  # ][ #  # ]:          0 :                     aNewLangTxt = aNewLangTxt.Erase( nPos, aParagraphLangPrefix.getLength() );
     169                 :          0 :                     bForSelection = true;
     170                 :          0 :                     bForParagraph = true;
     171                 :            :                 }
     172 [ #  # ][ #  # ]:          0 :                 else if (STRING_NOTFOUND != (nPos = aNewLangTxt.Search( aDocumentLangPrefix , 0 )))
         [ #  # ][ #  # ]
     173                 :            :                 {
     174                 :            :                     // ... as default document language
     175 [ #  # ][ #  # ]:          0 :                     aNewLangTxt = aNewLangTxt.Erase( nPos, aDocumentLangPrefix.getLength() );
     176                 :          0 :                     bForSelection = false;
     177                 :            :                 }
     178                 :            : 
     179         [ #  # ]:          0 :                 if (bForParagraph)
     180                 :            :                 {
     181                 :          0 :                     bRestoreSelection = true;
     182         [ #  # ]:          0 :                     SwLangHelper::SelectPara( rEditView, aSelection );
     183         [ #  # ]:          0 :                     aSelection = pOLV->GetSelection();
     184                 :            :                 }
     185         [ #  # ]:          0 :                 if (!bForSelection) // document language to be changed...
     186                 :            :                 {
     187         [ #  # ]:          0 :                     rSh.StartAction();
     188                 :          0 :                     rSh.LockView( sal_True );
     189         [ #  # ]:          0 :                     rSh.Push();
     190                 :            : 
     191                 :            :                     // prepare to apply new language to all text in document
     192         [ #  # ]:          0 :                     rSh.SelAll();
     193         [ #  # ]:          0 :                     rSh.ExtendedSelectAll();
     194                 :            :                 }
     195                 :            : 
     196 [ #  # ][ #  # ]:          0 :                 if (aNewLangTxt == aStrNone)
     197         [ #  # ]:          0 :                     SwLangHelper::SetLanguage_None( rSh, pOLV, aSelection, bForSelection, aEditAttr );
     198 [ #  # ][ #  # ]:          0 :                 else if (aNewLangTxt == aStrResetLangs)
     199         [ #  # ]:          0 :                     SwLangHelper::ResetLanguages( rSh, pOLV, aSelection, bForSelection );
     200                 :            :                 else
     201         [ #  # ]:          0 :                     SwLangHelper::SetLanguage( rSh, pOLV, aSelection, aNewLangTxt, bForSelection, aEditAttr );
     202                 :            : 
     203                 :            :                 // ugly hack, as it seems that EditView/EditEngine does not update their spellchecking marks
     204                 :            :                 // when setting a new language attribute
     205         [ #  # ]:          0 :                 if (bForSelection)
     206                 :            :                 {
     207                 :          0 :                     const SwViewOption* pVOpt = rView.GetWrtShellPtr()->GetViewOptions();
     208         [ #  # ]:          0 :                     sal_uLong nCntrl = pEditEngine->GetControlWord();
     209                 :            :                     // turn off
     210                 :          0 :                     nCntrl &= ~EE_CNTRL_ONLINESPELLING;
     211         [ #  # ]:          0 :                     pEditEngine->SetControlWord(nCntrl);
     212                 :            : 
     213                 :            :                     //turn back on
     214         [ #  # ]:          0 :                     if (pVOpt->IsOnlineSpell())
     215                 :          0 :                         nCntrl |= EE_CNTRL_ONLINESPELLING;
     216                 :            :                     else
     217                 :          0 :                         nCntrl &= ~EE_CNTRL_ONLINESPELLING;
     218         [ #  # ]:          0 :                     pEditEngine->SetControlWord(nCntrl);
     219                 :            : 
     220         [ #  # ]:          0 :                     pEditEngine->CompleteOnlineSpelling();
     221         [ #  # ]:          0 :                     rEditView.Invalidate();
     222                 :            :                 }
     223                 :            : 
     224         [ #  # ]:          0 :                 if (!bForSelection)
     225                 :            :                 {
     226                 :            :                     // need to release view and restore selection...
     227         [ #  # ]:          0 :                     rSh.Pop( sal_False );
     228                 :          0 :                     rSh.LockView( sal_False );
     229         [ #  # ]:          0 :                     rSh.EndAction();
     230 [ #  # ][ #  # ]:          0 :                 }
     231                 :            :             }
     232                 :            :         }
     233                 :            : 
     234                 :            :         // invalidate slot to get the new language displayed
     235         [ #  # ]:          0 :         pViewFrame->GetBindings().Invalidate( rReq.GetSlot() );
     236                 :            : 
     237         [ #  # ]:          0 :         rReq.Done();
     238 [ #  # ][ #  # ]:          0 :         return bRestoreSelection;
     239                 :            :     }
     240                 :            : 
     241                 :            : 
     242                 :          0 :     void SetLanguage( SwWrtShell &rWrtSh, const String &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet )
     243                 :            :     {
     244         [ #  # ]:          0 :         SetLanguage( rWrtSh, 0 , ESelection(), rLangText, bIsForSelection, rCoreSet );
     245                 :          0 :     }
     246                 :            : 
     247                 :          0 :     void SetLanguage( SwWrtShell &rWrtSh, OutlinerView* pOLV, ESelection aSelection, const String &rLangText, bool bIsForSelection, SfxItemSet &rCoreSet )
     248                 :            :     {
     249         [ #  # ]:          0 :         const LanguageType nLang = SvtLanguageTable().GetType( rLangText );
     250         [ #  # ]:          0 :         if (nLang != LANGUAGE_DONTKNOW)
     251                 :            :         {
     252                 :          0 :             sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage( nLang );
     253                 :            : 
     254         [ #  # ]:          0 :             EditEngine* pEditEngine = pOLV ? pOLV->GetEditView().GetEditEngine() : NULL;
     255                 :            :             OSL_ENSURE( !pOLV || pEditEngine, "OutlinerView without EditEngine???" );
     256                 :            : 
     257                 :            :             //get ScriptType
     258                 :          0 :             sal_uInt16 nLangWhichId = 0;
     259                 :          0 :             bool bIsSingleScriptType = true;
     260   [ #  #  #  # ]:          0 :             switch (nScriptType)
     261                 :            :             {
     262         [ #  # ]:          0 :                 case SCRIPTTYPE_LATIN :    nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE : RES_CHRATR_LANGUAGE; break;
     263         [ #  # ]:          0 :                 case SCRIPTTYPE_ASIAN :    nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CJK : RES_CHRATR_CJK_LANGUAGE; break;
     264         [ #  # ]:          0 :                 case SCRIPTTYPE_COMPLEX :  nLangWhichId = pEditEngine ? EE_CHAR_LANGUAGE_CTL : RES_CHRATR_CTL_LANGUAGE; break;
     265                 :            :                 default:
     266                 :          0 :                     bIsSingleScriptType = false;
     267                 :            :                     OSL_FAIL("unexpected case" );
     268                 :            :             }
     269         [ #  # ]:          0 :             if (bIsSingleScriptType)
     270                 :            :             {
     271                 :            :                 // change language for selection or paragraph
     272                 :            :                 // (for paragraph is handled by previosuly having set the selection to the
     273                 :            :                 // whole paragraph)
     274         [ #  # ]:          0 :                 if (bIsForSelection)
     275                 :            :                 {
     276                 :            :                     // apply language to current selection
     277         [ #  # ]:          0 :                     if (pEditEngine)
     278                 :            :                     {
     279         [ #  # ]:          0 :                         rCoreSet.Put( SvxLanguageItem( nLang, nLangWhichId ));
     280                 :          0 :                         pEditEngine->QuickSetAttribs( rCoreSet, aSelection);
     281                 :            :                     }
     282                 :            :                     else
     283                 :            :                     {
     284                 :          0 :                         rWrtSh.GetCurAttr( rCoreSet );
     285         [ #  # ]:          0 :                         rCoreSet.Put( SvxLanguageItem( nLang, nLangWhichId ));
     286                 :          0 :                         rWrtSh.SetAttr( rCoreSet );
     287                 :            :                     }
     288                 :            :                 }
     289                 :            :                 else // change language for all text
     290                 :            :                 {
     291                 :            :                     // set document default language
     292   [ #  #  #  # ]:          0 :                     switch (nLangWhichId)
     293                 :            :                     {
     294                 :          0 :                          case EE_CHAR_LANGUAGE :      nLangWhichId = RES_CHRATR_LANGUAGE; break;
     295                 :          0 :                          case EE_CHAR_LANGUAGE_CJK :  nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
     296                 :          0 :                          case EE_CHAR_LANGUAGE_CTL :  nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
     297                 :            :                     }
     298                 :            :                     //Set the default document language
     299         [ #  # ]:          0 :                     rWrtSh.SetDefault( SvxLanguageItem( nLang, nLangWhichId ) );
     300                 :            : 
     301                 :            :                     //Resolves: fdo#35282 Clear the language from all Text Styles, and
     302                 :            :                     //fallback to default document language
     303                 :          0 :                     const SwTxtFmtColls *pColls = rWrtSh.GetDoc()->GetTxtFmtColls();
     304         [ #  # ]:          0 :                     for(sal_uInt16 i = 0, nCount = pColls->size(); i < nCount; ++i)
     305                 :            :                     {
     306                 :          0 :                         SwTxtFmtColl &rTxtColl = *(*pColls)[ i ];
     307                 :          0 :                         rTxtColl.ResetFmtAttr(nLangWhichId);
     308                 :            :                     }
     309                 :            :                     //Resolves: fdo#35282 Clear the language from all Character Styles,
     310                 :            :                     //and fallback to default document language
     311                 :          0 :                     const SwCharFmts *pCharFmts = rWrtSh.GetDoc()->GetCharFmts();
     312         [ #  # ]:          0 :                     for(sal_uInt16 i = 0, nCount = pCharFmts->size(); i < nCount; ++i)
     313                 :            :                     {
     314                 :          0 :                         SwCharFmt &rCharFmt = *(*pCharFmts)[ i ];
     315                 :          0 :                         rCharFmt.ResetFmtAttr(nLangWhichId);
     316                 :            :                     }
     317                 :            : 
     318                 :            :                     // #i102191: hard set respective language attribute in text document
     319                 :            :                     // (for all text in the document - which should be selected by now...)
     320         [ #  # ]:          0 :                     rWrtSh.SetAttr( SvxLanguageItem( nLang, nLangWhichId ) );
     321                 :            :                 }
     322                 :            :             }
     323                 :            :         }
     324                 :          0 :     }
     325                 :            : 
     326                 :          0 :     void SetLanguage_None( SwWrtShell &rWrtSh, bool bIsForSelection, SfxItemSet &rCoreSet )
     327                 :            :     {
     328         [ #  # ]:          0 :         SetLanguage_None( rWrtSh,0,ESelection(),bIsForSelection,rCoreSet );
     329                 :          0 :     }
     330                 :            : 
     331                 :          0 :     void SetLanguage_None( SwWrtShell &rWrtSh, OutlinerView* pOLV, ESelection aSelection, bool bIsForSelection, SfxItemSet &rCoreSet )
     332                 :            :     {
     333                 :            :         // EditEngine IDs
     334                 :            :         const sal_uInt16 aLangWhichId_EE[3] =
     335                 :            :         {
     336                 :            :             EE_CHAR_LANGUAGE,
     337                 :            :             EE_CHAR_LANGUAGE_CJK,
     338                 :            :             EE_CHAR_LANGUAGE_CTL
     339                 :          0 :         };
     340                 :            : 
     341                 :            :         // Writewr IDs
     342                 :            :         const sal_uInt16 aLangWhichId_Writer[3] =
     343                 :            :         {
     344                 :            :             RES_CHRATR_LANGUAGE,
     345                 :            :             RES_CHRATR_CJK_LANGUAGE,
     346                 :            :             RES_CHRATR_CTL_LANGUAGE
     347                 :          0 :         };
     348                 :            : 
     349         [ #  # ]:          0 :         if (bIsForSelection)
     350                 :            :         {
     351                 :            :             // change language for selection or paragraph
     352                 :            :             // (for paragraph is handled by previosuly having set the selection to the
     353                 :            :             // whole paragraph)
     354                 :            : 
     355 [ #  # ][ #  # ]:          0 :             EditEngine* pEditEngine = pOLV ? pOLV->GetEditView().GetEditEngine() : NULL;
     356                 :            :             OSL_ENSURE( !pOLV || pEditEngine, "OutlinerView without EditEngine???" );
     357         [ #  # ]:          0 :             if (pEditEngine)
     358                 :            :             {
     359         [ #  # ]:          0 :                 for (sal_uInt16 i = 0; i < 3; ++i)
     360 [ #  # ][ #  # ]:          0 :                     rCoreSet.Put( SvxLanguageItem( LANGUAGE_NONE, aLangWhichId_EE[i] ));
                 [ #  # ]
     361         [ #  # ]:          0 :                 pEditEngine->QuickSetAttribs( rCoreSet, aSelection);
     362                 :            :             }
     363                 :            :             else
     364                 :            :             {
     365         [ #  # ]:          0 :                 rWrtSh.GetCurAttr( rCoreSet );
     366         [ #  # ]:          0 :                 for (sal_uInt16 i = 0; i < 3; ++i)
     367 [ #  # ][ #  # ]:          0 :                     rCoreSet.Put( SvxLanguageItem( LANGUAGE_NONE, aLangWhichId_Writer[i] ));
                 [ #  # ]
     368         [ #  # ]:          0 :                 rWrtSh.SetAttr( rCoreSet );
     369                 :            :             }
     370                 :            :         }
     371                 :            :         else // change language for all text
     372                 :            :         {
     373         [ #  # ]:          0 :             std::set<sal_uInt16> aAttribs;
     374         [ #  # ]:          0 :             for (sal_uInt16 i = 0; i < 3; ++i)
     375                 :            :             {
     376 [ #  # ][ #  # ]:          0 :                 rWrtSh.SetDefault( SvxLanguageItem( LANGUAGE_NONE, aLangWhichId_Writer[i] ) );
                 [ #  # ]
     377         [ #  # ]:          0 :                 aAttribs.insert( aLangWhichId_Writer[i] );
     378                 :            :             }
     379                 :            : 
     380                 :            :             // set all language attributes to default
     381                 :            :             // (for all text in the document - which should be selected by now...)
     382         [ #  # ]:          0 :             rWrtSh.ResetAttr( aAttribs );
     383                 :            :         }
     384                 :          0 :     }
     385                 :            : 
     386                 :          0 :     void ResetLanguages( SwWrtShell &rWrtSh, bool bIsForSelection )
     387                 :            :     {
     388         [ #  # ]:          0 :         ResetLanguages( rWrtSh, 0 , ESelection(), bIsForSelection );
     389                 :          0 :     }
     390                 :            : 
     391                 :          0 :     void ResetLanguages( SwWrtShell &rWrtSh, OutlinerView* pOLV, ESelection aSelection, bool bIsForSelection )
     392                 :            :     {
     393                 :            :         (void) bIsForSelection;
     394                 :            :         (void) aSelection;
     395                 :            : 
     396                 :            :         // reset language for current selection.
     397                 :            :         // The selection should already have been expanded to the whole paragraph or
     398                 :            :         // to all text in the document if those are the ranges where to reset
     399                 :            :         // the language attributes
     400                 :            : 
     401         [ #  # ]:          0 :         if (pOLV)
     402                 :            :         {
     403                 :          0 :             EditView &rEditView = pOLV->GetEditView();
     404                 :          0 :             rEditView.RemoveAttribs( true, EE_CHAR_LANGUAGE );
     405                 :          0 :             rEditView.RemoveAttribs( true, EE_CHAR_LANGUAGE_CJK );
     406                 :          0 :             rEditView.RemoveAttribs( true, EE_CHAR_LANGUAGE_CTL );
     407                 :            :         }
     408                 :            :         else
     409                 :            :         {
     410         [ #  # ]:          0 :             std::set<sal_uInt16> aAttribs;
     411         [ #  # ]:          0 :             aAttribs.insert( RES_CHRATR_LANGUAGE );
     412         [ #  # ]:          0 :             aAttribs.insert( RES_CHRATR_CJK_LANGUAGE );
     413         [ #  # ]:          0 :             aAttribs.insert( RES_CHRATR_CTL_LANGUAGE );
     414         [ #  # ]:          0 :             rWrtSh.ResetAttr( aAttribs );
     415                 :            :         }
     416                 :          0 :     }
     417                 :            : 
     418                 :            : 
     419                 :            :     /// @returns : the language for the selected text that is set for the
     420                 :            :     ///     specified attribute (script type).
     421                 :            :     ///     If there are more than one languages used LANGUAGE_DONTKNOW will be returned.
     422                 :            :     /// @param nLangWhichId : one of
     423                 :            :     ///     RES_CHRATR_LANGUAGE, RES_CHRATR_CJK_LANGUAGE, RES_CHRATR_CTL_LANGUAGE,
     424                 :        598 :     LanguageType GetLanguage( SwWrtShell &rSh, sal_uInt16 nLangWhichId )
     425                 :            :     {
     426 [ +  - ][ +  - ]:        598 :         SfxItemSet aSet( rSh.GetAttrPool(), nLangWhichId, nLangWhichId );
     427         [ +  - ]:        598 :         rSh.GetCurAttr( aSet );
     428                 :            : 
     429 [ +  - ][ +  - ]:        598 :         return GetLanguage(aSet,nLangWhichId);
         [ +  - ][ +  - ]
     430                 :            :     }
     431                 :            : 
     432                 :        598 :     LanguageType GetLanguage( SfxItemSet aSet, sal_uInt16 nLangWhichId )
     433                 :            :     {
     434                 :            : 
     435                 :        598 :         LanguageType nLang = LANGUAGE_SYSTEM;
     436                 :            : 
     437                 :        598 :         const SfxPoolItem *pItem = 0;
     438         [ +  - ]:        598 :         SfxItemState nState = aSet.GetItemState( nLangWhichId, sal_True, &pItem );
     439 [ +  + ][ +  - ]:        598 :         if (nState > SFX_ITEM_DEFAULT && pItem)
     440                 :            :         {
     441                 :            :             // the item is set and can be used
     442         [ -  + ]:          3 :             nLang = (dynamic_cast< const SvxLanguageItem* >(pItem))->GetLanguage();
     443                 :            :         }
     444         [ +  - ]:        595 :         else if (nState == SFX_ITEM_DEFAULT)
     445                 :            :         {
     446                 :            :             // since the attribute is not set: retrieve the default value
     447 [ +  - ][ +  - ]:        595 :             nLang = (dynamic_cast< const SvxLanguageItem& >(aSet.GetPool()->GetDefaultItem( nLangWhichId ))).GetLanguage();
     448                 :            :         }
     449         [ #  # ]:          0 :         else if (nState == SFX_ITEM_DONTCARE)
     450                 :            :         {
     451                 :            :             // there is more than one language...
     452                 :          0 :             nLang = LANGUAGE_DONTKNOW;
     453                 :            :         }
     454                 :            :         OSL_ENSURE( nLang != LANGUAGE_SYSTEM, "failed to get the language?" );
     455                 :            : 
     456                 :        598 :         return nLang;
     457                 :            :     }
     458                 :            : 
     459                 :            :     /// @returns: the language in use for the selected text.
     460                 :            :     ///     'In use' means the language(s) matching the script type(s) of the
     461                 :            :     ///     selected text. Or in other words, the language a spell checker would use.
     462                 :            :     ///     If there is more than one language LANGUAGE_DONTKNOW will be returned.
     463                 :        598 :     LanguageType GetCurrentLanguage( SwWrtShell &rSh )
     464                 :            :     {
     465                 :            :         // get all script types used in current selection
     466                 :        598 :         const sal_uInt16 nScriptType = rSh.GetScriptType();
     467                 :            : 
     468                 :            :         //set language attribute to use according to the script type
     469                 :        598 :         sal_uInt16 nLangWhichId = 0;
     470                 :        598 :         bool bIsSingleScriptType = true;
     471   [ +  -  -  - ]:        598 :         switch (nScriptType)
     472                 :            :         {
     473                 :        598 :              case SCRIPTTYPE_LATIN :    nLangWhichId = RES_CHRATR_LANGUAGE; break;
     474                 :          0 :              case SCRIPTTYPE_ASIAN :    nLangWhichId = RES_CHRATR_CJK_LANGUAGE; break;
     475                 :          0 :              case SCRIPTTYPE_COMPLEX :  nLangWhichId = RES_CHRATR_CTL_LANGUAGE; break;
     476                 :          0 :              default: bIsSingleScriptType = false; break;
     477                 :            :         }
     478                 :            : 
     479                 :            :         // get language according to the script type(s) in use
     480                 :        598 :         LanguageType nCurrentLang = LANGUAGE_SYSTEM;
     481         [ +  - ]:        598 :         if (bIsSingleScriptType)
     482                 :        598 :             nCurrentLang = GetLanguage( rSh, nLangWhichId );
     483                 :            :         else
     484                 :            :         {
     485                 :            :             // check if all script types are set to LANGUAGE_NONE and return
     486                 :            :             // that if this is the case. Otherwise, having multiple script types
     487                 :            :             // in use always means there are several languages in use...
     488                 :            :             const sal_uInt16 aScriptTypes[3] =
     489                 :            :             {
     490                 :            :                 RES_CHRATR_LANGUAGE,
     491                 :            :                 RES_CHRATR_CJK_LANGUAGE,
     492                 :            :                 RES_CHRATR_CTL_LANGUAGE
     493                 :          0 :             };
     494                 :          0 :             nCurrentLang = LANGUAGE_NONE;
     495         [ #  # ]:          0 :             for (sal_uInt16 i = 0; i < 3; ++i)
     496                 :            :             {
     497         [ #  # ]:          0 :                 LanguageType nTmpLang = GetLanguage( rSh, aScriptTypes[i] );
     498         [ #  # ]:          0 :                 if (nTmpLang != LANGUAGE_NONE)
     499                 :            :                 {
     500                 :          0 :                     nCurrentLang = LANGUAGE_DONTKNOW;
     501                 :          0 :                     break;
     502                 :            :                 }
     503                 :            :             }
     504                 :            :         }
     505                 :            :         OSL_ENSURE( nCurrentLang != LANGUAGE_SYSTEM, "failed to get the language?" );
     506                 :            : 
     507                 :        598 :         return nCurrentLang;
     508                 :            :     }
     509                 :            : 
     510                 :            :     /// @returns: the language in use for the selected text.
     511                 :            :     ///     'In use' means the language(s) matching the script type(s) of the
     512                 :            :     ///     selected text. Or in other words, the language a spell checker would use.
     513                 :            :     ///     If there is more than one language LANGUAGE_DONTKNOW will be returned.
     514                 :          0 :     LanguageType GetCurrentLanguage( SfxItemSet aSet, sal_uInt16 nScriptType )
     515                 :            :     {
     516                 :            :         //set language attribute to use according to the script type
     517                 :          0 :         sal_uInt16 nLangWhichId = 0;
     518                 :          0 :         bool bIsSingleScriptType = true;
     519   [ #  #  #  # ]:          0 :         switch (nScriptType)
     520                 :            :         {
     521                 :          0 :              case SCRIPTTYPE_LATIN :    nLangWhichId = EE_CHAR_LANGUAGE; break;
     522                 :          0 :              case SCRIPTTYPE_ASIAN :    nLangWhichId = EE_CHAR_LANGUAGE_CJK; break;
     523                 :          0 :              case SCRIPTTYPE_COMPLEX :  nLangWhichId = EE_CHAR_LANGUAGE_CTL; break;
     524                 :          0 :              default: bIsSingleScriptType = false;
     525                 :            :         }
     526                 :            : 
     527                 :            :         // get language according to the script type(s) in use
     528                 :          0 :         LanguageType nCurrentLang = LANGUAGE_SYSTEM;
     529         [ #  # ]:          0 :         if (bIsSingleScriptType)
     530         [ #  # ]:          0 :             nCurrentLang = GetLanguage( aSet, nLangWhichId );
     531                 :            :         else
     532                 :            :         {
     533                 :            :             // check if all script types are set to LANGUAGE_NONE and return
     534                 :            :             // that if this is the case. Otherwise, having multiple script types
     535                 :            :             // in use always means there are several languages in use...
     536                 :            :             const sal_uInt16 aScriptTypes[3] =
     537                 :            :             {
     538                 :            :                 EE_CHAR_LANGUAGE,
     539                 :            :                 EE_CHAR_LANGUAGE_CJK,
     540                 :            :                 EE_CHAR_LANGUAGE_CTL
     541                 :          0 :             };
     542                 :          0 :             nCurrentLang = LANGUAGE_NONE;
     543         [ #  # ]:          0 :             for (sal_uInt16 i = 0; i < 3; ++i)
     544                 :            :             {
     545 [ #  # ][ #  # ]:          0 :                 LanguageType nTmpLang = GetLanguage( aSet, aScriptTypes[i] );
                 [ #  # ]
     546         [ #  # ]:          0 :                 if (nTmpLang != LANGUAGE_NONE)
     547                 :            :                 {
     548                 :          0 :                     nCurrentLang = LANGUAGE_DONTKNOW;
     549                 :          0 :                     break;
     550                 :            :                 }
     551                 :            :             }
     552                 :            :         }
     553                 :            :         OSL_ENSURE( nCurrentLang != LANGUAGE_SYSTEM, "failed to get the language?" );
     554                 :            : 
     555                 :          0 :         return nCurrentLang;
     556                 :            :     }
     557                 :            : 
     558                 :        598 :     String GetTextForLanguageGuessing( SwWrtShell &rSh )
     559                 :            :     {
     560                 :            :         // string for guessing language
     561                 :        598 :         String aText;
     562         [ +  - ]:        598 :         SwPaM *pCrsr = rSh.GetCrsr();
     563                 :        598 :         SwTxtNode *pNode = pCrsr->GetNode()->GetTxtNode();
     564         [ +  - ]:        598 :         if (pNode)
     565                 :            :         {
     566         [ +  - ]:        598 :             aText = pNode->GetTxt();
     567         [ +  + ]:        598 :             if (aText.Len() > 0)
     568                 :            :             {
     569                 :        407 :                 xub_StrLen nStt = 0;
     570                 :        407 :                 xub_StrLen nEnd = pCrsr->GetPoint()->nContent.GetIndex();
     571                 :            :                 // at most 100 chars to the left...
     572         [ +  + ]:        407 :                 nStt = nEnd > 100 ? nEnd - 100 : 0;
     573                 :            :                 // ... and 100 to the right of the cursor position
     574         [ -  + ]:        407 :                 nEnd = aText.Len() - nEnd > 100 ? nEnd + 100 : aText.Len();
     575 [ +  - ][ +  - ]:        407 :                 aText = aText.Copy( nStt, nEnd - nStt );
                 [ +  - ]
     576                 :            :             }
     577                 :            :         }
     578                 :        598 :         return aText;
     579                 :            :     }
     580                 :            : 
     581                 :          0 :     String GetTextForLanguageGuessing( EditEngine* rEditEngine, ESelection aDocSelection )
     582                 :            :     {
     583                 :            :         // string for guessing language
     584                 :          0 :         String aText;
     585                 :            : 
     586 [ #  # ][ #  # ]:          0 :         aText = rEditEngine->GetText(aDocSelection);
                 [ #  # ]
     587         [ #  # ]:          0 :         if (aText.Len() > 0)
     588                 :            :         {
     589                 :          0 :             xub_StrLen nStt = 0;
     590                 :          0 :             xub_StrLen nEnd = aDocSelection.nEndPos;
     591                 :            :             // at most 100 chars to the left...
     592         [ #  # ]:          0 :             nStt = nEnd > 100 ? nEnd - 100 : 0;
     593                 :            :             // ... and 100 to the right of the cursor position
     594         [ #  # ]:          0 :             nEnd = aText.Len() - nEnd > 100 ? nEnd + 100 : aText.Len();
     595 [ #  # ][ #  # ]:          0 :             aText = aText.Copy( nStt, nEnd - nStt );
                 [ #  # ]
     596                 :            :         }
     597                 :            : 
     598                 :          0 :         return aText;
     599                 :            :     }
     600                 :            : 
     601                 :            : 
     602                 :          0 :     void SelectPara( EditView &rEditView, const ESelection &rCurSel )
     603                 :            :     {
     604                 :          0 :         ESelection aParaSel( rCurSel.nStartPara, 0, rCurSel.nStartPara, USHRT_MAX );
     605         [ #  # ]:          0 :         rEditView.SetSelection( aParaSel );
     606                 :          0 :     }
     607                 :            : 
     608                 :          0 :     void SelectCurrentPara( SwWrtShell &rWrtSh )
     609                 :            :     {
     610                 :            :         // select current para
     611         [ #  # ]:          0 :         if (!rWrtSh.IsSttPara())
     612                 :          0 :             rWrtSh.MovePara( fnParaCurr, fnParaStart );
     613         [ #  # ]:          0 :         if (!rWrtSh.HasMark())
     614                 :          0 :             rWrtSh.SetMark();
     615                 :          0 :         rWrtSh.SwapPam();
     616         [ #  # ]:          0 :         if (!rWrtSh.IsEndPara())
     617                 :          0 :             rWrtSh.MovePara( fnParaCurr, fnParaEnd );
     618                 :            :     #if OSL_DEBUG_LEVEL > 1
     619                 :            :         String aSelTxt;
     620                 :            :         rWrtSh.GetSelectedText( aSelTxt );
     621                 :            :         (void) aSelTxt;
     622                 :            :     #endif
     623                 :          0 :     }
     624                 :            : }
     625                 :            : 
     626                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10