LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - optasian.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 212 0.5 %
Date: 2012-12-27 Functions: 2 21 9.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <map>
      21             : #include <optasian.hxx>
      22             : #include <editeng/langitem.hxx>
      23             : #include <editeng/unolingu.hxx>
      24             : #include <optasian.hrc>
      25             : #include <dialmgr.hxx>
      26             : #include <cuires.hrc>
      27             : #include <i18npool/mslangid.hxx>
      28             : #include <tools/shl.hxx>
      29             : #include <svl/asiancfg.hxx>
      30             : #include <com/sun/star/lang/Locale.hpp>
      31             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32             : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
      33             : #include <com/sun/star/beans/XPropertySet.hpp>
      34             : #include <sfx2/viewfrm.hxx>
      35             : #include <sfx2/objsh.hxx>
      36             : #include <vcl/svapp.hxx>
      37             : #include <comphelper/processfactory.hxx>
      38             : #include <unotools/localedatawrapper.hxx>
      39             : 
      40             : using namespace com::sun::star::uno;
      41             : using namespace com::sun::star::lang;
      42             : using namespace com::sun::star::i18n;
      43             : using namespace com::sun::star::frame;
      44             : using namespace com::sun::star::beans;
      45             : using rtl::OUString;
      46             : 
      47             : const sal_Char cIsKernAsianPunctuation[] = "IsKernAsianPunctuation";
      48             : const sal_Char cCharacterCompressionType[] = "CharacterCompressionType";
      49             : 
      50             : struct SvxForbiddenChars_Impl
      51             : {
      52             :     ~SvxForbiddenChars_Impl();
      53             : 
      54             :     sal_Bool                bRemoved;
      55             :     ForbiddenCharacters*    pCharacters;
      56             : };
      57             : 
      58           0 : SvxForbiddenChars_Impl::~SvxForbiddenChars_Impl()
      59             : {
      60           0 :     delete pCharacters;
      61           0 : }
      62             : 
      63             : typedef ::std::map< LanguageType, SvxForbiddenChars_Impl* > SvxForbiddenCharacterMap_Impl;
      64             : 
      65             : struct SvxAsianLayoutPage_Impl
      66             : {
      67             :     SvxAsianConfig  aConfig;
      68           0 :         SvxAsianLayoutPage_Impl() {}
      69             : 
      70             :     ~SvxAsianLayoutPage_Impl();
      71             : 
      72             :     Reference< XForbiddenCharacters >   xForbidden;
      73             :     Reference< XPropertySet >           xPrSet;
      74             :     Reference< XPropertySetInfo >       xPrSetInfo;
      75             :     SvxForbiddenCharacterMap_Impl       aChangedLanguagesMap;
      76             : 
      77             :     sal_Bool                hasForbiddenCharacters(LanguageType eLang);
      78             :     SvxForbiddenChars_Impl* getForbiddenCharacters(LanguageType eLang);
      79             :     void                    addForbiddenCharacters(LanguageType eLang, ForbiddenCharacters* pForbidden);
      80             : };
      81             : 
      82           0 : SvxAsianLayoutPage_Impl::~SvxAsianLayoutPage_Impl()
      83             : {
      84           0 :     SvxForbiddenCharacterMap_Impl::iterator it;
      85           0 :     for( it = aChangedLanguagesMap.begin(); it != aChangedLanguagesMap.end(); ++it )
      86             :     {
      87           0 :         delete it->second;
      88             :     }
      89           0 : }
      90             : 
      91           0 : sal_Bool    SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang)
      92             : {
      93           0 :     return aChangedLanguagesMap.count( eLang );
      94             : }
      95             : 
      96           0 : SvxForbiddenChars_Impl* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang)
      97             : {
      98           0 :     SvxForbiddenCharacterMap_Impl::iterator it = aChangedLanguagesMap.find( eLang );
      99             :     DBG_ASSERT( ( it != aChangedLanguagesMap.end() ), "language not available");
     100           0 :     if( it != aChangedLanguagesMap.end() )
     101           0 :         return it->second;
     102           0 :     return 0;
     103             : }
     104             : 
     105           0 : void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
     106             :     LanguageType eLang, ForbiddenCharacters* pForbidden)
     107             : {
     108           0 :     SvxForbiddenCharacterMap_Impl::iterator itOld = aChangedLanguagesMap.find( eLang );
     109           0 :     if( itOld == aChangedLanguagesMap.end() )
     110             :     {
     111           0 :         SvxForbiddenChars_Impl* pChar = new SvxForbiddenChars_Impl;
     112           0 :         pChar->bRemoved = 0 == pForbidden;
     113           0 :         pChar->pCharacters = pForbidden ? new ForbiddenCharacters(*pForbidden) : 0;
     114           0 :         aChangedLanguagesMap.insert( ::std::make_pair( eLang, pChar ) );
     115             :     }
     116             :     else
     117             :     {
     118           0 :         itOld->second->bRemoved = 0 == pForbidden;
     119           0 :         delete itOld->second->pCharacters;
     120           0 :         itOld->second->pCharacters = pForbidden ? new ForbiddenCharacters(*pForbidden) : 0;
     121             :     }
     122           0 : }
     123             : 
     124             : static LanguageType eLastUsedLanguageTypeForForbiddenCharacters = USHRT_MAX;
     125             : 
     126           0 : SvxAsianLayoutPage::SvxAsianLayoutPage( Window* pParent, const SfxItemSet& rSet ) :
     127           0 :     SfxTabPage(pParent, CUI_RES( RID_SVXPAGE_ASIAN_LAYOUT ), rSet),
     128           0 :     aKerningGB(             this, CUI_RES(GB_KERNING            )),
     129           0 :     aCharKerningRB(         this, CUI_RES(RB_CHAR_KERNING       )),
     130           0 :     aCharPunctKerningRB(    this, CUI_RES(RB_CHAR_PUNCT     )),
     131           0 :     aCharDistGB(            this, CUI_RES(GB_CHAR_DIST      )),
     132           0 :     aNoCompressionRB(       this, CUI_RES(RB_NO_COMP            )),
     133           0 :     aPunctCompressionRB(    this, CUI_RES(RB_PUNCT_COMP     )),
     134           0 :      aPunctKanaCompressionRB(this, CUI_RES(RB_PUNCT_KANA_COMP   )),
     135           0 :     aStartEndGB(            this, CUI_RES(GB_START_END      )),
     136           0 :     aLanguageFT(            this, CUI_RES(FT_LANGUAGE           )),
     137           0 :     aLanguageLB(            this, CUI_RES(LB_LANGUAGE           )),
     138           0 :     aStandardCB(            this, CUI_RES(CB_STANDARD           )),
     139           0 :     aStartFT(               this, CUI_RES(FT_START          )),
     140           0 :     aStartED(               this, CUI_RES(ED_START          )),
     141           0 :     aEndFT(                 this, CUI_RES(FT_END                )),
     142           0 :     aEndED(                 this, CUI_RES(ED_END                )),
     143           0 :     aHintFT(                this, CUI_RES(FT_HINT               )),
     144           0 :     pImpl(new SvxAsianLayoutPage_Impl)
     145             : {
     146           0 :     FreeResource();
     147           0 :     LanguageHdl(&aLanguageLB);
     148           0 :     aLanguageLB.SetSelectHdl(LINK(this, SvxAsianLayoutPage, LanguageHdl));
     149           0 :     aStandardCB.SetClickHdl(LINK(this, SvxAsianLayoutPage, ChangeStandardHdl));
     150           0 :     Link aLk(LINK(this, SvxAsianLayoutPage, ModifyHdl));
     151           0 :     aStartED.SetModifyHdl(aLk);
     152           0 :     aEndED.SetModifyHdl(aLk);
     153             : 
     154           0 :     aLanguageLB.SetLanguageList( LANG_LIST_FBD_CHARS, sal_False, sal_False );
     155           0 : }
     156             : 
     157           0 : SvxAsianLayoutPage::~SvxAsianLayoutPage()
     158             : {
     159           0 :     delete pImpl;
     160           0 : }
     161             : 
     162           0 : SfxTabPage* SvxAsianLayoutPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
     163             : {
     164           0 :     return new SvxAsianLayoutPage(pParent, rAttrSet);
     165             : }
     166             : 
     167           0 : sal_Bool SvxAsianLayoutPage::FillItemSet( SfxItemSet& )
     168             : {
     169           0 :     if(aCharKerningRB.IsChecked() != aCharKerningRB.GetSavedValue())
     170             :     {
     171           0 :         pImpl->aConfig.SetKerningWesternTextOnly(aCharKerningRB.IsChecked());
     172           0 :         OUString sPunct(cIsKernAsianPunctuation);
     173           0 :         if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sPunct))
     174             :         {
     175           0 :             Any aVal;
     176           0 :             sal_Bool bVal = !aCharKerningRB.IsChecked();
     177           0 :             aVal.setValue(&bVal, ::getBooleanCppuType());
     178           0 :             pImpl->xPrSet->setPropertyValue(sPunct, aVal);
     179           0 :         }
     180             :     }
     181             : 
     182           0 :     if(aNoCompressionRB.IsChecked() != aNoCompressionRB.GetSavedValue() ||
     183           0 :             aPunctCompressionRB.IsChecked() != aPunctCompressionRB.GetSavedValue())
     184             :     {
     185           0 :         sal_Int16 nSet = aNoCompressionRB.IsChecked() ? 0 :
     186           0 :                             aPunctCompressionRB.IsChecked() ? 1 : 2;
     187           0 :         pImpl->aConfig.SetCharDistanceCompression(nSet);
     188           0 :         OUString sCompress(cCharacterCompressionType);
     189           0 :         if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sCompress))
     190             :         {
     191           0 :             Any aVal;
     192           0 :             aVal <<= nSet;
     193           0 :             pImpl->xPrSet->setPropertyValue(sCompress, aVal);
     194           0 :         }
     195             :     }
     196           0 :     pImpl->aConfig.Commit();
     197           0 :     if(pImpl->xForbidden.is())
     198             :     {
     199             :         try
     200             :         {
     201           0 :             SvxForbiddenCharacterMap_Impl::iterator itElem;
     202           0 :             for( itElem = pImpl->aChangedLanguagesMap.begin();
     203           0 :                 itElem != pImpl->aChangedLanguagesMap.end(); ++itElem )
     204             :             {
     205           0 :                 Locale aLocale( LanguageTag( itElem->first ).getLocale());
     206           0 :                 if(itElem->second->bRemoved)
     207           0 :                     pImpl->xForbidden->removeForbiddenCharacters( aLocale );
     208           0 :                 else if(itElem->second->pCharacters)
     209           0 :                     pImpl->xForbidden->setForbiddenCharacters( aLocale, *( itElem->second->pCharacters ) );
     210           0 :             }
     211             :         }
     212           0 :         catch (const Exception&)
     213             :         {
     214             :             OSL_FAIL("exception in XForbiddenCharacters");
     215             :         }
     216             :     }
     217           0 :     eLastUsedLanguageTypeForForbiddenCharacters = aLanguageLB.GetSelectLanguage();
     218             : 
     219           0 :     return sal_False;
     220             : }
     221             : 
     222           0 : void SvxAsianLayoutPage::Reset( const SfxItemSet& )
     223             : {
     224           0 :     SfxViewFrame* pCurFrm = SfxViewFrame::Current();
     225           0 :     SfxObjectShell* pDocSh = pCurFrm ? pCurFrm->GetObjectShell() : 0;
     226           0 :     Reference< XModel > xModel;
     227           0 :     if(pDocSh)
     228           0 :         xModel = pDocSh->GetModel();
     229           0 :     Reference<XMultiServiceFactory> xFact(xModel, UNO_QUERY);
     230           0 :     if(xFact.is())
     231             :     {
     232             :         pImpl->xPrSet = Reference<XPropertySet>(
     233           0 :             xFact->createInstance("com.sun.star.document.Settings"), UNO_QUERY);
     234             :     }
     235           0 :     if( pImpl->xPrSet.is() )
     236           0 :         pImpl->xPrSetInfo = pImpl->xPrSet->getPropertySetInfo();
     237           0 :     OUString sForbidden("ForbiddenCharacters");
     238           0 :     sal_Bool bKernWesternText = pImpl->aConfig.IsKerningWesternTextOnly();
     239           0 :     sal_Int16 nCompress = pImpl->aConfig.GetCharDistanceCompression();
     240           0 :     if(pImpl->xPrSetInfo.is())
     241             :     {
     242           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sForbidden))
     243             :         {
     244           0 :             Any aForbidden = pImpl->xPrSet->getPropertyValue(sForbidden);
     245           0 :             aForbidden >>= pImpl->xForbidden;
     246             :         }
     247           0 :         OUString sCompress(cCharacterCompressionType);
     248           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sCompress))
     249             :         {
     250           0 :             Any aVal = pImpl->xPrSet->getPropertyValue(sCompress);
     251           0 :             aVal >>= nCompress;
     252             :         }
     253           0 :         OUString sPunct(cIsKernAsianPunctuation);
     254           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sPunct))
     255             :         {
     256           0 :             Any aVal = pImpl->xPrSet->getPropertyValue(sPunct);
     257           0 :             bKernWesternText = !*(sal_Bool*)aVal.getValue();
     258           0 :         }
     259             :     }
     260             :     else
     261             :     {
     262           0 :         aStartEndGB.Enable(sal_False);
     263           0 :         aLanguageFT.Enable(sal_False);
     264           0 :         aLanguageLB.Enable(sal_False);
     265           0 :         aStandardCB.Enable(sal_False);
     266           0 :         aStartFT.Enable(sal_False);
     267           0 :         aStartED.Enable(sal_False);
     268           0 :         aEndFT.Enable(sal_False);
     269           0 :         aEndED.Enable(sal_False);
     270           0 :         aHintFT.Enable(sal_False);
     271             :     }
     272           0 :     if(bKernWesternText)
     273           0 :         aCharKerningRB.Check(sal_True);
     274             :     else
     275           0 :         aCharPunctKerningRB.Check(sal_True);
     276           0 :     switch(nCompress)
     277             :     {
     278           0 :         case 0 : aNoCompressionRB.Check();        break;
     279           0 :         case 1 : aPunctCompressionRB.Check();     break;
     280           0 :         default: aPunctKanaCompressionRB.Check();
     281             :     }
     282           0 :     aCharKerningRB.SaveValue();
     283           0 :     aNoCompressionRB.SaveValue();
     284           0 :     aPunctCompressionRB.SaveValue();
     285           0 :     aPunctKanaCompressionRB.SaveValue();
     286             : 
     287           0 :     aLanguageLB.SelectEntryPos(0);
     288             :     //preselect the system language in the box - if available
     289           0 :     if(USHRT_MAX == eLastUsedLanguageTypeForForbiddenCharacters)
     290             :     {
     291             :         eLastUsedLanguageTypeForForbiddenCharacters =
     292           0 :             Application::GetSettings().GetLanguageTag().getLanguageType();
     293           0 :         if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters))
     294           0 :             eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_SIMPLIFIED;
     295           0 :         else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters))
     296           0 :             eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_TRADITIONAL;
     297             :     }
     298           0 :     aLanguageLB.SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters );
     299           0 :     LanguageHdl(&aLanguageLB);
     300           0 : }
     301             : 
     302           0 : IMPL_LINK_NOARG(SvxAsianLayoutPage, LanguageHdl)
     303             : {
     304             :     //set current value
     305           0 :     LanguageType eSelectLanguage = aLanguageLB.GetSelectLanguage();
     306           0 :     LanguageTag aLanguageTag( eSelectLanguage);
     307           0 :     Locale aLocale( aLanguageTag.getLocale());
     308             : 
     309           0 :     OUString sStart, sEnd;
     310             :     sal_Bool bAvail;
     311           0 :     if(pImpl->xForbidden.is())
     312             :     {
     313           0 :         bAvail = pImpl->hasForbiddenCharacters(eSelectLanguage);
     314           0 :         if(bAvail)
     315             :         {
     316           0 :             SvxForbiddenChars_Impl* pElement = pImpl->getForbiddenCharacters(eSelectLanguage);
     317           0 :             if(pElement->bRemoved || !pElement->pCharacters)
     318             :             {
     319           0 :                 bAvail = sal_False;
     320             :             }
     321             :             else
     322             :             {
     323           0 :                 sStart = pElement->pCharacters->beginLine;
     324           0 :                 sEnd = pElement->pCharacters->endLine;
     325             :             }
     326             :         }
     327             :         else
     328             :         {
     329             :             try
     330             :             {
     331           0 :                 bAvail = pImpl->xForbidden->hasForbiddenCharacters(aLocale);
     332           0 :                 if(bAvail)
     333             :                 {
     334           0 :                     ForbiddenCharacters aForbidden = pImpl->xForbidden->getForbiddenCharacters( aLocale );
     335           0 :                     sStart = aForbidden.beginLine;
     336           0 :                     sEnd = aForbidden.endLine;
     337             :                 }
     338             :             }
     339           0 :             catch (const Exception&)
     340             :             {
     341             :                 OSL_FAIL("exception in XForbiddenCharacters");
     342             :             }
     343             :         }
     344             :     }
     345             :     else
     346             :     {
     347           0 :         bAvail = pImpl->aConfig.GetStartEndChars( aLocale, sStart, sEnd );
     348             :     }
     349           0 :     if(!bAvail)
     350             :     {
     351           0 :         LocaleDataWrapper aWrap( aLanguageTag );
     352           0 :         ForbiddenCharacters aForbidden = aWrap.getForbiddenCharacters();
     353           0 :         sStart = aForbidden.beginLine;
     354           0 :         sEnd = aForbidden.endLine;
     355             :     }
     356           0 :     aStandardCB.Check(!bAvail);
     357           0 :     aStartED.Enable(bAvail);
     358           0 :     aEndED.Enable(bAvail);
     359           0 :     aStartFT.Enable(bAvail);
     360           0 :     aEndFT.Enable(bAvail);
     361           0 :     aStartED.SetText(sStart);
     362           0 :     aEndED.SetText(sEnd);
     363             : 
     364           0 :     return 0;
     365             : }
     366             : 
     367           0 : IMPL_LINK(SvxAsianLayoutPage, ChangeStandardHdl, CheckBox*, pBox)
     368             : {
     369           0 :     sal_Bool bCheck = pBox->IsChecked();
     370           0 :     aStartED.Enable(!bCheck);
     371           0 :     aEndED.Enable(!bCheck);
     372           0 :     aStartFT.Enable(!bCheck);
     373           0 :     aEndFT.Enable(!bCheck);
     374             : 
     375           0 :     ModifyHdl(&aStartED);
     376           0 :     return 0;
     377             : }
     378             : 
     379           0 : IMPL_LINK(SvxAsianLayoutPage, ModifyHdl, Edit*, pEdit)
     380             : {
     381           0 :     LanguageType eSelectLanguage = aLanguageLB.GetSelectLanguage();
     382           0 :     Locale aLocale( LanguageTag( eSelectLanguage ).getLocale());
     383           0 :     OUString sStart = aStartED.GetText();
     384           0 :     OUString sEnd = aEndED.GetText();
     385           0 :     sal_Bool bEnable = pEdit->IsEnabled();
     386           0 :     if(pImpl->xForbidden.is())
     387             :     {
     388             :         try
     389             :         {
     390           0 :             if(bEnable)
     391             :             {
     392           0 :                 ForbiddenCharacters aSet;
     393           0 :                 aSet.beginLine = sStart;
     394           0 :                 aSet.endLine = sEnd;
     395           0 :                 pImpl->addForbiddenCharacters(eSelectLanguage, &aSet);
     396             :             }
     397             :             else
     398           0 :                 pImpl->addForbiddenCharacters(eSelectLanguage, 0);
     399             :         }
     400           0 :         catch (const Exception&)
     401             :         {
     402             :             OSL_FAIL("exception in XForbiddenCharacters");
     403             :         }
     404             :     }
     405           0 :     pImpl->aConfig.SetStartEndChars( aLocale, bEnable ? &sStart : 0, bEnable ? &sEnd : 0);
     406           0 :     return 0;
     407             : }
     408             : 
     409           0 : sal_uInt16* SvxAsianLayoutPage::GetRanges()
     410             : {
     411             :     //no items are used
     412             :     static sal_uInt16 pAsianLayoutRanges[] = { 0 };
     413           0 :     return pAsianLayoutRanges;
     414           3 : }
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10