1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: htmlcfg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include "htmlcfg.hxx"
35 #include <svtools/parhtml.hxx>
36 #include <sfx2/bindings.hxx>
38 #include <sfx2/viewfrm.hxx>
40 #include <svx/svxids.hrc>
41 #include "txencbox.hxx"
43 // -----------------------------------------------------------------------
44 #define HTMLCFG_UNKNOWN_TAGS 0x01
45 //#define HTMLCFG_STYLE_SHEETS 0x02
46 //#define HTMLCFG_NETSCAPE3 0x04
47 #define HTMLCFG_STAR_BASIC 0x08
48 #define HTMLCFG_LOCAL_GRF 0x10
49 #define HTMLCFG_PRINT_LAYOUT_EXTENSION 0x20
50 #define HTMLCFG_IGNORE_FONT_FAMILY 0x40
51 #define HTMLCFG_IS_BASIC_WARNING 0x80
52 #define HTMLCFG_NUMBERS_ENGLISH_US 0x100
56 using namespace com::sun::star::uno
;
58 static SvxHtmlOptions
* pOptions
= 0;
60 #define C2U(cChar) OUString::createFromAscii(cChar)
61 /* -----------------------------23.11.00 11:39--------------------------------
63 ---------------------------------------------------------------------------*/
64 struct HtmlOptions_Impl
67 sal_Int32 nExportMode
;
68 sal_Int32 aFontSizeArr
[HTML_FONT_COUNT
];
70 sal_Bool bIsEncodingDefault
;
73 nFlags(HTMLCFG_LOCAL_GRF
|HTMLCFG_IS_BASIC_WARNING
),
74 nExportMode(HTML_CFG_NS40
),
75 eEncoding( gsl_getSystemTextEncoding() ),
76 bIsEncodingDefault(sal_True
)
78 aFontSizeArr
[0] = HTMLFONTSZ1_DFLT
;
79 aFontSizeArr
[1] = HTMLFONTSZ2_DFLT
;
80 aFontSizeArr
[2] = HTMLFONTSZ3_DFLT
;
81 aFontSizeArr
[3] = HTMLFONTSZ4_DFLT
;
82 aFontSizeArr
[4] = HTMLFONTSZ5_DFLT
;
83 aFontSizeArr
[5] = HTMLFONTSZ6_DFLT
;
84 aFontSizeArr
[6] = HTMLFONTSZ7_DFLT
;
88 /* -----------------------------23.11.00 11:39--------------------------------
90 ---------------------------------------------------------------------------*/
91 const Sequence
<OUString
>& SvxHtmlOptions::GetPropertyNames()
93 static Sequence
<OUString
> aNames
;
94 if(!aNames
.getLength())
96 static const char* aPropNames
[] =
98 "Import/UnknownTag", // 0
99 "Import/FontSetting", // 1
100 "Import/FontSize/Size_1", // 2
101 "Import/FontSize/Size_2", // 3
102 "Import/FontSize/Size_3", // 4
103 "Import/FontSize/Size_4", // 5
104 "Import/FontSize/Size_5", // 6
105 "Import/FontSize/Size_6", // 7
106 "Import/FontSize/Size_7", // 8
107 "Export/Browser", // 9
109 "Export/PrintLayout", // 11
110 "Export/LocalGraphic", // 12
111 "Export/Warning", // 13
112 "Export/Encoding", // 14
113 "Import/NumbersEnglishUS" // 15
115 const int nCount
= sizeof(aPropNames
) / sizeof(aPropNames
[0]);
116 aNames
.realloc(nCount
);
117 OUString
* pNames
= aNames
.getArray();
118 for(int i
= 0; i
< nCount
; i
++)
119 pNames
[i
] = C2U(aPropNames
[i
]);
123 // -----------------------------------------------------------------------
124 SvxHtmlOptions::SvxHtmlOptions() :
125 ConfigItem(C2U("Office.Common/Filter/HTML"))
127 pImp
= new HtmlOptions_Impl
;
128 const Sequence
<OUString
>& aNames
= GetPropertyNames();
129 Sequence
<Any
> aValues
= GetProperties(aNames
);
130 const Any
* pValues
= aValues
.getConstArray();
131 DBG_ASSERT(aValues
.getLength() == aNames
.getLength(), "GetProperties failed");
132 if(aValues
.getLength() == aNames
.getLength())
135 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
137 if(pValues
[nProp
].hasValue())
142 if(*(sal_Bool
*)pValues
[nProp
].getValue())
143 pImp
->nFlags
|= HTMLCFG_UNKNOWN_TAGS
;
144 break;//"Import/UnknownTag",
146 if(*(sal_Bool
*)pValues
[nProp
].getValue())
147 pImp
->nFlags
|= HTMLCFG_IGNORE_FONT_FAMILY
;
148 break;//"Import/FontSetting",
149 case 2: pValues
[nProp
] >>= pImp
->aFontSizeArr
[0]; break;//"Import/FontSize/Size_1",
150 case 3: pValues
[nProp
] >>= pImp
->aFontSizeArr
[1]; break;//"Import/FontSize/Size_2",
151 case 4: pValues
[nProp
] >>= pImp
->aFontSizeArr
[2]; break;//"Import/FontSize/Size_3",
152 case 5: pValues
[nProp
] >>= pImp
->aFontSizeArr
[3]; break;//"Import/FontSize/Size_4",
153 case 6: pValues
[nProp
] >>= pImp
->aFontSizeArr
[4]; break;//"Import/FontSize/Size_5",
154 case 7: pValues
[nProp
] >>= pImp
->aFontSizeArr
[5]; break;//"Import/FontSize/Size_6",
155 case 8: pValues
[nProp
] >>= pImp
->aFontSizeArr
[6]; break;//"Import/FontSize/Size_7",
156 case 9://"Export/Browser",
158 sal_Int32 nExpMode
= 0;
159 // pValues[nProp] >>= pImp->nExportMode;
160 pValues
[nProp
] >>= nExpMode
;
163 case 0: nExpMode
= HTML_CFG_HTML32
; break;
164 case 1: nExpMode
= HTML_CFG_MSIE_40
; break;
165 // case 2: nExpMode = HTML_CFG_NS30; break; depricated
166 case 3: nExpMode
= HTML_CFG_WRITER
; break;
167 case 4: nExpMode
= HTML_CFG_NS40
; break;
168 case 5: nExpMode
= HTML_CFG_MSIE_40_OLD
;break;
169 default: nExpMode
= HTML_CFG_NS40
; break;
172 pImp
->nExportMode
= nExpMode
;
176 if(*(sal_Bool
*)pValues
[nProp
].getValue())
177 pImp
->nFlags
|= HTMLCFG_STAR_BASIC
;
178 break;//"Export/Basic",
180 if(*(sal_Bool
*)pValues
[nProp
].getValue())
181 pImp
->nFlags
|= HTMLCFG_PRINT_LAYOUT_EXTENSION
;
182 break;//"Export/PrintLayout",
184 if(*(sal_Bool
*)pValues
[nProp
].getValue())
185 pImp
->nFlags
|= HTMLCFG_LOCAL_GRF
;
186 break;//"Export/LocalGraphic",
188 if(*(sal_Bool
*)pValues
[nProp
].getValue())
189 pImp
->nFlags
|= HTMLCFG_IS_BASIC_WARNING
;
190 break;//"Export/Warning"
192 case 14: pValues
[nProp
] >>= pImp
->eEncoding
;
193 pImp
->bIsEncodingDefault
= sal_False
;
194 break;//"Export/Encoding"
197 if(*(sal_Bool
*)pValues
[nProp
].getValue())
198 pImp
->nFlags
|= HTMLCFG_NUMBERS_ENGLISH_US
;
199 break;//"Import/NumbersEnglishUS"
206 // -----------------------------------------------------------------------
207 SvxHtmlOptions::~SvxHtmlOptions()
211 // -----------------------------------------------------------------------
212 void SvxHtmlOptions::Commit()
214 const Sequence
<OUString
>& aNames
= GetPropertyNames();
216 // const OUString* pNames = aNames.getConstArray();
217 Sequence
<Any
> aValues(aNames
.getLength());
218 Any
* pValues
= aValues
.getArray();
220 // const Type& rType = ::getBooleanCppuType();
221 for(int nProp
= 0; nProp
< aNames
.getLength(); nProp
++)
223 sal_Bool bSet
= sal_False
;
226 case 0: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_UNKNOWN_TAGS
);break;//"Import/UnknownTag",
227 case 1: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_IGNORE_FONT_FAMILY
);break;//"Import/FontSetting",
228 case 2: pValues
[nProp
] <<= pImp
->aFontSizeArr
[0];break;//"Import/FontSize/Size_1",
229 case 3: pValues
[nProp
] <<= pImp
->aFontSizeArr
[1];break;//"Import/FontSize/Size_2",
230 case 4: pValues
[nProp
] <<= pImp
->aFontSizeArr
[2];break;//"Import/FontSize/Size_3",
231 case 5: pValues
[nProp
] <<= pImp
->aFontSizeArr
[3];break;//"Import/FontSize/Size_4",
232 case 6: pValues
[nProp
] <<= pImp
->aFontSizeArr
[4];break;//"Import/FontSize/Size_5",
233 case 7: pValues
[nProp
] <<= pImp
->aFontSizeArr
[5];break;//"Import/FontSize/Size_6",
234 case 8: pValues
[nProp
] <<= pImp
->aFontSizeArr
[6];break;//"Import/FontSize/Size_7",
235 case 9: //"Export/Browser",
237 sal_Int32 nExpMode
= pImp
->nExportMode
;
241 case HTML_CFG_HTML32
: nExpMode
= 0; break;
242 case HTML_CFG_MSIE_40
: nExpMode
= 1; break;
243 // case HTML_CFG_NS30: nExpMode = 2; break; depricated
244 case HTML_CFG_WRITER
: nExpMode
= 3; break;
245 case HTML_CFG_NS40
: nExpMode
= 4; break;
246 case HTML_CFG_MSIE_40_OLD
: nExpMode
= 5; break;
247 default: nExpMode
= 4; break; // NS40
250 pValues
[nProp
] <<= nExpMode
;
253 case 10: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_STAR_BASIC
);break;//"Export/Basic",
254 case 11: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_PRINT_LAYOUT_EXTENSION
);break;//"Export/PrintLayout",
255 case 12: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_LOCAL_GRF
);break;//"Export/LocalGraphic",
256 case 13: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_IS_BASIC_WARNING
);break;//"Export/Warning"
258 if(!pImp
->bIsEncodingDefault
)
259 pValues
[nProp
] <<= pImp
->eEncoding
;
260 break;//"Export/Encoding",
261 case 15: bSet
= 0 != (pImp
->nFlags
& HTMLCFG_NUMBERS_ENGLISH_US
);break;//"Import/NumbersEnglishUS"
263 if(nProp
< 2 || ( nProp
> 9 && nProp
< 14 ) || nProp
== 15)
264 pValues
[nProp
].setValue(&bSet
, ::getCppuBooleanType());
266 PutProperties(aNames
, aValues
);
268 // -----------------------------------------------------------------------
269 USHORT
SvxHtmlOptions::GetFontSize(USHORT nPos
) const
271 if(nPos
< HTML_FONT_COUNT
)
272 return (USHORT
)pImp
->aFontSizeArr
[nPos
];
275 // -----------------------------------------------------------------------
276 void SvxHtmlOptions::SetFontSize(USHORT nPos
, USHORT nSize
)
278 if(nPos
< HTML_FONT_COUNT
)
280 pImp
->aFontSizeArr
[nPos
] = nSize
;
285 // -----------------------------------------------------------------------
287 // -----------------------------------------------------------------------
290 BOOL
SvxHtmlOptions::IsImportUnknown() const
292 return 0 != (pImp
->nFlags
& HTMLCFG_UNKNOWN_TAGS
) ;
295 // -----------------------------------------------------------------------
298 void SvxHtmlOptions::SetImportUnknown(BOOL bSet
)
301 pImp
->nFlags
|= HTMLCFG_UNKNOWN_TAGS
;
303 pImp
->nFlags
&= ~HTMLCFG_UNKNOWN_TAGS
;
307 // -----------------------------------------------------------------------
310 USHORT
SvxHtmlOptions::GetExportMode() const
312 return (USHORT
)pImp
->nExportMode
;
315 // -----------------------------------------------------------------------
318 void SvxHtmlOptions::SetExportMode(USHORT nSet
)
320 if(nSet
<= HTML_CFG_MAX
)
322 pImp
->nExportMode
= nSet
;
324 // Invalidierung, falls blinkender Text erlaubt/verboten wurde
325 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
327 pViewFrame
->GetBindings().Invalidate(SID_DRAW_TEXT_MARQUEE
);
331 // -----------------------------------------------------------------------
334 BOOL
SvxHtmlOptions::IsStarBasic() const
336 return 0 != (pImp
->nFlags
& HTMLCFG_STAR_BASIC
) ;
339 // -----------------------------------------------------------------------
342 void SvxHtmlOptions::SetStarBasic(BOOL bSet
)
345 pImp
->nFlags
|= HTMLCFG_STAR_BASIC
;
347 pImp
->nFlags
&= ~HTMLCFG_STAR_BASIC
;
351 /*-----------------14.02.97 08.34-------------------
353 --------------------------------------------------*/
355 BOOL
SvxHtmlOptions::IsSaveGraphicsLocal() const
357 return 0 != (pImp
->nFlags
& HTMLCFG_LOCAL_GRF
) ;
359 /*-----------------14.02.97 08.34-------------------
361 --------------------------------------------------*/
362 void SvxHtmlOptions::SetSaveGraphicsLocal(BOOL bSet
)
365 pImp
->nFlags
|= HTMLCFG_LOCAL_GRF
;
367 pImp
->nFlags
&= ~HTMLCFG_LOCAL_GRF
;
371 /*-----------------10/21/97 08:34am-----------------
373 --------------------------------------------------*/
375 BOOL
SvxHtmlOptions::IsPrintLayoutExtension() const
377 BOOL bRet
= 0 != (pImp
->nFlags
& HTMLCFG_PRINT_LAYOUT_EXTENSION
);
378 switch( pImp
->nExportMode
)
380 case HTML_CFG_MSIE_40
:
382 case HTML_CFG_WRITER
:
389 /*-----------------10/21/97 08:34am-----------------
391 --------------------------------------------------*/
392 void SvxHtmlOptions::SetPrintLayoutExtension(BOOL bSet
)
395 pImp
->nFlags
|= HTMLCFG_PRINT_LAYOUT_EXTENSION
;
397 pImp
->nFlags
&= ~HTMLCFG_PRINT_LAYOUT_EXTENSION
;
401 /*-----------------10.07.98 10.02-------------------
403 --------------------------------------------------*/
405 BOOL
SvxHtmlOptions::IsIgnoreFontFamily() const
407 return 0 != (pImp
->nFlags
& HTMLCFG_IGNORE_FONT_FAMILY
) ;
409 /*-----------------10.07.98 10.02-------------------
411 --------------------------------------------------*/
412 void SvxHtmlOptions::SetIgnoreFontFamily(BOOL bSet
)
415 pImp
->nFlags
|= HTMLCFG_IGNORE_FONT_FAMILY
;
417 pImp
->nFlags
&= ~HTMLCFG_IGNORE_FONT_FAMILY
;
420 /* -----------------05.02.99 09:03-------------------
422 * --------------------------------------------------*/
423 BOOL
SvxHtmlOptions::IsStarBasicWarning() const
425 return 0 != (pImp
->nFlags
& HTMLCFG_IS_BASIC_WARNING
) ;
427 /* -----------------05.02.99 09:03-------------------
429 * --------------------------------------------------*/
430 void SvxHtmlOptions::SetStarBasicWarning(BOOL bSet
)
433 pImp
->nFlags
|= HTMLCFG_IS_BASIC_WARNING
;
435 pImp
->nFlags
&= ~HTMLCFG_IS_BASIC_WARNING
;
439 /*-----------------19.02.2001 18:40-----------------
441 * --------------------------------------------------*/
442 rtl_TextEncoding
SvxHtmlOptions::GetTextEncoding() const
444 rtl_TextEncoding eRet
;
445 if(pImp
->bIsEncodingDefault
)
446 eRet
= SvxTextEncodingBox::GetBestMimeEncoding();
448 eRet
= (rtl_TextEncoding
)pImp
->eEncoding
;
452 /*-----------------19.02.2001 18:40-----------------
454 * --------------------------------------------------*/
455 void SvxHtmlOptions::SetTextEncoding( rtl_TextEncoding eEnc
)
457 pImp
->eEncoding
= eEnc
;
458 pImp
->bIsEncodingDefault
= sal_False
;
461 /* -----------------------------15.08.2001 12:01------------------------------
463 ---------------------------------------------------------------------------*/
464 sal_Bool
SvxHtmlOptions::IsDefaultTextEncoding() const
466 return pImp
->bIsEncodingDefault
;
469 SvxHtmlOptions
* SvxHtmlOptions::Get()
472 pOptions
= new SvxHtmlOptions
;
477 /* ---------------------- 2006-06-07T21:02+0200 ---------------------- */
478 BOOL
SvxHtmlOptions::IsNumbersEnglishUS() const
480 return 0 != (pImp
->nFlags
& HTMLCFG_NUMBERS_ENGLISH_US
) ;
484 /* ---------------------- 2006-06-07T21:02+0200 ---------------------- */
485 void SvxHtmlOptions::SetNumbersEnglishUS(BOOL bSet
)
488 pImp
->nFlags
|= HTMLCFG_NUMBERS_ENGLISH_US
;
490 pImp
->nFlags
&= ~HTMLCFG_NUMBERS_ENGLISH_US
;