1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <oox/ole/axcontrol.hxx>
21 
22 #include <com/sun/star/awt/FontSlant.hpp>
23 #include <com/sun/star/awt/FontStrikeout.hpp>
24 #include <com/sun/star/awt/FontUnderline.hpp>
25 #include <com/sun/star/awt/FontWeight.hpp>
26 #include <com/sun/star/awt/ImagePosition.hpp>
27 #include <com/sun/star/awt/ImageScaleMode.hpp>
28 #include <com/sun/star/awt/Point.hpp>
29 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
30 #include <com/sun/star/awt/Size.hpp>
31 #include <com/sun/star/awt/TextAlign.hpp>
32 #include <com/sun/star/awt/VisualEffect.hpp>
33 #include <com/sun/star/awt/XControlModel.hpp>
34 #include <com/sun/star/beans/NamedValue.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/container/XIndexContainer.hpp>
37 #include <com/sun/star/drawing/XDrawPage.hpp>
38 #include <com/sun/star/form/XForm.hpp>
39 #include <com/sun/star/form/XFormComponent.hpp>
40 #include <com/sun/star/form/XFormsSupplier.hpp>
41 #include <com/sun/star/form/binding/XBindableValue.hpp>
42 #include <com/sun/star/form/binding/XListEntrySink.hpp>
43 #include <com/sun/star/form/binding/XListEntrySource.hpp>
44 #include <com/sun/star/form/binding/XValueBinding.hpp>
45 #include <com/sun/star/frame/XModel.hpp>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
48 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
49 #include <com/sun/star/style/VerticalAlignment.hpp>
50 #include <com/sun/star/table/CellAddress.hpp>
51 #include <com/sun/star/table/CellRangeAddress.hpp>
52 #include <rtl/tencinfo.h>
53 #include <osl/diagnose.h>
54 #include <vcl/font.hxx>
55 #include <vcl/outdev.hxx>
56 #include <vcl/settings.hxx>
57 #include <vcl/svapp.hxx>
58 #include <oox/helper/attributelist.hxx>
59 #include <oox/helper/binaryinputstream.hxx>
60 #include <oox/helper/graphichelper.hxx>
61 #include <oox/helper/propertymap.hxx>
62 #include <oox/ole/axbinarywriter.hxx>
63 #include <oox/token/properties.hxx>
64 #include <oox/token/tokens.hxx>
65 #include <tools/diagnose_ex.h>
66 
67 namespace oox::ole {
68 
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::awt;
71 using namespace ::com::sun::star::beans;
72 using namespace ::com::sun::star::container;
73 using namespace ::com::sun::star::drawing;
74 using namespace ::com::sun::star::form;
75 using namespace ::com::sun::star::form::binding;
76 using namespace ::com::sun::star::frame;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::sheet;
79 using namespace ::com::sun::star::style;
80 using namespace ::com::sun::star::table;
81 using namespace ::com::sun::star::uno;
82 
83 namespace {
84 
85 const sal_uInt32 COMCTL_ID_SIZE             = 0x12344321;
86 
87 const sal_uInt32 COMCTL_ID_COMMONDATA       = 0xABCDEF01;
88 const sal_uInt32 COMCTL_COMMON_FLATBORDER   = 0x00000001;
89 const sal_uInt32 COMCTL_COMMON_ENABLED      = 0x00000002;
90 const sal_uInt32 COMCTL_COMMON_3DBORDER     = 0x00000004;
91 
92 const sal_uInt32 COMCTL_ID_COMPLEXDATA      = 0xBDECDE1F;
93 const sal_uInt32 COMCTL_COMPLEX_FONT        = 0x00000001;
94 const sal_uInt32 COMCTL_COMPLEX_MOUSEICON   = 0x00000002;
95 
96 const sal_uInt32 COMCTL_ID_SCROLLBAR_60     = 0x99470A83;
97 const sal_uInt32 COMCTL_SCROLLBAR_HOR       = 0x00000010;
98 
99 const sal_uInt32 COMCTL_ID_PROGRESSBAR_50   = 0xE6E17E84;
100 const sal_uInt32 COMCTL_ID_PROGRESSBAR_60   = 0x97AB8A01;
101 
102 const sal_uInt32 AX_CMDBUTTON_DEFFLAGS      = 0x0000001B;
103 const sal_uInt32 AX_LABEL_DEFFLAGS          = 0x0080001B;
104 const sal_uInt32 AX_IMAGE_DEFFLAGS          = 0x0000001B;
105 const sal_uInt32 AX_MORPHDATA_DEFFLAGS      = 0x2C80081B;
106 const sal_uInt32 AX_SPINBUTTON_DEFFLAGS     = 0x0000001B;
107 const sal_uInt32 AX_SCROLLBAR_DEFFLAGS      = 0x0000001B;
108 
109 const sal_uInt16 AX_POS_TOPLEFT             = 0;
110 const sal_uInt16 AX_POS_TOP                 = 1;
111 const sal_uInt16 AX_POS_TOPRIGHT            = 2;
112 const sal_uInt16 AX_POS_LEFT                = 3;
113 const sal_uInt16 AX_POS_CENTER              = 4;
114 const sal_uInt16 AX_POS_RIGHT               = 5;
115 const sal_uInt16 AX_POS_BOTTOMLEFT          = 6;
116 const sal_uInt16 AX_POS_BOTTOM              = 7;
117 const sal_uInt16 AX_POS_BOTTOMRIGHT         = 8;
118 
119 #define AX_PICPOS_IMPL( label, image ) ((AX_POS_##label << 16) | AX_POS_##image)
120 const sal_uInt32 AX_PICPOS_LEFTTOP          = AX_PICPOS_IMPL( TOPRIGHT,    TOPLEFT );
121 const sal_uInt32 AX_PICPOS_LEFTCENTER       = AX_PICPOS_IMPL( RIGHT,       LEFT );
122 const sal_uInt32 AX_PICPOS_LEFTBOTTOM       = AX_PICPOS_IMPL( BOTTOMRIGHT, BOTTOMLEFT );
123 const sal_uInt32 AX_PICPOS_RIGHTTOP         = AX_PICPOS_IMPL( TOPLEFT,     TOPRIGHT );
124 const sal_uInt32 AX_PICPOS_RIGHTCENTER      = AX_PICPOS_IMPL( LEFT,        RIGHT );
125 const sal_uInt32 AX_PICPOS_RIGHTBOTTOM      = AX_PICPOS_IMPL( BOTTOMLEFT,  BOTTOMRIGHT );
126 const sal_uInt32 AX_PICPOS_ABOVELEFT        = AX_PICPOS_IMPL( BOTTOMLEFT,  TOPLEFT );
127 const sal_uInt32 AX_PICPOS_ABOVECENTER      = AX_PICPOS_IMPL( BOTTOM,      TOP  );
128 const sal_uInt32 AX_PICPOS_ABOVERIGHT       = AX_PICPOS_IMPL( BOTTOMRIGHT, TOPRIGHT );
129 const sal_uInt32 AX_PICPOS_BELOWLEFT        = AX_PICPOS_IMPL( TOPLEFT,     BOTTOMLEFT );
130 const sal_uInt32 AX_PICPOS_BELOWCENTER      = AX_PICPOS_IMPL( TOP,         BOTTOM );
131 const sal_uInt32 AX_PICPOS_BELOWRIGHT       = AX_PICPOS_IMPL( TOPRIGHT,    BOTTOMRIGHT );
132 const sal_uInt32 AX_PICPOS_CENTER           = AX_PICPOS_IMPL( CENTER,      CENTER  );
133 #undef AX_PICPOS_IMPL
134 
135 const sal_Int32 AX_MATCHENTRY_FIRSTLETTER   = 0;
136 const sal_Int32 AX_MATCHENTRY_COMPLETE      = 1;
137 const sal_Int32 AX_MATCHENTRY_NONE          = 2;
138 
139 const sal_Int32 AX_ORIENTATION_AUTO         = -1;
140 const sal_Int32 AX_ORIENTATION_VERTICAL     = 0;
141 const sal_Int32 AX_ORIENTATION_HORIZONTAL   = 1;
142 
143 const sal_Int32 AX_PROPTHUMB_ON             = -1;
144 
145 const sal_uInt32 AX_TABSTRIP_TABS           = 0;
146 const sal_uInt32 AX_TABSTRIP_NONE           = 2;
147 
148 const sal_uInt32 AX_CONTAINER_ENABLED       = 0x00000004;
149 const sal_uInt32 AX_CONTAINER_NOCLASSTABLE  = 0x00008000;
150 
151 const sal_uInt32 AX_CONTAINER_DEFFLAGS      = 0x00000004;
152 
153 const sal_Int32 AX_CONTAINER_DEFWIDTH       = 4000;
154 const sal_Int32 AX_CONTAINER_DEFHEIGHT      = 3000;
155 
156 const sal_Int32 AX_CONTAINER_CYCLEALL       = 0;
157 
158 const sal_Int32 AX_CONTAINER_SCR_NONE       = 0x00;
159 
160 const sal_Int16 API_BORDER_NONE             = 0;
161 const sal_Int16 API_BORDER_SUNKEN           = 1;
162 const sal_Int16 API_BORDER_FLAT             = 2;
163 
164 const sal_Int16 API_STATE_UNCHECKED         = 0;
165 const sal_Int16 API_STATE_CHECKED           = 1;
166 const sal_Int16 API_STATE_DONTKNOW          = 2;
167 
168 /** Tries to extract a range address from a defined name. */
lclExtractRangeFromName(CellRangeAddress & orRangeAddr,const Reference<XModel> & rxDocModel,const OUString & rAddressString)169 bool lclExtractRangeFromName( CellRangeAddress& orRangeAddr, const Reference< XModel >& rxDocModel, const OUString& rAddressString )
170 {
171     try
172     {
173         PropertySet aPropSet( rxDocModel );
174         Reference< XNameAccess > xRangesNA( aPropSet.getAnyProperty( PROP_NamedRanges ), UNO_QUERY_THROW );
175         Reference< XCellRangeReferrer > xReferrer( xRangesNA->getByName( rAddressString ), UNO_QUERY_THROW );
176         Reference< XCellRangeAddressable > xAddressable( xReferrer->getReferredCells(), UNO_QUERY_THROW );
177         orRangeAddr = xAddressable->getRangeAddress();
178         return true;
179     }
180     catch (const Exception&)
181     {
182         TOOLS_WARN_EXCEPTION("oox", "");
183     }
184     return false;
185 }
186 
lclExtractAddressFromName(CellAddress & orAddress,const Reference<XModel> & rxDocModel,const OUString & rAddressString)187 bool lclExtractAddressFromName( CellAddress& orAddress, const Reference< XModel >& rxDocModel, const OUString& rAddressString )
188 {
189     CellRangeAddress aRangeAddr;
190     if( lclExtractRangeFromName( aRangeAddr, rxDocModel, rAddressString ) &&
191         (aRangeAddr.StartColumn == aRangeAddr.EndColumn) &&
192         (aRangeAddr.StartRow == aRangeAddr.EndRow) )
193     {
194         orAddress.Sheet = aRangeAddr.Sheet;
195         orAddress.Column = aRangeAddr.StartColumn;
196         orAddress.Row = aRangeAddr.StartRow;
197         return true;
198     }
199     return false;
200 }
201 
lclPrepareConverter(PropertySet & rConverter,const Reference<XModel> & rxDocModel,const OUString & rAddressString,sal_Int32 nRefSheet,bool bRange)202 void lclPrepareConverter( PropertySet& rConverter, const Reference< XModel >& rxDocModel,
203         const OUString& rAddressString, sal_Int32 nRefSheet, bool bRange )
204 {
205     if( !rConverter.is() ) try
206     {
207         Reference< XMultiServiceFactory > xModelFactory( rxDocModel, UNO_QUERY_THROW );
208         OUString aServiceName = bRange ?
209             OUString( "com.sun.star.table.CellRangeAddressConversion" ) :
210             OUString( "com.sun.star.table.CellAddressConversion" );
211         rConverter.set( xModelFactory->createInstance( aServiceName ) );
212     }
213     catch (const Exception&)
214     {
215         TOOLS_WARN_EXCEPTION("oox", "");
216     }
217     rConverter.setProperty( PROP_XLA1Representation, rAddressString );
218     rConverter.setProperty( PROP_ReferenceSheet, nRefSheet );
219 }
220 
221 } // namespace
222 
ControlConverter(const Reference<XModel> & rxDocModel,const GraphicHelper & rGraphicHelper,bool bDefaultColorBgr)223 ControlConverter::ControlConverter( const Reference< XModel >& rxDocModel,
224         const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr ) :
225     mxDocModel( rxDocModel ),
226     mrGraphicHelper( rGraphicHelper ),
227     mbDefaultColorBgr( bDefaultColorBgr )
228 {
229     OSL_ENSURE( mxDocModel.is(), "ControlConverter::ControlConverter - missing document model" );
230 }
231 
~ControlConverter()232 ControlConverter::~ControlConverter()
233 {
234 }
235 
236 // Generic conversion ---------------------------------------------------------
237 
convertPosition(PropertyMap & rPropMap,const AxPairData & rPos) const238 void ControlConverter::convertPosition( PropertyMap& rPropMap, const AxPairData& rPos ) const
239 {
240     // position is given in 1/100 mm, UNO needs AppFont units
241     awt::Point aAppFontPos = mrGraphicHelper.convertHmmToAppFont( awt::Point( rPos.first, rPos.second ) );
242     rPropMap.setProperty( PROP_PositionX, aAppFontPos.X );
243     rPropMap.setProperty( PROP_PositionY, aAppFontPos.Y );
244 }
245 
convertSize(PropertyMap & rPropMap,const AxPairData & rSize) const246 void ControlConverter::convertSize( PropertyMap& rPropMap, const AxPairData& rSize ) const
247 {
248     // size is given in 1/100 mm, UNO needs AppFont units
249     awt::Size aAppFontSize = mrGraphicHelper.convertHmmToAppFont( awt::Size( rSize.first, rSize.second ) );
250     rPropMap.setProperty( PROP_Width, aAppFontSize.Width );
251     rPropMap.setProperty( PROP_Height, aAppFontSize.Height );
252 }
253 
convertColor(PropertyMap & rPropMap,sal_Int32 nPropId,sal_uInt32 nOleColor) const254 void ControlConverter::convertColor( PropertyMap& rPropMap, sal_Int32 nPropId, sal_uInt32 nOleColor ) const
255 {
256     rPropMap.setProperty( nPropId, OleHelper::decodeOleColor( mrGraphicHelper, nOleColor, mbDefaultColorBgr ) );
257 }
258 
convertToMSColor(PropertySet const & rPropSet,sal_Int32 nPropId,sal_uInt32 & nOleColor,sal_uInt32 nDefault)259 void ControlConverter::convertToMSColor( PropertySet const & rPropSet, sal_Int32 nPropId, sal_uInt32& nOleColor, sal_uInt32 nDefault )
260 {
261     sal_uInt32 nRGB = 0;
262     if (rPropSet.getProperty( nRGB, nPropId ))
263         nOleColor = OleHelper::encodeOleColor( nRGB );
264     else
265         nOleColor = nDefault;
266 }
convertPicture(PropertyMap & rPropMap,const StreamDataSequence & rPicData) const267 void ControlConverter::convertPicture( PropertyMap& rPropMap, const StreamDataSequence& rPicData ) const
268 {
269     if( rPicData.hasElements() )
270     {
271         uno::Reference<graphic::XGraphic> xGraphic = mrGraphicHelper.importGraphic(rPicData);
272         if (xGraphic.is())
273             rPropMap.setProperty(PROP_Graphic, xGraphic);
274     }
275 }
276 
convertOrientation(PropertyMap & rPropMap,bool bHorizontal)277 void ControlConverter::convertOrientation( PropertyMap& rPropMap, bool bHorizontal )
278 {
279     sal_Int32 nScrollOrient = bHorizontal ? ScrollBarOrientation::HORIZONTAL : ScrollBarOrientation::VERTICAL;
280     rPropMap.setProperty( PROP_Orientation, nScrollOrient );
281 }
282 
convertToMSOrientation(PropertySet const & rPropSet,bool & bHorizontal)283 void ControlConverter::convertToMSOrientation( PropertySet const & rPropSet, bool& bHorizontal )
284 {
285     sal_Int32 nScrollOrient = ScrollBarOrientation::HORIZONTAL;
286     if ( rPropSet.getProperty( nScrollOrient, PROP_Orientation ) )
287         bHorizontal = ( nScrollOrient == ScrollBarOrientation::HORIZONTAL );
288 }
289 
convertVerticalAlign(PropertyMap & rPropMap,sal_Int32 nVerticalAlign)290 void ControlConverter::convertVerticalAlign( PropertyMap& rPropMap, sal_Int32 nVerticalAlign )
291 {
292     VerticalAlignment eAlign = VerticalAlignment_TOP;
293     switch( nVerticalAlign )
294     {
295         case XML_Top:       eAlign = VerticalAlignment_TOP;     break;
296         case XML_Center:    eAlign = VerticalAlignment_MIDDLE;  break;
297         case XML_Bottom:    eAlign = VerticalAlignment_BOTTOM;  break;
298     }
299     rPropMap.setProperty( PROP_VerticalAlign, eAlign );
300 }
301 
convertScrollabilitySettings(PropertyMap & rPropMap,const AxPairData & rScrollPos,const AxPairData & rScrollArea,sal_Int32 nScrollBars) const302 void ControlConverter::convertScrollabilitySettings( PropertyMap& rPropMap,
303                                          const AxPairData& rScrollPos, const AxPairData& rScrollArea,
304                                          sal_Int32 nScrollBars ) const
305 {
306     awt::Size tmpSize = mrGraphicHelper.convertHmmToAppFont( awt::Size( rScrollArea.first, rScrollArea.second ) );
307     awt::Point tmpPos = mrGraphicHelper.convertHmmToAppFont( awt::Point( rScrollPos.first, rScrollPos.second ) );
308     rPropMap.setProperty( PROP_ScrollHeight, tmpSize.Height );
309     rPropMap.setProperty( PROP_ScrollWidth, tmpSize.Width );
310     rPropMap.setProperty( PROP_ScrollTop, tmpPos.Y );
311     rPropMap.setProperty( PROP_ScrollLeft, tmpPos.X );
312     rPropMap.setProperty( PROP_HScroll, ( nScrollBars & 0x1 ) == 0x1 );
313     rPropMap.setProperty( PROP_VScroll, ( nScrollBars & 0x2 ) == 0x2 );
314 }
315 
convertScrollBar(PropertyMap & rPropMap,sal_Int32 nMin,sal_Int32 nMax,sal_Int32 nPosition,sal_Int32 nSmallChange,sal_Int32 nLargeChange,bool bAwtModel)316 void ControlConverter::convertScrollBar( PropertyMap& rPropMap,
317         sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nPosition,
318         sal_Int32 nSmallChange, sal_Int32 nLargeChange, bool bAwtModel )
319 {
320     rPropMap.setProperty( PROP_ScrollValueMin, ::std::min( nMin, nMax ) );
321     rPropMap.setProperty( PROP_ScrollValueMax, ::std::max( nMin, nMax ) );
322     rPropMap.setProperty( PROP_LineIncrement, nSmallChange );
323     rPropMap.setProperty( PROP_BlockIncrement, nLargeChange );
324     rPropMap.setProperty( bAwtModel ? PROP_ScrollValue : PROP_DefaultScrollValue, nPosition );
325 }
326 
bindToSources(const Reference<XControlModel> & rxCtrlModel,const OUString & rCtrlSource,const OUString & rRowSource,sal_Int32 nRefSheet) const327 void ControlConverter::bindToSources( const Reference< XControlModel >& rxCtrlModel,
328         const OUString& rCtrlSource, const OUString& rRowSource, sal_Int32 nRefSheet ) const
329 {
330     // value binding
331     if( !rCtrlSource.isEmpty() ) try
332     {
333         // first check if the XBindableValue interface is supported
334         Reference< XBindableValue > xBindable( rxCtrlModel, UNO_QUERY_THROW );
335 
336         // convert address string to cell address struct
337         CellAddress aAddress;
338         if( !lclExtractAddressFromName( aAddress, mxDocModel, rCtrlSource ) )
339         {
340             lclPrepareConverter( maAddressConverter, mxDocModel, rCtrlSource, nRefSheet, false );
341             if( !maAddressConverter.getProperty( aAddress, PROP_Address ) )
342                 throw RuntimeException();
343         }
344 
345         // create argument sequence
346         NamedValue aValue;
347         aValue.Name = "BoundCell";
348         aValue.Value <<= aAddress;
349         Sequence< Any > aArgs( 1 );
350         aArgs[ 0 ] <<= aValue;
351 
352         // create the CellValueBinding instance and set at the control model
353         Reference< XMultiServiceFactory > xModelFactory( mxDocModel, UNO_QUERY_THROW );
354         Reference< XValueBinding > xBinding( xModelFactory->createInstanceWithArguments( "com.sun.star.table.CellValueBinding", aArgs ), UNO_QUERY_THROW );
355         xBindable->setValueBinding( xBinding );
356     }
357     catch (const Exception&)
358     {
359         TOOLS_WARN_EXCEPTION("oox", "");
360     }
361 
362     // list entry source
363     if( rRowSource.isEmpty() )
364         return;
365 
366     try
367     {
368         // first check if the XListEntrySink interface is supported
369         Reference< XListEntrySink > xEntrySink( rxCtrlModel, UNO_QUERY_THROW );
370 
371         // convert address string to cell range address struct
372         CellRangeAddress aRangeAddr;
373         if( !lclExtractRangeFromName( aRangeAddr, mxDocModel, rRowSource ) )
374         {
375             lclPrepareConverter( maRangeConverter, mxDocModel, rRowSource, nRefSheet, true );
376             if( !maRangeConverter.getProperty( aRangeAddr, PROP_Address ) )
377                 throw RuntimeException();
378         }
379 
380         // create argument sequence
381         NamedValue aValue;
382         aValue.Name = "CellRange";
383         aValue.Value <<= aRangeAddr;
384         Sequence< Any > aArgs( 1 );
385         aArgs[ 0 ] <<= aValue;
386 
387         // create the EntrySource instance and set at the control model
388         Reference< XMultiServiceFactory > xModelFactory( mxDocModel, UNO_QUERY_THROW );
389         Reference< XListEntrySource > xEntrySource( xModelFactory->createInstanceWithArguments("com.sun.star.table.CellRangeListSource", aArgs ), UNO_QUERY_THROW );
390         xEntrySink->setListEntrySource( xEntrySource );
391     }
392     catch (const Exception&)
393     {
394         TOOLS_WARN_EXCEPTION("oox", "");
395     }
396 }
397 
398 // ActiveX (Forms 2.0) specific conversion ------------------------------------
399 
convertAxBackground(PropertyMap & rPropMap,sal_uInt32 nBackColor,sal_uInt32 nFlags,ApiTransparencyMode eTranspMode) const400 void ControlConverter::convertAxBackground( PropertyMap& rPropMap,
401         sal_uInt32 nBackColor, sal_uInt32 nFlags, ApiTransparencyMode eTranspMode ) const
402 {
403     bool bOpaque = getFlag( nFlags, AX_FLAGS_OPAQUE );
404     switch( eTranspMode )
405     {
406         case ApiTransparencyMode::NotSupported:
407             // fake transparency by using system window background if needed
408             convertColor( rPropMap, PROP_BackgroundColor, bOpaque ? nBackColor : AX_SYSCOLOR_WINDOWBACK );
409         break;
410         case ApiTransparencyMode::Void:
411             // keep transparency by leaving the (void) default property value
412             if( bOpaque )
413                 convertColor( rPropMap, PROP_BackgroundColor, nBackColor );
414         break;
415     }
416 }
417 
convertAxBorder(PropertyMap & rPropMap,sal_uInt32 nBorderColor,sal_Int32 nBorderStyle,sal_Int32 nSpecialEffect) const418 void ControlConverter::convertAxBorder( PropertyMap& rPropMap,
419         sal_uInt32 nBorderColor, sal_Int32 nBorderStyle, sal_Int32 nSpecialEffect ) const
420 {
421     sal_Int16 nBorder = (nBorderStyle == AX_BORDERSTYLE_SINGLE) ? API_BORDER_FLAT :
422         ((nSpecialEffect == AX_SPECIALEFFECT_FLAT) ? API_BORDER_NONE : API_BORDER_SUNKEN);
423     rPropMap.setProperty( PROP_Border, nBorder );
424     convertColor( rPropMap, PROP_BorderColor, nBorderColor );
425 }
426 
convertToAxBorder(PropertySet const & rPropSet,sal_uInt32 & nBorderColor,sal_Int32 & nBorderStyle,sal_Int32 & nSpecialEffect)427 void ControlConverter::convertToAxBorder( PropertySet const & rPropSet,
428         sal_uInt32& nBorderColor, sal_Int32& nBorderStyle, sal_Int32& nSpecialEffect )
429 {
430     sal_Int16 nBorder = API_BORDER_NONE;
431     rPropSet.getProperty( nBorder, PROP_Border );
432     nBorderStyle = AX_BORDERSTYLE_NONE;
433     nSpecialEffect =  AX_SPECIALEFFECT_FLAT;
434     switch ( nBorder )
435     {
436         case API_BORDER_FLAT:
437             nBorderStyle = AX_BORDERSTYLE_SINGLE;
438             break;
439         case API_BORDER_SUNKEN:
440             nSpecialEffect =  AX_SPECIALEFFECT_SUNKEN;
441             break;
442         case API_BORDER_NONE:
443         default:
444             break;
445     }
446     convertToMSColor( rPropSet, PROP_BorderColor, nBorderColor );
447 }
448 
convertAxVisualEffect(PropertyMap & rPropMap,sal_Int32 nSpecialEffect)449 void ControlConverter::convertAxVisualEffect( PropertyMap& rPropMap, sal_Int32 nSpecialEffect )
450 {
451     sal_Int16 nVisualEffect = (nSpecialEffect == AX_SPECIALEFFECT_FLAT) ? VisualEffect::FLAT : VisualEffect::LOOK3D;
452     rPropMap.setProperty( PROP_VisualEffect, nVisualEffect );
453 }
454 
convertToAxVisualEffect(PropertySet const & rPropSet,sal_Int32 & nSpecialEffect)455 void ControlConverter::convertToAxVisualEffect( PropertySet const & rPropSet, sal_Int32& nSpecialEffect )
456 {
457     sal_Int16 nVisualEffect = AX_SPECIALEFFECT_FLAT;
458     rPropSet.getProperty( nVisualEffect, PROP_VisualEffect );
459     // is this appropriate AX_SPECIALEFFECT_XXXX value ?
460     if (nVisualEffect == VisualEffect::LOOK3D )
461         nSpecialEffect = AX_SPECIALEFFECT_RAISED;
462 }
463 
convertAxPicture(PropertyMap & rPropMap,const StreamDataSequence & rPicData,sal_uInt32 nPicPos) const464 void ControlConverter::convertAxPicture( PropertyMap& rPropMap, const StreamDataSequence& rPicData, sal_uInt32 nPicPos ) const
465 {
466     // the picture
467     convertPicture( rPropMap, rPicData );
468 
469     // picture position
470     sal_Int16 nImagePos = ImagePosition::LeftCenter;
471     switch( nPicPos )
472     {
473         case AX_PICPOS_LEFTTOP:     nImagePos = ImagePosition::LeftTop;     break;
474         case AX_PICPOS_LEFTCENTER:  nImagePos = ImagePosition::LeftCenter;  break;
475         case AX_PICPOS_LEFTBOTTOM:  nImagePos = ImagePosition::LeftBottom;  break;
476         case AX_PICPOS_RIGHTTOP:    nImagePos = ImagePosition::RightTop;    break;
477         case AX_PICPOS_RIGHTCENTER: nImagePos = ImagePosition::RightCenter; break;
478         case AX_PICPOS_RIGHTBOTTOM: nImagePos = ImagePosition::RightBottom; break;
479         case AX_PICPOS_ABOVELEFT:   nImagePos = ImagePosition::AboveLeft;   break;
480         case AX_PICPOS_ABOVECENTER: nImagePos = ImagePosition::AboveCenter; break;
481         case AX_PICPOS_ABOVERIGHT:  nImagePos = ImagePosition::AboveRight;  break;
482         case AX_PICPOS_BELOWLEFT:   nImagePos = ImagePosition::BelowLeft;   break;
483         case AX_PICPOS_BELOWCENTER: nImagePos = ImagePosition::BelowCenter; break;
484         case AX_PICPOS_BELOWRIGHT:  nImagePos = ImagePosition::BelowRight;  break;
485         case AX_PICPOS_CENTER:      nImagePos = ImagePosition::Centered;    break;
486         default:    OSL_FAIL( "ControlConverter::convertAxPicture - unknown picture position" );
487     }
488     rPropMap.setProperty( PROP_ImagePosition, nImagePos );
489 }
490 
convertAxPicture(PropertyMap & rPropMap,const StreamDataSequence & rPicData,sal_Int32 nPicSizeMode) const491 void ControlConverter::convertAxPicture( PropertyMap& rPropMap, const StreamDataSequence& rPicData,
492         sal_Int32 nPicSizeMode ) const
493 {
494     // the picture
495     convertPicture( rPropMap, rPicData );
496 
497     // picture scale mode
498     sal_Int16 nScaleMode = ImageScaleMode::NONE;
499     switch( nPicSizeMode )
500     {
501         case AX_PICSIZE_CLIP:       nScaleMode = ImageScaleMode::NONE;          break;
502         case AX_PICSIZE_STRETCH:    nScaleMode = ImageScaleMode::ANISOTROPIC;   break;
503         case AX_PICSIZE_ZOOM:       nScaleMode = ImageScaleMode::ISOTROPIC;     break;
504         default:    OSL_FAIL( "ControlConverter::convertAxPicture - unknown picture size mode" );
505     }
506     rPropMap.setProperty( PROP_ScaleMode, nScaleMode );
507 }
508 
convertAxState(PropertyMap & rPropMap,const OUString & rValue,sal_Int32 nMultiSelect,ApiDefaultStateMode eDefStateMode,bool bAwtModel)509 void ControlConverter::convertAxState( PropertyMap& rPropMap,
510         const OUString& rValue, sal_Int32 nMultiSelect, ApiDefaultStateMode eDefStateMode, bool bAwtModel )
511 {
512     bool bBooleanState = eDefStateMode == API_DEFAULTSTATE_BOOLEAN;
513     bool bSupportsTriState = eDefStateMode == API_DEFAULTSTATE_TRISTATE;
514 
515     // state
516     sal_Int16 nState = bSupportsTriState ? API_STATE_DONTKNOW : API_STATE_UNCHECKED;
517     if( rValue.getLength() == 1 ) switch( rValue[ 0 ] )
518     {
519         case '0':   nState = API_STATE_UNCHECKED;   break;
520         case '1':   nState = API_STATE_CHECKED;     break;
521         // any other string (also empty) means 'dontknow'
522     }
523     sal_Int32 nPropId = bAwtModel ? PROP_State : PROP_DefaultState;
524     if( bBooleanState )
525         rPropMap.setProperty( nPropId, nState != API_STATE_UNCHECKED );
526     else
527         rPropMap.setProperty( nPropId, nState );
528 
529     // tristate
530     if( bSupportsTriState )
531         rPropMap.setProperty( PROP_TriState, nMultiSelect == AX_SELECTION_MULTI );
532 }
533 
convertToAxState(PropertySet const & rPropSet,OUString & rValue,sal_Int32 & nMultiSelect,ApiDefaultStateMode eDefStateMode)534 void ControlConverter::convertToAxState( PropertySet const & rPropSet,
535         OUString& rValue, sal_Int32& nMultiSelect, ApiDefaultStateMode eDefStateMode )
536 {
537     bool bSupportsTriState = eDefStateMode == API_DEFAULTSTATE_TRISTATE;
538 
539     sal_Int16 nState = API_STATE_DONTKNOW;
540 
541     // need to use State for current state ( I think this is regardless of whether
542     // control is awt or not )
543     rPropSet.getProperty( nState, PROP_State );
544 
545     rValue.clear(); // empty e.g. 'don't know'
546     if ( nState == API_STATE_UNCHECKED )
547         rValue = "0";
548     else if ( nState == API_STATE_CHECKED )
549         rValue = "1";
550 
551     // tristate
552     if( bSupportsTriState )
553     {
554         bool bTriStateEnabled = false;
555         bool bPropertyExists = rPropSet.getProperty( bTriStateEnabled, PROP_TriState );
556         if( bPropertyExists && bTriStateEnabled )
557             nMultiSelect = AX_SELECTION_MULTI;
558     }
559 }
560 
convertAxOrientation(PropertyMap & rPropMap,const AxPairData & rSize,sal_Int32 nOrientation)561 void ControlConverter::convertAxOrientation( PropertyMap& rPropMap,
562         const AxPairData& rSize, sal_Int32 nOrientation )
563 {
564     bool bHorizontal = true;
565     switch( nOrientation )
566     {
567         case AX_ORIENTATION_AUTO:       bHorizontal = rSize.first > rSize.second;   break;
568         case AX_ORIENTATION_VERTICAL:   bHorizontal = false;                        break;
569         case AX_ORIENTATION_HORIZONTAL: bHorizontal = true;                         break;
570         default:    OSL_FAIL( "ControlConverter::convertAxOrientation - unknown orientation" );
571     }
572     convertOrientation( rPropMap, bHorizontal );
573 }
574 
convertToAxOrientation(PropertySet const & rPropSet,sal_Int32 & nOrientation)575 void ControlConverter::convertToAxOrientation( PropertySet const & rPropSet,
576         sal_Int32& nOrientation )
577 {
578     bool bHorizontal = true;
579     convertToMSOrientation( rPropSet, bHorizontal );
580 
581     if ( bHorizontal )
582         nOrientation = AX_ORIENTATION_HORIZONTAL;
583     else
584         nOrientation = AX_ORIENTATION_VERTICAL;
585 }
586 
ControlModelBase()587 ControlModelBase::ControlModelBase() :
588     maSize( 0, 0 ),
589     mbAwtModel( false )
590 {
591 }
592 
~ControlModelBase()593 ControlModelBase::~ControlModelBase()
594 {
595 }
596 
getServiceName() const597 OUString ControlModelBase::getServiceName() const
598 {
599     ApiControlType eCtrlType = getControlType();
600     if( mbAwtModel ) switch( eCtrlType )
601     {
602         case API_CONTROL_BUTTON:        return "com.sun.star.awt.UnoControlButtonModel";
603         case API_CONTROL_FIXEDTEXT:     return "com.sun.star.awt.UnoControlFixedTextModel";
604         case API_CONTROL_IMAGE:         return "com.sun.star.awt.UnoControlImageControlModel";
605         case API_CONTROL_CHECKBOX:      return "com.sun.star.awt.UnoControlCheckBoxModel";
606         case API_CONTROL_RADIOBUTTON:   return "com.sun.star.form.component.RadioButton";
607         case API_CONTROL_EDIT:          return "com.sun.star.awt.UnoControlEditModel";
608         case API_CONTROL_NUMERIC:       return "com.sun.star.awt.UnoControlNumericFieldModel";
609         case API_CONTROL_LISTBOX:       return "com.sun.star.form.component.ListBox";
610         case API_CONTROL_COMBOBOX:      return "com.sun.star.form.component.ComboBox";
611         case API_CONTROL_SPINBUTTON:    return "com.sun.star.form.component.SpinButton";
612         case API_CONTROL_SCROLLBAR:     return "com.sun.star.form.component.ScrollBar";
613         case API_CONTROL_PROGRESSBAR:   return "com.sun.star.awt.UnoControlProgressBarModel";
614         case API_CONTROL_GROUPBOX:      return "com.sun.star.form.component.GroupBox";
615         case API_CONTROL_FRAME:         return "com.sun.star.awt.UnoFrameModel";
616         case API_CONTROL_PAGE:          return "com.sun.star.awt.UnoPageModel";
617         case API_CONTROL_MULTIPAGE:     return "com.sun.star.awt.UnoMultiPageModel";
618         case API_CONTROL_DIALOG:        return "com.sun.star.awt.UnoControlDialogModel";
619         default:    OSL_FAIL( "ControlModelBase::getServiceName - no AWT model service supported" );
620     }
621     else switch( eCtrlType )
622     {
623         case API_CONTROL_BUTTON:        return "com.sun.star.form.component.CommandButton";
624         case API_CONTROL_FIXEDTEXT:     return "com.sun.star.form.component.FixedText";
625         case API_CONTROL_IMAGE:         return "com.sun.star.form.component.DatabaseImageControl";
626         case API_CONTROL_CHECKBOX:      return "com.sun.star.form.component.CheckBox";
627         case API_CONTROL_RADIOBUTTON:   return "com.sun.star.form.component.RadioButton";
628         case API_CONTROL_EDIT:          return "com.sun.star.form.component.TextField";
629         case API_CONTROL_NUMERIC:       return "com.sun.star.form.component.NumericField";
630         case API_CONTROL_LISTBOX:       return "com.sun.star.form.component.ListBox";
631         case API_CONTROL_COMBOBOX:      return "com.sun.star.form.component.ComboBox";
632         case API_CONTROL_SPINBUTTON:    return "com.sun.star.form.component.SpinButton";
633         case API_CONTROL_SCROLLBAR:     return "com.sun.star.form.component.ScrollBar";
634         case API_CONTROL_GROUPBOX:      return "com.sun.star.form.component.GroupBox";
635         default:    OSL_FAIL( "ControlModelBase::getServiceName - no form component service supported" );
636     }
637     return OUString();
638 }
639 
importProperty(sal_Int32,const OUString &)640 void ControlModelBase::importProperty( sal_Int32 /*nPropId*/, const OUString& /*rValue*/ )
641 {
642 }
643 
importPictureData(sal_Int32,BinaryInputStream &)644 void ControlModelBase::importPictureData( sal_Int32 /*nPropId*/, BinaryInputStream& /*rInStrm*/ )
645 {
646 }
647 
convertProperties(PropertyMap &,const ControlConverter &) const648 void ControlModelBase::convertProperties( PropertyMap& /*rPropMap*/, const ControlConverter& /*rConv*/ ) const
649 {
650 }
651 
convertFromProperties(PropertySet &,const ControlConverter &)652 void ControlModelBase::convertFromProperties( PropertySet& /*rPropMap*/, const ControlConverter& /*rConv*/ )
653 {
654 }
655 
convertSize(PropertyMap & rPropMap,const ControlConverter & rConv) const656 void ControlModelBase::convertSize( PropertyMap& rPropMap, const ControlConverter& rConv ) const
657 {
658     rConv.convertSize( rPropMap, maSize );
659 }
660 
ComCtlModelBase(sal_uInt32 nDataPartId5,sal_uInt32 nDataPartId6,sal_uInt16 nVersion)661 ComCtlModelBase::ComCtlModelBase( sal_uInt32 nDataPartId5, sal_uInt32 nDataPartId6,
662         sal_uInt16 nVersion ) :
663     maFontData( "Tahoma", 82500 ),
664     mnFlags( 0 ),
665     mnVersion( nVersion ),
666     mnDataPartId5( nDataPartId5 ),
667     mnDataPartId6( nDataPartId6 ),
668     mbCommonPart( true ),
669     mbComplexPart( true )
670 {
671 }
672 
importBinaryModel(BinaryInputStream & rInStrm)673 bool ComCtlModelBase::importBinaryModel( BinaryInputStream& rInStrm )
674 {
675     // read initial size part and header of the control data part
676     if( importSizePart( rInStrm ) && readPartHeader( rInStrm, getDataPartId(), mnVersion ) )
677     {
678         // if flags part exists, the first int32 of the data part contains its size
679         sal_uInt32 nCommonPartSize = 0;
680         if (mbCommonPart)
681             nCommonPartSize = rInStrm.readuInt32();
682         // implementations must read the exact amount of data, stream must point to its end afterwards
683         importControlData( rInStrm );
684         // read following parts
685         if( !rInStrm.isEof() &&
686             (!mbCommonPart || importCommonPart( rInStrm, nCommonPartSize )) &&
687             (!mbComplexPart || importComplexPart( rInStrm )) )
688         {
689             return !rInStrm.isEof();
690         }
691     }
692     return false;
693 }
694 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const695 void ComCtlModelBase::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
696 {
697     if( mbCommonPart )
698         rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, COMCTL_COMMON_ENABLED ) );
699     ControlModelBase::convertProperties( rPropMap, rConv );
700 }
701 
getDataPartId() const702 sal_uInt32 ComCtlModelBase::getDataPartId() const
703 {
704     switch( mnVersion )
705     {
706         case COMCTL_VERSION_50: return mnDataPartId5;
707         case COMCTL_VERSION_60: return mnDataPartId6;
708     }
709     OSL_FAIL( "ComCtlObjectBase::getDataPartId - unexpected version" );
710     return SAL_MAX_UINT32;
711 }
712 
readPartHeader(BinaryInputStream & rInStrm,sal_uInt32 nExpPartId,sal_uInt16 nExpMajor,sal_uInt16 nExpMinor)713 bool ComCtlModelBase::readPartHeader( BinaryInputStream& rInStrm, sal_uInt32 nExpPartId, sal_uInt16 nExpMajor, sal_uInt16 nExpMinor )
714 {
715     // no idea if all this is correct...
716     sal_uInt32 nPartId = rInStrm.readuInt32();
717     sal_uInt16 nMinor = rInStrm.readuInt16();
718     sal_uInt16 nMajor = rInStrm.readuInt16();
719     bool bPartId = nPartId == nExpPartId;
720     OSL_ENSURE( bPartId, "ComCtlObjectBase::readPartHeader - unexpected part identifier" );
721     bool bVersion = ((nExpMajor == SAL_MAX_UINT16) || (nExpMajor == nMajor)) && ((nExpMinor == SAL_MAX_UINT16) || (nExpMinor == nMinor));
722     OSL_ENSURE( bVersion, "ComCtlObjectBase::readPartHeader - unexpected part version" );
723     return !rInStrm.isEof() && bPartId && bVersion;
724 }
725 
importSizePart(BinaryInputStream & rInStrm)726 bool ComCtlModelBase::importSizePart( BinaryInputStream& rInStrm )
727 {
728     if( readPartHeader( rInStrm, COMCTL_ID_SIZE, 0, 8 ) )
729     {
730         maSize.first = rInStrm.readInt32();
731         maSize.second = rInStrm.readInt32();
732         return !rInStrm.isEof();
733     }
734     return false;
735 }
736 
importCommonPart(BinaryInputStream & rInStrm,sal_uInt32 nPartSize)737 bool ComCtlModelBase::importCommonPart( BinaryInputStream& rInStrm, sal_uInt32 nPartSize )
738 {
739     sal_Int64 nEndPos = rInStrm.tell() + nPartSize;
740     if( (nPartSize >= 16) && readPartHeader( rInStrm, COMCTL_ID_COMMONDATA, 5, 0 ) )
741     {
742         rInStrm.skip( 4 );
743         mnFlags = rInStrm.readuInt32();
744         rInStrm.seek( nEndPos );
745         return !rInStrm.isEof();
746     }
747     return false;
748 }
749 
importComplexPart(BinaryInputStream & rInStrm)750 bool ComCtlModelBase::importComplexPart( BinaryInputStream& rInStrm )
751 {
752     if( readPartHeader( rInStrm, COMCTL_ID_COMPLEXDATA, 5, 1 ) )
753     {
754         sal_uInt32 nContFlags = rInStrm.readuInt32();
755         bool bReadOk =
756             (!getFlag( nContFlags, COMCTL_COMPLEX_FONT ) || OleHelper::importStdFont( maFontData, rInStrm, true )) &&
757             (!getFlag( nContFlags, COMCTL_COMPLEX_MOUSEICON ) || OleHelper::importStdPic( maMouseIcon, rInStrm ));
758         return bReadOk && !rInStrm.isEof();
759     }
760     return false;
761 }
762 
ComCtlScrollBarModel(sal_uInt16 nVersion)763 ComCtlScrollBarModel::ComCtlScrollBarModel( sal_uInt16 nVersion ) :
764     ComCtlModelBase( SAL_MAX_UINT32, COMCTL_ID_SCROLLBAR_60, nVersion ),
765     mnScrollBarFlags( 0x00000011 ),
766     mnLargeChange( 1 ),
767     mnSmallChange( 1 ),
768     mnMin( 0 ),
769     mnMax( 32767 ),
770     mnPosition( 0 )
771 {
772 }
773 
getControlType() const774 ApiControlType ComCtlScrollBarModel::getControlType() const
775 {
776     return API_CONTROL_SCROLLBAR;
777 }
778 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const779 void ComCtlScrollBarModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
780 {
781     rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
782     ControlConverter::convertOrientation( rPropMap, getFlag( mnScrollBarFlags, COMCTL_SCROLLBAR_HOR ) );
783     ControlConverter::convertScrollBar( rPropMap, mnMin, mnMax, mnPosition, mnSmallChange, mnLargeChange, mbAwtModel );
784     ComCtlModelBase::convertProperties( rPropMap, rConv );
785 }
786 
importControlData(BinaryInputStream & rInStrm)787 void ComCtlScrollBarModel::importControlData( BinaryInputStream& rInStrm )
788 {
789     mnScrollBarFlags = rInStrm.readuInt32();
790     mnLargeChange = rInStrm.readInt32();
791     mnSmallChange = rInStrm.readInt32();
792     mnMin = rInStrm.readInt32();
793     mnMax = rInStrm.readInt32();
794     mnPosition = rInStrm.readInt32();
795 }
796 
ComCtlProgressBarModel(sal_uInt16 nVersion)797 ComCtlProgressBarModel::ComCtlProgressBarModel( sal_uInt16 nVersion ) :
798     ComCtlModelBase( COMCTL_ID_PROGRESSBAR_50, COMCTL_ID_PROGRESSBAR_60, nVersion ),
799     mfMin( 0.0 ),
800     mfMax( 100.0 ),
801     mnVertical( 0 ),
802     mnSmooth( 0 )
803 {
804 }
805 
getControlType() const806 ApiControlType ComCtlProgressBarModel::getControlType() const
807 {
808     return API_CONTROL_PROGRESSBAR;
809 }
810 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const811 void ComCtlProgressBarModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
812 {
813     sal_uInt16 nBorder = getFlag( mnFlags, COMCTL_COMMON_3DBORDER ) ? API_BORDER_SUNKEN :
814         (getFlag( mnFlags, COMCTL_COMMON_FLATBORDER ) ? API_BORDER_FLAT : API_BORDER_NONE);
815     rPropMap.setProperty( PROP_Border, nBorder );
816     rPropMap.setProperty( PROP_ProgressValueMin, getLimitedValue< sal_Int32, double >( ::std::min( mfMin, mfMax ), 0.0, SAL_MAX_INT32 ) );
817     rPropMap.setProperty( PROP_ProgressValueMax, getLimitedValue< sal_Int32, double >( ::std::max( mfMin, mfMax ), 0.0, SAL_MAX_INT32 ) );
818     // ComCtl model does not provide current value?
819     ComCtlModelBase::convertProperties( rPropMap, rConv );
820 }
821 
importControlData(BinaryInputStream & rInStrm)822 void ComCtlProgressBarModel::importControlData( BinaryInputStream& rInStrm )
823 {
824     mfMin = rInStrm.readFloat();
825     mfMax = rInStrm.readFloat();
826     if( mnVersion == COMCTL_VERSION_60 )
827     {
828         mnVertical = rInStrm.readuInt16();
829         mnSmooth = rInStrm.readuInt16();
830     }
831 }
832 
AxControlModelBase()833 AxControlModelBase::AxControlModelBase()
834 {
835 }
836 
importProperty(sal_Int32 nPropId,const OUString & rValue)837 void AxControlModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
838 {
839     switch( nPropId )
840     {
841         // size of the control shape: format is "width;height"
842         case XML_Size:
843         {
844             sal_Int32 nSepPos = rValue.indexOf( ';' );
845             OSL_ENSURE( nSepPos >= 0, "AxControlModelBase::importProperty - missing separator in 'Size' property" );
846             if( nSepPos >= 0 )
847             {
848                 maSize.first = rValue.copy( 0, nSepPos ).toInt32();
849                 maSize.second = rValue.copy( nSepPos + 1 ).toInt32();
850             }
851         }
852         break;
853     }
854 }
855 
AxFontDataModel(bool bSupportsAlign)856 AxFontDataModel::AxFontDataModel( bool bSupportsAlign ) :
857     mbSupportsAlign( bSupportsAlign )
858 {
859 }
860 
importProperty(sal_Int32 nPropId,const OUString & rValue)861 void AxFontDataModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
862 {
863     switch( nPropId )
864     {
865         case XML_FontName:          maFontData.maFontName = rValue;                                             break;
866         case XML_FontEffects:
867             maFontData.mnFontEffects = static_cast<AxFontFlags>(AttributeConversion::decodeUnsigned( rValue ));
868             break;
869         case XML_FontHeight:        maFontData.mnFontHeight = AttributeConversion::decodeInteger( rValue );     break;
870         case XML_FontCharSet:       maFontData.mnFontCharSet = AttributeConversion::decodeInteger( rValue );    break;
871         case XML_ParagraphAlign:
872             maFontData.mnHorAlign = static_cast<AxHorizontalAlign>(AttributeConversion::decodeInteger( rValue ));
873             break;
874         default:                    AxControlModelBase::importProperty( nPropId, rValue );
875     }
876 }
877 
importBinaryModel(BinaryInputStream & rInStrm)878 bool AxFontDataModel::importBinaryModel( BinaryInputStream& rInStrm )
879 {
880     return maFontData.importBinaryModel( rInStrm );
881 }
882 
exportBinaryModel(BinaryOutputStream & rOutStrm)883 void AxFontDataModel::exportBinaryModel( BinaryOutputStream& rOutStrm )
884 {
885     maFontData.exportBinaryModel( rOutStrm );
886 }
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const887 void AxFontDataModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
888 {
889     // font name
890     if( !maFontData.maFontName.isEmpty() )
891         rPropMap.setProperty( PROP_FontName, maFontData.maFontName );
892 
893     // font effects
894     rPropMap.setProperty( PROP_FontWeight, maFontData.mnFontEffects & AxFontFlags::Bold ? awt::FontWeight::BOLD : awt::FontWeight::NORMAL );
895     rPropMap.setProperty( PROP_FontSlant, maFontData.mnFontEffects & AxFontFlags::Italic ? FontSlant_ITALIC : FontSlant_NONE );
896     if (maFontData.mnFontEffects & AxFontFlags::Underline)
897         rPropMap.setProperty( PROP_FontUnderline, maFontData.mbDblUnderline ? awt::FontUnderline::DOUBLE : awt::FontUnderline::SINGLE );
898     else
899         rPropMap.setProperty( PROP_FontUnderline, awt::FontUnderline::NONE );
900     rPropMap.setProperty( PROP_FontStrikeout, maFontData.mnFontEffects & AxFontFlags::Strikeout ? awt::FontStrikeout::SINGLE : awt::FontStrikeout::NONE );
901     rPropMap.setProperty( PROP_FontHeight, maFontData.getHeightPoints() );
902 
903     // font character set
904     rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
905     if( (0 <= maFontData.mnFontCharSet) && (maFontData.mnFontCharSet <= SAL_MAX_UINT8) )
906         eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( maFontData.mnFontCharSet ) );
907     if( eFontEnc != RTL_TEXTENCODING_DONTKNOW )
908         rPropMap.setProperty( PROP_FontCharset, static_cast< sal_Int16 >( eFontEnc ) );
909 
910     // text alignment
911     if( mbSupportsAlign )
912     {
913         sal_Int32 nAlign = awt::TextAlign::LEFT;
914         switch( maFontData.mnHorAlign )
915         {
916             case AxHorizontalAlign::Left:      nAlign = awt::TextAlign::LEFT;   break;
917             case AxHorizontalAlign::Right:     nAlign = awt::TextAlign::RIGHT;  break;
918             case AxHorizontalAlign::Center:    nAlign = awt::TextAlign::CENTER; break;
919             default:    OSL_FAIL( "AxFontDataModel::convertProperties - unknown text alignment" );
920         }
921         // form controls expect short value
922         rPropMap.setProperty( PROP_Align, static_cast< sal_Int16 >( nAlign ) );
923     }
924 
925     // process base class properties
926     AxControlModelBase::convertProperties( rPropMap, rConv );
927 }
928 
convertFromProperties(PropertySet & rPropSet,const ControlConverter &)929 void AxFontDataModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& /*rConv */)
930 {
931     rPropSet.getProperty( maFontData.maFontName, PROP_FontName );
932     float fontWeight = float(0);
933     if ( rPropSet.getProperty(fontWeight, PROP_FontWeight ) )
934         setFlag( maFontData.mnFontEffects, AxFontFlags::Bold, ( fontWeight == awt::FontWeight::BOLD ) );
935     FontSlant nSlant = FontSlant_NONE;
936     if ( rPropSet.getProperty( nSlant, PROP_FontSlant ) )
937         setFlag( maFontData.mnFontEffects, AxFontFlags::Italic, ( nSlant == FontSlant_ITALIC ) );
938 
939     sal_Int16 nUnderLine = awt::FontUnderline::NONE;
940     if ( rPropSet.getProperty( nUnderLine, PROP_FontUnderline ) )
941         setFlag( maFontData.mnFontEffects, AxFontFlags::Underline, nUnderLine != awt::FontUnderline::NONE && nUnderLine != awt::FontUnderline::DONTKNOW);
942     sal_Int16 nStrikeout = awt::FontStrikeout::NONE ;
943     if ( rPropSet.getProperty( nStrikeout, PROP_FontStrikeout ) )
944         setFlag( maFontData.mnFontEffects, AxFontFlags::Strikeout, nStrikeout != awt::FontStrikeout::NONE && nStrikeout != awt::FontStrikeout::DONTKNOW);
945 
946     float fontHeight = 0.0;
947     if ( rPropSet.getProperty( fontHeight, PROP_FontHeight ) )
948     {
949         if ( fontHeight == 0 )  // tdf#118684
950         {
951             vcl::Font aDefaultVCLFont = Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetAppFont();
952             fontHeight = static_cast< float >( aDefaultVCLFont.GetFontHeight() );
953         }
954         maFontData.setHeightPoints( static_cast< sal_Int16 >( fontHeight ) );
955     }
956 
957     // TODO - handle textencoding
958     sal_Int16 nAlign = 0;
959     if ( rPropSet.getProperty( nAlign, PROP_Align ) )
960     {
961         switch ( nAlign )
962         {
963             case awt::TextAlign::LEFT: maFontData.mnHorAlign = AxHorizontalAlign::Left;   break;
964             case awt::TextAlign::RIGHT: maFontData.mnHorAlign = AxHorizontalAlign::Right;  break;
965             case awt::TextAlign::CENTER: maFontData.mnHorAlign = AxHorizontalAlign::Center; break;
966             default:    OSL_FAIL( "AxFontDataModel::convertFromProperties - unknown text alignment" );
967         }
968     }
969 }
970 
AxCommandButtonModel()971 AxCommandButtonModel::AxCommandButtonModel() :
972     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
973     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
974     mnFlags( AX_CMDBUTTON_DEFFLAGS ),
975     mnPicturePos( AX_PICPOS_ABOVECENTER ),
976     mnVerticalAlign( XML_Center ),
977     mbFocusOnClick( true )
978 {
979 }
980 
importProperty(sal_Int32 nPropId,const OUString & rValue)981 void AxCommandButtonModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
982 {
983     switch( nPropId )
984     {
985         case XML_Caption:               maCaption = rValue;                                                 break;
986         case XML_ForeColor:             mnTextColor = AttributeConversion::decodeUnsigned( rValue );        break;
987         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );        break;
988         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );            break;
989         case XML_PicturePosition:       mnPicturePos = AttributeConversion::decodeUnsigned( rValue );       break;
990         case XML_TakeFocusOnClick:      mbFocusOnClick = AttributeConversion::decodeInteger( rValue ) != 0; break;
991         default:                        AxFontDataModel::importProperty( nPropId, rValue );
992     }
993 }
994 
importPictureData(sal_Int32 nPropId,BinaryInputStream & rInStrm)995 void AxCommandButtonModel::importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm )
996 {
997     switch( nPropId )
998     {
999         case XML_Picture:   OleHelper::importStdPic( maPictureData, rInStrm );    break;
1000         default:            AxFontDataModel::importPictureData( nPropId, rInStrm );
1001     }
1002 }
1003 
importBinaryModel(BinaryInputStream & rInStrm)1004 bool AxCommandButtonModel::importBinaryModel( BinaryInputStream& rInStrm )
1005 {
1006     AxBinaryPropertyReader aReader( rInStrm );
1007     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
1008     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1009     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1010     aReader.readStringProperty( maCaption );
1011     aReader.readIntProperty< sal_uInt32 >( mnPicturePos );
1012     aReader.readPairProperty( maSize );
1013     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1014     aReader.readPictureProperty( maPictureData );
1015     aReader.skipIntProperty< sal_uInt16 >(); // accelerator
1016     aReader.readBoolProperty( mbFocusOnClick, true ); // binary flag means "do not take focus"
1017     aReader.skipPictureProperty(); // mouse icon
1018     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
1019 }
1020 
exportBinaryModel(BinaryOutputStream & rOutStrm)1021 void AxCommandButtonModel::exportBinaryModel( BinaryOutputStream& rOutStrm )
1022 {
1023     AxBinaryPropertyWriter aWriter( rOutStrm );
1024     aWriter.writeIntProperty< sal_uInt32 >( mnTextColor );
1025     if ( mnBackColor )
1026         aWriter.writeIntProperty< sal_uInt32 >( mnBackColor );
1027     else
1028         aWriter.skipProperty(); // default backcolour
1029     aWriter.writeIntProperty< sal_uInt32 >( mnFlags );
1030     aWriter.writeStringProperty( maCaption );
1031     aWriter.skipProperty(); // pict pos
1032     aWriter.writePairProperty( maSize );
1033     aWriter.skipProperty(); // mouse pointer
1034     aWriter.skipProperty(); // picture data
1035     aWriter.skipProperty(); // accelerator
1036     aWriter.writeBoolProperty( mbFocusOnClick ); // binary flag means "do not take focus"
1037     aWriter.skipProperty(); // mouse icon
1038     aWriter.finalizeExport();
1039     AxFontDataModel::exportBinaryModel( rOutStrm );
1040 }
1041 
exportCompObj(BinaryOutputStream & rOutStream)1042 void AxCommandButtonModel::exportCompObj( BinaryOutputStream& rOutStream )
1043 {
1044     // should be able to replace this hardcoded foo with
1045     // proper export info from MS-OLEDS spec.
1046     static sal_uInt8 const aCompObj[] = {
1047         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1048         0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x32, 0x05, 0xD7,
1049         0x69, 0xCE, 0xCD, 0x11, 0xA7, 0x77, 0x00, 0xDD,
1050         0x01, 0x14, 0x3C, 0x57, 0x22, 0x00, 0x00, 0x00,
1051         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1052         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6d, 0x73, 0x20,
1053         0x32, 0x2e, 0x30, 0x20, 0x43, 0x6F, 0x6D, 0x6D,
1054         0x61, 0x6E, 0x64, 0x42, 0x75, 0x74, 0x74, 0x6F,
1055         0x6E, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
1056         0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
1057         0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x16, 0x00,
1058         0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
1059         0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x42,
1060         0x75, 0x74, 0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00,
1061         0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
1062         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1063     };
1064     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1065 }
1066 
getControlType() const1067 ApiControlType AxCommandButtonModel::getControlType() const
1068 {
1069     return API_CONTROL_BUTTON;
1070 }
1071 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1072 void AxCommandButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1073 {
1074     rPropMap.setProperty( PROP_Label, maCaption );
1075     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1076     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1077     rPropMap.setProperty( PROP_FocusOnClick, mbFocusOnClick );
1078     rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
1079     ControlConverter::convertVerticalAlign( rPropMap, mnVerticalAlign );
1080     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::NotSupported );
1081     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1082     AxFontDataModel::convertProperties( rPropMap, rConv );
1083 }
1084 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1085 void AxCommandButtonModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1086 {
1087     (void)rPropSet.getProperty(maCaption, PROP_Label);
1088     bool bRes = false;
1089     if ( rPropSet.getProperty( bRes, PROP_Enabled ) )
1090         setFlag( mnFlags, AX_FLAGS_ENABLED, bRes );
1091     if ( rPropSet.getProperty( bRes,  PROP_MultiLine ) )
1092         setFlag( mnFlags, AX_FLAGS_WORDWRAP, bRes );
1093     (void)rPropSet.getProperty(mbFocusOnClick, PROP_FocusOnClick);
1094 
1095     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1096     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
1097 
1098     AxFontDataModel::convertFromProperties( rPropSet, rConv );
1099 }
1100 
AxLabelModel()1101 AxLabelModel::AxLabelModel() :
1102     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
1103     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
1104     mnFlags( AX_LABEL_DEFFLAGS ),
1105     mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
1106     mnBorderStyle( AX_BORDERSTYLE_NONE ),
1107     mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
1108     mnVerticalAlign( XML_Top )
1109 {
1110 }
1111 
importProperty(sal_Int32 nPropId,const OUString & rValue)1112 void AxLabelModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
1113 {
1114     switch( nPropId )
1115     {
1116         case XML_Caption:               maCaption = rValue;                                             break;
1117         case XML_ForeColor:             mnTextColor = AttributeConversion::decodeUnsigned( rValue );    break;
1118         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
1119         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
1120         case XML_BorderColor:           mnBorderColor = AttributeConversion::decodeUnsigned( rValue );  break;
1121         case XML_BorderStyle:           mnBorderStyle = AttributeConversion::decodeInteger( rValue );   break;
1122         case XML_SpecialEffect:         mnSpecialEffect = AttributeConversion::decodeInteger( rValue ); break;
1123         default:                        AxFontDataModel::importProperty( nPropId, rValue );
1124     }
1125 }
1126 
importBinaryModel(BinaryInputStream & rInStrm)1127 bool AxLabelModel::importBinaryModel( BinaryInputStream& rInStrm )
1128 {
1129     AxBinaryPropertyReader aReader( rInStrm );
1130     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
1131     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1132     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1133     aReader.readStringProperty( maCaption );
1134     aReader.skipIntProperty< sal_uInt32 >(); // picture position
1135     aReader.readPairProperty( maSize );
1136     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1137     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
1138     aReader.readIntProperty< sal_uInt16 >( mnBorderStyle );
1139     aReader.readIntProperty< sal_uInt16 >( mnSpecialEffect );
1140     aReader.skipPictureProperty(); // picture
1141     aReader.skipIntProperty< sal_uInt16 >(); // accelerator
1142     aReader.skipPictureProperty(); // mouse icon
1143     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
1144 }
1145 
exportBinaryModel(BinaryOutputStream & rOutStrm)1146 void AxLabelModel::exportBinaryModel( BinaryOutputStream& rOutStrm )
1147 {
1148     AxBinaryPropertyWriter aWriter( rOutStrm );
1149     aWriter.writeIntProperty< sal_uInt32 >( mnTextColor );
1150     if ( mnBackColor )
1151         aWriter.writeIntProperty< sal_uInt32 >( mnBackColor );
1152     else
1153         // if mnBackColor == 0 then it's the libreoffice default backcolour is
1154         // the MSO Label default which is AX_SYSCOLOR_BUTTONFACE
1155         aWriter.writeIntProperty< sal_uInt32 >( AX_SYSCOLOR_WINDOWBACK );
1156     aWriter.writeIntProperty< sal_uInt32 >( mnFlags );
1157     aWriter.writeStringProperty( maCaption );
1158     aWriter.skipProperty(); // picture position
1159     aWriter.writePairProperty( maSize );
1160     aWriter.skipProperty(); // mouse pointer
1161     aWriter.writeIntProperty< sal_uInt32 >( mnBorderColor );
1162     aWriter.writeIntProperty< sal_uInt16 >( mnBorderStyle );
1163     aWriter.writeIntProperty< sal_uInt16 >( mnSpecialEffect );
1164     aWriter.skipProperty(); // picture
1165     aWriter.skipProperty(); // accelerator
1166     aWriter.skipProperty(); // mouse icon
1167     aWriter.finalizeExport();
1168     AxFontDataModel::exportBinaryModel( rOutStrm );
1169 }
1170 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1171 void AxLabelModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1172 {
1173     rPropSet.getProperty( maCaption, PROP_Label );
1174     bool bRes = false;
1175     if ( rPropSet.getProperty( bRes, PROP_Enabled ) )
1176         setFlag( mnFlags, AX_FLAGS_ENABLED, bRes );
1177     if ( rPropSet.getProperty( bRes,  PROP_MultiLine ) )
1178         setFlag( mnFlags, AX_FLAGS_WORDWRAP, bRes );
1179 
1180     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1181     // VerticalAlign doesn't seem to be read from binary
1182 
1183     // not sure about background color, how do we decide when to set
1184     // AX_FLAGS_OPAQUE ?
1185     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor  );
1186     ControlConverter::convertToAxBorder( rPropSet, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1187 
1188     AxFontDataModel::convertFromProperties( rPropSet, rConv );
1189 }
1190 
exportCompObj(BinaryOutputStream & rOutStream)1191 void AxLabelModel::exportCompObj( BinaryOutputStream& rOutStream )
1192 {
1193     // should be able to replace this hardcoded foo with
1194     // proper export info from MS-OLEDS spec.
1195     static sal_uInt8 const aCompObj[] = {
1196         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1197         0xFF, 0xFF, 0xFF, 0xFF, 0x23, 0x9E, 0x8C, 0x97,
1198         0xB0, 0xD4, 0xCE, 0x11, 0xBF, 0x2D, 0x00, 0xAA,
1199         0x00, 0x3F, 0x40, 0xD0, 0x1A, 0x00, 0x00, 0x00,
1200         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1201         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1202         0x32, 0x2E, 0x30, 0x20, 0x4C, 0x61, 0x62, 0x65,
1203         0x6C, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
1204         0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
1205         0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x0E, 0x00,
1206         0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
1207         0x4C, 0x61, 0x62, 0x65, 0x6C, 0x2E, 0x31, 0x00,
1208         0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
1209         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1210     };
1211     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1212 }
1213 
getControlType() const1214 ApiControlType AxLabelModel::getControlType() const
1215 {
1216     return API_CONTROL_FIXEDTEXT;
1217 }
1218 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1219 void AxLabelModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1220 {
1221     rPropMap.setProperty( PROP_Label, maCaption );
1222     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1223     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1224     rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
1225     ControlConverter::convertVerticalAlign( rPropMap, mnVerticalAlign );
1226     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1227     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1228     AxFontDataModel::convertProperties( rPropMap, rConv );
1229 }
1230 
AxImageModel()1231 AxImageModel::AxImageModel() :
1232     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
1233     mnFlags( AX_IMAGE_DEFFLAGS ),
1234     mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
1235     mnBorderStyle( AX_BORDERSTYLE_SINGLE ),
1236     mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
1237     mnPicSizeMode( AX_PICSIZE_CLIP ),
1238     mnPicAlign( AX_PICALIGN_CENTER ),
1239     mbPicTiling( false )
1240 {
1241 }
1242 
importProperty(sal_Int32 nPropId,const OUString & rValue)1243 void AxImageModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
1244 {
1245     switch( nPropId )
1246     {
1247         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );      break;
1248         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );          break;
1249         case XML_BorderColor:           mnBorderColor = AttributeConversion::decodeUnsigned( rValue );    break;
1250         case XML_BorderStyle:           mnBorderStyle = AttributeConversion::decodeInteger( rValue );     break;
1251         case XML_SpecialEffect:         mnSpecialEffect = AttributeConversion::decodeInteger( rValue );   break;
1252         case XML_SizeMode:              mnPicSizeMode = AttributeConversion::decodeInteger( rValue );     break;
1253         case XML_PictureAlignment:      mnPicAlign = AttributeConversion::decodeInteger( rValue );        break;
1254         case XML_PictureTiling:         mbPicTiling = AttributeConversion::decodeInteger( rValue ) != 0;  break;
1255         default:                        AxControlModelBase::importProperty( nPropId, rValue );
1256     }
1257 }
1258 
importPictureData(sal_Int32 nPropId,BinaryInputStream & rInStrm)1259 void AxImageModel::importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm )
1260 {
1261     switch( nPropId )
1262     {
1263         case XML_Picture:   OleHelper::importStdPic( maPictureData, rInStrm );    break;
1264         default:            AxControlModelBase::importPictureData( nPropId, rInStrm );
1265     }
1266 }
1267 
importBinaryModel(BinaryInputStream & rInStrm)1268 bool AxImageModel::importBinaryModel( BinaryInputStream& rInStrm )
1269 {
1270     AxBinaryPropertyReader aReader( rInStrm );
1271     aReader.skipUndefinedProperty();
1272     aReader.skipUndefinedProperty();
1273     aReader.skipBoolProperty(); // auto-size
1274     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
1275     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1276     aReader.readIntProperty< sal_uInt8 >( mnBorderStyle );
1277     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1278     aReader.readIntProperty< sal_uInt8 >( mnPicSizeMode );
1279     aReader.readIntProperty< sal_uInt8 >( mnSpecialEffect );
1280     aReader.readPairProperty( maSize );
1281     aReader.readPictureProperty( maPictureData );
1282     aReader.readIntProperty< sal_uInt8 >( mnPicAlign );
1283     aReader.readBoolProperty( mbPicTiling );
1284     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1285     aReader.skipPictureProperty(); // mouse icon
1286     return aReader.finalizeImport();
1287 }
1288 
exportBinaryModel(BinaryOutputStream & rOutStrm)1289 void AxImageModel::exportBinaryModel( BinaryOutputStream& rOutStrm )
1290 {
1291     AxBinaryPropertyWriter aWriter( rOutStrm );
1292     aWriter.skipProperty(); //undefined
1293     aWriter.skipProperty(); //undefined
1294     aWriter.skipProperty(); //auto-size
1295     aWriter.writeIntProperty< sal_uInt32 >( mnBorderColor );
1296     if ( mnBackColor )
1297         aWriter.writeIntProperty< sal_uInt32 >( mnBackColor );
1298     else
1299         aWriter.skipProperty(); // default backcolour
1300     aWriter.writeIntProperty< sal_uInt8 >( mnBorderStyle );
1301     aWriter.skipProperty(); // mouse pointer
1302     aWriter.writeIntProperty< sal_uInt8 >( mnPicSizeMode );
1303     aWriter.writeIntProperty< sal_uInt8 >( mnSpecialEffect );
1304     aWriter.writePairProperty( maSize );
1305     aWriter.skipProperty(); //maPictureData );
1306     aWriter.writeIntProperty< sal_uInt8 >( mnPicAlign );
1307     aWriter.writeBoolProperty( mbPicTiling );
1308     aWriter.writeIntProperty< sal_uInt32 >( mnFlags );
1309     aWriter.skipProperty(); // mouse icon
1310     aWriter.finalizeExport();
1311 }
1312 
exportCompObj(BinaryOutputStream & rOutStream)1313 void AxImageModel::exportCompObj( BinaryOutputStream& rOutStream )
1314 {
1315     // should be able to replace this hardcoded foo with
1316     // proper export info from MS-OLEDS spec.
1317     static sal_uInt8 const aCompObj[] = {
1318         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1319         0xFF, 0xFF, 0xFF, 0xFF, 0x41, 0x92, 0x59, 0x4C,
1320         0x26, 0x69, 0x1B, 0x10, 0x99, 0x92, 0x00, 0x00,
1321         0x0B, 0x65, 0xC6, 0xF9, 0x1A, 0x00, 0x00, 0x00,
1322         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1323         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1324         0x32, 0x2E, 0x30, 0x20, 0x49, 0x6D, 0x61, 0x67,
1325         0x65, 0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D,
1326         0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F,
1327         0x62, 0x6A, 0x65, 0x63, 0x74, 0x00, 0x0E, 0x00,
1328         0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E,
1329         0x49, 0x6D, 0x61, 0x67, 0x65, 0x2E, 0x31, 0x00,
1330         0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
1331         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1332     };
1333     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1334 }
1335 
getControlType() const1336 ApiControlType AxImageModel::getControlType() const
1337 {
1338     return API_CONTROL_IMAGE;
1339 }
1340 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1341 void AxImageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1342 {
1343     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1344     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1345     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1346     rConv.convertAxPicture( rPropMap, maPictureData, mnPicSizeMode );
1347     AxControlModelBase::convertProperties( rPropMap, rConv );
1348 }
1349 
AxTabStripModel()1350 AxTabStripModel::AxTabStripModel() :
1351     mnListIndex( 0 ),
1352     mnTabStyle( 0 ),
1353     mnTabData( 0 ),
1354     mnVariousPropertyBits( 0 )
1355 {
1356 }
1357 
importBinaryModel(BinaryInputStream & rInStrm)1358 bool AxTabStripModel::importBinaryModel( BinaryInputStream& rInStrm )
1359 {
1360     // not worth reading much here, basically we are interested
1361     // in whether we have tabs, the width, the height and the
1362     // captions, everything else we can pretty much discard ( for now )
1363     AxBinaryPropertyReader aReader( rInStrm );
1364     aReader.readIntProperty< sal_uInt32 >( mnListIndex ); // ListIndex
1365     aReader.skipIntProperty< sal_uInt32 >(); // Backcolor
1366     aReader.skipIntProperty< sal_uInt32 >(); // ForeColor
1367     aReader.skipUndefinedProperty();
1368     aReader.readPairProperty( maSize );
1369     aReader.readArrayStringProperty( maItems );
1370     aReader.skipIntProperty< sal_uInt8 >();  // MousePointer
1371     aReader.skipUndefinedProperty();
1372     aReader.skipIntProperty< sal_uInt32 >(); // TabOrientation
1373     aReader.readIntProperty< sal_uInt32 >(mnTabStyle); // TabStyle
1374     aReader.skipBoolProperty();              // MultiRow
1375     aReader.skipIntProperty< sal_uInt32 >(); // TabFixedWidth
1376     aReader.skipIntProperty< sal_uInt32 >(); // TabFixedHeight
1377     aReader.skipBoolProperty();              // ToolTips
1378     aReader.skipUndefinedProperty();
1379     aReader.skipArrayStringProperty();  // ToolTip strings
1380     aReader.skipUndefinedProperty();
1381     aReader.readArrayStringProperty( maTabNames ); // Tab names
1382     aReader.readIntProperty< sal_uInt32 >(mnVariousPropertyBits); // VariousPropertyBits
1383     aReader.skipBoolProperty();// NewVersion
1384     aReader.skipIntProperty< sal_uInt32 >(); // TabsAllocated
1385     aReader.skipArrayStringProperty();  // Tags
1386     aReader.readIntProperty<sal_uInt32 >(mnTabData);  // TabData
1387     aReader.skipArrayStringProperty();  // Accelerators
1388     aReader.skipPictureProperty(); // Mouse Icon
1389     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
1390 }
1391 
getControlType() const1392 ApiControlType AxTabStripModel::getControlType() const
1393 {
1394     return API_CONTROL_TABSTRIP;
1395 }
1396 
AxMorphDataModelBase()1397 AxMorphDataModelBase::AxMorphDataModelBase() :
1398     mnTextColor( AX_SYSCOLOR_WINDOWTEXT ),
1399     mnBackColor( AX_SYSCOLOR_WINDOWBACK ),
1400     mnFlags( AX_MORPHDATA_DEFFLAGS ),
1401     mnPicturePos( AX_PICPOS_ABOVECENTER ),
1402     mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
1403     mnBorderStyle( AX_BORDERSTYLE_NONE ),
1404     mnSpecialEffect( AX_SPECIALEFFECT_SUNKEN ),
1405     mnDisplayStyle( AX_DISPLAYSTYLE_TEXT ),
1406     mnMultiSelect( AX_SELECTION_SINGLE ),
1407     mnScrollBars( AX_SCROLLBAR_NONE ),
1408     mnMatchEntry( AX_MATCHENTRY_NONE ),
1409     mnShowDropButton( AX_SHOWDROPBUTTON_NEVER ),
1410     mnMaxLength( 0 ),
1411     mnPasswordChar( 0 ),
1412     mnListRows( 8 ),
1413     mnVerticalAlign( XML_Center )
1414 {
1415 }
1416 
importProperty(sal_Int32 nPropId,const OUString & rValue)1417 void AxMorphDataModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
1418 {
1419     switch( nPropId )
1420     {
1421         case XML_Caption:               maCaption = rValue;                                             break;
1422         case XML_Value:                 maValue = rValue;                                               break;
1423         case XML_GroupName:             maGroupName = rValue;                                           break;
1424         case XML_ForeColor:             mnTextColor = AttributeConversion::decodeUnsigned( rValue );    break;
1425         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
1426         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
1427         case XML_PicturePosition:       mnPicturePos = AttributeConversion::decodeUnsigned( rValue );   break;
1428         case XML_BorderColor:           mnBorderColor = AttributeConversion::decodeUnsigned( rValue );  break;
1429         case XML_BorderStyle:           mnBorderStyle = AttributeConversion::decodeInteger( rValue );   break;
1430         case XML_SpecialEffect:         mnSpecialEffect = AttributeConversion::decodeInteger( rValue ); break;
1431         case XML_DisplayStyle:          mnDisplayStyle = AttributeConversion::decodeInteger( rValue );  break;
1432         case XML_MultiSelect:           mnMultiSelect = AttributeConversion::decodeInteger( rValue );   break;
1433         case XML_ScrollBars:            mnScrollBars = AttributeConversion::decodeInteger( rValue );    break;
1434         case XML_MatchEntry:            mnMatchEntry = AttributeConversion::decodeInteger( rValue );    break;
1435         case XML_ShowDropButtonWhen:    mnShowDropButton = AttributeConversion::decodeInteger( rValue );break;
1436         case XML_MaxLength:             mnMaxLength = AttributeConversion::decodeInteger( rValue );     break;
1437         case XML_PasswordChar:          mnPasswordChar = AttributeConversion::decodeInteger( rValue );  break;
1438         case XML_ListRows:              mnListRows = AttributeConversion::decodeInteger( rValue );      break;
1439         default:                        AxFontDataModel::importProperty( nPropId, rValue );
1440     }
1441 }
1442 
importPictureData(sal_Int32 nPropId,BinaryInputStream & rInStrm)1443 void AxMorphDataModelBase::importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm )
1444 {
1445     switch( nPropId )
1446     {
1447         case XML_Picture:   OleHelper::importStdPic( maPictureData, rInStrm );    break;
1448         default:            AxFontDataModel::importPictureData( nPropId, rInStrm );
1449     }
1450 }
1451 
importBinaryModel(BinaryInputStream & rInStrm)1452 bool AxMorphDataModelBase::importBinaryModel( BinaryInputStream& rInStrm )
1453 {
1454     AxBinaryPropertyReader aReader( rInStrm, true );
1455     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1456     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1457     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
1458     aReader.readIntProperty< sal_Int32 >( mnMaxLength );
1459     aReader.readIntProperty< sal_uInt8 >( mnBorderStyle );
1460     aReader.readIntProperty< sal_uInt8 >( mnScrollBars );
1461     aReader.readIntProperty< sal_uInt8 >( mnDisplayStyle );
1462     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1463     aReader.readPairProperty( maSize );
1464     aReader.readIntProperty< sal_uInt16 >( mnPasswordChar );
1465     aReader.skipIntProperty< sal_uInt32 >(); // list width
1466     aReader.skipIntProperty< sal_uInt16 >(); // bound column
1467     aReader.skipIntProperty< sal_Int16 >(); // text column
1468     aReader.skipIntProperty< sal_Int16 >(); // column count
1469     aReader.readIntProperty< sal_uInt16 >( mnListRows );
1470     aReader.skipIntProperty< sal_uInt16 >(); // column info count
1471     aReader.readIntProperty< sal_uInt8 >( mnMatchEntry );
1472     aReader.skipIntProperty< sal_uInt8 >(); // list style
1473     aReader.readIntProperty< sal_uInt8 >( mnShowDropButton );
1474     aReader.skipUndefinedProperty();
1475     aReader.skipIntProperty< sal_uInt8 >(); // drop down style
1476     aReader.readIntProperty< sal_uInt8 >( mnMultiSelect );
1477     aReader.readStringProperty( maValue );
1478     aReader.readStringProperty( maCaption );
1479     aReader.readIntProperty< sal_uInt32 >( mnPicturePos );
1480     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
1481     aReader.readIntProperty< sal_uInt32 >( mnSpecialEffect );
1482     aReader.skipPictureProperty(); // mouse icon
1483     aReader.readPictureProperty( maPictureData );
1484     aReader.skipIntProperty< sal_uInt16 >(); // accelerator
1485     aReader.skipUndefinedProperty();
1486     aReader.skipBoolProperty();
1487     aReader.readStringProperty( maGroupName );
1488     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
1489 }
1490 
exportBinaryModel(BinaryOutputStream & rOutStrm)1491 void AxMorphDataModelBase::exportBinaryModel( BinaryOutputStream& rOutStrm )
1492 {
1493     AxBinaryPropertyWriter aWriter( rOutStrm, true );
1494     if ( mnFlags != AX_MORPHDATA_DEFFLAGS )
1495         aWriter.writeIntProperty< sal_uInt32 >( mnFlags );
1496     else
1497         aWriter.skipProperty(); //mnFlags
1498     if ( mnBackColor )
1499         aWriter.writeIntProperty< sal_uInt32 >( mnBackColor );
1500     else
1501         aWriter.skipProperty(); // default backcolour
1502     aWriter.writeIntProperty< sal_uInt32 >( mnTextColor );
1503 
1504     // only write if different from default
1505     if ( ( ( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT ) || ( mnDisplayStyle == AX_DISPLAYSTYLE_COMBOBOX ) ) && mnMaxLength != 0 )
1506         aWriter.writeIntProperty< sal_Int32 >( mnMaxLength );
1507     else
1508         aWriter.skipProperty(); //mnMaxLength
1509     if ( ( ( mnDisplayStyle == AX_DISPLAYSTYLE_COMBOBOX ) || ( mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX ) || ( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT ) ) && mnBorderStyle != AX_BORDERSTYLE_NONE )
1510         aWriter.writeIntProperty< sal_uInt8 >( mnBorderStyle );
1511     else
1512         aWriter.skipProperty(); //mnBorderStyle
1513 
1514     if ( ( mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX || mnDisplayStyle == AX_DISPLAYSTYLE_TEXT ) && mnScrollBars != AX_SCROLLBAR_NONE )
1515         aWriter.writeIntProperty< sal_uInt8 >( mnScrollBars );
1516     else
1517         aWriter.skipProperty(); //mnScrollBars
1518     aWriter.writeIntProperty< sal_uInt8 >( mnDisplayStyle );
1519     aWriter.skipProperty(); // mouse pointer
1520     aWriter.writePairProperty( maSize );
1521     if  ( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT )
1522         aWriter.writeIntProperty< sal_uInt16 >( mnPasswordChar );
1523     else
1524         aWriter.skipProperty(); // mnPasswordChar
1525     aWriter.skipProperty(); // list width
1526     aWriter.skipProperty(); // bound column
1527     aWriter.skipProperty(); // text column
1528     aWriter.skipProperty(); // column count
1529     aWriter.skipProperty(); // mnListRows
1530     aWriter.skipProperty(); // column info count
1531     aWriter.skipProperty(); // mnMatchEntry
1532     aWriter.skipProperty(); // list style
1533     aWriter.skipProperty(); // mnShowDropButton );
1534     aWriter.skipProperty();
1535     aWriter.skipProperty(); // drop down style
1536     if ( (mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX || mnDisplayStyle == AX_DISPLAYSTYLE_CHECKBOX) && mnMultiSelect != AX_SELECTION_SINGLE )
1537         aWriter.writeIntProperty< sal_uInt8 >( mnMultiSelect );
1538     // although CheckBox, ListBox, OptionButton, ToggleButton are also supported
1539     // they can only have the fileformat default
1540     else
1541         aWriter.skipProperty(); //mnMultiSelect
1542     aWriter.writeStringProperty( maValue );
1543 
1544     if ( ( mnDisplayStyle == AX_DISPLAYSTYLE_CHECKBOX ) || ( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON ) || ( mnDisplayStyle == AX_DISPLAYSTYLE_TOGGLE ) )
1545         aWriter.writeStringProperty( maCaption );
1546     else
1547         aWriter.skipProperty(); // mnCaption
1548     aWriter.skipProperty(); // mnPicturePos );
1549     if ( ( mnDisplayStyle == AX_DISPLAYSTYLE_COMBOBOX || mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX ||  mnDisplayStyle == AX_DISPLAYSTYLE_TEXT ) && mnBorderColor != AX_SYSCOLOR_WINDOWFRAME )
1550        aWriter.writeIntProperty< sal_uInt32 >( mnBorderColor );
1551     else
1552         aWriter.skipProperty(); // mnBorderColor
1553     if (  mnSpecialEffect != AX_SPECIALEFFECT_SUNKEN  )
1554         aWriter.writeIntProperty< sal_uInt32 >( mnSpecialEffect );
1555     else
1556         aWriter.skipProperty(); //mnSpecialEffect
1557     aWriter.skipProperty(); // mouse icon
1558     aWriter.skipProperty(); // maPictureData
1559     aWriter.skipProperty(); // accelerator
1560     aWriter.skipProperty(); // undefined
1561     aWriter.writeBoolProperty(true); // must be 1 for morph
1562     if ( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON )
1563         aWriter.writeStringProperty( maGroupName );
1564     else
1565         aWriter.skipProperty(); //maGroupName
1566     aWriter.finalizeExport();
1567     AxFontDataModel::exportBinaryModel( rOutStrm );
1568 }
1569 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1570 void AxMorphDataModelBase::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1571 {
1572     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1573     rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
1574     if ( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON )
1575     {
1576         // If unspecified, radio buttons autoGroup in the same document/sheet
1577         // NOTE: form controls should not autoGroup with ActiveX controls - see drawingfragment.cxx
1578         OUString sGroupName = !maGroupName.isEmpty() ? maGroupName : "autoGroup_";
1579         rPropMap.setProperty( PROP_GroupName, sGroupName );
1580     }
1581     AxFontDataModel::convertProperties( rPropMap, rConv );
1582 }
1583 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1584 void AxMorphDataModelBase::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1585 {
1586     if ( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON )
1587         rPropSet.getProperty( maGroupName, PROP_GroupName );
1588     AxFontDataModel::convertFromProperties( rPropSet, rConv );
1589 }
1590 
AxToggleButtonModel()1591 AxToggleButtonModel::AxToggleButtonModel()
1592 {
1593     mnDisplayStyle = AX_DISPLAYSTYLE_TOGGLE;
1594 }
1595 
getControlType() const1596 ApiControlType AxToggleButtonModel::getControlType() const
1597 {
1598     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TOGGLE, "AxToggleButtonModel::getControlType - invalid control type" );
1599     return API_CONTROL_BUTTON;
1600 }
1601 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1602 void AxToggleButtonModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1603 {
1604     rPropSet.getProperty( maCaption, PROP_Label );
1605 
1606     bool bRes = false;
1607     if ( rPropSet.getProperty( bRes,  PROP_MultiLine ) )
1608         setFlag( mnFlags, AX_FLAGS_WORDWRAP, bRes );
1609 
1610     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
1611     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1612     // need to process the image if one exists
1613     ControlConverter::convertToAxState( rPropSet, maValue, mnMultiSelect, API_DEFAULTSTATE_BOOLEAN );
1614     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
1615 }
1616 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1617 void AxToggleButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1618 {
1619     rPropMap.setProperty( PROP_Label, maCaption );
1620     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1621     rPropMap.setProperty( PROP_Toggle, true );
1622     ControlConverter::convertVerticalAlign( rPropMap, mnVerticalAlign );
1623     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::NotSupported );
1624     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1625     ControlConverter::convertAxState( rPropMap, maValue, mnMultiSelect, API_DEFAULTSTATE_BOOLEAN, mbAwtModel );
1626     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1627 }
1628 
exportCompObj(BinaryOutputStream & rOutStream)1629 void AxToggleButtonModel::exportCompObj( BinaryOutputStream& rOutStream )
1630 {
1631     // should be able to replace this hardcoded foo with
1632     // proper export info from MS-OLEDS spec.
1633     static sal_uInt8 const aCompObj[] = {
1634             0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1635             0xFF, 0xFF, 0xFF, 0xFF, 0x60, 0x1D, 0xD2, 0x8B,
1636             0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1637             0x00, 0x60, 0x02, 0xF3, 0x21, 0x00, 0x00, 0x00,
1638             0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1639             0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1640             0x32, 0x2E, 0x30, 0x20, 0x54, 0x6F, 0x67, 0x67,
1641             0x6C, 0x65, 0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E,
1642             0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D, 0x62,
1643             0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F, 0x62,
1644             0x6A, 0x65, 0x63, 0x74, 0x00, 0x15, 0x00, 0x00,
1645             0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x54,
1646             0x6F, 0x67, 0x67, 0x6C, 0x65, 0x42, 0x75, 0x74,
1647             0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00, 0xF4, 0x39,
1648             0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1649             0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1650     };
1651     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1652 }
1653 
AxCheckBoxModel()1654 AxCheckBoxModel::AxCheckBoxModel()
1655 {
1656     mnDisplayStyle = AX_DISPLAYSTYLE_CHECKBOX;
1657 }
1658 
getControlType() const1659 ApiControlType AxCheckBoxModel::getControlType() const
1660 {
1661     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_CHECKBOX, "AxCheckBoxModel::getControlType - invalid control type" );
1662     return API_CONTROL_CHECKBOX;
1663 }
1664 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1665 void AxCheckBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1666 {
1667     rPropMap.setProperty( PROP_Label, maCaption );
1668     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1669     ControlConverter::convertVerticalAlign( rPropMap, mnVerticalAlign );
1670     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1671     ControlConverter::convertAxVisualEffect( rPropMap, mnSpecialEffect );
1672     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1673     ControlConverter::convertAxState( rPropMap, maValue, mnMultiSelect, API_DEFAULTSTATE_TRISTATE, mbAwtModel );
1674     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1675 }
1676 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1677 void AxCheckBoxModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1678 {
1679     rPropSet.getProperty( maCaption, PROP_Label );
1680 
1681     bool bRes = false;
1682     if ( rPropSet.getProperty( bRes,  PROP_MultiLine ) )
1683         setFlag( mnFlags, AX_FLAGS_WORDWRAP, bRes );
1684 
1685     ControlConverter::convertToAxVisualEffect( rPropSet, mnSpecialEffect );
1686     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
1687     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1688     // need to process the image if one exists
1689     ControlConverter::convertToAxState( rPropSet, maValue, mnMultiSelect, API_DEFAULTSTATE_TRISTATE );
1690     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
1691 }
1692 
exportCompObj(BinaryOutputStream & rOutStream)1693 void AxCheckBoxModel::exportCompObj( BinaryOutputStream& rOutStream )
1694 {
1695     // should be able to replace this hardcoded foo with
1696     // proper export info from MS-OLEDS spec.
1697     static sal_uInt8 const aCompObj[] = {
1698         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1699         0xFF, 0xFF, 0xFF, 0xFF, 0x40, 0x1D, 0xD2, 0x8B,
1700         0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1701         0x00, 0x60, 0x02, 0xF3, 0x1D, 0x00, 0x00, 0x00,
1702         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1703         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1704         0x32, 0x2E, 0x30, 0x20, 0x43, 0x68, 0x65, 0x63,
1705         0x6B, 0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00,
1706         0x00, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65,
1707         0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74,
1708         0x00, 0x11, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72,
1709         0x6D, 0x73, 0x2E, 0x43, 0x68, 0x65, 0x63, 0x6B,
1710         0x42, 0x6F, 0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39,
1711         0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1712         0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1713     };
1714     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1715 }
1716 
AxOptionButtonModel()1717 AxOptionButtonModel::AxOptionButtonModel()
1718 {
1719     mnDisplayStyle = AX_DISPLAYSTYLE_OPTBUTTON;
1720 }
1721 
getControlType() const1722 ApiControlType AxOptionButtonModel::getControlType() const
1723 {
1724     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON, "AxOptionButtonModel::getControlType - invalid control type" );
1725     return API_CONTROL_RADIOBUTTON;
1726 }
1727 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1728 void AxOptionButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1729 {
1730     rPropMap.setProperty( PROP_Label, maCaption );
1731     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1732     ControlConverter::convertVerticalAlign( rPropMap, mnVerticalAlign );
1733     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1734     ControlConverter::convertAxVisualEffect( rPropMap, mnSpecialEffect );
1735     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1736     ControlConverter::convertAxState( rPropMap, maValue, mnMultiSelect, API_DEFAULTSTATE_SHORT, mbAwtModel );
1737     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1738 }
1739 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1740 void AxOptionButtonModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1741 {
1742     rPropSet.getProperty( maCaption, PROP_Label );
1743 
1744     bool bRes = false;
1745     if ( rPropSet.getProperty( bRes,  PROP_MultiLine ) )
1746         setFlag( mnFlags, AX_FLAGS_WORDWRAP, bRes );
1747 
1748     ControlConverter::convertToAxVisualEffect( rPropSet, mnSpecialEffect );
1749     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
1750     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1751     // need to process the image if one exists
1752     ControlConverter::convertToAxState( rPropSet, maValue, mnMultiSelect, API_DEFAULTSTATE_BOOLEAN );
1753     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
1754 }
1755 
exportCompObj(BinaryOutputStream & rOutStream)1756 void AxOptionButtonModel::exportCompObj( BinaryOutputStream& rOutStream )
1757 {
1758     // should be able to replace this hardcoded foo with
1759     // proper export info from MS-OLEDS spec.
1760     static sal_uInt8 const aCompObj[] = {
1761         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1762         0xFF, 0xFF, 0xFF, 0xFF, 0x50, 0x1D, 0xD2, 0x8B,
1763         0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1764         0x00, 0x60, 0x02, 0xF3, 0x21, 0x00, 0x00, 0x00,
1765         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1766         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1767         0x32, 0x2E, 0x30, 0x20, 0x4F, 0x70, 0x74, 0x69,
1768         0x6F, 0x6E, 0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E,
1769         0x00, 0x10, 0x00, 0x00, 0x00, 0x45, 0x6D, 0x62,
1770         0x65, 0x64, 0x64, 0x65, 0x64, 0x20, 0x4F, 0x62,
1771         0x6A, 0x65, 0x63, 0x74, 0x00, 0x15, 0x00, 0x00,
1772         0x00, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x4F,
1773         0x70, 0x74, 0x69, 0x6F, 0x6E, 0x42, 0x75, 0x74,
1774         0x74, 0x6F, 0x6E, 0x2E, 0x31, 0x00, 0xF4, 0x39,
1775         0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1776         0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1777     };
1778     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1779 }
1780 
AxTextBoxModel()1781 AxTextBoxModel::AxTextBoxModel()
1782 {
1783     mnDisplayStyle = AX_DISPLAYSTYLE_TEXT;
1784 }
1785 
getControlType() const1786 ApiControlType AxTextBoxModel::getControlType() const
1787 {
1788     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT, "AxTextBoxModel::getControlType - invalid control type" );
1789     return API_CONTROL_EDIT;
1790 }
1791 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1792 void AxTextBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1793 {
1794     if (getFlag( mnFlags, AX_FLAGS_MULTILINE ) && getFlag( mnFlags, AX_FLAGS_WORDWRAP ))
1795         rPropMap.setProperty( PROP_MultiLine, true );
1796     else
1797         rPropMap.setProperty( PROP_MultiLine, false );
1798     rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
1799     rPropMap.setProperty( PROP_ReadOnly, getFlag( mnFlags, AX_FLAGS_LOCKED ) );
1800     rPropMap.setProperty( mbAwtModel ? PROP_Text : PROP_DefaultText, maValue );
1801     rPropMap.setProperty( PROP_MaxTextLen, getLimitedValue< sal_Int16, sal_Int32 >( mnMaxLength, 0, SAL_MAX_INT16 ) );
1802     if( (0 < mnPasswordChar) && (mnPasswordChar <= SAL_MAX_INT16) )
1803         rPropMap.setProperty( PROP_EchoChar, static_cast< sal_Int16 >( mnPasswordChar ) );
1804     rPropMap.setProperty( PROP_HScroll, getFlag( mnScrollBars, AX_SCROLLBAR_HORIZONTAL ) );
1805     rPropMap.setProperty( PROP_VScroll, getFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL ) );
1806     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1807     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1808     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1809 }
1810 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1811 void AxTextBoxModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1812 {
1813     bool bRes = false;
1814     if ( rPropSet.getProperty( bRes,  PROP_MultiLine ) ) {
1815         setFlag( mnFlags, AX_FLAGS_WORDWRAP, bRes );
1816         setFlag( mnFlags, AX_FLAGS_MULTILINE, bRes );
1817     }
1818     if ( rPropSet.getProperty( bRes,  PROP_HideInactiveSelection ) )
1819         setFlag( mnFlags, AX_FLAGS_HIDESELECTION, bRes );
1820     if ( rPropSet.getProperty( bRes,  PROP_ReadOnly ) )
1821         setFlag( mnFlags, AX_FLAGS_LOCKED, bRes );
1822     rPropSet.getProperty( maValue, ( mbAwtModel ? PROP_Text : PROP_DefaultText ) );
1823     if (maValue.isEmpty() && !mbAwtModel)
1824         // No default value? Then try exporting the current one.
1825         rPropSet.getProperty( maValue, PROP_Text);
1826     sal_Int16 nTmp(0);
1827     if ( rPropSet.getProperty( nTmp, PROP_MaxTextLen ) )
1828         mnMaxLength = nTmp;
1829     if ( rPropSet.getProperty( nTmp, PROP_EchoChar ) )
1830         mnPasswordChar = nTmp;
1831     if ( rPropSet.getProperty( bRes,  PROP_HScroll ) )
1832         setFlag( mnScrollBars, AX_SCROLLBAR_HORIZONTAL, bRes );
1833     if ( rPropSet.getProperty( bRes,  PROP_VScroll ) )
1834         setFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL, bRes );
1835 
1836     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor, 0x80000005L );
1837     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1838 
1839     ControlConverter::convertToAxBorder( rPropSet, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1840     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
1841 }
1842 
exportCompObj(BinaryOutputStream & rOutStream)1843 void AxTextBoxModel::exportCompObj( BinaryOutputStream& rOutStream )
1844 {
1845     // should be able to replace this hardcoded foo with
1846     // proper export info from MS-OLEDS spec.
1847     static sal_uInt8 const aCompObj[] = {
1848         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1849         0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x1D, 0xD2, 0x8B,
1850         0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1851         0x00, 0x60, 0x02, 0xF3, 0x1C, 0x00, 0x00, 0x00,
1852         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1853         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1854         0x32, 0x2E, 0x30, 0x20, 0x54, 0x65, 0x78, 0x74,
1855         0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00, 0x00,
1856         0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
1857         0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
1858         0x10, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D,
1859         0x73, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x42, 0x6F,
1860         0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71,
1861         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1862         0x00, 0x00, 0x00, 0x00
1863     };
1864     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1865 }
1866 
AxNumericFieldModel()1867 AxNumericFieldModel::AxNumericFieldModel()
1868 {
1869     mnDisplayStyle = AX_DISPLAYSTYLE_TEXT;
1870 }
1871 
getControlType() const1872 ApiControlType AxNumericFieldModel::getControlType() const
1873 {
1874     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT, "AxNumericFieldModel::getControlType - invalid control type" );
1875     return API_CONTROL_NUMERIC;
1876 }
1877 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1878 void AxNumericFieldModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1879 {
1880     rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
1881     // TODO: OUString::toDouble() does not handle local decimal separator
1882     rPropMap.setProperty( mbAwtModel ? PROP_Value : PROP_DefaultValue, maValue.toDouble() );
1883     rPropMap.setProperty( PROP_Spin, getFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL ) );
1884     rPropMap.setProperty( PROP_Repeat, true );
1885     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1886     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1887     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1888 }
1889 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1890 void AxNumericFieldModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1891 {
1892     bool bRes = false;
1893     if ( rPropSet.getProperty( bRes,  PROP_HideInactiveSelection ) )
1894         setFlag( mnFlags, AX_FLAGS_HIDESELECTION, bRes );
1895     rPropSet.getProperty( maValue, ( mbAwtModel ? PROP_Text : PROP_DefaultText ) );
1896     if ( rPropSet.getProperty( bRes,  PROP_Spin ) )
1897         setFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL, bRes );
1898 
1899     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
1900     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1901 
1902     ControlConverter::convertToAxBorder( rPropSet, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1903     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
1904 }
1905 
exportCompObj(BinaryOutputStream & rOutStream)1906 void AxNumericFieldModel::exportCompObj( BinaryOutputStream& rOutStream )
1907 {
1908     // should be able to replace this hardcoded foo with
1909     // proper export info from MS-OLEDS spec.
1910     static sal_uInt8 const aCompObj[] = {
1911         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1912         0xFF, 0xFF, 0xFF, 0xFF, 0x10, 0x1D, 0xD2, 0x8B,
1913         0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1914         0x00, 0x60, 0x02, 0xF3, 0x1C, 0x00, 0x00, 0x00,
1915         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1916         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1917         0x32, 0x2E, 0x30, 0x20, 0x54, 0x65, 0x78, 0x74,
1918         0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00, 0x00,
1919         0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
1920         0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
1921         0x10, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D,
1922         0x73, 0x2E, 0x54, 0x65, 0x78, 0x74, 0x42, 0x6F,
1923         0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71,
1924         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1925         0x00, 0x00, 0x00, 0x00
1926     };
1927     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1928 }
1929 
AxListBoxModel()1930 AxListBoxModel::AxListBoxModel()
1931 {
1932     mnDisplayStyle = AX_DISPLAYSTYLE_LISTBOX;
1933 }
1934 
getControlType() const1935 ApiControlType AxListBoxModel::getControlType() const
1936 {
1937     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX, "AxListBoxModel::getControlType - invalid control type" );
1938     return API_CONTROL_LISTBOX;
1939 }
1940 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1941 void AxListBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1942 {
1943     bool bMultiSelect = (mnMultiSelect == AX_SELECTION_MULTI) || (mnMultiSelect == AX_SELECTION_EXTENDED);
1944     rPropMap.setProperty( PROP_MultiSelection, bMultiSelect );
1945     rPropMap.setProperty( PROP_Dropdown, false );
1946     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
1947     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1948     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1949 }
1950 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)1951 void AxListBoxModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
1952 {
1953     bool bRes = false;
1954     if ( rPropSet.getProperty( bRes, PROP_MultiSelection ) )
1955         ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
1956 
1957     ControlConverter::convertToAxBorder( rPropSet, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1958     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
1959     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
1960 }
1961 
exportCompObj(BinaryOutputStream & rOutStream)1962 void AxListBoxModel::exportCompObj( BinaryOutputStream& rOutStream )
1963 {
1964     // should be able to replace this hardcoded foo with
1965     // proper export info from MS-OLEDS spec.
1966     static sal_uInt8 const aCompObj[] = {
1967         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
1968         0xFF, 0xFF, 0xFF, 0xFF, 0x20, 0x1D, 0xD2, 0x8B,
1969         0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
1970         0x00, 0x60, 0x02, 0xF3, 0x1C, 0x00, 0x00, 0x00,
1971         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
1972         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
1973         0x32, 0x2E, 0x30, 0x20, 0x4C, 0x69, 0x73, 0x74,
1974         0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00, 0x00,
1975         0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64,
1976         0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x00,
1977         0x10, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72, 0x6D,
1978         0x73, 0x2E, 0x4C, 0x69, 0x73, 0x74, 0x42, 0x6F,
1979         0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71,
1980         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1981         0x00, 0x00, 0x00, 0x00
1982     };
1983     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
1984 }
1985 
AxComboBoxModel()1986 AxComboBoxModel::AxComboBoxModel()
1987 {
1988     mnDisplayStyle = AX_DISPLAYSTYLE_COMBOBOX;
1989     mnFlags = 0x2c80481b;
1990 }
1991 
getControlType() const1992 ApiControlType AxComboBoxModel::getControlType() const
1993 {
1994     OSL_ENSURE( (mnDisplayStyle == AX_DISPLAYSTYLE_COMBOBOX) || (mnDisplayStyle == AX_DISPLAYSTYLE_DROPDOWN), "AxComboBoxModel::getControlType - invalid control type" );
1995     return (mnDisplayStyle == AX_DISPLAYSTYLE_DROPDOWN) ? API_CONTROL_LISTBOX : API_CONTROL_COMBOBOX;
1996 }
1997 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const1998 void AxComboBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1999 {
2000     if( mnDisplayStyle != AX_DISPLAYSTYLE_DROPDOWN )
2001     {
2002         rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
2003         rPropMap.setProperty( mbAwtModel ? PROP_Text : PROP_DefaultText, maValue );
2004         rPropMap.setProperty( PROP_MaxTextLen, getLimitedValue< sal_Int16, sal_Int32 >( mnMaxLength, 0, SAL_MAX_INT16 ) );
2005         bool bAutoComplete = (mnMatchEntry == AX_MATCHENTRY_FIRSTLETTER) || (mnMatchEntry == AX_MATCHENTRY_COMPLETE);
2006         rPropMap.setProperty( PROP_Autocomplete, bAutoComplete );
2007     }
2008     bool bShowDropdown = (mnShowDropButton == AX_SHOWDROPBUTTON_FOCUS) || (mnShowDropButton == AX_SHOWDROPBUTTON_ALWAYS);
2009     rPropMap.setProperty( PROP_Dropdown, bShowDropdown );
2010     rPropMap.setProperty( PROP_LineCount, getLimitedValue< sal_Int16, sal_Int32 >( mnListRows, 1, SAL_MAX_INT16 ) );
2011     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::Void );
2012     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
2013     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
2014 }
2015 
convertFromProperties(PropertySet & rPropSet,const ControlConverter & rConv)2016 void AxComboBoxModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& rConv )
2017 {
2018     // when would we have mnDisplayStyle = AX_DISPLAYSTYLE_DROPDOWN ?
2019     // #TODO check against msocximex
2020     mnDisplayStyle = AX_DISPLAYSTYLE_COMBOBOX;
2021     bool bRes = false;
2022 
2023     if ( rPropSet.getProperty( bRes, PROP_HideInactiveSelection ) )
2024         setFlag( mnFlags, AX_FLAGS_HIDESELECTION, bRes );
2025     rPropSet.getProperty( maValue, ( mbAwtModel ? PROP_Text : PROP_DefaultText ) );
2026 
2027     sal_Int16 nTmp(0);
2028     if ( rPropSet.getProperty( nTmp, PROP_MaxTextLen ) )
2029         mnMaxLength = nTmp;
2030     if ( rPropSet.getProperty( bRes, PROP_Autocomplete ) )
2031     {
2032         // when to choose AX_MATCHENTRY_FIRSTLETTER ?
2033         // #TODO check against msocximex
2034         if ( bRes )
2035             mnMatchEntry = AX_MATCHENTRY_COMPLETE;
2036     }
2037     if ( rPropSet.getProperty( bRes, PROP_Dropdown ) )
2038     {
2039         rPropSet.getProperty( mnListRows, PROP_LineCount );
2040         if ( !mnListRows )
2041             mnListRows = 1;
2042     }
2043     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
2044     ControlConverter::convertToMSColor( rPropSet, PROP_TextColor, mnTextColor );
2045 
2046     ControlConverter::convertToAxBorder( rPropSet, mnBorderColor, mnBorderStyle, mnSpecialEffect );
2047     AxMorphDataModelBase::convertFromProperties( rPropSet, rConv );
2048 }
2049 
exportCompObj(BinaryOutputStream & rOutStream)2050 void AxComboBoxModel::exportCompObj( BinaryOutputStream& rOutStream )
2051 {
2052     // should be able to replace this hardcoded foo with
2053     // proper export info from MS-OLEDS spec.
2054     static sal_uInt8 const aCompObj[] = {
2055         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2056         0xFF, 0xFF, 0xFF, 0xFF, 0x30, 0x1D, 0xD2, 0x8B,
2057         0x42, 0xEC, 0xCE, 0x11, 0x9E, 0x0D, 0x00, 0xAA,
2058         0x00, 0x60, 0x02, 0xF3, 0x1D, 0x00, 0x00, 0x00,
2059         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2060         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2061         0x32, 0x2E, 0x30, 0x20, 0x43, 0x6F, 0x6D, 0x62,
2062         0x6F, 0x42, 0x6F, 0x78, 0x00, 0x10, 0x00, 0x00,
2063         0x00, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65,
2064         0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74,
2065         0x00, 0x11, 0x00, 0x00, 0x00, 0x46, 0x6F, 0x72,
2066         0x6D, 0x73, 0x2E, 0x43, 0x6F, 0x6D, 0x62, 0x6F,
2067         0x42, 0x6F, 0x78, 0x2E, 0x31, 0x00, 0xF4, 0x39,
2068         0xB2, 0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2069         0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2070     };
2071     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
2072 }
2073 
AxSpinButtonModel()2074 AxSpinButtonModel::AxSpinButtonModel() :
2075     mnArrowColor( AX_SYSCOLOR_BUTTONTEXT ),
2076     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
2077     mnFlags( AX_SPINBUTTON_DEFFLAGS ),
2078     mnOrientation( AX_ORIENTATION_AUTO ),
2079     mnMin( 0 ),
2080     mnMax( 100 ),
2081     mnPosition( 0 ),
2082     mnSmallChange( 1 ),
2083     mnDelay( 50 )
2084 {
2085 }
2086 
getControlType() const2087 ApiControlType AxSpinButtonModel::getControlType() const
2088 {
2089     return API_CONTROL_SPINBUTTON;
2090 }
2091 
importProperty(sal_Int32 nPropId,const OUString & rValue)2092 void AxSpinButtonModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
2093 {
2094     switch( nPropId )
2095     {
2096         case XML_ForeColor:             mnArrowColor = AttributeConversion::decodeUnsigned( rValue );   break;
2097         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
2098         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
2099         case XML_Orientation:           mnOrientation = AttributeConversion::decodeInteger( rValue );   break;
2100         case XML_Min:                   mnMin = AttributeConversion::decodeInteger( rValue );           break;
2101         case XML_Max:                   mnMax = AttributeConversion::decodeInteger( rValue );           break;
2102         case XML_Position:              mnPosition = AttributeConversion::decodeInteger( rValue );      break;
2103         case XML_SmallChange:           mnSmallChange = AttributeConversion::decodeInteger( rValue );   break;
2104         case XML_Delay:                 mnDelay = AttributeConversion::decodeInteger( rValue );         break;
2105         default:                        AxControlModelBase::importProperty( nPropId, rValue );
2106     }
2107 }
2108 
importBinaryModel(BinaryInputStream & rInStrm)2109 bool AxSpinButtonModel::importBinaryModel( BinaryInputStream& rInStrm )
2110 {
2111     AxBinaryPropertyReader aReader( rInStrm );
2112     aReader.readIntProperty< sal_uInt32 >( mnArrowColor );
2113     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
2114     aReader.readIntProperty< sal_uInt32 >( mnFlags );
2115     aReader.readPairProperty( maSize );
2116     aReader.skipIntProperty< sal_uInt32 >(); // unused
2117     aReader.readIntProperty< sal_Int32 >( mnMin );
2118     aReader.readIntProperty< sal_Int32 >( mnMax );
2119     aReader.readIntProperty< sal_Int32 >( mnPosition );
2120     aReader.skipIntProperty< sal_uInt32 >(); // prev enabled
2121     aReader.skipIntProperty< sal_uInt32 >(); // next enabled
2122     aReader.readIntProperty< sal_Int32 >( mnSmallChange );
2123     aReader.readIntProperty< sal_Int32 >( mnOrientation );
2124     aReader.readIntProperty< sal_Int32 >( mnDelay );
2125     aReader.skipPictureProperty(); // mouse icon
2126     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
2127     return aReader.finalizeImport();
2128 }
2129 
exportBinaryModel(BinaryOutputStream & rOutStrm)2130 void AxSpinButtonModel::exportBinaryModel( BinaryOutputStream& rOutStrm )
2131 {
2132     AxBinaryPropertyWriter aWriter( rOutStrm );
2133     aWriter.writeIntProperty< sal_uInt32 >( mnArrowColor );
2134     if ( mnBackColor )
2135         aWriter.writeIntProperty< sal_uInt32 >( mnBackColor );
2136     else
2137         aWriter.skipProperty(); // default backcolour
2138     aWriter.writeIntProperty< sal_uInt32 >( mnFlags );
2139     aWriter.writePairProperty( maSize );
2140     aWriter.skipProperty(); // unused
2141     aWriter.writeIntProperty< sal_Int32 >( mnMin );
2142     aWriter.writeIntProperty< sal_Int32 >( mnMax );
2143     aWriter.writeIntProperty< sal_Int32 >( mnPosition );
2144     aWriter.skipProperty(); // prev enabled
2145     aWriter.skipProperty(); // next enabled
2146     aWriter.writeIntProperty< sal_Int32 >( mnSmallChange );
2147     aWriter.writeIntProperty< sal_Int32 >( mnOrientation );
2148     aWriter.writeIntProperty< sal_Int32 >( mnDelay );
2149     aWriter.skipProperty(); // mouse icon
2150     aWriter.skipProperty(); // mouse pointer
2151 
2152     aWriter.finalizeExport();
2153 }
2154 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2155 void AxSpinButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2156 {
2157     sal_Int32 nMin = ::std::min( mnMin, mnMax );
2158     sal_Int32 nMax = ::std::max( mnMin, mnMax );
2159     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
2160     rPropMap.setProperty( PROP_SpinValueMin, nMin );
2161     rPropMap.setProperty( PROP_SpinValueMax, nMax );
2162     rPropMap.setProperty( PROP_SpinIncrement, mnSmallChange );
2163     rPropMap.setProperty( mbAwtModel ? PROP_SpinValue : PROP_DefaultSpinValue, mnPosition );
2164     rPropMap.setProperty( PROP_Repeat, true );
2165     rPropMap.setProperty( PROP_RepeatDelay, mnDelay );
2166     rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
2167     rConv.convertColor( rPropMap, PROP_SymbolColor, mnArrowColor );
2168     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::NotSupported );
2169     ControlConverter::convertAxOrientation( rPropMap, maSize, mnOrientation );
2170     AxControlModelBase::convertProperties( rPropMap, rConv );
2171 }
2172 
convertFromProperties(PropertySet & rPropSet,const ControlConverter &)2173 void AxSpinButtonModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& )
2174 {
2175     bool bRes = false;
2176     if ( rPropSet.getProperty( bRes,  PROP_Enabled ) )
2177         setFlag( mnFlags, AX_FLAGS_ENABLED, bRes );
2178     rPropSet.getProperty( mnMin, PROP_SpinValueMin );
2179     rPropSet.getProperty( mnMax, PROP_SpinValueMax );
2180     rPropSet.getProperty( mnSmallChange, PROP_SpinIncrement );
2181     rPropSet.getProperty( mnPosition, ( mbAwtModel ? PROP_SpinValue : PROP_DefaultSpinValue ) );
2182     rPropSet.getProperty( mnDelay, PROP_RepeatDelay );
2183     ControlConverter::convertToMSColor( rPropSet, PROP_SymbolColor, mnArrowColor);
2184     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
2185 
2186     ControlConverter::convertToAxOrientation( rPropSet, mnOrientation );
2187 }
2188 
exportCompObj(BinaryOutputStream & rOutStream)2189 void AxSpinButtonModel::exportCompObj( BinaryOutputStream& rOutStream )
2190 {
2191     // should be able to replace this hardcoded foo with
2192     // proper export info from MS-OLEDS spec.
2193     static sal_uInt8 const aCompObj[] =
2194     {
2195         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2196         0xFF, 0xFF, 0xFF, 0xFF, 0xB0, 0x6F, 0x17, 0x79,
2197         0xF2, 0xB7, 0xCE, 0x11, 0x97, 0xEF, 0x00, 0xAA,
2198         0x00, 0x6D, 0x27, 0x76, 0x1F, 0x00, 0x00, 0x00,
2199         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2200         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2201         0x32, 0x2E, 0x30, 0x20, 0x53, 0x70, 0x69, 0x6E,
2202         0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E, 0x00, 0x10,
2203         0x00, 0x00, 0x00, 0x45, 0x6D, 0x62, 0x65, 0x64,
2204         0x64, 0x65, 0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65,
2205         0x63, 0x74, 0x00, 0x13, 0x00, 0x00, 0x00, 0x46,
2206         0x6F, 0x72, 0x6D, 0x73, 0x2E, 0x53, 0x70, 0x69,
2207         0x6E, 0x42, 0x75, 0x74, 0x74, 0x6F, 0x6E, 0x2E,
2208         0x31, 0x00, 0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00,
2209         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2210         0x00, 0x00
2211     };
2212 
2213     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
2214 }
2215 
AxScrollBarModel()2216 AxScrollBarModel::AxScrollBarModel() :
2217     mnArrowColor( AX_SYSCOLOR_BUTTONTEXT ),
2218     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
2219     mnFlags( AX_SCROLLBAR_DEFFLAGS ),
2220     mnOrientation( AX_ORIENTATION_AUTO ),
2221     mnPropThumb( AX_PROPTHUMB_ON ),
2222     mnMin( 0 ),
2223     mnMax( 32767 ),
2224     mnPosition( 0 ),
2225     mnSmallChange( 1 ),
2226     mnLargeChange( 1 ),
2227     mnDelay( 50 )
2228 {
2229 }
2230 
getControlType() const2231 ApiControlType AxScrollBarModel::getControlType() const
2232 {
2233     return API_CONTROL_SCROLLBAR;
2234 }
2235 
importProperty(sal_Int32 nPropId,const OUString & rValue)2236 void AxScrollBarModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
2237 {
2238     switch( nPropId )
2239     {
2240         case XML_ForeColor:             mnArrowColor = AttributeConversion::decodeUnsigned( rValue );   break;
2241         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
2242         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
2243         case XML_Orientation:           mnOrientation = AttributeConversion::decodeInteger( rValue );   break;
2244         case XML_ProportionalThumb:     mnPropThumb = AttributeConversion::decodeInteger( rValue );     break;
2245         case XML_Min:                   mnMin = AttributeConversion::decodeInteger( rValue );           break;
2246         case XML_Max:                   mnMax = AttributeConversion::decodeInteger( rValue );           break;
2247         case XML_Position:              mnPosition = AttributeConversion::decodeInteger( rValue );      break;
2248         case XML_SmallChange:           mnSmallChange = AttributeConversion::decodeInteger( rValue );   break;
2249         case XML_LargeChange:           mnLargeChange = AttributeConversion::decodeInteger( rValue );   break;
2250         case XML_Delay:                 mnDelay = AttributeConversion::decodeInteger( rValue );         break;
2251         default:                        AxControlModelBase::importProperty( nPropId, rValue );
2252     }
2253 }
2254 
importBinaryModel(BinaryInputStream & rInStrm)2255 bool AxScrollBarModel::importBinaryModel( BinaryInputStream& rInStrm )
2256 {
2257     AxBinaryPropertyReader aReader( rInStrm );
2258     aReader.readIntProperty< sal_uInt32 >( mnArrowColor );
2259     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
2260     aReader.readIntProperty< sal_uInt32 >( mnFlags );
2261     aReader.readPairProperty( maSize );
2262     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
2263     aReader.readIntProperty< sal_Int32 >( mnMin );
2264     aReader.readIntProperty< sal_Int32 >( mnMax );
2265     aReader.readIntProperty< sal_Int32 >( mnPosition );
2266     aReader.skipIntProperty< sal_uInt32 >(); // unused
2267     aReader.skipIntProperty< sal_uInt32 >(); // prev enabled
2268     aReader.skipIntProperty< sal_uInt32 >(); // next enabled
2269     aReader.readIntProperty< sal_Int32 >( mnSmallChange );
2270     aReader.readIntProperty< sal_Int32 >( mnLargeChange );
2271     aReader.readIntProperty< sal_Int32 >( mnOrientation );
2272     aReader.readIntProperty< sal_Int16 >( mnPropThumb );
2273     aReader.readIntProperty< sal_Int32 >( mnDelay );
2274     aReader.skipPictureProperty(); // mouse icon
2275     return aReader.finalizeImport();
2276 }
2277 
exportBinaryModel(BinaryOutputStream & rOutStrm)2278 void AxScrollBarModel::exportBinaryModel( BinaryOutputStream& rOutStrm )
2279 {
2280     AxBinaryPropertyWriter aWriter( rOutStrm );
2281     aWriter.writeIntProperty< sal_uInt32 >( mnArrowColor );
2282     if ( mnBackColor )
2283         aWriter.writeIntProperty< sal_uInt32 >( mnBackColor );
2284     else
2285         aWriter.skipProperty(); // default backcolour
2286     aWriter.writeIntProperty< sal_uInt32 >( mnFlags );
2287     aWriter.writePairProperty( maSize );
2288     aWriter.skipProperty(); // mouse pointer
2289     aWriter.writeIntProperty< sal_Int32 >( mnMin );
2290     aWriter.writeIntProperty< sal_Int32 >( mnMax );
2291     aWriter.writeIntProperty< sal_Int32 >( mnPosition );
2292     aWriter.skipProperty(); // unused
2293     aWriter.skipProperty(); // prev enabled
2294     aWriter.skipProperty(); // next enabled
2295     aWriter.writeIntProperty< sal_Int32 >( mnSmallChange );
2296     aWriter.writeIntProperty< sal_Int32 >( mnLargeChange );
2297     aWriter.writeIntProperty< sal_Int32 >( mnOrientation );
2298     aWriter.writeIntProperty< sal_Int16 >( mnPropThumb );
2299     aWriter.writeIntProperty< sal_Int32 >( mnDelay );
2300     aWriter.skipProperty(); // mouse icon
2301     aWriter.finalizeExport();
2302 }
2303 
exportCompObj(BinaryOutputStream & rOutStream)2304 void AxScrollBarModel::exportCompObj( BinaryOutputStream& rOutStream )
2305 {
2306     // should be able to replace this hardcoded foo with
2307     // proper export info from MS-OLEDS spec.
2308     static sal_uInt8 const aCompObj[] =
2309     {
2310         0x01, 0x00, 0xFE, 0xFF, 0x03, 0x0A, 0x00, 0x00,
2311         0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x81, 0xD1, 0xDF,
2312         0x2F, 0x5E, 0xCE, 0x11, 0xA4, 0x49, 0x00, 0xAA,
2313         0x00, 0x4A, 0x80, 0x3D, 0x1E, 0x00, 0x00, 0x00,
2314         0x4D, 0x69, 0x63, 0x72, 0x6F, 0x73, 0x6F, 0x66,
2315         0x74, 0x20, 0x46, 0x6F, 0x72, 0x6D, 0x73, 0x20,
2316         0x32, 0x2E, 0x30, 0x20, 0x53, 0x63, 0x72, 0x6F,
2317         0x6C, 0x6C, 0x42, 0x61, 0x72, 0x00, 0x10, 0x00,
2318         0x00, 0x00, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64,
2319         0x65, 0x64, 0x20, 0x4F, 0x62, 0x6A, 0x65, 0x63,
2320         0x74, 0x00, 0x12, 0x00, 0x00, 0x00, 0x46, 0x6F,
2321         0x72, 0x6D, 0x73, 0x2E, 0x53, 0x63, 0x72, 0x6F,
2322         0x6C, 0x6C, 0x42, 0x61, 0x72, 0x2E, 0x31, 0x00,
2323         0xF4, 0x39, 0xB2, 0x71, 0x00, 0x00, 0x00, 0x00,
2324         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
2325     };
2326     rOutStream.writeMemory( aCompObj, sizeof( aCompObj ) );
2327 }
2328 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2329 void AxScrollBarModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2330 {
2331     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
2332     rPropMap.setProperty( PROP_RepeatDelay, mnDelay );
2333     rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
2334     if( (mnPropThumb == AX_PROPTHUMB_ON) && (mnMin != mnMax) && (mnLargeChange > 0) )
2335     {
2336         // use double to prevent integer overflow in division (fInterval+mnLargeChange may become 0 when performed as int)
2337         double fInterval = fabs( static_cast< double >( mnMax - mnMin ) );
2338         sal_Int32 nThumbLen = getLimitedValue< sal_Int32, double >( (fInterval * mnLargeChange) / (fInterval + mnLargeChange), 1, SAL_MAX_INT32 );
2339         rPropMap.setProperty( PROP_VisibleSize, nThumbLen );
2340     }
2341     rConv.convertColor( rPropMap, PROP_SymbolColor, mnArrowColor );
2342     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, ApiTransparencyMode::NotSupported );
2343     ControlConverter::convertAxOrientation( rPropMap, maSize, mnOrientation );
2344     ControlConverter::convertScrollBar( rPropMap, mnMin, mnMax, mnPosition, mnSmallChange, mnLargeChange, mbAwtModel );
2345     AxControlModelBase::convertProperties( rPropMap, rConv );
2346 }
2347 
convertFromProperties(PropertySet & rPropSet,const ControlConverter &)2348 void AxScrollBarModel::convertFromProperties( PropertySet& rPropSet, const ControlConverter& )
2349 {
2350     bool bRes = false;
2351     if ( rPropSet.getProperty( bRes,  PROP_Enabled ) )
2352         setFlag( mnFlags, AX_FLAGS_ENABLED, bRes );
2353     rPropSet.getProperty( mnDelay, PROP_RepeatDelay );
2354     mnPropThumb = AX_PROPTHUMB_ON; // default
2355     ControlConverter::convertToMSColor( rPropSet, PROP_SymbolColor, mnArrowColor);
2356     ControlConverter::convertToMSColor( rPropSet, PROP_BackgroundColor, mnBackColor );
2357     ControlConverter::convertToAxOrientation( rPropSet, mnOrientation );
2358 
2359     rPropSet.getProperty( mnMin, PROP_ScrollValueMin );
2360     rPropSet.getProperty( mnMax, PROP_ScrollValueMax );
2361     rPropSet.getProperty( mnSmallChange, PROP_LineIncrement );
2362     rPropSet.getProperty( mnLargeChange, PROP_BlockIncrement );
2363     rPropSet.getProperty( mnPosition, ( mbAwtModel ? PROP_ScrollValue : PROP_DefaultScrollValue ) );
2364 
2365 }
2366 
AxContainerModelBase(bool bFontSupport)2367 AxContainerModelBase::AxContainerModelBase( bool bFontSupport ) :
2368     AxFontDataModel( false ),   // no support for alignment properties
2369     maLogicalSize( AX_CONTAINER_DEFWIDTH, AX_CONTAINER_DEFHEIGHT ),
2370     maScrollPos( 0, 0 ),
2371     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
2372     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
2373     mnFlags( AX_CONTAINER_DEFFLAGS ),
2374     mnBorderColor( AX_SYSCOLOR_BUTTONTEXT ),
2375     mnBorderStyle( AX_BORDERSTYLE_NONE ),
2376     mnScrollBars( AX_CONTAINER_SCR_NONE ),
2377     mnCycleType( AX_CONTAINER_CYCLEALL ),
2378     mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
2379     mnPicAlign( AX_PICALIGN_CENTER ),
2380     mnPicSizeMode( AX_PICSIZE_CLIP ),
2381     mbPicTiling( false ),
2382     mbFontSupport( bFontSupport )
2383 {
2384     setAwtModelMode();
2385     // different default size for frame
2386     maSize = AxPairData( AX_CONTAINER_DEFWIDTH, AX_CONTAINER_DEFHEIGHT );
2387 }
2388 
importProperty(sal_Int32 nPropId,const OUString & rValue)2389 void AxContainerModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
2390 {
2391     if( nPropId == XML_Caption )
2392         maCaption = rValue;
2393 }
2394 
importBinaryModel(BinaryInputStream & rInStrm)2395 bool AxContainerModelBase::importBinaryModel( BinaryInputStream& rInStrm )
2396 {
2397     AxBinaryPropertyReader aReader( rInStrm );
2398     aReader.skipUndefinedProperty();
2399     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
2400     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
2401     aReader.skipIntProperty< sal_uInt32 >(); // next available control ID
2402     aReader.skipUndefinedProperty();
2403     aReader.skipUndefinedProperty();
2404     aReader.readIntProperty< sal_uInt32 >( mnFlags );
2405     aReader.readIntProperty< sal_uInt8 >( mnBorderStyle );
2406     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
2407     aReader.readIntProperty< sal_uInt8 >( mnScrollBars );
2408     aReader.readPairProperty( maSize );
2409     aReader.readPairProperty( maLogicalSize );
2410     aReader.readPairProperty( maScrollPos );
2411     aReader.skipIntProperty< sal_uInt32 >(); // number of control groups
2412     aReader.skipUndefinedProperty();
2413     aReader.skipPictureProperty(); // mouse icon
2414     aReader.readIntProperty< sal_uInt8 >( mnCycleType );
2415     aReader.readIntProperty< sal_uInt8 >( mnSpecialEffect );
2416     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
2417     aReader.readStringProperty( maCaption );
2418     aReader.readFontProperty( maFontData );
2419     aReader.readPictureProperty( maPictureData );
2420     aReader.skipIntProperty< sal_Int32 >(); // zoom
2421     aReader.readIntProperty< sal_uInt8 >( mnPicAlign );
2422     aReader.readBoolProperty( mbPicTiling );
2423     aReader.readIntProperty< sal_uInt8 >( mnPicSizeMode );
2424     aReader.skipIntProperty< sal_uInt32 >(); // shape cookie
2425     aReader.skipIntProperty< sal_uInt32 >(); // draw buffer size
2426     return aReader.finalizeImport();
2427 }
2428 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2429 void AxContainerModelBase::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2430 {
2431     if( mbFontSupport )
2432     {
2433         rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
2434         AxFontDataModel::convertProperties( rPropMap, rConv );
2435     }
2436 }
2437 
importClassTable(BinaryInputStream & rInStrm,AxClassTable & orClassTable)2438 bool AxContainerModelBase::importClassTable( BinaryInputStream& rInStrm, AxClassTable& orClassTable )
2439 {
2440     bool bValid = true;
2441     orClassTable.clear();
2442     if( !getFlag( mnFlags, AX_CONTAINER_NOCLASSTABLE ) )
2443     {
2444         sal_uInt16 nCount = rInStrm.readuInt16();
2445         for( sal_uInt16 nIndex = 0; bValid && (nIndex < nCount); ++nIndex )
2446         {
2447             orClassTable.emplace_back( );
2448             AxBinaryPropertyReader aReader( rInStrm );
2449             aReader.readGuidProperty( orClassTable.back() );
2450             aReader.skipGuidProperty(); // source interface GUID
2451             aReader.skipUndefinedProperty();
2452             aReader.skipGuidProperty(); // default interface GUID
2453             aReader.skipIntProperty< sal_uInt32 >(); // class table and var flags
2454             aReader.skipIntProperty< sal_uInt32 >(); // method count
2455             aReader.skipIntProperty< sal_Int32 >(); // IDispatch identifier for linked cell access
2456             aReader.skipIntProperty< sal_uInt16 >(); // get function index for linked cell access
2457             aReader.skipIntProperty< sal_uInt16 >(); // put function index for linked cell access
2458             aReader.skipIntProperty< sal_uInt16 >(); // linked cell access property type
2459             aReader.skipIntProperty< sal_uInt16 >(); // get function index of value
2460             aReader.skipIntProperty< sal_uInt16 >(); // put function index of value
2461             aReader.skipIntProperty< sal_uInt16 >(); // value type
2462             aReader.skipIntProperty< sal_Int32 >(); // IDispatch identifier for source range access
2463             aReader.skipIntProperty< sal_uInt16 >(); // get function index for source range access
2464             bValid = aReader.finalizeImport();
2465         }
2466     }
2467     return bValid;
2468 }
2469 
AxFrameModel()2470 AxFrameModel::AxFrameModel() :
2471     AxContainerModelBase( true )
2472 {
2473 }
2474 
getControlType() const2475 ApiControlType AxFrameModel::getControlType() const
2476 {
2477     return mbAwtModel ? API_CONTROL_FRAME : API_CONTROL_GROUPBOX;
2478 }
2479 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2480 void AxFrameModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2481 {
2482     rPropMap.setProperty( PROP_Label, maCaption );
2483     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) );
2484     AxContainerModelBase::convertProperties( rPropMap, rConv );
2485 }
2486 
AxPageModel()2487 AxPageModel::AxPageModel()
2488 {
2489 }
2490 
getControlType() const2491 ApiControlType AxPageModel::getControlType() const
2492 {
2493     return API_CONTROL_PAGE;
2494 }
2495 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2496 void AxPageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2497 {
2498     rPropMap.setProperty( PROP_Title, maCaption );
2499     rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor );
2500     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) );
2501     AxContainerModelBase::convertProperties( rPropMap, rConv );
2502 }
2503 
AxMultiPageModel()2504 AxMultiPageModel::AxMultiPageModel() :
2505     mnActiveTab( 0 ),
2506     mnTabStyle( AX_TABSTRIP_TABS )
2507 {
2508 }
2509 
getControlType() const2510 ApiControlType AxMultiPageModel::getControlType() const
2511 {
2512     return API_CONTROL_MULTIPAGE;
2513 }
2514 
importPageAndMultiPageProperties(BinaryInputStream & rInStrm,sal_Int32 nPages)2515 void AxMultiPageModel::importPageAndMultiPageProperties( BinaryInputStream& rInStrm, sal_Int32 nPages )
2516 {
2517     // PageProperties
2518     for ( sal_Int32 nPage = 0; nPage < nPages; ++nPage )
2519     {
2520         AxBinaryPropertyReader aReader( rInStrm );
2521         aReader.skipUndefinedProperty();
2522         aReader.skipIntProperty< sal_uInt32 >(); // TransitionEffect
2523         aReader.skipIntProperty< sal_uInt32 >(); // TransitionPeriod
2524     }
2525     // MultiPageProperties
2526     AxBinaryPropertyReader aReader( rInStrm );
2527     sal_uInt32 nPageCount = 0;
2528     aReader.skipUndefinedProperty();
2529     aReader.readIntProperty< sal_uInt32 >(nPageCount); // PageCount
2530     aReader.skipIntProperty< sal_uInt32 >(); //ID
2531 
2532     // IDs
2533     for ( sal_uInt32 count = 0; count < nPageCount; ++count )
2534     {
2535         mnIDs.push_back( rInStrm.readInt32() );
2536     }
2537 }
2538 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2539 void AxMultiPageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2540 {
2541     rPropMap.setProperty( PROP_Title, maCaption );
2542     rPropMap.setProperty( PROP_MultiPageValue, mnActiveTab + 1);
2543     rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor );
2544     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) );
2545     rPropMap.setProperty( PROP_Decoration, mnTabStyle != AX_TABSTRIP_NONE );
2546 
2547     AxContainerModelBase::convertProperties( rPropMap, rConv );
2548 }
2549 
AxUserFormModel()2550 AxUserFormModel::AxUserFormModel()
2551 {
2552 }
2553 
getControlType() const2554 ApiControlType AxUserFormModel::getControlType() const
2555 {
2556     return API_CONTROL_DIALOG;
2557 }
2558 
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2559 void AxUserFormModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2560 {
2561     rPropMap.setProperty( PROP_Title, maCaption );
2562     rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor );
2563     rConv.convertAxPicture( rPropMap, maPictureData, AX_PICPOS_CENTER  );
2564     rConv.convertScrollabilitySettings( rPropMap, maScrollPos, maLogicalSize, mnScrollBars );
2565     AxContainerModelBase::convertProperties( rPropMap, rConv );
2566 }
2567 
HtmlSelectModel()2568 HtmlSelectModel::HtmlSelectModel()
2569 {
2570 }
2571 
2572 bool
importBinaryModel(BinaryInputStream & rInStrm)2573 HtmlSelectModel::importBinaryModel( BinaryInputStream& rInStrm )
2574 {
2575     if (rInStrm.size()<=0)
2576         return true;
2577 
2578     OUString sStringContents = rInStrm.readUnicodeArray( rInStrm.size() );
2579 
2580     // replace crlf with lf
2581     OUString data = sStringContents.replaceAll( "\x0D\x0A" , "\x0A" );
2582 
2583     std::vector< OUString > listValues;
2584     std::vector< sal_Int16 > selectedIndices;
2585 
2586     // Ultra hacky parser for the info
2587     sal_Int32 nLineIdx {0};
2588     // first line will tell us if multiselect is enabled
2589     if (data.getToken( 0, '\n', nLineIdx )=="<SELECT MULTIPLE")
2590         mnMultiSelect = AX_SELECTION_MULTI;
2591     // skip first and last lines, no data there
2592     if (nLineIdx>0)
2593     {
2594         for (;;)
2595         {
2596             OUString sLine( data.getToken( 0, '\n', nLineIdx ) );
2597             if (nLineIdx<0)
2598                 break;  // skip last line
2599 
2600             if ( !sLine.isEmpty() )
2601             {
2602                 OUString displayValue  = sLine.getToken( 1, '>' );
2603                 if ( displayValue.getLength() )
2604                 {
2605                     // Really we should be using a proper html parser
2606                     // escaping some common bits to be escaped
2607                     displayValue = displayValue.replaceAll( "&lt;", "<" );
2608                     displayValue = displayValue.replaceAll( "&gt;", ">" );
2609                     displayValue = displayValue.replaceAll( "&quot;", "\"" );
2610                     displayValue = displayValue.replaceAll( "&amp;", "&" );
2611                     listValues.push_back( displayValue );
2612                     if( sLine.indexOf( "OPTION SELECTED" ) != -1 )
2613                         selectedIndices.push_back( static_cast< sal_Int16 >( listValues.size() ) - 1 );
2614                 }
2615             }
2616         }
2617     }
2618     if ( !listValues.empty() )
2619     {
2620         msListData.realloc( listValues.size() );
2621         sal_Int32 index = 0;
2622         for (auto const& listValue : listValues)
2623              msListData[ index++ ] = listValue;
2624     }
2625     if ( !selectedIndices.empty() )
2626     {
2627         msIndices.realloc( selectedIndices.size() );
2628         sal_Int32 index = 0;
2629         for (auto const& selectedIndice : selectedIndices)
2630              msIndices[ index++ ] = selectedIndice;
2631     }
2632     return true;
2633 }
2634 
2635 void
convertProperties(PropertyMap & rPropMap,const ControlConverter & rConv) const2636 HtmlSelectModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
2637 {
2638    rPropMap.setProperty( PROP_StringItemList, msListData );
2639    rPropMap.setProperty( PROP_SelectedItems, msIndices );
2640    rPropMap.setProperty( PROP_Dropdown, true );
2641    AxListBoxModel::convertProperties( rPropMap, rConv );
2642 }
2643 
HtmlTextBoxModel()2644 HtmlTextBoxModel::HtmlTextBoxModel()
2645 {
2646 }
2647 
2648 bool
importBinaryModel(BinaryInputStream & rInStrm)2649 HtmlTextBoxModel::importBinaryModel( BinaryInputStream& rInStrm )
2650 {
2651 #ifdef DEBUG
2652     OUString sStringContents = rInStrm.readUnicodeArray( rInStrm.size() );
2653     // in msocximex ( where this is ported from, it appears *nothing* is read
2654     // from the control stream ), surely there is some useful info there ?
2655     SAL_WARN("oox", "HtmlTextBoxModel::importBinaryModel - string contents of stream: " << sStringContents );
2656 #else
2657     (void) rInStrm;
2658 #endif
2659     return true;
2660 }
2661 
EmbeddedControl(const OUString & rName)2662 EmbeddedControl::EmbeddedControl( const OUString& rName ) :
2663     maName( rName )
2664 {
2665 }
2666 
createModelFromGuid(const OUString & rClassId)2667 ControlModelBase* EmbeddedControl::createModelFromGuid( const OUString& rClassId )
2668 {
2669     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_COMMANDBUTTON ) )     return &createModel< AxCommandButtonModel >();
2670     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_LABEL ) )             return &createModel< AxLabelModel >();
2671     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_IMAGE ) )             return &createModel< AxImageModel >();
2672     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_TOGGLEBUTTON ) )      return &createModel< AxToggleButtonModel >();
2673     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_CHECKBOX ) )          return &createModel< AxCheckBoxModel >();
2674     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_OPTIONBUTTON ) )      return &createModel< AxOptionButtonModel >();
2675     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_TEXTBOX ) )           return &createModel< AxTextBoxModel >();
2676     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_LISTBOX ) )           return &createModel< AxListBoxModel >();
2677     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_COMBOBOX ) )          return &createModel< AxComboBoxModel >();
2678     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_SPINBUTTON ) )        return &createModel< AxSpinButtonModel >();
2679     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_SCROLLBAR ) )         return &createModel< AxScrollBarModel >();
2680     if( rClassId.equalsIgnoreAsciiCase( AX_GUID_FRAME ) )             return &createModel< AxFrameModel >();
2681     if( rClassId.equalsIgnoreAsciiCase( COMCTL_GUID_SCROLLBAR_60 ) )  return &createModel< ComCtlScrollBarModel >( COMCTL_VERSION_60 );
2682     if( rClassId.equalsIgnoreAsciiCase( HTML_GUID_SELECT ) )  return &createModel< HtmlSelectModel >();
2683     if( rClassId.equalsIgnoreAsciiCase( HTML_GUID_TEXTBOX ) ) return &createModel< HtmlTextBoxModel >();
2684 
2685     mxModel.reset();
2686     return nullptr;
2687 }
2688 
getServiceName() const2689 OUString EmbeddedControl::getServiceName() const
2690 {
2691     return mxModel ? mxModel->getServiceName() : OUString();
2692 }
2693 
convertProperties(const Reference<XControlModel> & rxCtrlModel,const ControlConverter & rConv) const2694 bool EmbeddedControl::convertProperties( const Reference< XControlModel >& rxCtrlModel, const ControlConverter& rConv ) const
2695 {
2696     if( mxModel && rxCtrlModel.is() && !maName.isEmpty() )
2697     {
2698         PropertyMap aPropMap;
2699         aPropMap.setProperty( PROP_Name, maName );
2700         try
2701         {
2702             aPropMap.setProperty( PROP_GenerateVbaEvents, true);
2703         }
2704         catch (const Exception&)
2705         {
2706             TOOLS_WARN_EXCEPTION("oox", "");
2707         }
2708         mxModel->convertProperties( aPropMap, rConv );
2709         PropertySet aPropSet( rxCtrlModel );
2710         aPropSet.setProperties( aPropMap );
2711         return true;
2712     }
2713     return false;
2714 }
2715 
convertFromProperties(const Reference<XControlModel> & rxCtrlModel,const ControlConverter & rConv)2716 void EmbeddedControl::convertFromProperties( const Reference< XControlModel >& rxCtrlModel, const ControlConverter& rConv )
2717 {
2718     if( mxModel && rxCtrlModel.is() && !maName.isEmpty() )
2719     {
2720         PropertySet aPropSet( rxCtrlModel );
2721         aPropSet.getProperty( maName, PROP_Name );
2722         mxModel->convertFromProperties( aPropSet, rConv );
2723     }
2724 }
2725 
EmbeddedForm(const Reference<XModel> & rxDocModel,const Reference<XDrawPage> & rxDrawPage,const GraphicHelper & rGraphicHelper)2726 EmbeddedForm::EmbeddedForm( const Reference< XModel >& rxDocModel,
2727         const Reference< XDrawPage >& rxDrawPage, const GraphicHelper& rGraphicHelper ) :
2728     maControlConv( rxDocModel, rGraphicHelper, true/*bDefaultColorBgr*/ ),
2729     mxModelFactory( rxDocModel, UNO_QUERY ),
2730     mxFormsSupp( rxDrawPage, UNO_QUERY )
2731 {
2732     OSL_ENSURE( mxModelFactory.is(), "EmbeddedForm::EmbeddedForm - missing service factory" );
2733 }
2734 
convertAndInsert(const EmbeddedControl & rControl,sal_Int32 & rnCtrlIndex)2735 Reference< XControlModel > EmbeddedForm::convertAndInsert( const EmbeddedControl& rControl, sal_Int32& rnCtrlIndex )
2736 {
2737     Reference< XControlModel > xRet;
2738     if( mxModelFactory.is() && rControl.hasModel() ) try
2739     {
2740         // create the UNO control model
2741         OUString aServiceName = rControl.getServiceName();
2742         Reference< XFormComponent > xFormComp( mxModelFactory->createInstance( aServiceName ), UNO_QUERY_THROW );
2743         Reference< XControlModel > xCtrlModel( xFormComp, UNO_QUERY_THROW );
2744 
2745         // convert the control properties
2746         if( rControl.convertProperties( xCtrlModel, maControlConv ) )
2747             xRet = xCtrlModel;
2748         // insert the control into the form
2749         Reference< XIndexContainer > xFormIC( createXForm(), UNO_SET_THROW );
2750         rnCtrlIndex = xFormIC->getCount();
2751         xFormIC->insertByIndex( rnCtrlIndex, Any( xFormComp ) );
2752     }
2753     catch (const Exception&)
2754     {
2755         TOOLS_WARN_EXCEPTION("oox", "exception creating Control");
2756     }
2757     return xRet;
2758 }
2759 
createXForm()2760 Reference< XIndexContainer > const & EmbeddedForm::createXForm()
2761 {
2762     if( mxFormsSupp.is() )
2763     {
2764         try
2765         {
2766             Reference< XNameContainer > xFormsNC( mxFormsSupp->getForms(), UNO_SET_THROW );
2767             OUString aFormName = "Standard";
2768             if( xFormsNC->hasByName( aFormName ) )
2769             {
2770                 mxFormIC.set( xFormsNC->getByName( aFormName ), UNO_QUERY_THROW );
2771             }
2772             else if( mxModelFactory.is() )
2773             {
2774                 Reference< XForm > xForm( mxModelFactory->createInstance( "com.sun.star.form.component.Form" ), UNO_QUERY_THROW );
2775                 xFormsNC->insertByName( aFormName, Any( xForm ) );
2776                 mxFormIC.set( xForm, UNO_QUERY_THROW );
2777             }
2778         }
2779         catch (const Exception&)
2780         {
2781             TOOLS_WARN_EXCEPTION("oox", "exception creating Form");
2782         }
2783         // always clear the forms supplier to not try to create the form again
2784         mxFormsSupp.clear();
2785     }
2786     return mxFormIC;
2787 }
2788 
2789 } // namespace oox
2790 
2791 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2792