Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <svtools/htmlcfg.hxx>
31 : : #include <svtools/parhtml.hxx>
32 : : #include <unotools/syslocale.hxx>
33 : : #include <tools/debug.hxx>
34 : : #include <tools/link.hxx>
35 : : #include <sal/macros.h>
36 : : #include <rtl/instance.hxx>
37 : : #include <list>
38 : :
39 : : // -----------------------------------------------------------------------
40 : : #define HTMLCFG_UNKNOWN_TAGS 0x01
41 : : //#define HTMLCFG_STYLE_SHEETS 0x02
42 : : //#define HTMLCFG_NETSCAPE3 0x04
43 : : #define HTMLCFG_STAR_BASIC 0x08
44 : : #define HTMLCFG_LOCAL_GRF 0x10
45 : : #define HTMLCFG_PRINT_LAYOUT_EXTENSION 0x20
46 : : #define HTMLCFG_IGNORE_FONT_FAMILY 0x40
47 : : #define HTMLCFG_IS_BASIC_WARNING 0x80
48 : : #define HTMLCFG_NUMBERS_ENGLISH_US 0x100
49 : :
50 : : using namespace utl;
51 : : using namespace com::sun::star::uno;
52 : :
53 : : using ::rtl::OUString;
54 : :
55 : : #define C2U(cChar) OUString::createFromAscii(cChar)
56 : :
57 : 1500 : struct HtmlOptions_Impl
58 : : {
59 : : ::std::list<Link> aList;
60 : : sal_Int32 nFlags;
61 : : sal_Int32 nExportMode;
62 : : sal_Int32 aFontSizeArr[HTML_FONT_COUNT];
63 : : sal_Int32 eEncoding;
64 : : sal_Bool bIsEncodingDefault;
65 : :
66 : 1591 : HtmlOptions_Impl() :
67 : : nFlags(HTMLCFG_LOCAL_GRF|HTMLCFG_IS_BASIC_WARNING),
68 : : nExportMode(HTML_CFG_NS40),
69 [ + - ]: 1591 : eEncoding( osl_getThreadTextEncoding() ),
70 : 1591 : bIsEncodingDefault(sal_True)
71 : : {
72 : 1591 : aFontSizeArr[0] = HTMLFONTSZ1_DFLT;
73 : 1591 : aFontSizeArr[1] = HTMLFONTSZ2_DFLT;
74 : 1591 : aFontSizeArr[2] = HTMLFONTSZ3_DFLT;
75 : 1591 : aFontSizeArr[3] = HTMLFONTSZ4_DFLT;
76 : 1591 : aFontSizeArr[4] = HTMLFONTSZ5_DFLT;
77 : 1591 : aFontSizeArr[5] = HTMLFONTSZ6_DFLT;
78 : 1591 : aFontSizeArr[6] = HTMLFONTSZ7_DFLT;
79 : 1591 : }
80 : : };
81 : :
82 : 1591 : const Sequence<OUString>& SvxHtmlOptions::GetPropertyNames()
83 : : {
84 [ + + ][ + - ]: 1591 : static Sequence<OUString> aNames;
[ + - ][ # # ]
85 [ + + ]: 1591 : if(!aNames.getLength())
86 : : {
87 : : static const char* aPropNames[] =
88 : : {
89 : : "Import/UnknownTag", // 0
90 : : "Import/FontSetting", // 1
91 : : "Import/FontSize/Size_1", // 2
92 : : "Import/FontSize/Size_2", // 3
93 : : "Import/FontSize/Size_3", // 4
94 : : "Import/FontSize/Size_4", // 5
95 : : "Import/FontSize/Size_5", // 6
96 : : "Import/FontSize/Size_6", // 7
97 : : "Import/FontSize/Size_7", // 8
98 : : "Export/Browser", // 9
99 : : "Export/Basic", // 0
100 : : "Export/PrintLayout", // 11
101 : : "Export/LocalGraphic", // 12
102 : : "Export/Warning", // 13
103 : : "Export/Encoding", // 14
104 : : "Import/NumbersEnglishUS" // 15
105 : : };
106 : 108 : const int nCount = SAL_N_ELEMENTS(aPropNames);
107 : 108 : aNames.realloc(nCount);
108 : 108 : OUString* pNames = aNames.getArray();
109 [ + + ]: 1836 : for(int i = 0; i < nCount; i++)
110 : 1728 : pNames[i] = C2U(aPropNames[i]);
111 : : }
112 : 1591 : return aNames;
113 : : }
114 : : // -----------------------------------------------------------------------
115 : 1591 : SvxHtmlOptions::SvxHtmlOptions() :
116 [ + - ]: 1591 : ConfigItem(C2U("Office.Common/Filter/HTML"))
117 : : {
118 [ + - ][ + - ]: 1591 : pImp = new HtmlOptions_Impl;
119 [ + - ][ + - ]: 1591 : Load( GetPropertyNames() );
120 : 1591 : }
121 : :
122 : : // -----------------------------------------------------------------------
123 : 1500 : SvxHtmlOptions::~SvxHtmlOptions()
124 : : {
125 [ + - ]: 1500 : delete pImp;
126 [ - + ]: 1500 : }
127 : :
128 : 1591 : void SvxHtmlOptions::Load( const Sequence< OUString >& aNames )
129 : : {
130 [ + - ]: 1591 : Sequence<Any> aValues = GetProperties(aNames);
131 : 1591 : const Any* pValues = aValues.getConstArray();
132 : : DBG_ASSERT(aValues.getLength() == aNames.getLength(), "GetProperties failed");
133 [ + - ]: 1591 : if(aValues.getLength() == aNames.getLength())
134 : : {
135 : 1591 : pImp->nFlags = 0;
136 [ + + ]: 27047 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
137 : : {
138 [ + + ]: 25456 : if(pValues[nProp].hasValue())
139 : : {
140 [ + + + + : 23865 : switch(nProp)
+ + + + +
+ + + + +
- + - ]
141 : : {
142 : : case 0:
143 [ - + ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
144 : 0 : pImp->nFlags |= HTMLCFG_UNKNOWN_TAGS;
145 : 1591 : break;//"Import/UnknownTag",
146 : : case 1:
147 [ - + ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
148 : 0 : pImp->nFlags |= HTMLCFG_IGNORE_FONT_FAMILY;
149 : 1591 : break;//"Import/FontSetting",
150 : 1591 : case 2: pValues[nProp] >>= pImp->aFontSizeArr[0]; break;//"Import/FontSize/Size_1",
151 : 1591 : case 3: pValues[nProp] >>= pImp->aFontSizeArr[1]; break;//"Import/FontSize/Size_2",
152 : 1591 : case 4: pValues[nProp] >>= pImp->aFontSizeArr[2]; break;//"Import/FontSize/Size_3",
153 : 1591 : case 5: pValues[nProp] >>= pImp->aFontSizeArr[3]; break;//"Import/FontSize/Size_4",
154 : 1591 : case 6: pValues[nProp] >>= pImp->aFontSizeArr[4]; break;//"Import/FontSize/Size_5",
155 : 1591 : case 7: pValues[nProp] >>= pImp->aFontSizeArr[5]; break;//"Import/FontSize/Size_6",
156 : 1591 : case 8: pValues[nProp] >>= pImp->aFontSizeArr[6]; break;//"Import/FontSize/Size_7",
157 : : case 9://"Export/Browser",
158 : : {
159 : 1591 : sal_Int32 nExpMode = 0;
160 : 1591 : pValues[nProp] >>= nExpMode;
161 [ - - + - ]: 1591 : switch( nExpMode )
162 : : {
163 : 0 : case 1: nExpMode = HTML_CFG_MSIE; break;
164 : 0 : case 3: nExpMode = HTML_CFG_WRITER; break;
165 : 1591 : case 4: nExpMode = HTML_CFG_NS40; break;
166 : 0 : default: nExpMode = HTML_CFG_NS40; break;
167 : : }
168 : :
169 : 1591 : pImp->nExportMode = nExpMode;
170 : : }
171 : 1591 : break;
172 : : case 10:
173 [ - + ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
174 : 0 : pImp->nFlags |= HTMLCFG_STAR_BASIC;
175 : 1591 : break;//"Export/Basic",
176 : : case 11:
177 [ - + ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
178 : 0 : pImp->nFlags |= HTMLCFG_PRINT_LAYOUT_EXTENSION;
179 : 1591 : break;//"Export/PrintLayout",
180 : : case 12:
181 [ + - ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
182 : 1591 : pImp->nFlags |= HTMLCFG_LOCAL_GRF;
183 : 1591 : break;//"Export/LocalGraphic",
184 : : case 13:
185 [ + - ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
186 : 1591 : pImp->nFlags |= HTMLCFG_IS_BASIC_WARNING;
187 : 1591 : break;//"Export/Warning"
188 : :
189 : 0 : case 14: pValues[nProp] >>= pImp->eEncoding;
190 : 0 : pImp->bIsEncodingDefault = sal_False;
191 : 0 : break;//"Export/Encoding"
192 : :
193 : : case 15:
194 [ - + ]: 1591 : if(*(sal_Bool*)pValues[nProp].getValue())
195 : 0 : pImp->nFlags |= HTMLCFG_NUMBERS_ENGLISH_US;
196 : 23865 : break;//"Import/NumbersEnglishUS"
197 : : }
198 : : }
199 : : }
200 [ + - ]: 1591 : }
201 : 1591 : }
202 : :
203 : : // -----------------------------------------------------------------------
204 : 0 : void SvxHtmlOptions::Commit()
205 : : {
206 [ # # ]: 0 : const Sequence<OUString>& aNames = GetPropertyNames();
207 : :
208 [ # # ]: 0 : Sequence<Any> aValues(aNames.getLength());
209 [ # # ]: 0 : Any* pValues = aValues.getArray();
210 : :
211 [ # # ]: 0 : for(int nProp = 0; nProp < aNames.getLength(); nProp++)
212 : : {
213 : 0 : sal_Bool bSet = sal_False;
214 [ # # # # : 0 : switch(nProp)
# # # # #
# # # # #
# # # ]
215 : : {
216 : 0 : case 0: bSet = 0 != (pImp->nFlags & HTMLCFG_UNKNOWN_TAGS);break;//"Import/UnknownTag",
217 : 0 : case 1: bSet = 0 != (pImp->nFlags & HTMLCFG_IGNORE_FONT_FAMILY);break;//"Import/FontSetting",
218 [ # # ]: 0 : case 2: pValues[nProp] <<= pImp->aFontSizeArr[0];break;//"Import/FontSize/Size_1",
219 [ # # ]: 0 : case 3: pValues[nProp] <<= pImp->aFontSizeArr[1];break;//"Import/FontSize/Size_2",
220 [ # # ]: 0 : case 4: pValues[nProp] <<= pImp->aFontSizeArr[2];break;//"Import/FontSize/Size_3",
221 [ # # ]: 0 : case 5: pValues[nProp] <<= pImp->aFontSizeArr[3];break;//"Import/FontSize/Size_4",
222 [ # # ]: 0 : case 6: pValues[nProp] <<= pImp->aFontSizeArr[4];break;//"Import/FontSize/Size_5",
223 [ # # ]: 0 : case 7: pValues[nProp] <<= pImp->aFontSizeArr[5];break;//"Import/FontSize/Size_6",
224 [ # # ]: 0 : case 8: pValues[nProp] <<= pImp->aFontSizeArr[6];break;//"Import/FontSize/Size_7",
225 : : case 9: //"Export/Browser",
226 : : {
227 : 0 : sal_Int32 nExpMode = pImp->nExportMode;
228 : :
229 [ # # # # ]: 0 : switch( nExpMode )
230 : : {
231 : 0 : case HTML_CFG_MSIE: nExpMode = 1; break;
232 : 0 : case HTML_CFG_WRITER: nExpMode = 3; break;
233 : 0 : case HTML_CFG_NS40: nExpMode = 4; break;
234 : 0 : default: nExpMode = 4; break; // NS40
235 : : }
236 : :
237 [ # # ]: 0 : pValues[nProp] <<= nExpMode;
238 : : break;
239 : : }
240 : 0 : case 10: bSet = 0 != (pImp->nFlags & HTMLCFG_STAR_BASIC);break;//"Export/Basic",
241 : 0 : case 11: bSet = 0 != (pImp->nFlags & HTMLCFG_PRINT_LAYOUT_EXTENSION);break;//"Export/PrintLayout",
242 : 0 : case 12: bSet = 0 != (pImp->nFlags & HTMLCFG_LOCAL_GRF);break;//"Export/LocalGraphic",
243 : 0 : case 13: bSet = 0 != (pImp->nFlags & HTMLCFG_IS_BASIC_WARNING);break;//"Export/Warning"
244 : : case 14:
245 [ # # ]: 0 : if(!pImp->bIsEncodingDefault)
246 [ # # ]: 0 : pValues[nProp] <<= pImp->eEncoding;
247 : 0 : break;//"Export/Encoding",
248 : 0 : case 15: bSet = 0 != (pImp->nFlags & HTMLCFG_NUMBERS_ENGLISH_US);break;//"Import/NumbersEnglishUS"
249 : : }
250 [ # # ][ # # ]: 0 : if(nProp < 2 || ( nProp > 9 && nProp < 14 ) || nProp == 15)
[ # # ][ # # ]
251 [ # # ]: 0 : pValues[nProp].setValue(&bSet, ::getCppuBooleanType());
252 : : }
253 [ # # ][ # # ]: 0 : PutProperties(aNames, aValues);
254 : 0 : }
255 : :
256 : 0 : void SvxHtmlOptions::CallListeners()
257 : : {
258 [ # # ][ # # ]: 0 : for ( ::std::list<Link>::const_iterator iter = pImp->aList.begin(); iter != pImp->aList.end(); ++iter )
[ # # ][ # # ]
[ # # ]
259 [ # # ][ # # ]: 0 : iter->Call( this );
260 : 0 : }
261 : :
262 : :
263 : 0 : void SvxHtmlOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
264 : : {
265 : 0 : Load( GetPropertyNames() );
266 : 0 : CallListeners();
267 : 0 : }
268 : :
269 : : // -----------------------------------------------------------------------
270 : 49 : sal_uInt16 SvxHtmlOptions::GetFontSize(sal_uInt16 nPos) const
271 : : {
272 [ + - ]: 49 : if(nPos < HTML_FONT_COUNT)
273 : 49 : return (sal_uInt16)pImp->aFontSizeArr[nPos];
274 : 49 : return 0;
275 : : }
276 : : // -----------------------------------------------------------------------
277 : 0 : void SvxHtmlOptions::SetFontSize(sal_uInt16 nPos, sal_uInt16 nSize)
278 : : {
279 [ # # ]: 0 : if(nPos < HTML_FONT_COUNT)
280 : : {
281 : 0 : pImp->aFontSizeArr[nPos] = nSize;
282 : 0 : SetModified();
283 : : }
284 : 0 : }
285 : :
286 : : // -----------------------------------------------------------------------
287 : :
288 : : // -----------------------------------------------------------------------
289 : :
290 : :
291 : 2 : sal_Bool SvxHtmlOptions::IsImportUnknown() const
292 : : {
293 : 2 : return 0 != (pImp->nFlags & HTMLCFG_UNKNOWN_TAGS) ;
294 : : }
295 : :
296 : : // -----------------------------------------------------------------------
297 : :
298 : :
299 : 0 : void SvxHtmlOptions::SetImportUnknown(sal_Bool bSet)
300 : : {
301 [ # # ]: 0 : if(bSet)
302 : 0 : pImp->nFlags |= HTMLCFG_UNKNOWN_TAGS;
303 : : else
304 : 0 : pImp->nFlags &= ~HTMLCFG_UNKNOWN_TAGS;
305 : 0 : SetModified();
306 : 0 : }
307 : :
308 : : // -----------------------------------------------------------------------
309 : :
310 : :
311 : 20 : sal_uInt16 SvxHtmlOptions::GetExportMode() const
312 : : {
313 : 20 : return (sal_uInt16)pImp->nExportMode;
314 : : }
315 : :
316 : : // -----------------------------------------------------------------------
317 : :
318 : :
319 : 0 : void SvxHtmlOptions::SetExportMode(sal_uInt16 nSet)
320 : : {
321 [ # # ]: 0 : if(nSet <= HTML_CFG_MAX )
322 : : {
323 : 0 : pImp->nExportMode = nSet;
324 : 0 : SetModified();
325 : 0 : CallListeners();
326 : : }
327 : 0 : }
328 : :
329 : : // -----------------------------------------------------------------------
330 : :
331 : :
332 : 4 : sal_Bool SvxHtmlOptions::IsStarBasic() const
333 : : {
334 : 4 : return 0 != (pImp->nFlags & HTMLCFG_STAR_BASIC) ;
335 : : }
336 : :
337 : : // -----------------------------------------------------------------------
338 : :
339 : :
340 : 0 : void SvxHtmlOptions::SetStarBasic(sal_Bool bSet)
341 : : {
342 [ # # ]: 0 : if(bSet)
343 : 0 : pImp->nFlags |= HTMLCFG_STAR_BASIC;
344 : : else
345 : 0 : pImp->nFlags &= ~HTMLCFG_STAR_BASIC;
346 : 0 : SetModified();
347 : 0 : }
348 : :
349 : 2 : sal_Bool SvxHtmlOptions::IsSaveGraphicsLocal() const
350 : : {
351 : 2 : return 0 != (pImp->nFlags & HTMLCFG_LOCAL_GRF) ;
352 : : }
353 : :
354 : 0 : void SvxHtmlOptions::SetSaveGraphicsLocal(sal_Bool bSet)
355 : : {
356 [ # # ]: 0 : if(bSet)
357 : 0 : pImp->nFlags |= HTMLCFG_LOCAL_GRF;
358 : : else
359 : 0 : pImp->nFlags &= ~HTMLCFG_LOCAL_GRF;
360 : 0 : SetModified();
361 : 0 : }
362 : :
363 : 12 : sal_Bool SvxHtmlOptions::IsPrintLayoutExtension() const
364 : : {
365 : 12 : sal_Bool bRet = 0 != (pImp->nFlags & HTMLCFG_PRINT_LAYOUT_EXTENSION);
366 [ + - ]: 12 : switch( pImp->nExportMode )
367 : : {
368 : : case HTML_CFG_MSIE:
369 : : case HTML_CFG_NS40 :
370 : : case HTML_CFG_WRITER :
371 : 12 : break;
372 : : default:
373 : 0 : bRet = sal_False;
374 : : }
375 : 12 : return bRet;
376 : : }
377 : :
378 : 0 : void SvxHtmlOptions::SetPrintLayoutExtension(sal_Bool bSet)
379 : : {
380 [ # # ]: 0 : if(bSet)
381 : 0 : pImp->nFlags |= HTMLCFG_PRINT_LAYOUT_EXTENSION;
382 : : else
383 : 0 : pImp->nFlags &= ~HTMLCFG_PRINT_LAYOUT_EXTENSION;
384 : 0 : SetModified();
385 : 0 : }
386 : :
387 : 2 : sal_Bool SvxHtmlOptions::IsIgnoreFontFamily() const
388 : : {
389 : 2 : return 0 != (pImp->nFlags & HTMLCFG_IGNORE_FONT_FAMILY) ;
390 : : }
391 : :
392 : 0 : void SvxHtmlOptions::SetIgnoreFontFamily(sal_Bool bSet)
393 : : {
394 [ # # ]: 0 : if(bSet)
395 : 0 : pImp->nFlags |= HTMLCFG_IGNORE_FONT_FAMILY;
396 : : else
397 : 0 : pImp->nFlags &= ~HTMLCFG_IGNORE_FONT_FAMILY;
398 : 0 : SetModified();
399 : 0 : }
400 : :
401 : 2 : sal_Bool SvxHtmlOptions::IsStarBasicWarning() const
402 : : {
403 : 2 : return 0 != (pImp->nFlags & HTMLCFG_IS_BASIC_WARNING) ;
404 : : }
405 : :
406 : 0 : void SvxHtmlOptions::SetStarBasicWarning(sal_Bool bSet)
407 : : {
408 [ # # ]: 0 : if(bSet)
409 : 0 : pImp->nFlags |= HTMLCFG_IS_BASIC_WARNING;
410 : : else
411 : 0 : pImp->nFlags &= ~HTMLCFG_IS_BASIC_WARNING;
412 : 0 : SetModified();
413 : 0 : }
414 : :
415 : 2 : rtl_TextEncoding SvxHtmlOptions::GetTextEncoding() const
416 : : {
417 : : rtl_TextEncoding eRet;
418 [ + - ]: 2 : if(pImp->bIsEncodingDefault)
419 : 2 : eRet = SvtSysLocale::GetBestMimeEncoding();
420 : : else
421 : 0 : eRet = (rtl_TextEncoding)pImp->eEncoding;
422 : 2 : return eRet;
423 : : }
424 : :
425 : 0 : void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc )
426 : : {
427 : 0 : pImp->eEncoding = eEnc;
428 : 0 : pImp->bIsEncodingDefault = sal_False;
429 : 0 : SetModified();
430 : 0 : }
431 : :
432 : 0 : sal_Bool SvxHtmlOptions::IsDefaultTextEncoding() const
433 : : {
434 : 0 : return pImp->bIsEncodingDefault;
435 : : }
436 : :
437 : : namespace
438 : : {
439 : : class theSvxHtmlOptions : public rtl::Static<SvxHtmlOptions, theSvxHtmlOptions> {};
440 : : }
441 : :
442 : 3698 : SvxHtmlOptions& SvxHtmlOptions::Get()
443 : : {
444 : 3698 : return theSvxHtmlOptions::get();
445 : : }
446 : :
447 : 3 : sal_Bool SvxHtmlOptions::IsNumbersEnglishUS() const
448 : : {
449 : 3 : return 0 != (pImp->nFlags & HTMLCFG_NUMBERS_ENGLISH_US) ;
450 : : }
451 : :
452 : 0 : void SvxHtmlOptions::SetNumbersEnglishUS(sal_Bool bSet)
453 : : {
454 [ # # ]: 0 : if(bSet)
455 : 0 : pImp->nFlags |= HTMLCFG_NUMBERS_ENGLISH_US;
456 : : else
457 : 0 : pImp->nFlags &= ~HTMLCFG_NUMBERS_ENGLISH_US;
458 : 0 : SetModified();
459 : 0 : }
460 : :
461 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|