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