xref: /aoo41x/main/oox/inc/oox/ole/axcontrol.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef OOX_OLE_AXCONTROL_HXX
29 #define OOX_OLE_AXCONTROL_HXX
30 
31 #include <boost/shared_ptr.hpp>
32 #include "oox/helper/binarystreambase.hxx"
33 #include "oox/helper/propertyset.hxx"
34 #include "oox/ole/axbinaryreader.hxx"
35 #include "oox/ole/olehelper.hxx"
36 
37 namespace com { namespace sun { namespace star {
38     namespace awt { class XControlModel; }
39     namespace container { class XIndexContainer; }
40     namespace drawing { class XDrawPage; }
41     namespace frame { class XModel; }
42     namespace form { class XFormsSupplier; }
43     namespace lang { class XMultiServiceFactory; }
44 } } }
45 
46 namespace oox {
47     class BinaryInputStream;
48     class GraphicHelper;
49     class PropertyMap;
50 }
51 
52 namespace oox {
53 namespace ole {
54 
55 // ============================================================================
56 
57 const sal_Char* const COMCTL_GUID_SCROLLBAR_60      = "{FE38753A-44A3-11D1-B5B7-0000C09000C4}";
58 const sal_Char* const COMCTL_GUID_PROGRESSBAR_50    = "{0713E8D2-850A-101B-AFC0-4210102A8DA7}";
59 const sal_Char* const COMCTL_GUID_PROGRESSBAR_60    = "{35053A22-8589-11D1-B16A-00C0F0283628}";
60 
61 const sal_uInt16 COMCTL_VERSION_50          = 5;
62 const sal_uInt16 COMCTL_VERSION_60          = 6;
63 
64 // ----------------------------------------------------------------------------
65 
66 const sal_Char* const AX_GUID_COMMANDBUTTON = "{D7053240-CE69-11CD-A777-00DD01143C57}";
67 const sal_Char* const AX_GUID_LABEL         = "{978C9E23-D4B0-11CE-BF2D-00AA003F40D0}";
68 const sal_Char* const AX_GUID_IMAGE         = "{4C599241-6926-101B-9992-00000B65C6F9}";
69 const sal_Char* const AX_GUID_TOGGLEBUTTON  = "{8BD21D60-EC42-11CE-9E0D-00AA006002F3}";
70 const sal_Char* const AX_GUID_CHECKBOX      = "{8BD21D40-EC42-11CE-9E0D-00AA006002F3}";
71 const sal_Char* const AX_GUID_OPTIONBUTTON  = "{8BD21D50-EC42-11CE-9E0D-00AA006002F3}";
72 const sal_Char* const AX_GUID_TEXTBOX       = "{8BD21D10-EC42-11CE-9E0D-00AA006002F3}";
73 const sal_Char* const AX_GUID_LISTBOX       = "{8BD21D20-EC42-11CE-9E0D-00AA006002F3}";
74 const sal_Char* const AX_GUID_COMBOBOX      = "{8BD21D30-EC42-11CE-9E0D-00AA006002F3}";
75 const sal_Char* const AX_GUID_SPINBUTTON    = "{79176FB0-B7F2-11CE-97EF-00AA006D2776}";
76 const sal_Char* const AX_GUID_SCROLLBAR     = "{DFD181E0-5E2F-11CE-A449-00AA004A803D}";
77 const sal_Char* const AX_GUID_FRAME         = "{6E182020-F460-11CE-9BCD-00AA00608E01}";
78 
79 const sal_uInt32 AX_SYSCOLOR_WINDOWBACK     = 0x80000005;
80 const sal_uInt32 AX_SYSCOLOR_WINDOWFRAME    = 0x80000006;
81 const sal_uInt32 AX_SYSCOLOR_WINDOWTEXT     = 0x80000008;
82 const sal_uInt32 AX_SYSCOLOR_BUTTONFACE     = 0x8000000F;
83 const sal_uInt32 AX_SYSCOLOR_BUTTONTEXT     = 0x80000012;
84 
85 const sal_uInt32 AX_FLAGS_ENABLED           = 0x00000002;
86 const sal_uInt32 AX_FLAGS_LOCKED            = 0x00000004;
87 const sal_uInt32 AX_FLAGS_OPAQUE            = 0x00000008;
88 const sal_uInt32 AX_FLAGS_COLUMNHEADS       = 0x00000400;
89 const sal_uInt32 AX_FLAGS_ENTIREROWS        = 0x00000800;
90 const sal_uInt32 AX_FLAGS_EXISTINGENTRIES   = 0x00001000;
91 const sal_uInt32 AX_FLAGS_CAPTIONLEFT       = 0x00002000;
92 const sal_uInt32 AX_FLAGS_EDITABLE          = 0x00004000;
93 const sal_uInt32 AX_FLAGS_IMEMODE_MASK      = 0x00078000;
94 const sal_uInt32 AX_FLAGS_DRAGENABLED       = 0x00080000;
95 const sal_uInt32 AX_FLAGS_ENTERASNEWLINE    = 0x00100000;
96 const sal_uInt32 AX_FLAGS_KEEPSELECTION     = 0x00200000;
97 const sal_uInt32 AX_FLAGS_TABASCHARACTER    = 0x00400000;
98 const sal_uInt32 AX_FLAGS_WORDWRAP          = 0x00800000;
99 const sal_uInt32 AX_FLAGS_BORDERSSUPPRESSED = 0x02000000;
100 const sal_uInt32 AX_FLAGS_SELECTLINE        = 0x04000000;
101 const sal_uInt32 AX_FLAGS_SINGLECHARSELECT  = 0x08000000;
102 const sal_uInt32 AX_FLAGS_AUTOSIZE          = 0x10000000;
103 const sal_uInt32 AX_FLAGS_HIDESELECTION     = 0x20000000;
104 const sal_uInt32 AX_FLAGS_MAXLENAUTOTAB     = 0x40000000;
105 const sal_uInt32 AX_FLAGS_MULTILINE         = 0x80000000;
106 
107 const sal_Int32 AX_BORDERSTYLE_NONE         = 0;
108 const sal_Int32 AX_BORDERSTYLE_SINGLE       = 1;
109 
110 const sal_Int32 AX_SPECIALEFFECT_FLAT       = 0;
111 const sal_Int32 AX_SPECIALEFFECT_RAISED     = 1;
112 const sal_Int32 AX_SPECIALEFFECT_SUNKEN     = 2;
113 const sal_Int32 AX_SPECIALEFFECT_ETCHED     = 3;
114 const sal_Int32 AX_SPECIALEFFECT_BUMPED     = 6;
115 
116 const sal_Int32 AX_PICSIZE_CLIP             = 0;
117 const sal_Int32 AX_PICSIZE_STRETCH          = 1;
118 const sal_Int32 AX_PICSIZE_ZOOM             = 3;
119 
120 const sal_Int32 AX_PICALIGN_TOPLEFT         = 0;
121 const sal_Int32 AX_PICALIGN_TOPRIGHT        = 1;
122 const sal_Int32 AX_PICALIGN_CENTER          = 2;
123 const sal_Int32 AX_PICALIGN_BOTTOMLEFT      = 3;
124 const sal_Int32 AX_PICALIGN_BOTTOMRIGHT     = 4;
125 
126 const sal_Int32 AX_DISPLAYSTYLE_TEXT        = 1;
127 const sal_Int32 AX_DISPLAYSTYLE_LISTBOX     = 2;
128 const sal_Int32 AX_DISPLAYSTYLE_COMBOBOX    = 3;
129 const sal_Int32 AX_DISPLAYSTYLE_CHECKBOX    = 4;
130 const sal_Int32 AX_DISPLAYSTYLE_OPTBUTTON   = 5;
131 const sal_Int32 AX_DISPLAYSTYLE_TOGGLE      = 6;
132 const sal_Int32 AX_DISPLAYSTYLE_DROPDOWN    = 7;
133 
134 const sal_Int32 AX_SELCTION_SINGLE          = 0;
135 const sal_Int32 AX_SELCTION_MULTI           = 1;
136 const sal_Int32 AX_SELCTION_EXTENDED        = 2;
137 
138 const sal_Int32 AX_SHOWDROPBUTTON_NEVER     = 0;
139 const sal_Int32 AX_SHOWDROPBUTTON_FOCUS     = 1;
140 const sal_Int32 AX_SHOWDROPBUTTON_ALWAYS    = 2;
141 
142 const sal_Int32 AX_SCROLLBAR_NONE           = 0x00;
143 const sal_Int32 AX_SCROLLBAR_HORIZONTAL     = 0x01;
144 const sal_Int32 AX_SCROLLBAR_VERTICAL       = 0x02;
145 
146 // ----------------------------------------------------------------------------
147 
148 /** Enumerates all UNO API control types supported by these filters. */
149 enum ApiControlType
150 {
151     API_CONTROL_BUTTON,
152     API_CONTROL_FIXEDTEXT,
153     API_CONTROL_IMAGE,
154     API_CONTROL_CHECKBOX,
155     API_CONTROL_RADIOBUTTON,
156     API_CONTROL_EDIT,
157     API_CONTROL_NUMERIC,
158     API_CONTROL_LISTBOX,
159     API_CONTROL_COMBOBOX,
160     API_CONTROL_SPINBUTTON,
161     API_CONTROL_SCROLLBAR,
162     API_CONTROL_TABSTRIP,
163     API_CONTROL_PROGRESSBAR,
164     API_CONTROL_GROUPBOX,
165     API_CONTROL_FRAME,
166     API_CONTROL_PAGE,
167     API_CONTROL_MULTIPAGE,
168     API_CONTROL_DIALOG
169 };
170 
171 // ============================================================================
172 
173 /** Specifies how a form control supports transparent background. */
174 enum ApiTransparencyMode
175 {
176     API_TRANSPARENCY_NOTSUPPORTED,      /// Control does not support transparency.
177     API_TRANSPARENCY_VOID,              /// Transparency is enabled by missing fill color.
178     API_TRANSPARENCY_PAINTTRANSPARENT   /// Transparency is enabled by the 'PaintTransparent' property.
179 };
180 
181 /** Specifies how a form control supports the DefaultState property. */
182 enum ApiDefaultStateMode
183 {
184     API_DEFAULTSTATE_BOOLEAN,           /// Control does not support tri-state, state is given as boolean.
185     API_DEFAULTSTATE_SHORT,             /// Control does not support tri-state, state is given as short.
186     API_DEFAULTSTATE_TRISTATE           /// Control supports tri-state, state is given as short.
187 };
188 
189 // ----------------------------------------------------------------------------
190 
191 /** A base class with useful helper functions for something that is able to
192     convert ActiveX and ComCtl form controls.
193  */
194 class ControlConverter
195 {
196 public:
197     explicit            ControlConverter(
198                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel,
199                             const GraphicHelper& rGraphicHelper,
200                             bool bDefaultColorBgr = true );
201     virtual             ~ControlConverter();
202 
203     // Generic conversion -----------------------------------------------------
204 
205     /** Converts the passed position in 1/100 mm to UNO properties. */
206     void                convertPosition(
207                             PropertyMap& rPropMap,
208                             const AxPairData& rPos ) const;
209 
210     /** Converts the passed size in 1/100 mm to UNO properties. */
211     void                convertSize(
212                             PropertyMap& rPropMap,
213                             const AxPairData& rSize ) const;
214 
215     /** Converts the passed encoded OLE color to UNO properties. */
216     void                convertColor(
217                             PropertyMap& rPropMap,
218                             sal_Int32 nPropId,
219                             sal_uInt32 nOleColor ) const;
220 
221     /** Converts the passed StdPic picture stream to UNO properties. */
222     void                convertPicture(
223                             PropertyMap& rPropMap,
224                             const StreamDataSequence& rPicData ) const;
225 
226     /** Converts the control orientation to UNO properties. */
227     void                convertOrientation(
228                             PropertyMap& rPropMap,
229                             bool bHorizontal ) const;
230 
231     /** Converts the vertical alignment to UNO properties. */
232     void                convertVerticalAlign(
233                             PropertyMap& rPropMap,
234                             sal_Int32 nVerticalAlign ) const;
235 
236     /** Converts common scrollbar settings to UNO properties. */
237     void                convertScrollBar(
238                             PropertyMap& rPropMap,
239                             sal_Int32 nMin, sal_Int32 nMax, sal_Int32 nPosition,
240                             sal_Int32 nSmallChange, sal_Int32 nLargeChange, bool bAwtModel ) const;
241 
242     /** Binds the passed control model to the passed data sources. The
243         implementation will check which source types are supported. */
244     void                bindToSources(
245                             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxCtrlModel,
246                             const ::rtl::OUString& rCtrlSource,
247                             const ::rtl::OUString& rRowSource,
248                             sal_Int32 nRefSheet = 0 ) const;
249 
250     // ActiveX (Forms 2.0) specific conversion --------------------------------
251 
252     /** Converts the Forms 2.0 background formatting to UNO properties. */
253     void                convertAxBackground(
254                             PropertyMap& rPropMap,
255                             sal_uInt32 nBackColor,
256                             sal_uInt32 nFlags,
257                             ApiTransparencyMode eTranspMode ) const;
258 
259     /** Converts the Forms 2.0 border formatting to UNO properties. */
260     void                convertAxBorder(
261                             PropertyMap& rPropMap,
262                             sal_uInt32 nBorderColor,
263                             sal_Int32 nBorderStyle,
264                             sal_Int32 nSpecialEffect ) const;
265 
266     /** Converts the Forms 2.0 special effect to UNO properties. */
267     void                convertAxVisualEffect(
268                             PropertyMap& rPropMap,
269                             sal_Int32 nSpecialEffect ) const;
270 
271     /** Converts the passed picture stream and Forms 2.0 position to UNO
272         properties. */
273     void                convertAxPicture(
274                             PropertyMap& rPropMap,
275                             const StreamDataSequence& rPicData,
276                             sal_uInt32 nPicPos ) const;
277 
278     /** Converts the passed picture stream and Forms 2.0 position to UNO
279         properties. */
280     void                convertAxPicture(
281                             PropertyMap& rPropMap,
282                             const StreamDataSequence& rPicData,
283                             sal_Int32 nPicSizeMode,
284                             sal_Int32 nPicAlign,
285                             bool bPicTiling ) const;
286 
287     /** Converts the Forms 2.0 value for checked/unchecked/dontknow to UNO
288         properties. */
289     void                convertAxState(
290                             PropertyMap& rPropMap,
291                             const ::rtl::OUString& rValue,
292                             sal_Int32 nMultiSelect,
293                             ApiDefaultStateMode eDefStateMode,
294                             bool bAwtModel ) const;
295 
296     /** Converts the Forms 2.0 control orientation to UNO properties. */
297     void                convertAxOrientation(
298                             PropertyMap& rPropMap,
299                             const AxPairData& rSize,
300                             sal_Int32 nOrientation ) const;
301 
302 private:
303     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > mxDocModel;
304     const GraphicHelper& mrGraphicHelper;
305     mutable PropertySet maAddressConverter;
306     mutable PropertySet maRangeConverter;
307     bool                mbDefaultColorBgr;
308 };
309 
310 // ============================================================================
311 
312 /** Base class for all models of form controls. */
313 class ControlModelBase
314 {
315 public:
316     explicit            ControlModelBase();
317     virtual             ~ControlModelBase();
318 
319     /** Sets this control model to AWT model mode. */
320     inline void         setAwtModelMode() { mbAwtModel = true; }
321     /** Sets this control model to form component mode. */
322     inline void         setFormComponentMode() { mbAwtModel = false; }
323 
324     /** Returns the UNO service name used to construct the AWT control model,
325         or the control form component. */
326     ::rtl::OUString     getServiceName() const;
327 
328     /** Derived classes set specific OOXML properties at the model structure. */
329     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
330     /** Derived classes set binary data (picture, mouse icon) at the model structure. */
331     virtual void        importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm );
332     /** Derived classes import a form control model from the passed input stream. */
333     virtual bool        importBinaryModel( BinaryInputStream& rInStrm ) = 0;
334 
335     /** Derived classes return the UNO control type enum value. */
336     virtual ApiControlType getControlType() const = 0;
337     /** Derived classes convert all control properties. */
338     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
339 
340     /** Converts the control size to UNO properties. */
341     void                convertSize( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
342 
343 public: // direct access needed for legacy VML drawing controls
344     AxPairData          maSize;         /// Size of the control in 1/100 mm.
345 
346 protected:
347     bool                mbAwtModel;     /// True = AWT control model, false = form component.
348 };
349 
350 typedef ::boost::shared_ptr< ControlModelBase > ControlModelRef;
351 
352 // ============================================================================
353 
354 /** Base class for all models of ComCtl form controls. */
355 class ComCtlModelBase : public ControlModelBase
356 {
357 public:
358     explicit            ComCtlModelBase(
359                             sal_uInt32 nDataPartId5, sal_uInt32 nDataPartId6, sal_uInt16 nVersion,
360                             bool bCommonPart, bool bComplexPart );
361 
362     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
363     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
364 
365 protected:
366     virtual void        importControlData( BinaryInputStream& rInStrm ) = 0;
367     virtual void        importCommonExtraData( BinaryInputStream& rInStrm );
368     virtual void        importCommonTrailingData( BinaryInputStream& rInStrm );
369 
370 private:
371     /** Returns the data part identifier according to the model version. */
372     sal_uInt32          getDataPartId() const;
373 
374     bool                readPartHeader( BinaryInputStream& rInStrm,
375                             sal_uInt32 nExpPartId,
376                             sal_uInt16 nExpMajor = SAL_MAX_UINT16,
377                             sal_uInt16 nExpMinor = SAL_MAX_UINT16 );
378 
379     bool                importSizePart( BinaryInputStream& rInStrm );
380     bool                importCommonPart( BinaryInputStream& rInStrm, sal_uInt32 nPartSize );
381     bool                importComplexPart( BinaryInputStream& rInStrm );
382 
383 protected:
384     StdFontInfo         maFontData;         /// Font formatting.
385     StreamDataSequence  maMouseIcon;        /// Binary picture stream for mouse icon.
386     sal_uInt32          mnFlags;            /// Common flags for ComCtl controls.
387     const sal_uInt16    mnVersion;          /// Current version of the ComCtl control model.
388 
389 private:
390     sal_uInt32          mnDataPartId5;      /// Identifier for version 5.0 control data.
391     sal_uInt32          mnDataPartId6;      /// Identifier for version 6.0 control data.
392     bool                mbCommonPart;       /// True = the COMCTL_COMMONDATA part exists.
393     bool                mbComplexPart;      /// True = the COMCTL_COMPLEXDATA part exists.
394 };
395 
396 // ============================================================================
397 
398 /** Model for a ComCtl scroll bar. */
399 class ComCtlScrollBarModel : public ComCtlModelBase
400 {
401 public:
402     explicit            ComCtlScrollBarModel( sal_uInt16 nVersion );
403 
404     virtual ApiControlType getControlType() const;
405     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
406 
407 protected:
408     virtual void        importControlData( BinaryInputStream& rInStrm );
409 
410 private:
411     sal_uInt32          mnScrollBarFlags;   /// Special flags for scroll bar model.
412     sal_Int32           mnLargeChange;      /// Increment step size (thumb).
413     sal_Int32           mnSmallChange;      /// Increment step size (buttons).
414     sal_Int32           mnMin;              /// Minimum of the value range.
415     sal_Int32           mnMax;              /// Maximum of the value range.
416     sal_Int32           mnPosition;         /// Value of the spin button.
417 };
418 
419 // ============================================================================
420 
421 /** Model for a ComCtl progress bar. */
422 class ComCtlProgressBarModel : public ComCtlModelBase
423 {
424 public:
425     explicit            ComCtlProgressBarModel( sal_uInt16 nVersion );
426 
427     virtual ApiControlType getControlType() const;
428     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
429 
430 protected:
431     virtual void        importControlData( BinaryInputStream& rInStrm );
432 
433 private:
434     float               mfMin;              /// Minimum of the value range.
435     float               mfMax;              /// Maximum of the value range.
436     sal_uInt16          mnVertical;         /// 0 = horizontal, 1 = vertical.
437     sal_uInt16          mnSmooth;           /// 0 = progress blocks, 1 = pixel resolution.
438 };
439 
440 // ============================================================================
441 
442 /** Base class for all models of Form 2.0 form controls. */
443 class AxControlModelBase : public ControlModelBase
444 {
445 public:
446     explicit            AxControlModelBase();
447 
448     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
449 };
450 
451 // ============================================================================
452 
453 /** Base class for Forms 2.0 controls supporting text formatting. */
454 class AxFontDataModel : public AxControlModelBase
455 {
456 public:
457     explicit            AxFontDataModel( bool bSupportsAlign = true );
458 
459     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
460     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
461     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
462 
463     /** Returns the font height in points. */
464     inline sal_Int16    getFontHeight() const { return maFontData.getHeightPoints(); }
465 
466 public: // direct access needed for legacy VML drawing controls
467     AxFontData          maFontData;         /// The font settings.
468 
469 private:
470     bool                mbSupportsAlign;    /// True = UNO model supports Align property.
471 };
472 
473 // ============================================================================
474 
475 /** Model for a Forms 2.0 command button. */
476 class AxCommandButtonModel : public AxFontDataModel
477 {
478 public:
479     explicit            AxCommandButtonModel();
480 
481     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
482     virtual void        importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm );
483     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
484 
485     virtual ApiControlType getControlType() const;
486     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
487 
488 public: // direct access needed for legacy VML drawing controls
489     StreamDataSequence  maPictureData;      /// Binary picture stream.
490     ::rtl::OUString     maCaption;          /// Visible caption of the button.
491     sal_uInt32          mnTextColor;        /// Text color.
492     sal_uInt32          mnBackColor;        /// Fill color.
493     sal_uInt32          mnFlags;            /// Various flags.
494     sal_uInt32          mnPicturePos;       /// Position of the picture relative to text.
495     sal_Int32           mnVerticalAlign;    /// Vertical alignment (legacy VML drawing controls only).
496     bool                mbFocusOnClick;     /// True = take focus on click.
497 };
498 
499 // ============================================================================
500 
501 /** Model for a Forms 2.0 label. */
502 class AxLabelModel : public AxFontDataModel
503 {
504 public:
505     explicit            AxLabelModel();
506 
507     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
508     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
509 
510     virtual ApiControlType getControlType() const;
511     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
512 
513 public: // direct access needed for legacy VML drawing controls
514     ::rtl::OUString     maCaption;          /// Visible caption of the button.
515     sal_uInt32          mnTextColor;        /// Text color.
516     sal_uInt32          mnBackColor;        /// Fill color.
517     sal_uInt32          mnFlags;            /// Various flags.
518     sal_uInt32          mnBorderColor;      /// Flat border color.
519     sal_Int32           mnBorderStyle;      /// Flat border style.
520     sal_Int32           mnSpecialEffect;    /// 3D border effect.
521     sal_Int32           mnVerticalAlign;    /// Vertical alignment (legacy VML drawing controls only).
522 };
523 
524 // ============================================================================
525 
526 /** Model for a Forms 2.0 image. */
527 class AxImageModel : public AxControlModelBase
528 {
529 public:
530     explicit            AxImageModel();
531 
532     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
533     virtual void        importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm );
534     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
535 
536     virtual ApiControlType getControlType() const;
537     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
538 
539 private:
540     StreamDataSequence  maPictureData;      /// Binary picture stream.
541     sal_uInt32          mnBackColor;        /// Fill color.
542     sal_uInt32          mnFlags;            /// Various flags.
543     sal_uInt32          mnBorderColor;      /// Flat border color.
544     sal_Int32           mnBorderStyle;      /// Flat border style.
545     sal_Int32           mnSpecialEffect;    /// 3D border effect.
546     sal_Int32           mnPicSizeMode;      /// Clip, stretch, zoom.
547     sal_Int32           mnPicAlign;         /// Anchor position of the picture.
548     bool                mbPicTiling;        /// True = picture is repeated.
549 };
550 
551 // ============================================================================
552 
553 /** Base class for a Forms 2.0 morph data control. */
554 class AxMorphDataModelBase : public AxFontDataModel
555 {
556 public:
557     explicit            AxMorphDataModelBase();
558 
559     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
560     virtual void        importPictureData( sal_Int32 nPropId, BinaryInputStream& rInStrm );
561     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
562     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
563 
564 public: // direct access needed for legacy VML drawing controls
565     StreamDataSequence  maPictureData;      /// Binary picture stream.
566     ::rtl::OUString     maCaption;          /// Visible caption of the button.
567     ::rtl::OUString     maValue;            /// Current value of the control.
568     ::rtl::OUString     maGroupName;        /// Group name for option buttons.
569     sal_uInt32          mnTextColor;        /// Text color.
570     sal_uInt32          mnBackColor;        /// Fill color.
571     sal_uInt32          mnFlags;            /// Various flags.
572     sal_uInt32          mnPicturePos;       /// Position of the picture relative to text.
573     sal_uInt32          mnBorderColor;      /// Flat border color.
574     sal_Int32           mnBorderStyle;      /// Flat border style.
575     sal_Int32           mnSpecialEffect;    /// 3D border effect.
576     sal_Int32           mnDisplayStyle;     /// Type of the morph control.
577     sal_Int32           mnMultiSelect;      /// Selection mode.
578     sal_Int32           mnScrollBars;       /// Horizontal/vertical scroll bar.
579     sal_Int32           mnMatchEntry;       /// Auto completion mode.
580     sal_Int32           mnShowDropButton;   /// When to show the dropdown button.
581     sal_Int32           mnMaxLength;        /// Maximum character count.
582     sal_Int32           mnPasswordChar;     /// Password character in edit fields.
583     sal_Int32           mnListRows;         /// Number of rows in dropdown box.
584     sal_Int32           mnVerticalAlign;    /// Vertical alignment (legacy VML drawing controls only).
585 };
586 
587 // ============================================================================
588 
589 /** Model for a Forms 2.0 toggle button. */
590 class AxToggleButtonModel : public AxMorphDataModelBase
591 {
592 public:
593     explicit            AxToggleButtonModel();
594 
595     virtual ApiControlType getControlType() const;
596     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
597 };
598 
599 // ============================================================================
600 
601 /** Model for a Forms 2.0 check box. */
602 class AxCheckBoxModel : public AxMorphDataModelBase
603 {
604 public:
605     explicit            AxCheckBoxModel();
606 
607     virtual ApiControlType getControlType() const;
608     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
609 };
610 
611 // ============================================================================
612 
613 /** Model for a Forms 2.0 option button. */
614 class AxOptionButtonModel : public AxMorphDataModelBase
615 {
616 public:
617     explicit            AxOptionButtonModel();
618 
619     /** Returns the group name used to goup several option buttons gogether. */
620     inline const ::rtl::OUString& getGroupName() const { return maGroupName; }
621 
622     virtual ApiControlType getControlType() const;
623     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
624 };
625 
626 // ============================================================================
627 
628 /** Model for a Forms 2.0 text box. */
629 class AxTextBoxModel : public AxMorphDataModelBase
630 {
631 public:
632     explicit            AxTextBoxModel();
633 
634     virtual ApiControlType getControlType() const;
635     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
636 };
637 
638 // ============================================================================
639 
640 /** Model for a numeric field (legacy drawing controls only). */
641 class AxNumericFieldModel : public AxMorphDataModelBase
642 {
643 public:
644     explicit            AxNumericFieldModel();
645 
646     virtual ApiControlType getControlType() const;
647     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
648 };
649 
650 // ============================================================================
651 
652 /** Model for a Forms 2.0 list box. */
653 class AxListBoxModel : public AxMorphDataModelBase
654 {
655 public:
656     explicit            AxListBoxModel();
657 
658     virtual ApiControlType getControlType() const;
659     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
660 };
661 
662 // ============================================================================
663 
664 /** Model for a Forms 2.0 combo box. */
665 class AxComboBoxModel : public AxMorphDataModelBase
666 {
667 public:
668     explicit            AxComboBoxModel();
669 
670     virtual ApiControlType getControlType() const;
671     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
672 };
673 
674 // ============================================================================
675 
676 /** Model for a Forms 2.0 spin button. */
677 class AxSpinButtonModel : public AxControlModelBase
678 {
679 public:
680     explicit            AxSpinButtonModel();
681 
682     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
683     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
684 
685     virtual ApiControlType getControlType() const;
686     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
687 
688 public: // direct access needed for legacy VML drawing controls
689     sal_uInt32          mnArrowColor;       /// Button arrow color.
690     sal_uInt32          mnBackColor;        /// Fill color.
691     sal_uInt32          mnFlags;            /// Various flags.
692     sal_Int32           mnOrientation;      /// Orientation of the buttons.
693     sal_Int32           mnMin;              /// Minimum of the value range.
694     sal_Int32           mnMax;              /// Maximum of the value range.
695     sal_Int32           mnPosition;         /// Value of the spin button.
696     sal_Int32           mnSmallChange;      /// Increment step size.
697     sal_Int32           mnDelay;            /// Repeat delay in milliseconds.
698 };
699 
700 // ============================================================================
701 
702 /** Model for a Forms 2.0 scroll bar. */
703 class AxScrollBarModel : public AxControlModelBase
704 {
705 public:
706     explicit            AxScrollBarModel();
707 
708     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
709     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
710 
711     virtual ApiControlType getControlType() const;
712     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
713 
714 public: // direct access needed for legacy VML drawing controls
715     sal_uInt32          mnArrowColor;       /// Button arrow color.
716     sal_uInt32          mnBackColor;        /// Fill color.
717     sal_uInt32          mnFlags;            /// Various flags.
718     sal_Int32           mnOrientation;      /// Orientation of the buttons.
719     sal_Int32           mnPropThumb;        /// Proportional thumb size.
720     sal_Int32           mnMin;              /// Minimum of the value range.
721     sal_Int32           mnMax;              /// Maximum of the value range.
722     sal_Int32           mnPosition;         /// Value of the spin button.
723     sal_Int32           mnSmallChange;      /// Increment step size (buttons).
724     sal_Int32           mnLargeChange;      /// Increment step size (thumb).
725     sal_Int32           mnDelay;            /// Repeat delay in milliseconds.
726 };
727 
728 // ============================================================================
729 
730 /** Model for a Forms 2.0 tabstrip control. */
731 class AxTabStripModel : public AxFontDataModel
732 {
733 public:
734     explicit            AxTabStripModel();
735 
736     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
737 
738     virtual ApiControlType getControlType() const;
739     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
740 
741     /** Returns the caption with the specified zero-based index. */
742     ::rtl::OUString     getCaption( sal_Int32 nIndex ) const;
743 
744 private:
745     AxStringArray       maCaptions;         /// Captions of all tabs.
746     sal_uInt32          mnBackColor;        /// Fill color.
747     sal_uInt32          mnTextColor;        /// Text color.
748     sal_uInt32          mnFlags;            /// Various flags.
749     sal_Int32           mnSelectedTab;      /// The index of the selected tab.
750     sal_uInt32          mnTabStyle;         /// Visual style of the tabs.
751     sal_Int32           mnTabFlagCount;     /// Number of entries in tab flag array.
752 };
753 
754 typedef ::boost::shared_ptr< AxTabStripModel > AxTabStripModelRef;
755 
756 // ============================================================================
757 
758 typedef ::std::vector< ::rtl::OUString > AxClassTable;
759 
760 /** Base class for ActiveX container controls. */
761 class AxContainerModelBase : public AxFontDataModel
762 {
763 public:
764     explicit            AxContainerModelBase( bool bFontSupport = false );
765 
766     /** Allows to set single properties specified by XML token identifier. */
767     virtual void        importProperty( sal_Int32 nPropId, const ::rtl::OUString& rValue );
768     /** Reads the leading structure in the 'f' stream containing the model for
769         this control. */
770     virtual bool        importBinaryModel( BinaryInputStream& rInStrm );
771     /** Converts font settings if supported. */
772     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
773 
774     /** Reads the class table structure for embedded controls following the own
775         model from the 'f' stream. */
776     bool                importClassTable( BinaryInputStream& rInStrm, AxClassTable& orClassTable );
777 
778 public: // direct access needed for legacy VML drawing controls
779     StreamDataSequence  maPictureData;      /// Binary picture stream.
780     ::rtl::OUString     maCaption;          /// Visible caption of the form.
781     AxPairData          maLogicalSize;      /// Logical form size (scroll area).
782     AxPairData          maScrollPos;        /// Scroll position.
783     sal_uInt32          mnBackColor;        /// Fill color.
784     sal_uInt32          mnTextColor;        /// Text color.
785     sal_uInt32          mnFlags;            /// Various flags.
786     sal_uInt32          mnBorderColor;      /// Flat border color.
787     sal_Int32           mnBorderStyle;      /// Flat border style.
788     sal_Int32           mnScrollBars;       /// Horizontal/vertical scroll bar.
789     sal_Int32           mnCycleType;        /// Cycle in all forms or in this form.
790     sal_Int32           mnSpecialEffect;    /// 3D border effect.
791     sal_Int32           mnPicAlign;         /// Anchor position of the picture.
792     sal_Int32           mnPicSizeMode;      /// Clip, stretch, zoom.
793     bool                mbPicTiling;        /// True = picture is repeated.
794     bool                mbFontSupport;      /// True = control supports the font property.
795 };
796 
797 typedef ::boost::shared_ptr< AxContainerModelBase > AxContainerModelRef;
798 
799 // ============================================================================
800 
801 /** Model for a Forms 2.0 frame control. */
802 class AxFrameModel : public AxContainerModelBase
803 {
804 public:
805     explicit            AxFrameModel();
806 
807     virtual ApiControlType getControlType() const;
808     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
809 };
810 
811 // ============================================================================
812 
813 /** Model for a Forms 2.0 formpage control (a single page in a multipage control). */
814 class AxFormPageModel : public AxContainerModelBase
815 {
816 public:
817     explicit            AxFormPageModel();
818 
819     virtual ApiControlType getControlType() const;
820     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
821 };
822 
823 // ============================================================================
824 
825 /** Model for a Forms 2.0 multipage control. Contains the tabstrip control
826     (class AxTabStripModel) and the single pages (class AxFormPageModel). */
827 class AxMultiPageModel : public AxContainerModelBase
828 {
829 public:
830     explicit            AxMultiPageModel();
831 
832     virtual ApiControlType getControlType() const;
833     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
834 
835     /** Sets the tabstrip control model related to this multipage control.
836         Contains all formatting attributes of the page tabs. */
837     void                setTabStripModel( const AxTabStripModelRef& rxTabStrip );
838 
839 private:
840     AxTabStripModelRef  mxTabStrip;
841 };
842 
843 // ============================================================================
844 
845 /** Model for a Forms 2.0 user form. */
846 class AxUserFormModel : public AxContainerModelBase
847 {
848 public:
849     explicit            AxUserFormModel();
850 
851     virtual ApiControlType getControlType() const;
852     virtual void        convertProperties( PropertyMap& rPropMap, const ControlConverter& rConv ) const;
853 };
854 
855 // ============================================================================
856 
857 /** A form control embedded in a document draw page. Contains a specific model
858     structure according to the type of the control. */
859 class EmbeddedControl
860 {
861 public:
862     explicit            EmbeddedControl( const ::rtl::OUString& rName );
863     virtual             ~EmbeddedControl();
864 
865     /** Creates and returns the internal control model of the specified type. */
866     template< typename ModelType >
867     inline ModelType&   createModel();
868 
869     /** Creates and returns the internal control model of the specified type. */
870     template< typename ModelType, typename ParamType >
871     inline ModelType&   createModel( const ParamType& rParam );
872 
873     /** Creates and returns the internal control model according to the passed
874         MS class identifier. */
875     ControlModelBase*   createModelFromGuid( const ::rtl::OUString& rClassId );
876 
877     /** Returns true, if the internal control model exists. */
878     inline bool         hasModel() const { return mxModel.get() != 0; }
879     /** Returns read-only access to the internal control model. */
880     inline const ControlModelBase* getModel() const { return mxModel.get(); }
881     /** Returns read/write access to the internal control model. */
882     inline ControlModelBase* getModel() { return mxModel.get(); }
883 
884     /** Returns the UNO service name needed to construct the control model. */
885     ::rtl::OUString     getServiceName() const;
886 
887     /** Converts all control properties and inserts them into the passed model. */
888     bool                convertProperties(
889                             const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >& rxCtrlModel,
890                             const ControlConverter& rConv ) const;
891 
892 private:
893     ControlModelRef     mxModel;            /// Control model containing the properties.
894     ::rtl::OUString     maName;             /// Name of the control.
895 };
896 
897 // ----------------------------------------------------------------------------
898 
899 template< typename ModelType >
900 inline ModelType& EmbeddedControl::createModel()
901 {
902     ::boost::shared_ptr< ModelType > xModel( new ModelType );
903     mxModel = xModel;
904     xModel->setFormComponentMode();
905     return *xModel;
906 }
907 
908 template< typename ModelType, typename ParamType >
909 inline ModelType& EmbeddedControl::createModel( const ParamType& rParam )
910 {
911     ::boost::shared_ptr< ModelType > xModel( new ModelType( rParam ) );
912     mxModel = xModel;
913     xModel->setFormComponentMode();
914     return *xModel;
915 }
916 
917 // ============================================================================
918 
919 /** A wrapper for a control form embedded directly in a draw page. */
920 class EmbeddedForm
921 {
922 public:
923     explicit            EmbeddedForm(
924                             const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxDocModel,
925                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >& rxDrawPage,
926                             const GraphicHelper& rGraphicHelper,
927                             bool bDefaultColorBgr = true );
928 
929     /** Converts the passed control and inserts the control model into the form.
930         @return  The API control model, if conversion was successful. */
931     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel >
932                         convertAndInsert( const EmbeddedControl& rControl, sal_Int32& rnCtrlIndex );
933 
934     /** Returns the XIndexContainer interface of the UNO control form, if existing. */
935     inline ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
936                         getXForm() const { return mxFormIC; }
937 
938 private:
939     /** Creates the form that will hold the form controls. */
940     ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >
941                         createXForm();
942 
943 private:
944     ControlConverter    maControlConv;
945     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > mxModelFactory;
946     ::com::sun::star::uno::Reference< ::com::sun::star::form::XFormsSupplier > mxFormsSupp;
947     ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > mxFormIC;
948 };
949 
950 // ============================================================================
951 
952 } // namespace ole
953 } // namespace oox
954 
955 #endif
956