LCOV - code coverage report
Current view: top level - svx/source/form - fmsrccfg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 125 0.0 %
Date: 2014-04-14 Functions: 0 14 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 "svx/fmsrccfg.hxx"
      21             : #include <com/sun/star/i18n/TransliterationModules.hpp>
      22             : #include <comphelper/processfactory.hxx>
      23             : 
      24             : using namespace ::com::sun::star::uno;
      25             : using namespace ::com::sun::star::i18n;
      26             : 
      27             : namespace svxform
      28             : {
      29             :     // search parameters
      30             : 
      31           0 :     FmSearchParams::FmSearchParams()
      32             :         :nTransliterationFlags( 0 )
      33             :         ,nSearchForType     ( 0 )
      34             :         ,nPosition          ( MATCHING_ANYWHERE )
      35             :         ,nLevOther          ( 2 )
      36             :         ,nLevShorter        ( 2 )
      37             :         ,nLevLonger         ( 2 )
      38             :         ,bLevRelaxed        ( true )
      39             :         ,bAllFields         ( false )
      40             :         ,bUseFormatter      ( true )
      41             :         ,bBackwards         ( false )
      42             :         ,bWildcard          ( false )
      43             :         ,bRegular           ( false )
      44             :         ,bApproxSearch      ( false )
      45           0 :         ,bSoundsLikeCJK     ( false )
      46             :     {
      47             :         nTransliterationFlags =
      48             :                 TransliterationModules_ignoreSpace_ja_JP
      49             :             |   TransliterationModules_ignoreMiddleDot_ja_JP
      50             :             |   TransliterationModules_ignoreProlongedSoundMark_ja_JP
      51             :             |   TransliterationModules_ignoreSeparator_ja_JP
      52           0 :             |   TransliterationModules_IGNORE_CASE;
      53           0 :     }
      54             : 
      55           0 :     bool FmSearchParams::isIgnoreWidthCJK( ) const
      56             :     {
      57           0 :         return 0 != (nTransliterationFlags & TransliterationModules_IGNORE_WIDTH);
      58             :     }
      59             : 
      60           0 :     bool FmSearchParams::isCaseSensitive( ) const
      61             :     {
      62           0 :         return 0 == (nTransliterationFlags & TransliterationModules_IGNORE_CASE);
      63             :     }
      64             : 
      65           0 :     void FmSearchParams::setCaseSensitive( bool _bCase )
      66             :     {
      67           0 :         if ( _bCase )
      68           0 :             nTransliterationFlags &= ~TransliterationModules_IGNORE_CASE;
      69             :         else
      70           0 :             nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
      71           0 :     }
      72             : 
      73             :     // maps from ascii values to int values
      74             : 
      75             :     struct Ascii2Int16
      76             :     {
      77             :         const sal_Char* pAscii;
      78             :         sal_Int16       nValue;
      79             :     };
      80             : 
      81           0 :     static const Ascii2Int16* lcl_getSearchForTypeValueMap()
      82             :     {
      83             :         static const Ascii2Int16 s_aSearchForTypeMap[] =
      84             :         {
      85             :             { "text",       0 },
      86             :             { "null",       1 },
      87             :             { "non-null",   2 },
      88             :             { NULL,         -1 }
      89             :         };
      90           0 :         return s_aSearchForTypeMap;
      91             :     }
      92             : 
      93           0 :     static const Ascii2Int16* lcl_getSearchPositionValueMap()
      94             :     {
      95             :         static const Ascii2Int16 s_aSearchPositionMap[] =
      96             :         {
      97             :             { "anywhere-in-field",      MATCHING_ANYWHERE },
      98             :             { "beginning-of-field",     MATCHING_BEGINNING },
      99             :             { "end-of-field",           MATCHING_END },
     100             :             { "complete-field",         MATCHING_WHOLETEXT },
     101             :             { NULL,                     -1 }
     102             :         };
     103           0 :         return s_aSearchPositionMap;
     104             :     }
     105             : 
     106           0 :     static sal_Int16 lcl_implMapAsciiValue( const OUString& _rAsciiValue, const Ascii2Int16* _pMap )
     107             :     {
     108             :         // search the map for the given ascii value
     109           0 :         const Ascii2Int16* pSearch = _pMap;
     110           0 :         while ( pSearch && pSearch->pAscii )
     111             :         {
     112           0 :             if ( _rAsciiValue.equalsAscii( pSearch->pAscii ) )
     113             :                 // found
     114           0 :                 return pSearch->nValue;
     115           0 :             ++pSearch;
     116             :         }
     117             : 
     118             :         OSL_FAIL("lcl_implMapAsciiValue: could not convert the ascii value " + _rAsciiValue + " !");
     119           0 :         return -1;
     120             :     }
     121             : 
     122           0 :     static const sal_Char* lcl_implMapIntValue( const sal_Int16 _nValue, const Ascii2Int16* _pMap )
     123             :     {
     124             :         // search the map for the given integer value
     125           0 :         const Ascii2Int16* pSearch = _pMap;
     126           0 :         while ( pSearch && pSearch->pAscii )
     127             :         {
     128           0 :             if ( _nValue == pSearch->nValue )
     129             :                 // found
     130           0 :                 return pSearch->pAscii;
     131           0 :             ++pSearch;
     132             :         }
     133             : 
     134             :         OSL_FAIL(
     135             :             (   OString( "lcl_implMapIntValue: could not convert the integer value " )
     136             :             +=  OString::number( _nValue )
     137             :             +=  OString( " !" )
     138             :             ).getStr()
     139             :         );
     140             :         static const sal_Char* s_pDummy = "";
     141             :             // just as a fallback ....
     142           0 :         return s_pDummy;
     143             :     }
     144             : 
     145             :     // class FmSearchConfigItem - a config item that stores search parameters
     146             : 
     147             : #define TA( c )     &c, getCppuType( &c )
     148             : 
     149           0 :     FmSearchConfigItem::FmSearchConfigItem()
     150           0 :         :OConfigurationValueContainer( ::comphelper::getProcessComponentContext(), m_aMutex, "/org.openoffice.Office.DataAccess/FormSearchOptions", CVC_UPDATE_ACCESS | CVC_LAZY_UPDATE, 2 )
     151             :     {
     152             :         // register our members so the data exchange with the node values is done automatically
     153             : 
     154           0 :         registerExchangeLocation( "SearchHistory",                      TA( aHistory ) );
     155           0 :         registerExchangeLocation( "LevenshteinOther",                   TA( nLevOther ) );
     156           0 :         registerExchangeLocation( "LevenshteinShorter",                 TA( nLevShorter ) );
     157           0 :         registerExchangeLocation( "LevenshteinLonger",                  TA( nLevLonger ) );
     158           0 :         registerExchangeLocation( "IsLevenshteinRelaxed",               TA( bLevRelaxed ) );
     159           0 :         registerExchangeLocation( "IsSearchAllFields",                  TA( bAllFields ) );
     160           0 :         registerExchangeLocation( "IsUseFormatter",                     TA( bUseFormatter ) );
     161           0 :         registerExchangeLocation( "IsBackwards",                        TA( bBackwards ) );
     162           0 :         registerExchangeLocation( "IsWildcardSearch",                   TA( bWildcard ) );
     163           0 :         registerExchangeLocation( "IsUseRegularExpression",             TA( bRegular ) );
     164           0 :         registerExchangeLocation( "IsSimilaritySearch",                 TA( bApproxSearch ) );
     165           0 :         registerExchangeLocation( "IsUseAsianOptions",                  TA( bSoundsLikeCJK ) );
     166             : 
     167             :         // the properties which need to be translated
     168           0 :         registerExchangeLocation( "SearchType",                         TA( m_sSearchForType ) );
     169           0 :         registerExchangeLocation( "SearchPosition",                     TA( m_sSearchPosition ) );
     170             : 
     171           0 :         registerExchangeLocation( "IsMatchCase",                        TA( m_bIsMatchCase ) );
     172           0 :         registerExchangeLocation( "Japanese/IsMatchFullHalfWidthForms", TA( m_bIsMatchFullHalfWidthForms ) );
     173           0 :         registerExchangeLocation( "Japanese/IsMatchHiraganaKatakana",   TA( m_bIsMatchHiraganaKatakana ) );
     174           0 :         registerExchangeLocation( "Japanese/IsMatchContractions",       TA( m_bIsMatchContractions ) );
     175           0 :         registerExchangeLocation( "Japanese/IsMatchMinusDashCho-on",    TA( m_bIsMatchMinusDashCho_on ) );
     176           0 :         registerExchangeLocation( "Japanese/IsMatchRepeatCharMarks",    TA( m_bIsMatchRepeatCharMarks ) );
     177           0 :         registerExchangeLocation( "Japanese/IsMatchVariantFormKanji",   TA( m_bIsMatchVariantFormKanji ) );
     178           0 :         registerExchangeLocation( "Japanese/IsMatchOldKanaForms",       TA( m_bIsMatchOldKanaForms ) );
     179           0 :         registerExchangeLocation( "Japanese/IsMatch_DiZi_DuZu",         TA( m_bIsMatch_DiZi_DuZu ) );
     180           0 :         registerExchangeLocation( "Japanese/IsMatch_BaVa_HaFa",         TA( m_bIsMatch_BaVa_HaFa ) );
     181           0 :         registerExchangeLocation( "Japanese/IsMatch_TsiThiChi_DhiZi",   TA( m_bIsMatch_TsiThiChi_DhiZi ) );
     182           0 :         registerExchangeLocation( "Japanese/IsMatch_HyuIyu_ByuVyu",     TA( m_bIsMatch_HyuIyu_ByuVyu ) );
     183           0 :         registerExchangeLocation( "Japanese/IsMatch_SeShe_ZeJe",        TA( m_bIsMatch_SeShe_ZeJe ) );
     184           0 :         registerExchangeLocation( "Japanese/IsMatch_IaIya",             TA( m_bIsMatch_IaIya ) );
     185           0 :         registerExchangeLocation( "Japanese/IsMatch_KiKu",              TA( m_bIsMatch_KiKu ) );
     186           0 :         registerExchangeLocation( "Japanese/IsIgnorePunctuation",       TA( m_bIsIgnorePunctuation ) );
     187           0 :         registerExchangeLocation( "Japanese/IsIgnoreWhitespace",        TA( m_bIsIgnoreWhitespace ) );
     188           0 :         registerExchangeLocation( "Japanese/IsIgnoreProlongedSoundMark",TA( m_bIsIgnoreProlongedSoundMark ) );
     189           0 :         registerExchangeLocation( "Japanese/IsIgnoreMiddleDot",         TA( m_bIsIgnoreMiddleDot ) );
     190             : 
     191           0 :         read( );
     192           0 :     }
     193             : 
     194           0 :     FmSearchConfigItem::~FmSearchConfigItem()
     195             :     {
     196           0 :         commit( );
     197           0 :     }
     198             : 
     199           0 :     void FmSearchConfigItem::implTranslateFromConfig( )
     200             :     {
     201             :         // the search-for string
     202           0 :         nSearchForType = lcl_implMapAsciiValue( m_sSearchForType, lcl_getSearchForTypeValueMap() );
     203             : 
     204             :         // the search position
     205           0 :         nPosition = lcl_implMapAsciiValue( m_sSearchPosition, lcl_getSearchPositionValueMap() );
     206             : 
     207             :         // the transliteration flags
     208           0 :         nTransliterationFlags = 0;
     209             : 
     210           0 :         if ( !m_bIsMatchCase                )   nTransliterationFlags |= TransliterationModules_IGNORE_CASE;
     211           0 :         if ( m_bIsMatchFullHalfWidthForms   )   nTransliterationFlags |= TransliterationModules_IGNORE_WIDTH;
     212           0 :         if ( m_bIsMatchHiraganaKatakana     )   nTransliterationFlags |= TransliterationModules_IGNORE_KANA;
     213           0 :         if ( m_bIsMatchContractions         )   nTransliterationFlags |= TransliterationModules_ignoreSize_ja_JP;
     214           0 :         if ( m_bIsMatchMinusDashCho_on      )   nTransliterationFlags |= TransliterationModules_ignoreMinusSign_ja_JP;
     215           0 :         if ( m_bIsMatchRepeatCharMarks      )   nTransliterationFlags |= TransliterationModules_ignoreIterationMark_ja_JP;
     216           0 :         if ( m_bIsMatchVariantFormKanji     )   nTransliterationFlags |= TransliterationModules_ignoreTraditionalKanji_ja_JP;
     217           0 :         if ( m_bIsMatchOldKanaForms         )   nTransliterationFlags |= TransliterationModules_ignoreTraditionalKana_ja_JP;
     218           0 :         if ( m_bIsMatch_DiZi_DuZu           )   nTransliterationFlags |= TransliterationModules_ignoreZiZu_ja_JP;
     219           0 :         if ( m_bIsMatch_BaVa_HaFa           )   nTransliterationFlags |= TransliterationModules_ignoreBaFa_ja_JP;
     220           0 :         if ( m_bIsMatch_TsiThiChi_DhiZi     )   nTransliterationFlags |= TransliterationModules_ignoreTiJi_ja_JP;
     221           0 :         if ( m_bIsMatch_HyuIyu_ByuVyu       )   nTransliterationFlags |= TransliterationModules_ignoreHyuByu_ja_JP;
     222           0 :         if ( m_bIsMatch_SeShe_ZeJe          )   nTransliterationFlags |= TransliterationModules_ignoreSeZe_ja_JP;
     223           0 :         if ( m_bIsMatch_IaIya               )   nTransliterationFlags |= TransliterationModules_ignoreIandEfollowedByYa_ja_JP;
     224           0 :         if ( m_bIsMatch_KiKu                )   nTransliterationFlags |= TransliterationModules_ignoreKiKuFollowedBySa_ja_JP;
     225             : 
     226           0 :         if ( m_bIsIgnorePunctuation         )   nTransliterationFlags |= TransliterationModules_ignoreSeparator_ja_JP;
     227           0 :         if ( m_bIsIgnoreWhitespace          )   nTransliterationFlags |= TransliterationModules_ignoreSpace_ja_JP;
     228           0 :         if ( m_bIsIgnoreProlongedSoundMark  )   nTransliterationFlags |= TransliterationModules_ignoreProlongedSoundMark_ja_JP;
     229           0 :         if ( m_bIsIgnoreMiddleDot           )   nTransliterationFlags |= TransliterationModules_ignoreMiddleDot_ja_JP;
     230           0 :     }
     231             : 
     232           0 :     void FmSearchConfigItem::implTranslateToConfig( )
     233             :     {
     234             :         // the search-for string
     235           0 :         m_sSearchForType = OUString::createFromAscii( lcl_implMapIntValue( nSearchForType, lcl_getSearchForTypeValueMap() ) );
     236             : 
     237             :         // the search position
     238           0 :         m_sSearchPosition = OUString::createFromAscii( lcl_implMapIntValue( nPosition, lcl_getSearchPositionValueMap() ) );
     239             : 
     240             :         // the transliteration flags
     241             : 
     242           0 :         m_bIsMatchCase                  = ( 0 == ( nTransliterationFlags & TransliterationModules_IGNORE_CASE ) );
     243           0 :         m_bIsMatchFullHalfWidthForms    = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_WIDTH ) );
     244           0 :         m_bIsMatchHiraganaKatakana      = ( 0 != ( nTransliterationFlags & TransliterationModules_IGNORE_KANA ) );
     245           0 :         m_bIsMatchContractions          = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSize_ja_JP ) );
     246           0 :         m_bIsMatchMinusDashCho_on       = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMinusSign_ja_JP ) );
     247           0 :         m_bIsMatchRepeatCharMarks       = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIterationMark_ja_JP ) );
     248           0 :         m_bIsMatchVariantFormKanji      = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKanji_ja_JP ) );
     249           0 :         m_bIsMatchOldKanaForms          = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTraditionalKana_ja_JP ) );
     250           0 :         m_bIsMatch_DiZi_DuZu            = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreZiZu_ja_JP ) );
     251           0 :         m_bIsMatch_BaVa_HaFa            = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreBaFa_ja_JP ) );
     252           0 :         m_bIsMatch_TsiThiChi_DhiZi      = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreTiJi_ja_JP ) );
     253           0 :         m_bIsMatch_HyuIyu_ByuVyu        = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreHyuByu_ja_JP ) );
     254           0 :         m_bIsMatch_SeShe_ZeJe           = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeZe_ja_JP ) );
     255           0 :         m_bIsMatch_IaIya                = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreIandEfollowedByYa_ja_JP ) );
     256           0 :         m_bIsMatch_KiKu                 = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreKiKuFollowedBySa_ja_JP ) );
     257             : 
     258           0 :         m_bIsIgnorePunctuation          = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSeparator_ja_JP ) );
     259           0 :         m_bIsIgnoreWhitespace           = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreSpace_ja_JP ) );
     260           0 :         m_bIsIgnoreProlongedSoundMark   = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreProlongedSoundMark_ja_JP ) );
     261           0 :         m_bIsIgnoreMiddleDot            = ( 0 != ( nTransliterationFlags & TransliterationModules_ignoreMiddleDot_ja_JP ) );
     262           0 :     }
     263             : 
     264           0 :     const FmSearchParams& FmSearchConfigItem::getParams() const
     265             :     {
     266             :         // ensure that the properties which are not stored directly are up-to-date
     267           0 :         const_cast< FmSearchConfigItem* >( this )->implTranslateFromConfig( );
     268             : 
     269             :         // and return our FmSearchParams part
     270           0 :         return *this;
     271             :     }
     272             : 
     273           0 :     void FmSearchConfigItem::setParams( const FmSearchParams& _rParams )
     274             :     {
     275             :         // copy the FmSearchParams part
     276           0 :         *static_cast< FmSearchParams* >( this ) = _rParams;
     277             : 
     278             :         // translate the settings not represented by a direct config value
     279           0 :         implTranslateToConfig();
     280           0 :     }
     281             : 
     282             : }
     283             : 
     284             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10