xref: /aoo42x/main/oox/source/ole/axcontrol.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "oox/ole/axcontrol.hxx"
29 
30 #include <com/sun/star/awt/FontSlant.hpp>
31 #include <com/sun/star/awt/FontStrikeout.hpp>
32 #include <com/sun/star/awt/FontUnderline.hpp>
33 #include <com/sun/star/awt/FontWeight.hpp>
34 #include <com/sun/star/awt/ImagePosition.hpp>
35 #include <com/sun/star/awt/ImageScaleMode.hpp>
36 #include <com/sun/star/awt/Point.hpp>
37 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
38 #include <com/sun/star/awt/Size.hpp>
39 #include <com/sun/star/awt/TextAlign.hpp>
40 #include <com/sun/star/awt/VisualEffect.hpp>
41 #include <com/sun/star/awt/XControlModel.hpp>
42 #include <com/sun/star/beans/NamedValue.hpp>
43 #include <com/sun/star/container/XIndexContainer.hpp>
44 #include <com/sun/star/form/XForm.hpp>
45 #include <com/sun/star/form/XFormComponent.hpp>
46 #include <com/sun/star/form/XFormsSupplier.hpp>
47 #include <com/sun/star/form/binding/XBindableValue.hpp>
48 #include <com/sun/star/form/binding/XListEntrySink.hpp>
49 #include <com/sun/star/form/binding/XListEntrySource.hpp>
50 #include <com/sun/star/form/binding/XValueBinding.hpp>
51 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
52 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
53 #include <com/sun/star/sheet/XCellRangeReferrer.hpp>
54 #include <com/sun/star/style/VerticalAlignment.hpp>
55 #include <com/sun/star/table/CellAddress.hpp>
56 #include <com/sun/star/table/CellRangeAddress.hpp>
57 #include <rtl/tencinfo.h>
58 #include "oox/helper/attributelist.hxx"
59 #include "oox/helper/binaryinputstream.hxx"
60 #include "oox/helper/containerhelper.hxx"
61 #include "oox/helper/graphichelper.hxx"
62 #include "oox/helper/propertymap.hxx"
63 
64 namespace oox {
65 namespace ole {
66 
67 // ============================================================================
68 
69 using namespace ::com::sun::star::awt;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::container;
72 using namespace ::com::sun::star::drawing;
73 using namespace ::com::sun::star::form;
74 using namespace ::com::sun::star::form::binding;
75 using namespace ::com::sun::star::frame;
76 using namespace ::com::sun::star::lang;
77 using namespace ::com::sun::star::sheet;
78 using namespace ::com::sun::star::style;
79 using namespace ::com::sun::star::table;
80 using namespace ::com::sun::star::uno;
81 
82 using ::rtl::OUString;
83 
84 // ============================================================================
85 
86 namespace {
87 
88 const sal_uInt32 COMCTL_ID_SIZE             = 0x12344321;
89 
90 const sal_uInt32 COMCTL_ID_COMMONDATA       = 0xABCDEF01;
91 const sal_uInt32 COMCTL_COMMON_FLATBORDER   = 0x00000001;
92 const sal_uInt32 COMCTL_COMMON_ENABLED      = 0x00000002;
93 const sal_uInt32 COMCTL_COMMON_3DBORDER     = 0x00000004;
94 const sal_uInt32 COMCTL_COMMON_OLEDROPMAN   = 0x00002000;
95 
96 const sal_uInt32 COMCTL_ID_COMPLEXDATA      = 0xBDECDE1F;
97 const sal_uInt32 COMCTL_COMPLEX_FONT        = 0x00000001;
98 const sal_uInt32 COMCTL_COMPLEX_MOUSEICON   = 0x00000002;
99 
100 const sal_uInt32 COMCTL_ID_SCROLLBAR_60     = 0x99470A83;
101 const sal_uInt32 COMCTL_SCROLLBAR_HOR       = 0x00000010;
102 const sal_Int32 COMCTL_SCROLLBAR_3D         = 0;
103 const sal_Int32 COMCTL_SCROLLBAR_FLAT       = 1;
104 const sal_Int32 COMCTL_SCROLLBAR_TRACK3D    = 2;
105 
106 const sal_uInt32 COMCTL_ID_PROGRESSBAR_50   = 0xE6E17E84;
107 const sal_uInt32 COMCTL_ID_PROGRESSBAR_60   = 0x97AB8A01;
108 
109 // ----------------------------------------------------------------------------
110 
111 const sal_uInt32 AX_CMDBUTTON_DEFFLAGS      = 0x0000001B;
112 const sal_uInt32 AX_LABEL_DEFFLAGS          = 0x0080001B;
113 const sal_uInt32 AX_IMAGE_DEFFLAGS          = 0x0000001B;
114 const sal_uInt32 AX_MORPHDATA_DEFFLAGS      = 0x2C80081B;
115 const sal_uInt32 AX_SPINBUTTON_DEFFLAGS     = 0x0000001B;
116 const sal_uInt32 AX_SCROLLBAR_DEFFLAGS      = 0x0000001B;
117 const sal_uInt32 AX_TABSTRIP_DEFFLAGS       = 0x0000001B;
118 
119 const sal_uInt16 AX_POS_TOPLEFT             = 0;
120 const sal_uInt16 AX_POS_TOP                 = 1;
121 const sal_uInt16 AX_POS_TOPRIGHT            = 2;
122 const sal_uInt16 AX_POS_LEFT                = 3;
123 const sal_uInt16 AX_POS_CENTER              = 4;
124 const sal_uInt16 AX_POS_RIGHT               = 5;
125 const sal_uInt16 AX_POS_BOTTOMLEFT          = 6;
126 const sal_uInt16 AX_POS_BOTTOM              = 7;
127 const sal_uInt16 AX_POS_BOTTOMRIGHT         = 8;
128 
129 #define AX_PICPOS_IMPL( label, image ) ((AX_POS_##label << 16) | AX_POS_##image)
130 const sal_uInt32 AX_PICPOS_LEFTTOP          = AX_PICPOS_IMPL( TOPRIGHT,    TOPLEFT );
131 const sal_uInt32 AX_PICPOS_LEFTCENTER       = AX_PICPOS_IMPL( RIGHT,       LEFT );
132 const sal_uInt32 AX_PICPOS_LEFTBOTTOM       = AX_PICPOS_IMPL( BOTTOMRIGHT, BOTTOMLEFT );
133 const sal_uInt32 AX_PICPOS_RIGHTTOP         = AX_PICPOS_IMPL( TOPLEFT,     TOPRIGHT );
134 const sal_uInt32 AX_PICPOS_RIGHTCENTER      = AX_PICPOS_IMPL( LEFT,        RIGHT );
135 const sal_uInt32 AX_PICPOS_RIGHTBOTTOM      = AX_PICPOS_IMPL( BOTTOMLEFT,  BOTTOMRIGHT );
136 const sal_uInt32 AX_PICPOS_ABOVELEFT        = AX_PICPOS_IMPL( BOTTOMLEFT,  TOPLEFT );
137 const sal_uInt32 AX_PICPOS_ABOVECENTER      = AX_PICPOS_IMPL( BOTTOM,      TOP  );
138 const sal_uInt32 AX_PICPOS_ABOVERIGHT       = AX_PICPOS_IMPL( BOTTOMRIGHT, TOPRIGHT );
139 const sal_uInt32 AX_PICPOS_BELOWLEFT        = AX_PICPOS_IMPL( TOPLEFT,     BOTTOMLEFT );
140 const sal_uInt32 AX_PICPOS_BELOWCENTER      = AX_PICPOS_IMPL( TOP,         BOTTOM );
141 const sal_uInt32 AX_PICPOS_BELOWRIGHT       = AX_PICPOS_IMPL( TOPRIGHT,    BOTTOMRIGHT );
142 const sal_uInt32 AX_PICPOS_CENTER           = AX_PICPOS_IMPL( CENTER,      CENTER  );
143 #undef AX_PICPOS_IMPL
144 
145 const sal_Int32 AX_MATCHENTRY_FIRSTLETTER   = 0;
146 const sal_Int32 AX_MATCHENTRY_COMPLETE      = 1;
147 const sal_Int32 AX_MATCHENTRY_NONE          = 2;
148 
149 const sal_Int32 AX_ORIENTATION_AUTO         = -1;
150 const sal_Int32 AX_ORIENTATION_VERTICAL     = 0;
151 const sal_Int32 AX_ORIENTATION_HORIZONTAL   = 1;
152 
153 const sal_Int32 AX_PROPTHUMB_ON             = -1;
154 const sal_Int32 AX_PROPTHUMB_OFF            = 0;
155 
156 const sal_uInt32 AX_TABSTRIP_TABS           = 0;
157 const sal_uInt32 AX_TABSTRIP_BUTTONS        = 1;
158 const sal_uInt32 AX_TABSTRIP_NONE           = 2;
159 
160 const sal_uInt32 AX_CONTAINER_ENABLED       = 0x00000004;
161 const sal_uInt32 AX_CONTAINER_HASDESIGNEXT  = 0x00004000;
162 const sal_uInt32 AX_CONTAINER_NOCLASSTABLE  = 0x00008000;
163 
164 const sal_uInt32 AX_CONTAINER_DEFFLAGS      = 0x00000004;
165 
166 const sal_Int32 AX_CONTAINER_DEFWIDTH       = 4000;
167 const sal_Int32 AX_CONTAINER_DEFHEIGHT      = 3000;
168 
169 const sal_Int32 AX_CONTAINER_CYCLEALL       = 0;
170 const sal_Int32 AX_CONTAINER_CYCLECURRENT   = 2;
171 
172 const sal_Int32 AX_CONTAINER_SCR_NONE       = 0x00;
173 const sal_Int32 AX_CONTAINER_SCR_HOR        = 0x01;
174 const sal_Int32 AX_CONTAINER_SCR_VER        = 0x02;
175 const sal_Int32 AX_CONTAINER_SCR_KEEP_HOR   = 0x04;
176 const sal_Int32 AX_CONTAINER_SCR_KEEP_VER   = 0x08;
177 const sal_Int32 AX_CONTAINER_SCR_SHOW_LEFT  = 0x10;
178 
179 // ----------------------------------------------------------------------------
180 
181 const sal_Int16 API_BORDER_NONE             = 0;
182 const sal_Int16 API_BORDER_SUNKEN           = 1;
183 const sal_Int16 API_BORDER_FLAT             = 2;
184 
185 const sal_Int16 API_STATE_UNCHECKED         = 0;
186 const sal_Int16 API_STATE_CHECKED           = 1;
187 const sal_Int16 API_STATE_DONTKNOW          = 2;
188 
189 // ----------------------------------------------------------------------------
190 
191 /** Tries to extract a range address from a defined name. */
192 bool lclExtractRangeFromName( CellRangeAddress& orRangeAddr, const Reference< XModel >& rxDocModel, const OUString& rAddressString )
193 {
194     try
195     {
196         PropertySet aPropSet( rxDocModel );
197         Reference< XNameAccess > xRangesNA( aPropSet.getAnyProperty( PROP_NamedRanges ), UNO_QUERY_THROW );
198         Reference< XCellRangeReferrer > xReferrer( xRangesNA->getByName( rAddressString ), UNO_QUERY_THROW );
199         Reference< XCellRangeAddressable > xAddressable( xReferrer->getReferredCells(), UNO_QUERY_THROW );
200         orRangeAddr = xAddressable->getRangeAddress();
201         return true;
202     }
203     catch( Exception& )
204     {
205     }
206     return false;
207 }
208 
209 bool lclExtractAddressFromName( CellAddress& orAddress, const Reference< XModel >& rxDocModel, const OUString& rAddressString )
210 {
211     CellRangeAddress aRangeAddr;
212     if( lclExtractRangeFromName( aRangeAddr, rxDocModel, rAddressString ) &&
213         (aRangeAddr.StartColumn == aRangeAddr.EndColumn) &&
214         (aRangeAddr.StartRow == aRangeAddr.EndRow) )
215     {
216         orAddress.Sheet = aRangeAddr.Sheet;
217         orAddress.Column = aRangeAddr.StartColumn;
218         orAddress.Row = aRangeAddr.StartRow;
219         return true;
220     }
221     return false;
222 }
223 
224 void lclPrepareConverter( PropertySet& rConverter, const Reference< XModel >& rxDocModel,
225         const OUString& rAddressString, sal_Int32 nRefSheet, bool bRange )
226 {
227     if( !rConverter.is() ) try
228     {
229         Reference< XMultiServiceFactory > xModelFactory( rxDocModel, UNO_QUERY_THROW );
230         OUString aServiceName = bRange ?
231             CREATE_OUSTRING( "com.sun.star.table.CellRangeAddressConversion" ) :
232             CREATE_OUSTRING( "com.sun.star.table.CellAddressConversion" );
233         rConverter.set( xModelFactory->createInstance( aServiceName ) );
234     }
235     catch( Exception& )
236     {
237     }
238     rConverter.setProperty( PROP_XLA1Representation, rAddressString );
239     rConverter.setProperty( PROP_ReferenceSheet, nRefSheet );
240 }
241 
242 } // namespace
243 
244 // ============================================================================
245 
246 ControlConverter::ControlConverter( const Reference< XModel >& rxDocModel,
247         const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr ) :
248     mxDocModel( rxDocModel ),
249     mrGraphicHelper( rGraphicHelper ),
250     mbDefaultColorBgr( bDefaultColorBgr )
251 {
252     OSL_ENSURE( mxDocModel.is(), "ControlConverter::ControlConverter - missing document model" );
253 }
254 
255 ControlConverter::~ControlConverter()
256 {
257 }
258 
259 // Generic conversion ---------------------------------------------------------
260 
261 void ControlConverter::convertPosition( PropertyMap& rPropMap, const AxPairData& rPos ) const
262 {
263     // position is given in 1/100 mm, UNO needs AppFont units
264     Point aAppFontPos = mrGraphicHelper.convertHmmToAppFont( Point( rPos.first, rPos.second ) );
265     rPropMap.setProperty( PROP_PositionX, aAppFontPos.X );
266     rPropMap.setProperty( PROP_PositionY, aAppFontPos.Y );
267 }
268 
269 void ControlConverter::convertSize( PropertyMap& rPropMap, const AxPairData& rSize ) const
270 {
271     // size is given in 1/100 mm, UNO needs AppFont units
272     Size aAppFontSize = mrGraphicHelper.convertHmmToAppFont( Size( rSize.first, rSize.second ) );
273     rPropMap.setProperty( PROP_Width, aAppFontSize.Width );
274     rPropMap.setProperty( PROP_Height, aAppFontSize.Height );
275 }
276 
277 void ControlConverter::convertColor( PropertyMap& rPropMap, sal_Int32 nPropId, sal_uInt32 nOleColor ) const
278 {
279     rPropMap.setProperty( nPropId, OleHelper::decodeOleColor( mrGraphicHelper, nOleColor, mbDefaultColorBgr ) );
280 }
281 
282 void ControlConverter::convertPicture( PropertyMap& rPropMap, const StreamDataSequence& rPicData ) const
283 {
284     if( rPicData.hasElements() )
285     {
286         OUString aGraphicUrl = mrGraphicHelper.importGraphicObject( rPicData );
287         if( aGraphicUrl.getLength() > 0 )
288             rPropMap.setProperty( PROP_ImageURL, aGraphicUrl );
289     }
290 }
291 
292 void ControlConverter::convertOrientation( PropertyMap& rPropMap, bool bHorizontal ) const
293 {
294     sal_Int32 nScrollOrient = bHorizontal ? ScrollBarOrientation::HORIZONTAL : ScrollBarOrientation::VERTICAL;
295     rPropMap.setProperty( PROP_Orientation, nScrollOrient );
296 }
297 
298 void ControlConverter::convertVerticalAlign( PropertyMap& rPropMap, sal_Int32 nVerticalAlign ) const
299 {
300     VerticalAlignment eAlign = VerticalAlignment_TOP;
301     switch( nVerticalAlign )
302     {
303         case XML_Top:       eAlign = VerticalAlignment_TOP;     break;
304         case XML_Center:    eAlign = VerticalAlignment_MIDDLE;  break;
305         case XML_Bottom:    eAlign = VerticalAlignment_BOTTOM;  break;
306     }
307     rPropMap.setProperty( PROP_VerticalAlign, eAlign );
308 }
309 
310 void ControlConverter::convertScrollBar( PropertyMap& rPropMap,
311         sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nPosition,
312         sal_Int32 nSmallChange, sal_Int32 nLargeChange, bool bAwtModel ) const
313 {
314     rPropMap.setProperty( PROP_ScrollValueMin, ::std::min( nMin, nMax ) );
315     rPropMap.setProperty( PROP_ScrollValueMax, ::std::max( nMin, nMax ) );
316     rPropMap.setProperty( PROP_LineIncrement, nSmallChange );
317     rPropMap.setProperty( PROP_BlockIncrement, nLargeChange );
318     rPropMap.setProperty( bAwtModel ? PROP_ScrollValue : PROP_DefaultScrollValue, nPosition );
319 }
320 
321 void ControlConverter::bindToSources( const Reference< XControlModel >& rxCtrlModel,
322         const OUString& rCtrlSource, const OUString& rRowSource, sal_Int32 nRefSheet ) const
323 {
324     // value binding
325     if( rCtrlSource.getLength() > 0 ) try
326     {
327         // first check if the XBindableValue interface is supported
328         Reference< XBindableValue > xBindable( rxCtrlModel, UNO_QUERY_THROW );
329 
330         // convert address string to cell address struct
331         CellAddress aAddress;
332         if( !lclExtractAddressFromName( aAddress, mxDocModel, rCtrlSource ) )
333         {
334             lclPrepareConverter( maAddressConverter, mxDocModel, rCtrlSource, nRefSheet, false );
335             if( !maAddressConverter.getProperty( aAddress, PROP_Address ) )
336                 throw RuntimeException();
337         }
338 
339         // create argument sequence
340         NamedValue aValue;
341         aValue.Name = CREATE_OUSTRING( "BoundCell" );
342         aValue.Value <<= aAddress;
343         Sequence< Any > aArgs( 1 );
344         aArgs[ 0 ] <<= aValue;
345 
346         // create the CellValueBinding instance and set at the control model
347         Reference< XMultiServiceFactory > xModelFactory( mxDocModel, UNO_QUERY_THROW );
348         Reference< XValueBinding > xBinding( xModelFactory->createInstanceWithArguments(
349             CREATE_OUSTRING( "com.sun.star.table.CellValueBinding" ), aArgs ), UNO_QUERY_THROW );
350         xBindable->setValueBinding( xBinding );
351     }
352     catch( Exception& )
353     {
354     }
355 
356     // list entry source
357     if( rRowSource.getLength() > 0 ) try
358     {
359         // first check if the XListEntrySink interface is supported
360         Reference< XListEntrySink > xEntrySink( rxCtrlModel, UNO_QUERY_THROW );
361 
362         // convert address string to cell range address struct
363         CellRangeAddress aRangeAddr;
364         if( !lclExtractRangeFromName( aRangeAddr, mxDocModel, rRowSource ) )
365         {
366             lclPrepareConverter( maRangeConverter, mxDocModel, rRowSource, nRefSheet, true );
367             if( !maRangeConverter.getProperty( aRangeAddr, PROP_Address ) )
368                 throw RuntimeException();
369         }
370 
371         // create argument sequence
372         NamedValue aValue;
373         aValue.Name = CREATE_OUSTRING( "CellRange" );
374         aValue.Value <<= aRangeAddr;
375         Sequence< Any > aArgs( 1 );
376         aArgs[ 0 ] <<= aValue;
377 
378         // create the EntrySource instance and set at the control model
379         Reference< XMultiServiceFactory > xModelFactory( mxDocModel, UNO_QUERY_THROW );
380         Reference< XListEntrySource > xEntrySource( xModelFactory->createInstanceWithArguments(
381             CREATE_OUSTRING( "com.sun.star.table.CellRangeListSource"  ), aArgs ), UNO_QUERY_THROW );
382         xEntrySink->setListEntrySource( xEntrySource );
383     }
384     catch( Exception& )
385     {
386     }
387 }
388 
389 // ActiveX (Forms 2.0) specific conversion ------------------------------------
390 
391 void ControlConverter::convertAxBackground( PropertyMap& rPropMap,
392         sal_uInt32 nBackColor, sal_uInt32 nFlags, ApiTransparencyMode eTranspMode ) const
393 {
394     bool bOpaque = getFlag( nFlags, AX_FLAGS_OPAQUE );
395     switch( eTranspMode )
396     {
397         case API_TRANSPARENCY_NOTSUPPORTED:
398             // fake transparency by using system window background if needed
399             convertColor( rPropMap, PROP_BackgroundColor, bOpaque ? nBackColor : AX_SYSCOLOR_WINDOWBACK );
400         break;
401         case API_TRANSPARENCY_PAINTTRANSPARENT:
402             rPropMap.setProperty( PROP_PaintTransparent, !bOpaque );
403             // run-through intended!
404         case API_TRANSPARENCY_VOID:
405             // keep transparency by leaving the (void) default property value
406             if( bOpaque )
407                 convertColor( rPropMap, PROP_BackgroundColor, nBackColor );
408         break;
409     }
410 }
411 
412 void ControlConverter::convertAxBorder( PropertyMap& rPropMap,
413         sal_uInt32 nBorderColor, sal_Int32 nBorderStyle, sal_Int32 nSpecialEffect ) const
414 {
415     sal_Int16 nBorder = (nBorderStyle == AX_BORDERSTYLE_SINGLE) ? API_BORDER_FLAT :
416         ((nSpecialEffect == AX_SPECIALEFFECT_FLAT) ? API_BORDER_NONE : API_BORDER_SUNKEN);
417     rPropMap.setProperty( PROP_Border, nBorder );
418     convertColor( rPropMap, PROP_BorderColor, nBorderColor );
419 }
420 
421 void ControlConverter::convertAxVisualEffect( PropertyMap& rPropMap, sal_Int32 nSpecialEffect ) const
422 {
423     sal_Int16 nVisualEffect = (nSpecialEffect == AX_SPECIALEFFECT_FLAT) ? VisualEffect::FLAT : VisualEffect::LOOK3D;
424     rPropMap.setProperty( PROP_VisualEffect, nVisualEffect );
425 }
426 
427 void ControlConverter::convertAxPicture( PropertyMap& rPropMap, const StreamDataSequence& rPicData, sal_uInt32 nPicPos ) const
428 {
429     // the picture
430     convertPicture( rPropMap, rPicData );
431 
432     // picture position
433     sal_Int16 nImagePos = ImagePosition::LeftCenter;
434     switch( nPicPos )
435     {
436         case AX_PICPOS_LEFTTOP:     nImagePos = ImagePosition::LeftTop;     break;
437         case AX_PICPOS_LEFTCENTER:  nImagePos = ImagePosition::LeftCenter;  break;
438         case AX_PICPOS_LEFTBOTTOM:  nImagePos = ImagePosition::LeftBottom;  break;
439         case AX_PICPOS_RIGHTTOP:    nImagePos = ImagePosition::RightTop;    break;
440         case AX_PICPOS_RIGHTCENTER: nImagePos = ImagePosition::RightCenter; break;
441         case AX_PICPOS_RIGHTBOTTOM: nImagePos = ImagePosition::RightBottom; break;
442         case AX_PICPOS_ABOVELEFT:   nImagePos = ImagePosition::AboveLeft;   break;
443         case AX_PICPOS_ABOVECENTER: nImagePos = ImagePosition::AboveCenter; break;
444         case AX_PICPOS_ABOVERIGHT:  nImagePos = ImagePosition::AboveRight;  break;
445         case AX_PICPOS_BELOWLEFT:   nImagePos = ImagePosition::BelowLeft;   break;
446         case AX_PICPOS_BELOWCENTER: nImagePos = ImagePosition::BelowCenter; break;
447         case AX_PICPOS_BELOWRIGHT:  nImagePos = ImagePosition::BelowRight;  break;
448         case AX_PICPOS_CENTER:      nImagePos = ImagePosition::Centered;    break;
449         default:    OSL_ENSURE( false, "ControlConverter::convertAxPicture - unknown picture position" );
450     }
451     rPropMap.setProperty( PROP_ImagePosition, nImagePos );
452 }
453 
454 void ControlConverter::convertAxPicture( PropertyMap& rPropMap, const StreamDataSequence& rPicData,
455         sal_Int32 nPicSizeMode, sal_Int32 /*nPicAlign*/, bool /*bPicTiling*/ ) const
456 {
457     // the picture
458     convertPicture( rPropMap, rPicData );
459 
460     // picture scale mode
461     sal_Int16 nScaleMode = ImageScaleMode::None;
462     switch( nPicSizeMode )
463     {
464         case AX_PICSIZE_CLIP:       nScaleMode = ImageScaleMode::None;          break;
465         case AX_PICSIZE_STRETCH:    nScaleMode = ImageScaleMode::Anisotropic;   break;
466         case AX_PICSIZE_ZOOM:       nScaleMode = ImageScaleMode::Isotropic;     break;
467         default:    OSL_ENSURE( false, "ControlConverter::convertAxPicture - unknown picture size mode" );
468     }
469     rPropMap.setProperty( PROP_ScaleMode, nScaleMode );
470 }
471 
472 void ControlConverter::convertAxState( PropertyMap& rPropMap,
473         const OUString& rValue, sal_Int32 nMultiSelect, ApiDefaultStateMode eDefStateMode, bool bAwtModel ) const
474 {
475     bool bBooleanState = eDefStateMode == API_DEFAULTSTATE_BOOLEAN;
476     bool bSupportsTriState = eDefStateMode == API_DEFAULTSTATE_TRISTATE;
477 
478     // state
479     sal_Int16 nState = bSupportsTriState ? API_STATE_DONTKNOW : API_STATE_UNCHECKED;
480     if( rValue.getLength() == 1 ) switch( rValue[ 0 ] )
481     {
482         case '0':   nState = API_STATE_UNCHECKED;   break;
483         case '1':   nState = API_STATE_CHECKED;     break;
484         // any other string (also empty) means 'dontknow'
485     }
486     sal_Int32 nPropId = bAwtModel ? PROP_State : PROP_DefaultState;
487     if( bBooleanState )
488         rPropMap.setProperty( nPropId, nState != API_STATE_UNCHECKED );
489     else
490         rPropMap.setProperty( nPropId, nState );
491 
492     // tristate
493     if( bSupportsTriState )
494         rPropMap.setProperty( PROP_TriState, nMultiSelect == AX_SELCTION_MULTI );
495 }
496 
497 void ControlConverter::convertAxOrientation( PropertyMap& rPropMap,
498         const AxPairData& rSize, sal_Int32 nOrientation ) const
499 {
500     bool bHorizontal = true;
501     switch( nOrientation )
502     {
503         case AX_ORIENTATION_AUTO:       bHorizontal = rSize.first > rSize.second;   break;
504         case AX_ORIENTATION_VERTICAL:   bHorizontal = false;                        break;
505         case AX_ORIENTATION_HORIZONTAL: bHorizontal = true;                         break;
506         default:    OSL_ENSURE( false, "ControlConverter::convertAxOrientation - unknown orientation" );
507     }
508     convertOrientation( rPropMap, bHorizontal );
509 }
510 
511 // ============================================================================
512 
513 ControlModelBase::ControlModelBase() :
514     maSize( 0, 0 ),
515     mbAwtModel( false )
516 {
517 }
518 
519 ControlModelBase::~ControlModelBase()
520 {
521 }
522 
523 OUString ControlModelBase::getServiceName() const
524 {
525     ApiControlType eCtrlType = getControlType();
526     if( mbAwtModel ) switch( eCtrlType )
527     {
528         case API_CONTROL_BUTTON:        return CREATE_OUSTRING( "com.sun.star.awt.UnoControlButtonModel" );
529         case API_CONTROL_FIXEDTEXT:     return CREATE_OUSTRING( "com.sun.star.awt.UnoControlFixedTextModel" );
530         case API_CONTROL_IMAGE:         return CREATE_OUSTRING( "com.sun.star.awt.UnoControlImageControlModel" );
531         case API_CONTROL_CHECKBOX:      return CREATE_OUSTRING( "com.sun.star.awt.UnoControlCheckBoxModel" );
532         case API_CONTROL_RADIOBUTTON:   return CREATE_OUSTRING( "com.sun.star.awt.UnoControlRadioButtonModel" );
533         case API_CONTROL_EDIT:          return CREATE_OUSTRING( "com.sun.star.awt.UnoControlEditModel" );
534         case API_CONTROL_NUMERIC:       return CREATE_OUSTRING( "com.sun.star.awt.UnoControlNumericFieldModel" );
535         case API_CONTROL_LISTBOX:       return CREATE_OUSTRING( "com.sun.star.awt.UnoControlListBoxModel" );
536         case API_CONTROL_COMBOBOX:      return CREATE_OUSTRING( "com.sun.star.awt.UnoControlComboBoxModel" );
537         case API_CONTROL_SPINBUTTON:    return CREATE_OUSTRING( "com.sun.star.awt.UnoControlSpinButtonModel" );
538         case API_CONTROL_SCROLLBAR:     return CREATE_OUSTRING( "com.sun.star.awt.UnoControlScrollBarModel" );
539         case API_CONTROL_PROGRESSBAR:   return CREATE_OUSTRING( "com.sun.star.awt.UnoControlProgressBarModel" );
540         case API_CONTROL_GROUPBOX:      return CREATE_OUSTRING( "com.sun.star.awt.UnoControlGroupBoxModel" );
541         case API_CONTROL_DIALOG:        return CREATE_OUSTRING( "com.sun.star.awt.UnoControlDialogModel" );
542         default:    OSL_ENSURE( false, "ControlModelBase::getServiceName - no AWT model service supported" );
543     }
544     else switch( eCtrlType )
545     {
546         case API_CONTROL_BUTTON:        return CREATE_OUSTRING( "com.sun.star.form.component.CommandButton" );
547         case API_CONTROL_FIXEDTEXT:     return CREATE_OUSTRING( "com.sun.star.form.component.FixedText" );
548         case API_CONTROL_IMAGE:         return CREATE_OUSTRING( "com.sun.star.form.component.DatabaseImageControl" );
549         case API_CONTROL_CHECKBOX:      return CREATE_OUSTRING( "com.sun.star.form.component.CheckBox" );
550         case API_CONTROL_RADIOBUTTON:   return CREATE_OUSTRING( "com.sun.star.form.component.RadioButton" );
551         case API_CONTROL_EDIT:          return CREATE_OUSTRING( "com.sun.star.form.component.TextField" );
552         case API_CONTROL_NUMERIC:       return CREATE_OUSTRING( "com.sun.star.form.component.NumericField" );
553         case API_CONTROL_LISTBOX:       return CREATE_OUSTRING( "com.sun.star.form.component.ListBox" );
554         case API_CONTROL_COMBOBOX:      return CREATE_OUSTRING( "com.sun.star.form.component.ComboBox" );
555         case API_CONTROL_SPINBUTTON:    return CREATE_OUSTRING( "com.sun.star.form.component.SpinButton" );
556         case API_CONTROL_SCROLLBAR:     return CREATE_OUSTRING( "com.sun.star.form.component.ScrollBar" );
557         case API_CONTROL_GROUPBOX:      return CREATE_OUSTRING( "com.sun.star.form.component.GroupBox" );
558         default:    OSL_ENSURE( false, "ControlModelBase::getServiceName - no form component service supported" );
559     }
560     return OUString();
561 }
562 
563 void ControlModelBase::importProperty( sal_Int32 /*nPropId*/, const OUString& /*rValue*/ )
564 {
565 }
566 
567 void ControlModelBase::importPictureData( sal_Int32 /*nPropId*/, BinaryInputStream& /*rInStrm*/ )
568 {
569 }
570 
571 void ControlModelBase::convertProperties( PropertyMap& /*rPropMap*/, const ControlConverter& /*rConv*/ ) const
572 {
573 }
574 
575 void ControlModelBase::convertSize( PropertyMap& rPropMap, const ControlConverter& rConv ) const
576 {
577     rConv.convertSize( rPropMap, maSize );
578 }
579 
580 // ============================================================================
581 
582 ComCtlModelBase::ComCtlModelBase( sal_uInt32 nDataPartId5, sal_uInt32 nDataPartId6,
583         sal_uInt16 nVersion, bool bCommonPart, bool bComplexPart ) :
584     maFontData( CREATE_OUSTRING( "Tahoma" ), 82500 ),
585     mnFlags( 0 ),
586     mnVersion( nVersion ),
587     mnDataPartId5( nDataPartId5 ),
588     mnDataPartId6( nDataPartId6 ),
589     mbCommonPart( bCommonPart ),
590     mbComplexPart( bComplexPart )
591 {
592 }
593 
594 bool ComCtlModelBase::importBinaryModel( BinaryInputStream& rInStrm )
595 {
596     // read initial size part and header of the control data part
597     if( importSizePart( rInStrm ) && readPartHeader( rInStrm, getDataPartId(), mnVersion ) )
598     {
599         // if flags part exists, the first int32 of the data part contains its size
600         sal_uInt32 nCommonPartSize = mbCommonPart ? rInStrm.readuInt32() : 0;
601         // implementations must read the exact amount of data, stream must point to its end afterwards
602         importControlData( rInStrm );
603         // read following parts
604         if( !rInStrm.isEof() &&
605             (!mbCommonPart || importCommonPart( rInStrm, nCommonPartSize )) &&
606             (!mbComplexPart || importComplexPart( rInStrm )) )
607         {
608             return !rInStrm.isEof();
609         }
610     }
611     return false;
612 }
613 
614 void ComCtlModelBase::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
615 {
616     if( mbCommonPart )
617         rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, COMCTL_COMMON_ENABLED ) );
618     ControlModelBase::convertProperties( rPropMap, rConv );
619 }
620 
621 void ComCtlModelBase::importCommonExtraData( BinaryInputStream& /*rInStrm*/ )
622 {
623 }
624 
625 void ComCtlModelBase::importCommonTrailingData( BinaryInputStream& /*rInStrm*/ )
626 {
627 }
628 
629 sal_uInt32 ComCtlModelBase::getDataPartId() const
630 {
631     switch( mnVersion )
632     {
633         case COMCTL_VERSION_50: return mnDataPartId5;
634         case COMCTL_VERSION_60: return mnDataPartId6;
635     }
636     OSL_ENSURE( false, "ComCtlObjectBase::getDataPartId - unxpected version" );
637     return SAL_MAX_UINT32;
638 }
639 
640 bool ComCtlModelBase::readPartHeader( BinaryInputStream& rInStrm, sal_uInt32 nExpPartId, sal_uInt16 nExpMajor, sal_uInt16 nExpMinor )
641 {
642     // no idea if all this is correct...
643     sal_uInt32 nPartId;
644     sal_uInt16 nMajor, nMinor;
645     rInStrm >> nPartId >> nMinor >> nMajor;
646     bool bPartId = nPartId == nExpPartId;
647     OSL_ENSURE( bPartId, "ComCtlObjectBase::readPartHeader - unexpected part identifier" );
648     bool bVersion = ((nExpMajor == SAL_MAX_UINT16) || (nExpMajor == nMajor)) && ((nExpMinor == SAL_MAX_UINT16) || (nExpMinor == nMinor));
649     OSL_ENSURE( bVersion, "ComCtlObjectBase::readPartHeader - unexpected part version" );
650     return !rInStrm.isEof() && bPartId && bVersion;
651 }
652 
653 bool ComCtlModelBase::importSizePart( BinaryInputStream& rInStrm )
654 {
655     if( readPartHeader( rInStrm, COMCTL_ID_SIZE, 0, 8 ) )
656     {
657         rInStrm >> maSize.first >> maSize.second;
658         return !rInStrm.isEof();
659     }
660     return false;
661 }
662 
663 bool ComCtlModelBase::importCommonPart( BinaryInputStream& rInStrm, sal_uInt32 nPartSize )
664 {
665     sal_Int64 nEndPos = rInStrm.tell() + nPartSize;
666     if( (nPartSize >= 16) && readPartHeader( rInStrm, COMCTL_ID_COMMONDATA, 5, 0 ) )
667     {
668         rInStrm.skip( 4 );
669         rInStrm >> mnFlags;
670         // implementations may read less than the exact amount of data
671         importCommonExtraData( rInStrm );
672         rInStrm.seek( nEndPos );
673         // implementations must read the exact amount of data, stream must point to its end afterwards
674         importCommonTrailingData( rInStrm );
675         return !rInStrm.isEof();
676     }
677     return false;
678 }
679 
680 bool ComCtlModelBase::importComplexPart( BinaryInputStream& rInStrm )
681 {
682     if( readPartHeader( rInStrm, COMCTL_ID_COMPLEXDATA, 5, 1 ) )
683     {
684         sal_uInt32 nContFlags;
685         rInStrm >> nContFlags;
686         bool bReadOk =
687             (!getFlag( nContFlags, COMCTL_COMPLEX_FONT ) || OleHelper::importStdFont( maFontData, rInStrm, true )) &&
688             (!getFlag( nContFlags, COMCTL_COMPLEX_MOUSEICON ) || OleHelper::importStdPic( maMouseIcon, rInStrm, true ));
689         return bReadOk && !rInStrm.isEof();
690     }
691     return false;
692 }
693 
694 // ============================================================================
695 
696 ComCtlScrollBarModel::ComCtlScrollBarModel( sal_uInt16 nVersion ) :
697     ComCtlModelBase( SAL_MAX_UINT32, COMCTL_ID_SCROLLBAR_60, nVersion, true, true ),
698     mnScrollBarFlags( 0x00000011 ),
699     mnLargeChange( 1 ),
700     mnSmallChange( 1 ),
701     mnMin( 0 ),
702     mnMax( 32767 ),
703     mnPosition( 0 )
704 {
705 }
706 
707 ApiControlType ComCtlScrollBarModel::getControlType() const
708 {
709     return API_CONTROL_SCROLLBAR;
710 }
711 
712 void ComCtlScrollBarModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
713 {
714     rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
715     rConv.convertOrientation( rPropMap, getFlag( mnScrollBarFlags, COMCTL_SCROLLBAR_HOR ) );
716     rConv.convertScrollBar( rPropMap, mnMin, mnMax, mnPosition, mnSmallChange, mnLargeChange, mbAwtModel );
717     ComCtlModelBase::convertProperties( rPropMap, rConv );
718 }
719 
720 void ComCtlScrollBarModel::importControlData( BinaryInputStream& rInStrm )
721 {
722     rInStrm >> mnScrollBarFlags >> mnLargeChange >> mnSmallChange >> mnMin >> mnMax >> mnPosition;
723 }
724 
725 // ============================================================================
726 
727 ComCtlProgressBarModel::ComCtlProgressBarModel( sal_uInt16 nVersion ) :
728     ComCtlModelBase( COMCTL_ID_PROGRESSBAR_50, COMCTL_ID_PROGRESSBAR_60, nVersion, true, true ),
729     mfMin( 0.0 ),
730     mfMax( 100.0 ),
731     mnVertical( 0 ),
732     mnSmooth( 0 )
733 {
734 }
735 
736 ApiControlType ComCtlProgressBarModel::getControlType() const
737 {
738     return API_CONTROL_PROGRESSBAR;
739 }
740 
741 void ComCtlProgressBarModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
742 {
743     sal_uInt16 nBorder = getFlag( mnFlags, COMCTL_COMMON_3DBORDER ) ? API_BORDER_SUNKEN :
744         (getFlag( mnFlags, COMCTL_COMMON_FLATBORDER ) ? API_BORDER_FLAT : API_BORDER_NONE);
745     rPropMap.setProperty( PROP_Border, nBorder );
746     rPropMap.setProperty( PROP_ProgressValueMin, getLimitedValue< sal_Int32, double >( ::std::min( mfMin, mfMax ), 0.0, SAL_MAX_INT32 ) );
747     rPropMap.setProperty( PROP_ProgressValueMax, getLimitedValue< sal_Int32, double >( ::std::max( mfMin, mfMax ), 0.0, SAL_MAX_INT32 ) );
748     // ComCtl model does not provide current value?
749     ComCtlModelBase::convertProperties( rPropMap, rConv );
750 }
751 
752 void ComCtlProgressBarModel::importControlData( BinaryInputStream& rInStrm )
753 {
754     rInStrm >> mfMin >> mfMax;
755     if( mnVersion == COMCTL_VERSION_60 )
756         rInStrm >> mnVertical >> mnSmooth;
757 }
758 
759 // ============================================================================
760 
761 AxControlModelBase::AxControlModelBase()
762 {
763 }
764 
765 void AxControlModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
766 {
767     switch( nPropId )
768     {
769         // size of the control shape: format is "width;height"
770         case XML_Size:
771         {
772             sal_Int32 nSepPos = rValue.indexOf( ';' );
773             OSL_ENSURE( nSepPos >= 0, "AxControlModelBase::importProperty - missing separator in 'Size' property" );
774             if( nSepPos >= 0 )
775             {
776                 maSize.first = rValue.copy( 0, nSepPos ).toInt32();
777                 maSize.second = rValue.copy( nSepPos + 1 ).toInt32();
778             }
779         }
780         break;
781     }
782 }
783 
784 // ============================================================================
785 
786 AxFontDataModel::AxFontDataModel( bool bSupportsAlign ) :
787     mbSupportsAlign( bSupportsAlign )
788 {
789 }
790 
791 void AxFontDataModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
792 {
793     switch( nPropId )
794     {
795         case XML_FontName:          maFontData.maFontName = rValue;                                             break;
796         case XML_FontEffects:       maFontData.mnFontEffects = AttributeConversion::decodeUnsigned( rValue );   break;
797         case XML_FontHeight:        maFontData.mnFontHeight = AttributeConversion::decodeInteger( rValue );     break;
798         case XML_FontCharSet:       maFontData.mnFontCharSet = AttributeConversion::decodeInteger( rValue );    break;
799         case XML_ParagraphAlign:    maFontData.mnHorAlign = AttributeConversion::decodeInteger( rValue );       break;
800         default:                    AxControlModelBase::importProperty( nPropId, rValue );
801     }
802 }
803 
804 bool AxFontDataModel::importBinaryModel( BinaryInputStream& rInStrm )
805 {
806     return maFontData.importBinaryModel( rInStrm );
807 }
808 
809 void AxFontDataModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
810 {
811     // font name
812     if( maFontData.maFontName.getLength() > 0 )
813         rPropMap.setProperty( PROP_FontName, maFontData.maFontName );
814 
815     // font effects
816     rPropMap.setProperty( PROP_FontWeight, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_BOLD, FontWeight::BOLD, FontWeight::NORMAL ) );
817     rPropMap.setProperty( PROP_FontSlant, getFlagValue< sal_Int16 >( maFontData.mnFontEffects, AX_FONTDATA_ITALIC, FontSlant_ITALIC, FontSlant_NONE ) );
818     rPropMap.setProperty( PROP_FontUnderline, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_UNDERLINE, maFontData.mbDblUnderline ? FontUnderline::DOUBLE : FontUnderline::SINGLE, FontUnderline::NONE ) );
819     rPropMap.setProperty( PROP_FontStrikeout, getFlagValue( maFontData.mnFontEffects, AX_FONTDATA_STRIKEOUT, FontStrikeout::SINGLE, FontStrikeout::NONE ) );
820     rPropMap.setProperty( PROP_FontHeight, maFontData.getHeightPoints() );
821 
822     // font character set
823     rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
824     if( (0 <= maFontData.mnFontCharSet) && (maFontData.mnFontCharSet <= SAL_MAX_UINT8) )
825         eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( maFontData.mnFontCharSet ) );
826     if( eFontEnc != RTL_TEXTENCODING_DONTKNOW )
827         rPropMap.setProperty( PROP_FontCharset, static_cast< sal_Int16 >( eFontEnc ) );
828 
829     // text alignment
830     if( mbSupportsAlign )
831     {
832         sal_Int32 nAlign = TextAlign::LEFT;
833         switch( maFontData.mnHorAlign )
834         {
835             case AX_FONTDATA_LEFT:      nAlign = TextAlign::LEFT;   break;
836             case AX_FONTDATA_RIGHT:     nAlign = TextAlign::RIGHT;  break;
837             case AX_FONTDATA_CENTER:    nAlign = TextAlign::CENTER; break;
838             default:    OSL_ENSURE( false, "AxFontDataModel::convertProperties - unknown text alignment" );
839         }
840         // form controls expect short value
841         rPropMap.setProperty( PROP_Align, static_cast< sal_Int16 >( nAlign ) );
842     }
843 
844     // process base class properties
845     AxControlModelBase::convertProperties( rPropMap, rConv );
846 }
847 
848 // ============================================================================
849 
850 AxCommandButtonModel::AxCommandButtonModel() :
851     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
852     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
853     mnFlags( AX_CMDBUTTON_DEFFLAGS ),
854     mnPicturePos( AX_PICPOS_ABOVECENTER ),
855     mnVerticalAlign( XML_Center ),
856     mbFocusOnClick( true )
857 {
858 }
859 
860 void AxCommandButtonModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
861 {
862     switch( nPropId )
863     {
864         case XML_Caption:               maCaption = rValue;                                                 break;
865         case XML_ForeColor:             mnTextColor = AttributeConversion::decodeUnsigned( rValue );        break;
866         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );        break;
867         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );            break;
868         case XML_PicturePosition:       mnPicturePos = AttributeConversion::decodeUnsigned( rValue );       break;
869         case XML_TakeFocusOnClick:      mbFocusOnClick = AttributeConversion::decodeInteger( rValue ) != 0; break;
870         default:                        AxFontDataModel::importProperty( nPropId, rValue );
871     }
872 }
873 
874 void AxCommandButtonModel::importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm )
875 {
876     switch( nPropId )
877     {
878         case XML_Picture:   OleHelper::importStdPic( maPictureData, rInStrm, true );    break;
879         default:            AxFontDataModel::importPictureData( nPropId, rInStrm );
880     }
881 }
882 
883 bool AxCommandButtonModel::importBinaryModel( BinaryInputStream& rInStrm )
884 {
885     AxBinaryPropertyReader aReader( rInStrm );
886     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
887     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
888     aReader.readIntProperty< sal_uInt32 >( mnFlags );
889     aReader.readStringProperty( maCaption );
890     aReader.readIntProperty< sal_uInt32 >( mnPicturePos );
891     aReader.readPairProperty( maSize );
892     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
893     aReader.readPictureProperty( maPictureData );
894     aReader.skipIntProperty< sal_uInt16 >(); // accelerator
895     aReader.readBoolProperty( mbFocusOnClick, true ); // binary flag means "do not take focus"
896     aReader.skipPictureProperty(); // mouse icon
897     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
898 }
899 
900 ApiControlType AxCommandButtonModel::getControlType() const
901 {
902     return API_CONTROL_BUTTON;
903 }
904 
905 void AxCommandButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
906 {
907     rPropMap.setProperty( PROP_Label, maCaption );
908     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
909     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
910     rPropMap.setProperty( PROP_FocusOnClick, mbFocusOnClick );
911     rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
912     rConv.convertVerticalAlign( rPropMap, mnVerticalAlign );
913     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
914     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
915     AxFontDataModel::convertProperties( rPropMap, rConv );
916 }
917 
918 // ============================================================================
919 
920 AxLabelModel::AxLabelModel() :
921     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
922     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
923     mnFlags( AX_LABEL_DEFFLAGS ),
924     mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
925     mnBorderStyle( AX_BORDERSTYLE_NONE ),
926     mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
927     mnVerticalAlign( XML_Top )
928 {
929 }
930 
931 void AxLabelModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
932 {
933     switch( nPropId )
934     {
935         case XML_Caption:               maCaption = rValue;                                             break;
936         case XML_ForeColor:             mnTextColor = AttributeConversion::decodeUnsigned( rValue );    break;
937         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
938         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
939         case XML_BorderColor:           mnBorderColor = AttributeConversion::decodeUnsigned( rValue );  break;
940         case XML_BorderStyle:           mnBorderStyle = AttributeConversion::decodeInteger( rValue );   break;
941         case XML_SpecialEffect:         mnSpecialEffect = AttributeConversion::decodeInteger( rValue ); break;
942         default:                        AxFontDataModel::importProperty( nPropId, rValue );
943     }
944 }
945 
946 bool AxLabelModel::importBinaryModel( BinaryInputStream& rInStrm )
947 {
948     AxBinaryPropertyReader aReader( rInStrm );
949     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
950     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
951     aReader.readIntProperty< sal_uInt32 >( mnFlags );
952     aReader.readStringProperty( maCaption );
953     aReader.skipIntProperty< sal_uInt32 >(); // picture position
954     aReader.readPairProperty( maSize );
955     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
956     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
957     aReader.readIntProperty< sal_uInt16 >( mnBorderStyle );
958     aReader.readIntProperty< sal_uInt16 >( mnSpecialEffect );
959     aReader.skipPictureProperty(); // picture
960     aReader.skipIntProperty< sal_uInt16 >(); // accelerator
961     aReader.skipPictureProperty(); // mouse icon
962     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
963 }
964 
965 ApiControlType AxLabelModel::getControlType() const
966 {
967     return API_CONTROL_FIXEDTEXT;
968 }
969 
970 void AxLabelModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
971 {
972     rPropMap.setProperty( PROP_Label, maCaption );
973     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
974     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
975     rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
976     rConv.convertVerticalAlign( rPropMap, mnVerticalAlign );
977     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
978     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
979     AxFontDataModel::convertProperties( rPropMap, rConv );
980 }
981 
982 // ============================================================================
983 
984 AxImageModel::AxImageModel() :
985     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
986     mnFlags( AX_IMAGE_DEFFLAGS ),
987     mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
988     mnBorderStyle( AX_BORDERSTYLE_SINGLE ),
989     mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
990     mnPicSizeMode( AX_PICSIZE_CLIP ),
991     mnPicAlign( AX_PICALIGN_CENTER ),
992     mbPicTiling( false )
993 {
994 }
995 
996 void AxImageModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
997 {
998     switch( nPropId )
999     {
1000         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );      break;
1001         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );          break;
1002         case XML_BorderColor:           mnBorderColor = AttributeConversion::decodeUnsigned( rValue );    break;
1003         case XML_BorderStyle:           mnBorderStyle = AttributeConversion::decodeInteger( rValue );     break;
1004         case XML_SpecialEffect:         mnSpecialEffect = AttributeConversion::decodeInteger( rValue );   break;
1005         case XML_SizeMode:              mnPicSizeMode = AttributeConversion::decodeInteger( rValue );     break;
1006         case XML_PictureAlignment:      mnPicAlign = AttributeConversion::decodeInteger( rValue );        break;
1007         case XML_PictureTiling:         mbPicTiling = AttributeConversion::decodeInteger( rValue ) != 0;  break;
1008         default:                        AxControlModelBase::importProperty( nPropId, rValue );
1009     }
1010 }
1011 
1012 void AxImageModel::importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm )
1013 {
1014     switch( nPropId )
1015     {
1016         case XML_Picture:   OleHelper::importStdPic( maPictureData, rInStrm, true );    break;
1017         default:            AxControlModelBase::importPictureData( nPropId, rInStrm );
1018     }
1019 }
1020 
1021 bool AxImageModel::importBinaryModel( BinaryInputStream& rInStrm )
1022 {
1023     AxBinaryPropertyReader aReader( rInStrm );
1024     aReader.skipUndefinedProperty();
1025     aReader.skipUndefinedProperty();
1026     aReader.skipBoolProperty(); // auto-size
1027     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
1028     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1029     aReader.readIntProperty< sal_uInt8 >( mnBorderStyle );
1030     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1031     aReader.readIntProperty< sal_uInt8 >( mnPicSizeMode );
1032     aReader.readIntProperty< sal_uInt8 >( mnSpecialEffect );
1033     aReader.readPairProperty( maSize );
1034     aReader.readPictureProperty( maPictureData );
1035     aReader.readIntProperty< sal_uInt8 >( mnPicAlign );
1036     aReader.readBoolProperty( mbPicTiling );
1037     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1038     aReader.skipPictureProperty(); // mouse icon
1039     return aReader.finalizeImport();
1040 }
1041 
1042 ApiControlType AxImageModel::getControlType() const
1043 {
1044     return API_CONTROL_IMAGE;
1045 }
1046 
1047 void AxImageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1048 {
1049     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1050     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1051     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1052     rConv.convertAxPicture( rPropMap, maPictureData, mnPicSizeMode, mnPicAlign, mbPicTiling );
1053     AxControlModelBase::convertProperties( rPropMap, rConv );
1054 }
1055 
1056 // ============================================================================
1057 
1058 AxMorphDataModelBase::AxMorphDataModelBase() :
1059     mnTextColor( AX_SYSCOLOR_WINDOWTEXT ),
1060     mnBackColor( AX_SYSCOLOR_WINDOWBACK ),
1061     mnFlags( AX_MORPHDATA_DEFFLAGS ),
1062     mnPicturePos( AX_PICPOS_ABOVECENTER ),
1063     mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
1064     mnBorderStyle( AX_BORDERSTYLE_NONE ),
1065     mnSpecialEffect( AX_SPECIALEFFECT_SUNKEN ),
1066     mnDisplayStyle( AX_DISPLAYSTYLE_TEXT ),
1067     mnMultiSelect( AX_SELCTION_SINGLE ),
1068     mnScrollBars( AX_SCROLLBAR_NONE ),
1069     mnMatchEntry( AX_MATCHENTRY_NONE ),
1070     mnShowDropButton( AX_SHOWDROPBUTTON_NEVER ),
1071     mnMaxLength( 0 ),
1072     mnPasswordChar( 0 ),
1073     mnListRows( 8 ),
1074     mnVerticalAlign( XML_Center )
1075 {
1076 }
1077 
1078 void AxMorphDataModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
1079 {
1080     switch( nPropId )
1081     {
1082         case XML_Caption:               maCaption = rValue;                                             break;
1083         case XML_Value:                 maValue = rValue;                                               break;
1084         case XML_GroupName:             maGroupName = rValue;                                           break;
1085         case XML_ForeColor:             mnTextColor = AttributeConversion::decodeUnsigned( rValue );    break;
1086         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
1087         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
1088         case XML_PicturePosition:       mnPicturePos = AttributeConversion::decodeUnsigned( rValue );   break;
1089         case XML_BorderColor:           mnBorderColor = AttributeConversion::decodeUnsigned( rValue );  break;
1090         case XML_BorderStyle:           mnBorderStyle = AttributeConversion::decodeInteger( rValue );   break;
1091         case XML_SpecialEffect:         mnSpecialEffect = AttributeConversion::decodeInteger( rValue ); break;
1092         case XML_DisplayStyle:          mnDisplayStyle = AttributeConversion::decodeInteger( rValue );  break;
1093         case XML_MultiSelect:           mnMultiSelect = AttributeConversion::decodeInteger( rValue );   break;
1094         case XML_ScrollBars:            mnScrollBars = AttributeConversion::decodeInteger( rValue );    break;
1095         case XML_MatchEntry:            mnMatchEntry = AttributeConversion::decodeInteger( rValue );    break;
1096         case XML_ShowDropButtonWhen:    mnShowDropButton = AttributeConversion::decodeInteger( rValue );break;
1097         case XML_MaxLength:             mnMaxLength = AttributeConversion::decodeInteger( rValue );     break;
1098         case XML_PasswordChar:          mnPasswordChar = AttributeConversion::decodeInteger( rValue );  break;
1099         case XML_ListRows:              mnListRows = AttributeConversion::decodeInteger( rValue );      break;
1100         default:                        AxFontDataModel::importProperty( nPropId, rValue );
1101     }
1102 }
1103 
1104 void AxMorphDataModelBase::importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm )
1105 {
1106     switch( nPropId )
1107     {
1108         case XML_Picture:   OleHelper::importStdPic( maPictureData, rInStrm, true );    break;
1109         default:            AxFontDataModel::importPictureData( nPropId, rInStrm );
1110     }
1111 }
1112 
1113 bool AxMorphDataModelBase::importBinaryModel( BinaryInputStream& rInStrm )
1114 {
1115     AxBinaryPropertyReader aReader( rInStrm, true );
1116     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1117     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1118     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
1119     aReader.readIntProperty< sal_Int32 >( mnMaxLength );
1120     aReader.readIntProperty< sal_uInt8 >( mnBorderStyle );
1121     aReader.readIntProperty< sal_uInt8 >( mnScrollBars );
1122     aReader.readIntProperty< sal_uInt8 >( mnDisplayStyle );
1123     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1124     aReader.readPairProperty( maSize );
1125     aReader.readIntProperty< sal_uInt16 >( mnPasswordChar );
1126     aReader.skipIntProperty< sal_uInt32 >(); // list width
1127     aReader.skipIntProperty< sal_uInt16 >(); // bound column
1128     aReader.skipIntProperty< sal_Int16 >(); // text column
1129     aReader.skipIntProperty< sal_Int16 >(); // column count
1130     aReader.readIntProperty< sal_uInt16 >( mnListRows );
1131     aReader.skipIntProperty< sal_uInt16 >(); // column info count
1132     aReader.readIntProperty< sal_uInt8 >( mnMatchEntry );
1133     aReader.skipIntProperty< sal_uInt8 >(); // list style
1134     aReader.readIntProperty< sal_uInt8 >( mnShowDropButton );
1135     aReader.skipUndefinedProperty();
1136     aReader.skipIntProperty< sal_uInt8 >(); // drop down style
1137     aReader.readIntProperty< sal_uInt8 >( mnMultiSelect );
1138     aReader.readStringProperty( maValue );
1139     aReader.readStringProperty( maCaption );
1140     aReader.readIntProperty< sal_uInt32 >( mnPicturePos );
1141     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
1142     aReader.readIntProperty< sal_uInt32 >( mnSpecialEffect );
1143     aReader.skipPictureProperty(); // mouse icon
1144     aReader.readPictureProperty( maPictureData );
1145     aReader.skipIntProperty< sal_uInt16 >(); // accelerator
1146     aReader.skipUndefinedProperty();
1147     aReader.skipBoolProperty();
1148     aReader.readStringProperty( maGroupName );
1149     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
1150 }
1151 
1152 void AxMorphDataModelBase::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1153 {
1154     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1155     rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
1156     AxFontDataModel::convertProperties( rPropMap, rConv );
1157 }
1158 
1159 // ============================================================================
1160 
1161 AxToggleButtonModel::AxToggleButtonModel()
1162 {
1163     mnDisplayStyle = AX_DISPLAYSTYLE_TOGGLE;
1164 }
1165 
1166 ApiControlType AxToggleButtonModel::getControlType() const
1167 {
1168     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TOGGLE, "AxToggleButtonModel::getControlType - invalid control type" );
1169     return API_CONTROL_BUTTON;
1170 }
1171 
1172 void AxToggleButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1173 {
1174     rPropMap.setProperty( PROP_Label, maCaption );
1175     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1176     rPropMap.setProperty( PROP_Toggle, true );
1177     rConv.convertVerticalAlign( rPropMap, mnVerticalAlign );
1178     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
1179     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1180     rConv.convertAxState( rPropMap, maValue, mnMultiSelect, API_DEFAULTSTATE_BOOLEAN, mbAwtModel );
1181     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1182 }
1183 
1184 // ============================================================================
1185 
1186 AxCheckBoxModel::AxCheckBoxModel()
1187 {
1188     mnDisplayStyle = AX_DISPLAYSTYLE_CHECKBOX;
1189 }
1190 
1191 ApiControlType AxCheckBoxModel::getControlType() const
1192 {
1193     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_CHECKBOX, "AxCheckBoxModel::getControlType - invalid control type" );
1194     return API_CONTROL_CHECKBOX;
1195 }
1196 
1197 void AxCheckBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1198 {
1199     rPropMap.setProperty( PROP_Label, maCaption );
1200     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1201     rConv.convertVerticalAlign( rPropMap, mnVerticalAlign );
1202     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1203     rConv.convertAxVisualEffect( rPropMap, mnSpecialEffect );
1204     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1205     rConv.convertAxState( rPropMap, maValue, mnMultiSelect, API_DEFAULTSTATE_TRISTATE, mbAwtModel );
1206     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1207 }
1208 
1209 // ============================================================================
1210 
1211 AxOptionButtonModel::AxOptionButtonModel()
1212 {
1213     mnDisplayStyle = AX_DISPLAYSTYLE_OPTBUTTON;
1214 }
1215 
1216 ApiControlType AxOptionButtonModel::getControlType() const
1217 {
1218     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON, "AxOptionButtonModel::getControlType - invalid control type" );
1219     return API_CONTROL_RADIOBUTTON;
1220 }
1221 
1222 void AxOptionButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1223 {
1224     rPropMap.setProperty( PROP_Label, maCaption );
1225     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
1226     rConv.convertVerticalAlign( rPropMap, mnVerticalAlign );
1227     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1228     rConv.convertAxVisualEffect( rPropMap, mnSpecialEffect );
1229     rConv.convertAxPicture( rPropMap, maPictureData, mnPicturePos );
1230     rConv.convertAxState( rPropMap, maValue, mnMultiSelect, API_DEFAULTSTATE_SHORT, mbAwtModel );
1231     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1232 }
1233 
1234 // ============================================================================
1235 
1236 AxTextBoxModel::AxTextBoxModel()
1237 {
1238     mnDisplayStyle = AX_DISPLAYSTYLE_TEXT;
1239 }
1240 
1241 ApiControlType AxTextBoxModel::getControlType() const
1242 {
1243     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT, "AxTextBoxModel::getControlType - invalid control type" );
1244     return API_CONTROL_EDIT;
1245 }
1246 
1247 void AxTextBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1248 {
1249     rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_MULTILINE ) );
1250     rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
1251     rPropMap.setProperty( mbAwtModel ? PROP_Text : PROP_DefaultText, maValue );
1252     rPropMap.setProperty( PROP_MaxTextLen, getLimitedValue< sal_Int16, sal_Int32 >( mnMaxLength, 0, SAL_MAX_INT16 ) );
1253     if( (0 < mnPasswordChar) && (mnPasswordChar <= SAL_MAX_INT16) )
1254         rPropMap.setProperty( PROP_EchoChar, static_cast< sal_Int16 >( mnPasswordChar ) );
1255     rPropMap.setProperty( PROP_HScroll, getFlag( mnScrollBars, AX_SCROLLBAR_HORIZONTAL ) );
1256     rPropMap.setProperty( PROP_VScroll, getFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL ) );
1257     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1258     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1259     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1260 }
1261 
1262 // ============================================================================
1263 
1264 AxNumericFieldModel::AxNumericFieldModel()
1265 {
1266     mnDisplayStyle = AX_DISPLAYSTYLE_TEXT;
1267 }
1268 
1269 ApiControlType AxNumericFieldModel::getControlType() const
1270 {
1271     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT, "AxNumericFieldModel::getControlType - invalid control type" );
1272     return API_CONTROL_NUMERIC;
1273 }
1274 
1275 void AxNumericFieldModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1276 {
1277     rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
1278     // TODO: OUString::toDouble() does not handle local decimal separator
1279     rPropMap.setProperty( mbAwtModel ? PROP_Value : PROP_DefaultValue, maValue.toDouble() );
1280     rPropMap.setProperty( PROP_Spin, getFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL ) );
1281     rPropMap.setProperty( PROP_Repeat, true );
1282     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1283     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1284     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1285 }
1286 
1287 // ============================================================================
1288 
1289 AxListBoxModel::AxListBoxModel()
1290 {
1291     mnDisplayStyle = AX_DISPLAYSTYLE_LISTBOX;
1292 }
1293 
1294 ApiControlType AxListBoxModel::getControlType() const
1295 {
1296     OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX, "AxListBoxModel::getControlType - invalid control type" );
1297     return API_CONTROL_LISTBOX;
1298 }
1299 
1300 void AxListBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1301 {
1302     bool bMultiSelect = (mnMultiSelect == AX_SELCTION_MULTI) || (mnMultiSelect == AX_SELCTION_EXTENDED);
1303     rPropMap.setProperty( PROP_MultiSelection, bMultiSelect );
1304     rPropMap.setProperty( PROP_Dropdown, false );
1305     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1306     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1307     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1308 }
1309 
1310 // ============================================================================
1311 
1312 AxComboBoxModel::AxComboBoxModel()
1313 {
1314     mnDisplayStyle = AX_DISPLAYSTYLE_COMBOBOX;
1315 }
1316 
1317 ApiControlType AxComboBoxModel::getControlType() const
1318 {
1319     OSL_ENSURE( (mnDisplayStyle == AX_DISPLAYSTYLE_COMBOBOX) || (mnDisplayStyle == AX_DISPLAYSTYLE_DROPDOWN), "AxComboBoxModel::getControlType - invalid control type" );
1320     return (mnDisplayStyle == AX_DISPLAYSTYLE_DROPDOWN) ? API_CONTROL_LISTBOX : API_CONTROL_COMBOBOX;
1321 }
1322 
1323 void AxComboBoxModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1324 {
1325     if( mnDisplayStyle != AX_DISPLAYSTYLE_DROPDOWN )
1326     {
1327         rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
1328         rPropMap.setProperty( mbAwtModel ? PROP_Text : PROP_DefaultText, maValue );
1329         rPropMap.setProperty( PROP_MaxTextLen, getLimitedValue< sal_Int16, sal_Int32 >( mnMaxLength, 0, SAL_MAX_INT16 ) );
1330         bool bAutoComplete = (mnMatchEntry == AX_MATCHENTRY_FIRSTLETTER) || (mnMatchEntry == AX_MATCHENTRY_COMPLETE);
1331         rPropMap.setProperty( PROP_Autocomplete, bAutoComplete );
1332     }
1333     bool bShowDropdown = (mnShowDropButton == AX_SHOWDROPBUTTON_FOCUS) || (mnShowDropButton == AX_SHOWDROPBUTTON_ALWAYS);
1334     rPropMap.setProperty( PROP_Dropdown, bShowDropdown );
1335     rPropMap.setProperty( PROP_LineCount, getLimitedValue< sal_Int16, sal_Int32 >( mnListRows, 1, SAL_MAX_INT16 ) );
1336     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
1337     rConv.convertAxBorder( rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
1338     AxMorphDataModelBase::convertProperties( rPropMap, rConv );
1339 }
1340 
1341 // ============================================================================
1342 
1343 AxSpinButtonModel::AxSpinButtonModel() :
1344     mnArrowColor( AX_SYSCOLOR_BUTTONTEXT ),
1345     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
1346     mnFlags( AX_SPINBUTTON_DEFFLAGS ),
1347     mnOrientation( AX_ORIENTATION_AUTO ),
1348     mnMin( 0 ),
1349     mnMax( 100 ),
1350     mnPosition( 0 ),
1351     mnSmallChange( 1 ),
1352     mnDelay( 50 )
1353 {
1354 }
1355 
1356 ApiControlType AxSpinButtonModel::getControlType() const
1357 {
1358     return API_CONTROL_SPINBUTTON;
1359 }
1360 
1361 void AxSpinButtonModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
1362 {
1363     switch( nPropId )
1364     {
1365         case XML_ForeColor:             mnArrowColor = AttributeConversion::decodeUnsigned( rValue );   break;
1366         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
1367         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
1368         case XML_Orientation:           mnOrientation = AttributeConversion::decodeInteger( rValue );   break;
1369         case XML_Min:                   mnMin = AttributeConversion::decodeInteger( rValue );           break;
1370         case XML_Max:                   mnMax = AttributeConversion::decodeInteger( rValue );           break;
1371         case XML_Position:              mnPosition = AttributeConversion::decodeInteger( rValue );      break;
1372         case XML_SmallChange:           mnSmallChange = AttributeConversion::decodeInteger( rValue );   break;
1373         case XML_Delay:                 mnDelay = AttributeConversion::decodeInteger( rValue );         break;
1374         default:                        AxControlModelBase::importProperty( nPropId, rValue );
1375     }
1376 }
1377 
1378 bool AxSpinButtonModel::importBinaryModel( BinaryInputStream& rInStrm )
1379 {
1380     AxBinaryPropertyReader aReader( rInStrm );
1381     aReader.readIntProperty< sal_uInt32 >( mnArrowColor );
1382     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1383     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1384     aReader.readPairProperty( maSize );
1385     aReader.skipIntProperty< sal_uInt32 >(); // unused
1386     aReader.readIntProperty< sal_Int32 >( mnMin );
1387     aReader.readIntProperty< sal_Int32 >( mnMax );
1388     aReader.readIntProperty< sal_Int32 >( mnPosition );
1389     aReader.skipIntProperty< sal_uInt32 >(); // prev enabled
1390     aReader.skipIntProperty< sal_uInt32 >(); // next enabled
1391     aReader.readIntProperty< sal_Int32 >( mnSmallChange );
1392     aReader.readIntProperty< sal_Int32 >( mnOrientation );
1393     aReader.readIntProperty< sal_Int32 >( mnDelay );
1394     aReader.skipPictureProperty(); // mouse icon
1395     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1396     return aReader.finalizeImport();
1397 }
1398 
1399 void AxSpinButtonModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1400 {
1401     sal_Int32 nMin = ::std::min( mnMin, mnMax );
1402     sal_Int32 nMax = ::std::max( mnMin, mnMax );
1403     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1404     rPropMap.setProperty( PROP_SpinValueMin, nMin );
1405     rPropMap.setProperty( PROP_SpinValueMax, nMax );
1406     rPropMap.setProperty( PROP_SpinIncrement, mnSmallChange );
1407     rPropMap.setProperty( mbAwtModel ? PROP_SpinValue : PROP_DefaultSpinValue, mnPosition );
1408     rPropMap.setProperty( PROP_Repeat, true );
1409     rPropMap.setProperty( PROP_RepeatDelay, mnDelay );
1410     rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
1411     rConv.convertColor( rPropMap, PROP_SymbolColor, mnArrowColor );
1412     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
1413     rConv.convertAxOrientation( rPropMap, maSize, mnOrientation );
1414     AxControlModelBase::convertProperties( rPropMap, rConv );
1415 }
1416 
1417 // ============================================================================
1418 
1419 AxScrollBarModel::AxScrollBarModel() :
1420     mnArrowColor( AX_SYSCOLOR_BUTTONTEXT ),
1421     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
1422     mnFlags( AX_SCROLLBAR_DEFFLAGS ),
1423     mnOrientation( AX_ORIENTATION_AUTO ),
1424     mnPropThumb( AX_PROPTHUMB_ON ),
1425     mnMin( 0 ),
1426     mnMax( 32767 ),
1427     mnPosition( 0 ),
1428     mnSmallChange( 1 ),
1429     mnLargeChange( 1 ),
1430     mnDelay( 50 )
1431 {
1432 }
1433 
1434 ApiControlType AxScrollBarModel::getControlType() const
1435 {
1436     return API_CONTROL_SCROLLBAR;
1437 }
1438 
1439 void AxScrollBarModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
1440 {
1441     switch( nPropId )
1442     {
1443         case XML_ForeColor:             mnArrowColor = AttributeConversion::decodeUnsigned( rValue );   break;
1444         case XML_BackColor:             mnBackColor = AttributeConversion::decodeUnsigned( rValue );    break;
1445         case XML_VariousPropertyBits:   mnFlags = AttributeConversion::decodeUnsigned( rValue );        break;
1446         case XML_Orientation:           mnOrientation = AttributeConversion::decodeInteger( rValue );   break;
1447         case XML_ProportionalThumb:     mnPropThumb = AttributeConversion::decodeInteger( rValue );     break;
1448         case XML_Min:                   mnMin = AttributeConversion::decodeInteger( rValue );           break;
1449         case XML_Max:                   mnMax = AttributeConversion::decodeInteger( rValue );           break;
1450         case XML_Position:              mnPosition = AttributeConversion::decodeInteger( rValue );      break;
1451         case XML_SmallChange:           mnSmallChange = AttributeConversion::decodeInteger( rValue );   break;
1452         case XML_LargeChange:           mnLargeChange = AttributeConversion::decodeInteger( rValue );   break;
1453         case XML_Delay:                 mnDelay = AttributeConversion::decodeInteger( rValue );         break;
1454         default:                        AxControlModelBase::importProperty( nPropId, rValue );
1455     }
1456 }
1457 
1458 bool AxScrollBarModel::importBinaryModel( BinaryInputStream& rInStrm )
1459 {
1460     AxBinaryPropertyReader aReader( rInStrm );
1461     aReader.readIntProperty< sal_uInt32 >( mnArrowColor );
1462     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1463     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1464     aReader.readPairProperty( maSize );
1465     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1466     aReader.readIntProperty< sal_Int32 >( mnMin );
1467     aReader.readIntProperty< sal_Int32 >( mnMax );
1468     aReader.readIntProperty< sal_Int32 >( mnPosition );
1469     aReader.skipIntProperty< sal_uInt32 >(); // unused
1470     aReader.skipIntProperty< sal_uInt32 >(); // prev enabled
1471     aReader.skipIntProperty< sal_uInt32 >(); // next enabled
1472     aReader.readIntProperty< sal_Int32 >( mnSmallChange );
1473     aReader.readIntProperty< sal_Int32 >( mnLargeChange );
1474     aReader.readIntProperty< sal_Int32 >( mnOrientation );
1475     aReader.readIntProperty< sal_Int16 >( mnPropThumb );
1476     aReader.readIntProperty< sal_Int32 >( mnDelay );
1477     aReader.skipPictureProperty(); // mouse icon
1478     return aReader.finalizeImport();
1479 }
1480 
1481 void AxScrollBarModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1482 {
1483     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
1484     rPropMap.setProperty( PROP_RepeatDelay, mnDelay );
1485     rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
1486     if( (mnPropThumb == AX_PROPTHUMB_ON) && (mnMin != mnMax) && (mnLargeChange > 0) )
1487     {
1488         // use double to prevent integer overflow in division (fInterval+mnLargeChange may become 0 when performed as int)
1489         double fInterval = fabs( static_cast< double >( mnMax - mnMin ) );
1490         sal_Int32 nThumbLen = getLimitedValue< sal_Int32, double >( (fInterval * mnLargeChange) / (fInterval + mnLargeChange), 1, SAL_MAX_INT32 );
1491         rPropMap.setProperty( PROP_VisibleSize, nThumbLen );
1492     }
1493     rConv.convertColor( rPropMap, PROP_SymbolColor, mnArrowColor );
1494     rConv.convertAxBackground( rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
1495     rConv.convertAxOrientation( rPropMap, maSize, mnOrientation );
1496     rConv.convertScrollBar( rPropMap, mnMin, mnMax, mnPosition, mnSmallChange, mnLargeChange, mbAwtModel );
1497     AxControlModelBase::convertProperties( rPropMap, rConv );
1498 }
1499 
1500 // ============================================================================
1501 
1502 AxTabStripModel::AxTabStripModel() :
1503     AxFontDataModel( false ),   // no support for alignment properties
1504     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
1505     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
1506     mnFlags( AX_TABSTRIP_DEFFLAGS ),
1507     mnSelectedTab( -1 ),
1508     mnTabStyle( AX_TABSTRIP_TABS ),
1509     mnTabFlagCount( 0 )
1510 {
1511 }
1512 
1513 bool AxTabStripModel::importBinaryModel( BinaryInputStream& rInStrm )
1514 {
1515     AxBinaryPropertyReader aReader( rInStrm );
1516     aReader.readIntProperty< sal_Int32 >( mnSelectedTab );
1517     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1518     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
1519     aReader.skipUndefinedProperty();
1520     aReader.readPairProperty( maSize );
1521     aReader.readStringArrayProperty( maCaptions );
1522     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1523     aReader.skipUndefinedProperty();
1524     aReader.skipIntProperty< sal_uInt32 >(); // tab orientation
1525     aReader.readIntProperty< sal_uInt32 >( mnTabStyle );
1526     aReader.skipBoolProperty(); // multiple rows
1527     aReader.skipIntProperty< sal_uInt32 >(); // fixed width
1528     aReader.skipIntProperty< sal_uInt32 >(); // fixed height
1529     aReader.skipBoolProperty(); // tooltips
1530     aReader.skipUndefinedProperty();
1531     aReader.skipStringArrayProperty(); // tooltip strings
1532     aReader.skipUndefinedProperty();
1533     aReader.skipStringArrayProperty(); // tab names
1534     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1535     aReader.skipBoolProperty(); // new version
1536     aReader.skipIntProperty< sal_uInt32 >(); // tabs allocated
1537     aReader.skipStringArrayProperty(); // tags
1538     aReader.readIntProperty< sal_uInt32 >( mnTabFlagCount );
1539     aReader.skipStringArrayProperty(); // accelerators
1540     aReader.skipPictureProperty(); // mouse icon
1541     return aReader.finalizeImport() && AxFontDataModel::importBinaryModel( rInStrm );
1542 }
1543 
1544 ApiControlType AxTabStripModel::getControlType() const
1545 {
1546     return API_CONTROL_TABSTRIP;
1547 }
1548 
1549 void AxTabStripModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1550 {
1551     rPropMap.setProperty( PROP_Decoration, mnTabStyle != AX_TABSTRIP_NONE );
1552     rPropMap.setProperty( PROP_MultiPageValue, mnSelectedTab );
1553     rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor );
1554     AxFontDataModel::convertProperties( rPropMap, rConv );
1555 }
1556 
1557 OUString AxTabStripModel::getCaption( sal_Int32 nIndex ) const
1558 {
1559     return ContainerHelper::getVectorElement( maCaptions, nIndex, OUString() );
1560 }
1561 
1562 // ============================================================================
1563 
1564 AxContainerModelBase::AxContainerModelBase( bool bFontSupport ) :
1565     AxFontDataModel( false ),   // no support for alignment properties
1566     maLogicalSize( AX_CONTAINER_DEFWIDTH, AX_CONTAINER_DEFHEIGHT ),
1567     maScrollPos( 0, 0 ),
1568     mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
1569     mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
1570     mnFlags( AX_CONTAINER_DEFFLAGS ),
1571     mnBorderColor( AX_SYSCOLOR_BUTTONTEXT ),
1572     mnBorderStyle( AX_BORDERSTYLE_NONE ),
1573     mnScrollBars( AX_CONTAINER_SCR_NONE ),
1574     mnCycleType( AX_CONTAINER_CYCLEALL ),
1575     mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
1576     mnPicAlign( AX_PICALIGN_CENTER ),
1577     mnPicSizeMode( AX_PICSIZE_CLIP ),
1578     mbPicTiling( false ),
1579     mbFontSupport( bFontSupport )
1580 {
1581     setAwtModelMode();
1582     // different default size for frame
1583     maSize = AxPairData( AX_CONTAINER_DEFWIDTH, AX_CONTAINER_DEFHEIGHT );
1584 }
1585 
1586 void AxContainerModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
1587 {
1588     if( nPropId == XML_Caption )
1589         maCaption = rValue;
1590 }
1591 
1592 bool AxContainerModelBase::importBinaryModel( BinaryInputStream& rInStrm )
1593 {
1594     AxBinaryPropertyReader aReader( rInStrm );
1595     aReader.skipUndefinedProperty();
1596     aReader.readIntProperty< sal_uInt32 >( mnBackColor );
1597     aReader.readIntProperty< sal_uInt32 >( mnTextColor );
1598     aReader.skipIntProperty< sal_uInt32 >(); // next availbale control ID
1599     aReader.skipUndefinedProperty();
1600     aReader.skipUndefinedProperty();
1601     aReader.readIntProperty< sal_uInt32 >( mnFlags );
1602     aReader.readIntProperty< sal_uInt8 >( mnBorderStyle );
1603     aReader.skipIntProperty< sal_uInt8 >(); // mouse pointer
1604     aReader.readIntProperty< sal_uInt8 >( mnScrollBars );
1605     aReader.readPairProperty( maSize );
1606     aReader.readPairProperty( maLogicalSize );
1607     aReader.readPairProperty( maScrollPos );
1608     aReader.skipIntProperty< sal_uInt32 >(); // number of control groups
1609     aReader.skipUndefinedProperty();
1610     aReader.skipPictureProperty(); // mouse icon
1611     aReader.readIntProperty< sal_uInt8 >( mnCycleType );
1612     aReader.readIntProperty< sal_uInt8 >( mnSpecialEffect );
1613     aReader.readIntProperty< sal_uInt32 >( mnBorderColor );
1614     aReader.readStringProperty( maCaption );
1615     aReader.readFontProperty( maFontData );
1616     aReader.readPictureProperty( maPictureData );
1617     aReader.skipIntProperty< sal_Int32 >(); // zoom
1618     aReader.readIntProperty< sal_uInt8 >( mnPicAlign );
1619     aReader.readBoolProperty( mbPicTiling );
1620     aReader.readIntProperty< sal_uInt8 >( mnPicSizeMode );
1621     aReader.skipIntProperty< sal_uInt32 >(); // shape cookie
1622     aReader.skipIntProperty< sal_uInt32 >(); // draw buffer size
1623     return aReader.finalizeImport();
1624 }
1625 
1626 void AxContainerModelBase::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1627 {
1628     if( mbFontSupport )
1629     {
1630         rConv.convertColor( rPropMap, PROP_TextColor, mnTextColor );
1631         AxFontDataModel::convertProperties( rPropMap, rConv );
1632     }
1633 }
1634 
1635 bool AxContainerModelBase::importClassTable( BinaryInputStream& rInStrm, AxClassTable& orClassTable )
1636 {
1637     bool bValid = true;
1638     orClassTable.clear();
1639     if( !getFlag( mnFlags, AX_CONTAINER_NOCLASSTABLE ) )
1640     {
1641         sal_uInt16 nCount = rInStrm.readuInt16();
1642         for( sal_uInt16 nIndex = 0; bValid && (nIndex < nCount); ++nIndex )
1643         {
1644             orClassTable.push_back( OUString() );
1645             AxBinaryPropertyReader aReader( rInStrm );
1646             aReader.readGuidProperty( orClassTable.back() );
1647             aReader.skipGuidProperty(); // source interface GUID
1648             aReader.skipUndefinedProperty();
1649             aReader.skipGuidProperty(); // default interface GUID
1650             aReader.skipIntProperty< sal_uInt32 >(); // class table and var flags
1651             aReader.skipIntProperty< sal_uInt32 >(); // method count
1652             aReader.skipIntProperty< sal_Int32 >(); // IDispatch identifier for linked cell access
1653             aReader.skipIntProperty< sal_uInt16 >(); // get function index for linked cell access
1654             aReader.skipIntProperty< sal_uInt16 >(); // put function index for linked cell access
1655             aReader.skipIntProperty< sal_uInt16 >(); // linked cell access property type
1656             aReader.skipIntProperty< sal_uInt16 >(); // get function index of value
1657             aReader.skipIntProperty< sal_uInt16 >(); // put function index of value
1658             aReader.skipIntProperty< sal_uInt16 >(); // value type
1659             aReader.skipIntProperty< sal_Int32 >(); // IDispatch identifier for source range access
1660             aReader.skipIntProperty< sal_uInt16 >(); // get function index for source range access
1661             bValid = aReader.finalizeImport();
1662         }
1663     }
1664     return bValid;
1665 }
1666 
1667 // ============================================================================
1668 
1669 AxFrameModel::AxFrameModel() :
1670     AxContainerModelBase( true )
1671 {
1672 }
1673 
1674 ApiControlType AxFrameModel::getControlType() const
1675 {
1676     return API_CONTROL_GROUPBOX;
1677 }
1678 
1679 void AxFrameModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1680 {
1681     rPropMap.setProperty( PROP_Label, maCaption );
1682     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) );
1683     AxContainerModelBase::convertProperties( rPropMap, rConv );
1684 }
1685 
1686 // ============================================================================
1687 
1688 AxFormPageModel::AxFormPageModel()
1689 {
1690 }
1691 
1692 ApiControlType AxFormPageModel::getControlType() const
1693 {
1694     return API_CONTROL_PAGE;
1695 }
1696 
1697 void AxFormPageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1698 {
1699     rPropMap.setProperty( PROP_Title, maCaption );
1700     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) );
1701     rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor );
1702     AxContainerModelBase::convertProperties( rPropMap, rConv );
1703 }
1704 
1705 // ============================================================================
1706 
1707 AxMultiPageModel::AxMultiPageModel()
1708 {
1709 }
1710 
1711 ApiControlType AxMultiPageModel::getControlType() const
1712 {
1713     return API_CONTROL_MULTIPAGE;
1714 }
1715 
1716 void AxMultiPageModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1717 {
1718     rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_CONTAINER_ENABLED ) );
1719     if( mxTabStrip.get() )
1720         mxTabStrip->convertProperties( rPropMap, rConv );
1721     AxContainerModelBase::convertProperties( rPropMap, rConv );
1722 }
1723 
1724 void AxMultiPageModel::setTabStripModel( const AxTabStripModelRef& rxTabStrip )
1725 {
1726     mxTabStrip = rxTabStrip;
1727 }
1728 
1729 // ============================================================================
1730 
1731 AxUserFormModel::AxUserFormModel()
1732 {
1733 }
1734 
1735 ApiControlType AxUserFormModel::getControlType() const
1736 {
1737     return API_CONTROL_DIALOG;
1738 }
1739 
1740 void AxUserFormModel::convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const
1741 {
1742     rPropMap.setProperty( PROP_Title, maCaption );
1743     rConv.convertColor( rPropMap, PROP_BackgroundColor, mnBackColor );
1744     AxContainerModelBase::convertProperties( rPropMap, rConv );
1745 }
1746 
1747 // ============================================================================
1748 
1749 EmbeddedControl::EmbeddedControl( const OUString& rName ) :
1750     maName( rName )
1751 {
1752 }
1753 
1754 EmbeddedControl::~EmbeddedControl()
1755 {
1756 }
1757 
1758 ControlModelBase* EmbeddedControl::createModelFromGuid( const OUString& rClassId )
1759 {
1760     OUString aClassId = rClassId.toAsciiUpperCase();
1761 
1762     if( aClassId.equalsAscii( AX_GUID_COMMANDBUTTON ) )     return &createModel< AxCommandButtonModel >();
1763     if( aClassId.equalsAscii( AX_GUID_LABEL ) )             return &createModel< AxLabelModel >();
1764     if( aClassId.equalsAscii( AX_GUID_IMAGE ) )             return &createModel< AxImageModel >();
1765     if( aClassId.equalsAscii( AX_GUID_TOGGLEBUTTON ) )      return &createModel< AxToggleButtonModel >();
1766     if( aClassId.equalsAscii( AX_GUID_CHECKBOX ) )          return &createModel< AxCheckBoxModel >();
1767     if( aClassId.equalsAscii( AX_GUID_OPTIONBUTTON ) )      return &createModel< AxOptionButtonModel >();
1768     if( aClassId.equalsAscii( AX_GUID_TEXTBOX ) )           return &createModel< AxTextBoxModel >();
1769     if( aClassId.equalsAscii( AX_GUID_LISTBOX ) )           return &createModel< AxListBoxModel >();
1770     if( aClassId.equalsAscii( AX_GUID_COMBOBOX ) )          return &createModel< AxComboBoxModel >();
1771     if( aClassId.equalsAscii( AX_GUID_SPINBUTTON ) )        return &createModel< AxSpinButtonModel >();
1772     if( aClassId.equalsAscii( AX_GUID_SCROLLBAR ) )         return &createModel< AxScrollBarModel >();
1773     if( aClassId.equalsAscii( AX_GUID_FRAME ) )             return &createModel< AxFrameModel >();
1774     if( aClassId.equalsAscii( COMCTL_GUID_SCROLLBAR_60 ) )  return &createModel< ComCtlScrollBarModel >( COMCTL_VERSION_60 );
1775 
1776     mxModel.reset();
1777     return 0;
1778 }
1779 
1780 OUString EmbeddedControl::getServiceName() const
1781 {
1782     return mxModel.get() ? mxModel->getServiceName() : OUString();
1783 }
1784 
1785 bool EmbeddedControl::convertProperties( const Reference< XControlModel >& rxCtrlModel, const ControlConverter& rConv ) const
1786 {
1787     if( mxModel.get() && rxCtrlModel.is() && (maName.getLength() > 0) )
1788     {
1789         PropertyMap aPropMap;
1790         aPropMap.setProperty( PROP_Name, maName );
1791         mxModel->convertProperties( aPropMap, rConv );
1792         PropertySet aPropSet( rxCtrlModel );
1793         aPropSet.setProperties( aPropMap );
1794         return true;
1795     }
1796     return false;
1797 }
1798 
1799 // ============================================================================
1800 
1801 EmbeddedForm::EmbeddedForm( const Reference< XModel >& rxDocModel,
1802         const Reference< XDrawPage >& rxDrawPage, const GraphicHelper& rGraphicHelper, bool bDefaultColorBgr ) :
1803     maControlConv( rxDocModel, rGraphicHelper, bDefaultColorBgr ),
1804     mxModelFactory( rxDocModel, UNO_QUERY ),
1805     mxFormsSupp( rxDrawPage, UNO_QUERY )
1806 {
1807     OSL_ENSURE( mxModelFactory.is(), "EmbeddedForm::EmbeddedForm - missing service factory" );
1808 }
1809 
1810 Reference< XControlModel > EmbeddedForm::convertAndInsert( const EmbeddedControl& rControl, sal_Int32& rnCtrlIndex )
1811 {
1812     if( mxModelFactory.is() && rControl.hasModel() ) try
1813     {
1814         // create the UNO control model
1815         OUString aServiceName = rControl.getServiceName();
1816         Reference< XFormComponent > xFormComp( mxModelFactory->createInstance( aServiceName ), UNO_QUERY_THROW );
1817         Reference< XControlModel > xCtrlModel( xFormComp, UNO_QUERY_THROW );
1818 
1819         // insert the control into the form
1820         Reference< XIndexContainer > xFormIC( createXForm(), UNO_SET_THROW );
1821         rnCtrlIndex = xFormIC->getCount();
1822         xFormIC->insertByIndex( rnCtrlIndex, Any( xFormComp ) );
1823 
1824         // convert the control properties
1825         if( rControl.convertProperties( xCtrlModel, maControlConv ) )
1826             return xCtrlModel;
1827     }
1828     catch( Exception& )
1829     {
1830     }
1831     return Reference< XControlModel >();
1832 }
1833 
1834 Reference< XIndexContainer > EmbeddedForm::createXForm()
1835 {
1836     if( mxFormsSupp.is() )
1837     {
1838         try
1839         {
1840             Reference< XNameContainer > xFormsNC( mxFormsSupp->getForms(), UNO_SET_THROW );
1841             OUString aFormName = CREATE_OUSTRING( "Standard" );
1842             if( xFormsNC->hasByName( aFormName ) )
1843             {
1844                 mxFormIC.set( xFormsNC->getByName( aFormName ), UNO_QUERY_THROW );
1845             }
1846             else if( mxModelFactory.is() )
1847             {
1848                 Reference< XForm > xForm( mxModelFactory->createInstance( CREATE_OUSTRING( "com.sun.star.form.component.Form" ) ), UNO_QUERY_THROW );
1849                 xFormsNC->insertByName( aFormName, Any( xForm ) );
1850                 mxFormIC.set( xForm, UNO_QUERY_THROW );
1851             }
1852         }
1853         catch( Exception& )
1854         {
1855         }
1856         // always clear the forms supplier to not try to create the form again
1857         mxFormsSupp.clear();
1858     }
1859     return mxFormIC;
1860 }
1861 
1862 // ============================================================================
1863 
1864 } // namespace ole
1865 } // namespace oox
1866