xref: /trunk/main/sw/source/filter/html/htmlform.cxx (revision e7bcddee6c39d101fb69f78a2147ccad17f37d94)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include <hintids.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/wrkwin.hxx>
31 
32 #include <toolkit/helper/vclunohelper.hxx>
33 #include <svtools/htmlkywd.hxx>
34 #include <svtools/htmltokn.h>
35 #include <svl/urihelper.hxx>
36 #include <sfx2/request.hxx>
37 #include <sfx2/docfile.hxx>
38 #include <sfx2/viewfrm.hxx>
39 #include <editeng/lrspitem.hxx>
40 #include <editeng/ulspitem.hxx>
41 #include <editeng/brshitem.hxx>
42 #include <editeng/colritem.hxx>
43 #include <editeng/fontitem.hxx>
44 #include <editeng/fhgtitem.hxx>
45 #include <editeng/wghtitem.hxx>
46 #include <editeng/postitem.hxx>
47 #include <editeng/udlnitem.hxx>
48 #include <editeng/crsditem.hxx>
49 #include <svx/svdouno.hxx>
50 #include <svx/fmglob.hxx>
51 #include <com/sun/star/form/ListSourceType.hpp>
52 #include <com/sun/star/form/FormButtonType.hpp>
53 #include <com/sun/star/form/FormSubmitEncoding.hpp>
54 #include <com/sun/star/form/FormSubmitMethod.hpp>
55 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
56 #include <com/sun/star/script/XEventAttacherManager.hpp>
57 #include <com/sun/star/text/WrapTextMode.hpp>
58 #include <com/sun/star/text/HoriOrientation.hpp>
59 #include <com/sun/star/text/VertOrientation.hpp>
60 #include <com/sun/star/text/TextContentAnchorType.hpp>
61 #include <com/sun/star/container/XIndexContainer.hpp>
62 #include <com/sun/star/drawing/XControlShape.hpp>
63 #include <com/sun/star/awt/XTextLayoutConstrains.hpp>
64 #include <com/sun/star/awt/XLayoutConstrains.hpp>
65 #include <com/sun/star/awt/XImageConsumer.hpp>
66 #include <com/sun/star/awt/ImageStatus.hpp>
67 #include <com/sun/star/form/XImageProducerSupplier.hpp>
68 #include <com/sun/star/form/XForm.hpp>
69 #include <doc.hxx>
70 #include <pam.hxx>
71 #include <swtable.hxx>
72 #include <fmtanchr.hxx>
73 #include <htmltbl.hxx>
74 #include <docsh.hxx>
75 #include <viewsh.hxx>
76 #include <unodraw.hxx>
77 #include <unotextrange.hxx>
78 #include "dcontact.hxx"
79 
80 #include "swcss1.hxx"
81 #include "swhtml.hxx"
82 #include "htmlform.hxx"
83 
84 
85 using namespace ::com::sun::star;
86 using namespace ::com::sun::star::uno;
87 using namespace ::com::sun::star::lang;
88 using namespace ::com::sun::star::form;
89 using ::rtl::OUString;
90 
91 const sal_uInt16 TABINDEX_MIN = 0;
92 const sal_uInt16 TABINDEX_MAX = 32767;
93 
94 static HTMLOptionEnum __FAR_DATA aHTMLFormMethodTable[] =
95 {
96     { OOO_STRING_SVTOOLS_HTML_METHOD_get,       FormSubmitMethod_GET    },
97     { OOO_STRING_SVTOOLS_HTML_METHOD_post,  FormSubmitMethod_POST   },
98     { 0,                    0                       }
99 };
100 
101 static HTMLOptionEnum __FAR_DATA aHTMLFormEncTypeTable[] =
102 {
103     { OOO_STRING_SVTOOLS_HTML_ET_url,           FormSubmitEncoding_URL          },
104     { OOO_STRING_SVTOOLS_HTML_ET_multipart, FormSubmitEncoding_MULTIPART    },
105     { OOO_STRING_SVTOOLS_HTML_ET_text,      FormSubmitEncoding_TEXT         },
106     { 0,                    0                               }
107 };
108 
109 enum HTMLWordWrapMode { HTML_WM_OFF, HTML_WM_HARD, HTML_WM_SOFT };
110 
111 static HTMLOptionEnum __FAR_DATA aHTMLTextAreaWrapTable[] =
112 {
113     { OOO_STRING_SVTOOLS_HTML_WW_off,       HTML_WM_OFF },
114     { OOO_STRING_SVTOOLS_HTML_WW_hard,  HTML_WM_HARD    },
115     { OOO_STRING_SVTOOLS_HTML_WW_soft,  HTML_WM_SOFT    },
116     { OOO_STRING_SVTOOLS_HTML_WW_physical,HTML_WM_HARD  },
117     { OOO_STRING_SVTOOLS_HTML_WW_virtual,   HTML_WM_SOFT    },
118     { 0,                0               }
119 };
120 
121 HTMLEventType __FAR_DATA aEventTypeTable[] =
122 {
123     HTML_ET_ONSUBMITFORM,
124     HTML_ET_ONRESETFORM,
125     HTML_ET_ONGETFOCUS,
126     HTML_ET_ONLOSEFOCUS,
127     HTML_ET_ONCLICK,
128     HTML_ET_ONCLICK_ITEM,
129     HTML_ET_ONCHANGE,
130     HTML_ET_ONSELECT,
131     HTML_ET_END
132 };
133 
134 const sal_Char * __FAR_DATA aEventListenerTable[] =
135 {
136     "XSubmitListener",
137     "XResetListener",
138     "XFocusListener",
139     "XFocusListener",
140     "XApproveActionListener",
141     "XItemListener",
142     "XChangeListener",
143     ""
144 };
145 
146 const sal_Char * __FAR_DATA aEventMethodTable[] =
147 {
148     "approveSubmit",
149     "approveReset",
150     "focusGained",
151     "focusLost",
152     "approveAction",
153     "itemStateChanged",
154     "changed",
155     ""
156 };
157 
158 const sal_Char * __FAR_DATA aEventSDOptionTable[] =
159 {
160     OOO_STRING_SVTOOLS_HTML_O_SDonsubmit,
161     OOO_STRING_SVTOOLS_HTML_O_SDonreset,
162     OOO_STRING_SVTOOLS_HTML_O_SDonfocus,
163     OOO_STRING_SVTOOLS_HTML_O_SDonblur,
164     OOO_STRING_SVTOOLS_HTML_O_SDonclick,
165     OOO_STRING_SVTOOLS_HTML_O_SDonclick,
166     OOO_STRING_SVTOOLS_HTML_O_SDonchange,
167     0
168 };
169 
170 const sal_Char * __FAR_DATA aEventOptionTable[] =
171 {
172     OOO_STRING_SVTOOLS_HTML_O_onsubmit,
173     OOO_STRING_SVTOOLS_HTML_O_onreset,
174     OOO_STRING_SVTOOLS_HTML_O_onfocus,
175     OOO_STRING_SVTOOLS_HTML_O_onblur,
176     OOO_STRING_SVTOOLS_HTML_O_onclick,
177     OOO_STRING_SVTOOLS_HTML_O_onclick,
178     OOO_STRING_SVTOOLS_HTML_O_onchange,
179     0
180 };
181 
182 /* */
183 
184 class SwHTMLForm_Impl
185 {
186     SwDocShell                  *pDocSh;
187 
188     SvKeyValueIterator          *pHeaderAttrs;
189 
190     // gecachte Interfaces
191     uno::Reference< drawing::XDrawPage >            xDrawPage;
192     uno::Reference< container::XIndexContainer >    xForms;
193     uno::Reference< drawing::XShapes >              xShapes;
194     uno::Reference< XMultiServiceFactory >          xServiceFactory;
195 
196     uno::Reference< script::XEventAttacherManager >     xControlEventManager;
197     uno::Reference< script::XEventAttacherManager >     xFormEventManager;
198 
199     // Kontext-Informationen
200     uno::Reference< container::XIndexContainer >    xFormComps;
201     uno::Reference< beans::XPropertySet >           xFCompPropSet;
202     uno::Reference< drawing::XShape >               xShape;
203 
204     String                      sText;
205     SvStringsDtor               aStringList;
206     SvStringsDtor               aValueList;
207     SvUShorts                   aSelectedList;
208 
209 public:
210 
SwHTMLForm_Impl(SwDocShell * pDSh)211     SwHTMLForm_Impl( SwDocShell *pDSh ) :
212         pDocSh( pDSh ),
213         pHeaderAttrs( pDSh ? pDSh->GetHeaderAttributes() : 0 )
214     {
215         ASSERT( pDocSh, "Keine DocShell, keine Controls" );
216     }
217 
218     const uno::Reference< XMultiServiceFactory >& GetServiceFactory();
219     const uno::Reference< drawing::XDrawPage >& GetDrawPage();
220     const uno::Reference< drawing::XShapes >& GetShapes();
221     const uno::Reference< script::XEventAttacherManager >& GetControlEventManager();
222     const uno::Reference< script::XEventAttacherManager >& GetFormEventManager();
223     const uno::Reference< container::XIndexContainer >& GetForms();
224 
GetFormComps() const225     const uno::Reference< container::XIndexContainer >& GetFormComps() const
226     {
227         return xFormComps;
228     }
229 
SetFormComps(const uno::Reference<container::XIndexContainer> & r)230     void SetFormComps( const uno::Reference< container::XIndexContainer >& r )
231     {
232         xFormComps = r;
233     }
234 
ReleaseFormComps()235     void ReleaseFormComps() { xFormComps = 0; xControlEventManager = 0; }
236 
GetFCompPropSet() const237     const uno::Reference< beans::XPropertySet >& GetFCompPropSet() const
238     {
239         return xFCompPropSet;
240     }
241 
SetFCompPropSet(const uno::Reference<beans::XPropertySet> & r)242     void SetFCompPropSet( const uno::Reference< beans::XPropertySet >& r )
243     {
244         xFCompPropSet = r;
245     }
246 
ReleaseFCompPropSet()247     void ReleaseFCompPropSet() { xFCompPropSet = 0; }
248 
GetShape() const249     const uno::Reference< drawing::XShape >& GetShape() const { return xShape; }
SetShape(const uno::Reference<drawing::XShape> & r)250     void SetShape( const uno::Reference< drawing::XShape >& r ) { xShape = r; }
ReleaseShape()251     void ReleaseShape() { xShape = 0; }
252 
GetText()253     String& GetText() { return sText; }
EraseText()254     void EraseText() { sText = aEmptyStr; }
255 
GetStringList()256     SvStringsDtor& GetStringList() { return aStringList; }
EraseStringList()257     void EraseStringList()
258     {
259         aStringList.DeleteAndDestroy( 0, aStringList.Count() );
260     }
261 
GetValueList()262     SvStringsDtor& GetValueList() { return aValueList; }
EraseValueList()263     void EraseValueList()
264     {
265         aValueList.DeleteAndDestroy( 0, aValueList.Count() );
266     }
267 
GetSelectedList()268     SvUShorts& GetSelectedList() { return aSelectedList; }
EraseSelectedList()269     void EraseSelectedList()
270     {
271         aSelectedList.Remove( 0, aSelectedList.Count() );
272     }
273 
GetHeaderAttrs() const274     SvKeyValueIterator *GetHeaderAttrs() const { return pHeaderAttrs; }
275 };
276 
GetServiceFactory()277 const uno::Reference< XMultiServiceFactory >& SwHTMLForm_Impl::GetServiceFactory()
278 {
279     if( !xServiceFactory.is() && pDocSh )
280     {
281         xServiceFactory =
282             uno::Reference< XMultiServiceFactory >( pDocSh->GetBaseModel(),
283                                                UNO_QUERY );
284         ASSERT( xServiceFactory.is(),
285                 "XServiceFactory nicht vom Model erhalten" );
286     }
287     return xServiceFactory;
288 }
289 
290 
GetDrawPage()291 const uno::Reference< drawing::XDrawPage >& SwHTMLForm_Impl::GetDrawPage()
292 {
293     if( !xDrawPage.is() && pDocSh )
294     {
295         uno::Reference< drawing::XDrawPageSupplier > xTxtDoc( pDocSh->GetBaseModel(),
296                                                          UNO_QUERY );
297         ASSERT( xTxtDoc.is(),
298                 "drawing::XDrawPageSupplier nicht vom XModel erhalten" );
299         xDrawPage = xTxtDoc->getDrawPage();
300         ASSERT( xDrawPage.is(), "drawing::XDrawPage nicht erhalten" );
301     }
302     return xDrawPage;
303 }
304 
GetForms()305 const uno::Reference< container::XIndexContainer >& SwHTMLForm_Impl::GetForms()
306 {
307     if( !xForms.is() )
308     {
309         GetDrawPage();
310         if( xDrawPage.is() )
311         {
312             uno::Reference< XFormsSupplier > xFormsSupplier( xDrawPage, UNO_QUERY );
313             ASSERT( xFormsSupplier.is(),
314                     "XFormsSupplier nicht vom drawing::XDrawPage erhalten" );
315 
316             uno::Reference< container::XNameContainer > xNameCont =
317                 xFormsSupplier->getForms();
318             xForms = uno::Reference< container::XIndexContainer >( xNameCont,
319                                                               UNO_QUERY );
320 
321             ASSERT( xForms.is(), "XForms nicht erhalten" );
322         }
323     }
324     return xForms;
325 }
326 
327 
GetShapes()328 const uno::Reference< drawing::XShapes > & SwHTMLForm_Impl::GetShapes()
329 {
330     if( !xShapes.is() )
331     {
332         GetDrawPage();
333         if( xDrawPage.is() )
334         {
335             xShapes = uno::Reference< drawing::XShapes >( xDrawPage, UNO_QUERY );
336             ASSERT( xShapes.is(),
337                     "XShapes nicht vom drawing::XDrawPage erhalten" );
338         }
339     }
340     return xShapes;
341 }
342 
343 const uno::Reference< script::XEventAttacherManager >&
GetControlEventManager()344                                     SwHTMLForm_Impl::GetControlEventManager()
345 {
346     if( !xControlEventManager.is() && xFormComps.is() )
347     {
348         xControlEventManager =
349             uno::Reference< script::XEventAttacherManager >( xFormComps, UNO_QUERY );
350         ASSERT( xControlEventManager.is(),
351     "uno::Reference< XEventAttacherManager > nicht von xFormComps erhalten" );
352     }
353 
354     return xControlEventManager;
355 }
356 
357 const uno::Reference< script::XEventAttacherManager >&
GetFormEventManager()358     SwHTMLForm_Impl::GetFormEventManager()
359 {
360     if( !xFormEventManager.is() )
361     {
362         GetForms();
363         if( xForms.is() )
364         {
365             xFormEventManager =
366                 uno::Reference< script::XEventAttacherManager >( xForms, UNO_QUERY );
367             ASSERT( xFormEventManager.is(),
368         "uno::Reference< XEventAttacherManager > nicht von xForms erhalten" );
369         }
370     }
371 
372     return xFormEventManager;
373 }
374 
375 class SwHTMLImageWatcher :
376     public cppu::WeakImplHelper2< awt::XImageConsumer, XEventListener >
377 {
378     uno::Reference< drawing::XShape >       xShape;     // das control
379     uno::Reference< XImageProducerSupplier >    xSrc;
380     uno::Reference< awt::XImageConsumer >   xThis;      // man selbst
381     sal_Bool                            bSetWidth;
382     sal_Bool                            bSetHeight;
383 
384     void clear();
385 
386 public:
387 
388     SwHTMLImageWatcher( const uno::Reference< drawing::XShape > & rShape,
389                         sal_Bool bWidth, sal_Bool bHeight );
390     ~SwHTMLImageWatcher();
391 
392     // startProduction darf nicht im Konstruktor gerufen werden, weil
393     // wir und ggf. selbst zerstoeren ... Deshlab eine eigene Methode.
start()394     void start() { xSrc->getImageProducer()->startProduction(); }
395 
396     // UNO Anbindung
397 
398     // XImageConsumer
399     virtual void SAL_CALL init( sal_Int32 Width, sal_Int32 Height);
400     virtual void SAL_CALL setColorModel(
401             sal_Int16 BitCount, const uno::Sequence< sal_Int32 >& RGBAPal,
402             sal_Int32 RedMask, sal_Int32 GreenMask, sal_Int32 BlueMask,
403             sal_Int32 AlphaMask);
404     virtual void SAL_CALL setPixelsByBytes(
405             sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height,
406             const uno::Sequence< sal_Int8 >& ProducerData,
407             sal_Int32 Offset, sal_Int32 Scansize);
408     virtual void SAL_CALL setPixelsByLongs(
409             sal_Int32 X, sal_Int32 Y, sal_Int32 Width, sal_Int32 Height,
410             const uno::Sequence< sal_Int32 >& ProducerData,
411             sal_Int32 Offset, sal_Int32 Scansize);
412     virtual void SAL_CALL complete(
413             sal_Int32 Status,
414             const uno::Reference< awt::XImageProducer > & Producer);
415 
416     // XEventListener
417     virtual void SAL_CALL disposing( const EventObject& Source );
418 };
419 
SwHTMLImageWatcher(const uno::Reference<drawing::XShape> & rShape,sal_Bool bWidth,sal_Bool bHeight)420 SwHTMLImageWatcher::SwHTMLImageWatcher(
421         const uno::Reference< drawing::XShape >& rShape,
422         sal_Bool bWidth, sal_Bool bHeight ) :
423     xShape( rShape ),
424     bSetWidth( bWidth ), bSetHeight( bHeight )
425 {
426     // Die Quelle des Images merken
427     uno::Reference< drawing::XControlShape > xControlShape( xShape, UNO_QUERY );
428     uno::Reference< awt::XControlModel > xControlModel(
429             xControlShape->getControl() );
430     xSrc = uno::Reference< XImageProducerSupplier >( xControlModel, UNO_QUERY );
431     ASSERT( xSrc.is(), "Kein XImageProducerSupplier" );
432 
433     // Als Event-Listener am Shape anmelden, damit wir es beim dispose
434     // loslassen können ...
435     uno::Reference< XEventListener > xEvtLstnr = (XEventListener *)this;
436     uno::Reference< XComponent > xComp( xShape, UNO_QUERY );
437     xComp->addEventListener( xEvtLstnr );
438 
439     // Zum Schluss halten wir noch eine Referenz auf uns selbst, damit
440     // wir am Leben bleiben ... (eigentlich sollte das nicht neotig sein,
441     // weil wir ja noch an diversen anderen Stellen angemeldet sind)
442     xThis = (awt::XImageConsumer *)this;
443 
444     // und am ImageProducer anmelden, um die Groesse zu erehalten ...
445     xSrc->getImageProducer()->addConsumer( xThis );
446 }
447 
~SwHTMLImageWatcher()448 SwHTMLImageWatcher::~SwHTMLImageWatcher()
449 {
450 }
451 
clear()452 void SwHTMLImageWatcher::clear()
453 {
454     // Am Shape als Event-Listener abmelden
455     uno::Reference< XEventListener > xEvtLstnr = (XEventListener *)this;
456     uno::Reference< XComponent > xComp( xShape, UNO_QUERY );
457     xComp->removeEventListener( xEvtLstnr );
458 
459     // Am ImageProducer abmelden
460     uno::Reference<awt::XImageProducer> xProd = xSrc->getImageProducer();
461     if( xProd.is() )
462         xProd->removeConsumer( xThis );
463 }
464 
465 //------------------------------------------------------------------------------
466 
init(sal_Int32 Width,sal_Int32 Height)467 void SwHTMLImageWatcher::init( sal_Int32 Width, sal_Int32 Height )
468 {
469     ASSERT( bSetWidth || bSetHeight,
470             "Breite oder Hoehe muss angepasst werden" );
471 
472     // Wenn keine Breite oder Hoehe angegeben ist, ist das das init von
473     // der leeren Grafik, die angezeigt wird, bevor der Stream einer
474     // asynchron anzuzeigenden Grfik verfuegbar ist.
475     if( !Width && !Height )
476         return;
477 
478     awt::Size aNewSz;
479     aNewSz.Width = Width;
480     aNewSz.Height = Height;
481     if( Application::GetDefaultDevice() )
482     {
483         Size aTmp(aNewSz.Width, aNewSz.Height);
484         aTmp = Application::GetDefaultDevice()
485                     ->PixelToLogic( aTmp, MapMode( MAP_100TH_MM ) );
486         aNewSz.Width = aTmp.Width();
487         aNewSz.Height = aTmp.Height();
488     }
489 
490     if( !bSetWidth || !bSetHeight )
491     {
492         awt::Size aSz( xShape->getSize() );
493         if( bSetWidth && aNewSz.Height )
494         {
495             aNewSz.Width *= aSz.Height;
496             aNewSz.Width /= aNewSz.Height;
497             aNewSz.Height = aSz.Height;
498         }
499         if( bSetHeight && aNewSz.Width )
500         {
501             aNewSz.Height *= aSz.Width;
502             aNewSz.Height /= aNewSz.Width;
503             aNewSz.Width = aSz.Width;
504         }
505     }
506     if( aNewSz.Width < MINFLY )
507         aNewSz.Width = MINFLY;
508     if( aNewSz.Height < MINFLY )
509         aNewSz.Height = MINFLY;
510 
511     xShape->setSize( aNewSz );
512     if( bSetWidth )
513     {
514         // Wenn das Control in einer Tabelle verankert ist, muesen
515         // die Tabellen-Spalten neu berechnet werden
516 
517         // Um an den SwXShape* zu gelangen, brauchen wir ein Interface,
518         // das auch vom SwXShape implementiert wird.
519 
520         uno::Reference< beans::XPropertySet > xPropSet( xShape, UNO_QUERY );
521         uno::Reference< XUnoTunnel> xTunnel( xPropSet, UNO_QUERY );
522                 SwXShape *pSwShape = xTunnel.is() ?
523                     reinterpret_cast< SwXShape * >( sal::static_int_cast< sal_IntPtr>(
524                     xTunnel->getSomething(SwXShape::getUnoTunnelId()) ))
525                 : 0;
526 
527         ASSERT( pSwShape, "Wo ist das SW-Shape?" );
528         if( pSwShape )
529         {
530             SwFrmFmt *pFrmFmt = pSwShape->GetFrmFmt();
531 
532             const SwDoc *pDoc = pFrmFmt->GetDoc();
533             const SwPosition* pAPos = pFrmFmt->GetAnchor().GetCntntAnchor();
534             SwNode *pANd;
535             SwTableNode *pTblNd;
536             if( pAPos &&
537                 0 != (pANd = & pAPos->nNode.GetNode()) &&
538                 0 != (pTblNd = pANd->FindTableNode()) )
539             {
540                 const sal_Bool bLastGrf = !pTblNd->GetTable().DecGrfsThatResize();
541                 SwHTMLTableLayout *pLayout =
542                     pTblNd->GetTable().GetHTMLTableLayout();
543                 if( pLayout )
544                 {
545                     const sal_uInt16 nBrowseWidth =
546                         pLayout->GetBrowseWidthByTable( *pDoc );
547 
548                     if ( nBrowseWidth )
549                     {
550                         pLayout->Resize( nBrowseWidth, sal_True, sal_True,
551                                          bLastGrf ? HTMLTABLE_RESIZE_NOW
552                                                   : 500 );
553                     }
554                 }
555             }
556         }
557     }
558 
559     // uns selbst abmelden und loeschen
560     clear();
561     uno::Reference< awt::XImageConsumer >  xTmp = (awt::XImageConsumer*)this;
562     xThis = 0;
563 }
564 
setColorModel(sal_Int16,const Sequence<sal_Int32> &,sal_Int32,sal_Int32,sal_Int32,sal_Int32)565 void SwHTMLImageWatcher::setColorModel(
566         sal_Int16, const Sequence< sal_Int32 >&, sal_Int32, sal_Int32,
567         sal_Int32, sal_Int32 )
568 {
569 }
570 
setPixelsByBytes(sal_Int32,sal_Int32,sal_Int32,sal_Int32,const Sequence<sal_Int8> &,sal_Int32,sal_Int32)571 void SwHTMLImageWatcher::setPixelsByBytes(
572         sal_Int32, sal_Int32, sal_Int32, sal_Int32,
573         const Sequence< sal_Int8 >&, sal_Int32, sal_Int32 )
574 {
575 }
576 
577 
setPixelsByLongs(sal_Int32,sal_Int32,sal_Int32,sal_Int32,const Sequence<sal_Int32> &,sal_Int32,sal_Int32)578 void SwHTMLImageWatcher::setPixelsByLongs(
579         sal_Int32, sal_Int32, sal_Int32, sal_Int32,
580         const Sequence< sal_Int32 >&, sal_Int32, sal_Int32 )
581 {
582 }
583 
584 
complete(sal_Int32 Status,const uno::Reference<awt::XImageProducer> &)585 void SwHTMLImageWatcher::complete( sal_Int32 Status,
586         const uno::Reference< awt::XImageProducer >& )
587 {
588     if( awt::ImageStatus::IMAGESTATUS_ERROR == Status || awt::ImageStatus::IMAGESTATUS_ABORTED == Status )
589     {
590         // uns selbst abmelden und loeschen
591         clear();
592         uno::Reference< awt::XImageConsumer > xTmp = (awt::XImageConsumer*)this;
593         xThis = 0;
594     }
595 }
596 
disposing(const lang::EventObject & evt)597 void SwHTMLImageWatcher::disposing(const lang::EventObject& evt)
598 {
599     uno::Reference< awt::XImageConsumer > xTmp;
600 
601     // Wenn das Shape verschwindet soll muessen wir es loslassen
602     uno::Reference< drawing::XShape > xTmpShape;
603     if( evt.Source == xShape )
604     {
605         clear();
606         xTmp = (awt::XImageConsumer*)this;
607         xThis = 0;
608     }
609 }
610 
DeleteFormImpl()611 void SwHTMLParser::DeleteFormImpl()
612 {
613     delete pFormImpl;
614     pFormImpl = 0;
615 }
616 
lcl_html_setFixedFontProperty(const uno::Reference<beans::XPropertySet> & rPropSet)617 static void lcl_html_setFixedFontProperty(
618         const uno::Reference< beans::XPropertySet >& rPropSet )
619 {
620     Font aFixedFont( OutputDevice::GetDefaultFont(
621                                     DEFAULTFONT_FIXED, LANGUAGE_ENGLISH_US,
622                                     DEFAULTFONT_FLAGS_ONLYONE )  );
623     Any aTmp;
624     aTmp <<= OUString( aFixedFont.GetName() );
625     rPropSet->setPropertyValue( OUString::createFromAscii("FontName"), aTmp );
626 
627     aTmp <<= OUString( aFixedFont.GetStyleName() );
628     rPropSet->setPropertyValue( OUString::createFromAscii("FontStyleName"),
629                                 aTmp );
630 
631     aTmp <<= (sal_Int16) aFixedFont.GetFamily();
632     rPropSet->setPropertyValue( OUString::createFromAscii("FontFamily"), aTmp );
633 
634     aTmp <<= (sal_Int16) aFixedFont.GetCharSet();
635     rPropSet->setPropertyValue( OUString::createFromAscii("FontCharset"),
636                                 aTmp );
637 
638     aTmp <<= (sal_Int16) aFixedFont.GetPitch();
639     rPropSet->setPropertyValue( OUString::createFromAscii("FontPitch"), aTmp );
640 
641     float fVal(10.);
642     aTmp.setValue( &fVal, ::getCppuType(&fVal ));
643     rPropSet->setPropertyValue( OUString::createFromAscii("FontHeight"), aTmp );
644 }
645 
646 class SwHTMLFormPendingStackData_Impl: public SwPendingStackData
647 {
648     uno::Reference< drawing::XShape >   xShape;
649     Size            aTextSz;
650     sal_Bool        bMinWidth;
651     sal_Bool        bMinHeight;
652 
653 public:
654 
SwHTMLFormPendingStackData_Impl(const uno::Reference<drawing::XShape> & rShape,const Size & rTextSz,sal_Bool bMinW,sal_Bool bMinH)655     SwHTMLFormPendingStackData_Impl(
656             const uno::Reference< drawing::XShape > & rShape, const Size& rTextSz,
657             sal_Bool bMinW, sal_Bool bMinH ) :
658         xShape( rShape ),
659         aTextSz( rTextSz ),
660         bMinWidth( bMinW ),
661         bMinHeight( bMinH )
662     {}
663 
GetShape() const664     const uno::Reference< drawing::XShape >& GetShape() const { return xShape; }
GetTextSize() const665     const Size& GetTextSize() const { return aTextSz; }
IsMinWidth() const666     sal_Bool IsMinWidth() const { return bMinWidth; }
IsMinHeight() const667     sal_Bool IsMinHeight() const { return bMinHeight; }
668 };
669 
SetPendingControlSize(int nToken)670 void SwHTMLParser::SetPendingControlSize( int nToken )
671 {
672     ASSERT( pPendStack, "Wo ist der Pending Stack?" );
673     SwHTMLFormPendingStackData_Impl *pData =
674         (SwHTMLFormPendingStackData_Impl *)pPendStack->pData;
675 
676     SwPendingStack* pTmp = pPendStack->pNext;
677     delete pPendStack;
678     pPendStack = pTmp;
679     ASSERT( !pPendStack, "Wo kommt der Pending-Stack her?" );
680 
681     SetControlSize( pData->GetShape(), pData->GetTextSize(),
682                     pData->IsMinWidth(), pData->IsMinHeight(),
683                     nToken );
684     delete pData;
685 }
686 
SetControlSize(const uno::Reference<drawing::XShape> & rShape,const Size & rTextSz,sal_Bool bMinWidth,sal_Bool bMinHeight,int nToken)687 void SwHTMLParser::SetControlSize( const uno::Reference< drawing::XShape >& rShape,
688                                    const Size& rTextSz,
689                                    sal_Bool bMinWidth,
690                                    sal_Bool bMinHeight,
691                                    int nToken )
692 {
693     nToken = 0;
694     if( !rTextSz.Width() && !rTextSz.Height() && !bMinWidth  && !bMinHeight )
695         return;
696 
697     // Um an den SwXShape* zu gelangen, brauchen wir ein Interface,
698     // das auch vom SwXShape implementiert wird.
699     uno::Reference< beans::XPropertySet > xPropSet( rShape, UNO_QUERY );
700 
701     ViewShell *pVSh;
702     pDoc->GetEditShell( &pVSh );
703     if( !pVSh && !nEventId )
704     {
705         // If there is no view shell by now and the doc shell is an internal
706         // one, no view shell will be created. That for, we have to do that of
707         // our own. This happens if a linked section is inserted or refreshed.
708         SwDocShell *pDocSh = pDoc->GetDocShell();
709         if( pDocSh )
710         {
711             if ( pDocSh->GetMedium() )
712             {
713                 // if there is no hidden property in the MediaDescriptor it should be removed after loading
714                 SFX_ITEMSET_ARG( pDocSh->GetMedium()->GetItemSet(), pHiddenItem, SfxBoolItem, SID_HIDDEN, sal_False );
715                 bRemoveHidden = ( pHiddenItem == NULL || !pHiddenItem->GetValue() );
716             }
717 
718             pTempViewFrame = SfxViewFrame::LoadHiddenDocument( *pDocSh, 0 );
719             CallStartAction();
720             pDoc->GetEditShell( &pVSh );
721         }
722     }
723 
724     uno::Reference< XUnoTunnel> xTunnel( xPropSet, UNO_QUERY );
725     SwXShape *pSwShape = xTunnel.is() ?
726         reinterpret_cast< SwXShape *>( sal::static_int_cast< sal_IntPtr >(
727             xTunnel->getSomething(SwXShape::getUnoTunnelId()) ))
728         : 0;
729 
730     ASSERT( pSwShape, "Wo ist das SW-Shape?" );
731 
732     // es muss ein Draw-Format sein
733     SwFrmFmt *pFrmFmt = pSwShape->GetFrmFmt();
734     ASSERT( RES_DRAWFRMFMT == pFrmFmt->Which(), "Kein DrawFrmFmt" );
735 
736     // Schauen, ob es ein SdrObject dafuer gibt
737     const SdrObject *pObj = pFrmFmt->FindSdrObject();
738     ASSERT( pObj, "SdrObject nicht gefunden" );
739     ASSERT( FmFormInventor == pObj->GetObjInventor(), "falscher Inventor" );
740 
741     const SdrView* pDrawView = pVSh ? pVSh->GetDrawView() : 0;
742 
743     SdrUnoObj *pFormObj = PTR_CAST( SdrUnoObj, pObj );
744     uno::Reference< awt::XControl > xControl;
745     if ( pDrawView && pVSh->GetWin() )
746         xControl = pFormObj->GetUnoControl( *pDrawView, *pVSh->GetWin() );
747 
748     awt::Size aSz( rShape->getSize() );
749     awt::Size aNewSz( 0, 0 );
750 
751     // #i71248# ensure we got a XControl before apllying corrections
752     if(xControl.is())
753     {
754         if( bMinWidth || bMinHeight )
755         {
756             uno::Reference< awt::XLayoutConstrains > xLC( xControl, UNO_QUERY );
757             awt::Size aTmpSz( xLC->getPreferredSize() );
758             if( bMinWidth )
759                 aNewSz.Width = aTmpSz.Width;
760             if( bMinHeight )
761                 aNewSz.Height = aTmpSz.Height;
762         }
763         if( rTextSz.Width() || rTextSz.Height())
764         {
765             uno::Reference< awt::XTextLayoutConstrains > xLC( xControl, UNO_QUERY );
766             ASSERT( xLC.is(), "kein XTextLayoutConstrains" );
767             if( xLC.is() )
768             {
769                 awt::Size aTmpSz( rTextSz.Width(), rTextSz.Height() );
770                 if( -1 == rTextSz.Width() )
771                 {
772                     aTmpSz.Width = 0;
773                     aTmpSz.Height = nSelectEntryCnt;
774                 }
775                 aTmpSz = xLC->getMinimumSize( static_cast< sal_Int16 >(aTmpSz.Width), static_cast< sal_Int16 >(aTmpSz.Height) );
776                 if( rTextSz.Width() )
777                     aNewSz.Width = aTmpSz.Width;
778                 if( rTextSz.Height() )
779                     aNewSz.Height = aTmpSz.Height;
780             }
781         }
782     }
783 
784     if( Application::GetDefaultDevice() )
785     {
786         Size aTmpSz( aNewSz.Width, aNewSz.Height );
787         aTmpSz = Application::GetDefaultDevice()
788                         ->PixelToLogic( aTmpSz, MapMode( MAP_100TH_MM ) );
789         aNewSz.Width  = aTmpSz.Width();
790         aNewSz.Height = aTmpSz.Height();
791     }
792     if( aNewSz.Width )
793     {
794         if( aNewSz.Width < MINLAY )
795             aNewSz.Width = MINLAY;
796         aSz.Width = aNewSz.Width;
797     }
798     if( aNewSz.Height )
799     {
800         if( aNewSz.Height < MINLAY )
801             aNewSz.Height = MINLAY;
802         aSz.Height = aNewSz.Height;
803     }
804 
805     rShape->setSize( aSz );
806 }
807 
lcl_html_setEvents(const uno::Reference<script::XEventAttacherManager> & rEvtMn,sal_uInt32 nPos,const SvxMacroTableDtor & rMacroTbl,const SvStringsDtor & rUnoMacroTbl,const SvStringsDtor & rUnoMacroParamTbl,const String & rType)808 static void lcl_html_setEvents(
809         const uno::Reference< script::XEventAttacherManager > & rEvtMn,
810         sal_uInt32 nPos, const SvxMacroTableDtor& rMacroTbl,
811         const SvStringsDtor& rUnoMacroTbl,
812         const SvStringsDtor& rUnoMacroParamTbl,
813         const String& rType )
814 {
815     // Erstmal muss die Anzahl der Events ermittelt werden ...
816     sal_Int32 nEvents = 0;
817     sal_uInt16 i;
818 
819     for( i = 0; HTML_ET_END != aEventTypeTable[i]; i++ )
820     {
821         const SvxMacro *pMacro = rMacroTbl.Get( aEventTypeTable[i] );
822         // Solange nicht alle Events implementiert sind, enthaelt die
823         // Tabelle auch Leerstrings!
824         if( pMacro && aEventListenerTable[i] )
825             nEvents++;
826     }
827     for( i=0; i< rUnoMacroTbl.Count(); i++ )
828     {
829         const String& rStr = *rUnoMacroTbl[i];
830         xub_StrLen nIndex = 0;
831         if( !rStr.GetToken( 0, '-', nIndex ).Len() || STRING_NOTFOUND == nIndex )
832             continue;
833         if( !rStr.GetToken( 0, '-', nIndex ).Len() || STRING_NOTFOUND == nIndex )
834             continue;
835         if( nIndex < rStr.Len() )
836             nEvents++;
837     }
838 
839     if( 0==nEvents )
840         return;
841 
842     Sequence<script::ScriptEventDescriptor> aDescs( nEvents );
843     script::ScriptEventDescriptor* pDescs = aDescs.getArray();
844     sal_Int32 nEvent = 0;
845 
846     for( i=0; HTML_ET_END != aEventTypeTable[i]; i++ )
847     {
848         const SvxMacro *pMacro = rMacroTbl.Get( aEventTypeTable[i] );
849         if( pMacro && aEventListenerTable[i] )
850         {
851             script::ScriptEventDescriptor& rDesc = pDescs[nEvent++];
852             rDesc.ListenerType =
853                     OUString::createFromAscii(aEventListenerTable[i]);
854             rDesc.EventMethod = OUString::createFromAscii(aEventMethodTable[i]);
855             rDesc.ScriptType = pMacro->GetLanguage();
856             rDesc.ScriptCode = pMacro->GetMacName();
857         }
858     }
859 
860     for( i=0; i< rUnoMacroTbl.Count(); i++ )
861     {
862         const String& rStr = *rUnoMacroTbl[i];
863         xub_StrLen nIndex = 0;
864         String sListener( rStr.GetToken( 0, '-', nIndex ) );
865         if( !sListener.Len() || STRING_NOTFOUND == nIndex )
866             continue;
867 
868         String sMethod( rStr.GetToken( 0, '-', nIndex ) );
869         if( !sMethod.Len() || STRING_NOTFOUND == nIndex )
870             continue;
871 
872         String sCode( rStr.Copy( nIndex ) );
873         if( !sCode.Len() )
874             continue;
875 
876         script::ScriptEventDescriptor& rDesc = pDescs[nEvent++];
877         rDesc.ListenerType = sListener;
878         rDesc.EventMethod = sMethod;
879         rDesc.ScriptType = rType;
880         rDesc.ScriptCode = sCode;
881         rDesc.AddListenerParam = OUString();
882 
883         if( rUnoMacroParamTbl.Count() )
884         {
885             String sSearch( sListener );
886             sSearch += '-';
887             sSearch += sMethod;
888             sSearch += '-';
889             xub_StrLen nLen = sSearch.Len();
890             for( sal_uInt16 j=0; j < rUnoMacroParamTbl.Count(); j++ )
891             {
892                 const String& rParam = *rUnoMacroParamTbl[j];
893                 if( rParam.CompareTo( sSearch, nLen ) == COMPARE_EQUAL &&
894                     rParam.Len() > nLen )
895                 {
896                     rDesc.AddListenerParam = rParam.Copy(nLen);
897                     break;
898                 }
899             }
900         }
901     }
902     rEvtMn->registerScriptEvents( nPos, aDescs );
903 }
904 
lcl_html_getEvents(const String & rOption,const String & rValue,SvStringsDtor & rUnoMacroTbl,SvStringsDtor & rUnoMacroParamTbl)905 static void lcl_html_getEvents( const String& rOption, const String& rValue,
906                                 SvStringsDtor& rUnoMacroTbl,
907                                 SvStringsDtor& rUnoMacroParamTbl )
908 {
909     if( rOption.CompareIgnoreCaseToAscii( OOO_STRING_SVTOOLS_HTML_O_sdevent,
910                             sizeof(OOO_STRING_SVTOOLS_HTML_O_sdevent)-1 ) == COMPARE_EQUAL )
911     {
912         String *pEvent = new String( rOption.Copy(sizeof(OOO_STRING_SVTOOLS_HTML_O_sdevent)-1) );
913         *pEvent += '-';
914         *pEvent += rValue;
915         rUnoMacroTbl.Insert( pEvent, rUnoMacroTbl.Count() );
916     }
917     else if( rOption.CompareIgnoreCaseToAscii( OOO_STRING_SVTOOLS_HTML_O_sdaddparam,
918                             sizeof(OOO_STRING_SVTOOLS_HTML_O_sdaddparam)-1 ) == COMPARE_EQUAL )
919     {
920         String *pParam =
921                     new String( rOption.Copy( sizeof(OOO_STRING_SVTOOLS_HTML_O_sdaddparam)-1 ) );
922         *pParam += '-';
923         *pParam += rValue;
924         rUnoMacroParamTbl.Insert( pParam, rUnoMacroParamTbl.Count() );
925     }
926 }
927 
InsertControl(const uno::Reference<XFormComponent> & rFComp,const uno::Reference<beans::XPropertySet> & rFCompPropSet,const Size & rSize,sal_Int16 eVertOri,sal_Int16 eHoriOri,SfxItemSet & rCSS1ItemSet,SvxCSS1PropertyInfo & rCSS1PropInfo,const SvxMacroTableDtor & rMacroTbl,const SvStringsDtor & rUnoMacroTbl,const SvStringsDtor & rUnoMacroParamTbl,sal_Bool bSetFCompPropSet,sal_Bool bHidden)928 uno::Reference< drawing::XShape > SwHTMLParser::InsertControl(
929         const uno::Reference< XFormComponent > & rFComp,
930         const uno::Reference< beans::XPropertySet > & rFCompPropSet,
931         const Size& rSize, sal_Int16 eVertOri, sal_Int16 eHoriOri,
932         SfxItemSet& rCSS1ItemSet, SvxCSS1PropertyInfo& rCSS1PropInfo,
933         const SvxMacroTableDtor& rMacroTbl, const SvStringsDtor& rUnoMacroTbl,
934         const SvStringsDtor& rUnoMacroParamTbl, sal_Bool bSetFCompPropSet,
935         sal_Bool bHidden )
936 {
937     uno::Reference< drawing::XShape >  xShape;
938 
939     const uno::Reference< container::XIndexContainer > & rFormComps =
940         pFormImpl->GetFormComps();
941     Any aAny( &rFComp, ::getCppuType( (uno::Reference< XFormComponent>*)0 ) );
942     rFormComps->insertByIndex( rFormComps->getCount(), aAny );
943 
944     if( !bHidden )
945     {
946         Any aTmp;
947         sal_uInt16 nLeftSpace = 0, nRightSpace = 0,
948                    nUpperSpace = 0, nLowerSpace = 0;
949 
950         const uno::Reference< XMultiServiceFactory > & rServiceFactory =
951             pFormImpl->GetServiceFactory();
952         if( !rServiceFactory.is() )
953             return xShape;
954 
955         uno::Reference< XInterface > xCreate =
956             rServiceFactory ->createInstance(
957                 OUString::createFromAscii("com.sun.star.drawing.ControlShape"));
958         if( !xCreate.is() )
959             return xShape;
960 
961         xShape = uno::Reference< drawing::XShape >( xCreate, UNO_QUERY );
962 
963         DBG_ASSERT( xShape.is(), "XShape nicht erhalten" );
964         awt::Size aTmpSz;
965         aTmpSz.Width  = rSize.Width();
966         aTmpSz.Height = rSize.Height();
967         xShape->setSize( aTmpSz );
968 
969         uno::Reference< beans::XPropertySet > xShapePropSet( xCreate, UNO_QUERY );
970 
971         // linken/rechten Rand setzen
972         const SfxPoolItem *pItem;
973         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_LR_SPACE, sal_True,
974                                                      &pItem ) )
975         {
976             // Ggf. den Erstzeilen-Einzug noch plaetten
977             const SvxLRSpaceItem *pLRItem = (const SvxLRSpaceItem *)pItem;
978             SvxLRSpaceItem aLRItem( *pLRItem );
979             aLRItem.SetTxtFirstLineOfst( 0 );
980             if( rCSS1PropInfo.bLeftMargin )
981             {
982                 nLeftSpace = static_cast< sal_uInt16 >(TWIP_TO_MM100( aLRItem.GetLeft() ));
983                 rCSS1PropInfo.bLeftMargin = sal_False;
984             }
985             if( rCSS1PropInfo.bRightMargin )
986             {
987                 nRightSpace = static_cast< sal_uInt16 >(TWIP_TO_MM100( aLRItem.GetRight() ));
988                 rCSS1PropInfo.bRightMargin = sal_False;
989             }
990             rCSS1ItemSet.ClearItem( RES_LR_SPACE );
991         }
992         if( nLeftSpace || nRightSpace )
993         {
994             Any aAny2;
995             aAny2 <<= (sal_Int32)nLeftSpace;
996             xShapePropSet->setPropertyValue(
997                     OUString::createFromAscii( "LeftMargin" ), aAny2 );
998 
999             aAny2 <<= (sal_Int32)nRightSpace;
1000             xShapePropSet->setPropertyValue(
1001                     OUString::createFromAscii( "RightMargin" ), aAny2 );
1002         }
1003 
1004         // oberen/unteren Rand setzen
1005         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_UL_SPACE, sal_True,
1006                                                      &pItem ) )
1007         {
1008             // Ggf. den Erstzeilen-Einzug noch plaetten
1009             const SvxULSpaceItem *pULItem = (const SvxULSpaceItem *)pItem;
1010             if( rCSS1PropInfo.bTopMargin )
1011             {
1012                 nUpperSpace = TWIP_TO_MM100_UNSIGNED( pULItem->GetUpper() );
1013                 rCSS1PropInfo.bTopMargin = sal_False;
1014             }
1015             if( rCSS1PropInfo.bBottomMargin )
1016             {
1017                 nLowerSpace = TWIP_TO_MM100_UNSIGNED( pULItem->GetLower() );
1018                 rCSS1PropInfo.bBottomMargin = sal_False;
1019             }
1020 
1021             rCSS1ItemSet.ClearItem( RES_UL_SPACE );
1022         }
1023         if( nUpperSpace || nLowerSpace )
1024         {
1025             uno::Any aAny2;
1026             aAny2 <<= (sal_Int32)nUpperSpace;
1027             xShapePropSet->setPropertyValue(
1028                     OUString::createFromAscii( "TopMargin" ), aAny2 );
1029 
1030             aAny2 <<= (sal_Int32)nLowerSpace;
1031             xShapePropSet->setPropertyValue(
1032                     OUString::createFromAscii( "BottomMargin" ), aAny2 );
1033         }
1034 
1035         uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
1036             rFCompPropSet->getPropertySetInfo();
1037         OUString sPropName = OUString::createFromAscii( "BackgroundColor" );
1038         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_BACKGROUND, sal_True,
1039                                                      &pItem ) &&
1040             xPropSetInfo->hasPropertyByName( sPropName ) )
1041         {
1042             const Color &rColor = ((const SvxBrushItem *)pItem)->GetColor();
1043             /// OD 02.09.2002 #99657#
1044             /// copy color, if color is not "no fill"/"auto fill"
1045             if( rColor.GetColor() != COL_TRANSPARENT )
1046             {
1047                 /// OD 02.09.2002 #99657#
1048                 /// copy complete color with transparency
1049                 aTmp <<= static_cast<sal_Int32>(rColor.GetColor());
1050                 rFCompPropSet->setPropertyValue( sPropName, aTmp );
1051             }
1052 
1053         }
1054 
1055         sPropName = OUString::createFromAscii( "TextColor" );
1056         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_COLOR, sal_True,
1057                                                      &pItem ) &&
1058             xPropSetInfo->hasPropertyByName( sPropName ) )
1059         {
1060             aTmp <<= (sal_Int32)((const SvxColorItem *)pItem)->GetValue()
1061                                                          .GetRGBColor();
1062             rFCompPropSet->setPropertyValue( sPropName, aTmp );
1063         }
1064 
1065         sPropName = OUString::createFromAscii( "FontHeight" );
1066         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_FONTSIZE,
1067                                                      sal_True, &pItem ) &&
1068             xPropSetInfo->hasPropertyByName( sPropName ) )
1069         {
1070             float fVal = static_cast< float >(
1071                 (((SvxFontHeightItem *)pItem)->GetHeight()) / 20.0 );
1072             aTmp.setValue( &fVal, ::getCppuType(&fVal));
1073             rFCompPropSet->setPropertyValue( sPropName, aTmp );
1074         }
1075 
1076         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_FONT, sal_True,
1077                                                      &pItem ) )
1078         {
1079             const SvxFontItem *pFontItem = (SvxFontItem *)pItem;
1080             sPropName = OUString::createFromAscii( "FontName" );
1081             if( xPropSetInfo->hasPropertyByName( sPropName ) )
1082             {
1083                 aTmp <<= OUString( pFontItem->GetFamilyName() );
1084                 rFCompPropSet->setPropertyValue( sPropName, aTmp );
1085             }
1086             sPropName = OUString::createFromAscii( "FontStyleName" );
1087             if( xPropSetInfo->hasPropertyByName( sPropName ) )
1088             {
1089                 aTmp <<= OUString( pFontItem->GetStyleName() );
1090                 rFCompPropSet->setPropertyValue( sPropName, aTmp );
1091             }
1092             sPropName = OUString::createFromAscii( "FontFamily" );
1093             if( xPropSetInfo->hasPropertyByName( sPropName ) )
1094             {
1095                 aTmp <<= (sal_Int16)pFontItem->GetFamily() ;
1096                 rFCompPropSet->setPropertyValue( sPropName, aTmp );
1097             }
1098             sPropName = OUString::createFromAscii( "FontCharset" );
1099             if( xPropSetInfo->hasPropertyByName( sPropName ) )
1100             {
1101                 aTmp <<= (sal_Int16)pFontItem->GetCharSet() ;
1102                 rFCompPropSet->setPropertyValue( sPropName, aTmp );
1103             }
1104             sPropName = OUString::createFromAscii( "FontPitch" );
1105             if( xPropSetInfo->hasPropertyByName( sPropName ) )
1106             {
1107                 aTmp <<= (sal_Int16)pFontItem->GetPitch() ;
1108                 rFCompPropSet->setPropertyValue( sPropName, aTmp );
1109             }
1110         }
1111 
1112         sPropName = OUString::createFromAscii( "FontWeight" );
1113         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_WEIGHT,
1114                                                      sal_True, &pItem ) &&
1115             xPropSetInfo->hasPropertyByName( sPropName ) )
1116         {
1117             float fVal = VCLUnoHelper::ConvertFontWeight(
1118                     ((SvxWeightItem *)pItem)->GetWeight() );
1119             aTmp.setValue( &fVal, ::getCppuType(&fVal));
1120             rFCompPropSet->setPropertyValue( sPropName, aTmp );
1121         }
1122 
1123         sPropName = OUString::createFromAscii( "FontSlant" );
1124         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_POSTURE,
1125                                                      sal_True, &pItem ) &&
1126             xPropSetInfo->hasPropertyByName( sPropName ) )
1127         {
1128             aTmp <<= (sal_Int16)((SvxPostureItem *)pItem)->GetPosture();
1129             rFCompPropSet->setPropertyValue( sPropName, aTmp );
1130         }
1131 
1132         sPropName = OUString::createFromAscii( "FontUnderline" );
1133         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_UNDERLINE,
1134                                                      sal_True, &pItem ) &&
1135             xPropSetInfo->hasPropertyByName( sPropName ) )
1136         {
1137             aTmp <<= (sal_Int16)((SvxUnderlineItem *)pItem)->GetLineStyle();
1138             rFCompPropSet->setPropertyValue( sPropName, aTmp );
1139         }
1140 
1141         sPropName = OUString::createFromAscii( "FontStrikeout" );
1142         if( SFX_ITEM_SET==rCSS1ItemSet.GetItemState( RES_CHRATR_CROSSEDOUT,
1143                                                      sal_True, &pItem ) &&
1144             xPropSetInfo->hasPropertyByName( sPropName ) )
1145         {
1146             aTmp <<= (sal_Int16)((SvxCrossedOutItem *)pItem)->GetStrikeout();
1147             rFCompPropSet->setPropertyValue( sPropName, aTmp );
1148         }
1149 
1150         uno::Reference< text::XTextRange >  xTxtRg;
1151         sal_Int16 nAnchorType = text::TextContentAnchorType_AS_CHARACTER;
1152         sal_Bool bSetPos = sal_False, bSetSurround = sal_False;
1153         sal_Int32 nXPos = 0, nYPos = 0;
1154         sal_Int16 nSurround = text::WrapTextMode_NONE;
1155         if( SVX_CSS1_POS_ABSOLUTE == rCSS1PropInfo.ePosition &&
1156             SVX_CSS1_LTYPE_TWIP == rCSS1PropInfo.eLeftType &&
1157             SVX_CSS1_LTYPE_TWIP == rCSS1PropInfo.eTopType )
1158         {
1159             const SwStartNode *pFlySttNd =
1160                 pPam->GetPoint()->nNode.GetNode().FindFlyStartNode();
1161 
1162             if( pFlySttNd )
1163             {
1164                 nAnchorType = text::TextContentAnchorType_AT_FRAME;
1165                 SwPaM aPaM( *pFlySttNd );
1166 
1167                 uno::Reference< text::XText >  xDummyTxtRef; // unsauber, aber laut OS geht das ...
1168                 xTxtRg = new SwXTextRange( aPaM, xDummyTxtRef );
1169             }
1170             else
1171             {
1172                 nAnchorType = text::TextContentAnchorType_AT_PAGE;
1173             }
1174             nXPos = TWIP_TO_MM100( rCSS1PropInfo.nLeft ) + nLeftSpace;
1175             nYPos = TWIP_TO_MM100( rCSS1PropInfo.nTop ) + nUpperSpace;
1176             bSetPos = sal_True;
1177 
1178             nSurround = text::WrapTextMode_THROUGHT;
1179             bSetSurround = sal_True;
1180         }
1181         else if( SVX_ADJUST_LEFT == rCSS1PropInfo.eFloat ||
1182                  text::HoriOrientation::LEFT == eHoriOri )
1183         {
1184             nAnchorType = text::TextContentAnchorType_AT_PARAGRAPH;
1185             nXPos = nLeftSpace;
1186             nYPos = nUpperSpace;
1187             bSetPos = sal_True;
1188             nSurround = text::WrapTextMode_RIGHT;
1189             bSetSurround = sal_True;
1190         }
1191         else if( text::VertOrientation::NONE != eVertOri )
1192         {
1193             sal_Int16 nVertOri = text::VertOrientation::NONE;
1194             switch( eVertOri )
1195             {
1196             case text::VertOrientation::NONE:
1197                 nVertOri = text::VertOrientation::NONE;
1198                 break;
1199             case text::VertOrientation::TOP:
1200                 nVertOri = text::VertOrientation::TOP;
1201                 break;
1202             case text::VertOrientation::CENTER:
1203                 nVertOri = text::VertOrientation::CENTER;
1204                 break;
1205             case text::VertOrientation::BOTTOM:
1206                 nVertOri = text::VertOrientation::BOTTOM;
1207                 break;
1208             case text::VertOrientation::CHAR_TOP:
1209                 nVertOri = text::VertOrientation::CHAR_TOP;
1210                 break;
1211             case text::VertOrientation::CHAR_CENTER:
1212                 nVertOri = text::VertOrientation::CHAR_CENTER;
1213                 break;
1214             case text::VertOrientation::CHAR_BOTTOM:
1215                 nVertOri = text::VertOrientation::CHAR_BOTTOM;
1216                 break;
1217             case text::VertOrientation::LINE_TOP:
1218                 nVertOri = text::VertOrientation::LINE_TOP;
1219                 break;
1220             case text::VertOrientation::LINE_CENTER:
1221                 nVertOri = text::VertOrientation::LINE_CENTER;
1222                 break;
1223             case text::VertOrientation::LINE_BOTTOM:
1224                 nVertOri = text::VertOrientation::LINE_BOTTOM;
1225                 break;
1226             }
1227             aTmp <<= (sal_Int16)nVertOri ;
1228             xShapePropSet->setPropertyValue(
1229                     OUString::createFromAscii( "VertOrient" ), aTmp );
1230         }
1231 
1232         aTmp <<= (sal_Int16)nAnchorType ;
1233         xShapePropSet->setPropertyValue(
1234                 OUString::createFromAscii( "AnchorType" ), aTmp );
1235 
1236         if( text::TextContentAnchorType_AT_PAGE == nAnchorType )
1237         {
1238             aTmp <<= (sal_Int16) 1 ;
1239             xShapePropSet->setPropertyValue(
1240                     OUString::createFromAscii( "AnchorPageNo" ), aTmp );
1241         }
1242         else
1243         {
1244             if( !xTxtRg.is() )
1245             {
1246                 uno::Reference< text::XText >  xDummyTxtRef; // unsauber, aber laut OS geht das ...
1247                 xTxtRg = new SwXTextRange( *pPam, xDummyTxtRef );
1248             }
1249 
1250             aTmp.setValue( &xTxtRg,
1251                            ::getCppuType((uno::Reference< text::XTextRange>*)0));
1252             xShapePropSet->setPropertyValue(
1253                     OUString::createFromAscii( "TextRange" ), aTmp );
1254         }
1255 
1256         if( bSetPos )
1257         {
1258             aTmp <<= (sal_Int16)text::HoriOrientation::NONE;
1259             xShapePropSet->setPropertyValue(
1260                     OUString::createFromAscii( "HoriOrient" ), aTmp );
1261             aTmp <<= (sal_Int32)nXPos ;
1262             xShapePropSet->setPropertyValue(
1263                     OUString::createFromAscii( "HoriOrientPosition" ), aTmp );
1264 
1265             aTmp <<= (sal_Int16)text::VertOrientation::NONE;
1266             xShapePropSet->setPropertyValue(
1267                     OUString::createFromAscii( "VertOrient" ), aTmp );
1268             aTmp <<= (sal_Int32)nYPos ;
1269             xShapePropSet->setPropertyValue(
1270                     OUString::createFromAscii( "VertOrientPosition" ), aTmp );
1271         }
1272         if( bSetSurround )
1273         {
1274             aTmp <<= (sal_Int16)nSurround ;
1275             xShapePropSet->setPropertyValue(
1276                     OUString::createFromAscii( "Surround" ), aTmp );
1277         }
1278 
1279         pFormImpl->GetShapes()->add(xShape);
1280 
1281         // Das Control-Model am Control-Shape setzen
1282         uno::Reference< drawing::XControlShape > xControlShape( xShape, UNO_QUERY );
1283         uno::Reference< awt::XControlModel >  xControlModel( rFComp, UNO_QUERY );
1284         xControlShape->setControl( xControlModel );
1285     }
1286 
1287     // Da beim Einfuegen der Controls der Fokus gesetzt wird, werden
1288     // auch schon Fokus-Events verschickt. Damit die nicht evtl. schon
1289     // vorhendene JavaSCript-Eents rufen, werden die Events nachtraeglich
1290     // gesetzt.
1291     if( rMacroTbl.Count() || rUnoMacroTbl.Count() )
1292     {
1293         lcl_html_setEvents( pFormImpl->GetControlEventManager(),
1294                             rFormComps->getCount() - 1,
1295                             rMacroTbl, rUnoMacroTbl, rUnoMacroParamTbl,
1296                             GetScriptTypeString(pFormImpl->GetHeaderAttrs()) );
1297     }
1298 
1299     if( bSetFCompPropSet )
1300     {
1301         pFormImpl->SetFCompPropSet( rFCompPropSet );
1302     }
1303 
1304     return xShape;
1305 }
1306 
NewForm(sal_Bool bAppend)1307 void SwHTMLParser::NewForm( sal_Bool bAppend )
1308 {
1309     // Gibt es schon eine Form?
1310     if( pFormImpl && pFormImpl->GetFormComps().is() )
1311         return;
1312 
1313     if( bAppend )
1314     {
1315         if( pPam->GetPoint()->nContent.GetIndex() )
1316             AppendTxtNode( AM_SPACE );
1317         else
1318             AddParSpace();
1319     }
1320 
1321     if( !pFormImpl )
1322         pFormImpl = new SwHTMLForm_Impl( pDoc->GetDocShell() );
1323 
1324     String aAction( sBaseURL );
1325     String sName, sTarget;
1326     sal_uInt16 nEncType = FormSubmitEncoding_URL;
1327     sal_uInt16 nMethod = FormSubmitMethod_GET;
1328     SvxMacroTableDtor aMacroTbl;
1329     SvStringsDtor aUnoMacroTbl;
1330     SvStringsDtor aUnoMacroParamTbl;
1331     SvKeyValueIterator *pHeaderAttrs = pFormImpl->GetHeaderAttrs();
1332     ScriptType eDfltScriptType = GetScriptType( pHeaderAttrs );
1333     const String& rDfltScriptType = GetScriptTypeString( pHeaderAttrs );
1334 
1335     const HTMLOptions *pHTMLOptions = GetOptions();
1336     for( sal_uInt16 i = pHTMLOptions->Count(); i; )
1337     {
1338         const HTMLOption *pOption = (*pHTMLOptions)[--i];
1339         ScriptType eScriptType2 = eDfltScriptType;
1340         sal_uInt16 nEvent = 0;
1341         sal_Bool bSetEvent = sal_False;
1342 
1343         switch( pOption->GetToken() )
1344         {
1345         case HTML_O_ACTION:
1346             aAction = pOption->GetString();
1347             break;
1348         case HTML_O_METHOD:
1349             nMethod = pOption->GetEnum( aHTMLFormMethodTable, nMethod );
1350             break;
1351         case HTML_O_ENCTYPE:
1352             nEncType = pOption->GetEnum( aHTMLFormEncTypeTable, nEncType );
1353             break;
1354         case HTML_O_TARGET:
1355             sTarget = pOption->GetString();
1356             break;
1357         case HTML_O_NAME:
1358             sName = pOption->GetString();
1359             break;
1360 
1361         case HTML_O_SDONSUBMIT:
1362             eScriptType2 = STARBASIC;
1363         case HTML_O_ONSUBMIT:
1364             nEvent = HTML_ET_ONSUBMITFORM;
1365             bSetEvent = sal_True;
1366             break;
1367 
1368         case HTML_O_SDONRESET:
1369             eScriptType2 = STARBASIC;
1370         case HTML_O_ONRESET:
1371             nEvent = HTML_ET_ONRESETFORM;
1372             bSetEvent = sal_True;
1373             break;
1374 
1375         default:
1376             lcl_html_getEvents( pOption->GetTokenString(),
1377                                 pOption->GetString(),
1378                                 aUnoMacroTbl, aUnoMacroParamTbl );
1379             break;
1380         }
1381 
1382         if( bSetEvent )
1383         {
1384             String sEvent( pOption->GetString() );
1385             if( sEvent.Len() )
1386             {
1387                 sEvent.ConvertLineEnd();
1388                 String aScriptType2;
1389                 if( EXTENDED_STYPE==eScriptType2 )
1390                     aScriptType2 = rDfltScriptType;
1391                 aMacroTbl.Insert( nEvent, new SvxMacro( sEvent, aScriptType2,
1392                                   eScriptType2 ) );
1393             }
1394         }
1395     }
1396 
1397     const uno::Reference< XMultiServiceFactory > & rSrvcMgr =
1398         pFormImpl->GetServiceFactory();
1399     if( !rSrvcMgr.is() )
1400         return;
1401 
1402     uno::Reference< XInterface > xInt = rSrvcMgr->createInstance(
1403             OUString::createFromAscii( "com.sun.star.form.component.Form" ) );
1404     if( !xInt.is() )
1405         return;
1406 
1407     uno::Reference< XForm >  xForm( xInt, UNO_QUERY );
1408     DBG_ASSERT( xForm.is(), "keine Form?" );
1409 
1410     uno::Reference< container::XIndexContainer > xFormComps( xForm, UNO_QUERY );
1411     pFormImpl->SetFormComps( xFormComps );
1412 
1413     uno::Reference< beans::XPropertySet > xFormPropSet( xForm, UNO_QUERY );
1414 
1415     Any aTmp;
1416     aTmp <<= OUString(sName);
1417     xFormPropSet->setPropertyValue( OUString::createFromAscii( "Name" ), aTmp );
1418 
1419     if( aAction.Len() )
1420     {
1421         aAction = URIHelper::SmartRel2Abs(INetURLObject(sBaseURL), aAction, Link(), false);
1422     }
1423     else
1424     {
1425         // Bei leerer URL das Directory nehmen
1426         INetURLObject aURLObj( aPathToFile );
1427         aAction = aURLObj.GetPartBeforeLastName();
1428     }
1429     aTmp <<= OUString(aAction);
1430     xFormPropSet->setPropertyValue( OUString::createFromAscii( "TargetURL" ),
1431                                     aTmp );
1432 
1433     FormSubmitMethod eMethod = (FormSubmitMethod)nMethod;
1434     aTmp.setValue( &eMethod, ::getCppuType((const FormSubmitMethod*)0) );
1435     xFormPropSet->setPropertyValue( OUString::createFromAscii( "SubmitMethod" ),
1436                                     aTmp );
1437 
1438     FormSubmitEncoding eEncType = (FormSubmitEncoding)nEncType;
1439     aTmp.setValue( &eEncType, ::getCppuType((const FormSubmitEncoding*)0) );
1440     xFormPropSet->setPropertyValue(
1441             OUString::createFromAscii( "SubmitEncoding" ), aTmp );
1442 
1443     if( sTarget.Len() )
1444     {
1445         aTmp <<= OUString(sTarget);
1446         xFormPropSet->setPropertyValue(
1447                 OUString::createFromAscii( "TargetFrame" ), aTmp );
1448     }
1449 
1450     const uno::Reference< container::XIndexContainer > & rForms =
1451         pFormImpl->GetForms();
1452     Any aAny( &xForm, ::getCppuType((uno::Reference< XForm>*)0) );
1453     rForms->insertByIndex( rForms->getCount(), aAny );
1454     if( aMacroTbl.Count() )
1455         lcl_html_setEvents( pFormImpl->GetFormEventManager(),
1456                             rForms->getCount() - 1,
1457                             aMacroTbl, aUnoMacroTbl, aUnoMacroParamTbl,
1458                             rDfltScriptType );
1459 }
1460 
EndForm(sal_Bool bAppend)1461 void SwHTMLParser::EndForm( sal_Bool bAppend )
1462 {
1463     if( pFormImpl && pFormImpl->GetFormComps().is() )
1464     {
1465         if( bAppend )
1466         {
1467             if( pPam->GetPoint()->nContent.GetIndex() )
1468                 AppendTxtNode( AM_SPACE );
1469             else
1470                 AddParSpace();
1471         }
1472 
1473         pFormImpl->ReleaseFormComps();
1474     }
1475 }
1476 
InsertInput()1477 void SwHTMLParser::InsertInput()
1478 {
1479     if( pPendStack )
1480     {
1481         SetPendingControlSize( HTML_INPUT );
1482         return;
1483     }
1484 
1485     if( !pFormImpl || !pFormImpl->GetFormComps().is() )
1486         return;
1487 
1488     String sImgSrc, aId, aClass, aStyle, sText;
1489     String sName;
1490     SvxMacroTableDtor aMacroTbl;
1491     SvStringsDtor aUnoMacroTbl;
1492     SvStringsDtor aUnoMacroParamTbl;
1493     sal_uInt16 nSize = 0;
1494     sal_Int16 nMaxLen = 0;
1495     sal_Int16 nChecked = STATE_NOCHECK;
1496     sal_Int32 nTabIndex = TABINDEX_MAX + 1;
1497     HTMLInputType eType = HTML_IT_TEXT;
1498     sal_Bool bDisabled = sal_False, bValue = sal_False;
1499     sal_Bool bSetGrfWidth = sal_False, bSetGrfHeight = sal_False;
1500     sal_Bool bHidden = sal_False;
1501     long nWidth=0, nHeight=0;
1502     sal_Int16 eVertOri = text::VertOrientation::TOP;
1503     sal_Int16 eHoriOri = text::HoriOrientation::NONE;
1504     SvKeyValueIterator *pHeaderAttrs = pFormImpl->GetHeaderAttrs();
1505     ScriptType eDfltScriptType = GetScriptType( pHeaderAttrs );
1506     const String& rDfltScriptType = GetScriptTypeString( pHeaderAttrs );
1507 
1508     sal_uInt16 nKeepCRLFToken = HTML_O_VALUE;
1509     const HTMLOptions *pHTMLOptions = GetOptions( &nKeepCRLFToken );
1510     for( sal_uInt16 i = pHTMLOptions->Count(); i; )
1511     {
1512         const HTMLOption *pOption = (*pHTMLOptions)[--i];
1513         ScriptType eScriptType2 = eDfltScriptType;
1514         sal_uInt16 nEvent = 0;
1515         sal_Bool bSetEvent = sal_False;
1516 
1517         switch( pOption->GetToken() )
1518         {
1519         case HTML_O_ID:
1520             aId = pOption->GetString();
1521             break;
1522         case HTML_O_STYLE:
1523             aStyle = pOption->GetString();
1524             break;
1525         case HTML_O_CLASS:
1526             aClass = pOption->GetString();
1527             break;
1528         case HTML_O_TYPE:
1529             eType = pOption->GetInputType();
1530             break;
1531         case HTML_O_NAME:
1532             sName = pOption->GetString();
1533             break;
1534         case HTML_O_VALUE:
1535             sText = pOption->GetString();
1536             bValue = sal_True;
1537             break;
1538         case HTML_O_CHECKED:
1539             nChecked = STATE_CHECK;
1540             break;
1541         case HTML_O_DISABLED:
1542             bDisabled = sal_True;
1543             break;
1544         case HTML_O_MAXLENGTH:
1545             nMaxLen = (sal_Int16)pOption->GetNumber();
1546             break;
1547         case HTML_O_SIZE:
1548             nSize = (sal_uInt16)pOption->GetNumber();
1549             break;
1550         case HTML_O_SRC:
1551             sImgSrc = pOption->GetString();
1552             break;
1553         case HTML_O_WIDTH:
1554             // erstmal nur als Pixelwerte merken!
1555             nWidth = pOption->GetNumber();
1556             break;
1557         case HTML_O_HEIGHT:
1558             // erstmal nur als Pixelwerte merken!
1559             nHeight = pOption->GetNumber();
1560             break;
1561         case HTML_O_ALIGN:
1562             eVertOri =
1563                 pOption->GetEnum( aHTMLImgVAlignTable, eVertOri );
1564             eHoriOri =
1565                 pOption->GetEnum( aHTMLImgHAlignTable, eHoriOri );
1566             break;
1567         case HTML_O_TABINDEX:
1568             // erstmal nur als Pixelwerte merken!
1569             nTabIndex = pOption->GetNumber();
1570             break;
1571 
1572         case HTML_O_SDONFOCUS:
1573             eScriptType2 = STARBASIC;
1574         case HTML_O_ONFOCUS:
1575             nEvent = HTML_ET_ONGETFOCUS;
1576             bSetEvent = sal_True;
1577             break;
1578 
1579         case HTML_O_SDONBLUR:               // eigtl. nur EDIT
1580             eScriptType2 = STARBASIC;
1581         case HTML_O_ONBLUR:
1582             nEvent = HTML_ET_ONLOSEFOCUS;
1583             bSetEvent = sal_True;
1584             break;
1585 
1586         case HTML_O_SDONCLICK:
1587             eScriptType2 = STARBASIC;
1588         case HTML_O_ONCLICK:
1589             nEvent = HTML_ET_ONCLICK;
1590             bSetEvent = sal_True;
1591             break;
1592 
1593         case HTML_O_SDONCHANGE:             // eigtl. nur EDIT
1594             eScriptType2 = STARBASIC;
1595         case HTML_O_ONCHANGE:
1596             nEvent = HTML_ET_ONCHANGE;
1597             bSetEvent = sal_True;
1598             break;
1599 
1600         case HTML_O_SDONSELECT:             // eigtl. nur EDIT
1601             eScriptType2 = STARBASIC;
1602         case HTML_O_ONSELECT:
1603             nEvent = HTML_ET_ONSELECT;
1604             bSetEvent = sal_True;
1605             break;
1606 
1607         default:
1608             lcl_html_getEvents( pOption->GetTokenString(),
1609                                 pOption->GetString(),
1610                                 aUnoMacroTbl, aUnoMacroParamTbl );
1611             break;
1612         }
1613 
1614         if( bSetEvent )
1615         {
1616             String sEvent( pOption->GetString() );
1617             if( sEvent.Len() )
1618             {
1619                 sEvent.ConvertLineEnd();
1620                 String aScriptType2;
1621                 if( EXTENDED_STYPE==eScriptType2 )
1622                     aScriptType2 = rDfltScriptType;
1623                 aMacroTbl.Insert( nEvent, new SvxMacro( sEvent, aScriptType2,
1624                                   eScriptType2 ) );
1625             }
1626         }
1627     }
1628 
1629     if( HTML_IT_IMAGE==eType )
1630     {
1631         // Image-Controls ohne Image-URL werden ignoriert (wie bei MS)
1632         if( !sImgSrc.Len() )
1633             return;
1634     }
1635     else
1636     {
1637         // ALIGN fuer alle Controls auszuwerten ist keine so gute Idee,
1638         // solange Absatz-gebundene Controls die Hoehe von Tabellen-Zellen
1639         // nicht beeinflussen
1640         // (#64110#, http://www.telekom.de/katalog-online/onlineshop.html)
1641         eVertOri = text::VertOrientation::TOP;
1642         eHoriOri = text::HoriOrientation::NONE;
1643     }
1644 
1645     // Defaults entsprechen HTML_IT_TEXT
1646     const sal_Char *pType = "TextField";
1647     sal_Bool bKeepCRLFInValue = sal_False;
1648     switch( eType )
1649     {
1650     case HTML_IT_CHECKBOX:
1651         pType = "CheckBox";
1652         bKeepCRLFInValue = sal_True;
1653         break;
1654 
1655     case HTML_IT_RADIO:
1656         pType = "RadioButton";
1657         bKeepCRLFInValue = sal_True;
1658         break;
1659 
1660     case HTML_IT_PASSWORD:
1661         bKeepCRLFInValue = sal_True;
1662         break;
1663 
1664     case HTML_IT_BUTTON:
1665         bKeepCRLFInValue = sal_True;
1666     case HTML_IT_SUBMIT:
1667     case HTML_IT_RESET:
1668         pType = "CommandButton";
1669         break;
1670 
1671     case HTML_IT_IMAGE:
1672         pType = "ImageButton";
1673         break;
1674 
1675     case HTML_IT_FILE:
1676         pType = "FileControl";
1677         break;
1678 
1679     case HTML_IT_HIDDEN:
1680         pType = "HiddenControl";
1681         bKeepCRLFInValue = sal_True;
1682         break;
1683     default:
1684         ;
1685     }
1686 
1687     // Fuer ein par Controls mussen CR/LF noch aus dem VALUE
1688     // geloescht werden.
1689     if( !bKeepCRLFInValue )
1690     {
1691         sText.EraseAllChars( SAL_CR );
1692         sText.EraseAllChars( SAL_LF );
1693     }
1694 
1695     const uno::Reference< XMultiServiceFactory > & rServiceFactory =
1696         pFormImpl->GetServiceFactory();
1697     if( !rServiceFactory.is() )
1698         return;
1699 
1700     String sServiceName(
1701             OUString::createFromAscii("com.sun.star.form.component.") );
1702     sServiceName.AppendAscii( pType );
1703     uno::Reference< XInterface > xInt =
1704         rServiceFactory->createInstance( sServiceName );
1705     if( !xInt.is() )
1706         return;
1707 
1708     uno::Reference< XFormComponent > xFComp( xInt, UNO_QUERY );
1709     if( !xFComp.is() )
1710         return;
1711 
1712     uno::Reference< beans::XPropertySet > xPropSet( xFComp, UNO_QUERY );
1713 
1714     Any aTmp;
1715     aTmp <<= OUString(sName);
1716     xPropSet->setPropertyValue( OUString::createFromAscii( "Name" ), aTmp );
1717 
1718     if( HTML_IT_HIDDEN != eType  )
1719     {
1720         if( nTabIndex >= TABINDEX_MIN && nTabIndex <= TABINDEX_MAX  )
1721         {
1722             aTmp <<= (sal_Int16) (sal_Int16)nTabIndex ;
1723             xPropSet->setPropertyValue( OUString::createFromAscii( "TabIndex" ), aTmp );
1724         }
1725 
1726         if( bDisabled )
1727         {
1728             sal_Bool bFalse = sal_False;
1729             aTmp.setValue(&bFalse, ::getBooleanCppuType()  );
1730             xPropSet->setPropertyValue( OUString::createFromAscii( "Enabled" ), aTmp );
1731         }
1732     }
1733 
1734     aTmp <<= OUString(sText);
1735 
1736     Size aSz( 0, 0 );       // defaults
1737     Size aTextSz( 0, 0 );   // Text-Size
1738     sal_Bool bMinWidth = sal_False, bMinHeight = sal_False;
1739     sal_Bool bUseSize = sal_False;
1740     switch( eType )
1741     {
1742     case HTML_IT_CHECKBOX:
1743     case HTML_IT_RADIO:
1744         {
1745             if( !bValue )
1746                 aTmp <<= OUString::createFromAscii( OOO_STRING_SVTOOLS_HTML_on );
1747             xPropSet->setPropertyValue( OUString::createFromAscii( "RefValue" ),
1748                                         aTmp );
1749             aTmp <<= OUString();
1750             xPropSet->setPropertyValue( OUString::createFromAscii( "Label" ),
1751                                         aTmp );
1752             // #53559#: Beim RadioButton darf die DefaultChecked-Property
1753             // erst gesetzt werden, wenn das Control angelegt und ein
1754             // activateTabOrder gerufen wurde, weil es sonst noch zu der
1755             // vorhergehenden Gruppe gehoert.
1756             if( HTML_IT_CHECKBOX == eType )
1757             {
1758                 aTmp <<= (sal_Int16) nChecked ;
1759                 xPropSet->setPropertyValue(
1760                         OUString::createFromAscii( "DefaultState" ), aTmp );
1761             }
1762 
1763             SvxMacro *pMacro = aMacroTbl.Get( HTML_ET_ONCLICK );
1764             if( pMacro )
1765             {
1766                 aMacroTbl.Remove( HTML_ET_ONCLICK );
1767                 aMacroTbl.Insert( HTML_ET_ONCLICK_ITEM, pMacro );
1768             }
1769             // SIZE auszuwerten duerfte hier keinen Sinn machen???
1770             bMinWidth = bMinHeight = sal_True;
1771         }
1772         break;
1773 
1774     case HTML_IT_IMAGE:
1775         {
1776             // SIZE = WIDTH
1777             aSz.Width() = nSize ? nSize : nWidth;
1778             aSz.Width() = nWidth;
1779             aSz.Height() = nHeight;
1780             if( (aSz.Width() || aSz.Height()) && Application::GetDefaultDevice() )
1781             {
1782                 aSz = Application::GetDefaultDevice()
1783                     ->PixelToLogic( aSz, MapMode( MAP_100TH_MM ) );
1784             }
1785             FormButtonType eButtonType = FormButtonType_SUBMIT;
1786             aTmp.setValue( &eButtonType,
1787                            ::getCppuType((const FormButtonType*)0));
1788             xPropSet->setPropertyValue(
1789                     OUString::createFromAscii( "ButtonType" ), aTmp );
1790 
1791             aTmp <<= (sal_Int16) 0  ;
1792             xPropSet->setPropertyValue( OUString::createFromAscii( "Border" ),
1793                                         aTmp );
1794         }
1795         break;
1796 
1797     case HTML_IT_BUTTON:
1798     case HTML_IT_SUBMIT:
1799     case HTML_IT_RESET:
1800         {
1801             FormButtonType eButtonType;
1802             switch( eType )
1803             {
1804             case HTML_IT_BUTTON:
1805                 eButtonType = FormButtonType_PUSH;
1806                 break;
1807             case HTML_IT_SUBMIT:
1808                 eButtonType = FormButtonType_SUBMIT;
1809                 if( !sText.Len() )
1810                     sText.AssignAscii( OOO_STRING_SVTOOLS_HTML_IT_submit );
1811                 break;
1812             case HTML_IT_RESET:
1813                 eButtonType = FormButtonType_RESET;
1814                 if( !sText.Len() )
1815                     sText.AssignAscii( OOO_STRING_SVTOOLS_HTML_IT_reset );
1816                 break;
1817             default:
1818                 ;
1819             }
1820             aTmp <<= OUString(sText);
1821             xPropSet->setPropertyValue( OUString::createFromAscii( "Label" ),
1822                                         aTmp );
1823 
1824             aTmp.setValue( &eButtonType,
1825                            ::getCppuType((const FormButtonType*)0));
1826             xPropSet->setPropertyValue(
1827                             OUString::createFromAscii( "ButtonType" ), aTmp );
1828 
1829             bMinWidth = bMinHeight = sal_True;
1830             bUseSize = sal_True;
1831         }
1832         break;
1833 
1834     case HTML_IT_PASSWORD:
1835     case HTML_IT_TEXT:
1836     case HTML_IT_FILE:
1837         if( HTML_IT_FILE != eType )
1838         {
1839         // Beim File-Control wird der VALUE aus Sicherheitsgruenden ignoriert.
1840             xPropSet->setPropertyValue(
1841                     OUString::createFromAscii( "DefaultText" ), aTmp );
1842             if( nMaxLen != 0 )
1843             {
1844                 aTmp <<= (sal_Int16) nMaxLen ;
1845                 xPropSet->setPropertyValue(
1846                         OUString::createFromAscii( "MaxTextLen" ), aTmp );
1847             }
1848         }
1849 
1850         if( HTML_IT_PASSWORD == eType )
1851         {
1852             aTmp <<= (sal_Int16)'*' ;
1853             xPropSet->setPropertyValue( OUString::createFromAscii( "EchoChar" ),
1854                                         aTmp );
1855         }
1856 
1857         lcl_html_setFixedFontProperty( xPropSet );
1858 
1859         if( !nSize )
1860             nSize = 20;
1861         aTextSz.Width() = nSize;
1862         bMinHeight = sal_True;
1863         break;
1864 
1865     case HTML_IT_HIDDEN:
1866         xPropSet->setPropertyValue( OUString::createFromAscii( "HiddenValue" ),
1867                                     aTmp );
1868         bHidden = sal_True;
1869         break;
1870     default:
1871         ;
1872     }
1873 
1874     if( bUseSize && nSize>0 )
1875     {
1876         if( Application::GetDefaultDevice() )
1877         {
1878             Size aNewSz( nSize, 0 );
1879             aNewSz = Application::GetDefaultDevice()
1880                         ->PixelToLogic( aNewSz, MapMode( MAP_100TH_MM ) );
1881             aSz.Width() = aNewSz.Width();
1882             ASSERT( !aTextSz.Width(), "Text-Breite ist gegeben" );
1883             bMinWidth = sal_False;
1884         }
1885     }
1886 
1887     SfxItemSet aCSS1ItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
1888     SvxCSS1PropertyInfo aCSS1PropInfo;
1889     if( HasStyleOptions( aStyle, aId, aClass ) )
1890     {
1891         ParseStyleOptions( aStyle, aId, aClass, aCSS1ItemSet, aCSS1PropInfo );
1892         if( aId.Len() )
1893             InsertBookmark( aId );
1894     }
1895 
1896     if( SVX_CSS1_LTYPE_TWIP== aCSS1PropInfo.eWidthType )
1897     {
1898         aSz.Width() = TWIP_TO_MM100( aCSS1PropInfo.nWidth );
1899         aTextSz.Width() = 0;
1900         bMinWidth = sal_False;
1901     }
1902     if( SVX_CSS1_LTYPE_TWIP== aCSS1PropInfo.eHeightType )
1903     {
1904         aSz.Height() = TWIP_TO_MM100( aCSS1PropInfo.nHeight );
1905         aTextSz.Height() = 0;
1906         bMinHeight = sal_False;
1907     }
1908 
1909     // Beim Image-Button bei nicht gegebern Groesse einen sinnvollen Default
1910     // setzen
1911     if( HTML_IT_IMAGE== eType )
1912     {
1913         if( !aSz.Width() )
1914         {
1915             aSz.Width() = HTML_DFLT_IMG_WIDTH;
1916             bSetGrfWidth = sal_True;
1917             if( pTable != 0 )
1918                 IncGrfsThatResizeTable();
1919         }
1920         if( !aSz.Height() )
1921         {
1922             aSz.Height() = HTML_DFLT_IMG_HEIGHT;
1923             bSetGrfHeight = sal_True;
1924         }
1925     }
1926     if( aSz.Width() < MINFLY )
1927         aSz.Width() = MINFLY;
1928     if( aSz.Height() < MINFLY )
1929         aSz.Height() = MINFLY;
1930 
1931     uno::Reference< drawing::XShape > xShape = InsertControl(
1932                                              xFComp, xPropSet, aSz,
1933                                              eVertOri, eHoriOri,
1934                                              aCSS1ItemSet, aCSS1PropInfo,
1935                                              aMacroTbl, aUnoMacroTbl,
1936                                              aUnoMacroParamTbl, sal_False,
1937                                              bHidden );
1938     if( aTextSz.Width() || aTextSz.Height() || bMinWidth || bMinHeight )
1939     {
1940         ASSERT( !(bSetGrfWidth || bSetGrfHeight), "Grafikgroesse anpassen???" );
1941         SetControlSize( xShape, aTextSz, bMinWidth, bMinHeight, HTML_INPUT );
1942     }
1943 
1944     if( HTML_IT_RADIO == eType )
1945     {
1946         aTmp <<= (sal_Int16) nChecked ;
1947         xPropSet->setPropertyValue( OUString::createFromAscii( "DefaultState" ), aTmp );
1948     }
1949 
1950     if( HTML_IT_IMAGE == eType )
1951     {
1952         // Die URL erst nach dem Einfuegen setzen, weil sich der
1953         // Download der Grafik erst dann am XModel anmelden kann,
1954         // wenn das Control eingefuegt ist.
1955         aTmp <<= OUString( URIHelper::SmartRel2Abs(INetURLObject(sBaseURL), sImgSrc, Link(), false));
1956         xPropSet->setPropertyValue( OUString::createFromAscii( "ImageURL" ),
1957                                     aTmp );
1958     }
1959 
1960     if( bSetGrfWidth || bSetGrfHeight )
1961     {
1962         SwHTMLImageWatcher* pWatcher =
1963             new SwHTMLImageWatcher( xShape, bSetGrfWidth, bSetGrfHeight );
1964         uno::Reference< awt::XImageConsumer > xCons = pWatcher;
1965         pWatcher->start();
1966     }
1967 }
1968 
NewTextArea()1969 void SwHTMLParser::NewTextArea()
1970 {
1971     if( pPendStack )
1972     {
1973         SetPendingControlSize( HTML_TEXTAREA_ON );
1974         return;
1975     }
1976 
1977     ASSERT( !bTextArea, "TextArea in TextArea???" );
1978     ASSERT( !pFormImpl || !pFormImpl->GetFCompPropSet().is(),
1979             "TextArea in Control???" );
1980 
1981     if( !pFormImpl || !pFormImpl->GetFormComps().is() )
1982     {
1983         // Spezialbehandlung fuer TextArea auch untem im Parser beenden
1984         FinishTextArea();
1985         return;
1986     }
1987 
1988     String aId, aClass, aStyle;
1989     String sName;
1990     sal_Int32 nTabIndex = TABINDEX_MAX + 1;
1991     SvxMacroTableDtor aMacroTbl;
1992     SvStringsDtor aUnoMacroTbl;
1993     SvStringsDtor aUnoMacroParamTbl;
1994     sal_uInt16 nRows = 0, nCols = 0;
1995     sal_uInt16 nWrap = HTML_WM_OFF;
1996     sal_Bool bDisabled = sal_False;
1997     SvKeyValueIterator *pHeaderAttrs = pFormImpl->GetHeaderAttrs();
1998     ScriptType eDfltScriptType = GetScriptType( pHeaderAttrs );
1999     const String& rDfltScriptType = GetScriptTypeString( pHeaderAttrs );
2000 
2001     const HTMLOptions *pHTMLOptions = GetOptions();
2002     for( sal_uInt16 i = pHTMLOptions->Count(); i; )
2003     {
2004         const HTMLOption *pOption = (*pHTMLOptions)[--i];
2005         ScriptType eScriptType2 = eDfltScriptType;
2006         sal_uInt16 nEvent = 0;
2007         sal_Bool bSetEvent = sal_False;
2008 
2009         switch( pOption->GetToken() )
2010         {
2011         case HTML_O_ID:
2012             aId = pOption->GetString();
2013             break;
2014         case HTML_O_STYLE:
2015             aStyle = pOption->GetString();
2016             break;
2017         case HTML_O_CLASS:
2018             aClass = pOption->GetString();
2019             break;
2020         case HTML_O_NAME:
2021             sName = pOption->GetString();
2022             break;
2023         case HTML_O_DISABLED:
2024             bDisabled = sal_True;
2025             break;
2026         case HTML_O_ROWS:
2027             nRows = (sal_uInt16)pOption->GetNumber();
2028             break;
2029         case HTML_O_COLS:
2030             nCols = (sal_uInt16)pOption->GetNumber();
2031             break;
2032         case HTML_O_WRAP:
2033             nWrap = pOption->GetEnum( aHTMLTextAreaWrapTable, nWrap );
2034             break;
2035 
2036         case HTML_O_TABINDEX:
2037             nTabIndex = pOption->GetSNumber();
2038             break;
2039 
2040         case HTML_O_SDONFOCUS:
2041             eScriptType2 = STARBASIC;
2042         case HTML_O_ONFOCUS:
2043             nEvent = HTML_ET_ONGETFOCUS;
2044             bSetEvent = sal_True;
2045             break;
2046 
2047         case HTML_O_SDONBLUR:
2048             eScriptType2 = STARBASIC;
2049         case HTML_O_ONBLUR:
2050             nEvent = HTML_ET_ONLOSEFOCUS;
2051             bSetEvent = sal_True;
2052             break;
2053 
2054         case HTML_O_SDONCLICK:
2055             eScriptType2 = STARBASIC;
2056         case HTML_O_ONCLICK:
2057             nEvent = HTML_ET_ONCLICK;
2058             bSetEvent = sal_True;
2059             break;
2060 
2061         case HTML_O_SDONCHANGE:
2062             eScriptType2 = STARBASIC;
2063         case HTML_O_ONCHANGE:
2064             nEvent = HTML_ET_ONCHANGE;
2065             bSetEvent = sal_True;
2066             break;
2067 
2068         case HTML_O_SDONSELECT:
2069             eScriptType2 = STARBASIC;
2070         case HTML_O_ONSELECT:
2071             nEvent = HTML_ET_ONSELECT;
2072             bSetEvent = sal_True;
2073             break;
2074 
2075         default:
2076             lcl_html_getEvents( pOption->GetTokenString(),
2077                                 pOption->GetString(),
2078                                 aUnoMacroTbl, aUnoMacroParamTbl );
2079             break;
2080         }
2081 
2082         if( bSetEvent )
2083         {
2084             String sEvent( pOption->GetString() );
2085             if( sEvent.Len() )
2086             {
2087                 sEvent.ConvertLineEnd();
2088                 if( EXTENDED_STYPE==eScriptType2 )
2089                     aScriptType = rDfltScriptType;
2090                 aMacroTbl.Insert( nEvent, new SvxMacro( sEvent, aScriptType,
2091                                   eScriptType2 ) );
2092             }
2093         }
2094     }
2095 
2096 
2097     const uno::Reference< lang::XMultiServiceFactory > & rSrvcMgr =
2098         pFormImpl->GetServiceFactory();
2099     if( !rSrvcMgr.is() )
2100     {
2101         FinishTextArea();
2102         return;
2103     }
2104     uno::Reference< uno::XInterface >  xInt = rSrvcMgr->createInstance(
2105         OUString::createFromAscii( "com.sun.star.form.component.TextField" ) );
2106     if( !xInt.is() )
2107     {
2108         FinishTextArea();
2109         return;
2110     }
2111 
2112     uno::Reference< XFormComponent > xFComp( xInt, UNO_QUERY );
2113     DBG_ASSERT( xFComp.is(), "keine FormComponent?" );
2114 
2115     uno::Reference< beans::XPropertySet > xPropSet( xFComp, UNO_QUERY );
2116 
2117     Any aTmp;
2118     aTmp <<= OUString(sName);
2119     xPropSet->setPropertyValue( OUString::createFromAscii( "Name" ), aTmp );
2120 
2121     sal_Bool bTrue = sal_True;
2122     aTmp.setValue( &bTrue, ::getBooleanCppuType() );
2123     xPropSet->setPropertyValue( OUString::createFromAscii( "MultiLine" ),
2124                                 aTmp );
2125     xPropSet->setPropertyValue( OUString::createFromAscii( "VScroll" ), aTmp );
2126     if( HTML_WM_OFF == nWrap )
2127         xPropSet->setPropertyValue( OUString::createFromAscii( "HScroll" ),
2128                                     aTmp );
2129     if( HTML_WM_HARD == nWrap )
2130         xPropSet->setPropertyValue(
2131                 OUString::createFromAscii( "HardLineBreaks" ), aTmp );
2132 
2133     if( nTabIndex >= TABINDEX_MIN && nTabIndex <= TABINDEX_MAX  )
2134     {
2135         aTmp <<= (sal_Int16)nTabIndex ;
2136         xPropSet->setPropertyValue( OUString::createFromAscii( "TabIndex" ),
2137                                     aTmp );
2138     }
2139 
2140     lcl_html_setFixedFontProperty( xPropSet );
2141 
2142     if( bDisabled )
2143     {
2144         sal_Bool bFalse = sal_False;
2145         aTmp.setValue( &bFalse, ::getBooleanCppuType() );
2146         xPropSet->setPropertyValue( OUString::createFromAscii( "Enabled" ),
2147                                     aTmp );
2148     }
2149 
2150     ASSERT( !pFormImpl->GetText().Len(), "Text ist nicht leer!" );
2151 
2152     if( !nCols )
2153         nCols = 20;
2154     if( !nRows )
2155         nRows = 1;
2156 
2157     Size aTextSz( nCols, nRows );
2158 
2159     SfxItemSet aCSS1ItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
2160     SvxCSS1PropertyInfo aCSS1PropInfo;
2161     if( HasStyleOptions( aStyle, aId, aClass ) )
2162     {
2163         ParseStyleOptions( aStyle, aId, aClass, aCSS1ItemSet, aCSS1PropInfo );
2164         if( aId.Len() )
2165             InsertBookmark( aId );
2166     }
2167 
2168     Size aSz( MINFLY, MINFLY );
2169     if( SVX_CSS1_LTYPE_TWIP== aCSS1PropInfo.eWidthType )
2170     {
2171         aSz.Width() = TWIP_TO_MM100( aCSS1PropInfo.nWidth );
2172         aTextSz.Width() = 0;
2173     }
2174     if( SVX_CSS1_LTYPE_TWIP== aCSS1PropInfo.eHeightType )
2175     {
2176         aSz.Height() = TWIP_TO_MM100( aCSS1PropInfo.nHeight );
2177         aTextSz.Height() = 0;
2178     }
2179     if( aSz.Width() < MINFLY )
2180         aSz.Width() = MINFLY;
2181     if( aSz.Height() < MINFLY )
2182         aSz.Height() = MINFLY;
2183 
2184     uno::Reference< drawing::XShape > xShape = InsertControl( xFComp, xPropSet, aSz,
2185                                       text::VertOrientation::TOP, text::HoriOrientation::NONE,
2186                                       aCSS1ItemSet, aCSS1PropInfo,
2187                                       aMacroTbl, aUnoMacroTbl,
2188                                       aUnoMacroParamTbl );
2189     if( aTextSz.Width() || aTextSz.Height() )
2190         SetControlSize( xShape, aTextSz, sal_False, sal_False,
2191                         HTML_TEXTAREA_ON );
2192 
2193     // einen neuen Kontext anlegen
2194     _HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_TEXTAREA_ON );
2195 
2196     // und PRE/Listing/XMP voruebergehend aussetzen
2197     SplitPREListingXMP( pCntxt );
2198     PushContext( pCntxt );
2199 
2200     bTextArea = sal_True;
2201     bTAIgnoreNewPara = sal_True;
2202 }
2203 
EndTextArea()2204 void SwHTMLParser::EndTextArea()
2205 {
2206     ASSERT( bTextArea, "keine TextArea oder falscher Typ" );
2207     ASSERT( pFormImpl && pFormImpl->GetFCompPropSet().is(),
2208             "TextArea fehlt" );
2209 
2210     const uno::Reference< beans::XPropertySet > & rPropSet =
2211         pFormImpl->GetFCompPropSet();
2212 
2213     Any aTmp;
2214     aTmp <<= OUString(pFormImpl->GetText());
2215     rPropSet->setPropertyValue( OUString::createFromAscii( "DefaultText" ),
2216                                 aTmp );
2217     pFormImpl->EraseText();
2218 
2219     pFormImpl->ReleaseFCompPropSet();
2220 
2221     // den Kontext holen
2222     _HTMLAttrContext *pCntxt = PopContext( HTML_TEXTAREA_ON );
2223     if( pCntxt )
2224     {
2225         // und ggf. die Attribute beenden
2226         EndContext( pCntxt );
2227         delete pCntxt;
2228     }
2229 
2230     bTextArea = sal_False;
2231 }
2232 
2233 
InsertTextAreaText(sal_uInt16 nToken)2234 void SwHTMLParser::InsertTextAreaText( sal_uInt16 nToken )
2235 {
2236     ASSERT( bTextArea, "keine TextArea oder falscher Typ" );
2237     ASSERT( pFormImpl && pFormImpl->GetFCompPropSet().is(),
2238             "TextArea fehlt" );
2239 
2240     String& rText = pFormImpl->GetText();
2241     switch( nToken)
2242     {
2243     case HTML_TEXTTOKEN:
2244         rText += aToken;
2245         break;
2246     case HTML_NEWPARA:
2247         if( !bTAIgnoreNewPara )
2248             rText += '\n';    // das ist hier richtig!!!
2249         break;
2250     default:
2251         rText += '<';
2252         rText += sSaveToken;
2253         if( aToken.Len() )
2254         {
2255             rText += ' ';
2256             rText += aToken;
2257         }
2258         rText += '>';
2259     }
2260 
2261     bTAIgnoreNewPara = sal_False;
2262 }
2263 
NewSelect()2264 void SwHTMLParser::NewSelect()
2265 {
2266     if( pPendStack )
2267     {
2268         SetPendingControlSize( HTML_SELECT_ON );
2269         return;
2270     }
2271 
2272     ASSERT( !bSelect, "Select in Select???" );
2273     ASSERT( !pFormImpl || !pFormImpl->GetFCompPropSet().is(),
2274             "Select in Control???" );
2275 
2276     if( !pFormImpl || !pFormImpl->GetFormComps().is() )
2277         return;
2278 
2279     String aId, aClass, aStyle;
2280     String sName;
2281     sal_Int32 nTabIndex = TABINDEX_MAX + 1;
2282     SvxMacroTableDtor aMacroTbl;
2283     SvStringsDtor aUnoMacroTbl;
2284     SvStringsDtor aUnoMacroParamTbl;
2285     sal_Bool bMultiple = sal_False;
2286     sal_Bool bDisabled = sal_False;
2287     nSelectEntryCnt = 1;
2288     SvKeyValueIterator *pHeaderAttrs = pFormImpl->GetHeaderAttrs();
2289     ScriptType eDfltScriptType = GetScriptType( pHeaderAttrs );
2290     const String& rDfltScriptType = GetScriptTypeString( pHeaderAttrs );
2291 
2292     const HTMLOptions *pHTMLOptions = GetOptions();
2293     for( sal_uInt16 i = pHTMLOptions->Count(); i; )
2294     {
2295         const HTMLOption *pOption = (*pHTMLOptions)[--i];
2296         ScriptType eScriptType2 = eDfltScriptType;
2297         sal_uInt16 nEvent = 0;
2298         sal_Bool bSetEvent = sal_False;
2299 
2300         switch( pOption->GetToken() )
2301         {
2302         case HTML_O_ID:
2303             aId = pOption->GetString();
2304             break;
2305         case HTML_O_STYLE:
2306             aStyle = pOption->GetString();
2307             break;
2308         case HTML_O_CLASS:
2309             aClass = pOption->GetString();
2310             break;
2311         case HTML_O_NAME:
2312             sName = pOption->GetString();
2313             break;
2314         case HTML_O_MULTIPLE:
2315             bMultiple = sal_True;
2316             break;
2317         case HTML_O_DISABLED:
2318             bDisabled = sal_True;
2319             break;
2320         case HTML_O_SIZE:
2321             nSelectEntryCnt = (sal_uInt16)pOption->GetNumber();
2322             break;
2323 
2324         case HTML_O_TABINDEX:
2325             nTabIndex = pOption->GetSNumber();
2326             break;
2327 
2328         case HTML_O_SDONFOCUS:
2329             eScriptType2 = STARBASIC;
2330         case HTML_O_ONFOCUS:
2331             nEvent = HTML_ET_ONGETFOCUS;
2332             bSetEvent = sal_True;
2333             break;
2334 
2335         case HTML_O_SDONBLUR:
2336             eScriptType2 = STARBASIC;
2337         case HTML_O_ONBLUR:
2338             nEvent = HTML_ET_ONLOSEFOCUS;
2339             bSetEvent = sal_True;
2340             break;
2341 
2342         case HTML_O_SDONCLICK:
2343             eScriptType2 = STARBASIC;
2344         case HTML_O_ONCLICK:
2345             nEvent = HTML_ET_ONCLICK;
2346             bSetEvent = sal_True;
2347             break;
2348 
2349         case HTML_O_SDONCHANGE:
2350             eScriptType2 = STARBASIC;
2351         case HTML_O_ONCHANGE:
2352             nEvent = HTML_ET_ONCHANGE;
2353             bSetEvent = sal_True;
2354             break;
2355 
2356         default:
2357             lcl_html_getEvents( pOption->GetTokenString(),
2358                                 pOption->GetString(),
2359                                 aUnoMacroTbl, aUnoMacroParamTbl );
2360             break;
2361         }
2362 
2363         if( bSetEvent )
2364         {
2365             String sEvent( pOption->GetString() );
2366             if( sEvent.Len() )
2367             {
2368                 sEvent.ConvertLineEnd();
2369                 if( EXTENDED_STYPE==eScriptType2 )
2370                     aScriptType = rDfltScriptType;
2371                 aMacroTbl.Insert( nEvent, new SvxMacro( sEvent, aScriptType,
2372                                   eScriptType2 ) );
2373             }
2374         }
2375     }
2376 
2377     const uno::Reference< lang::XMultiServiceFactory > & rSrvcMgr =
2378         pFormImpl->GetServiceFactory();
2379     if( !rSrvcMgr.is() )
2380     {
2381         FinishTextArea();
2382         return;
2383     }
2384     uno::Reference< uno::XInterface >  xInt = rSrvcMgr->createInstance(
2385         OUString::createFromAscii( "com.sun.star.form.component.ListBox" ) );
2386     if( !xInt.is() )
2387     {
2388         FinishTextArea();
2389         return;
2390     }
2391 
2392     uno::Reference< XFormComponent > xFComp( xInt, UNO_QUERY );
2393     DBG_ASSERT(xFComp.is(), "keine FormComponent?");
2394 
2395     uno::Reference< beans::XPropertySet >  xPropSet( xFComp, UNO_QUERY );
2396 
2397     Any aTmp;
2398     aTmp <<= OUString(sName);
2399     xPropSet->setPropertyValue( OUString::createFromAscii( "Name" ), aTmp );
2400 
2401     if( nTabIndex >= TABINDEX_MIN && nTabIndex <= TABINDEX_MAX  )
2402     {
2403         aTmp <<= (sal_Int16)nTabIndex ;
2404         xPropSet->setPropertyValue( OUString::createFromAscii( "TabIndex" ),
2405                                     aTmp );
2406     }
2407 
2408     if( bDisabled )
2409     {
2410         sal_Bool bFalse = sal_False;
2411         aTmp.setValue( &bFalse, ::getBooleanCppuType() );
2412         xPropSet->setPropertyValue( OUString::createFromAscii( "Enabled" ),
2413                                     aTmp );
2414     }
2415 
2416     Size aTextSz( 0, 0 );
2417     sal_Bool bMinWidth = sal_True, bMinHeight = sal_True;
2418     if( !bMultiple && 1==nSelectEntryCnt )
2419     {
2420         sal_Bool bTrue = sal_True;
2421         aTmp.setValue( &bTrue, ::getBooleanCppuType() );
2422         xPropSet->setPropertyValue( OUString::createFromAscii( "Dropdown" ),
2423                                     aTmp );
2424     }
2425     else
2426     {
2427         if( nSelectEntryCnt <= 1 )      // 4 Zeilen als default
2428             nSelectEntryCnt = 4;
2429 
2430         if( bMultiple )
2431         {
2432             sal_Bool bTrue = sal_True;
2433             aTmp.setValue( &bTrue, ::getBooleanCppuType() );
2434             xPropSet->setPropertyValue(
2435                     OUString::createFromAscii( "MultiSelection" ), aTmp );
2436         }
2437         aTextSz.Height() = nSelectEntryCnt;
2438         bMinHeight = sal_False;
2439     }
2440 
2441     SfxItemSet aCSS1ItemSet( pDoc->GetAttrPool(), pCSS1Parser->GetWhichMap() );
2442     SvxCSS1PropertyInfo aCSS1PropInfo;
2443     if( HasStyleOptions( aStyle, aId, aClass ) )
2444     {
2445         ParseStyleOptions( aStyle, aId, aClass, aCSS1ItemSet, aCSS1PropInfo );
2446         if( aId.Len() )
2447             InsertBookmark( aId );
2448     }
2449 
2450     Size aSz( MINFLY, MINFLY );
2451     bFixSelectWidth = bFixSelectHeight = sal_True;
2452     if( SVX_CSS1_LTYPE_TWIP== aCSS1PropInfo.eWidthType )
2453     {
2454         aSz.Width() = TWIP_TO_MM100( aCSS1PropInfo.nWidth );
2455         bFixSelectWidth = sal_False;
2456         bMinWidth = sal_False;
2457     }
2458     if( SVX_CSS1_LTYPE_TWIP== aCSS1PropInfo.eHeightType )
2459     {
2460         aSz.Height() = TWIP_TO_MM100( aCSS1PropInfo.nHeight );
2461         aTextSz.Height() = sal_False;
2462         bMinHeight = sal_False;
2463     }
2464     if( aSz.Width() < MINFLY )
2465         aSz.Width() = MINFLY;
2466     if( aSz.Height() < MINFLY )
2467         aSz.Height() = MINFLY;
2468 
2469     uno::Reference< drawing::XShape >  xShape = InsertControl( xFComp, xPropSet, aSz,
2470                                       text::VertOrientation::TOP, text::HoriOrientation::NONE,
2471                                       aCSS1ItemSet, aCSS1PropInfo,
2472                                       aMacroTbl, aUnoMacroTbl,
2473                                       aUnoMacroParamTbl );
2474     if( bFixSelectWidth )
2475         pFormImpl->SetShape( xShape );
2476     if( aTextSz.Height() || bMinWidth || bMinHeight )
2477         SetControlSize( xShape, aTextSz, bMinWidth, bMinHeight,
2478                         HTML_SELECT_ON );
2479 
2480     // einen neuen Kontext anlegen
2481     _HTMLAttrContext *pCntxt = new _HTMLAttrContext( HTML_SELECT_ON );
2482 
2483     // und PRE/Listing/XMP voruebergehend aussetzen
2484     SplitPREListingXMP( pCntxt );
2485     PushContext( pCntxt );
2486 
2487     bSelect = sal_True;
2488 }
2489 
EndSelect()2490 void SwHTMLParser::EndSelect()
2491 {
2492     if( pPendStack )
2493     {
2494         SetPendingControlSize( HTML_SELECT_OFF );
2495         return;
2496     }
2497 
2498     ASSERT( bSelect, "keine Select" );
2499     ASSERT( pFormImpl && pFormImpl->GetFCompPropSet().is(),
2500             "kein Select-Control" );
2501 
2502     const uno::Reference< beans::XPropertySet > & rPropSet =
2503         pFormImpl->GetFCompPropSet();
2504 
2505     // die Groesse anpassen
2506     Size aNewSz( MINFLY, MINFLY );
2507 
2508     sal_uInt16 nEntryCnt = pFormImpl->GetStringList().Count();
2509     if( nEntryCnt )
2510     {
2511         Sequence<OUString> aList( (sal_Int32)nEntryCnt );
2512         Sequence<OUString> aValueList( (sal_Int32)nEntryCnt );
2513         OUString *pStrings = aList.getArray();
2514         OUString *pValues = aValueList.getArray();
2515         sal_uInt16 i;
2516 
2517         for( i = 0; i < nEntryCnt; i++ )
2518         {
2519             String sText( *pFormImpl->GetStringList()[i] );
2520             sText.EraseTrailingChars();
2521             pStrings[i] = sText;
2522 
2523             sText = *pFormImpl->GetValueList()[i];
2524             pValues[i] = sText;
2525         }
2526 
2527         Any aAny( &aList, ::getCppuType((uno::Sequence<OUString>*)0) );
2528 
2529         rPropSet->setPropertyValue(
2530                 OUString::createFromAscii( "StringItemList" ), aAny );
2531 
2532         aAny <<= ListSourceType_VALUELIST;
2533         rPropSet->setPropertyValue(
2534                 OUString::createFromAscii( "ListSourceType" ), aAny );
2535 
2536         aAny.setValue( &aValueList, ::getCppuType((uno::Sequence<OUString>*)0) );
2537 
2538         rPropSet->setPropertyValue( OUString::createFromAscii( "ListSource" ),
2539                                     aAny );
2540 
2541         sal_uInt16 nSelCnt = pFormImpl->GetSelectedList().Count();
2542         if( !nSelCnt && 1 == nSelectEntryCnt && nEntryCnt )
2543         {
2544             // In einer DropDown-Listbox sollte immer ein Eintrag selektiert
2545             // sein.
2546             pFormImpl->GetSelectedList().Insert( (sal_uInt16)0, (sal_uInt16)0 );
2547             nSelCnt = 1;
2548         }
2549         Sequence<sal_Int16> aSelList( (sal_Int32)nSelCnt );
2550         sal_Int16 *pSels = aSelList.getArray();
2551         for( i=0; i<nSelCnt; i++ )
2552         {
2553             pSels[i] = (sal_Int16)pFormImpl->GetSelectedList()[i];
2554         }
2555         aAny.setValue( &aSelList,
2556                        ::getCppuType((uno::Sequence<sal_Int16>*)0) );
2557 
2558         rPropSet->setPropertyValue(
2559                 OUString::createFromAscii( "DefaultSelection" ), aAny );
2560 
2561         pFormImpl->EraseStringList();
2562         pFormImpl->EraseValueList();
2563     }
2564 
2565     pFormImpl->EraseSelectedList();
2566 
2567     if( bFixSelectWidth )
2568     {
2569         ASSERT( pFormImpl->GetShape().is(), "Kein Shape gemerkt" );
2570         Size aTextSz( -1, 0 );
2571         SetControlSize( pFormImpl->GetShape(), aTextSz, sal_False, sal_False,
2572                         HTML_SELECT_OFF );
2573     }
2574 
2575     pFormImpl->ReleaseFCompPropSet();
2576 
2577     // den Kontext holen
2578     _HTMLAttrContext *pCntxt = PopContext( HTML_SELECT_ON );
2579     if( pCntxt )
2580     {
2581         // und ggf. die Attribute beenden
2582         EndContext( pCntxt );
2583         delete pCntxt;
2584     }
2585 
2586     bSelect = sal_False;
2587 }
2588 
InsertSelectOption()2589 void SwHTMLParser::InsertSelectOption()
2590 {
2591     ASSERT( bSelect, "keine Select" );
2592     ASSERT( pFormImpl && pFormImpl->GetFCompPropSet().is(),
2593             "kein Select-Control" );
2594 
2595     bLBEntrySelected = sal_False;
2596     String aValue;
2597 
2598     const HTMLOptions *pHTMLOptions = GetOptions();
2599     for( sal_uInt16 i = pHTMLOptions->Count(); i; )
2600     {
2601         HTMLOption *pOption = (*pHTMLOptions)[--i];
2602         switch( pOption->GetToken() )
2603         {
2604         case HTML_O_ID:
2605             // erstmal weglassen!!!
2606             break;
2607         case HTML_O_SELECTED:
2608             bLBEntrySelected = sal_True;
2609             break;
2610         case HTML_O_VALUE:
2611             aValue = pOption->GetString();
2612             if( !aValue.Len() )
2613                 aValue.AssignAscii( "$$$empty$$$" );
2614             break;
2615         }
2616     }
2617 
2618     sal_uInt16 nEntryCnt = pFormImpl->GetStringList().Count();
2619     pFormImpl->GetStringList().Insert( new String( aEmptyStr ), nEntryCnt );
2620     pFormImpl->GetValueList().Insert( new String( aValue ), nEntryCnt );
2621     if( bLBEntrySelected )
2622         pFormImpl->GetSelectedList().Insert( nEntryCnt,
2623                                 pFormImpl->GetSelectedList().Count() );
2624 }
2625 
InsertSelectText()2626 void SwHTMLParser::InsertSelectText()
2627 {
2628     ASSERT( bSelect, "keine Select" );
2629     ASSERT( pFormImpl && pFormImpl->GetFCompPropSet().is(),
2630             "kein Select-Control" );
2631 
2632     sal_uInt16 nEntryCnt = pFormImpl->GetStringList().Count();
2633     if( nEntryCnt )
2634     {
2635         String& rText = *pFormImpl->GetStringList()[nEntryCnt-1];
2636 
2637         if( aToken.Len() && ' '==aToken.GetChar( 0 ) )
2638         {
2639             xub_StrLen nLen = rText.Len();
2640             if( !nLen || ' '==rText.GetChar( nLen-1 ))
2641                 aToken.Erase( 0, 1 );
2642         }
2643         if( aToken.Len() )
2644             rText += aToken;
2645     }
2646 }
2647