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

Generated by: LCOV version 1.10