merge the formfield patch from ooo-build
[ooovba.git] / oox / source / ole / axcontrol.cxx
blob2495305d1c35e63d669089d2f7ddd6a1fbd526f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: axcontrol.cxx,v $
10 * $Revision: 1.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/ole/axcontrol.hxx"
32 #include <rtl/tencinfo.h>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/awt/FontSlant.hpp>
36 #include <com/sun/star/awt/FontStrikeout.hpp>
37 #include <com/sun/star/awt/FontUnderline.hpp>
38 #include <com/sun/star/awt/FontWeight.hpp>
39 #include <com/sun/star/awt/ImagePosition.hpp>
40 #include <com/sun/star/awt/ImageScaleMode.hpp>
41 #include <com/sun/star/awt/ScrollBarOrientation.hpp>
42 #include <com/sun/star/awt/TextAlign.hpp>
43 #include <com/sun/star/awt/VisualEffect.hpp>
44 #include <com/sun/star/awt/XControlModel.hpp>
45 #include <com/sun/star/style/VerticalAlignment.hpp>
46 #include <com/sun/star/form/XFormComponent.hpp>
47 #include "properties.hxx"
48 #include "tokens.hxx"
49 #include "oox/helper/attributelist.hxx"
50 #include "oox/helper/binaryinputstream.hxx"
51 #include "oox/helper/graphichelper.hxx"
52 #include "oox/helper/propertymap.hxx"
53 #include "oox/helper/propertyset.hxx"
54 #include "oox/core/filterbase.hxx"
55 #include "oox/ole/axcontrolhelper.hxx"
56 #include "oox/ole/olehelper.hxx"
58 using ::rtl::OUString;
59 using ::com::sun::star::uno::Any;
60 using ::com::sun::star::uno::Exception;
61 using ::com::sun::star::uno::Reference;
62 using ::com::sun::star::uno::UNO_QUERY_THROW;
63 using ::com::sun::star::container::XIndexContainer;
64 using ::com::sun::star::awt::XControlModel;
65 using ::com::sun::star::form::XFormComponent;
66 using ::oox::core::FilterBase;
68 namespace oox {
69 namespace ole {
71 // ============================================================================
73 namespace {
75 const sal_uInt32 AX_FLAGS_ENABLED = 0x00000002;
76 const sal_uInt32 AX_FLAGS_LOCKED = 0x00000004;
77 const sal_uInt32 AX_FLAGS_OPAQUE = 0x00000008;
78 const sal_uInt32 AX_FLAGS_COLUMNHEADS = 0x00000400;
79 const sal_uInt32 AX_FLAGS_ENTIREROWS = 0x00000800;
80 const sal_uInt32 AX_FLAGS_EXISTINGENTRIES = 0x00001000;
81 const sal_uInt32 AX_FLAGS_CAPTIONLEFT = 0x00002000;
82 const sal_uInt32 AX_FLAGS_EDITABLE = 0x00004000;
83 const sal_uInt32 AX_FLAGS_IMEMODE_MASK = 0x00078000;
84 const sal_uInt32 AX_FLAGS_DRAGENABLED = 0x00080000;
85 const sal_uInt32 AX_FLAGS_ENTERASNEWLINE = 0x00100000;
86 const sal_uInt32 AX_FLAGS_KEEPSELECTION = 0x00200000;
87 const sal_uInt32 AX_FLAGS_TABASCHARACTER = 0x00400000;
88 const sal_uInt32 AX_FLAGS_WORDWRAP = 0x00800000;
89 const sal_uInt32 AX_FLAGS_BORDERSSUPPRESSED = 0x02000000;
90 const sal_uInt32 AX_FLAGS_SELECTLINE = 0x04000000;
91 const sal_uInt32 AX_FLAGS_SINGLECHARSELECT = 0x08000000;
92 const sal_uInt32 AX_FLAGS_AUTOSIZE = 0x10000000;
93 const sal_uInt32 AX_FLAGS_HIDESELECTION = 0x20000000;
94 const sal_uInt32 AX_FLAGS_MAXLENAUTOTAB = 0x40000000;
95 const sal_uInt32 AX_FLAGS_MULTILINE = 0x80000000;
97 const sal_uInt32 AX_CMDBUTTON_DEFFLAGS = 0x0000001B;
98 const sal_uInt32 AX_LABEL_DEFFLAGS = 0x0080001B;
99 const sal_uInt32 AX_IMAGE_DEFFLAGS = 0x0000001B;
100 const sal_uInt32 AX_MORPHDATA_DEFFLAGS = 0x2C80081B;
101 const sal_uInt32 AX_SPINBUTTON_DEFFLAGS = 0x0000001B;
102 const sal_uInt32 AX_SCROLLBAR_DEFFLAGS = 0x0000001B;
104 const sal_uInt32 AX_FONT_BOLD = 0x00000001;
105 const sal_uInt32 AX_FONT_ITALIC = 0x00000002;
106 const sal_uInt32 AX_FONT_UNDERLINE = 0x00000004;
107 const sal_uInt32 AX_FONT_STRIKEOUT = 0x00000008;
108 const sal_uInt32 AX_FONT_DISABLED = 0x00002000;
109 const sal_uInt32 AX_FONT_AUTOCOLOR = 0x40000000;
111 const sal_Int32 AX_FONTALIGN_LEFT = 1;
112 const sal_Int32 AX_FONTALIGN_RIGHT = 2;
113 const sal_Int32 AX_FONTALIGN_CENTER = 3;
115 const sal_Int32 AX_BORDERSTYLE_NONE = 0;
116 const sal_Int32 AX_BORDERSTYLE_SINGLE = 1;
118 const sal_Int32 AX_SPECIALEFFECT_FLAT = 0;
119 const sal_Int32 AX_SPECIALEFFECT_RAISED = 1;
120 const sal_Int32 AX_SPECIALEFFECT_SUNKEN = 2;
121 const sal_Int32 AX_SPECIALEFFECT_ETCHED = 3;
122 const sal_Int32 AX_SPECIALEFFECT_BUMPED = 6;
124 const sal_uInt16 AX_POS_TOPLEFT = 0;
125 const sal_uInt16 AX_POS_TOP = 1;
126 const sal_uInt16 AX_POS_TOPRIGHT = 2;
127 const sal_uInt16 AX_POS_LEFT = 3;
128 const sal_uInt16 AX_POS_CENTER = 4;
129 const sal_uInt16 AX_POS_RIGHT = 5;
130 const sal_uInt16 AX_POS_BOTTOMLEFT = 6;
131 const sal_uInt16 AX_POS_BOTTOM = 7;
132 const sal_uInt16 AX_POS_BOTTOMRIGHT = 8;
134 #define AX_PICPOS( label, image ) ((AX_POS_##label << 16) | AX_POS_##image)
135 const sal_uInt32 AX_PICPOS_LEFTTOP = AX_PICPOS( TOPRIGHT, TOPLEFT );
136 const sal_uInt32 AX_PICPOS_LEFTCENTER = AX_PICPOS( RIGHT, LEFT );
137 const sal_uInt32 AX_PICPOS_LEFTBOTTOM = AX_PICPOS( BOTTOMRIGHT, BOTTOMLEFT );
138 const sal_uInt32 AX_PICPOS_RIGHTTOP = AX_PICPOS( TOPLEFT, TOPRIGHT );
139 const sal_uInt32 AX_PICPOS_RIGHTCENTER = AX_PICPOS( LEFT, RIGHT );
140 const sal_uInt32 AX_PICPOS_RIGHTBOTTOM = AX_PICPOS( BOTTOMLEFT, BOTTOMRIGHT );
141 const sal_uInt32 AX_PICPOS_ABOVELEFT = AX_PICPOS( BOTTOMLEFT, TOPLEFT );
142 const sal_uInt32 AX_PICPOS_ABOVECENTER = AX_PICPOS( BOTTOM, TOP );
143 const sal_uInt32 AX_PICPOS_ABOVERIGHT = AX_PICPOS( BOTTOMRIGHT, TOPRIGHT );
144 const sal_uInt32 AX_PICPOS_BELOWLEFT = AX_PICPOS( TOPLEFT, BOTTOMLEFT );
145 const sal_uInt32 AX_PICPOS_BELOWCENTER = AX_PICPOS( TOP, BOTTOM );
146 const sal_uInt32 AX_PICPOS_BELOWRIGHT = AX_PICPOS( TOPRIGHT, BOTTOMRIGHT );
147 const sal_uInt32 AX_PICPOS_CENTER = AX_PICPOS( CENTER, CENTER );
148 #undef AX_PICPOS
150 const sal_Int32 AX_PICSIZE_CLIP = 0;
151 const sal_Int32 AX_PICSIZE_STRETCH = 1;
152 const sal_Int32 AX_PICSIZE_ZOOM = 3;
154 const sal_Int32 AX_PICALIGN_TOPLEFT = 0;
155 const sal_Int32 AX_PICALIGN_TOPRIGHT = 1;
156 const sal_Int32 AX_PICALIGN_CENTER = 2;
157 const sal_Int32 AX_PICALIGN_BOTTOMLEFT = 3;
158 const sal_Int32 AX_PICALIGN_BOTTOMRIGHT = 4;
160 const sal_Int32 AX_DISPLAYSTYLE_TEXT = 1;
161 const sal_Int32 AX_DISPLAYSTYLE_LISTBOX = 2;
162 const sal_Int32 AX_DISPLAYSTYLE_COMBOBOX = 3;
163 const sal_Int32 AX_DISPLAYSTYLE_CHECKBOX = 4;
164 const sal_Int32 AX_DISPLAYSTYLE_OPTBUTTON = 5;
165 const sal_Int32 AX_DISPLAYSTYLE_TOGGLE = 6;
166 const sal_Int32 AX_DISPLAYSTYLE_DROPDOWN = 7;
168 const sal_Int32 AX_SELCTION_SINGLE = 0;
169 const sal_Int32 AX_SELCTION_MULTI = 1;
170 const sal_Int32 AX_SELCTION_EXTENDED = 2;
172 const sal_Int32 AX_SCROLLBAR_NONE = 0x00;
173 const sal_Int32 AX_SCROLLBAR_HORIZONTAL = 0x01;
174 const sal_Int32 AX_SCROLLBAR_VERTICAL = 0x02;
176 const sal_Int32 AX_MATCHENTRY_FIRSTLETTER = 0;
177 const sal_Int32 AX_MATCHENTRY_COMPLETE = 1;
178 const sal_Int32 AX_MATCHENTRY_NONE = 2;
180 const sal_Int32 AX_SHOWDROPBUTTON_NEVER = 0;
181 const sal_Int32 AX_SHOWDROPBUTTON_FOCUS = 1;
182 const sal_Int32 AX_SHOWDROPBUTTON_ALWAYS = 2;
184 const sal_Int32 AX_ORIENTATION_AUTO = -1;
185 const sal_Int32 AX_ORIENTATION_VERTICAL = 0;
186 const sal_Int32 AX_ORIENTATION_HORIZONTAL = 1;
188 const sal_Int32 AX_PROPTHUMB_ON = -1;
189 const sal_Int32 AX_PROPTHUMB_OFF = 0;
191 // ----------------------------------------------------------------------------
193 const sal_Int16 API_BORDER_NONE = 0;
194 const sal_Int16 API_BORDER_SUNKEN = 1;
195 const sal_Int16 API_BORDER_FLAT = 2;
197 const sal_Int16 API_STATE_UNCHECKED = 0;
198 const sal_Int16 API_STATE_CHECKED = 1;
199 const sal_Int16 API_STATE_DONTKNOW = 2;
201 // ----------------------------------------------------------------------------
203 /** Specifies how a form control supports transparent background. */
204 enum ApiTransparencyMode
206 API_TRANSPARENCY_NOTSUPPORTED, /// Control does not support transparency.
207 API_TRANSPARENCY_VOID, /// Transparency is enabled by missing fill color.
208 API_TRANSPARENCY_PAINTTRANSPARENT /// Transparency is enabled by the 'PaintTransparent' property.
211 // ----------------------------------------------------------------------------
213 /** Converts the AX background formatting to UNO properties. */
214 void lclConvertBackground( AxControlHelper& rHelper, PropertyMap& rPropMap, sal_uInt32 nBackColor, sal_uInt32 nFlags, ApiTransparencyMode eTranspMode )
216 bool bOpaque = getFlag( nFlags, AX_FLAGS_OPAQUE );
217 switch( eTranspMode )
219 case API_TRANSPARENCY_NOTSUPPORTED:
220 // fake transparency by using system window background if needed
221 rPropMap.setProperty( PROP_BackgroundColor, rHelper.convertColor( bOpaque ? nBackColor : AX_SYSCOLOR_WINDOWBACK ) );
222 break;
223 case API_TRANSPARENCY_PAINTTRANSPARENT:
224 rPropMap.setProperty( PROP_PaintTransparent, !bOpaque );
225 // run-through intended!
226 case API_TRANSPARENCY_VOID:
227 // keep transparency by leaving the (void) default property value
228 if( bOpaque )
229 rPropMap.setProperty( PROP_BackgroundColor, rHelper.convertColor( nBackColor ) );
230 break;
234 // ----------------------------------------------------------------------------
236 /** Converts the AX border formatting to UNO properties. */
237 void lclConvertBorder( AxControlHelper& rHelper, PropertyMap& rPropMap, sal_uInt32 nBorderColor, sal_Int32 nBorderStyle, sal_Int32 nSpecialEffect )
239 sal_Int16 nBorder = (nBorderStyle == AX_BORDERSTYLE_SINGLE) ? API_BORDER_FLAT :
240 ((nSpecialEffect == AX_SPECIALEFFECT_FLAT) ? API_BORDER_NONE : API_BORDER_SUNKEN);
241 rPropMap.setProperty( PROP_Border, nBorder );
242 rPropMap.setProperty( PROP_BorderColor, rHelper.convertColor( nBorderColor ) );
245 // ----------------------------------------------------------------------------
247 /** Converts the AX special effect to UNO properties. */
248 void lclConvertVisualEffect( AxControlHelper& /*rHelper*/, PropertyMap& rPropMap, sal_Int32 nSpecialEffect )
250 namespace AwtVisualEffect = ::com::sun::star::awt::VisualEffect;
251 sal_Int16 nVisualEffect = (nSpecialEffect == AX_SPECIALEFFECT_FLAT) ? AwtVisualEffect::FLAT : AwtVisualEffect::LOOK3D;
252 rPropMap.setProperty( PROP_VisualEffect, nVisualEffect );
255 // ----------------------------------------------------------------------------
257 /** Converts the AX picture to UNO properties. */
258 void lclConvertPicture( AxControlHelper& rHelper, PropertyMap& rPropMap, const StreamDataSequence& rPicData )
260 if( rPicData.hasElements() )
262 SequenceInputStream aInStrm( rPicData );
263 StreamDataSequence aPictureData;
264 if( OleHelper::importStdPic( aPictureData, aInStrm, true ) )
266 OUString aGraphicUrl = rHelper.getFilter().getGraphicHelper().importGraphicObject( aPictureData );
267 if( aGraphicUrl.getLength() > 0 )
268 rPropMap.setProperty( PROP_ImageURL, aGraphicUrl );
273 // ----------------------------------------------------------------------------
275 /** Converts the AX picture and position to UNO properties. */
276 void lclConvertPicture( AxControlHelper& rHelper, PropertyMap& rPropMap, const StreamDataSequence& rPicData, sal_uInt32 nPicPos )
278 // the picture
279 lclConvertPicture( rHelper, rPropMap, rPicData );
281 // picture position
282 namespace AwtImagePos = ::com::sun::star::awt::ImagePosition;
283 sal_Int16 nImagePos = AwtImagePos::LeftCenter;
284 switch( nPicPos )
286 case AX_PICPOS_LEFTTOP: nImagePos = AwtImagePos::LeftTop; break;
287 case AX_PICPOS_LEFTCENTER: nImagePos = AwtImagePos::LeftCenter; break;
288 case AX_PICPOS_LEFTBOTTOM: nImagePos = AwtImagePos::LeftBottom; break;
289 case AX_PICPOS_RIGHTTOP: nImagePos = AwtImagePos::RightTop; break;
290 case AX_PICPOS_RIGHTCENTER: nImagePos = AwtImagePos::RightCenter; break;
291 case AX_PICPOS_RIGHTBOTTOM: nImagePos = AwtImagePos::RightBottom; break;
292 case AX_PICPOS_ABOVELEFT: nImagePos = AwtImagePos::AboveLeft; break;
293 case AX_PICPOS_ABOVECENTER: nImagePos = AwtImagePos::AboveCenter; break;
294 case AX_PICPOS_ABOVERIGHT: nImagePos = AwtImagePos::AboveRight; break;
295 case AX_PICPOS_BELOWLEFT: nImagePos = AwtImagePos::BelowLeft; break;
296 case AX_PICPOS_BELOWCENTER: nImagePos = AwtImagePos::BelowCenter; break;
297 case AX_PICPOS_BELOWRIGHT: nImagePos = AwtImagePos::BelowRight; break;
298 case AX_PICPOS_CENTER: nImagePos = AwtImagePos::Centered; break;
299 default: OSL_ENSURE( false, "lclConvertPicture - unknown picture position" );
301 rPropMap.setProperty( PROP_ImagePosition, nImagePos );
304 // ----------------------------------------------------------------------------
306 /** Converts the AX picture and position to UNO properties. */
307 void lclConvertPicture( AxControlHelper& rHelper, PropertyMap& rPropMap, const StreamDataSequence& rPicData, sal_Int32 nPicSizeMode, sal_Int32 /*nPicAlign*/, bool /*bPicTiling*/ )
309 // the picture
310 lclConvertPicture( rHelper, rPropMap, rPicData );
312 // picture scale mode
313 namespace AwtScaleMode = ::com::sun::star::awt::ImageScaleMode;
314 sal_Int16 nScaleMode = AwtScaleMode::None;
315 switch( nPicSizeMode )
317 case AX_PICSIZE_CLIP: nScaleMode = AwtScaleMode::None; break;
318 case AX_PICSIZE_STRETCH: nScaleMode = AwtScaleMode::Anisotropic; break;
319 case AX_PICSIZE_ZOOM: nScaleMode = AwtScaleMode::Isotropic; break;
320 default: OSL_ENSURE( false, "lclConvertPicture - unknown picture size mode" );
322 rPropMap.setProperty( PROP_ScaleMode, nScaleMode );
325 // ----------------------------------------------------------------------------
327 /** Converts the AX value for checked/unchecked/dontknow to UNO properties. */
328 void lclConvertState( AxControlHelper& /*rHelper*/, PropertyMap& rPropMap, const OUString& rValue, sal_Int32 nMultiSelect, bool bSupportsTriState )
330 // state
331 sal_Int16 nState = bSupportsTriState ? API_STATE_DONTKNOW : API_STATE_UNCHECKED;
332 if( rValue.getLength() == 1 ) switch( rValue[ 0 ] )
334 case '0': nState = API_STATE_UNCHECKED; break;
335 case '1': nState = API_STATE_CHECKED; break;
336 // any other string (also empty) means 'dontknow'
338 rPropMap.setProperty( PROP_DefaultState, nState );
340 // tristate
341 if( bSupportsTriState )
342 rPropMap.setProperty( PROP_TriState, nMultiSelect == AX_SELCTION_MULTI );
345 // ----------------------------------------------------------------------------
347 /** Converts the AX control orientation to UNO properties. */
348 void lclConvertOrientation( AxControlHelper& /*rHelper*/, PropertyMap& rPropMap, sal_Int32 nOrientation, sal_Int32 nWidth, sal_Int32 nHeight )
350 namespace AwtScrollBarOrient = ::com::sun::star::awt::ScrollBarOrientation;
351 sal_Int32 nScrollOrient = AwtScrollBarOrient::HORIZONTAL;
352 switch( nOrientation )
354 case AX_ORIENTATION_AUTO: if( nWidth <= nHeight) nScrollOrient = AwtScrollBarOrient::VERTICAL; break;
355 case AX_ORIENTATION_VERTICAL: nScrollOrient = AwtScrollBarOrient::VERTICAL; break;
356 case AX_ORIENTATION_HORIZONTAL: nScrollOrient = AwtScrollBarOrient::HORIZONTAL; break;
357 default: OSL_ENSURE( false, "lclConvertOrientation - unknown orientation" );
359 rPropMap.setProperty( PROP_Orientation, nScrollOrient );
362 } // namespace
364 // ============================================================================
366 AxControlModelBase::AxControlModelBase() :
367 mnWidth( 0 ),
368 mnHeight( 0 )
372 AxControlModelBase::~AxControlModelBase()
376 void AxControlModelBase::importProperty( sal_Int32 nPropId, const OUString& rValue )
378 switch( nPropId )
380 // size of the control shape: format is "width;height"
381 case XML_Size:
383 sal_Int32 nSepPos = rValue.indexOf( ';' );
384 OSL_ENSURE( nSepPos >= 0, "AxControlModelBase::importProperty - missing separator in 'Size' property" );
385 if( nSepPos >= 0 )
387 mnWidth = rValue.copy( 0, nSepPos ).toInt32();
388 mnHeight = rValue.copy( nSepPos + 1 ).toInt32();
391 break;
395 void AxControlModelBase::importPictureData( sal_Int32 /*nPropId*/, const StreamDataSequence& /*rDataSeq*/ )
399 void AxControlModelBase::convertProperties( AxControlHelper& /*rHelper*/, PropertyMap& /*rPropMap*/ ) const
403 // ============================================================================
405 AxFontDataModel::AxFontDataModel() :
406 mnFontEffects( 0 ),
407 mnFontHeight( 160 ),
408 mnFontCharSet( 1 ),
409 mnHorAlign( AX_FONTALIGN_LEFT )
413 void AxFontDataModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
415 switch( nPropId )
417 case XML_FontName: maFontName = rValue; break;
418 case XML_FontEffects: mnFontEffects = AttributeList::decodeUnsigned( rValue ); break;
419 case XML_FontHeight: mnFontHeight = AttributeList::decodeInteger( rValue ); break;
420 case XML_FontCharSet: mnFontCharSet = AttributeList::decodeInteger( rValue ); break;
421 case XML_ParagraphAlign: mnHorAlign = AttributeList::decodeInteger( rValue ); break;
422 default: AxControlModelBase::importProperty( nPropId, rValue );
426 void AxFontDataModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
428 namespace cssa = ::com::sun::star::awt;
430 // font name
431 if( maFontName.getLength() > 0 )
432 rPropMap.setProperty( PROP_FontName, maFontName );
434 // font effects
435 rPropMap.setProperty( PROP_FontWeight, getFlagValue( mnFontEffects, AX_FONT_BOLD, cssa::FontWeight::BOLD, cssa::FontWeight::NORMAL ) );
436 rPropMap.setProperty( PROP_FontSlant, getFlagValue< sal_Int16 >( mnFontEffects, AX_FONT_ITALIC, cssa::FontSlant_ITALIC, cssa::FontSlant_NONE ) );
437 rPropMap.setProperty( PROP_FontUnderline, getFlagValue( mnFontEffects, AX_FONT_UNDERLINE, cssa::FontUnderline::SINGLE, cssa::FontUnderline::NONE ) );
438 rPropMap.setProperty( PROP_FontStrikeout, getFlagValue( mnFontEffects, AX_FONT_STRIKEOUT, cssa::FontStrikeout::SINGLE, cssa::FontStrikeout::NONE ) );
440 /* font height in points. MSO uses weird font sizes:
441 1pt->30, 2pt->45, 3pt->60, 4pt->75, 5pt->105, 6pt->120, 7pt->135,
442 8pt->165, 9pt->180, 10pt->195, 11pt->225, ... */
443 sal_Int16 nHeight = getLimitedValue< sal_Int16, sal_Int32 >( (mnFontHeight + 10) / 20, 1, SAL_MAX_INT16 );
444 rPropMap.setProperty( PROP_FontHeight, nHeight );
446 // font character set
447 rtl_TextEncoding eFontEnc = RTL_TEXTENCODING_DONTKNOW;
448 if( (0 <= mnFontCharSet) && (mnFontCharSet <= SAL_MAX_UINT8) )
449 eFontEnc = rtl_getTextEncodingFromWindowsCharset( static_cast< sal_uInt8 >( mnFontCharSet ) );
450 if( eFontEnc != RTL_TEXTENCODING_DONTKNOW )
451 rPropMap.setProperty( PROP_FontCharset, static_cast< sal_Int16 >( eFontEnc ) );
453 // text alignment
454 sal_Int32 nAlign = cssa::TextAlign::LEFT;
455 switch( mnHorAlign )
457 case AX_FONTALIGN_LEFT: nAlign = cssa::TextAlign::LEFT; break;
458 case AX_FONTALIGN_RIGHT: nAlign = cssa::TextAlign::RIGHT; break;
459 case AX_FONTALIGN_CENTER: nAlign = cssa::TextAlign::CENTER; break;
460 default: OSL_ENSURE( false, "AxFontDataModel::convertProperties - unknown text alignment" );
462 // form controls expect short value
463 rPropMap.setProperty( PROP_Align, static_cast< sal_Int16 >( nAlign ) );
465 // process base class properties
466 AxControlModelBase::convertProperties( rHelper, rPropMap );
469 // ============================================================================
471 AxCommandButtonModel::AxCommandButtonModel() :
472 mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
473 mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
474 mnFlags( AX_CMDBUTTON_DEFFLAGS ),
475 mnPicturePos( AX_PICPOS_ABOVECENTER ),
476 mbFocusOnClick( true )
480 void AxCommandButtonModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
482 switch( nPropId )
484 case XML_Caption: maCaption = rValue; break;
485 case XML_ForeColor: mnTextColor = AttributeList::decodeUnsigned( rValue ); break;
486 case XML_BackColor: mnBackColor = AttributeList::decodeUnsigned( rValue ); break;
487 case XML_VariousPropertyBits: mnFlags = AttributeList::decodeUnsigned( rValue ); break;
488 case XML_PicturePosition: mnPicturePos = AttributeList::decodeUnsigned( rValue ); break;
489 case XML_TakeFocusOnClick: mbFocusOnClick = AttributeList::decodeInteger( rValue ) != 0; break;
490 default: AxFontDataModel::importProperty( nPropId, rValue );
494 void AxCommandButtonModel::importPictureData( sal_Int32 nPropId, const StreamDataSequence& rDataSeq )
496 switch( nPropId )
498 case XML_Picture: maPictureData = rDataSeq; break;
499 default: AxFontDataModel::importPictureData( nPropId, rDataSeq );
503 OUString AxCommandButtonModel::getServiceName() const
505 return CREATE_OUSTRING( "com.sun.star.form.component.CommandButton" );
508 void AxCommandButtonModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
510 rPropMap.setProperty( PROP_Label, maCaption );
511 rPropMap.setProperty( PROP_TextColor, rHelper.convertColor( mnTextColor ) );
512 rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
513 rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
514 rPropMap.setProperty( PROP_FocusOnClick, mbFocusOnClick );
515 rPropMap.setProperty( PROP_VerticalAlign, ::com::sun::star::style::VerticalAlignment_MIDDLE );
516 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
517 lclConvertPicture( rHelper, rPropMap, maPictureData, mnPicturePos );
518 AxFontDataModel::convertProperties( rHelper, rPropMap );
521 // ============================================================================
523 AxLabelModel::AxLabelModel() :
524 mnTextColor( AX_SYSCOLOR_BUTTONTEXT ),
525 mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
526 mnFlags( AX_LABEL_DEFFLAGS ),
527 mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
528 mnBorderStyle( AX_BORDERSTYLE_NONE ),
529 mnSpecialEffect( AX_SPECIALEFFECT_FLAT )
533 void AxLabelModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
535 switch( nPropId )
537 case XML_Caption: maCaption = rValue; break;
538 case XML_ForeColor: mnTextColor = AttributeList::decodeUnsigned( rValue ); break;
539 case XML_BackColor: mnBackColor = AttributeList::decodeUnsigned( rValue ); break;
540 case XML_VariousPropertyBits: mnFlags = AttributeList::decodeUnsigned( rValue ); break;
541 case XML_BorderColor: mnBorderColor = AttributeList::decodeUnsigned( rValue ); break;
542 case XML_BorderStyle: mnBorderStyle = AttributeList::decodeInteger( rValue ); break;
543 case XML_SpecialEffect: mnSpecialEffect = AttributeList::decodeInteger( rValue ); break;
544 default: AxFontDataModel::importProperty( nPropId, rValue );
548 OUString AxLabelModel::getServiceName() const
550 return CREATE_OUSTRING( "com.sun.star.form.component.FixedText" );
553 void AxLabelModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
555 rPropMap.setProperty( PROP_Label, maCaption );
556 rPropMap.setProperty( PROP_TextColor, rHelper.convertColor( mnTextColor ) );
557 rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
558 rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
559 rPropMap.setProperty( PROP_VerticalAlign, ::com::sun::star::style::VerticalAlignment_TOP );
560 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
561 lclConvertBorder( rHelper, rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
562 AxFontDataModel::convertProperties( rHelper, rPropMap );
565 // ============================================================================
567 AxImageModel::AxImageModel() :
568 mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
569 mnFlags( AX_IMAGE_DEFFLAGS ),
570 mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
571 mnBorderStyle( AX_BORDERSTYLE_SINGLE ),
572 mnSpecialEffect( AX_SPECIALEFFECT_FLAT ),
573 mnPicSizeMode( AX_PICSIZE_CLIP ),
574 mnPicAlign( AX_PICALIGN_CENTER ),
575 mbPicTiling( false )
579 void AxImageModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
581 switch( nPropId )
583 case XML_BackColor: mnBackColor = AttributeList::decodeUnsigned( rValue ); break;
584 case XML_VariousPropertyBits: mnFlags = AttributeList::decodeUnsigned( rValue ); break;
585 case XML_BorderColor: mnBorderColor = AttributeList::decodeUnsigned( rValue ); break;
586 case XML_BorderStyle: mnBorderStyle = AttributeList::decodeInteger( rValue ); break;
587 case XML_SpecialEffect: mnSpecialEffect = AttributeList::decodeInteger( rValue ); break;
588 case XML_SizeMode: mnPicSizeMode = AttributeList::decodeInteger( rValue ); break;
589 case XML_PictureAlignment: mnPicAlign = AttributeList::decodeInteger( rValue ); break;
590 case XML_PictureTiling: mbPicTiling = AttributeList::decodeInteger( rValue ) != 0; break;
591 default: AxControlModelBase::importProperty( nPropId, rValue );
595 void AxImageModel::importPictureData( sal_Int32 nPropId, const StreamDataSequence& rDataSeq )
597 switch( nPropId )
599 case XML_Picture: maPictureData = rDataSeq; break;
600 default: AxControlModelBase::importPictureData( nPropId, rDataSeq );
604 OUString AxImageModel::getServiceName() const
606 return CREATE_OUSTRING( "com.sun.star.form.component.DatabaseImageControl" );
609 void AxImageModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
611 rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
612 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
613 lclConvertBorder( rHelper, rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
614 lclConvertPicture( rHelper, rPropMap, maPictureData, mnPicSizeMode, mnPicAlign, mbPicTiling );
615 AxControlModelBase::convertProperties( rHelper, rPropMap );
618 // ============================================================================
620 AxMorphDataModel::AxMorphDataModel() :
621 mnTextColor( AX_SYSCOLOR_WINDOWTEXT ),
622 mnBackColor( AX_SYSCOLOR_WINDOWBACK ),
623 mnFlags( AX_MORPHDATA_DEFFLAGS ),
624 mnPicturePos( AX_PICPOS_ABOVECENTER ),
625 mnBorderColor( AX_SYSCOLOR_WINDOWFRAME ),
626 mnBorderStyle( AX_BORDERSTYLE_NONE ),
627 mnSpecialEffect( AX_SPECIALEFFECT_SUNKEN ),
628 mnDisplayStyle( AX_DISPLAYSTYLE_TEXT ),
629 mnMultiSelect( AX_SELCTION_SINGLE ),
630 mnScrollBars( AX_SCROLLBAR_NONE ),
631 mnMatchEntry( AX_MATCHENTRY_NONE ),
632 mnShowDropButton( AX_SHOWDROPBUTTON_NEVER ),
633 mnMaxLength( 0 ),
634 mnPasswordChar( 0 ),
635 mnListRows( 8 )
639 void AxMorphDataModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
641 switch( nPropId )
643 case XML_Caption: maCaption = rValue; break;
644 case XML_Value: maValue = rValue; break;
645 case XML_GroupName: maGroupName = rValue; break;
646 case XML_ForeColor: mnTextColor = AttributeList::decodeUnsigned( rValue ); break;
647 case XML_BackColor: mnBackColor = AttributeList::decodeUnsigned( rValue ); break;
648 case XML_VariousPropertyBits: mnFlags = AttributeList::decodeUnsigned( rValue ); break;
649 case XML_PicturePosition: mnPicturePos = AttributeList::decodeUnsigned( rValue ); break;
650 case XML_BorderColor: mnBorderColor = AttributeList::decodeUnsigned( rValue ); break;
651 case XML_BorderStyle: mnBorderStyle = AttributeList::decodeInteger( rValue ); break;
652 case XML_SpecialEffect: mnSpecialEffect = AttributeList::decodeInteger( rValue ); break;
653 case XML_DisplayStyle: mnDisplayStyle = AttributeList::decodeInteger( rValue ); break;
654 case XML_MultiSelect: mnMultiSelect = AttributeList::decodeInteger( rValue ); break;
655 case XML_ScrollBars: mnScrollBars = AttributeList::decodeInteger( rValue ); break;
656 case XML_MatchEntry: mnMatchEntry = AttributeList::decodeInteger( rValue ); break;
657 case XML_ShowDropButtonWhen: mnShowDropButton = AttributeList::decodeInteger( rValue ); break;
658 case XML_MaxLength: mnMaxLength = AttributeList::decodeInteger( rValue ); break;
659 case XML_PasswordChar: mnPasswordChar = AttributeList::decodeInteger( rValue ); break;
660 case XML_ListRows: mnListRows = AttributeList::decodeInteger( rValue ); break;
661 default: AxFontDataModel::importProperty( nPropId, rValue );
665 void AxMorphDataModel::importPictureData( sal_Int32 nPropId, const StreamDataSequence& rDataSeq )
667 switch( nPropId )
669 case XML_Picture: maPictureData = rDataSeq; break;
670 default: AxFontDataModel::importPictureData( nPropId, rDataSeq );
674 void AxMorphDataModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
676 rPropMap.setProperty( PROP_TextColor, rHelper.convertColor( mnTextColor ) );
677 rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
678 AxFontDataModel::convertProperties( rHelper, rPropMap );
681 // ============================================================================
683 AxToggleButtonModel::AxToggleButtonModel()
687 OUString AxToggleButtonModel::getServiceName() const
689 OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TOGGLE, "AxToggleButtonModel::getServiceName - invalid control type" );
690 return CREATE_OUSTRING( "com.sun.star.form.component.CommandButton" );
693 void AxToggleButtonModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
695 rPropMap.setProperty( PROP_Label, maCaption );
696 rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
697 rPropMap.setProperty( PROP_VerticalAlign, ::com::sun::star::style::VerticalAlignment_MIDDLE );
698 rPropMap.setProperty( PROP_Toggle, true );
699 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
700 lclConvertPicture( rHelper, rPropMap, maPictureData, mnPicturePos );
701 AxMorphDataModel::convertProperties( rHelper, rPropMap );
704 // ============================================================================
706 AxCheckBoxModel::AxCheckBoxModel()
710 OUString AxCheckBoxModel::getServiceName() const
712 OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_CHECKBOX, "AxCheckBoxModel::getServiceName - invalid control type" );
713 return CREATE_OUSTRING( "com.sun.star.form.component.CheckBox" );
716 void AxCheckBoxModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
718 rPropMap.setProperty( PROP_Label, maCaption );
719 rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
720 rPropMap.setProperty( PROP_VerticalAlign, ::com::sun::star::style::VerticalAlignment_MIDDLE );
721 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
722 lclConvertVisualEffect( rHelper, rPropMap, mnSpecialEffect );
723 lclConvertPicture( rHelper, rPropMap, maPictureData, mnPicturePos );
724 lclConvertState( rHelper, rPropMap, maValue, mnMultiSelect, true );
725 AxMorphDataModel::convertProperties( rHelper, rPropMap );
728 // ============================================================================
730 AxOptionButtonModel::AxOptionButtonModel()
734 OUString AxOptionButtonModel::getServiceName() const
736 OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_OPTBUTTON, "AxOptionButtonModel::getServiceName - invalid control type" );
737 return CREATE_OUSTRING( "com.sun.star.form.component.RadioButton" );
740 void AxOptionButtonModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
742 rPropMap.setProperty( PROP_Label, maCaption );
743 rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_WORDWRAP ) );
744 rPropMap.setProperty( PROP_VerticalAlign, ::com::sun::star::style::VerticalAlignment_MIDDLE );
745 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
746 lclConvertVisualEffect( rHelper, rPropMap, mnSpecialEffect );
747 lclConvertPicture( rHelper, rPropMap, maPictureData, mnPicturePos );
748 lclConvertState( rHelper, rPropMap, maValue, mnMultiSelect, false );
749 AxMorphDataModel::convertProperties( rHelper, rPropMap );
752 // ============================================================================
754 AxTextBoxModel::AxTextBoxModel()
758 OUString AxTextBoxModel::getServiceName() const
760 OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_TEXT, "AxTextBoxModel::getServiceName - invalid control type" );
761 return CREATE_OUSTRING( "com.sun.star.form.component.TextField" );
764 void AxTextBoxModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
766 rPropMap.setProperty( PROP_MultiLine, getFlag( mnFlags, AX_FLAGS_MULTILINE ) );
767 rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
768 rPropMap.setProperty( PROP_DefaultText, maValue );
769 rPropMap.setProperty( PROP_MaxTextLen, getLimitedValue< sal_Int16, sal_Int32 >( mnMaxLength, 0, SAL_MAX_INT16 ) );
770 if( (0 < mnPasswordChar) && (mnPasswordChar <= SAL_MAX_INT16) )
771 rPropMap.setProperty( PROP_EchoChar, static_cast< sal_Int16 >( mnPasswordChar ) );
772 rPropMap.setProperty( PROP_HScroll, getFlag( mnScrollBars, AX_SCROLLBAR_HORIZONTAL ) );
773 rPropMap.setProperty( PROP_VScroll, getFlag( mnScrollBars, AX_SCROLLBAR_VERTICAL ) );
774 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
775 lclConvertBorder( rHelper, rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
776 AxMorphDataModel::convertProperties( rHelper, rPropMap );
779 // ============================================================================
781 AxListBoxModel::AxListBoxModel()
785 OUString AxListBoxModel::getServiceName() const
787 OSL_ENSURE( mnDisplayStyle == AX_DISPLAYSTYLE_LISTBOX, "AxListBoxModel::getServiceName - invalid control type" );
788 return CREATE_OUSTRING( "com.sun.star.form.component.ListBox" );
791 void AxListBoxModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
793 bool bMultiSelect = (mnMultiSelect == AX_SELCTION_MULTI) || (mnMultiSelect == AX_SELCTION_EXTENDED);
794 rPropMap.setProperty( PROP_MultiSelection, bMultiSelect );
795 rPropMap.setProperty( PROP_Dropdown, false );
796 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
797 lclConvertBorder( rHelper, rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
798 AxMorphDataModel::convertProperties( rHelper, rPropMap );
801 // ============================================================================
803 AxComboBoxModel::AxComboBoxModel()
807 OUString AxComboBoxModel::getServiceName() const
809 OSL_ENSURE( (mnDisplayStyle == AX_DISPLAYSTYLE_COMBOBOX) || (mnDisplayStyle == AX_DISPLAYSTYLE_DROPDOWN), "AxComboBoxModel::getServiceName - invalid control type" );
810 return (mnDisplayStyle == AX_DISPLAYSTYLE_DROPDOWN) ? CREATE_OUSTRING( "com.sun.star.form.component.ListBox" ) : CREATE_OUSTRING( "com.sun.star.form.component.ComboBox" );
813 void AxComboBoxModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
815 if( mnDisplayStyle != AX_DISPLAYSTYLE_DROPDOWN )
817 rPropMap.setProperty( PROP_HideInactiveSelection, getFlag( mnFlags, AX_FLAGS_HIDESELECTION ) );
818 rPropMap.setProperty( PROP_DefaultText, maValue );
819 rPropMap.setProperty( PROP_MaxTextLen, getLimitedValue< sal_Int16, sal_Int32 >( mnMaxLength, 0, SAL_MAX_INT16 ) );
820 bool bAutoComplete = (mnMatchEntry == AX_MATCHENTRY_FIRSTLETTER) || (mnMatchEntry == AX_MATCHENTRY_COMPLETE);
821 rPropMap.setProperty( PROP_Autocomplete, bAutoComplete );
823 bool bShowDropdown = (mnShowDropButton == AX_SHOWDROPBUTTON_FOCUS) || (mnShowDropButton == AX_SHOWDROPBUTTON_ALWAYS);
824 rPropMap.setProperty( PROP_Dropdown, bShowDropdown );
825 rPropMap.setProperty( PROP_LineCount, getLimitedValue< sal_Int16, sal_Int32 >( mnListRows, 1, SAL_MAX_INT16 ) );
826 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_VOID );
827 lclConvertBorder( rHelper, rPropMap, mnBorderColor, mnBorderStyle, mnSpecialEffect );
828 AxMorphDataModel::convertProperties( rHelper, rPropMap );
831 // ============================================================================
833 AxSpinButtonModel::AxSpinButtonModel() :
834 mnArrowColor( AX_SYSCOLOR_BUTTONTEXT ),
835 mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
836 mnFlags( AX_SPINBUTTON_DEFFLAGS ),
837 mnOrientation( AX_ORIENTATION_AUTO ),
838 mnMin( 0 ),
839 mnMax( 100 ),
840 mnPosition( 0 ),
841 mnSmallChange( 1 ),
842 mnDelay( 50 )
846 OUString AxSpinButtonModel::getServiceName() const
848 return CREATE_OUSTRING( "com.sun.star.form.component.SpinButton" );
851 void AxSpinButtonModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
853 switch( nPropId )
855 case XML_ForeColor: mnArrowColor = AttributeList::decodeUnsigned( rValue ); break;
856 case XML_BackColor: mnBackColor = AttributeList::decodeUnsigned( rValue ); break;
857 case XML_VariousPropertyBits: mnFlags = AttributeList::decodeUnsigned( rValue ); break;
858 case XML_Orientation: mnOrientation = AttributeList::decodeInteger( rValue ); break;
859 case XML_Min: mnMin = AttributeList::decodeInteger( rValue ); break;
860 case XML_Max: mnMax = AttributeList::decodeInteger( rValue ); break;
861 case XML_Position: mnPosition = AttributeList::decodeInteger( rValue ); break;
862 case XML_SmallChange: mnSmallChange = AttributeList::decodeInteger( rValue ); break;
863 case XML_Delay: mnDelay = AttributeList::decodeInteger( rValue ); break;
864 default: AxControlModelBase::importProperty( nPropId, rValue );
868 void AxSpinButtonModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
870 sal_Int32 nMin = ::std::min( mnMin, mnMax );
871 sal_Int32 nMax = ::std::max( mnMin, mnMax );
872 rPropMap.setProperty( PROP_SymbolColor, rHelper.convertColor( mnArrowColor ) );
873 rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
874 rPropMap.setProperty( PROP_SpinValueMin, nMin );
875 rPropMap.setProperty( PROP_SpinValueMax, nMax );
876 rPropMap.setProperty( PROP_SpinIncrement, mnSmallChange );
877 rPropMap.setProperty( PROP_DefaultSpinValue, mnPosition );
878 rPropMap.setProperty( PROP_Repeat, true );
879 rPropMap.setProperty( PROP_RepeatDelay, mnDelay );
880 rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
881 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
882 lclConvertOrientation( rHelper, rPropMap, mnOrientation, mnWidth, mnHeight );
883 AxControlModelBase::convertProperties( rHelper, rPropMap );
886 // ============================================================================
888 AxScrollBarModel::AxScrollBarModel() :
889 mnArrowColor( AX_SYSCOLOR_BUTTONTEXT ),
890 mnBackColor( AX_SYSCOLOR_BUTTONFACE ),
891 mnFlags( AX_SCROLLBAR_DEFFLAGS ),
892 mnOrientation( AX_ORIENTATION_AUTO ),
893 mnPropThumb( AX_PROPTHUMB_ON ),
894 mnMin( 0 ),
895 mnMax( 32767 ),
896 mnPosition( 0 ),
897 mnSmallChange( 1 ),
898 mnLargeChange( 1 ),
899 mnDelay( 50 )
903 OUString AxScrollBarModel::getServiceName() const
905 return CREATE_OUSTRING( "com.sun.star.form.component.ScrollBar" );
908 void AxScrollBarModel::importProperty( sal_Int32 nPropId, const OUString& rValue )
910 switch( nPropId )
912 case XML_ForeColor: mnArrowColor = AttributeList::decodeUnsigned( rValue ); break;
913 case XML_BackColor: mnBackColor = AttributeList::decodeUnsigned( rValue ); break;
914 case XML_VariousPropertyBits: mnFlags = AttributeList::decodeUnsigned( rValue ); break;
915 case XML_Orientation: mnOrientation = AttributeList::decodeInteger( rValue ); break;
916 case XML_ProportionalThumb: mnPropThumb = AttributeList::decodeInteger( rValue ); break;
917 case XML_Min: mnMin = AttributeList::decodeInteger( rValue ); break;
918 case XML_Max: mnMax = AttributeList::decodeInteger( rValue ); break;
919 case XML_Position: mnPosition = AttributeList::decodeInteger( rValue ); break;
920 case XML_SmallChange: mnSmallChange = AttributeList::decodeInteger( rValue ); break;
921 case XML_LargeChange: mnLargeChange = AttributeList::decodeInteger( rValue ); break;
922 case XML_Delay: mnDelay = AttributeList::decodeInteger( rValue ); break;
923 default: AxControlModelBase::importProperty( nPropId, rValue );
927 void AxScrollBarModel::convertProperties( AxControlHelper& rHelper, PropertyMap& rPropMap ) const
929 sal_Int32 nMin = ::std::min( mnMin, mnMax );
930 sal_Int32 nMax = ::std::max( mnMin, mnMax );
931 rPropMap.setProperty( PROP_SymbolColor, rHelper.convertColor( mnArrowColor ) );
932 rPropMap.setProperty( PROP_Enabled, getFlag( mnFlags, AX_FLAGS_ENABLED ) );
933 rPropMap.setProperty( PROP_ScrollValueMin, nMin );
934 rPropMap.setProperty( PROP_ScrollValueMax, nMax );
935 rPropMap.setProperty( PROP_LineIncrement, mnSmallChange );
936 rPropMap.setProperty( PROP_BlockIncrement, mnLargeChange );
937 rPropMap.setProperty( PROP_DefaultScrollValue, mnPosition );
938 rPropMap.setProperty( PROP_RepeatDelay, mnDelay );
939 rPropMap.setProperty( PROP_Border, API_BORDER_NONE );
940 if( (mnPropThumb == AX_PROPTHUMB_ON) && (nMin < nMax) && (mnLargeChange > 0) )
942 double fInterval = nMax - nMin; // prevent integer overflow (fInterval+mnLargeChange may become 0 when int is used)
943 sal_Int32 nThumbLen = getLimitedValue< sal_Int32, double >( (fInterval * mnLargeChange) / (fInterval + mnLargeChange), 1, SAL_MAX_INT32 );
944 rPropMap.setProperty( PROP_VisibleSize, nThumbLen );
946 lclConvertBackground( rHelper, rPropMap, mnBackColor, mnFlags, API_TRANSPARENCY_NOTSUPPORTED );
947 lclConvertOrientation( rHelper, rPropMap, mnOrientation, mnWidth, mnHeight );
948 AxControlModelBase::convertProperties( rHelper, rPropMap );
951 // ============================================================================
953 AxControl::AxControl( const OUString& rName ) :
954 maName( rName )
958 AxControl::~AxControl()
962 AxControlModelBase* AxControl::createModel( const OUString& rClassId )
964 // TODO: move into a factory
965 if( rClassId.equalsIgnoreAsciiCaseAscii( "{D7053240-CE69-11CD-A777-00DD01143C57}" ) ) // Forms.CommandButton.1
966 mxModel.reset( new AxCommandButtonModel );
967 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{978C9E23-D4B0-11CE-BF2D-00AA003F40D0}" ) ) // Forms.Label.1
968 mxModel.reset( new AxLabelModel );
969 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{4C599241-6926-101B-9992-00000B65C6F9}" ) ) // Forms.Image.1
970 mxModel.reset( new AxImageModel );
971 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{8BD21D60-EC42-11CE-9E0D-00AA006002F3}" ) ) // Forms.ToggleButton.1
972 mxModel.reset( new AxToggleButtonModel );
973 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{8BD21D40-EC42-11CE-9E0D-00AA006002F3}" ) ) // Forms.CheckBox.1
974 mxModel.reset( new AxCheckBoxModel );
975 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{8BD21D50-EC42-11CE-9E0D-00AA006002F3}" ) ) // Forms.OptionButton.1
976 mxModel.reset( new AxOptionButtonModel );
977 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{8BD21D10-EC42-11CE-9E0D-00AA006002F3}" ) ) // Forms.TextBox.1
978 mxModel.reset( new AxTextBoxModel );
979 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{8BD21D20-EC42-11CE-9E0D-00AA006002F3}" ) ) // Forms.ListBox.1
980 mxModel.reset( new AxListBoxModel );
981 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{8BD21D30-EC42-11CE-9E0D-00AA006002F3}" ) ) // Forms.ComboBox.1
982 mxModel.reset( new AxComboBoxModel );
983 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{79176FB0-B7F2-11CE-97EF-00AA006D2776}" ) ) // Forms.SpinButton.1
984 mxModel.reset( new AxSpinButtonModel );
985 else if( rClassId.equalsIgnoreAsciiCaseAscii( "{DFD181E0-5E2F-11CE-A449-00AA004A803D}" ) ) // Forms.ScrollBar.1
986 mxModel.reset( new AxScrollBarModel );
987 else
988 mxModel.reset();
990 return mxModel.get();
993 Reference< XControlModel > AxControl::convertAndInsert( AxControlHelper& rHelper ) const
995 Reference< XControlModel > xCtrlModel;
996 if( mxModel.get() ) try
998 Reference< XIndexContainer > xFormIC( rHelper.getControlForm(), UNO_QUERY_THROW );
1000 // document model creates the form control model
1001 xCtrlModel.set( rHelper.getFilter().getModelFactory()->createInstance( mxModel->getServiceName() ), UNO_QUERY_THROW );
1002 Reference< XFormComponent > xFormComp( xCtrlModel, UNO_QUERY_THROW );
1004 // insert control model into the passed form
1005 sal_Int32 nNewIndex = xFormIC->getCount();
1006 xFormIC->insertByIndex( nNewIndex, Any( xFormComp ) );
1008 // convert all control properties
1009 PropertyMap aPropMap;
1010 aPropMap.setProperty( PROP_Name, maName );
1011 mxModel->convertProperties( rHelper, aPropMap );
1013 PropertySet aPropSet( xCtrlModel );
1014 aPropSet.setProperties( aPropMap );
1016 catch( Exception& )
1018 xCtrlModel.clear(); // on error: forget the created form control model
1020 return xCtrlModel;
1023 // ============================================================================
1025 } // namespace ole
1026 } // namespace oox