summaryrefslogtreecommitdiff
path: root/sw/source/filter/html/htmlforw.cxx
blob: 4b00a5b5770514c3216255060fb1014051e3be83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include <com/sun/star/form/FormSubmitEncoding.hpp>
#include <com/sun/star/form/FormSubmitMethod.hpp>
#include <com/sun/star/form/FormButtonType.hpp>
#include <com/sun/star/script/XEventAttacherManager.hpp>
#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <com/sun/star/form/XFormsSupplier.hpp>
#include <com/sun/star/form/XForm.hpp>
#include <com/sun/star/form/FormComponentType.hpp>
#include <com/sun/star/awt/XTextLayoutConstrains.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <hintids.hxx>
#include <o3tl/any.hxx>
#include <vcl/svapp.hxx>
#include <svl/macitem.hxx>
#include <svtools/htmlout.hxx>
#include <svtools/htmlkywd.hxx>
#include <svl/urihelper.hxx>
#include <vcl/unohelp.hxx>
#include <svx/svdouno.hxx>
#include <editeng/brushitem.hxx>
#include <editeng/colritem.hxx>
#include <editeng/fhgtitem.hxx>
#include <editeng/fontitem.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/postitem.hxx>
#include <editeng/udlnitem.hxx>
#include <editeng/crossedoutitem.hxx>
#include <docsh.hxx>
#include <fmtanchr.hxx>
#include <docary.hxx>
#include <viewsh.hxx>
#include <pam.hxx>
#include <doc.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <IDocumentDrawModelAccess.hxx>
#include "wrthtml.hxx"
#include "htmlfly.hxx"
#include "htmlform.hxx"
#include <frmfmt.hxx>
#include <memory>

using namespace ::com::sun::star;

const HtmlFrmOpts HTML_FRMOPTS_CONTROL   =
    HtmlFrmOpts::NONE;
const HtmlFrmOpts HTML_FRMOPTS_CONTROL_CSS1  =
    HtmlFrmOpts::SAlign |
    HtmlFrmOpts::SSize |
    HtmlFrmOpts::SSpace |
    HtmlFrmOpts::BrClear;
const HtmlFrmOpts HTML_FRMOPTS_IMG_CONTROL   =
    HtmlFrmOpts::Align |
    HtmlFrmOpts::BrClear;
const HtmlFrmOpts HTML_FRMOPTS_IMG_CONTROL_CSS1 =
    HtmlFrmOpts::SAlign |
    HtmlFrmOpts::SSpace;

static void lcl_html_outEvents( SvStream& rStrm,
                         const uno::Reference< form::XFormComponent >& rFormComp,
                         bool bCfgStarBasic,
                         rtl_TextEncoding eDestEnc,
                         OUString *pNonConvertableChars )
{
    uno::Reference< uno::XInterface > xParentIfc = rFormComp->getParent();
    OSL_ENSURE( xParentIfc.is(), "lcl_html_outEvents: no parent interface" );
    if( !xParentIfc.is() )
        return;
    uno::Reference< container::XIndexAccess > xIndexAcc( xParentIfc, uno::UNO_QUERY );
    uno::Reference< script::XEventAttacherManager > xEventManager( xParentIfc,
                                                              uno::UNO_QUERY );
    if( !xIndexAcc.is() || !xEventManager.is() )
        return;

    // and search for the position of the ControlModel within
    sal_Int32 nCount = xIndexAcc->getCount(), nPos;
    for( nPos = 0 ; nPos < nCount; nPos++ )
    {
        uno::Any aTmp = xIndexAcc->getByIndex(nPos);
        if( auto x1 = o3tl::tryAccess<uno::Reference<form::XFormComponent>>(aTmp) )

        {
            if( rFormComp == *x1 )
                break;
        }
        else if( auto x2 = o3tl::tryAccess<uno::Reference<form::XForm>>(aTmp) )
        {
            uno::Reference< form::XFormComponent > xFC( *x2, uno::UNO_QUERY );
            if( rFormComp == xFC )
                break;
        }
        else
        {
            OSL_ENSURE( false, "lcl_html_outEvents: wrong reflection" );
        }
    }

    if( nPos == nCount )
        return;

    const uno::Sequence< script::ScriptEventDescriptor > aDescs =
            xEventManager->getScriptEvents( nPos );
    if( !aDescs.hasElements() )
        return;

    for( const script::ScriptEventDescriptor& rDesc : aDescs )
    {
        ScriptType eScriptType = EXTENDED_STYPE;
        OUString aScriptType( rDesc.ScriptType );
        if( aScriptType.equalsIgnoreAsciiCase(SVX_MACRO_LANGUAGE_JAVASCRIPT) )
            eScriptType = JAVASCRIPT;
        else if( aScriptType.equalsIgnoreAsciiCase(SVX_MACRO_LANGUAGE_STARBASIC ) )
            eScriptType = STARBASIC;
        if( JAVASCRIPT != eScriptType && !bCfgStarBasic )
            continue;

        OUString sListener( rDesc.ListenerType );
        if (!sListener.isEmpty())
        {
            const sal_Int32 nIdx { sListener.lastIndexOf('.')+1 };
            if (nIdx>0)
            {
                if (nIdx<sListener.getLength())
                {
                    sListener = sListener.copy(nIdx);
                }
                else
                {
                    sListener.clear();
                }
            }
        }
        OUString sMethod( rDesc.EventMethod );

        const char *pOpt = nullptr;
        for( int j=0; aEventListenerTable[j]; j++ )
        {
            if( sListener.equalsAscii( aEventListenerTable[j] ) &&
                sMethod.equalsAscii( aEventMethodTable[j] ) )
            {
                pOpt = (STARBASIC==eScriptType ? aEventSDOptionTable
                                               : aEventOptionTable)[j];
                break;
            }
        }

        OString sOut = " ";
        if( pOpt && (EXTENDED_STYPE != eScriptType ||
                     rDesc.AddListenerParam.isEmpty()) )
            sOut += OString(pOpt);
        else
        {
            sOut += OOO_STRING_SVTOOLS_HTML_O_sdevent +
                OUStringToOString(sListener, RTL_TEXTENCODING_ASCII_US) + "-" +
                OUStringToOString(sMethod, RTL_TEXTENCODING_ASCII_US);
        }
        sOut += "=\"";
        rStrm.WriteOString( sOut );
        HTMLOutFuncs::Out_String( rStrm, rDesc.ScriptCode, eDestEnc, pNonConvertableChars );
        rStrm.WriteChar( '\"' );
        if( EXTENDED_STYPE == eScriptType &&
            !rDesc.AddListenerParam.isEmpty() )
        {
            sOut = " " OOO_STRING_SVTOOLS_HTML_O_sdaddparam +
                OUStringToOString(sListener, RTL_TEXTENCODING_ASCII_US) + "-" +
                OUStringToOString(sMethod, RTL_TEXTENCODING_ASCII_US) + "=\"";
            rStrm.WriteOString( sOut );
            HTMLOutFuncs::Out_String( rStrm, rDesc.AddListenerParam,
                                      eDestEnc, pNonConvertableChars );
            rStrm.WriteChar( '\"' );
        }
    }
}

static bool lcl_html_isHTMLControl( sal_Int16 nClassId )
{
    bool bRet = false;

    switch( nClassId )
    {
    case form::FormComponentType::TEXTFIELD:
    case form::FormComponentType::COMMANDBUTTON:
    case form::FormComponentType::RADIOBUTTON:
    case form::FormComponentType::CHECKBOX:
    case form::FormComponentType::LISTBOX:
    case form::FormComponentType::IMAGEBUTTON:
    case form::FormComponentType::FILECONTROL:
        bRet = true;
        break;
    }

    return bRet;
}

bool SwHTMLWriter::HasControls() const
{
    sal_uInt32 nStartIdx = m_pCurrentPam->GetPoint()->nNode.GetIndex();
    size_t i = 0;

    // Skip all controls in front of the current paragraph
    while ( i < m_aHTMLControls.size() && m_aHTMLControls[i]->nNdIdx < nStartIdx )
        ++i;

    return i < m_aHTMLControls.size() && m_aHTMLControls[i]->nNdIdx == nStartIdx;
}

void SwHTMLWriter::OutForm( bool bTag_On, const SwStartNode *pStartNd )
{
    if( m_bPreserveForm )   // we are in a table or an area with form spanned over it
        return;

    if( !bTag_On )
    {
        // end the form when all controls are output
        if( mxFormComps.is() &&
            mxFormComps->getCount() == m_nFormCntrlCnt )
        {
            OutForm( false, mxFormComps );
            mxFormComps.clear();
        }
        return;
    }

    uno::Reference< container::XIndexContainer > xNewFormComps;
    sal_uInt32 nStartIdx = pStartNd ? pStartNd->GetIndex()
                                    : m_pCurrentPam->GetPoint()->nNode.GetIndex();

    // skip controls before the interesting area
    size_t i = 0;
    while ( i < m_aHTMLControls.size() && m_aHTMLControls[i]->nNdIdx < nStartIdx )
        ++i;

    if( !pStartNd )
    {
        // Check for a single node: there it's only interesting, if there is
        // a control for the node and to which form it belongs.
        if( i < m_aHTMLControls.size() &&
            m_aHTMLControls[i]->nNdIdx == nStartIdx )
            xNewFormComps = m_aHTMLControls[i]->xFormComps;
    }
    else
    {
        // we iterate over a table/an area: we're interested in:
        // - if there are controls with different start nodes
        // - if there is a form, with controls which aren't all in the table/area

        uno::Reference< container::XIndexContainer > xCurrentFormComps;// current form in table
        const SwStartNode *pCurrentStNd = nullptr; // and the start node of a Control
        sal_Int32 nCurrentCtrls = 0;   // and the found controls in it
        sal_uInt32 nEndIdx =  pStartNd->EndOfSectionIndex();
        for( ; i < m_aHTMLControls.size() &&
            m_aHTMLControls[i]->nNdIdx <= nEndIdx; i++ )
        {
            const SwStartNode *pCntrlStNd =
                m_pDoc->GetNodes()[m_aHTMLControls[i]->nNdIdx]->StartOfSectionNode();

            if( xCurrentFormComps.is() )
            {
                // already inside a form ...
                if( xCurrentFormComps==m_aHTMLControls[i]->xFormComps )
                {
                    // ... and the control is also inside ...
                    if( pCurrentStNd!=pCntrlStNd )
                    {
                        // ... but it's inside another cell:
                        // Then open a form above the table
                        xNewFormComps = xCurrentFormComps;
                        break;
                    }
                    nCurrentCtrls = nCurrentCtrls + m_aHTMLControls[i]->nCount;
                }
                else
                {
                    // ... but the Control is in another cell:
                    // There we act as if we open a new from and continue searching.
                    xCurrentFormComps = m_aHTMLControls[i]->xFormComps;
                    pCurrentStNd = pCntrlStNd;
                    nCurrentCtrls = m_aHTMLControls[i]->nCount;
                }
            }
            else
            {
                // We aren't in a form:
                // There we act as if we open a form.
                xCurrentFormComps = m_aHTMLControls[i]->xFormComps;
                pCurrentStNd = pCntrlStNd;
                nCurrentCtrls = m_aHTMLControls[i]->nCount;
            }
        }
        if( !xNewFormComps.is() && xCurrentFormComps.is() &&
            nCurrentCtrls != xCurrentFormComps->getCount() )
        {
            // A form should be opened in the table/area which isn't completely
            // inside the table. Then we must also now open the form.
            xNewFormComps = xCurrentFormComps;
        }
    }

    if( xNewFormComps.is() &&
        (!mxFormComps.is() || xNewFormComps != mxFormComps) )
    {
        // A form should be opened ...
        if( mxFormComps.is() )
        {
            // ... but a form is still open: That is in every case an error,
            // but we'll close the old form nevertheless.
            OutForm( false, mxFormComps );

            //!!!nWarn = 1; // Control will be assigned to wrong form
        }

        mxFormComps = xNewFormComps;

        OutForm( true, mxFormComps );
        uno::Reference< beans::XPropertySet >  xTmp;
        OutHiddenControls( mxFormComps, xTmp );
    }
}

void SwHTMLWriter::OutHiddenForms()
{
    // Without DrawModel there can't be controls. Then you also can't access the
    // document via UNO, because otherwise a DrawModel would be created.
    if( !m_pDoc->getIDocumentDrawModelAccess().GetDrawModel() )
        return;

    SwDocShell *pDocSh = m_pDoc->GetDocShell();
    if( !pDocSh )
        return;

    uno::Reference< drawing::XDrawPageSupplier > xDPSupp( pDocSh->GetBaseModel(),
                                                     uno::UNO_QUERY );
    OSL_ENSURE( xDPSupp.is(), "XTextDocument not received from XModel" );
    uno::Reference< drawing::XDrawPage > xDrawPage = xDPSupp->getDrawPage();

    OSL_ENSURE( xDrawPage.is(), "XDrawPage not received" );
    if( !xDrawPage.is() )
        return;

    uno::Reference< form::XFormsSupplier > xFormsSupplier( xDrawPage, uno::UNO_QUERY );
    OSL_ENSURE( xFormsSupplier.is(),
            "XFormsSupplier not received from XDrawPage" );

    uno::Reference< container::XNameContainer > xTmp = xFormsSupplier->getForms();
    OSL_ENSURE( xTmp.is(), "XForms not received" );
    uno::Reference< container::XIndexContainer > xForms( xTmp, uno::UNO_QUERY );
    OSL_ENSURE( xForms.is(), "XForms without container::XIndexContainer?" );

    sal_Int32 nCount = xForms->getCount();
    for( sal_Int32 i=0; i<nCount; i++)
    {
        uno::Any aTmp = xForms->getByIndex( i );
        if( auto x = o3tl::tryAccess<uno::Reference<form::XForm>>(aTmp) )
            OutHiddenForm( *x );
        else
        {
            OSL_ENSURE( false, "OutHiddenForms: wrong reflection" );
        }
    }
}

void SwHTMLWriter::OutHiddenForm( const uno::Reference< form::XForm > & rForm )
{
    uno::Reference< container::XIndexContainer > xFormComps( rForm, uno::UNO_QUERY );
    if( !xFormComps.is() )
        return;

    sal_Int32 nCount = xFormComps->getCount();
    bool bHiddenOnly = nCount > 0, bHidden = false;
    for( sal_Int32 i=0; i<nCount; i++ )
    {
        uno::Any aTmp = xFormComps->getByIndex( i );
        auto xFormComp = o3tl::tryAccess<uno::Reference<form::XFormComponent>>(
            aTmp);
        OSL_ENSURE( xFormComp, "OutHiddenForm: wrong reflection" );
        if( !xFormComp )
            continue;

        uno::Reference< form::XForm > xForm( *xFormComp, uno::UNO_QUERY );
        if( xForm.is() )
            OutHiddenForm( xForm );

        if( bHiddenOnly )
        {
            uno::Reference< beans::XPropertySet >  xPropSet( *xFormComp, uno::UNO_QUERY );
            OUString sPropName("ClassId");
            if( xPropSet->getPropertySetInfo()->hasPropertyByName( sPropName ) )
            {
                uno::Any aAny2 = xPropSet->getPropertyValue( sPropName );
                if( auto n = o3tl::tryAccess<sal_Int16>(aAny2) )
                {
                    if( form::FormComponentType::HIDDENCONTROL == *n )
                        bHidden = true;
                    else if( lcl_html_isHTMLControl( *n ) )
                        bHiddenOnly = false;
                }
            }
        }
    }

    if( bHidden && bHiddenOnly )
    {
        OutForm( true, xFormComps );
        uno::Reference< beans::XPropertySet > xTmp;
        OutHiddenControls( xFormComps, xTmp );
        OutForm( false, xFormComps );
    }
}

void SwHTMLWriter::OutForm( bool bOn,
                const uno::Reference< container::XIndexContainer > & rFormComps )
{
    m_nFormCntrlCnt = 0;

    if( !bOn )
    {
        DecIndentLevel(); // indent content of form
        if( m_bLFPossible )
            OutNewLine();
        HTMLOutFuncs::Out_AsciiTag( Strm(), GetNamespace() + OOO_STRING_SVTOOLS_HTML_form, false );
        m_bLFPossible = true;

        return;
    }

    // the new form is opened
    if( m_bLFPossible )
        OutNewLine();
    OString sOut = "<" OOO_STRING_SVTOOLS_HTML_form;

    uno::Reference< beans::XPropertySet > xFormPropSet( rFormComps, uno::UNO_QUERY );

    uno::Any aTmp = xFormPropSet->getPropertyValue( "Name" );
    if( auto s = o3tl::tryAccess<OUString>(aTmp) )
    {
        if( !s->isEmpty() )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_name "=\"";
            Strm().WriteOString( sOut );
            HTMLOutFuncs::Out_String( Strm(), *s,
                                      m_eDestEnc, &m_aNonConvertableCharacters );
            sOut = "\"";
        }
    }

    aTmp = xFormPropSet->getPropertyValue( "TargetURL" );
    if( auto s = o3tl::tryAccess<OUString>(aTmp) )
    {
        if ( !s->isEmpty() )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_action "=\"";
            Strm().WriteOString( sOut );
            OUString aURL
                = URIHelper::simpleNormalizedMakeRelative( GetBaseURL(), *s);
            HTMLOutFuncs::Out_String( Strm(), aURL, m_eDestEnc, &m_aNonConvertableCharacters );
            sOut = "\"";
        }
    }

    aTmp = xFormPropSet->getPropertyValue( "SubmitMethod" );
    if( auto eMethod = o3tl::tryAccess<form::FormSubmitMethod>(aTmp) )
    {
        if( form::FormSubmitMethod_POST==*eMethod )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_method "=\""
                OOO_STRING_SVTOOLS_HTML_METHOD_post "\"";
        }
    }
    aTmp = xFormPropSet->getPropertyValue( "SubmitEncoding" );
    if( auto eEncType = o3tl::tryAccess<form::FormSubmitEncoding>(aTmp) )
    {
        const char *pStr = nullptr;
        switch( *eEncType )
        {
        case form::FormSubmitEncoding_MULTIPART:
            pStr = OOO_STRING_SVTOOLS_HTML_ET_multipart;
            break;
        case form::FormSubmitEncoding_TEXT:
            pStr = OOO_STRING_SVTOOLS_HTML_ET_text;
            break;
        default:
            ;
        }

        if( pStr )
        {
            sOut += OStringLiteral(" " OOO_STRING_SVTOOLS_HTML_O_enctype "=\"") +
                pStr + "\"";
        }
    }

    aTmp = xFormPropSet->getPropertyValue( "TargetFrame" );
    if( auto s = o3tl::tryAccess<OUString>(aTmp) )
    {
        if (!s->isEmpty() )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_target "=\"";
            Strm().WriteOString( sOut );
            HTMLOutFuncs::Out_String( Strm(), *s,
                                      m_eDestEnc, &m_aNonConvertableCharacters );
            sOut = "\"";
        }
    }

    Strm().WriteOString( sOut );
    uno::Reference< form::XFormComponent > xFormComp( rFormComps, uno::UNO_QUERY );
    lcl_html_outEvents( Strm(), xFormComp, m_bCfgStarBasic, m_eDestEnc, &m_aNonConvertableCharacters );
    Strm().WriteChar( '>' );

    IncIndentLevel(); // indent content of form
    m_bLFPossible = true;
}

void SwHTMLWriter::OutHiddenControls(
        const uno::Reference< container::XIndexContainer > & rFormComps,
        const uno::Reference< beans::XPropertySet > & rPropSet )
{
    sal_Int32 nCount = rFormComps->getCount();
    sal_Int32 nPos = 0;
    if( rPropSet.is() )
    {
        bool bDone = false;

        uno::Reference< form::XFormComponent > xFC( rPropSet, uno::UNO_QUERY );
        for( nPos=0; !bDone && nPos < nCount; nPos++ )
        {
            uno::Any aTmp = rFormComps->getByIndex( nPos );
            auto x = o3tl::tryAccess<uno::Reference<form::XFormComponent>>(aTmp);
            OSL_ENSURE( x,
                    "OutHiddenControls: wrong reflection" );
            bDone = x && *x == xFC;
        }
    }

    for( ; nPos < nCount; nPos++ )
    {
        uno::Any aTmp = rFormComps->getByIndex( nPos );
        auto xFC = o3tl::tryAccess<uno::Reference<form::XFormComponent>>(aTmp);
        OSL_ENSURE( xFC,
                "OutHiddenControls: wrong reflection" );
        if( !xFC )
            continue;
        uno::Reference< beans::XPropertySet > xPropSet( *xFC, uno::UNO_QUERY );

        OUString sPropName = "ClassId";
        if( !xPropSet->getPropertySetInfo()->hasPropertyByName( sPropName ) )
            continue;

        aTmp = xPropSet->getPropertyValue( sPropName );
        auto n = o3tl::tryAccess<sal_Int16>(aTmp);
        if( !n )
            continue;

        if( form::FormComponentType::HIDDENCONTROL == *n )
        {
            if( m_bLFPossible )
                OutNewLine( true );
            OString sOut = "<" OOO_STRING_SVTOOLS_HTML_input " "
                OOO_STRING_SVTOOLS_HTML_O_type "=\""
                OOO_STRING_SVTOOLS_HTML_IT_hidden "\"";

            aTmp = xPropSet->getPropertyValue( "Name" );
            if( auto s = o3tl::tryAccess<OUString>(aTmp) )
            {
                if( !s->isEmpty() )
                {
                    sOut += " " OOO_STRING_SVTOOLS_HTML_O_name "=\"";
                    Strm().WriteOString( sOut );
                    HTMLOutFuncs::Out_String( Strm(), *s,
                                              m_eDestEnc, &m_aNonConvertableCharacters );
                    sOut = "\"";
                }
            }
            aTmp = xPropSet->getPropertyValue( "HiddenValue" );
            if( auto s = o3tl::tryAccess<OUString>(aTmp) )
            {
                if( !s->isEmpty() )
                {
                    sOut += " " OOO_STRING_SVTOOLS_HTML_O_value "=\"";
                    Strm().WriteOString( sOut );
                    HTMLOutFuncs::Out_String( Strm(), *s,
                                              m_eDestEnc, &m_aNonConvertableCharacters );
                    sOut = "\"";
                }
            }
            sOut += ">";
            Strm().WriteOString( sOut );

            m_nFormCntrlCnt++;
        }
        else if( lcl_html_isHTMLControl( *n ) )
        {
            break;
        }
    }
}

// here are the output routines, thus the form::Forms are bundled:

const SdrObject *SwHTMLWriter::GetHTMLControl( const SwDrawFrameFormat& rFormat )
{
    // it must be a Draw-Format
    OSL_ENSURE( RES_DRAWFRMFMT == rFormat.Which(),
            "GetHTMLControl only allow for Draw-Formats" );

    // Look if a SdrObject exists for it
    const SdrObject *pObj = rFormat.FindSdrObject();
    if( !pObj || SdrInventor::FmForm != pObj->GetObjInventor() )
        return nullptr;

    const SdrUnoObj& rFormObj = dynamic_cast<const SdrUnoObj&>(*pObj);
    const uno::Reference< awt::XControlModel >&  xControlModel =
            rFormObj.GetUnoControlModel();

    OSL_ENSURE( xControlModel.is(), "UNO-Control without model" );
    if( !xControlModel.is() )
        return nullptr;

    uno::Reference< beans::XPropertySet >  xPropSet( xControlModel, uno::UNO_QUERY );

    OUString sPropName("ClassId");
    if( !xPropSet->getPropertySetInfo()->hasPropertyByName( sPropName ) )
        return nullptr;

    uno::Any aTmp = xPropSet->getPropertyValue( sPropName );
    if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
    {
        if( lcl_html_isHTMLControl( *n ) )
        {
            return pObj;
        }
    }

    return nullptr;
}

static void GetControlSize(const SdrUnoObj& rFormObj, Size& rSz, SwDoc *pDoc)
{
    SwViewShell *pVSh = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
    if( !pVSh )
        return;

    uno::Reference< awt::XControl >  xControl;
    SdrView* pDrawView = pVSh->GetDrawView();
    OSL_ENSURE( pDrawView && pVSh->GetWin(), "no DrawView or window!" );
    if ( pDrawView && pVSh->GetWin() )
        xControl = rFormObj.GetUnoControl( *pDrawView, *pVSh->GetWin() );
    uno::Reference< awt::XTextLayoutConstrains > xLC( xControl, uno::UNO_QUERY );
    OSL_ENSURE( xLC.is(), "no XTextLayoutConstrains" );
    if( !xLC.is() )
        return;

    sal_Int16 nCols=0, nLines=0;
    xLC->getColumnsAndLines( nCols, nLines );
    rSz.setWidth( nCols );
    rSz.setHeight( nLines );
}

Writer& OutHTML_DrawFrameFormatAsControl( Writer& rWrt,
                                     const SwDrawFrameFormat& rFormat,
                                     const SdrUnoObj& rFormObj,
                                     bool bInCntnr )
{
    const uno::Reference< awt::XControlModel >& xControlModel =
        rFormObj.GetUnoControlModel();

    OSL_ENSURE( xControlModel.is(), "UNO-Control without model" );
    if( !xControlModel.is() )
        return rWrt;

    uno::Reference< beans::XPropertySet > xPropSet( xControlModel, uno::UNO_QUERY );
    uno::Reference< beans::XPropertySetInfo > xPropSetInfo =
            xPropSet->getPropertySetInfo();

    SwHTMLWriter & rHTMLWrt = static_cast<SwHTMLWriter&>(rWrt);
    rHTMLWrt.m_nFormCntrlCnt++;

    enum Tag { TAG_INPUT, TAG_SELECT, TAG_TEXTAREA, TAG_NONE };
    static char const * const TagNames[] = {
        OOO_STRING_SVTOOLS_HTML_input, OOO_STRING_SVTOOLS_HTML_select,
        OOO_STRING_SVTOOLS_HTML_textarea };
    Tag eTag = TAG_INPUT;
    enum Type {
        TYPE_TEXT, TYPE_PASSWORD, TYPE_CHECKBOX, TYPE_RADIO, TYPE_FILE,
        TYPE_SUBMIT, TYPE_IMAGE, TYPE_RESET, TYPE_BUTTON, TYPE_NONE };
    static char const * const TypeNames[] = {
        OOO_STRING_SVTOOLS_HTML_IT_text, OOO_STRING_SVTOOLS_HTML_IT_password,
        OOO_STRING_SVTOOLS_HTML_IT_checkbox, OOO_STRING_SVTOOLS_HTML_IT_radio,
        OOO_STRING_SVTOOLS_HTML_IT_file, OOO_STRING_SVTOOLS_HTML_IT_submit,
        OOO_STRING_SVTOOLS_HTML_IT_image, OOO_STRING_SVTOOLS_HTML_IT_reset,
        OOO_STRING_SVTOOLS_HTML_IT_button };
    Type eType = TYPE_NONE;
    OUString sValue;
    OString sOptions;
    bool bEmptyValue = false;
    uno::Any aTmp = xPropSet->getPropertyValue( "ClassId" );
    sal_Int16 nClassId = *o3tl::doAccess<sal_Int16>(aTmp);
    HtmlFrmOpts nFrameOpts = HTML_FRMOPTS_CONTROL;
    switch( nClassId )
    {
    case form::FormComponentType::CHECKBOX:
    case form::FormComponentType::RADIOBUTTON:
        eType = (form::FormComponentType::CHECKBOX == nClassId
                    ? TYPE_CHECKBOX : TYPE_RADIO);
        aTmp = xPropSet->getPropertyValue( "DefaultState" );
        if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
        {
            if ( TRISTATE_FALSE != *n )
            {
                sOptions += " " OOO_STRING_SVTOOLS_HTML_O_checked "=\""
                    OOO_STRING_SVTOOLS_HTML_O_checked
                    "\"";
            }
        }

        aTmp = xPropSet->getPropertyValue( "RefValue" );
        if( auto rVal = o3tl::tryAccess<OUString>(aTmp) )

        {
            if( rVal->isEmpty() )
                bEmptyValue = true;
            else if( *rVal != OOO_STRING_SVTOOLS_HTML_on )
                sValue = *rVal;
        }
        break;

    case form::FormComponentType::COMMANDBUTTON:
        {
            form::FormButtonType eButtonType = form::FormButtonType_PUSH;
            aTmp = xPropSet->getPropertyValue( "ButtonType" );
            if( auto t = o3tl::tryAccess<form::FormButtonType>(aTmp) )
                eButtonType = *t;

            switch( eButtonType )
            {
            case form::FormButtonType_RESET:
                eType = TYPE_RESET;
                break;
            case form::FormButtonType_SUBMIT:
                eType = TYPE_SUBMIT;
                break;
            case form::FormButtonType_PUSH:
            default:
                eType = TYPE_BUTTON;
            }

            aTmp = xPropSet->getPropertyValue( "Label" );
            if( auto s = o3tl::tryAccess<OUString>(aTmp) )
            {
                if( !s->isEmpty() )
                {
                    sValue = *s;
                }
            }
        }
        break;

    case form::FormComponentType::LISTBOX:
        if( rHTMLWrt.m_bLFPossible )
            rHTMLWrt.OutNewLine( true );
        eTag = TAG_SELECT;
        aTmp = xPropSet->getPropertyValue( "Dropdown" );
        if( auto b1 = o3tl::tryAccess<bool>(aTmp) )
        {
            if( !*b1 )
            {
                Size aSz( 0, 0 );
                GetControlSize( rFormObj, aSz, rWrt.m_pDoc );

                // How many are visible ??
                if( aSz.Height() )
                {
                    sOptions += " " OOO_STRING_SVTOOLS_HTML_O_size "=\"" +
                        OString::number(static_cast<sal_Int32>(aSz.Height())) + "\"";
                }

                auto aTmp2 = xPropSet->getPropertyValue( "MultiSelection" );
                if( auto b2 = o3tl::tryAccess<bool>(aTmp2) )
                {
                    if ( *b2 )
                    {
                        sOptions += " " OOO_STRING_SVTOOLS_HTML_O_multiple;
                    }
                }
            }
        }
        break;

    case form::FormComponentType::TEXTFIELD:
        {
            Size aSz( 0, 0 );
            GetControlSize( rFormObj, aSz, rWrt.m_pDoc );

            bool bMultiLine = false;
            OUString sMultiLine("MultiLine");
            if( xPropSetInfo->hasPropertyByName( sMultiLine ) )
            {
                aTmp = xPropSet->getPropertyValue( sMultiLine );
                auto b = o3tl::tryAccess<bool>(aTmp);
                bMultiLine = b && *b;
            }

            if( bMultiLine )
            {
                if( rHTMLWrt.m_bLFPossible )
                    rHTMLWrt.OutNewLine( true );
                eTag = TAG_TEXTAREA;

                if( aSz.Height() )
                {
                    sOptions += " " OOO_STRING_SVTOOLS_HTML_O_rows "=\"" +
                        OString::number(static_cast<sal_Int32>(aSz.Height())) + "\"";
                }
                if( aSz.Width() )
                {
                    sOptions += " " OOO_STRING_SVTOOLS_HTML_O_cols "=\"" +
                        OString::number(static_cast<sal_Int32>(aSz.Width())) + "\"";
                }

                aTmp = xPropSet->getPropertyValue( "HScroll" );
                if( aTmp.getValueType() == cppu::UnoType<void>::get() ||
                    (aTmp.getValueType() == cppu::UnoType<bool>::get() &&
                    !*o3tl::forceAccess<bool>(aTmp)) )
                {
                    const char *pWrapStr = nullptr;
                    auto aTmp2 = xPropSet->getPropertyValue( "HardLineBreaks" );
                    auto b = o3tl::tryAccess<bool>(aTmp2);
                    pWrapStr = (b && *b) ? OOO_STRING_SVTOOLS_HTML_WW_hard
                                         : OOO_STRING_SVTOOLS_HTML_WW_soft;
                    sOptions += OStringLiteral(" " OOO_STRING_SVTOOLS_HTML_O_wrap "=\"") +
                        pWrapStr + "\"";
                }
            }
            else
            {
                eType = TYPE_TEXT;
                OUString sEchoChar("EchoChar");
                if( xPropSetInfo->hasPropertyByName( sEchoChar ) )
                {
                    aTmp = xPropSet->getPropertyValue( sEchoChar );
                    if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
                    {
                        if( *n != 0 )
                            eType = TYPE_PASSWORD;
                    }
                }

                if( aSz.Width() )
                {
                    sOptions += " " OOO_STRING_SVTOOLS_HTML_O_size "=\"" +
                        OString::number(static_cast<sal_Int32>(aSz.Width())) + "\"";
                }

                aTmp = xPropSet->getPropertyValue( "MaxTextLen" );
                if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
                {
                    if( *n != 0 )
                    {
                        sOptions += " " OOO_STRING_SVTOOLS_HTML_O_maxlength "=\"" +
                            OString::number(static_cast<sal_Int32>(*n)) + "\"";
                    }
                }

                if( xPropSetInfo->hasPropertyByName( "DefaultText" ) )
                {
                    aTmp = xPropSet->getPropertyValue( "DefaultText" );
                    if( auto s = o3tl::tryAccess<OUString>(aTmp) )
                    {
                        if( !s->isEmpty() )
                        {
                            sValue = *s;
                        }
                    }
                }
            }
        }
        break;

    case form::FormComponentType::FILECONTROL:
        {
            Size aSz( 0, 0 );
            GetControlSize( rFormObj, aSz, rWrt.m_pDoc );
            eType = TYPE_FILE;

            if( aSz.Width() )
            {
                sOptions += " " OOO_STRING_SVTOOLS_HTML_O_size "=\"" +
                    OString::number(static_cast<sal_Int32>(aSz.Width())) + "\"";
            }

            // VALUE vim form: don't export because of security reasons
        }
        break;

    case form::FormComponentType::IMAGEBUTTON:
        eType = TYPE_IMAGE;
        nFrameOpts = HTML_FRMOPTS_IMG_CONTROL;
        break;

    default:                // doesn't know HTML
        eTag = TAG_NONE;    // therefore skip it
        break;
    }

    if( eTag == TAG_NONE )
        return rWrt;

    OString sOut = OStringLiteral("<") + TagNames[eTag];
    if( eType != TYPE_NONE )
    {
        sOut += OStringLiteral(" " OOO_STRING_SVTOOLS_HTML_O_type "=\"") +
            TypeNames[eType] + "\"";
    }

    aTmp = xPropSet->getPropertyValue("Name");
    if( auto s = o3tl::tryAccess<OUString>(aTmp) )
    {
        if( !s->isEmpty() )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_name "=\"";
            rWrt.Strm().WriteOString( sOut );
            HTMLOutFuncs::Out_String( rWrt.Strm(), *s,
                                      rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
            sOut = "\"";
        }
    }

    aTmp = xPropSet->getPropertyValue("Enabled");
    if( auto b = o3tl::tryAccess<bool>(aTmp) )
    {
        if( !*b )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_disabled;
        }
    }

    if( !sValue.isEmpty() || bEmptyValue )
    {
        sOut += " " OOO_STRING_SVTOOLS_HTML_O_value "=\"";
        rWrt.Strm().WriteOString( sOut );
        HTMLOutFuncs::Out_String( rWrt.Strm(), sValue, rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
        sOut = "\"";
    }

    sOut += " " + sOptions;

    if( TYPE_IMAGE == eType )
    {
        aTmp = xPropSet->getPropertyValue( "ImageURL" );
        if( auto s = o3tl::tryAccess<OUString>(aTmp) )
        {
            if( !s->isEmpty() )
            {
                sOut += " " OOO_STRING_SVTOOLS_HTML_O_src "=\"";
                rWrt.Strm().WriteOString( sOut );

                HTMLOutFuncs::Out_String( rWrt.Strm(),
                            URIHelper::simpleNormalizedMakeRelative( rWrt.GetBaseURL(), *s),
                            rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
                sOut = "\"";
            }
        }

        Size aTwipSz( rFormObj.GetLogicRect().GetSize() );
        Size aPixelSz( 0, 0 );
        if( (aTwipSz.Width() || aTwipSz.Height()) &&
            Application::GetDefaultDevice() )
        {
            aPixelSz =
                Application::GetDefaultDevice()->LogicToPixel( aTwipSz,
                                                    MapMode(MapUnit::MapTwip) );
            if( !aPixelSz.Width() && aTwipSz.Width() )
                aPixelSz.setWidth( 1 );
            if( !aPixelSz.Height() && aTwipSz.Height() )
                aPixelSz.setHeight( 1 );
        }

        if( aPixelSz.Width() )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_width "=\"" +
                OString::number(static_cast<sal_Int32>(aPixelSz.Width())) + "\"";
        }

        if( aPixelSz.Height() )
        {
            sOut += " " OOO_STRING_SVTOOLS_HTML_O_height "=\"" +
                OString::number(static_cast<sal_Int32>(aPixelSz.Height())) + "\"";
        }
    }

    aTmp = xPropSet->getPropertyValue( "TabIndex" );
    if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
    {
        sal_Int16 nTabIndex = *n;
        if( nTabIndex > 0 )
        {
            if( nTabIndex >= 32767 )
                nTabIndex = 32767;

            sOut += " " OOO_STRING_SVTOOLS_HTML_O_tabindex "=\"" +
                OString::number(static_cast<sal_Int32>(nTabIndex)) + "\"";
        }
    }

    if( !sOut.isEmpty() )
        rWrt.Strm().WriteOString( sOut );

    OSL_ENSURE( !bInCntnr, "Container is not supported for Controls" );
    if( rHTMLWrt.IsHTMLMode( HTMLMODE_ABS_POS_DRAW ) && !bInCntnr )
    {
        // If Character-Objects can't be positioned absolutely,
        // then delete the corresponding flag.
        nFrameOpts |= (TYPE_IMAGE == eType
                            ? HTML_FRMOPTS_IMG_CONTROL_CSS1
                            : HTML_FRMOPTS_CONTROL_CSS1);
    }
    OString aEndTags;
    if( nFrameOpts != HtmlFrmOpts::NONE )
        aEndTags = rHTMLWrt.OutFrameFormatOptions(rFormat, OUString(), nFrameOpts);

    if( rHTMLWrt.m_bCfgOutStyles )
    {
        bool bEdit = TAG_TEXTAREA == eTag || TYPE_FILE == eType ||
                     TYPE_TEXT == eType;

        SfxItemSet aItemSet( rHTMLWrt.m_pDoc->GetAttrPool(), svl::Items<RES_CHRATR_BEGIN,
                             RES_CHRATR_END>{} );
        if( xPropSetInfo->hasPropertyByName( "BackgroundColor" ) )
        {
            aTmp = xPropSet->getPropertyValue( "BackgroundColor" );
            if( auto n = o3tl::tryAccess<sal_Int32>(aTmp) )
            {
                Color aCol(*n);
                aItemSet.Put( SvxBrushItem( aCol, RES_CHRATR_BACKGROUND ) );
            }
        }
        if( xPropSetInfo->hasPropertyByName( "TextColor" ) )
        {
            aTmp = xPropSet->getPropertyValue( "TextColor" );
            if( auto n = o3tl::tryAccess<sal_Int32>(aTmp) )
            {
                Color aColor( *n );
                aItemSet.Put( SvxColorItem( aColor, RES_CHRATR_COLOR ) );
            }
        }
        if( xPropSetInfo->hasPropertyByName( "FontHeight" ) )
        {
            aTmp = xPropSet->getPropertyValue( "FontHeight" );
            if( auto nHeight = o3tl::tryAccess<float>(aTmp) )

            {
                if( *nHeight > 0  && (!bEdit || !rtl::math::approxEqual(*nHeight, 10.0)) )
                    aItemSet.Put( SvxFontHeightItem( sal_Int16(*nHeight * 20.), 100, RES_CHRATR_FONTSIZE ) );
            }
        }
        if( xPropSetInfo->hasPropertyByName( "FontName" ) )
        {
            aTmp = xPropSet->getPropertyValue( "FontName" );
            if( auto aFName = o3tl::tryAccess<OUString>(aTmp) )
            {
                if( !aFName->isEmpty() )
                {
                    vcl::Font aFixedFont( OutputDevice::GetDefaultFont(
                                        DefaultFontType::FIXED, LANGUAGE_ENGLISH_US,
                                        GetDefaultFontFlags::OnlyOne ) );
                    if( !bEdit || *aFName != aFixedFont.GetFamilyName() )
                    {
                        FontFamily eFamily = FAMILY_DONTKNOW;
                        if( xPropSetInfo->hasPropertyByName( "FontFamily" ) )
                        {
                            auto aTmp2 = xPropSet->getPropertyValue( "FontFamily" );
                            if( auto n = o3tl::tryAccess<sal_Int16>(aTmp2) )
                                eFamily = static_cast<FontFamily>(*n);
                        }
                        SvxFontItem aItem(eFamily, *aFName, OUString(), PITCH_DONTKNOW, RTL_TEXTENCODING_DONTKNOW, RES_CHRATR_FONT);
                        aItemSet.Put( aItem );
                    }
                }
            }
        }
        if( xPropSetInfo->hasPropertyByName( "FontWeight" ) )
        {
            aTmp = xPropSet->getPropertyValue( "FontWeight" );
            if( auto x = o3tl::tryAccess<float>(aTmp) )
            {
                FontWeight eWeight =
                    vcl::unohelper::ConvertFontWeight( *x );
                if( eWeight != WEIGHT_DONTKNOW && eWeight != WEIGHT_NORMAL )
                    aItemSet.Put( SvxWeightItem( eWeight, RES_CHRATR_WEIGHT ) );
            }
        }
        if( xPropSetInfo->hasPropertyByName( "FontSlant" ) )
        {
            aTmp = xPropSet->getPropertyValue( "FontSlant" );
            if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
            {
                FontItalic eItalic = static_cast<FontItalic>(*n);
                if( eItalic != ITALIC_DONTKNOW && eItalic != ITALIC_NONE )
                    aItemSet.Put( SvxPostureItem( eItalic, RES_CHRATR_POSTURE ) );
            }
        }
        if( xPropSetInfo->hasPropertyByName( "FontLineStyle" ) )
        {
            aTmp = xPropSet->getPropertyValue( "FontLineStyle" );
            if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
            {
                FontLineStyle eUnderline = static_cast<FontLineStyle>(*n);
                if( eUnderline != LINESTYLE_DONTKNOW  &&
                    eUnderline != LINESTYLE_NONE )
                    aItemSet.Put( SvxUnderlineItem( eUnderline, RES_CHRATR_UNDERLINE ) );
            }
        }
        if( xPropSetInfo->hasPropertyByName( "FontStrikeout" ) )
        {
            aTmp = xPropSet->getPropertyValue( "FontStrikeout" );
            if( auto n = o3tl::tryAccess<sal_Int16>(aTmp) )
            {
                FontStrikeout eStrikeout = static_cast<FontStrikeout>(*n);
                if( eStrikeout != STRIKEOUT_DONTKNOW &&
                    eStrikeout != STRIKEOUT_NONE )
                    aItemSet.Put( SvxCrossedOutItem( eStrikeout, RES_CHRATR_CROSSEDOUT ) );
            }
        }

        rHTMLWrt.OutCSS1_FrameFormatOptions( rFormat, nFrameOpts, &rFormObj,
                                        &aItemSet );
    }

    uno::Reference< form::XFormComponent >  xFormComp( xControlModel, uno::UNO_QUERY );
    lcl_html_outEvents( rWrt.Strm(), xFormComp, rHTMLWrt.m_bCfgStarBasic,
                        rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );

    rWrt.Strm().WriteChar( '>' );

    if( TAG_SELECT == eTag )
    {
        aTmp = xPropSet->getPropertyValue( "StringItemList" );
        if( auto aList = o3tl::tryAccess<uno::Sequence<OUString>>(aTmp) )
        {
            rHTMLWrt.IncIndentLevel(); // the content of Select can be indented
            sal_Int32 nCnt = aList->getLength();
            const OUString *pStrings = aList->getConstArray();

            const OUString *pValues = nullptr;
            sal_Int32 nValCnt = 0;
            auto aTmp2 = xPropSet->getPropertyValue( "ListSource" );
            uno::Sequence<OUString> aValList;
            if( auto s = o3tl::tryAccess<uno::Sequence<OUString>>(aTmp2) )
            {
                aValList = *s;
                nValCnt = aValList.getLength();
                pValues = aValList.getConstArray();
            }

            uno::Any aSelTmp = xPropSet->getPropertyValue( "DefaultSelection" );
            const sal_Int16 *pSels = nullptr;
            sal_Int32 nSel = 0;
            sal_Int32 nSelCnt = 0;
            uno::Sequence<sal_Int16> aSelList;
            if( auto s = o3tl::tryAccess<uno::Sequence<sal_Int16>>(aSelTmp) )
            {
                aSelList = *s;
                nSelCnt = aSelList.getLength();
                pSels = aSelList.getConstArray();
            }

            for( sal_Int32 i = 0; i < nCnt; i++ )
            {
                OUString sVal;
                bool bSelected = false, bEmptyVal = false;
                if( i < nValCnt )
                {
                    const OUString& rVal = pValues[i];
                    if( rVal == "$$$empty$$$" )
                        bEmptyVal = true;
                    else
                        sVal = rVal;
                }

                bSelected = (nSel < nSelCnt) && pSels[nSel] == i;
                if( bSelected )
                    nSel++;

                rHTMLWrt.OutNewLine(); // every Option gets its own line
                sOut = "<" OOO_STRING_SVTOOLS_HTML_option;
                if( !sVal.isEmpty() || bEmptyVal )
                {
                    sOut += " " OOO_STRING_SVTOOLS_HTML_O_value "=\"";
                    rWrt.Strm().WriteOString( sOut );
                    HTMLOutFuncs::Out_String( rWrt.Strm(), sVal,
                        rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
                    sOut = "\"";
                }
                if( bSelected )
                    sOut += " " OOO_STRING_SVTOOLS_HTML_O_selected;

                sOut += ">";
                rWrt.Strm().WriteOString( sOut );

                HTMLOutFuncs::Out_String( rWrt.Strm(), pStrings[i],
                                          rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
            }
            HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_option, false );

            rHTMLWrt.DecIndentLevel();
            rHTMLWrt.OutNewLine();// the </SELECT> gets its own line
        }
        HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_select, false );
    }
    else if( TAG_TEXTAREA == eTag )
    {
        // In TextAreas no additional spaces or LF may be exported!
        OUString sVal;
        aTmp = xPropSet->getPropertyValue( "DefaultText" );
        if( auto s = o3tl::tryAccess<OUString>(aTmp) )
        {
            if( !s->isEmpty() )
            {
                sVal = *s;
            }
        }
        if( !sVal.isEmpty() )
        {
            sVal = convertLineEnd(sVal, LINEEND_LF);
            sal_Int32 nPos = 0;
            while ( nPos != -1 )
            {
                if( nPos )
                    rWrt.Strm().WriteCharPtr( SAL_NEWLINE_STRING );
                OUString aLine = sVal.getToken( 0, 0x0A, nPos );
                HTMLOutFuncs::Out_String( rWrt.Strm(), aLine,
                                        rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters );
            }
        }
        HTMLOutFuncs::Out_AsciiTag( rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_textarea, false );
    }
    else if( TYPE_CHECKBOX == eType || TYPE_RADIO == eType )
    {
        aTmp = xPropSet->getPropertyValue("Label");
        if( auto s = o3tl::tryAccess<OUString>(aTmp) )
        {
            if( !s->isEmpty() )
            {
                HTMLOutFuncs::Out_String( rWrt.Strm(), *s,
                    rHTMLWrt.m_eDestEnc, &rHTMLWrt.m_aNonConvertableCharacters ).WriteChar( ' ' );
            }
        }
    }

    if( !aEndTags.isEmpty() )
        rWrt.Strm().WriteOString( aEndTags );

    // Controls aren't bound to a paragraph, therefore don't output LF anymore!
    rHTMLWrt.m_bLFPossible = false;

    if( rHTMLWrt.mxFormComps.is() )
        rHTMLWrt.OutHiddenControls( rHTMLWrt.mxFormComps, xPropSet );
    return rWrt;
}

/**
 * Find out if a format belongs to a control and if yes return its form.
 */
static void AddControl( HTMLControls& rControls,
                        const SdrUnoObj& rFormObj,
                        sal_uInt32 nNodeIdx )
{
    const uno::Reference< awt::XControlModel >& xControlModel =
            rFormObj.GetUnoControlModel();
    if( !xControlModel.is() )
        return;

    uno::Reference< form::XFormComponent >  xFormComp( xControlModel, uno::UNO_QUERY );
    uno::Reference< uno::XInterface >  xIfc = xFormComp->getParent();
    uno::Reference< form::XForm >  xForm(xIfc, uno::UNO_QUERY);

    OSL_ENSURE( xForm.is(), "Where is the form?" );
    if( xForm.is() )
    {
        uno::Reference< container::XIndexContainer >  xFormComps( xForm, uno::UNO_QUERY );
        std::unique_ptr<HTMLControl> pHCntrl(new HTMLControl( xFormComps, nNodeIdx ));
        auto itPair = rControls.insert( std::move(pHCntrl) );
        if (!itPair.second )
        {
            if( (*itPair.first)->xFormComps==xFormComps )
                (*itPair.first)->nCount++;
        }
    }
}

void SwHTMLWriter::GetControls()
{
    // Idea: first off collect the paragraph- and character-bound controls.
    // In the process for every control the paragraph position and VCForm are
    // saved in an array.
    // With that array it's possible to find out where form::Forms must be
    // opened and closed.

    if( m_pHTMLPosFlyFrames )
    {
        // collect the paragraph-bound controls
        for( size_t i=0; i<m_pHTMLPosFlyFrames->size(); i++ )
        {
            const SwHTMLPosFlyFrame* pPosFlyFrame = (*m_pHTMLPosFlyFrames)[ i ].get();
            if( HtmlOut::Control != pPosFlyFrame->GetOutFn() )
                continue;

            const SdrObject *pSdrObj = pPosFlyFrame->GetSdrObject();
            OSL_ENSURE( pSdrObj, "Where is the SdrObject?" );
            if( !pSdrObj )
                continue;

            AddControl( m_aHTMLControls, dynamic_cast<const SdrUnoObj&>(*pSdrObj),
                        pPosFlyFrame->GetNdIndex().GetIndex() );
        }
    }

    // and now the ones in a character-bound frame
    const SwFrameFormats* pSpzFrameFormats = m_pDoc->GetSpzFrameFormats();
    for( size_t i=0; i<pSpzFrameFormats->size(); i++ )
    {
        const SwFrameFormat *pFrameFormat = (*pSpzFrameFormats)[i];
        if( RES_DRAWFRMFMT != pFrameFormat->Which() )
            continue;

        const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor();
        const SwPosition *pPos = rAnchor.GetContentAnchor();
        if ((RndStdIds::FLY_AS_CHAR != rAnchor.GetAnchorId()) || !pPos)
            continue;

        const SdrObject *pSdrObj =
            SwHTMLWriter::GetHTMLControl( *static_cast<const SwDrawFrameFormat*>(pFrameFormat) );
        if( !pSdrObj )
            continue;

        AddControl( m_aHTMLControls, dynamic_cast<const SdrUnoObj&>(*pSdrObj), pPos->nNode.GetIndex() );
    }
}

HTMLControl::HTMLControl(
        const uno::Reference< container::XIndexContainer > & rFormComps,
        sal_uInt32 nIdx ) :
    xFormComps( rFormComps ), nNdIdx( nIdx ), nCount( 1 )
{}

HTMLControl::~HTMLControl()
{}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */