1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <osl/thread.h>
22 #include <svtools/htmlcfg.hxx>
23 #include <svtools/parhtml.hxx>
24 #include <unotools/syslocale.hxx>
25 #include <tools/debug.hxx>
26 #include <tools/link.hxx>
27 #include <sal/macros.h>
28 #include <rtl/instance.hxx>
32 #define HTMLCFG_UNKNOWN_TAGS 0x01
33 //#define HTMLCFG_STYLE_SHEETS 0x02
34 //#define HTMLCFG_NETSCAPE3 0x04
35 #define HTMLCFG_STAR_BASIC 0x08
36 #define HTMLCFG_LOCAL_GRF 0x10
37 #define HTMLCFG_PRINT_LAYOUT_EXTENSION 0x20
38 #define HTMLCFG_IGNORE_FONT_FAMILY 0x40
39 #define HTMLCFG_IS_BASIC_WARNING 0x80
40 #define HTMLCFG_NUMBERS_ENGLISH_US 0x100
43 using namespace com::sun::star::uno
;
46 struct HtmlOptions_Impl
48 ::std::list
<Link
<>> aList
;
50 sal_Int32 nExportMode
;
51 sal_Int32 aFontSizeArr
[HTML_FONT_COUNT
];
53 bool bIsEncodingDefault
;
56 nFlags(HTMLCFG_LOCAL_GRF
|HTMLCFG_IS_BASIC_WARNING
),
57 nExportMode(HTML_CFG_NS40
),
58 eEncoding( osl_getThreadTextEncoding() ),
59 bIsEncodingDefault(true)
61 aFontSizeArr
[0] = HTMLFONTSZ1_DFLT
;
62 aFontSizeArr
[1] = HTMLFONTSZ2_DFLT
;
63 aFontSizeArr
[2] = HTMLFONTSZ3_DFLT
;
64 aFontSizeArr
[3] = HTMLFONTSZ4_DFLT
;
65 aFontSizeArr
[4] = HTMLFONTSZ5_DFLT
;
66 aFontSizeArr
[5] = HTMLFONTSZ6_DFLT
;
67 aFontSizeArr
[6] = HTMLFONTSZ7_DFLT
;
71 const Sequence
<OUString
>& SvxHtmlOptions::GetPropertyNames()
73 static Sequence
<OUString
> aNames
;
74 if(!aNames
.getLength())
76 static const char* aPropNames
[] =
78 "Import/UnknownTag", // 0
79 "Import/FontSetting", // 1
80 "Import/FontSize/Size_1", // 2
81 "Import/FontSize/Size_2", // 3
82 "Import/FontSize/Size_3", // 4
83 "Import/FontSize/Size_4", // 5
84 "Import/FontSize/Size_5", // 6
85 "Import/FontSize/Size_6", // 7
86 "Import/FontSize/Size_7", // 8
87 "Export/Browser", // 9
89 "Export/PrintLayout", // 11
90 "Export/LocalGraphic", // 12
91 "Export/Warning", // 13
92 "Export/Encoding", // 14
93 "Import/NumbersEnglishUS" // 15
95 const int nCount
= SAL_N_ELEMENTS(aPropNames
);
96 aNames
.realloc(nCount
);
97 OUString
* pNames
= aNames
.getArray();
98 for(int i
= 0; i
< nCount
; i
++)
99 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
104 SvxHtmlOptions::SvxHtmlOptions() :
105 ConfigItem("Office.Common/Filter/HTML")
107 pImp
= new HtmlOptions_Impl
;
108 Load( GetPropertyNames() );
112 SvxHtmlOptions::~SvxHtmlOptions()
117 void SvxHtmlOptions::Load( const Sequence
< OUString
>& aNames
)
119 Sequence
<Any
> aValues
= GetProperties(aNames
);
120 const Any
* pValues
= aValues
.getConstArray();
121 DBG_ASSERT(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
122 if(aValues
.getLength() == aNames
.getLength())
125 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
127 if(pValues
[nProp
].hasValue())
132 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
133 pImp
->nFlags
|= HTMLCFG_UNKNOWN_TAGS
;
134 break;//"Import/UnknownTag",
136 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
137 pImp
->nFlags
|= HTMLCFG_IGNORE_FONT_FAMILY
;
138 break;//"Import/FontSetting",
139 case 2: pValues
[nProp
] >>= pImp
->aFontSizeArr
[0]; break;//"Import/FontSize/Size_1",
140 case 3: pValues
[nProp
] >>= pImp
->aFontSizeArr
[1]; break;//"Import/FontSize/Size_2",
141 case 4: pValues
[nProp
] >>= pImp
->aFontSizeArr
[2]; break;//"Import/FontSize/Size_3",
142 case 5: pValues
[nProp
] >>= pImp
->aFontSizeArr
[3]; break;//"Import/FontSize/Size_4",
143 case 6: pValues
[nProp
] >>= pImp
->aFontSizeArr
[4]; break;//"Import/FontSize/Size_5",
144 case 7: pValues
[nProp
] >>= pImp
->aFontSizeArr
[5]; break;//"Import/FontSize/Size_6",
145 case 8: pValues
[nProp
] >>= pImp
->aFontSizeArr
[6]; break;//"Import/FontSize/Size_7",
146 case 9://"Export/Browser",
148 sal_Int32 nExpMode
= 0;
149 pValues
[nProp
] >>= nExpMode
;
152 case 1: nExpMode
= HTML_CFG_MSIE
; break;
153 case 3: nExpMode
= HTML_CFG_WRITER
; break;
154 case 4: nExpMode
= HTML_CFG_NS40
; break;
155 default: nExpMode
= HTML_CFG_NS40
; break;
158 pImp
->nExportMode
= nExpMode
;
162 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
163 pImp
->nFlags
|= HTMLCFG_STAR_BASIC
;
164 break;//"Export/Basic",
166 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
167 pImp
->nFlags
|= HTMLCFG_PRINT_LAYOUT_EXTENSION
;
168 break;//"Export/PrintLayout",
170 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
171 pImp
->nFlags
|= HTMLCFG_LOCAL_GRF
;
172 break;//"Export/LocalGraphic",
174 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
175 pImp
->nFlags
|= HTMLCFG_IS_BASIC_WARNING
;
176 break;//"Export/Warning"
178 case 14: pValues
[nProp
] >>= pImp
->eEncoding
;
179 pImp
->bIsEncodingDefault
= false;
180 break;//"Export/Encoding"
183 if(*static_cast<sal_Bool
const *>(pValues
[nProp
].getValue()))
184 pImp
->nFlags
|= HTMLCFG_NUMBERS_ENGLISH_US
;
185 break;//"Import/NumbersEnglishUS"
193 void SvxHtmlOptions::ImplCommit()
195 const Sequence
<OUString
>& aNames
= GetPropertyNames();
197 Sequence
<Any
> aValues(aNames
.getLength());
198 Any
* pValues
= aValues
.getArray();
200 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
205 case 0: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_UNKNOWN_TAGS
);break;//"Import/UnknownTag",
206 case 1: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_IGNORE_FONT_FAMILY
);break;//"Import/FontSetting",
207 case 2: pValues
[nProp
] <<= pImp
->aFontSizeArr
[0];break;//"Import/FontSize/Size_1",
208 case 3: pValues
[nProp
] <<= pImp
->aFontSizeArr
[1];break;//"Import/FontSize/Size_2",
209 case 4: pValues
[nProp
] <<= pImp
->aFontSizeArr
[2];break;//"Import/FontSize/Size_3",
210 case 5: pValues
[nProp
] <<= pImp
->aFontSizeArr
[3];break;//"Import/FontSize/Size_4",
211 case 6: pValues
[nProp
] <<= pImp
->aFontSizeArr
[4];break;//"Import/FontSize/Size_5",
212 case 7: pValues
[nProp
] <<= pImp
->aFontSizeArr
[5];break;//"Import/FontSize/Size_6",
213 case 8: pValues
[nProp
] <<= pImp
->aFontSizeArr
[6];break;//"Import/FontSize/Size_7",
214 case 9: //"Export/Browser",
216 sal_Int32 nExpMode
= pImp
->nExportMode
;
220 case HTML_CFG_MSIE
: nExpMode
= 1; break;
221 case HTML_CFG_WRITER
: nExpMode
= 3; break;
222 case HTML_CFG_NS40
: nExpMode
= 4; break;
223 default: nExpMode
= 4; break; // NS40
226 pValues
[nProp
] <<= nExpMode
;
229 case 10: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_STAR_BASIC
);break;//"Export/Basic",
230 case 11: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_PRINT_LAYOUT_EXTENSION
);break;//"Export/PrintLayout",
231 case 12: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_LOCAL_GRF
);break;//"Export/LocalGraphic",
232 case 13: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_IS_BASIC_WARNING
);break;//"Export/Warning"
234 if(!pImp
->bIsEncodingDefault
)
235 pValues
[nProp
] <<= pImp
->eEncoding
;
236 break;//"Export/Encoding",
237 case 15: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_NUMBERS_ENGLISH_US
);break;//"Import/NumbersEnglishUS"
239 if(nProp
< 2 || ( nProp
> 9 && nProp
< 14 ) || nProp
== 15)
240 pValues
[nProp
].setValue(&bSet
, cppu::UnoType
<bool>::get());
242 PutProperties(aNames
, aValues
);
245 void SvxHtmlOptions::CallListeners()
247 for ( ::std::list
<Link
<>>::const_iterator iter
= pImp
->aList
.begin(); iter
!= pImp
->aList
.end(); ++iter
)
252 void SvxHtmlOptions::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
254 Load( GetPropertyNames() );
259 sal_uInt16
SvxHtmlOptions::GetFontSize(sal_uInt16 nPos
) const
261 if(nPos
< HTML_FONT_COUNT
)
262 return (sal_uInt16
)pImp
->aFontSizeArr
[nPos
];
266 void SvxHtmlOptions::SetFontSize(sal_uInt16 nPos
, sal_uInt16 nSize
)
268 if(nPos
< HTML_FONT_COUNT
)
270 pImp
->aFontSizeArr
[nPos
] = nSize
;
280 bool SvxHtmlOptions::IsImportUnknown() const
282 return 0 != (pImp
->nFlags
& HTMLCFG_UNKNOWN_TAGS
) ;
288 void SvxHtmlOptions::SetImportUnknown(bool bSet
)
291 pImp
->nFlags
|= HTMLCFG_UNKNOWN_TAGS
;
293 pImp
->nFlags
&= ~HTMLCFG_UNKNOWN_TAGS
;
300 sal_uInt16
SvxHtmlOptions::GetExportMode() const
302 return (sal_uInt16
)pImp
->nExportMode
;
308 void SvxHtmlOptions::SetExportMode(sal_uInt16 nSet
)
310 if(nSet
<= HTML_CFG_MAX
)
312 pImp
->nExportMode
= nSet
;
321 bool SvxHtmlOptions::IsStarBasic() const
323 return 0 != (pImp
->nFlags
& HTMLCFG_STAR_BASIC
) ;
329 void SvxHtmlOptions::SetStarBasic(bool bSet
)
332 pImp
->nFlags
|= HTMLCFG_STAR_BASIC
;
334 pImp
->nFlags
&= ~HTMLCFG_STAR_BASIC
;
338 bool SvxHtmlOptions::IsSaveGraphicsLocal() const
340 return 0 != (pImp
->nFlags
& HTMLCFG_LOCAL_GRF
) ;
343 void SvxHtmlOptions::SetSaveGraphicsLocal(bool bSet
)
346 pImp
->nFlags
|= HTMLCFG_LOCAL_GRF
;
348 pImp
->nFlags
&= ~HTMLCFG_LOCAL_GRF
;
352 bool SvxHtmlOptions::IsPrintLayoutExtension() const
354 bool bRet
= 0 != (pImp
->nFlags
& HTMLCFG_PRINT_LAYOUT_EXTENSION
);
355 switch( pImp
->nExportMode
)
359 case HTML_CFG_WRITER
:
367 void SvxHtmlOptions::SetPrintLayoutExtension(bool bSet
)
370 pImp
->nFlags
|= HTMLCFG_PRINT_LAYOUT_EXTENSION
;
372 pImp
->nFlags
&= ~HTMLCFG_PRINT_LAYOUT_EXTENSION
;
376 bool SvxHtmlOptions::IsIgnoreFontFamily() const
378 return 0 != (pImp
->nFlags
& HTMLCFG_IGNORE_FONT_FAMILY
) ;
381 void SvxHtmlOptions::SetIgnoreFontFamily(bool bSet
)
384 pImp
->nFlags
|= HTMLCFG_IGNORE_FONT_FAMILY
;
386 pImp
->nFlags
&= ~HTMLCFG_IGNORE_FONT_FAMILY
;
390 bool SvxHtmlOptions::IsStarBasicWarning() const
392 return 0 != (pImp
->nFlags
& HTMLCFG_IS_BASIC_WARNING
) ;
395 void SvxHtmlOptions::SetStarBasicWarning(bool bSet
)
398 pImp
->nFlags
|= HTMLCFG_IS_BASIC_WARNING
;
400 pImp
->nFlags
&= ~HTMLCFG_IS_BASIC_WARNING
;
404 rtl_TextEncoding
SvxHtmlOptions::GetTextEncoding() const
406 rtl_TextEncoding eRet
;
407 if(pImp
->bIsEncodingDefault
)
408 eRet
= SvtSysLocale::GetBestMimeEncoding();
410 eRet
= (rtl_TextEncoding
)pImp
->eEncoding
;
414 void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc
)
416 pImp
->eEncoding
= eEnc
;
417 pImp
->bIsEncodingDefault
= false;
421 bool SvxHtmlOptions::IsDefaultTextEncoding() const
423 return pImp
->bIsEncodingDefault
;
428 class theSvxHtmlOptions
: public rtl::Static
<SvxHtmlOptions
, theSvxHtmlOptions
> {};
431 SvxHtmlOptions
& SvxHtmlOptions::Get()
433 return theSvxHtmlOptions::get();
436 bool SvxHtmlOptions::IsNumbersEnglishUS() const
438 return 0 != (pImp
->nFlags
& HTMLCFG_NUMBERS_ENGLISH_US
) ;
441 void SvxHtmlOptions::SetNumbersEnglishUS(bool bSet
)
444 pImp
->nFlags
|= HTMLCFG_NUMBERS_ENGLISH_US
;
446 pImp
->nFlags
&= ~HTMLCFG_NUMBERS_ENGLISH_US
;
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */