LCOV - code coverage report
Current view: top level - cui/source/options - optasian.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 207 0.0 %
Date: 2014-11-03 Functions: 0 21 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( LANG_LIST_FBD_CHARS, false, false );
     150           0 : }
     151             : 
     152           0 : SvxAsianLayoutPage::~SvxAsianLayoutPage()
     153             : {
     154           0 :     delete pImpl;
     155           0 : }
     156             : 
     157           0 : SfxTabPage* SvxAsianLayoutPage::Create( vcl::Window* pParent, const SfxItemSet* rAttrSet )
     158             : {
     159           0 :     return new SvxAsianLayoutPage(pParent, *rAttrSet);
     160             : }
     161             : 
     162           0 : bool SvxAsianLayoutPage::FillItemSet( SfxItemSet* )
     163             : {
     164           0 :     if(m_pCharKerningRB->IsValueChangedFromSaved())
     165             :     {
     166           0 :         pImpl->aConfig.SetKerningWesternTextOnly(m_pCharKerningRB->IsChecked());
     167           0 :         OUString sPunct(cIsKernAsianPunctuation);
     168           0 :         if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sPunct))
     169             :         {
     170           0 :             Any aVal;
     171           0 :             sal_Bool bVal = !m_pCharKerningRB->IsChecked();
     172           0 :             aVal.setValue(&bVal, ::getBooleanCppuType());
     173           0 :             pImpl->xPrSet->setPropertyValue(sPunct, aVal);
     174           0 :         }
     175             :     }
     176             : 
     177           0 :     if(m_pNoCompressionRB->IsValueChangedFromSaved() ||
     178           0 :        m_pPunctCompressionRB->IsValueChangedFromSaved())
     179             :     {
     180           0 :         sal_Int16 nSet = m_pNoCompressionRB->IsChecked() ? 0 :
     181           0 :                             m_pPunctCompressionRB->IsChecked() ? 1 : 2;
     182           0 :         pImpl->aConfig.SetCharDistanceCompression(nSet);
     183           0 :         OUString sCompress(cCharacterCompressionType);
     184           0 :         if(pImpl->xPrSetInfo.is() && pImpl->xPrSetInfo->hasPropertyByName(sCompress))
     185             :         {
     186           0 :             Any aVal;
     187           0 :             aVal <<= nSet;
     188           0 :             pImpl->xPrSet->setPropertyValue(sCompress, aVal);
     189           0 :         }
     190             :     }
     191           0 :     pImpl->aConfig.Commit();
     192           0 :     if(pImpl->xForbidden.is())
     193             :     {
     194             :         try
     195             :         {
     196           0 :             SvxForbiddenCharacterMap_Impl::iterator itElem;
     197           0 :             for( itElem = pImpl->aChangedLanguagesMap.begin();
     198           0 :                 itElem != pImpl->aChangedLanguagesMap.end(); ++itElem )
     199             :             {
     200           0 :                 Locale aLocale( LanguageTag::convertToLocale( itElem->first ));
     201           0 :                 if(itElem->second->bRemoved)
     202           0 :                     pImpl->xForbidden->removeForbiddenCharacters( aLocale );
     203           0 :                 else if(itElem->second->pCharacters)
     204           0 :                     pImpl->xForbidden->setForbiddenCharacters( aLocale, *( itElem->second->pCharacters ) );
     205           0 :             }
     206             :         }
     207           0 :         catch (const Exception&)
     208             :         {
     209             :             OSL_FAIL("exception in XForbiddenCharacters");
     210             :         }
     211             :     }
     212           0 :     eLastUsedLanguageTypeForForbiddenCharacters = m_pLanguageLB->GetSelectLanguage();
     213             : 
     214           0 :     return false;
     215             : }
     216             : 
     217           0 : void SvxAsianLayoutPage::Reset( const SfxItemSet* )
     218             : {
     219           0 :     SfxViewFrame* pCurFrm = SfxViewFrame::Current();
     220           0 :     SfxObjectShell* pDocSh = pCurFrm ? pCurFrm->GetObjectShell() : 0;
     221           0 :     Reference< XModel > xModel;
     222           0 :     if(pDocSh)
     223           0 :         xModel = pDocSh->GetModel();
     224           0 :     Reference<XMultiServiceFactory> xFact(xModel, UNO_QUERY);
     225           0 :     if(xFact.is())
     226             :     {
     227           0 :         pImpl->xPrSet = Reference<XPropertySet>(
     228           0 :             xFact->createInstance("com.sun.star.document.Settings"), UNO_QUERY);
     229             :     }
     230           0 :     if( pImpl->xPrSet.is() )
     231           0 :         pImpl->xPrSetInfo = pImpl->xPrSet->getPropertySetInfo();
     232           0 :     OUString sForbidden("ForbiddenCharacters");
     233           0 :     bool bKernWesternText = pImpl->aConfig.IsKerningWesternTextOnly();
     234           0 :     sal_Int16 nCompress = pImpl->aConfig.GetCharDistanceCompression();
     235           0 :     if(pImpl->xPrSetInfo.is())
     236             :     {
     237           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sForbidden))
     238             :         {
     239           0 :             Any aForbidden = pImpl->xPrSet->getPropertyValue(sForbidden);
     240           0 :             aForbidden >>= pImpl->xForbidden;
     241             :         }
     242           0 :         OUString sCompress(cCharacterCompressionType);
     243           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sCompress))
     244             :         {
     245           0 :             Any aVal = pImpl->xPrSet->getPropertyValue(sCompress);
     246           0 :             aVal >>= nCompress;
     247             :         }
     248           0 :         OUString sPunct(cIsKernAsianPunctuation);
     249           0 :         if(pImpl->xPrSetInfo->hasPropertyByName(sPunct))
     250             :         {
     251           0 :             Any aVal = pImpl->xPrSet->getPropertyValue(sPunct);
     252           0 :             bKernWesternText = !*(sal_Bool*)aVal.getValue();
     253           0 :         }
     254             :     }
     255             :     else
     256             :     {
     257           0 :         m_pLanguageFT->Enable(false);
     258           0 :         m_pLanguageLB->Enable(false);
     259           0 :         m_pStandardCB->Enable(false);
     260           0 :         m_pStartFT->Enable(false);
     261           0 :         m_pStartED->Enable(false);
     262           0 :         m_pEndFT->Enable(false);
     263           0 :         m_pEndED->Enable(false);
     264           0 :         m_pHintFT->Enable(false);
     265             :     }
     266           0 :     if(bKernWesternText)
     267           0 :         m_pCharKerningRB->Check(true);
     268             :     else
     269           0 :         m_pCharPunctKerningRB->Check(true);
     270           0 :     switch(nCompress)
     271             :     {
     272           0 :         case 0 : m_pNoCompressionRB->Check();        break;
     273           0 :         case 1 : m_pPunctCompressionRB->Check();     break;
     274           0 :         default: m_pPunctKanaCompressionRB->Check();
     275             :     }
     276           0 :     m_pCharKerningRB->SaveValue();
     277           0 :     m_pNoCompressionRB->SaveValue();
     278           0 :     m_pPunctCompressionRB->SaveValue();
     279           0 :     m_pPunctKanaCompressionRB->SaveValue();
     280             : 
     281           0 :     m_pLanguageLB->SelectEntryPos(0);
     282             :     //preselect the system language in the box - if available
     283           0 :     if(USHRT_MAX == eLastUsedLanguageTypeForForbiddenCharacters)
     284             :     {
     285             :         eLastUsedLanguageTypeForForbiddenCharacters =
     286           0 :             Application::GetSettings().GetLanguageTag().getLanguageType();
     287           0 :         if (MsLangId::isSimplifiedChinese(eLastUsedLanguageTypeForForbiddenCharacters))
     288           0 :             eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_SIMPLIFIED;
     289           0 :         else if (MsLangId::isTraditionalChinese(eLastUsedLanguageTypeForForbiddenCharacters))
     290           0 :             eLastUsedLanguageTypeForForbiddenCharacters = LANGUAGE_CHINESE_TRADITIONAL;
     291             :     }
     292           0 :     m_pLanguageLB->SelectLanguage( eLastUsedLanguageTypeForForbiddenCharacters );
     293           0 :     LanguageHdl(m_pLanguageLB);
     294           0 : }
     295             : 
     296           0 : IMPL_LINK_NOARG(SvxAsianLayoutPage, LanguageHdl)
     297             : {
     298             :     //set current value
     299           0 :     LanguageType eSelectLanguage = m_pLanguageLB->GetSelectLanguage();
     300           0 :     LanguageTag aLanguageTag( eSelectLanguage);
     301           0 :     Locale aLocale( aLanguageTag.getLocale());
     302             : 
     303           0 :     OUString sStart, sEnd;
     304             :     bool bAvail;
     305           0 :     if(pImpl->xForbidden.is())
     306             :     {
     307           0 :         bAvail = pImpl->hasForbiddenCharacters(eSelectLanguage);
     308           0 :         if(bAvail)
     309             :         {
     310           0 :             SvxForbiddenChars_Impl* pElement = pImpl->getForbiddenCharacters(eSelectLanguage);
     311           0 :             if(pElement->bRemoved || !pElement->pCharacters)
     312             :             {
     313           0 :                 bAvail = false;
     314             :             }
     315             :             else
     316             :             {
     317           0 :                 sStart = pElement->pCharacters->beginLine;
     318           0 :                 sEnd = pElement->pCharacters->endLine;
     319             :             }
     320             :         }
     321             :         else
     322             :         {
     323             :             try
     324             :             {
     325           0 :                 bAvail = pImpl->xForbidden->hasForbiddenCharacters(aLocale);
     326           0 :                 if(bAvail)
     327             :                 {
     328           0 :                     ForbiddenCharacters aForbidden = pImpl->xForbidden->getForbiddenCharacters( aLocale );
     329           0 :                     sStart = aForbidden.beginLine;
     330           0 :                     sEnd = aForbidden.endLine;
     331             :                 }
     332             :             }
     333           0 :             catch (const Exception&)
     334             :             {
     335             :                 OSL_FAIL("exception in XForbiddenCharacters");
     336             :             }
     337             :         }
     338             :     }
     339             :     else
     340             :     {
     341           0 :         bAvail = pImpl->aConfig.GetStartEndChars( aLocale, sStart, sEnd );
     342             :     }
     343           0 :     if(!bAvail)
     344             :     {
     345           0 :         LocaleDataWrapper aWrap( aLanguageTag );
     346           0 :         ForbiddenCharacters aForbidden = aWrap.getForbiddenCharacters();
     347           0 :         sStart = aForbidden.beginLine;
     348           0 :         sEnd = aForbidden.endLine;
     349             :     }
     350           0 :     m_pStandardCB->Check(!bAvail);
     351           0 :     m_pStartED->Enable(bAvail);
     352           0 :     m_pEndED->Enable(bAvail);
     353           0 :     m_pStartFT->Enable(bAvail);
     354           0 :     m_pEndFT->Enable(bAvail);
     355           0 :     m_pStartED->SetText(sStart);
     356           0 :     m_pEndED->SetText(sEnd);
     357             : 
     358           0 :     return 0;
     359             : }
     360             : 
     361           0 : IMPL_LINK(SvxAsianLayoutPage, ChangeStandardHdl, CheckBox*, pBox)
     362             : {
     363           0 :     bool bCheck = pBox->IsChecked();
     364           0 :     m_pStartED->Enable(!bCheck);
     365           0 :     m_pEndED->Enable(!bCheck);
     366           0 :     m_pStartFT->Enable(!bCheck);
     367           0 :     m_pEndFT->Enable(!bCheck);
     368             : 
     369           0 :     ModifyHdl(m_pStartED);
     370           0 :     return 0;
     371             : }
     372             : 
     373           0 : IMPL_LINK(SvxAsianLayoutPage, ModifyHdl, Edit*, pEdit)
     374             : {
     375           0 :     LanguageType eSelectLanguage = m_pLanguageLB->GetSelectLanguage();
     376           0 :     Locale aLocale( LanguageTag::convertToLocale( eSelectLanguage ));
     377           0 :     OUString sStart = m_pStartED->GetText();
     378           0 :     OUString sEnd = m_pEndED->GetText();
     379           0 :     bool bEnable = pEdit->IsEnabled();
     380           0 :     if(pImpl->xForbidden.is())
     381             :     {
     382             :         try
     383             :         {
     384           0 :             if(bEnable)
     385             :             {
     386           0 :                 ForbiddenCharacters aSet;
     387           0 :                 aSet.beginLine = sStart;
     388           0 :                 aSet.endLine = sEnd;
     389           0 :                 pImpl->addForbiddenCharacters(eSelectLanguage, &aSet);
     390             :             }
     391             :             else
     392           0 :                 pImpl->addForbiddenCharacters(eSelectLanguage, 0);
     393             :         }
     394           0 :         catch (const Exception&)
     395             :         {
     396             :             OSL_FAIL("exception in XForbiddenCharacters");
     397             :         }
     398             :     }
     399           0 :     pImpl->aConfig.SetStartEndChars( aLocale, bEnable ? &sStart : 0, bEnable ? &sEnd : 0);
     400           0 :     return 0;
     401             : }
     402             : 
     403           0 : const sal_uInt16* SvxAsianLayoutPage::GetRanges()
     404             : {
     405             :     //no items are used
     406             :     static const sal_uInt16 pAsianLayoutRanges[] = { 0 };
     407           0 :     return pAsianLayoutRanges;
     408           0 : }
     409             : 
     410             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10