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