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