LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svtools/source/config - htmlcfg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 96 214 44.9 %
Date: 2013-07-09 Functions: 17 32 53.1 %
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             : 
      21             : #include <svtools/htmlcfg.hxx>
      22             : #include <svtools/parhtml.hxx>
      23             : #include <unotools/syslocale.hxx>
      24             : #include <tools/debug.hxx>
      25             : #include <tools/link.hxx>
      26             : #include <sal/macros.h>
      27             : #include <rtl/instance.hxx>
      28             : #include <list>
      29             : 
      30             : // -----------------------------------------------------------------------
      31             : #define HTMLCFG_UNKNOWN_TAGS            0x01
      32             : //#define HTMLCFG_STYLE_SHEETS          0x02
      33             : //#define HTMLCFG_NETSCAPE3             0x04
      34             : #define HTMLCFG_STAR_BASIC              0x08
      35             : #define HTMLCFG_LOCAL_GRF               0x10
      36             : #define HTMLCFG_PRINT_LAYOUT_EXTENSION  0x20
      37             : #define HTMLCFG_IGNORE_FONT_FAMILY      0x40
      38             : #define HTMLCFG_IS_BASIC_WARNING        0x80
      39             : #define HTMLCFG_NUMBERS_ENGLISH_US      0x100
      40             : 
      41             : using namespace utl;
      42             : using namespace com::sun::star::uno;
      43             : 
      44             : 
      45        1015 : struct HtmlOptions_Impl
      46             : {
      47             :     ::std::list<Link> aList;
      48             :     sal_Int32   nFlags;
      49             :     sal_Int32   nExportMode;
      50             :     sal_Int32   aFontSizeArr[HTML_FONT_COUNT];
      51             :     sal_Int32   eEncoding;
      52             :     sal_Bool    bIsEncodingDefault;
      53             : 
      54        1018 :     HtmlOptions_Impl() :
      55             :         nFlags(HTMLCFG_LOCAL_GRF|HTMLCFG_IS_BASIC_WARNING),
      56             :         nExportMode(HTML_CFG_NS40),
      57        1018 :         eEncoding( osl_getThreadTextEncoding() ),
      58        2036 :         bIsEncodingDefault(sal_True)
      59             :     {
      60        1018 :         aFontSizeArr[0] = HTMLFONTSZ1_DFLT;
      61        1018 :         aFontSizeArr[1] = HTMLFONTSZ2_DFLT;
      62        1018 :         aFontSizeArr[2] = HTMLFONTSZ3_DFLT;
      63        1018 :         aFontSizeArr[3] = HTMLFONTSZ4_DFLT;
      64        1018 :         aFontSizeArr[4] = HTMLFONTSZ5_DFLT;
      65        1018 :         aFontSizeArr[5] = HTMLFONTSZ6_DFLT;
      66        1018 :         aFontSizeArr[6] = HTMLFONTSZ7_DFLT;
      67        1018 :     }
      68             : };
      69             : 
      70        1018 : const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
      71             : {
      72        1018 :     static Sequence<OUString> aNames;
      73        1018 :     if(!aNames.getLength())
      74             :     {
      75             :         static const char* aPropNames[] =
      76             :         {
      77             :             "Import/UnknownTag",                    //  0
      78             :             "Import/FontSetting",                   //  1
      79             :             "Import/FontSize/Size_1",               //  2
      80             :             "Import/FontSize/Size_2",               //  3
      81             :             "Import/FontSize/Size_3",               //  4
      82             :             "Import/FontSize/Size_4",               //  5
      83             :             "Import/FontSize/Size_5",               //  6
      84             :             "Import/FontSize/Size_6",               //  7
      85             :             "Import/FontSize/Size_7",               //  8
      86             :             "Export/Browser",                       //  9
      87             :             "Export/Basic",                         //  0
      88             :             "Export/PrintLayout",                   // 11
      89             :             "Export/LocalGraphic",                  // 12
      90             :             "Export/Warning",                       // 13
      91             :             "Export/Encoding",                      // 14
      92             :             "Import/NumbersEnglishUS"               // 15
      93             :         };
      94          56 :         const int nCount = SAL_N_ELEMENTS(aPropNames);
      95          56 :         aNames.realloc(nCount);
      96          56 :         OUString* pNames = aNames.getArray();
      97         952 :         for(int i = 0; i < nCount; i++)
      98         896 :             pNames[i] = OUString::createFromAscii(aPropNames[i]);
      99             :     }
     100        1018 :     return aNames;
     101             : }
     102             : // -----------------------------------------------------------------------
     103        1018 : SvxHtmlOptions::SvxHtmlOptions() :
     104        1018 :     ConfigItem("Office.Common/Filter/HTML")
     105             : {
     106        1018 :     pImp = new HtmlOptions_Impl;
     107        1018 :     Load( GetPropertyNames() );
     108        1018 : }
     109             : 
     110             : // -----------------------------------------------------------------------
     111        2030 : SvxHtmlOptions::~SvxHtmlOptions()
     112             : {
     113        1015 :     delete pImp;
     114        1015 : }
     115             : 
     116        1018 : void SvxHtmlOptions::Load( const Sequence< OUString >& aNames )
     117             : {
     118        1018 :     Sequence<Any> aValues = GetProperties(aNames);
     119        1018 :     const Any* pValues = aValues.getConstArray();
     120             :     DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
     121        1018 :     if(aValues.getLength() == aNames.getLength())
     122             :     {
     123        1018 :         pImp->nFlags = 0;
     124       17306 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     125             :         {
     126       16288 :             if(pValues[nProp].hasValue())
     127             :             {
     128       15270 :                 switch(nProp)
     129             :                 {
     130             :                     case  0:
     131        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     132           0 :                             pImp->nFlags |= HTMLCFG_UNKNOWN_TAGS;
     133        1018 :                     break;//"Import/UnknownTag",
     134             :                     case  1:
     135        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     136           0 :                             pImp->nFlags |= HTMLCFG_IGNORE_FONT_FAMILY;
     137        1018 :                     break;//"Import/FontSetting",
     138        1018 :                     case  2: pValues[nProp] >>= pImp->aFontSizeArr[0]; break;//"Import/FontSize/Size_1",
     139        1018 :                     case  3: pValues[nProp] >>= pImp->aFontSizeArr[1]; break;//"Import/FontSize/Size_2",
     140        1018 :                     case  4: pValues[nProp] >>= pImp->aFontSizeArr[2]; break;//"Import/FontSize/Size_3",
     141        1018 :                     case  5: pValues[nProp] >>= pImp->aFontSizeArr[3]; break;//"Import/FontSize/Size_4",
     142        1018 :                     case  6: pValues[nProp] >>= pImp->aFontSizeArr[4]; break;//"Import/FontSize/Size_5",
     143        1018 :                     case  7: pValues[nProp] >>= pImp->aFontSizeArr[5]; break;//"Import/FontSize/Size_6",
     144        1018 :                     case  8: pValues[nProp] >>= pImp->aFontSizeArr[6]; break;//"Import/FontSize/Size_7",
     145             :                     case  9://"Export/Browser",
     146             :                         {
     147        1018 :                             sal_Int32 nExpMode = 0;
     148        1018 :                             pValues[nProp] >>= nExpMode;
     149        1018 :                             switch( nExpMode )
     150             :                             {
     151           0 :                                 case 1:     nExpMode = HTML_CFG_MSIE;    break;
     152           0 :                                 case 3:     nExpMode = HTML_CFG_WRITER;     break;
     153        1018 :                                 case 4:     nExpMode = HTML_CFG_NS40;       break;
     154           0 :                                 default:    nExpMode = HTML_CFG_NS40;       break;
     155             :                             }
     156             : 
     157        1018 :                             pImp->nExportMode = nExpMode;
     158             :                         }
     159        1018 :                         break;
     160             :                     case 10:
     161        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     162           0 :                             pImp->nFlags |= HTMLCFG_STAR_BASIC;
     163        1018 :                     break;//"Export/Basic",
     164             :                     case 11:
     165        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     166           0 :                             pImp->nFlags |= HTMLCFG_PRINT_LAYOUT_EXTENSION;
     167        1018 :                     break;//"Export/PrintLayout",
     168             :                     case 12:
     169        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     170        1018 :                             pImp->nFlags |= HTMLCFG_LOCAL_GRF;
     171        1018 :                     break;//"Export/LocalGraphic",
     172             :                     case 13:
     173        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     174        1018 :                             pImp->nFlags |= HTMLCFG_IS_BASIC_WARNING;
     175        1018 :                     break;//"Export/Warning"
     176             : 
     177           0 :                     case 14: pValues[nProp] >>= pImp->eEncoding;
     178           0 :                              pImp->bIsEncodingDefault = sal_False;
     179           0 :                     break;//"Export/Encoding"
     180             : 
     181             :                     case 15:
     182        1018 :                         if(*(sal_Bool*)pValues[nProp].getValue())
     183           0 :                             pImp->nFlags |= HTMLCFG_NUMBERS_ENGLISH_US;
     184        1018 :                     break;//"Import/NumbersEnglishUS"
     185             :                 }
     186             :             }
     187             :         }
     188        1018 :     }
     189        1018 : }
     190             : 
     191             : // -----------------------------------------------------------------------
     192           0 : void    SvxHtmlOptions::Commit()
     193             : {
     194           0 :     const Sequence<OUString>& aNames = GetPropertyNames();
     195             : 
     196           0 :     Sequence<Any> aValues(aNames.getLength());
     197           0 :     Any* pValues = aValues.getArray();
     198             : 
     199           0 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     200             :     {
     201           0 :         sal_Bool bSet = sal_False;
     202           0 :         switch(nProp)
     203             :         {
     204           0 :             case  0: bSet = 0 != (pImp->nFlags & HTMLCFG_UNKNOWN_TAGS);break;//"Import/UnknownTag",
     205           0 :             case  1: bSet = 0 != (pImp->nFlags & HTMLCFG_IGNORE_FONT_FAMILY);break;//"Import/FontSetting",
     206           0 :             case  2: pValues[nProp] <<= pImp->aFontSizeArr[0];break;//"Import/FontSize/Size_1",
     207           0 :             case  3: pValues[nProp] <<= pImp->aFontSizeArr[1];break;//"Import/FontSize/Size_2",
     208           0 :             case  4: pValues[nProp] <<= pImp->aFontSizeArr[2];break;//"Import/FontSize/Size_3",
     209           0 :             case  5: pValues[nProp] <<= pImp->aFontSizeArr[3];break;//"Import/FontSize/Size_4",
     210           0 :             case  6: pValues[nProp] <<= pImp->aFontSizeArr[4];break;//"Import/FontSize/Size_5",
     211           0 :             case  7: pValues[nProp] <<= pImp->aFontSizeArr[5];break;//"Import/FontSize/Size_6",
     212           0 :             case  8: pValues[nProp] <<= pImp->aFontSizeArr[6];break;//"Import/FontSize/Size_7",
     213             :             case  9:                //"Export/Browser",
     214             :                 {
     215           0 :                     sal_Int32 nExpMode = pImp->nExportMode;
     216             : 
     217           0 :                     switch( nExpMode )
     218             :                     {
     219           0 :                         case HTML_CFG_MSIE:      nExpMode = 1;   break;
     220           0 :                         case HTML_CFG_WRITER:       nExpMode = 3;   break;
     221           0 :                         case HTML_CFG_NS40:         nExpMode = 4;   break;
     222           0 :                         default:                    nExpMode = 4;   break;  // NS40
     223             :                     }
     224             : 
     225           0 :                     pValues[nProp] <<= nExpMode;
     226           0 :                     break;
     227             :                 }
     228           0 :             case 10: bSet = 0 != (pImp->nFlags & HTMLCFG_STAR_BASIC);break;//"Export/Basic",
     229           0 :             case 11: bSet = 0 != (pImp->nFlags & HTMLCFG_PRINT_LAYOUT_EXTENSION);break;//"Export/PrintLayout",
     230           0 :             case 12: bSet = 0 != (pImp->nFlags & HTMLCFG_LOCAL_GRF);break;//"Export/LocalGraphic",
     231           0 :             case 13: bSet = 0 != (pImp->nFlags & HTMLCFG_IS_BASIC_WARNING);break;//"Export/Warning"
     232             :             case 14:
     233           0 :                 if(!pImp->bIsEncodingDefault)
     234           0 :                     pValues[nProp] <<= pImp->eEncoding;
     235           0 :                 break;//"Export/Encoding",
     236           0 :             case 15: bSet = 0 != (pImp->nFlags & HTMLCFG_NUMBERS_ENGLISH_US);break;//"Import/NumbersEnglishUS"
     237             :         }
     238           0 :         if(nProp < 2 || ( nProp > 9 && nProp < 14 ) || nProp == 15)
     239           0 :             pValues[nProp].setValue(&bSet, ::getCppuBooleanType());
     240             :     }
     241           0 :     PutProperties(aNames, aValues);
     242           0 : }
     243             : 
     244           0 : void SvxHtmlOptions::CallListeners()
     245             : {
     246           0 :     for ( ::std::list<Link>::const_iterator iter = pImp->aList.begin(); iter != pImp->aList.end(); ++iter )
     247           0 :         iter->Call( this );
     248           0 : }
     249             : 
     250             : 
     251           0 : void SvxHtmlOptions::Notify( const com::sun::star::uno::Sequence< OUString >& )
     252             : {
     253           0 :     Load( GetPropertyNames() );
     254           0 :     CallListeners();
     255           0 : }
     256             : 
     257             : // -----------------------------------------------------------------------
     258          28 : sal_uInt16  SvxHtmlOptions::GetFontSize(sal_uInt16 nPos) const
     259             : {
     260          28 :     if(nPos < HTML_FONT_COUNT)
     261          28 :         return (sal_uInt16)pImp->aFontSizeArr[nPos];
     262           0 :     return 0;
     263             : }
     264             : // -----------------------------------------------------------------------
     265           0 : void SvxHtmlOptions::SetFontSize(sal_uInt16 nPos, sal_uInt16 nSize)
     266             : {
     267           0 :     if(nPos < HTML_FONT_COUNT)
     268             :     {
     269           0 :         pImp->aFontSizeArr[nPos] = nSize;
     270           0 :         SetModified();
     271             :     }
     272           0 : }
     273             : 
     274             : // -----------------------------------------------------------------------
     275             : 
     276             : // -----------------------------------------------------------------------
     277             : 
     278             : 
     279           1 : sal_Bool SvxHtmlOptions::IsImportUnknown() const
     280             : {
     281           1 :     return 0 != (pImp->nFlags & HTMLCFG_UNKNOWN_TAGS) ;
     282             : }
     283             : 
     284             : // -----------------------------------------------------------------------
     285             : 
     286             : 
     287           0 : void SvxHtmlOptions::SetImportUnknown(sal_Bool bSet)
     288             : {
     289           0 :     if(bSet)
     290           0 :         pImp->nFlags |= HTMLCFG_UNKNOWN_TAGS;
     291             :     else
     292           0 :         pImp->nFlags &= ~HTMLCFG_UNKNOWN_TAGS;
     293           0 :     SetModified();
     294           0 : }
     295             : 
     296             : // -----------------------------------------------------------------------
     297             : 
     298             : 
     299          12 : sal_uInt16  SvxHtmlOptions::GetExportMode() const
     300             : {
     301          12 :     return (sal_uInt16)pImp->nExportMode;
     302             : }
     303             : 
     304             : // -----------------------------------------------------------------------
     305             : 
     306             : 
     307           0 : void SvxHtmlOptions::SetExportMode(sal_uInt16 nSet)
     308             : {
     309           0 :     if(nSet <= HTML_CFG_MAX )
     310             :     {
     311           0 :         pImp->nExportMode = nSet;
     312           0 :         SetModified();
     313           0 :         CallListeners();
     314             :     }
     315           0 : }
     316             : 
     317             : // -----------------------------------------------------------------------
     318             : 
     319             : 
     320           4 : sal_Bool SvxHtmlOptions::IsStarBasic() const
     321             : {
     322           4 :     return 0 != (pImp->nFlags & HTMLCFG_STAR_BASIC) ;
     323             : }
     324             : 
     325             : // -----------------------------------------------------------------------
     326             : 
     327             : 
     328           0 : void SvxHtmlOptions::SetStarBasic(sal_Bool bSet)
     329             : {
     330           0 :     if(bSet)
     331           0 :         pImp->nFlags |=  HTMLCFG_STAR_BASIC;
     332             :     else
     333           0 :         pImp->nFlags &= ~HTMLCFG_STAR_BASIC;
     334           0 :     SetModified();
     335           0 : }
     336             : 
     337           2 : sal_Bool SvxHtmlOptions::IsSaveGraphicsLocal() const
     338             : {
     339           2 :     return 0 != (pImp->nFlags & HTMLCFG_LOCAL_GRF) ;
     340             : }
     341             : 
     342           0 : void SvxHtmlOptions::SetSaveGraphicsLocal(sal_Bool bSet)
     343             : {
     344           0 :     if(bSet)
     345           0 :         pImp->nFlags |=  HTMLCFG_LOCAL_GRF;
     346             :     else
     347           0 :         pImp->nFlags &= ~HTMLCFG_LOCAL_GRF;
     348           0 :     SetModified();
     349           0 : }
     350             : 
     351           5 : sal_Bool    SvxHtmlOptions::IsPrintLayoutExtension() const
     352             : {
     353           5 :     sal_Bool bRet = 0 != (pImp->nFlags & HTMLCFG_PRINT_LAYOUT_EXTENSION);
     354           5 :     switch( pImp->nExportMode )
     355             :     {
     356             :         case HTML_CFG_MSIE:
     357             :         case HTML_CFG_NS40  :
     358             :         case HTML_CFG_WRITER :
     359           5 :         break;
     360             :         default:
     361           0 :             bRet = sal_False;
     362             :     }
     363           5 :     return bRet;
     364             : }
     365             : 
     366           0 : void    SvxHtmlOptions::SetPrintLayoutExtension(sal_Bool bSet)
     367             : {
     368           0 :     if(bSet)
     369           0 :         pImp->nFlags |=  HTMLCFG_PRINT_LAYOUT_EXTENSION;
     370             :     else
     371           0 :         pImp->nFlags &= ~HTMLCFG_PRINT_LAYOUT_EXTENSION;
     372           0 :     SetModified();
     373           0 : }
     374             : 
     375           1 : sal_Bool SvxHtmlOptions::IsIgnoreFontFamily() const
     376             : {
     377           1 :     return 0 != (pImp->nFlags & HTMLCFG_IGNORE_FONT_FAMILY) ;
     378             : }
     379             : 
     380           0 : void SvxHtmlOptions::SetIgnoreFontFamily(sal_Bool bSet)
     381             : {
     382           0 :     if(bSet)
     383           0 :         pImp->nFlags |=  HTMLCFG_IGNORE_FONT_FAMILY;
     384             :     else
     385           0 :         pImp->nFlags &= ~HTMLCFG_IGNORE_FONT_FAMILY;
     386           0 :     SetModified();
     387           0 : }
     388             : 
     389           2 : sal_Bool SvxHtmlOptions::IsStarBasicWarning() const
     390             : {
     391           2 :     return 0 != (pImp->nFlags & HTMLCFG_IS_BASIC_WARNING) ;
     392             : }
     393             : 
     394           0 : void SvxHtmlOptions::SetStarBasicWarning(sal_Bool bSet)
     395             : {
     396           0 :     if(bSet)
     397           0 :         pImp->nFlags |=  HTMLCFG_IS_BASIC_WARNING;
     398             :     else
     399           0 :         pImp->nFlags &= ~HTMLCFG_IS_BASIC_WARNING;
     400           0 :     SetModified();
     401           0 : }
     402             : 
     403           2 : rtl_TextEncoding SvxHtmlOptions::GetTextEncoding() const
     404             : {
     405             :     rtl_TextEncoding eRet;
     406           2 :     if(pImp->bIsEncodingDefault)
     407           2 :         eRet = SvtSysLocale::GetBestMimeEncoding();
     408             :     else
     409           0 :         eRet = (rtl_TextEncoding)pImp->eEncoding;
     410           2 :     return eRet;
     411             : }
     412             : 
     413           0 : void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc )
     414             : {
     415           0 :     pImp->eEncoding = eEnc;
     416           0 :     pImp->bIsEncodingDefault = sal_False;
     417           0 :     SetModified();
     418           0 : }
     419             : 
     420           0 : sal_Bool SvxHtmlOptions::IsDefaultTextEncoding() const
     421             : {
     422           0 :     return pImp->bIsEncodingDefault;
     423             : }
     424             : 
     425             : namespace
     426             : {
     427             :     class theSvxHtmlOptions : public rtl::Static<SvxHtmlOptions, theSvxHtmlOptions> {};
     428             : }
     429             : 
     430        1629 : SvxHtmlOptions& SvxHtmlOptions::Get()
     431             : {
     432        1629 :     return theSvxHtmlOptions::get();
     433             : }
     434             : 
     435           1 : sal_Bool SvxHtmlOptions::IsNumbersEnglishUS() const
     436             : {
     437           1 :     return 0 != (pImp->nFlags & HTMLCFG_NUMBERS_ENGLISH_US) ;
     438             : }
     439             : 
     440           0 : void SvxHtmlOptions::SetNumbersEnglishUS(sal_Bool bSet)
     441             : {
     442           0 :     if(bSet)
     443           0 :         pImp->nFlags |=  HTMLCFG_NUMBERS_ENGLISH_US;
     444             :     else
     445           0 :         pImp->nFlags &= ~HTMLCFG_NUMBERS_ENGLISH_US;
     446           0 :     SetModified();
     447           0 : }
     448             : 
     449             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10