LCOV - code coverage report
Current view: top level - cui/source/options - optasian.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 225 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 22 0.0 %
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 <dialmgr.hxx>
      25             : #include <cuires.hrc>
      26             : #include <i18nlangtag/mslangid.hxx>
      27             : #include <svl/asiancfg.hxx>
      28             : #include <com/sun/star/lang/Locale.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <com/sun/star/i18n/XForbiddenCharacters.hpp>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include <sfx2/viewfrm.hxx>
      33             : #include <sfx2/objsh.hxx>
      34             : #include <vcl/svapp.hxx>
      35             : #include <vcl/settings.hxx>
      36             : #include <comphelper/processfactory.hxx>
      37             : #include <unotools/localedatawrapper.hxx>
      38             : 
      39             : using namespace com::sun::star::uno;
      40             : using namespace com::sun::star::lang;
      41             : using namespace com::sun::star::i18n;
      42             : using namespace com::sun::star::frame;
      43             : using namespace com::sun::star::beans;
      44             : 
      45             : const sal_Char cIsKernAsianPunctuation[] = "IsKernAsianPunctuation";
      46             : const sal_Char cCharacterCompressionType[] = "CharacterCompressionType";
      47             : 
      48             : struct SvxForbiddenChars_Impl
      49             : {
      50             :     ~SvxForbiddenChars_Impl();
      51             : 
      52             :     bool                bRemoved;
      53             :     ForbiddenCharacters*    pCharacters;
      54             : };
      55             : 
      56           0 : SvxForbiddenChars_Impl::~SvxForbiddenChars_Impl()
      57             : {
      58           0 :     delete pCharacters;
      59           0 : }
      60             : 
      61             : typedef ::std::map< LanguageType, SvxForbiddenChars_Impl* > SvxForbiddenCharacterMap_Impl;
      62             : 
      63             : struct SvxAsianLayoutPage_Impl
      64             : {
      65             :     SvxAsianConfig  aConfig;
      66           0 :     SvxAsianLayoutPage_Impl() {}
      67             : 
      68             :     ~SvxAsianLayoutPage_Impl();
      69             : 
      70             :     Reference< XForbiddenCharacters >   xForbidden;
      71             :     Reference< XPropertySet >           xPrSet;
      72             :     Reference< XPropertySetInfo >       xPrSetInfo;
      73             :     SvxForbiddenCharacterMap_Impl       aChangedLanguagesMap;
      74             : 
      75             :     bool                hasForbiddenCharacters(LanguageType eLang);
      76             :     SvxForbiddenChars_Impl* getForbiddenCharacters(LanguageType eLang);
      77             :     void                    addForbiddenCharacters(LanguageType eLang, ForbiddenCharacters* pForbidden);
      78             : };
      79             : 
      80           0 : SvxAsianLayoutPage_Impl::~SvxAsianLayoutPage_Impl()
      81             : {
      82           0 :     SvxForbiddenCharacterMap_Impl::iterator it;
      83           0 :     for( it = aChangedLanguagesMap.begin(); it != aChangedLanguagesMap.end(); ++it )
      84             :     {
      85           0 :         delete it->second;
      86             :     }
      87           0 : }
      88             : 
      89           0 : bool    SvxAsianLayoutPage_Impl::hasForbiddenCharacters(LanguageType eLang)
      90             : {
      91           0 :     return aChangedLanguagesMap.count( eLang );
      92             : }
      93             : 
      94           0 : SvxForbiddenChars_Impl* SvxAsianLayoutPage_Impl::getForbiddenCharacters(LanguageType eLang)
      95             : {
      96           0 :     SvxForbiddenCharacterMap_Impl::iterator it = aChangedLanguagesMap.find( eLang );
      97             :     DBG_ASSERT( ( it != aChangedLanguagesMap.end() ), "language not available");
      98           0 :     if( it != aChangedLanguagesMap.end() )
      99           0 :         return it->second;
     100           0 :     return 0;
     101             : }
     102             : 
     103           0 : void SvxAsianLayoutPage_Impl::addForbiddenCharacters(
     104             :     LanguageType eLang, ForbiddenCharacters* pForbidden)
     105             : {
     106           0 :     SvxForbiddenCharacterMap_Impl::iterator itOld = aChangedLanguagesMap.find( eLang );
     107           0 :     if( itOld == aChangedLanguagesMap.end() )
     108             :     {
     109           0 :         SvxForbiddenChars_Impl* pChar = new SvxForbiddenChars_Impl;
     110           0 :         pChar->bRemoved = 0 == pForbidden;
     111           0 :         pChar->pCharacters = pForbidden ? new ForbiddenCharacters(*pForbidden) : 0;
     112           0 :         aChangedLanguagesMap.insert( ::std::make_pair( eLang, pChar ) );
     113             :     }
     114             :     else
     115             :     {
     116           0 :         itOld->second->bRemoved = 0 == pForbidden;
     117           0 :         delete itOld->second->pCharacters;
     118           0 :         itOld->second->pCharacters = pForbidden ? new ForbiddenCharacters(*pForbidden) : 0;
     119             :     }
     120           0 : }
     121             : 
     122             : static LanguageType eLastUsedLanguageTypeForForbiddenCharacters = USHRT_MAX;
     123             : 
     124           0 : SvxAsianLayoutPage::SvxAsianLayoutPage( vcl::Window* pParent, const SfxItemSet& rSet ) :
     125             :     SfxTabPage(pParent, "OptAsianPage", "cui/ui/optasianpage.ui", &rSet),
     126           0 :     pImpl(new SvxAsianLayoutPage_Impl)
     127             : {
     128           0 :     get(m_pCharKerningRB, "charkerning");
     129           0 :     get(m_pCharPunctKerningRB, "charpunctkerning");
     130           0 :     get(m_pNoCompressionRB, "nocompression");
     131           0 :     get(m_pPunctCompressionRB, "punctcompression");
     132           0 :     get(m_pPunctKanaCompressionRB, "punctkanacompression");
     133           0 :     get(m_pLanguageFT, "languageft");
     134           0 :     get(m_pLanguageLB, "language");
     135           0 :     get(m_pStandardCB, "standard");
     136           0 :     get(m_pStartFT, "startft");
     137           0 :     get(m_pStartED, "start");
     138           0 :     get(m_pEndFT, "endft");
     139           0 :     get(m_pEndED, "end");
     140           0 :     get(m_pHintFT, "hintft");
     141             : 
     142           0 :     LanguageHdl(m_pLanguageLB);
     143           0 :     m_pLanguageLB->SetSelectHdl(LINK(this, SvxAsianLayoutPage, LanguageHdl));
     144           0 :     m_pStandardCB->SetClickHdl(LINK(this, SvxAsianLayoutPage, ChangeStandardHdl));
     145           0 :     Link<> aLk(LINK(this, SvxAsianLayoutPage, ModifyHdl));
     146           0 :     m_pStartED->SetModifyHdl(aLk);
     147           0 :     m_pEndED->SetModifyHdl(aLk);
     148             : 
     149           0 :     m_pLanguageLB->SetLanguageList( SvxLanguageListFlags::FBD_CHARS, false, false );
     150           0 : }
     151             : 
     152           0 : SvxAsianLayoutPage::~SvxAsianLayoutPage()
     153             : {
     154           0 :     disposeOnce();
     155           0 : }
     156             : 
     157           0 : void SvxAsianLayoutPage::dispose()
     158             : {
     159           0 :     delete pImpl;
     160           0 :     pImpl = NULL;
     161           0 :     m_pCharKerningRB.clear();
     162           0 :     m_pCharPunctKerningRB.clear();
     163           0 :     m_pNoCompressionRB.clear();
     164           0 :     m_pPunctCompressionRB.clear();
     165           0 :     m_pPunctKanaCompressionRB.clear();
     166           0 :     m_pLanguageFT.clear();
     167           0 :     m_pLanguageLB.clear();
     168           0 :     m_pStandardCB.clear();
     169           0 :     m_pStartFT.clear();
     170           0 :     m_pStartED.clear();
     171           0 :     m_pEndFT.clear();
     172           0 :     m_pEndED.clear();
     173           0 :     m_pHintFT.clear();
     174           0 :     SfxTabPage::dispose();
     175           0 : }
     176             : 
     177           0 : VclPtr<SfxTabPage> SvxAsianLayoutPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
     178             : {
     179           0 :     return VclPtr<SvxAsianLayoutPage>::Create(pParent, *rAttrSet);
     180             : }
     181             : 
     182           0 : bool SvxAsianLayoutPage::FillItemSet( SfxItemSet* )
     183             : {
     184           0 :     if(m_pCharKerningRB->IsValueChangedFromSaved())
     185             :     {
     186           0 :         pImpl->aConfig.SetKerningWesternTextOnly(m_pCharKerningRB->IsChecked());
     187           0 :         OUString sPunct(cIsKernAsianPunctuation);
     188           0 :         if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sPunct))
     189             :         {
     190           0 :             Any aVal;
     191           0 :             sal_Bool bVal = !m_pCharKerningRB->IsChecked();
     192           0 :             aVal.setValue(&bVal, cppu::UnoType<bool>::get());
     193           0 :             pImpl->xPrSet->setPropertyValue(sPunct, aVal);
     194           0 :         }
     195             :     }
     196             : 
     197           0 :     if(m_pNoCompressionRB->IsValueChangedFromSaved() ||
     198           0 :        m_pPunctCompressionRB->IsValueChangedFromSaved())
     199             :     {
     200           0 :         sal_Int16 nSet = m_pNoCompressionRB->IsChecked() ? 0 :
     201           0 :                             m_pPunctCompressionRB->IsChecked() ? 1 : 2;
     202           0 :         pImpl->aConfig.SetCharDistanceCompression(nSet);
     203           0 :         OUString sCompress(cCharacterCompressionType);
     204           0 :         if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sCompress))
     205             :         {
     206           0 :             Any aVal;
     207           0 :             aVal <<= nSet;
     208           0 :             pImpl->xPrSet->setPropertyValue(sCompress, aVal);
     209           0 :         }
     210             :     }
     211           0 :     pImpl->aConfig.Commit();
     212           0 :     if(pImpl->xForbidden.is())
     213             :     {
     214             :         try
     215             :         {
     216           0 :             SvxForbiddenCharacterMap_Impl::iterator itElem;
     217           0 :             for( itElem = pImpl->aChangedLanguagesMap.begin();
     218           0 :                 itElem != pImpl->aChangedLanguagesMap.end(); ++itElem )
     219             :             {
     220           0 :                 Locale aLocale( LanguageTag::convertToLocale( itElem->first ));
     221           0 :                 if(itElem->second->bRemoved)
     222           0 :                     pImpl->xForbidden->removeForbiddenCharacters( aLocale );
     223           0 :                 else if(itElem->second->pCharacters)
     224           0 :                     pImpl->xForbidden->setForbiddenCharacters( aLocale, *( itElem->second->pCharacters ) );
     225           0 :             }
     226             :         }
     227           0 :         catch (const Exception&)
     228             :         {
     229             :             OSL_FAIL("exception in XForbiddenCharacters");
     230             :         }
     231             :     }
     232           0 :     eLastUsedLanguageTypeForForbiddenCharacters = m_pLanguageLB->GetSelectLanguage();
     233             : 
     234           0 :     return false;
     235             : }
     236             : 
     237           0 : void SvxAsianLayoutPage::Reset( const SfxItemSet* )
     238             : {
     239           0 :     SfxViewFrame* pCurFrm = SfxViewFrame::Current();
     240           0 :     SfxObjectShell* pDocSh = pCurFrm ? pCurFrm->GetObjectShell() : 0;
     241           0 :     Reference< XModel > xModel;
     242           0 :     if(pDocSh)
     243           0 :         xModel = pDocSh->GetModel();
     244           0 :     Reference<XMultiServiceFactory> xFact(xModel, UNO_QUERY);
     245           0 :     if(xFact.is())
     246             :     {
     247           0 :         pImpl->xPrSet = Reference<XPropertySet>(
     248           0 :             xFact->createInstance("com.sun.star.document.Settings"), UNO_QUERY);
     249             :     }
     250           0 :     if( pImpl->xPrSet.is() )
     251           0 :         pImpl->xPrSetInfo = pImpl->xPrSet->getPropertySetInfo();
     252           0 :     OUString sForbidden("ForbiddenCharacters");
     253           0 :     bool bKernWesternText = pImpl->aConfig.IsKerningWesternTextOnly();
     254           0 :     sal_Int16 nCompress = pImpl->aConfig.GetCharDistanceCompression();
     255           0 :     if(pImpl->xPrSetInfo.is())
     256             :     {
     257           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sForbidden))
     258             :         {
     259           0 :             Any aForbidden = pImpl->xPrSet->getPropertyValue(sForbidden);
     260           0 :             aForbidden >>= pImpl->xForbidden;
     261             :         }
     262           0 :         OUString sCompress(cCharacterCompressionType);
     263           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sCompress))
     264             :         {
     265           0 :             Any aVal = pImpl->xPrSet->getPropertyValue(sCompress);
     266           0 :             aVal >>= nCompress;
     267             :         }
     268           0 :         OUString sPunct(cIsKernAsianPunctuation);
     269           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sPunct))
     270             :         {
     271           0 :             Any aVal = pImpl->xPrSet->getPropertyValue(sPunct);
     272           0 :             bKernWesternText = !*static_cast<sal_Bool const *>(aVal.getValue());
     273           0 :         }
     274             :     }
     275             :     else
     276             :     {
     277           0 :         m_pLanguageFT->Enable(false);
     278           0 :         m_pLanguageLB->Enable(false);
     279           0 :         m_pStandardCB->Enable(false);
     280           0 :         m_pStartFT->Enable(false);
     281           0 :         m_pStartED->Enable(false);
     282           0 :         m_pEndFT->Enable(false);
     283           0 :         m_pEndED->Enable(false);
     284           0 :         m_pHintFT->Enable(false);
     285             :     }
     286           0 :     if(bKernWesternText)
     287           0 :         m_pCharKerningRB->Check(true);
     288             :     else
     289           0 :         m_pCharPunctKerningRB->Check(true);
     290           0 :     switch(nCompress)
     291             :     {
     292           0 :         case 0 : m_pNoCompressionRB->Check();        break;
     293           0 :         case 1 : m_pPunctCompressionRB->Check();     break;
     294           0 :         default: m_pPunctKanaCompressionRB->Check();
     295             :     }
     296           0 :     m_pCharKerningRB->SaveValue();
     297           0 :     m_pNoCompressionRB->SaveValue();
     298           0 :     m_pPunctCompressionRB->SaveValue();
     299           0 :     m_pPunctKanaCompressionRB->SaveValue();
     300             : 
     301           0 :     m_pLanguageLB->SelectEntryPos(0);
     302             :     //preselect the system language in the box - if available
     303           0 :     if(USHRT_MAX == eLastUsedLanguageTypeForForbiddenCharacters)
     304             :     {
     305             :         eLastUsedLanguageTypeForForbiddenCharacters =
     306           0 :             Application::GetSettings().GetLanguageTag().getLanguageType();
     307           0 :         if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters))
     308           0 :             eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_SIMPLIFIED;
     309           0 :         else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters))
     310           0 :             eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_TRADITIONAL;
     311             :     }
     312           0 :     m_pLanguageLB->SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters );
     313           0 :     LanguageHdl(m_pLanguageLB);
     314           0 : }
     315             : 
     316           0 : IMPL_LINK_NOARG(SvxAsianLayoutPage, LanguageHdl)
     317             : {
     318             :     //set current value
     319           0 :     LanguageType eSelectLanguage = m_pLanguageLB->GetSelectLanguage();
     320           0 :     LanguageTag aLanguageTag( eSelectLanguage);
     321           0 :     Locale aLocale( aLanguageTag.getLocale());
     322             : 
     323           0 :     OUString sStart, sEnd;
     324             :     bool bAvail;
     325           0 :     if(pImpl->xForbidden.is())
     326             :     {
     327           0 :         bAvail = pImpl->hasForbiddenCharacters(eSelectLanguage);
     328           0 :         if(bAvail)
     329             :         {
     330           0 :             SvxForbiddenChars_Impl* pElement = pImpl->getForbiddenCharacters(eSelectLanguage);
     331           0 :             if(pElement->bRemoved || !pElement->pCharacters)
     332             :             {
     333           0 :                 bAvail = false;
     334             :             }
     335             :             else
     336             :             {
     337           0 :                 sStart = pElement->pCharacters->beginLine;
     338           0 :                 sEnd = pElement->pCharacters->endLine;
     339             :             }
     340             :         }
     341             :         else
     342             :         {
     343             :             try
     344             :             {
     345           0 :                 bAvail = pImpl->xForbidden->hasForbiddenCharacters(aLocale);
     346           0 :                 if(bAvail)
     347             :                 {
     348           0 :                     ForbiddenCharacters aForbidden = pImpl->xForbidden->getForbiddenCharacters( aLocale );
     349           0 :                     sStart = aForbidden.beginLine;
     350           0 :                     sEnd = aForbidden.endLine;
     351             :                 }
     352             :             }
     353           0 :             catch (const Exception&)
     354             :             {
     355             :                 OSL_FAIL("exception in XForbiddenCharacters");
     356             :             }
     357             :         }
     358             :     }
     359             :     else
     360             :     {
     361           0 :         bAvail = pImpl->aConfig.GetStartEndChars( aLocale, sStart, sEnd );
     362             :     }
     363           0 :     if(!bAvail)
     364             :     {
     365           0 :         LocaleDataWrapper aWrap( aLanguageTag );
     366           0 :         ForbiddenCharacters aForbidden = aWrap.getForbiddenCharacters();
     367           0 :         sStart = aForbidden.beginLine;
     368           0 :         sEnd = aForbidden.endLine;
     369             :     }
     370           0 :     m_pStandardCB->Check(!bAvail);
     371           0 :     m_pStartED->Enable(bAvail);
     372           0 :     m_pEndED->Enable(bAvail);
     373           0 :     m_pStartFT->Enable(bAvail);
     374           0 :     m_pEndFT->Enable(bAvail);
     375           0 :     m_pStartED->SetText(sStart);
     376           0 :     m_pEndED->SetText(sEnd);
     377             : 
     378           0 :     return 0;
     379             : }
     380             : 
     381           0 : IMPL_LINK(SvxAsianLayoutPage, ChangeStandardHdl, CheckBox*, pBox)
     382             : {
     383           0 :     bool bCheck = pBox->IsChecked();
     384           0 :     m_pStartED->Enable(!bCheck);
     385           0 :     m_pEndED->Enable(!bCheck);
     386           0 :     m_pStartFT->Enable(!bCheck);
     387           0 :     m_pEndFT->Enable(!bCheck);
     388             : 
     389           0 :     ModifyHdl(m_pStartED);
     390           0 :     return 0;
     391             : }
     392             : 
     393           0 : IMPL_LINK(SvxAsianLayoutPage, ModifyHdl, Edit*, pEdit)
     394             : {
     395           0 :     LanguageType eSelectLanguage = m_pLanguageLB->GetSelectLanguage();
     396           0 :     Locale aLocale( LanguageTag::convertToLocale( eSelectLanguage ));
     397           0 :     OUString sStart = m_pStartED->GetText();
     398           0 :     OUString sEnd = m_pEndED->GetText();
     399           0 :     bool bEnable = pEdit->IsEnabled();
     400           0 :     if(pImpl->xForbidden.is())
     401             :     {
     402             :         try
     403             :         {
     404           0 :             if(bEnable)
     405             :             {
     406           0 :                 ForbiddenCharacters aSet;
     407           0 :                 aSet.beginLine = sStart;
     408           0 :                 aSet.endLine = sEnd;
     409           0 :                 pImpl->addForbiddenCharacters(eSelectLanguage, &aSet);
     410             :             }
     411             :             else
     412           0 :                 pImpl->addForbiddenCharacters(eSelectLanguage, 0);
     413             :         }
     414           0 :         catch (const Exception&)
     415             :         {
     416             :             OSL_FAIL("exception in XForbiddenCharacters");
     417             :         }
     418             :     }
     419           0 :     pImpl->aConfig.SetStartEndChars( aLocale, bEnable ? &sStart : 0, bEnable ? &sEnd : 0);
     420           0 :     return 0;
     421             : }
     422             : 
     423           0 : const sal_uInt16* SvxAsianLayoutPage::GetRanges()
     424             : {
     425             :     //no items are used
     426             :     static const sal_uInt16 pAsianLayoutRanges[] = { 0 };
     427           0 :     return pAsianLayoutRanges;
     428           0 : }
     429             : 
     430             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11