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