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 <svtools/htmlcfg.hxx>
22 #include <svtools/parhtml.hxx>
23 #include <unotools/syslocale.hxx>
24 #include <tools/debug.hxx>
25 #include <tools/link.hxx>
26 #include <sal/macros.h>
27 #include <rtl/instance.hxx>
30 // -----------------------------------------------------------------------
31 #define HTMLCFG_UNKNOWN_TAGS 0x01
32 //#define HTMLCFG_STYLE_SHEETS 0x02
33 //#define HTMLCFG_NETSCAPE3 0x04
34 #define HTMLCFG_STAR_BASIC 0x08
35 #define HTMLCFG_LOCAL_GRF 0x10
36 #define HTMLCFG_PRINT_LAYOUT_EXTENSION 0x20
37 #define HTMLCFG_IGNORE_FONT_FAMILY 0x40
38 #define HTMLCFG_IS_BASIC_WARNING 0x80
39 #define HTMLCFG_NUMBERS_ENGLISH_US 0x100
42 using namespace com::sun::star::uno
;
45 struct HtmlOptions_Impl
47 ::std::list
<Link
> aList
;
49 sal_Int32 nExportMode
;
50 sal_Int32 aFontSizeArr
[HTML_FONT_COUNT
];
52 sal_Bool bIsEncodingDefault
;
55 nFlags(HTMLCFG_LOCAL_GRF
|HTMLCFG_IS_BASIC_WARNING
),
56 nExportMode(HTML_CFG_NS40
),
57 eEncoding( osl_getThreadTextEncoding() ),
58 bIsEncodingDefault(sal_True
)
60 aFontSizeArr
[0] = HTMLFONTSZ1_DFLT
;
61 aFontSizeArr
[1] = HTMLFONTSZ2_DFLT
;
62 aFontSizeArr
[2] = HTMLFONTSZ3_DFLT
;
63 aFontSizeArr
[3] = HTMLFONTSZ4_DFLT
;
64 aFontSizeArr
[4] = HTMLFONTSZ5_DFLT
;
65 aFontSizeArr
[5] = HTMLFONTSZ6_DFLT
;
66 aFontSizeArr
[6] = HTMLFONTSZ7_DFLT
;
70 const Sequence
<OUString
>& SvxHtmlOptions::GetPropertyNames()
72 static Sequence
<OUString
> aNames
;
73 if(!aNames
.getLength())
75 static const char* aPropNames
[] =
77 "Import/UnknownTag", // 0
78 "Import/FontSetting", // 1
79 "Import/FontSize/Size_1", // 2
80 "Import/FontSize/Size_2", // 3
81 "Import/FontSize/Size_3", // 4
82 "Import/FontSize/Size_4", // 5
83 "Import/FontSize/Size_5", // 6
84 "Import/FontSize/Size_6", // 7
85 "Import/FontSize/Size_7", // 8
86 "Export/Browser", // 9
88 "Export/PrintLayout", // 11
89 "Export/LocalGraphic", // 12
90 "Export/Warning", // 13
91 "Export/Encoding", // 14
92 "Import/NumbersEnglishUS" // 15
94 const int nCount
= SAL_N_ELEMENTS(aPropNames
);
95 aNames
.realloc(nCount
);
96 OUString
* pNames
= aNames
.getArray();
97 for(int i
= 0; i
< nCount
; i
++)
98 pNames
[i
] = OUString::createFromAscii(aPropNames
[i
]);
102 // -----------------------------------------------------------------------
103 SvxHtmlOptions::SvxHtmlOptions() :
104 ConfigItem("Office.Common/Filter/HTML")
106 pImp
= new HtmlOptions_Impl
;
107 Load( GetPropertyNames() );
110 // -----------------------------------------------------------------------
111 SvxHtmlOptions::~SvxHtmlOptions()
116 void SvxHtmlOptions::Load( const Sequence
< OUString
>& aNames
)
118 Sequence
<Any
> aValues
= GetProperties(aNames
);
119 const Any
* pValues
= aValues
.getConstArray();
120 DBG_ASSERT(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
121 if(aValues
.getLength() == aNames
.getLength())
124 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
126 if(pValues
[nProp
].hasValue())
131 if(*(sal_Bool
*)pValues
[nProp
].getValue())
132 pImp
->nFlags
|= HTMLCFG_UNKNOWN_TAGS
;
133 break;//"Import/UnknownTag",
135 if(*(sal_Bool
*)pValues
[nProp
].getValue())
136 pImp
->nFlags
|= HTMLCFG_IGNORE_FONT_FAMILY
;
137 break;//"Import/FontSetting",
138 case 2: pValues
[nProp
] >>= pImp
->aFontSizeArr
[0]; break;//"Import/FontSize/Size_1",
139 case 3: pValues
[nProp
] >>= pImp
->aFontSizeArr
[1]; break;//"Import/FontSize/Size_2",
140 case 4: pValues
[nProp
] >>= pImp
->aFontSizeArr
[2]; break;//"Import/FontSize/Size_3",
141 case 5: pValues
[nProp
] >>= pImp
->aFontSizeArr
[3]; break;//"Import/FontSize/Size_4",
142 case 6: pValues
[nProp
] >>= pImp
->aFontSizeArr
[4]; break;//"Import/FontSize/Size_5",
143 case 7: pValues
[nProp
] >>= pImp
->aFontSizeArr
[5]; break;//"Import/FontSize/Size_6",
144 case 8: pValues
[nProp
] >>= pImp
->aFontSizeArr
[6]; break;//"Import/FontSize/Size_7",
145 case 9://"Export/Browser",
147 sal_Int32 nExpMode
= 0;
148 pValues
[nProp
] >>= nExpMode
;
151 case 1: nExpMode
= HTML_CFG_MSIE
; break;
152 case 3: nExpMode
= HTML_CFG_WRITER
; break;
153 case 4: nExpMode
= HTML_CFG_NS40
; break;
154 default: nExpMode
= HTML_CFG_NS40
; break;
157 pImp
->nExportMode
= nExpMode
;
161 if(*(sal_Bool
*)pValues
[nProp
].getValue())
162 pImp
->nFlags
|= HTMLCFG_STAR_BASIC
;
163 break;//"Export/Basic",
165 if(*(sal_Bool
*)pValues
[nProp
].getValue())
166 pImp
->nFlags
|= HTMLCFG_PRINT_LAYOUT_EXTENSION
;
167 break;//"Export/PrintLayout",
169 if(*(sal_Bool
*)pValues
[nProp
].getValue())
170 pImp
->nFlags
|= HTMLCFG_LOCAL_GRF
;
171 break;//"Export/LocalGraphic",
173 if(*(sal_Bool
*)pValues
[nProp
].getValue())
174 pImp
->nFlags
|= HTMLCFG_IS_BASIC_WARNING
;
175 break;//"Export/Warning"
177 case 14: pValues
[nProp
] >>= pImp
->eEncoding
;
178 pImp
->bIsEncodingDefault
= sal_False
;
179 break;//"Export/Encoding"
182 if(*(sal_Bool
*)pValues
[nProp
].getValue())
183 pImp
->nFlags
|= HTMLCFG_NUMBERS_ENGLISH_US
;
184 break;//"Import/NumbersEnglishUS"
191 // -----------------------------------------------------------------------
192 void SvxHtmlOptions::Commit()
194 const Sequence
<OUString
>& aNames
= GetPropertyNames();
196 Sequence
<Any
> aValues(aNames
.getLength());
197 Any
* pValues
= aValues
.getArray();
199 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
201 sal_Bool bSet
= sal_False
;
204 case 0: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_UNKNOWN_TAGS
);break;//"Import/UnknownTag",
205 case 1: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_IGNORE_FONT_FAMILY
);break;//"Import/FontSetting",
206 case 2: pValues
[nProp
] <<= pImp
->aFontSizeArr
[0];break;//"Import/FontSize/Size_1",
207 case 3: pValues
[nProp
] <<= pImp
->aFontSizeArr
[1];break;//"Import/FontSize/Size_2",
208 case 4: pValues
[nProp
] <<= pImp
->aFontSizeArr
[2];break;//"Import/FontSize/Size_3",
209 case 5: pValues
[nProp
] <<= pImp
->aFontSizeArr
[3];break;//"Import/FontSize/Size_4",
210 case 6: pValues
[nProp
] <<= pImp
->aFontSizeArr
[4];break;//"Import/FontSize/Size_5",
211 case 7: pValues
[nProp
] <<= pImp
->aFontSizeArr
[5];break;//"Import/FontSize/Size_6",
212 case 8: pValues
[nProp
] <<= pImp
->aFontSizeArr
[6];break;//"Import/FontSize/Size_7",
213 case 9: //"Export/Browser",
215 sal_Int32 nExpMode
= pImp
->nExportMode
;
219 case HTML_CFG_MSIE
: nExpMode
= 1; break;
220 case HTML_CFG_WRITER
: nExpMode
= 3; break;
221 case HTML_CFG_NS40
: nExpMode
= 4; break;
222 default: nExpMode
= 4; break; // NS40
225 pValues
[nProp
] <<= nExpMode
;
228 case 10: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_STAR_BASIC
);break;//"Export/Basic",
229 case 11: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_PRINT_LAYOUT_EXTENSION
);break;//"Export/PrintLayout",
230 case 12: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_LOCAL_GRF
);break;//"Export/LocalGraphic",
231 case 13: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_IS_BASIC_WARNING
);break;//"Export/Warning"
233 if(!pImp
->bIsEncodingDefault
)
234 pValues
[nProp
] <<= pImp
->eEncoding
;
235 break;//"Export/Encoding",
236 case 15: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_NUMBERS_ENGLISH_US
);break;//"Import/NumbersEnglishUS"
238 if(nProp
< 2 || ( nProp
> 9 && nProp
< 14 ) || nProp
== 15)
239 pValues
[nProp
].setValue(&bSet
, ::getCppuBooleanType());
241 PutProperties(aNames
, aValues
);
244 void SvxHtmlOptions::CallListeners()
246 for ( ::std::list
<Link
>::const_iterator iter
= pImp
->aList
.begin(); iter
!= pImp
->aList
.end(); ++iter
)
251 void SvxHtmlOptions::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
253 Load( GetPropertyNames() );
257 // -----------------------------------------------------------------------
258 sal_uInt16
SvxHtmlOptions::GetFontSize(sal_uInt16 nPos
) const
260 if(nPos
< HTML_FONT_COUNT
)
261 return (sal_uInt16
)pImp
->aFontSizeArr
[nPos
];
264 // -----------------------------------------------------------------------
265 void SvxHtmlOptions::SetFontSize(sal_uInt16 nPos
, sal_uInt16 nSize
)
267 if(nPos
< HTML_FONT_COUNT
)
269 pImp
->aFontSizeArr
[nPos
] = nSize
;
274 // -----------------------------------------------------------------------
276 // -----------------------------------------------------------------------
279 sal_Bool
SvxHtmlOptions::IsImportUnknown() const
281 return 0 != (pImp
->nFlags
& HTMLCFG_UNKNOWN_TAGS
) ;
284 // -----------------------------------------------------------------------
287 void SvxHtmlOptions::SetImportUnknown(sal_Bool bSet
)
290 pImp
->nFlags
|= HTMLCFG_UNKNOWN_TAGS
;
292 pImp
->nFlags
&= ~HTMLCFG_UNKNOWN_TAGS
;
296 // -----------------------------------------------------------------------
299 sal_uInt16
SvxHtmlOptions::GetExportMode() const
301 return (sal_uInt16
)pImp
->nExportMode
;
304 // -----------------------------------------------------------------------
307 void SvxHtmlOptions::SetExportMode(sal_uInt16 nSet
)
309 if(nSet
<= HTML_CFG_MAX
)
311 pImp
->nExportMode
= nSet
;
317 // -----------------------------------------------------------------------
320 sal_Bool
SvxHtmlOptions::IsStarBasic() const
322 return 0 != (pImp
->nFlags
& HTMLCFG_STAR_BASIC
) ;
325 // -----------------------------------------------------------------------
328 void SvxHtmlOptions::SetStarBasic(sal_Bool bSet
)
331 pImp
->nFlags
|= HTMLCFG_STAR_BASIC
;
333 pImp
->nFlags
&= ~HTMLCFG_STAR_BASIC
;
337 sal_Bool
SvxHtmlOptions::IsSaveGraphicsLocal() const
339 return 0 != (pImp
->nFlags
& HTMLCFG_LOCAL_GRF
) ;
342 void SvxHtmlOptions::SetSaveGraphicsLocal(sal_Bool bSet
)
345 pImp
->nFlags
|= HTMLCFG_LOCAL_GRF
;
347 pImp
->nFlags
&= ~HTMLCFG_LOCAL_GRF
;
351 sal_Bool
SvxHtmlOptions::IsPrintLayoutExtension() const
353 sal_Bool bRet
= 0 != (pImp
->nFlags
& HTMLCFG_PRINT_LAYOUT_EXTENSION
);
354 switch( pImp
->nExportMode
)
358 case HTML_CFG_WRITER
:
366 void SvxHtmlOptions::SetPrintLayoutExtension(sal_Bool bSet
)
369 pImp
->nFlags
|= HTMLCFG_PRINT_LAYOUT_EXTENSION
;
371 pImp
->nFlags
&= ~HTMLCFG_PRINT_LAYOUT_EXTENSION
;
375 sal_Bool
SvxHtmlOptions::IsIgnoreFontFamily() const
377 return 0 != (pImp
->nFlags
& HTMLCFG_IGNORE_FONT_FAMILY
) ;
380 void SvxHtmlOptions::SetIgnoreFontFamily(sal_Bool bSet
)
383 pImp
->nFlags
|= HTMLCFG_IGNORE_FONT_FAMILY
;
385 pImp
->nFlags
&= ~HTMLCFG_IGNORE_FONT_FAMILY
;
389 sal_Bool
SvxHtmlOptions::IsStarBasicWarning() const
391 return 0 != (pImp
->nFlags
& HTMLCFG_IS_BASIC_WARNING
) ;
394 void SvxHtmlOptions::SetStarBasicWarning(sal_Bool bSet
)
397 pImp
->nFlags
|= HTMLCFG_IS_BASIC_WARNING
;
399 pImp
->nFlags
&= ~HTMLCFG_IS_BASIC_WARNING
;
403 rtl_TextEncoding
SvxHtmlOptions::GetTextEncoding() const
405 rtl_TextEncoding eRet
;
406 if(pImp
->bIsEncodingDefault
)
407 eRet
= SvtSysLocale::GetBestMimeEncoding();
409 eRet
= (rtl_TextEncoding
)pImp
->eEncoding
;
413 void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc
)
415 pImp
->eEncoding
= eEnc
;
416 pImp
->bIsEncodingDefault
= sal_False
;
420 sal_Bool
SvxHtmlOptions::IsDefaultTextEncoding() const
422 return pImp
->bIsEncodingDefault
;
427 class theSvxHtmlOptions
: public rtl::Static
<SvxHtmlOptions
, theSvxHtmlOptions
> {};
430 SvxHtmlOptions
& SvxHtmlOptions::Get()
432 return theSvxHtmlOptions::get();
435 sal_Bool
SvxHtmlOptions::IsNumbersEnglishUS() const
437 return 0 != (pImp
->nFlags
& HTMLCFG_NUMBERS_ENGLISH_US
) ;
440 void SvxHtmlOptions::SetNumbersEnglishUS(sal_Bool bSet
)
443 pImp
->nFlags
|= HTMLCFG_NUMBERS_ENGLISH_US
;
445 pImp
->nFlags
&= ~HTMLCFG_NUMBERS_ENGLISH_US
;
449 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */