GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svtools / source / config / htmlcfg.cxx
blob5fff13455a3259ecd465102d777b0dff23a8594d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 #include <list>
31 // -----------------------------------------------------------------------
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
42 using namespace utl;
43 using namespace com::sun::star::uno;
46 struct HtmlOptions_Impl
48 ::std::list<Link> aList;
49 sal_Int32 nFlags;
50 sal_Int32 nExportMode;
51 sal_Int32 aFontSizeArr[HTML_FONT_COUNT];
52 sal_Int32 eEncoding;
53 sal_Bool bIsEncodingDefault;
55 HtmlOptions_Impl() :
56 nFlags(HTMLCFG_LOCAL_GRF|HTMLCFG_IS_BASIC_WARNING),
57 nExportMode(HTML_CFG_NS40),
58 eEncoding( osl_getThreadTextEncoding() ),
59 bIsEncodingDefault(sal_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
88 "Export/Basic", // 0
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]);
101 return aNames;
103 // -----------------------------------------------------------------------
104 SvxHtmlOptions::SvxHtmlOptions() :
105 ConfigItem("Office.Common/Filter/HTML")
107 pImp = new HtmlOptions_Impl;
108 Load( GetPropertyNames() );
111 // -----------------------------------------------------------------------
112 SvxHtmlOptions::~SvxHtmlOptions()
114 delete pImp;
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())
124 pImp->nFlags = 0;
125 for(int nProp = 0; nProp < aNames.getLength(); nProp++)
127 if(pValues[nProp].hasValue())
129 switch(nProp)
131 case 0:
132 if(*(sal_Bool*)pValues[nProp].getValue())
133 pImp->nFlags |= HTMLCFG_UNKNOWN_TAGS;
134 break;//"Import/UnknownTag",
135 case 1:
136 if(*(sal_Bool*)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;
150 switch( 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;
160 break;
161 case 10:
162 if(*(sal_Bool*)pValues[nProp].getValue())
163 pImp->nFlags |= HTMLCFG_STAR_BASIC;
164 break;//"Export/Basic",
165 case 11:
166 if(*(sal_Bool*)pValues[nProp].getValue())
167 pImp->nFlags |= HTMLCFG_PRINT_LAYOUT_EXTENSION;
168 break;//"Export/PrintLayout",
169 case 12:
170 if(*(sal_Bool*)pValues[nProp].getValue())
171 pImp->nFlags |= HTMLCFG_LOCAL_GRF;
172 break;//"Export/LocalGraphic",
173 case 13:
174 if(*(sal_Bool*)pValues[nProp].getValue())
175 pImp->nFlags |= HTMLCFG_IS_BASIC_WARNING;
176 break;//"Export/Warning"
178 case 14: pValues[nProp] >>= pImp->eEncoding;
179 pImp->bIsEncodingDefault = sal_False;
180 break;//"Export/Encoding"
182 case 15:
183 if(*(sal_Bool*)pValues[nProp].getValue())
184 pImp->nFlags |= HTMLCFG_NUMBERS_ENGLISH_US;
185 break;//"Import/NumbersEnglishUS"
192 // -----------------------------------------------------------------------
193 void SvxHtmlOptions::Commit()
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++)
202 sal_Bool bSet = sal_False;
203 switch(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;
218 switch( nExpMode )
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;
227 break;
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"
233 case 14:
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, ::getCppuBooleanType());
242 PutProperties(aNames, aValues);
245 void SvxHtmlOptions::CallListeners()
247 for ( ::std::list<Link>::const_iterator iter = pImp->aList.begin(); iter != pImp->aList.end(); ++iter )
248 iter->Call( this );
252 void SvxHtmlOptions::Notify( const com::sun::star::uno::Sequence< OUString >& )
254 Load( GetPropertyNames() );
255 CallListeners();
258 // -----------------------------------------------------------------------
259 sal_uInt16 SvxHtmlOptions::GetFontSize(sal_uInt16 nPos) const
261 if(nPos < HTML_FONT_COUNT)
262 return (sal_uInt16)pImp->aFontSizeArr[nPos];
263 return 0;
265 // -----------------------------------------------------------------------
266 void SvxHtmlOptions::SetFontSize(sal_uInt16 nPos, sal_uInt16 nSize)
268 if(nPos < HTML_FONT_COUNT)
270 pImp->aFontSizeArr[nPos] = nSize;
271 SetModified();
275 // -----------------------------------------------------------------------
277 // -----------------------------------------------------------------------
280 sal_Bool SvxHtmlOptions::IsImportUnknown() const
282 return 0 != (pImp->nFlags & HTMLCFG_UNKNOWN_TAGS) ;
285 // -----------------------------------------------------------------------
288 void SvxHtmlOptions::SetImportUnknown(sal_Bool bSet)
290 if(bSet)
291 pImp->nFlags |= HTMLCFG_UNKNOWN_TAGS;
292 else
293 pImp->nFlags &= ~HTMLCFG_UNKNOWN_TAGS;
294 SetModified();
297 // -----------------------------------------------------------------------
300 sal_uInt16 SvxHtmlOptions::GetExportMode() const
302 return (sal_uInt16)pImp->nExportMode;
305 // -----------------------------------------------------------------------
308 void SvxHtmlOptions::SetExportMode(sal_uInt16 nSet)
310 if(nSet <= HTML_CFG_MAX )
312 pImp->nExportMode = nSet;
313 SetModified();
314 CallListeners();
318 // -----------------------------------------------------------------------
321 sal_Bool SvxHtmlOptions::IsStarBasic() const
323 return 0 != (pImp->nFlags & HTMLCFG_STAR_BASIC) ;
326 // -----------------------------------------------------------------------
329 void SvxHtmlOptions::SetStarBasic(sal_Bool bSet)
331 if(bSet)
332 pImp->nFlags |= HTMLCFG_STAR_BASIC;
333 else
334 pImp->nFlags &= ~HTMLCFG_STAR_BASIC;
335 SetModified();
338 sal_Bool SvxHtmlOptions::IsSaveGraphicsLocal() const
340 return 0 != (pImp->nFlags & HTMLCFG_LOCAL_GRF) ;
343 void SvxHtmlOptions::SetSaveGraphicsLocal(sal_Bool bSet)
345 if(bSet)
346 pImp->nFlags |= HTMLCFG_LOCAL_GRF;
347 else
348 pImp->nFlags &= ~HTMLCFG_LOCAL_GRF;
349 SetModified();
352 sal_Bool SvxHtmlOptions::IsPrintLayoutExtension() const
354 sal_Bool bRet = 0 != (pImp->nFlags & HTMLCFG_PRINT_LAYOUT_EXTENSION);
355 switch( pImp->nExportMode )
357 case HTML_CFG_MSIE:
358 case HTML_CFG_NS40 :
359 case HTML_CFG_WRITER :
360 break;
361 default:
362 bRet = sal_False;
364 return bRet;
367 void SvxHtmlOptions::SetPrintLayoutExtension(sal_Bool bSet)
369 if(bSet)
370 pImp->nFlags |= HTMLCFG_PRINT_LAYOUT_EXTENSION;
371 else
372 pImp->nFlags &= ~HTMLCFG_PRINT_LAYOUT_EXTENSION;
373 SetModified();
376 sal_Bool SvxHtmlOptions::IsIgnoreFontFamily() const
378 return 0 != (pImp->nFlags & HTMLCFG_IGNORE_FONT_FAMILY) ;
381 void SvxHtmlOptions::SetIgnoreFontFamily(sal_Bool bSet)
383 if(bSet)
384 pImp->nFlags |= HTMLCFG_IGNORE_FONT_FAMILY;
385 else
386 pImp->nFlags &= ~HTMLCFG_IGNORE_FONT_FAMILY;
387 SetModified();
390 sal_Bool SvxHtmlOptions::IsStarBasicWarning() const
392 return 0 != (pImp->nFlags & HTMLCFG_IS_BASIC_WARNING) ;
395 void SvxHtmlOptions::SetStarBasicWarning(sal_Bool bSet)
397 if(bSet)
398 pImp->nFlags |= HTMLCFG_IS_BASIC_WARNING;
399 else
400 pImp->nFlags &= ~HTMLCFG_IS_BASIC_WARNING;
401 SetModified();
404 rtl_TextEncoding SvxHtmlOptions::GetTextEncoding() const
406 rtl_TextEncoding eRet;
407 if(pImp->bIsEncodingDefault)
408 eRet = SvtSysLocale::GetBestMimeEncoding();
409 else
410 eRet = (rtl_TextEncoding)pImp->eEncoding;
411 return eRet;
414 void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc )
416 pImp->eEncoding = eEnc;
417 pImp->bIsEncodingDefault = sal_False;
418 SetModified();
421 sal_Bool SvxHtmlOptions::IsDefaultTextEncoding() const
423 return pImp->bIsEncodingDefault;
426 namespace
428 class theSvxHtmlOptions : public rtl::Static<SvxHtmlOptions, theSvxHtmlOptions> {};
431 SvxHtmlOptions& SvxHtmlOptions::Get()
433 return theSvxHtmlOptions::get();
436 sal_Bool SvxHtmlOptions::IsNumbersEnglishUS() const
438 return 0 != (pImp->nFlags & HTMLCFG_NUMBERS_ENGLISH_US) ;
441 void SvxHtmlOptions::SetNumbersEnglishUS(sal_Bool bSet)
443 if(bSet)
444 pImp->nFlags |= HTMLCFG_NUMBERS_ENGLISH_US;
445 else
446 pImp->nFlags &= ~HTMLCFG_NUMBERS_ENGLISH_US;
447 SetModified();
450 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */