Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <com/sun/star/frame/XModel.hpp>
21 : #include <com/sun/star/form/FormSubmitEncoding.hpp>
22 : #include <com/sun/star/form/FormSubmitMethod.hpp>
23 : #include <com/sun/star/form/FormButtonType.hpp>
24 : #include <com/sun/star/script/XEventAttacher.hpp>
25 : #include <com/sun/star/script/XEventAttacherManager.hpp>
26 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
27 : #include <com/sun/star/form/XFormsSupplier.hpp>
28 : #include <com/sun/star/form/XForm.hpp>
29 : #include <com/sun/star/form/FormComponentType.hpp>
30 : #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
31 : #include <comphelper/string.hxx>
32 : #include <hintids.hxx>
33 : #include <vcl/svapp.hxx>
34 : #include <vcl/wrkwin.hxx>
35 : #include <svl/macitem.hxx>
36 : #include <svtools/htmlout.hxx>
37 : #include <svtools/htmltokn.h>
38 : #include <svtools/htmlkywd.hxx>
39 : #include <svl/urihelper.hxx>
40 : #include <toolkit/helper/vclunohelper.hxx>
41 : #include <svx/svdouno.hxx>
42 : #include <svx/fmglob.hxx>
43 : #include <editeng/brushitem.hxx>
44 : #include <editeng/colritem.hxx>
45 : #include <editeng/fhgtitem.hxx>
46 : #include <editeng/fontitem.hxx>
47 : #include <editeng/wghtitem.hxx>
48 : #include <editeng/postitem.hxx>
49 : #include <editeng/udlnitem.hxx>
50 : #include <editeng/crossedoutitem.hxx>
51 : #include <docsh.hxx>
52 : #include <fmtanchr.hxx>
53 : #include <docary.hxx>
54 : #include <viewsh.hxx>
55 : #include "pam.hxx"
56 : #include "doc.hxx"
57 : #include "ndtxt.hxx"
58 : #include "flypos.hxx"
59 : #include "wrthtml.hxx"
60 : #include "htmlfly.hxx"
61 : #include "htmlform.hxx"
62 : #include "frmfmt.hxx"
63 : #include <rtl/strbuf.hxx>
64 :
65 : using namespace ::com::sun::star;
66 :
67 : const sal_uInt32 HTML_FRMOPTS_CONTROL =
68 : 0;
69 : const sal_uInt32 HTML_FRMOPTS_CONTROL_CSS1 =
70 : HTML_FRMOPT_S_ALIGN |
71 : HTML_FRMOPT_S_SIZE |
72 : HTML_FRMOPT_S_SPACE |
73 : HTML_FRMOPT_BRCLEAR;
74 : const sal_uInt32 HTML_FRMOPTS_IMG_CONTROL =
75 : HTML_FRMOPT_ALIGN |
76 : HTML_FRMOPT_BRCLEAR;
77 : const sal_uInt32 HTML_FRMOPTS_IMG_CONTROL_CSS1 =
78 : HTML_FRMOPT_S_ALIGN |
79 : HTML_FRMOPT_S_SPACE;
80 :
81 :
82 :
83 0 : static void lcl_html_outEvents( SvStream& rStrm,
84 : const uno::Reference< form::XFormComponent > rFormComp,
85 : sal_Bool bCfgStarBasic,
86 : rtl_TextEncoding eDestEnc,
87 : String *pNonConvertableChars )
88 : {
89 0 : uno::Reference< container::XChild > xChild( rFormComp, uno::UNO_QUERY );
90 0 : uno::Reference< uno::XInterface > xParentIfc = xChild->getParent();
91 : OSL_ENSURE( xParentIfc.is(), "lcl_html_outEvents: no parent interface" );
92 0 : if( !xParentIfc.is() )
93 0 : return;
94 0 : uno::Reference< container::XIndexAccess > xIndexAcc( xParentIfc, uno::UNO_QUERY );
95 : uno::Reference< script::XEventAttacherManager > xEventManager( xParentIfc,
96 0 : uno::UNO_QUERY );
97 0 : if( !xIndexAcc.is() || !xEventManager.is() )
98 0 : return;
99 :
100 : // Und die Position des ControlModel darin suchen
101 0 : sal_Int32 nCount = xIndexAcc->getCount(), nPos;
102 0 : for( nPos = 0 ; nPos < nCount; nPos++ )
103 : {
104 0 : uno::Any aTmp = xIndexAcc->getByIndex(nPos);
105 : OSL_ENSURE( aTmp.getValueType() ==
106 : ::getCppuType( (uno::Reference<form::XFormComponent>*)0 ) ||
107 : aTmp.getValueType() ==
108 : ::getCppuType( (uno::Reference<form::XForm>*)0 ),
109 : "lcl_html_outEvents: falsche Reflection" );
110 0 : if( aTmp.getValueType() ==
111 0 : ::getCppuType( (uno::Reference< form::XFormComponent >*)0) )
112 :
113 : {
114 0 : if( rFormComp ==
115 0 : *(uno::Reference< form::XFormComponent > *)aTmp.getValue() )
116 0 : break;
117 : }
118 0 : else if( aTmp.getValueType() ==
119 0 : ::getCppuType( (uno::Reference< form::XForm>*)0) )
120 : {
121 : uno::Reference< form::XFormComponent > xFC(
122 0 : *(uno::Reference< form::XForm > *)aTmp.getValue(), uno::UNO_QUERY );
123 0 : if( rFormComp == xFC )
124 0 : break;
125 : }
126 0 : }
127 :
128 0 : if( nPos == nCount )
129 0 : return;
130 :
131 : uno::Sequence< script::ScriptEventDescriptor > aDescs =
132 0 : xEventManager->getScriptEvents( nPos );
133 0 : nCount = aDescs.getLength();
134 0 : if( !nCount )
135 0 : return;
136 :
137 0 : const script::ScriptEventDescriptor *pDescs = aDescs.getConstArray();
138 0 : for( sal_Int32 i = 0; i < nCount; i++ )
139 : {
140 0 : ScriptType eScriptType = EXTENDED_STYPE;
141 0 : String aScriptType( pDescs[i].ScriptType );
142 0 : if( aScriptType.EqualsIgnoreCaseAscii(SVX_MACRO_LANGUAGE_JAVASCRIPT) )
143 0 : eScriptType = JAVASCRIPT;
144 0 : else if( aScriptType.EqualsIgnoreCaseAscii(SVX_MACRO_LANGUAGE_STARBASIC ) )
145 0 : eScriptType = STARBASIC;
146 0 : if( JAVASCRIPT != eScriptType && !bCfgStarBasic )
147 0 : continue;
148 :
149 0 : String sListener( pDescs[i].ListenerType );
150 0 : xub_StrLen nTok = comphelper::string::getTokenCount(sListener, '.');
151 0 : if( nTok )
152 0 : sListener = sListener.GetToken( nTok-1, '.' );
153 0 : String sMethod( pDescs[i].EventMethod );
154 :
155 0 : const sal_Char *pOpt = 0;
156 0 : for( sal_uInt16 j=0; aEventListenerTable[j]; j++ )
157 : {
158 0 : if( sListener.EqualsAscii( aEventListenerTable[j] ) &&
159 0 : sMethod.EqualsAscii( aEventMethodTable[j] ) )
160 : {
161 : pOpt = (STARBASIC==eScriptType ? aEventSDOptionTable
162 0 : : aEventOptionTable)[j];
163 0 : break;
164 : }
165 : }
166 :
167 0 : OStringBuffer sOut;
168 0 : sOut.append(' ');
169 0 : if( pOpt && (EXTENDED_STYPE != eScriptType ||
170 0 : pDescs[i].AddListenerParam.isEmpty()) )
171 0 : sOut.append(pOpt);
172 : else
173 : {
174 0 : sOut.append(OOO_STRING_SVTOOLS_HTML_O_sdevent)
175 : .append(OUStringToOString(sListener,
176 0 : RTL_TEXTENCODING_ASCII_US))
177 0 : .append('-')
178 : .append(OUStringToOString(sMethod,
179 0 : RTL_TEXTENCODING_ASCII_US));
180 : }
181 0 : sOut.append("=\"");
182 0 : rStrm << sOut.makeStringAndClear().getStr();
183 0 : HTMLOutFuncs::Out_String( rStrm, pDescs[i].ScriptCode, eDestEnc, pNonConvertableChars );
184 0 : rStrm << '\"';
185 0 : if( EXTENDED_STYPE == eScriptType &&
186 0 : !pDescs[i].AddListenerParam.isEmpty() )
187 : {
188 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_sdaddparam)
189 : .append(OUStringToOString(sListener,
190 0 : RTL_TEXTENCODING_ASCII_US))
191 0 : .append('-')
192 : .append(OUStringToOString(sMethod,
193 0 : RTL_TEXTENCODING_ASCII_US))
194 0 : .append("=\"");
195 0 : rStrm << sOut.makeStringAndClear().getStr();
196 0 : HTMLOutFuncs::Out_String( rStrm, pDescs[i].AddListenerParam,
197 0 : eDestEnc, pNonConvertableChars );
198 0 : rStrm << '\"';
199 : }
200 0 : }
201 : }
202 :
203 0 : static sal_Bool lcl_html_isHTMLControl( sal_Int16 nClassId )
204 : {
205 0 : sal_Bool bRet = sal_False;
206 :
207 0 : switch( nClassId )
208 : {
209 : case form::FormComponentType::TEXTFIELD:
210 : case form::FormComponentType::COMMANDBUTTON:
211 : case form::FormComponentType::RADIOBUTTON:
212 : case form::FormComponentType::CHECKBOX:
213 : case form::FormComponentType::LISTBOX:
214 : case form::FormComponentType::IMAGEBUTTON:
215 : case form::FormComponentType::FILECONTROL:
216 0 : bRet = sal_True;
217 0 : break;
218 : }
219 :
220 0 : return bRet;
221 : }
222 :
223 0 : sal_Bool SwHTMLWriter::HasControls() const
224 : {
225 0 : sal_uInt32 nStartIdx = pCurPam->GetPoint()->nNode.GetIndex();
226 : sal_uInt16 i;
227 :
228 : // Skip all controls in front of the current paragraph
229 0 : for( i = 0; i < aHTMLControls.size() &&
230 0 : aHTMLControls[i]->nNdIdx < nStartIdx; i++ )
231 : ;
232 :
233 0 : return i < aHTMLControls.size() && aHTMLControls[i]->nNdIdx == nStartIdx;
234 : }
235 :
236 527 : void SwHTMLWriter::OutForm( sal_Bool bTag_On, const SwStartNode *pStartNd )
237 : {
238 527 : if( bPreserveForm ) // wir sind in einer Tabelle oder einem Bereich
239 263 : return; // ueber dem eine Form aufgespannt wurde
240 :
241 527 : if( !bTag_On )
242 : {
243 : // die Form beenden wenn alle Controls ausgegeben wurden
244 263 : if( pxFormComps && pxFormComps->is() &&
245 0 : (*pxFormComps)->getCount() == nFormCntrlCnt )
246 : {
247 0 : OutForm( sal_False, *pxFormComps );
248 0 : (*pxFormComps) = 0;
249 : }
250 263 : return;
251 : }
252 :
253 264 : uno::Reference< container::XIndexContainer > xNewFormComps; // die neue Form
254 1 : sal_uInt32 nStartIdx = pStartNd ? pStartNd->GetIndex()
255 265 : : pCurPam->GetPoint()->nNode.GetIndex();
256 :
257 : // Ueberspringen von Controls vor dem interesanten Bereich
258 : sal_uInt16 i;
259 264 : for( i = 0; i < aHTMLControls.size() &&
260 0 : aHTMLControls[i]->nNdIdx < nStartIdx; i++ )
261 : ;
262 :
263 264 : if( !pStartNd )
264 : {
265 : // Check fuer einen einzelnen Node: da ist nur interessant, ob
266 : // es zu dem Node ein Control gibt und zu welcher Form es gehoert
267 263 : if( i < aHTMLControls.size() &&
268 0 : aHTMLControls[i]->nNdIdx == nStartIdx )
269 0 : xNewFormComps = aHTMLControls[i]->xFormComps;
270 : }
271 : else
272 : {
273 : // wir klappern eine Tabelle/einen Bereich ab: hier interessiert uns:
274 : // - ob es Controls mit unterschiedlichen Start-Nodes gibt
275 : // - ob es eine Form gibt, fuer die nicht alle Controls in der
276 : // Tabelle/dem Bereich liegen
277 :
278 1 : uno::Reference< container::XIndexContainer > xCurrentFormComps;// die aktuelle Form in der Tabelle
279 1 : const SwStartNode *pCurrentStNd = 0; // und der Start-Node eines Ctrls
280 1 : xub_StrLen nCurrentCtrls = 0; // und die in ihr gefundenen Controls
281 1 : sal_uInt32 nEndIdx = pStartNd->EndOfSectionIndex();
282 1 : for( ; i < aHTMLControls.size() &&
283 0 : aHTMLControls[i]->nNdIdx <= nEndIdx; i++ )
284 : {
285 : const SwStartNode *pCntrlStNd =
286 0 : pDoc->GetNodes()[aHTMLControls[i]->nNdIdx]->StartOfSectionNode();
287 :
288 0 : if( xCurrentFormComps.is() )
289 : {
290 : // Wir befinden uns bereits in einer Form ...
291 0 : if( xCurrentFormComps==aHTMLControls[i]->xFormComps )
292 : {
293 : // ... und das Control befindet sich auch darin ...
294 0 : if( pCurrentStNd!=pCntrlStNd )
295 : {
296 : // ... aber es liegt in einer anderen Zelle:
297 : // Dann muessen eir eine Form ueber der Tabelle
298 : // aufmachen
299 0 : xNewFormComps = xCurrentFormComps;
300 0 : break;
301 : }
302 0 : nCurrentCtrls = nCurrentCtrls + aHTMLControls[i]->nCount;
303 : }
304 : else
305 : {
306 : // ... aber das Control liegt in einer anderen Zelle:
307 : // Da tun wir so, als ob wir eine neue Form aufmachen
308 : // und suchen weiter.
309 0 : xCurrentFormComps = aHTMLControls[i]->xFormComps;
310 0 : pCurrentStNd = pCntrlStNd;
311 0 : nCurrentCtrls = aHTMLControls[i]->nCount;
312 : }
313 : }
314 : else
315 : {
316 : // Wir befinden uns noch in keiner Form:
317 : // Da tun wir mal so, als ob wie wir die Form aufmachen.
318 0 : xCurrentFormComps = aHTMLControls[i]->xFormComps;
319 0 : pCurrentStNd = pCntrlStNd;
320 0 : nCurrentCtrls = aHTMLControls[i]->nCount;
321 : }
322 : }
323 1 : if( !xNewFormComps.is() && xCurrentFormComps.is() &&
324 0 : nCurrentCtrls != xCurrentFormComps->getCount() )
325 : {
326 : // In der Tablle/dem Bereich sollte eine Form aufgemacht werden,
327 : // die nicht vollstaendig in der Tabelle liegt. Dan muessen
328 : // wie die Form jetzt ebenfalls oeffen.
329 0 : xNewFormComps = xCurrentFormComps;
330 1 : }
331 : }
332 :
333 264 : if( xNewFormComps.is() &&
334 0 : (!pxFormComps || !(xNewFormComps == *pxFormComps)) )
335 : {
336 : // Es soll eine Form aufgemacht werden ...
337 0 : if( pxFormComps && pxFormComps->is() )
338 : {
339 : // .. es ist aber noch eine Form offen: Das ist in
340 : // jedem Fall eine Fehler, aber wir schliessen die alte
341 : // Form trotzdem
342 0 : OutForm( sal_False, *pxFormComps );
343 :
344 : //!!!nWarn = 1; // Control wird falscher Form zugeordnet
345 : }
346 :
347 0 : if( !pxFormComps )
348 0 : pxFormComps = new uno::Reference< container::XIndexContainer > ;
349 0 : *pxFormComps = xNewFormComps;
350 :
351 0 : OutForm( sal_True, *pxFormComps );
352 0 : uno::Reference< beans::XPropertySet > xTmp;
353 0 : OutHiddenControls( *pxFormComps, xTmp );
354 264 : }
355 : }
356 :
357 2 : void SwHTMLWriter::OutHiddenForms()
358 : {
359 : // Ohne DrawModel kann es auch keine Controls geben. Dann darf man
360 : // auch nicht per UNO auf das Dok zugreifen, weil sonst ein DrawModel
361 : // angelegt wird.
362 2 : if( !pDoc->GetDrawModel() )
363 0 : return;
364 :
365 2 : SwDocShell *pDocSh = pDoc->GetDocShell();
366 2 : if( !pDocSh )
367 0 : return;
368 :
369 : uno::Reference< drawing::XDrawPageSupplier > xDPSupp( pDocSh->GetBaseModel(),
370 2 : uno::UNO_QUERY );
371 : OSL_ENSURE( xDPSupp.is(), "XTextDocument nicht vom XModel erhalten" );
372 4 : uno::Reference< drawing::XDrawPage > xDrawPage = xDPSupp->getDrawPage();
373 :
374 : OSL_ENSURE( xDrawPage.is(), "XDrawPage nicht erhalten" );
375 2 : if( !xDrawPage.is() )
376 0 : return;
377 :
378 4 : uno::Reference< form::XFormsSupplier > xFormsSupplier( xDrawPage, uno::UNO_QUERY );
379 : OSL_ENSURE( xFormsSupplier.is(),
380 : "XFormsSupplier nicht vom XDrawPage erhalten" );
381 :
382 4 : uno::Reference< container::XNameContainer > xTmp = xFormsSupplier->getForms();
383 : OSL_ENSURE( xTmp.is(), "XForms nicht erhalten" );
384 4 : uno::Reference< container::XIndexContainer > xForms( xTmp, uno::UNO_QUERY );
385 : OSL_ENSURE( xForms.is(), "XForms ohne container::XIndexContainer?" );
386 :
387 2 : sal_Int32 nCount = xForms->getCount();
388 2 : for( sal_Int32 i=0; i<nCount; i++)
389 : {
390 0 : uno::Any aTmp = xForms->getByIndex( i );
391 : OSL_ENSURE( aTmp.getValueType() ==
392 : ::getCppuType((uno::Reference< form::XForm >*)0),
393 : "OutHiddenForms: falsche Reflection" );
394 0 : if( aTmp.getValueType() ==
395 0 : ::getCppuType((uno::Reference< form::XForm >*)0) )
396 0 : OutHiddenForm( *(uno::Reference< form::XForm > *)aTmp.getValue() );
397 2 : }
398 : }
399 :
400 0 : void SwHTMLWriter::OutHiddenForm( const uno::Reference< form::XForm > & rForm )
401 : {
402 0 : uno::Reference< container::XIndexContainer > xFormComps( rForm, uno::UNO_QUERY );
403 0 : if( !xFormComps.is() )
404 0 : return;
405 :
406 0 : sal_Int32 nCount = xFormComps->getCount();
407 0 : sal_Bool bHiddenOnly = nCount > 0, bHidden = sal_False;
408 0 : for( sal_Int32 i=0; i<nCount; i++ )
409 : {
410 0 : uno::Any aTmp = xFormComps->getByIndex( i );
411 : OSL_ENSURE( aTmp.getValueType() ==
412 : ::getCppuType((uno::Reference<form::XFormComponent>*)0),
413 : "OutHiddenForm: falsche Reflection" );
414 0 : if( aTmp.getValueType() !=
415 0 : ::getCppuType((uno::Reference<form::XFormComponent>*)0) )
416 0 : continue;
417 :
418 : uno::Reference< form::XFormComponent > xFormComp =
419 0 : *(uno::Reference< form::XFormComponent > *)aTmp.getValue();
420 0 : uno::Reference< form::XForm > xForm( xFormComp, uno::UNO_QUERY );
421 0 : if( xForm.is() )
422 0 : OutHiddenForm( xForm );
423 :
424 0 : if( bHiddenOnly )
425 : {
426 0 : uno::Reference< beans::XPropertySet > xPropSet( xFormComp, uno::UNO_QUERY );
427 0 : OUString sPropName("ClassId");
428 0 : if( xPropSet->getPropertySetInfo()->hasPropertyByName( sPropName ) )
429 : {
430 0 : uno::Any aAny2 = xPropSet->getPropertyValue( sPropName );
431 0 : if( aAny2.getValueType() == ::getCppuType((sal_Int16*)0) )
432 : {
433 0 : if( form::FormComponentType::HIDDENCONTROL ==
434 0 : *(sal_Int16*)aAny2.getValue() )
435 0 : bHidden = sal_True;
436 0 : else if( lcl_html_isHTMLControl(
437 0 : *(sal_Int16*)aAny2.getValue() ) )
438 0 : bHiddenOnly = sal_False;
439 0 : }
440 0 : }
441 : }
442 0 : }
443 :
444 0 : if( bHidden && bHiddenOnly )
445 : {
446 0 : OutForm( sal_True, xFormComps );
447 0 : uno::Reference< beans::XPropertySet > xTmp;
448 0 : OutHiddenControls( xFormComps, xTmp );
449 0 : OutForm( sal_False, xFormComps );
450 0 : }
451 : }
452 :
453 0 : void SwHTMLWriter::OutForm( sal_Bool bOn,
454 : const uno::Reference< container::XIndexContainer > & rFormComps )
455 : {
456 0 : nFormCntrlCnt = 0;
457 :
458 0 : if( !bOn )
459 : {
460 0 : DecIndentLevel(); // Inhalt der Form einruecken
461 0 : if( bLFPossible )
462 0 : OutNewLine();
463 0 : HTMLOutFuncs::Out_AsciiTag( Strm(), OOO_STRING_SVTOOLS_HTML_form, sal_False );
464 0 : bLFPossible = sal_True;
465 :
466 0 : return;
467 : }
468 :
469 : // die neue Form wird geoeffnet
470 0 : if( bLFPossible )
471 0 : OutNewLine();
472 0 : OStringBuffer sOut;
473 0 : sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_form);
474 :
475 0 : uno::Reference< beans::XPropertySet > xFormPropSet( rFormComps, uno::UNO_QUERY );
476 :
477 0 : uno::Any aTmp = xFormPropSet->getPropertyValue(
478 0 : OUString("Name") );
479 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
480 0 : !((OUString*)aTmp.getValue())->isEmpty() )
481 : {
482 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name).append("=\"");
483 0 : Strm() << sOut.makeStringAndClear().getStr();
484 0 : HTMLOutFuncs::Out_String( Strm(), *(OUString*)aTmp.getValue(),
485 0 : eDestEnc, &aNonConvertableCharacters );
486 0 : sOut.append('\"');
487 : }
488 :
489 0 : aTmp = xFormPropSet->getPropertyValue(
490 0 : OUString("TargetURL") );
491 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
492 0 : !((OUString*)aTmp.getValue())->isEmpty() )
493 : {
494 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_action).append("=\"");
495 0 : Strm() << sOut.makeStringAndClear().getStr();
496 0 : String aURL( *(OUString*)aTmp.getValue() );
497 0 : aURL = URIHelper::simpleNormalizedMakeRelative( GetBaseURL(), aURL);
498 0 : HTMLOutFuncs::Out_String( Strm(), aURL, eDestEnc, &aNonConvertableCharacters );
499 0 : sOut.append('\"');
500 : }
501 :
502 0 : aTmp = xFormPropSet->getPropertyValue(
503 0 : OUString("SubmitMethod") );
504 0 : if( aTmp.getValueType() == ::getCppuType((const form::FormSubmitMethod*)0) )
505 : {
506 : form::FormSubmitMethod eMethod =
507 0 : *( form::FormSubmitMethod*)aTmp.getValue();
508 0 : if( form::FormSubmitMethod_POST==eMethod )
509 : {
510 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_method)
511 0 : .append("=\"").append(OOO_STRING_SVTOOLS_HTML_METHOD_post)
512 0 : .append('\"');
513 : }
514 : }
515 0 : aTmp = xFormPropSet->getPropertyValue(
516 0 : OUString("SubmitEncoding") );
517 0 : if( aTmp.getValueType()==::getCppuType((const form::FormSubmitEncoding*)0) )
518 : {
519 : form::FormSubmitEncoding eEncType =
520 0 : *( form::FormSubmitEncoding*)aTmp.getValue();
521 0 : const sal_Char *pStr = 0;
522 0 : switch( eEncType )
523 : {
524 : case form::FormSubmitEncoding_MULTIPART:
525 0 : pStr = OOO_STRING_SVTOOLS_HTML_ET_multipart;
526 0 : break;
527 : case form::FormSubmitEncoding_TEXT:
528 0 : pStr = OOO_STRING_SVTOOLS_HTML_ET_text;
529 0 : break;
530 : default:
531 : ;
532 : }
533 :
534 0 : if( pStr )
535 : {
536 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_enctype)
537 0 : .append("=\"").append(pStr).append('\"');
538 : }
539 : }
540 :
541 0 : aTmp = xFormPropSet->getPropertyValue(
542 0 : OUString("TargetFrame") );
543 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0)&&
544 0 : !((OUString*)aTmp.getValue())->isEmpty() )
545 : {
546 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_target).append("=\"");
547 0 : Strm() << sOut.makeStringAndClear().getStr();
548 0 : HTMLOutFuncs::Out_String( Strm(), *(OUString*)aTmp.getValue(),
549 0 : eDestEnc, &aNonConvertableCharacters );
550 0 : sOut.append('\"');
551 : }
552 :
553 0 : Strm() << sOut.makeStringAndClear().getStr();
554 0 : uno::Reference< form::XFormComponent > xFormComp( rFormComps, uno::UNO_QUERY );
555 0 : lcl_html_outEvents( Strm(), xFormComp, bCfgStarBasic, eDestEnc, &aNonConvertableCharacters );
556 0 : Strm() << '>';
557 :
558 0 : IncIndentLevel(); // Inhalt der Form einruecken
559 0 : bLFPossible = sal_True;
560 : }
561 :
562 0 : void SwHTMLWriter::OutHiddenControls(
563 : const uno::Reference< container::XIndexContainer > & rFormComps,
564 : const uno::Reference< beans::XPropertySet > & rPropSet )
565 : {
566 0 : sal_Int32 nCount = rFormComps->getCount();
567 0 : sal_Int32 nPos = 0;
568 0 : sal_Bool bDone = sal_False;
569 0 : if( rPropSet.is() )
570 : {
571 0 : uno::Reference< form::XFormComponent > xFC( rPropSet, uno::UNO_QUERY );
572 0 : for( nPos=0; !bDone && nPos < nCount; nPos++ )
573 : {
574 0 : uno::Any aTmp = rFormComps->getByIndex( nPos );
575 : OSL_ENSURE( aTmp.getValueType() ==
576 : ::getCppuType((uno::Reference< form::XFormComponent>*)0),
577 : "OutHiddenControls: falsche Reflection" );
578 0 : bDone = aTmp.getValueType() ==
579 0 : ::getCppuType((uno::Reference< form::XFormComponent>*)0) &&
580 0 : *(uno::Reference< form::XFormComponent > *)aTmp.getValue() ==
581 0 : xFC;
582 0 : }
583 : }
584 :
585 0 : for( ; nPos < nCount; nPos++ )
586 : {
587 0 : uno::Any aTmp = rFormComps->getByIndex( nPos );
588 : OSL_ENSURE( aTmp.getValueType() ==
589 : ::getCppuType((uno::Reference< form::XFormComponent>*)0),
590 : "OutHiddenControls: falsche Reflection" );
591 0 : if( aTmp.getValueType() !=
592 0 : ::getCppuType((uno::Reference< form::XFormComponent>*)0) )
593 0 : continue;
594 : uno::Reference< form::XFormComponent > xFC =
595 0 : *(uno::Reference< form::XFormComponent > *)aTmp.getValue();
596 0 : uno::Reference< beans::XPropertySet > xPropSet( xFC, uno::UNO_QUERY );
597 :
598 0 : OUString sPropName = OUString("ClassId");
599 0 : if( !xPropSet->getPropertySetInfo()->hasPropertyByName( sPropName ) )
600 0 : continue;
601 :
602 0 : aTmp = xPropSet->getPropertyValue( sPropName );
603 0 : if( aTmp.getValueType() != ::getCppuType((const sal_Int16*)0) )
604 0 : continue;
605 :
606 0 : if( form::FormComponentType::HIDDENCONTROL ==
607 0 : *(sal_Int16*) aTmp.getValue() )
608 : {
609 0 : if( bLFPossible )
610 0 : OutNewLine( sal_True );
611 0 : OStringBuffer sOut;
612 0 : sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_input).append(' ')
613 0 : .append(OOO_STRING_SVTOOLS_HTML_O_type).append('=')
614 0 : .append(OOO_STRING_SVTOOLS_HTML_IT_hidden);
615 :
616 0 : aTmp = xPropSet->getPropertyValue(
617 0 : OUString("Name") );
618 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
619 0 : !((OUString*)aTmp.getValue())->isEmpty() )
620 : {
621 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name)
622 0 : .append("=\"");
623 0 : Strm() << sOut.makeStringAndClear().getStr();
624 0 : HTMLOutFuncs::Out_String( Strm(), *(OUString*)aTmp.getValue(),
625 0 : eDestEnc, &aNonConvertableCharacters );
626 0 : sOut.append('\"');
627 : }
628 0 : aTmp = xPropSet->getPropertyValue(
629 0 : OUString("HiddenValue") );
630 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
631 0 : !((OUString*)aTmp.getValue())->isEmpty() )
632 : {
633 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_value)
634 0 : .append("=\"");
635 0 : Strm() << sOut.makeStringAndClear().getStr();
636 0 : HTMLOutFuncs::Out_String( Strm(), *(OUString*)aTmp.getValue(),
637 0 : eDestEnc, &aNonConvertableCharacters );
638 0 : sOut.append('\"');
639 : }
640 0 : sOut.append('>');
641 0 : Strm() << sOut.makeStringAndClear().getStr();
642 :
643 0 : nFormCntrlCnt++;
644 : }
645 0 : else if( lcl_html_isHTMLControl( *(sal_Int16*) aTmp.getValue() ) )
646 : {
647 0 : break;
648 : }
649 0 : }
650 0 : }
651 :
652 :
653 : // hier folgen die Ausgabe-Routinen, dadurch sind die form::Forms gebuendelt:
654 :
655 0 : const SdrObject *SwHTMLWriter::GetHTMLControl( const SwDrawFrmFmt& rFmt )
656 : {
657 : // es muss ein Draw-Format sein
658 : OSL_ENSURE( RES_DRAWFRMFMT == rFmt.Which(),
659 : "GetHTMLControl nuer fuer Draw-Formate erlaubt" );
660 :
661 : // Schauen, ob es ein SdrObject dafuer gibt
662 0 : const SdrObject *pObj = rFmt.FindSdrObject();
663 0 : if( !pObj || FmFormInventor != pObj->GetObjInventor() )
664 0 : return 0;
665 :
666 0 : SdrUnoObj *pFormObj = PTR_CAST( SdrUnoObj, pObj );
667 : uno::Reference< awt::XControlModel > xControlModel =
668 0 : pFormObj->GetUnoControlModel();
669 :
670 : OSL_ENSURE( xControlModel.is(), "UNO-Control ohne Model" );
671 0 : if( !xControlModel.is() )
672 0 : return 0;
673 :
674 0 : uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
675 :
676 0 : OUString sPropName("ClassId");
677 0 : if( !xPropSet->getPropertySetInfo()->hasPropertyByName( sPropName ) )
678 0 : return 0;
679 :
680 0 : uno::Any aTmp = xPropSet->getPropertyValue( sPropName );
681 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0)&&
682 0 : lcl_html_isHTMLControl( *(sal_Int16*) aTmp.getValue() ) )
683 : {
684 0 : return pObj;
685 : }
686 :
687 0 : return 0;
688 : }
689 :
690 0 : static void GetControlSize( const SdrObject& rSdrObj, Size& rSz,
691 : SwDoc *pDoc )
692 : {
693 0 : ViewShell *pVSh = 0;
694 0 : pDoc->GetEditShell( &pVSh );
695 0 : if( !pVSh )
696 0 : return;
697 :
698 0 : SdrUnoObj *pFormObj = PTR_CAST( SdrUnoObj, &rSdrObj );
699 0 : uno::Reference< awt::XControl > xControl;
700 0 : SdrView* pDrawView = pVSh->GetDrawView();
701 : OSL_ENSURE( pDrawView && pVSh->GetWin(), "no DrawView or window!" );
702 0 : if ( pDrawView && pVSh->GetWin() )
703 0 : xControl = pFormObj->GetUnoControl( *pDrawView, *pVSh->GetWin() );
704 0 : uno::Reference< awt::XTextLayoutConstrains > xLC( xControl, uno::UNO_QUERY );
705 : OSL_ENSURE( xLC.is(), "kein XTextLayoutConstrains" );
706 0 : if( !xLC.is() )
707 0 : return;
708 :
709 0 : sal_Int16 nCols=0, nLines=0;
710 0 : xLC->getColumnsAndLines( nCols, nLines );
711 0 : rSz.Width() = nCols;
712 0 : rSz.Height() = nLines;
713 : }
714 :
715 0 : Writer& OutHTML_DrawFrmFmtAsControl( Writer& rWrt,
716 : const SwDrawFrmFmt& rFmt,
717 : const SdrObject& rSdrObject,
718 : sal_Bool bInCntnr )
719 : {
720 0 : SwHTMLWriter & rHTMLWrt = (SwHTMLWriter&)rWrt;
721 :
722 0 : SdrUnoObj *pFormObj = PTR_CAST( SdrUnoObj, &rSdrObject );
723 : uno::Reference< awt::XControlModel > xControlModel =
724 0 : pFormObj->GetUnoControlModel();
725 :
726 : OSL_ENSURE( xControlModel.is(), "UNO-Control ohne Model" );
727 0 : if( !xControlModel.is() )
728 0 : return rWrt;
729 :
730 0 : uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
731 : uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
732 0 : xPropSet->getPropertySetInfo();
733 :
734 0 : rHTMLWrt.nFormCntrlCnt++;
735 :
736 : enum Tag { TAG_INPUT, TAG_SELECT, TAG_TEXTAREA, TAG_NONE };
737 : static char const * const TagNames[] = {
738 : OOO_STRING_SVTOOLS_HTML_input, OOO_STRING_SVTOOLS_HTML_select,
739 : OOO_STRING_SVTOOLS_HTML_textarea };
740 0 : Tag eTag = TAG_INPUT;
741 : enum Type {
742 : TYPE_TEXT, TYPE_PASSWORD, TYPE_CHECKBOX, TYPE_RADIO, TYPE_FILE,
743 : TYPE_SUBMIT, TYPE_IMAGE, TYPE_RESET, TYPE_BUTTON, TYPE_NONE };
744 : static char const * const TypeNames[] = {
745 : OOO_STRING_SVTOOLS_HTML_IT_text, OOO_STRING_SVTOOLS_HTML_IT_password,
746 : OOO_STRING_SVTOOLS_HTML_IT_checkbox, OOO_STRING_SVTOOLS_HTML_IT_radio,
747 : OOO_STRING_SVTOOLS_HTML_IT_file, OOO_STRING_SVTOOLS_HTML_IT_submit,
748 : OOO_STRING_SVTOOLS_HTML_IT_image, OOO_STRING_SVTOOLS_HTML_IT_reset,
749 : OOO_STRING_SVTOOLS_HTML_IT_button };
750 0 : Type eType = TYPE_NONE;
751 0 : OUString sValue;
752 0 : OStringBuffer sOptions;
753 0 : sal_Bool bEmptyValue = sal_False;
754 0 : uno::Any aTmp = xPropSet->getPropertyValue(
755 0 : OUString("ClassId") );
756 0 : sal_Int16 nClassId = *(sal_Int16*) aTmp.getValue();
757 0 : sal_uInt32 nFrmOpts = HTML_FRMOPTS_CONTROL;
758 0 : switch( nClassId )
759 : {
760 : case form::FormComponentType::CHECKBOX:
761 : case form::FormComponentType::RADIOBUTTON:
762 : eType = (form::FormComponentType::CHECKBOX == nClassId
763 0 : ? TYPE_CHECKBOX : TYPE_RADIO);
764 0 : aTmp = xPropSet->getPropertyValue(
765 0 : OUString("DefaultState") );
766 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0) &&
767 0 : STATE_NOCHECK != *(sal_Int16*) aTmp.getValue() )
768 : {
769 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_checked);
770 : }
771 :
772 0 : aTmp = xPropSet->getPropertyValue(
773 0 : OUString("RefValue") );
774 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) )
775 :
776 : {
777 0 : const OUString& rVal = *(OUString*)aTmp.getValue();
778 0 : if( rVal.isEmpty() )
779 0 : bEmptyValue = sal_True;
780 0 : else if( rVal.compareToAscii( OOO_STRING_SVTOOLS_HTML_on ) != 0 )
781 0 : sValue = rVal;
782 : }
783 0 : break;
784 :
785 : case form::FormComponentType::COMMANDBUTTON:
786 : {
787 0 : form::FormButtonType eButtonType = form::FormButtonType_PUSH;
788 0 : aTmp = xPropSet->getPropertyValue(
789 0 : OUString("ButtonType") );
790 0 : if( aTmp.getValueType() ==
791 0 : ::getCppuType((const form::FormButtonType*)0) )
792 0 : eButtonType = *( form::FormButtonType*)aTmp.getValue();
793 :
794 0 : switch( eButtonType )
795 : {
796 : case form::FormButtonType_RESET:
797 0 : eType = TYPE_RESET;
798 0 : break;
799 : case form::FormButtonType_SUBMIT:
800 0 : eType = TYPE_SUBMIT;
801 0 : break;
802 : case form::FormButtonType_PUSH:
803 : default:
804 0 : eType = TYPE_BUTTON;
805 : }
806 :
807 0 : aTmp = xPropSet->getPropertyValue(
808 0 : OUString("Label") );
809 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
810 0 : !((OUString*)aTmp.getValue())->isEmpty() )
811 : {
812 0 : sValue = *(OUString*)aTmp.getValue();
813 : }
814 : }
815 0 : break;
816 :
817 : case form::FormComponentType::LISTBOX:
818 0 : if( rHTMLWrt.bLFPossible )
819 0 : rHTMLWrt.OutNewLine( sal_True );
820 0 : eTag = TAG_SELECT;
821 0 : aTmp = xPropSet->getPropertyValue(
822 0 : OUString("Dropdown") );
823 0 : if( aTmp.getValueType() == ::getBooleanCppuType() &&
824 0 : !*(sal_Bool*)aTmp.getValue() )
825 : {
826 0 : Size aSz( 0, 0 );
827 0 : GetControlSize( rSdrObject, aSz, rWrt.pDoc );
828 :
829 : // wieviele sind sichtbar ??
830 0 : if( aSz.Height() )
831 : {
832 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_size).
833 0 : append('=').append(static_cast<sal_Int32>(aSz.Height()));
834 : }
835 :
836 0 : aTmp = xPropSet->getPropertyValue(
837 0 : OUString("MultiSelection") );
838 0 : if( aTmp.getValueType() == ::getBooleanCppuType() &&
839 0 : *(sal_Bool*)aTmp.getValue() )
840 : {
841 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_multiple);
842 : }
843 : }
844 0 : break;
845 :
846 : case form::FormComponentType::TEXTFIELD:
847 : {
848 0 : Size aSz( 0, 0 );
849 0 : GetControlSize( rSdrObject, aSz, rWrt.pDoc );
850 :
851 0 : sal_Bool bMultiLine = sal_False;
852 0 : OUString sMultiLine("MultiLine");
853 0 : if( xPropSetInfo->hasPropertyByName( sMultiLine ) )
854 : {
855 0 : aTmp = xPropSet->getPropertyValue( sMultiLine );
856 0 : bMultiLine = aTmp.getValueType() == ::getBooleanCppuType() &&
857 0 : *(sal_Bool*)aTmp.getValue();
858 : }
859 :
860 0 : if( bMultiLine )
861 : {
862 0 : if( rHTMLWrt.bLFPossible )
863 0 : rHTMLWrt.OutNewLine( sal_True );
864 0 : eTag = TAG_TEXTAREA;
865 :
866 0 : if( aSz.Height() )
867 : {
868 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_rows).
869 0 : append('=').
870 0 : append(static_cast<sal_Int32>(aSz.Height()));
871 : }
872 0 : if( aSz.Width() )
873 : {
874 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_cols).
875 0 : append('=').
876 0 : append(static_cast<sal_Int32>(aSz.Width()));
877 : }
878 :
879 0 : aTmp = xPropSet->getPropertyValue(
880 0 : OUString("HScroll") );
881 0 : if( aTmp.getValueType() == ::getVoidCppuType() ||
882 0 : (aTmp.getValueType() == ::getBooleanCppuType() &&
883 0 : !*(sal_Bool*)aTmp.getValue()) )
884 : {
885 0 : const sal_Char *pWrapStr = 0;
886 0 : aTmp = xPropSet->getPropertyValue(
887 0 : OUString("HardLineBreaks") );
888 : pWrapStr =
889 0 : (aTmp.getValueType() == ::getBooleanCppuType() &&
890 0 : *(sal_Bool*)aTmp.getValue()) ? OOO_STRING_SVTOOLS_HTML_WW_hard
891 0 : : OOO_STRING_SVTOOLS_HTML_WW_soft;
892 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_wrap).
893 0 : append('=').append(pWrapStr);
894 : }
895 : }
896 : else
897 : {
898 0 : eType = TYPE_TEXT;
899 0 : OUString sEchoChar("EchoChar");
900 0 : if( xPropSetInfo->hasPropertyByName( sEchoChar ) )
901 : {
902 0 : aTmp = xPropSet->getPropertyValue( sEchoChar );
903 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0) &&
904 0 : *(sal_Int16*)aTmp.getValue() != 0 )
905 0 : eType = TYPE_PASSWORD;
906 : }
907 :
908 0 : if( aSz.Width() )
909 : {
910 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_size).
911 0 : append('=').append(static_cast<sal_Int32>(aSz.Width()));
912 : }
913 :
914 0 : aTmp = xPropSet->getPropertyValue(
915 0 : OUString("MaxTextLen") );
916 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0) &&
917 0 : *(sal_Int16*) aTmp.getValue() != 0 )
918 : {
919 0 : sOptions.append(' ').
920 0 : append(OOO_STRING_SVTOOLS_HTML_O_maxlength).
921 0 : append('=').append(static_cast<sal_Int32>(
922 0 : *(sal_Int16*) aTmp.getValue()));
923 : }
924 :
925 0 : OUString sDefaultText("DefaultText");
926 0 : if( xPropSetInfo->hasPropertyByName( sDefaultText ) )
927 : {
928 0 : aTmp = xPropSet->getPropertyValue( sDefaultText );
929 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
930 0 : !((OUString*)aTmp.getValue())->isEmpty() )
931 : {
932 0 : sValue = *(OUString*)aTmp.getValue();
933 : }
934 0 : }
935 0 : }
936 : }
937 0 : break;
938 :
939 : case form::FormComponentType::FILECONTROL:
940 : {
941 0 : Size aSz( 0, 0 );
942 0 : GetControlSize( rSdrObject, aSz, rWrt.pDoc );
943 0 : eType = TYPE_FILE;
944 :
945 0 : if( aSz.Width() )
946 : {
947 0 : sOptions.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_size).
948 0 : append('=').append(static_cast<sal_Int32>(aSz.Width()));
949 : }
950 :
951 : // VALUE vim form aus Sicherheitsgruenden nicht exportieren
952 : }
953 0 : break;
954 :
955 :
956 : case form::FormComponentType::IMAGEBUTTON:
957 0 : eType = TYPE_IMAGE;
958 0 : nFrmOpts = HTML_FRMOPTS_IMG_CONTROL;
959 0 : break;
960 :
961 : default: // kennt HTML nicht
962 0 : eTag = TAG_NONE; // also ueberspringen
963 0 : break;
964 : }
965 :
966 0 : if( eTag == TAG_NONE )
967 0 : return rWrt;
968 :
969 0 : OStringBuffer sOut;
970 0 : sOut.append('<').append(TagNames[eTag]);
971 0 : if( eType != TYPE_NONE )
972 : {
973 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_type).
974 0 : append('=').append(TypeNames[eType]);
975 : }
976 :
977 0 : aTmp = xPropSet->getPropertyValue("Name");
978 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
979 0 : !((OUString*)aTmp.getValue())->isEmpty() )
980 : {
981 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_name).
982 0 : append(RTL_CONSTASCII_STRINGPARAM("=\""));
983 0 : rWrt.Strm() << sOut.makeStringAndClear().getStr();
984 0 : HTMLOutFuncs::Out_String( rWrt.Strm(), *(OUString*)aTmp.getValue(),
985 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
986 0 : sOut.append('\"');
987 : }
988 :
989 0 : aTmp = xPropSet->getPropertyValue("Enabled");
990 0 : if( aTmp.getValueType() == ::getBooleanCppuType() &&
991 0 : !*(sal_Bool*)aTmp.getValue() )
992 : {
993 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_disabled);
994 : }
995 :
996 0 : if( !sValue.isEmpty() || bEmptyValue )
997 : {
998 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_value).append(
999 0 : RTL_CONSTASCII_STRINGPARAM("=\""));
1000 0 : rWrt.Strm() << sOut.makeStringAndClear().getStr();
1001 0 : HTMLOutFuncs::Out_String( rWrt.Strm(), sValue, rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
1002 0 : sOut.append('\"');
1003 : }
1004 :
1005 0 : sOut.append(sOptions.makeStringAndClear());
1006 :
1007 0 : if( TYPE_IMAGE == eType )
1008 : {
1009 0 : aTmp = xPropSet->getPropertyValue(
1010 0 : OUString("ImageURL") );
1011 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
1012 0 : !((OUString*)aTmp.getValue())->isEmpty() )
1013 : {
1014 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_src).
1015 0 : append(RTL_CONSTASCII_STRINGPARAM("=\""));
1016 0 : rWrt.Strm() << sOut.makeStringAndClear().getStr();
1017 :
1018 0 : HTMLOutFuncs::Out_String( rWrt.Strm(),
1019 0 : URIHelper::simpleNormalizedMakeRelative( rWrt.GetBaseURL(), *(OUString*)aTmp.getValue()),
1020 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
1021 0 : sOut.append('\"');
1022 : }
1023 :
1024 0 : Size aTwipSz( rSdrObject.GetLogicRect().GetSize() );
1025 0 : Size aPixelSz( 0, 0 );
1026 0 : if( (aTwipSz.Width() || aTwipSz.Height()) &&
1027 0 : Application::GetDefaultDevice() )
1028 : {
1029 : aPixelSz =
1030 : Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
1031 0 : MapMode(MAP_TWIP) );
1032 0 : if( !aPixelSz.Width() && aTwipSz.Width() )
1033 0 : aPixelSz.Width() = 1;
1034 0 : if( !aPixelSz.Height() && aTwipSz.Height() )
1035 0 : aPixelSz.Height() = 1;
1036 : }
1037 :
1038 0 : if( aPixelSz.Width() )
1039 : {
1040 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_width).
1041 0 : append('=').append(static_cast<sal_Int32>(aPixelSz.Width()));
1042 : }
1043 :
1044 0 : if( aPixelSz.Height() )
1045 : {
1046 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_height).
1047 0 : append('=').append(static_cast<sal_Int32>(aPixelSz.Height()));
1048 : }
1049 : }
1050 :
1051 0 : aTmp = xPropSet->getPropertyValue(
1052 0 : OUString("TabIndex") );
1053 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0) )
1054 : {
1055 0 : sal_Int16 nTabIndex = *(sal_Int16*) aTmp.getValue();
1056 0 : if( nTabIndex > 0 )
1057 : {
1058 0 : if( nTabIndex >= 32767 )
1059 0 : nTabIndex = 32767;
1060 :
1061 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_tabindex).
1062 0 : append('=').append(static_cast<sal_Int32>(nTabIndex));
1063 : }
1064 : }
1065 :
1066 0 : if( !sOut.isEmpty() )
1067 0 : rWrt.Strm() << sOut.makeStringAndClear().getStr();
1068 :
1069 : OSL_ENSURE( !bInCntnr, "Container wird fuer Controls nicht unterstuertzt" );
1070 0 : if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) && !bInCntnr )
1071 : {
1072 : // Wenn Zeichen-Objekte nicht absolut positioniert werden duerfen,
1073 : // das entsprechende Flag loeschen.
1074 : nFrmOpts |= (TYPE_IMAGE == eType
1075 : ? HTML_FRMOPTS_IMG_CONTROL_CSS1
1076 0 : : HTML_FRMOPTS_CONTROL_CSS1);
1077 : }
1078 0 : OString aEndTags;
1079 0 : if( nFrmOpts != 0 )
1080 0 : aEndTags = rHTMLWrt.OutFrmFmtOptions( rFmt, aEmptyStr, nFrmOpts );
1081 :
1082 0 : if( rHTMLWrt.bCfgOutStyles )
1083 : {
1084 0 : sal_Bool bEdit = TAG_TEXTAREA == eTag || TYPE_FILE == eType ||
1085 0 : TYPE_TEXT == eType;
1086 :
1087 0 : SfxItemSet aItemSet( rHTMLWrt.pDoc->GetAttrPool(), RES_CHRATR_BEGIN,
1088 0 : RES_CHRATR_END );
1089 0 : OUString sPropName("BackgroundColor");
1090 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1091 : {
1092 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1093 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int32*)0) )
1094 : {
1095 0 : Color aCol(*(sal_Int32*)aTmp .getValue());
1096 0 : aItemSet.Put( SvxBrushItem( aCol, RES_CHRATR_BACKGROUND ) );
1097 : }
1098 : }
1099 0 : sPropName = OUString("TextColor");
1100 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1101 : {
1102 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1103 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int32*)0) )
1104 : {
1105 0 : Color aColor( *(sal_Int32*)aTmp .getValue() );
1106 0 : aItemSet.Put( SvxColorItem( aColor, RES_CHRATR_COLOR ) );
1107 : }
1108 : }
1109 0 : sPropName = OUString("FontHeight");
1110 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1111 : {
1112 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1113 0 : if( aTmp.getValueType() == ::getCppuType((const float*)0) )
1114 :
1115 : {
1116 0 : float nHeight = *(float*)aTmp.getValue();
1117 0 : if( nHeight > 0 && (!bEdit || nHeight != 10.) )
1118 0 : aItemSet.Put( SvxFontHeightItem( sal_Int16(nHeight * 20.), 100, RES_CHRATR_FONTSIZE ) );
1119 : }
1120 : }
1121 0 : sPropName = OUString("FontName");
1122 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1123 : {
1124 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1125 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
1126 0 : !((OUString*)aTmp.getValue())->isEmpty() )
1127 : {
1128 : Font aFixedFont( OutputDevice::GetDefaultFont(
1129 : DEFAULTFONT_FIXED, LANGUAGE_ENGLISH_US,
1130 0 : DEFAULTFONT_FLAGS_ONLYONE ) );
1131 0 : String aFName( *(OUString*)aTmp.getValue() );
1132 0 : if( !bEdit || aFName != aFixedFont.GetName() )
1133 : {
1134 0 : FontFamily eFamily = FAMILY_DONTKNOW;
1135 0 : sPropName = OUString("FontFamily");
1136 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1137 : {
1138 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1139 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0))
1140 0 : eFamily = (FontFamily)*(sal_Int16*) aTmp.getValue();
1141 : }
1142 0 : SvxFontItem aItem( eFamily, aFName, aEmptyStr, PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, RES_CHRATR_FONT );
1143 0 : aItemSet.Put( aItem );
1144 0 : }
1145 : }
1146 : }
1147 0 : sPropName = OUString("FontWeight");
1148 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1149 : {
1150 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1151 0 : if( aTmp.getValueType() == ::getCppuType((const float*)0) )
1152 : {
1153 : FontWeight eWeight =
1154 0 : VCLUnoHelper::ConvertFontWeight( *(float*)aTmp.getValue() );
1155 0 : if( eWeight != WEIGHT_DONTKNOW && eWeight != WEIGHT_NORMAL )
1156 0 : aItemSet.Put( SvxWeightItem( eWeight, RES_CHRATR_WEIGHT ) );
1157 : }
1158 : }
1159 0 : sPropName = OUString("FontSlant");
1160 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1161 : {
1162 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1163 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0))
1164 : {
1165 0 : FontItalic eItalic = (FontItalic)*(sal_Int16*)aTmp.getValue();
1166 0 : if( eItalic != ITALIC_DONTKNOW && eItalic != ITALIC_NONE )
1167 0 : aItemSet.Put( SvxPostureItem( eItalic, RES_CHRATR_POSTURE ) );
1168 : }
1169 : }
1170 0 : sPropName = OUString("FontUnderline");
1171 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1172 : {
1173 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1174 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0) )
1175 : {
1176 : FontUnderline eUnderline =
1177 0 : (FontUnderline)*(sal_Int16*)aTmp.getValue();
1178 0 : if( eUnderline != UNDERLINE_DONTKNOW &&
1179 : eUnderline != UNDERLINE_NONE )
1180 0 : aItemSet.Put( SvxUnderlineItem( eUnderline, RES_CHRATR_UNDERLINE ) );
1181 : }
1182 : }
1183 0 : sPropName = OUString("FontStrikeout");
1184 0 : if( xPropSetInfo->hasPropertyByName( sPropName ) )
1185 : {
1186 0 : aTmp = xPropSet->getPropertyValue( sPropName );
1187 0 : if( aTmp.getValueType() == ::getCppuType((const sal_Int16*)0))
1188 : {
1189 : FontStrikeout eStrikeout =
1190 0 : (FontStrikeout)*(sal_Int16*)aTmp.getValue();
1191 0 : if( eStrikeout != STRIKEOUT_DONTKNOW &&
1192 : eStrikeout != STRIKEOUT_NONE )
1193 0 : aItemSet.Put( SvxCrossedOutItem( eStrikeout, RES_CHRATR_CROSSEDOUT ) );
1194 : }
1195 : }
1196 :
1197 : rHTMLWrt.OutCSS1_FrmFmtOptions( rFmt, nFrmOpts, &rSdrObject,
1198 0 : &aItemSet );
1199 : }
1200 :
1201 0 : uno::Reference< form::XFormComponent > xFormComp( xControlModel, uno::UNO_QUERY );
1202 0 : lcl_html_outEvents( rWrt.Strm(), xFormComp, rHTMLWrt.bCfgStarBasic,
1203 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
1204 :
1205 0 : rWrt.Strm() << '>';
1206 :
1207 0 : if( TAG_SELECT == eTag )
1208 : {
1209 0 : aTmp = xPropSet->getPropertyValue(
1210 0 : OUString("StringItemList") );
1211 0 : if( aTmp.getValueType() == ::getCppuType((uno::Sequence<OUString>*)0) )
1212 : {
1213 0 : rHTMLWrt.IncIndentLevel(); // der Inhalt von Select darf
1214 : // eingerueckt werden
1215 0 : uno::Sequence<OUString> aList( *(uno::Sequence<OUString>*)aTmp.getValue() );
1216 0 : sal_Int32 nCnt = aList.getLength();
1217 0 : const OUString *pStrings = aList.getConstArray();
1218 :
1219 0 : const OUString *pValues = 0;
1220 0 : sal_Int32 nValCnt = 0;
1221 0 : aTmp = xPropSet->getPropertyValue(
1222 0 : OUString("ListSource") );
1223 0 : uno::Sequence<OUString> aValList;
1224 0 : if( aTmp.getValueType() == ::getCppuType((uno::Sequence<OUString>*)0) )
1225 : {
1226 0 : aValList = *(uno::Sequence<OUString>*)aTmp.getValue();
1227 0 : nValCnt = aValList.getLength();
1228 0 : pValues = aValList.getConstArray();
1229 : }
1230 :
1231 0 : uno::Any aSelTmp = xPropSet->getPropertyValue(
1232 0 : OUString("DefaultSelection") );
1233 0 : const sal_Int16 *pSels = 0;
1234 0 : sal_Int32 nSel = 0;
1235 0 : sal_Int32 nSelCnt = 0;
1236 0 : uno::Sequence<sal_Int16> aSelList;
1237 0 : if( aSelTmp.getValueType() ==::getCppuType((uno::Sequence<sal_Int16>*)0))
1238 : {
1239 0 : aSelList = *(uno::Sequence<sal_Int16>*)aSelTmp.getValue();
1240 0 : nSelCnt = aSelList.getLength();
1241 0 : pSels = aSelList.getConstArray();
1242 : }
1243 :
1244 0 : for( sal_Int32 i = 0; i < nCnt; i++ )
1245 : {
1246 0 : OUString sVal;
1247 0 : sal_Bool bSelected = sal_False, bEmptyVal = sal_False;
1248 0 : if( i < nValCnt )
1249 : {
1250 0 : const OUString& rVal = pValues[i];
1251 0 : if( rVal.compareToAscii( "$$$empty$$$" ) == 0 )
1252 0 : bEmptyVal = sal_True;
1253 : else
1254 0 : sVal = rVal;
1255 : }
1256 :
1257 0 : bSelected = (nSel < nSelCnt) && pSels[nSel] == i;
1258 0 : if( bSelected )
1259 0 : nSel++;
1260 :
1261 0 : rHTMLWrt.OutNewLine(); // jede Option bekommt eine eigene Zeile
1262 0 : sOut.append('<').append(OOO_STRING_SVTOOLS_HTML_option);
1263 0 : if( !sVal.isEmpty() || bEmptyVal )
1264 : {
1265 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_value).
1266 0 : append(RTL_CONSTASCII_STRINGPARAM("=\""));
1267 0 : rWrt.Strm() << sOut.makeStringAndClear().getStr();
1268 0 : HTMLOutFuncs::Out_String( rWrt.Strm(), sVal,
1269 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
1270 0 : sOut.append('\"');
1271 : }
1272 0 : if( bSelected )
1273 0 : sOut.append(' ').append(OOO_STRING_SVTOOLS_HTML_O_selected);
1274 :
1275 0 : sOut.append('>');
1276 0 : rWrt.Strm() << sOut.makeStringAndClear().getStr();
1277 :
1278 0 : HTMLOutFuncs::Out_String( rWrt.Strm(), pStrings[i],
1279 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
1280 0 : }
1281 0 : HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_option, sal_False );
1282 :
1283 0 : rHTMLWrt.DecIndentLevel();
1284 0 : rHTMLWrt.OutNewLine();// das </SELECT> bekommt eine eigene Zeile
1285 : }
1286 0 : HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_select, sal_False );
1287 : }
1288 0 : else if( TAG_TEXTAREA == eTag )
1289 : {
1290 : // In TextAreas duerfen keine zusaetzlichen Spaces oder LF exportiert
1291 : // werden!
1292 0 : String sVal;
1293 0 : aTmp = xPropSet->getPropertyValue(
1294 0 : OUString("DefaultText") );
1295 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0)&&
1296 0 : !((OUString*)aTmp.getValue())->isEmpty() )
1297 : {
1298 0 : sVal = String( *(OUString*)aTmp.getValue() );
1299 : }
1300 0 : if( sVal.Len() )
1301 : {
1302 0 : sVal = convertLineEnd(sVal, LINEEND_LF);
1303 0 : sal_Int32 nPos = 0;
1304 0 : while ( nPos != -1 )
1305 : {
1306 0 : if( nPos )
1307 0 : rWrt.Strm() << SwHTMLWriter::sNewLine;
1308 0 : String aLine = sVal.GetToken( 0, 0x0A, nPos );
1309 0 : HTMLOutFuncs::Out_String( rWrt.Strm(), aLine,
1310 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters );
1311 0 : }
1312 : }
1313 0 : HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), OOO_STRING_SVTOOLS_HTML_textarea, sal_False );
1314 : }
1315 0 : else if( TYPE_CHECKBOX == eType || TYPE_RADIO == eType )
1316 : {
1317 0 : aTmp = xPropSet->getPropertyValue("Label");
1318 0 : if( aTmp.getValueType() == ::getCppuType((const OUString*)0) &&
1319 0 : !((OUString*)aTmp.getValue())->isEmpty() )
1320 : {
1321 0 : sValue = *(OUString*)aTmp.getValue();
1322 0 : HTMLOutFuncs::Out_String( rWrt.Strm(), sValue,
1323 0 : rHTMLWrt.eDestEnc, &rHTMLWrt.aNonConvertableCharacters ) << ' ';
1324 : }
1325 : }
1326 :
1327 0 : if( !aEndTags.isEmpty() )
1328 0 : rWrt.Strm() << aEndTags.getStr();
1329 :
1330 : // Controls sind nicht absatz-gebunden, deshalb kein LF mehr ausgeben!
1331 0 : rHTMLWrt.bLFPossible = sal_False;
1332 :
1333 0 : if( rHTMLWrt.pxFormComps && rHTMLWrt.pxFormComps->is() )
1334 0 : rHTMLWrt.OutHiddenControls( *rHTMLWrt.pxFormComps, xPropSet );
1335 0 : return rWrt;
1336 : }
1337 :
1338 :
1339 : // Ermitteln, ob eine Format zu einem Control gehoert und wenn ja
1340 : // dessen Form zurueckgeben
1341 0 : static void AddControl( HTMLControls& rControls,
1342 : const SdrObject *pSdrObj,
1343 : sal_uInt32 nNodeIdx )
1344 : {
1345 0 : SdrUnoObj *pFormObj = PTR_CAST( SdrUnoObj, pSdrObj );
1346 : OSL_ENSURE( pFormObj, "Doch kein FormObj" );
1347 : uno::Reference< awt::XControlModel > xControlModel =
1348 0 : pFormObj->GetUnoControlModel();
1349 0 : if( !xControlModel.is() )
1350 0 : return;
1351 :
1352 0 : uno::Reference< form::XFormComponent > xFormComp( xControlModel, uno::UNO_QUERY );
1353 0 : uno::Reference< uno::XInterface > xIfc = xFormComp->getParent();
1354 0 : uno::Reference< form::XForm > xForm(xIfc, uno::UNO_QUERY);
1355 :
1356 : OSL_ENSURE( xForm.is(), "Wo ist die Form?" );
1357 0 : if( xForm.is() )
1358 : {
1359 0 : uno::Reference< container::XIndexContainer > xFormComps( xForm, uno::UNO_QUERY );
1360 0 : HTMLControl *pHCntrl = new HTMLControl( xFormComps, nNodeIdx );
1361 0 : HTMLControls::const_iterator it = rControls.find( pHCntrl );
1362 0 : if( it == rControls.end() )
1363 0 : rControls.insert( pHCntrl );
1364 : else
1365 : {
1366 0 : if( (*it)->xFormComps==xFormComps )
1367 0 : (*it)->nCount++;
1368 0 : delete pHCntrl;
1369 0 : }
1370 0 : }
1371 : }
1372 :
1373 :
1374 2 : void SwHTMLWriter::GetControls()
1375 : {
1376 : // Idee: die absatz- und zeichengebundenen Controls werden erst einmal
1377 : // eingesammelt. Dabei wird fuer jedes Control des Absatz-Position
1378 : // und VCForm in einem Array gemerkt.
1379 : // Ueber dieses Array laesst sich dann feststellen, wo form::Forms geoeffnet
1380 : // und geschlossen werden muessen.
1381 : sal_uInt16 i;
1382 2 : if( pHTMLPosFlyFrms )
1383 : {
1384 : // die absatz-gebundenen Controls einsammeln
1385 0 : for( i=0; i<pHTMLPosFlyFrms->size(); i++ )
1386 : {
1387 0 : const SwHTMLPosFlyFrm* pPosFlyFrm = (*pHTMLPosFlyFrms)[ i ];
1388 0 : if( HTML_OUT_CONTROL != pPosFlyFrm->GetOutFn() )
1389 0 : continue;
1390 :
1391 0 : const SdrObject *pSdrObj = pPosFlyFrm->GetSdrObject();
1392 : OSL_ENSURE( pSdrObj, "Wo ist das SdrObject?" );
1393 0 : if( !pSdrObj )
1394 0 : continue;
1395 :
1396 : AddControl( aHTMLControls, pSdrObj,
1397 0 : pPosFlyFrm->GetNdIndex().GetIndex() );
1398 : }
1399 : }
1400 :
1401 : // und jetzt die in einem zeichengebundenen Rahmen
1402 2 : const SwFrmFmts* pSpzFrmFmts = pDoc->GetSpzFrmFmts();
1403 2 : for( i=0; i<pSpzFrmFmts->size(); i++ )
1404 : {
1405 0 : const SwFrmFmt *pFrmFmt = (*pSpzFrmFmts)[i];
1406 0 : if( RES_DRAWFRMFMT != pFrmFmt->Which() )
1407 0 : continue;
1408 :
1409 0 : const SwFmtAnchor& rAnchor = pFrmFmt->GetAnchor();
1410 0 : const SwPosition *pPos = rAnchor.GetCntntAnchor();
1411 0 : if ((FLY_AS_CHAR != rAnchor.GetAnchorId()) || !pPos)
1412 0 : continue;
1413 :
1414 : const SdrObject *pSdrObj =
1415 0 : SwHTMLWriter::GetHTMLControl( *(const SwDrawFrmFmt*)pFrmFmt );
1416 0 : if( !pSdrObj )
1417 0 : continue;
1418 :
1419 0 : AddControl( aHTMLControls, pSdrObj, pPos->nNode.GetIndex() );
1420 : }
1421 2 : }
1422 :
1423 :
1424 0 : HTMLControl::HTMLControl(
1425 : const uno::Reference< container::XIndexContainer > & rFormComps,
1426 : sal_uInt32 nIdx ) :
1427 0 : xFormComps( rFormComps ), nNdIdx( nIdx ), nCount( 1 )
1428 0 : {}
1429 :
1430 :
1431 0 : HTMLControl::~HTMLControl()
1432 99 : {}
1433 :
1434 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|