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

Generated by: LCOV version 1.11