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