1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 #ifndef INCLUDED_FILTER_MSFILTER_MSTOOLBAR_HXX
10 #define INCLUDED_FILTER_MSFILTER_MSTOOLBAR_HXX
15 #include <com/sun/star/uno/Any.hxx>
16 #include <com/sun/star/uno/Reference.hxx>
17 #include <filter/msfilter/msfilterdllapi.h>
18 #include <rtl/ustring.hxx>
19 #include <sal/types.h>
20 #include <tools/stream.hxx>
21 #include <vcl/bitmapex.hxx>
23 namespace com
{ namespace sun
{ namespace star
{
24 namespace beans
{ struct PropertyValue
; }
25 namespace container
{ class XIndexAccess
; }
26 namespace graphic
{ class XGraphic
; }
27 namespace ui
{ class XUIConfigurationManager
; }
28 namespace ui
{ class XUIConfigurationManagerSupplier
; }
33 class MSOCommandConvertor
36 virtual ~MSOCommandConvertor() {}
37 virtual OUString
MSOCommandToOOCommand( sal_Int16 msoCmd
) = 0;
38 virtual OUString
MSOTCIDToOOCommand( sal_Int16 msoTCID
) = 0;
43 class MSFILTER_DLLPUBLIC CustomToolBarImportHelper
45 struct iconcontrolitem
48 css::uno::Reference
< css::graphic::XGraphic
> image
;
50 std::vector
< iconcontrolitem
> iconcommands
;
51 std::unique_ptr
< MSOCommandConvertor
> pMSOCmdConvertor
;
52 css::uno::Reference
< css::ui::XUIConfigurationManagerSupplier
> m_xCfgSupp
;
53 css::uno::Reference
< css::ui::XUIConfigurationManager
> m_xAppCfgMgr
;
54 SfxObjectShell
& mrDocSh
;
55 static void ScaleImage( css::uno::Reference
< css::graphic::XGraphic
>& xGraphic
, long nNewSize
);
57 CustomToolBarImportHelper( SfxObjectShell
& rDocSh
, const css::uno::Reference
< css::ui::XUIConfigurationManager
>& rxAppCfgMgr
);
59 void setMSOCommandMap( MSOCommandConvertor
* pCnvtr
) { pMSOCmdConvertor
.reset( pCnvtr
); }
60 css::uno::Reference
< css::ui::XUIConfigurationManager
> getCfgManager();
61 const css::uno::Reference
< css::ui::XUIConfigurationManager
>& getAppCfgManager() const { return m_xAppCfgMgr
;}
64 static css::uno::Any
createCommandFromMacro( const OUString
& sCmd
);
66 void addIcon( const css::uno::Reference
< css::graphic::XGraphic
>& xImage
, const OUString
& sString
);
68 OUString
MSOCommandToOOCommand( sal_Int16 msoCmd
);
69 OUString
MSOTCIDToOOCommand( sal_Int16 msoTCID
);
70 SfxObjectShell
& GetDocShell() { return mrDocSh
; }
71 bool createMenu( const OUString
& rName
, const css::uno::Reference
< css::container::XIndexAccess
>& xMenuDesc
);
74 class MSFILTER_DLLPUBLIC TBBase
77 static int nIndent
; // num spaces to indent before printing
79 #ifdef DEBUG_FILTER_MSTOOLBAR
80 static void indent_printf(FILE* fp
, const char* format
, ... );
82 sal_uInt32 nOffSet
; // usually for debug we can store the offset in the stream to this record
84 TBBase() : nOffSet( 0 ) {}
87 TBBase(TBBase
const &) = default;
88 TBBase(TBBase
&&) = default;
89 TBBase
& operator =(TBBase
const &) = default;
90 TBBase
& operator =(TBBase
&&) = default;
92 virtual bool Read(SvStream
&rS
) = 0;
93 #ifdef DEBUG_FILTER_MSTOOLBAR
94 virtual void Print( FILE* ) {} // #FIXME remove this an implement the debug routines in all the classes below to enable some sort of readable output
96 sal_uInt32
GetOffset() const { return nOffSet
; }
107 TBBase::nIndent
= TBBase::nIndent
+ 2;
109 ~Indent() { TBBase::nIndent
= TBBase::nIndent
- 2; }
113 class MSFILTER_DLLPUBLIC WString final
: public TBBase
119 bool Read(SvStream
&rS
) override
;
120 const OUString
& getString() const { return sString
; }
123 class MSFILTER_DLLPUBLIC TBCExtraInfo final
: public TBBase
125 WString wstrHelpFile
;
126 sal_Int32 idHelpContext
;
128 WString wstrOnAction
;
133 TBCExtraInfo(const TBCExtraInfo
&) = delete;
134 TBCExtraInfo
& operator = ( const TBCExtraInfo
&) = delete;
137 bool Read(SvStream
&rS
) override
;
138 #ifdef DEBUG_FILTER_MSTOOLBAR
139 virtual void Print( FILE* ) override
;
141 OUString
const & getOnAction() const;
144 class MSFILTER_DLLPUBLIC TBCGeneralInfo final
: public TBBase
148 WString descriptionText
;
150 TBCExtraInfo extraInfo
;
154 bool Read(SvStream
&rS
) override
;
155 void ImportToolBarControlData( CustomToolBarImportHelper
&, std::vector
< css::beans::PropertyValue
>& );
156 OUString
const & CustomText() { return customText
.getString(); }
159 class MSFILTER_DLLPUBLIC TBCBitMap final
: public TBBase
161 friend class TBCBSpecific
; // #FIXME hacky access, need to fix
166 virtual ~TBCBitMap() override
;
167 bool Read(SvStream
&rS
) override
;
168 #ifdef DEBUG_FILTER_MSTOOLBAR
169 virtual void Print( FILE* ) override
;
172 BitmapEx
& getBitMap() { return mBitMap
;}
175 class MSFILTER_DLLPUBLIC TBCMenuSpecific final
: public TBBase
178 std::shared_ptr
< WString
> name
; //exist only if tbid equals 0x00000001
181 bool Read(SvStream
&rS
) override
;
185 class MSFILTER_DLLPUBLIC TBCCDData final
: public TBBase
187 sal_Int16 cwstrItems
; //Signed integer that specifies the number of items in wstrList. MUST be positive.
188 std::vector
< WString
> wstrList
; // Zero-based index array of WString structures. Number of elements MUST be equal to cwstrItems.
189 sal_Int16 cwstrMRU
; // Signed integer that specifies the number of most recently used string
190 sal_Int16 iSel
; // Signed integer that specifies the zero-based index of the selected item in the wstrList field. MUST be equal to 0xFFFF (-1) or greater than or equal to 0x0000.
191 sal_Int16 cLines
; // Signed integer that specifies the suggested number of lines that the toolbar control will display at any time when displaying the elements of wstrList of available items.
192 sal_Int16 dxWidth
; // Signed integer that specifies the width in pixels that the interior of the dropdown has. This excludes the width of the toolbar control border and scroll bar.
193 WString wstrEdit
; //Structure of type WString. Editable text for editable area of the ComboBox toolbar control.
197 virtual ~TBCCDData() override
;
198 bool Read(SvStream
&rS
) override
;
201 class TBCComboDropdownSpecific final
: public TBBase
203 std::shared_ptr
< TBCCDData
> data
;
205 TBCComboDropdownSpecific( const TBCHeader
& header
);
206 bool Read(SvStream
&rS
) override
;
209 class TBCBSpecific
: public TBBase
212 std::shared_ptr
< TBCBitMap
> icon
; // optional
213 std::shared_ptr
< TBCBitMap
> iconMask
; // optional
214 std::shared_ptr
< sal_uInt16
> iBtnFace
; // optional
215 std::shared_ptr
< WString
> wstrAcc
; // optional
219 bool Read(SvStream
&rS
) override
;
220 // #TODO just add a getGraphic member here
221 TBCBitMap
* getIcon();
222 TBCBitMap
* getIconMask();
223 sal_uInt16
* getBtnFace() { return iBtnFace
.get(); }
226 /* TBCHeader.tct controlSpecificInfo type
228 0x01 (Button control) TBCBSpecific
229 0x10 (ExpandingGrid control) TBCBSpecific
230 0x0A (Popup control) TBCMenuSpecific
231 0x0C (ButtonPopup control) TBCMenuSpecific
232 0x0D (SplitButtonPopup control) TBCMenuSpecific
233 0x0E (SplitButtonMRUPopup control) TBCMenuSpecific
234 0x02 (Edit control) TBCComboDropdow nSpecific
235 0x04 (ComboBox control) TBCComboDropdow nSpecific
236 0x14 (GraphicCombo control) TBCComboDropdow nSpecific
237 0x03 (DropDown control) TBCComboDropdow nSpecific
238 0x06 (SplitDropDown control) TBCComboDropdow nSpecific
239 0x09 (GraphicDropDown control) TBCComboDropdow nSpecific
240 0x07 (OCXDropDown control) controlSpecificInfo MUST NOT exist
241 0x0F (Label control) controlSpecificInfo MUST NOT exist
242 0x12 (Grid control) controlSpecificInfo MUST NOT exist
243 0x13 (Gauge control) controlSpecificInfo MUST NOT exist
244 0x16 (ActiveX control) controlSpecificInfo MUST NOT exist
247 class MSFILTER_DLLPUBLIC TBCHeader
: public TBBase
256 std::shared_ptr
< sal_uInt16
> width
; //optional
257 std::shared_ptr
< sal_uInt16
> height
; //optional
261 virtual ~TBCHeader() override
;
263 TBCHeader(TBCHeader
const &) = default;
264 TBCHeader(TBCHeader
&&) = default;
265 TBCHeader
& operator =(TBCHeader
const &) = default;
266 TBCHeader
& operator =(TBCHeader
&&) = default;
268 sal_uInt8
getTct() const { return tct
; }
269 sal_uInt16
getTcID() const { return tcid
; }
270 bool isVisible() const { return !( bFlagsTCR
& 0x1 ); }
271 bool isBeginGroup() const { return ( bFlagsTCR
& 0x2 ) != 0; }
272 bool Read(SvStream
&rS
) override
;
273 #ifdef DEBUG_FILTER_MSTOOLBAR
274 virtual void Print( FILE* ) override
;
276 sal_uInt32
getTbct() const { return tbct
; };
279 class MSFILTER_DLLPUBLIC TBCData final
: public TBBase
282 TBCGeneralInfo controlGeneralInfo
;
283 std::shared_ptr
< TBBase
> controlSpecificInfo
; // can be one of TBCBSpecific, TBCMenuSpecific or TBCComboDropdow nSpecific depending on the control type specified by TBCHeader.tct
284 TBCData(const TBCData
&) = delete;
285 TBCData
& operator = ( const TBCData
&) = delete;
287 TBCData( const TBCHeader
& Header
);
288 bool Read(SvStream
&rS
) override
;
289 #ifdef DEBUG_FILTER_MSTOOLBAR
290 virtual void Print( FILE* ) override
;
292 void ImportToolBarControl( CustomToolBarImportHelper
&, std::vector
< css::beans::PropertyValue
>&, bool& bBeginGroup
, bool bIsMenuBar
);
293 TBCGeneralInfo
& getGeneralInfo() { return controlGeneralInfo
; }
294 TBCMenuSpecific
* getMenuSpecific();
297 class MSFILTER_DLLPUBLIC TB final
: public TBBase
299 sal_uInt8 bSignature
;// Signed integer that specifies the toolbar signature number. MUST be 0x02.
300 sal_uInt8 bVersion
; // Signed integer that specifies the toolbar version number. MUST be 0x01.
301 sal_Int16 cCL
; // Signed integer that SHOULD specify the number of toolbar controls contained in this toolbar.
302 sal_Int32 ltbid
;// Signed integer that specifies the toolbar ID. MUST be 0x0001 (custom toolbar ID).
303 sal_uInt32 ltbtr
;// Unsigned integer of type TBTRFlags that specifies the toolbar type and toolbar restrictions.
304 sal_uInt16 cRowsDefault
;// Unsigned integer that specifies the number of preferred rows for the toolbar when the toolbar is not docked. MUST be less than or equal to 255.
305 sal_uInt16 bFlags
; //Unsigned integer of type TBFlags.
306 WString name
; //Structure of type WString that specifies the toolbar name
309 bool Read(SvStream
&rS
) override
;
310 #ifdef DEBUG_FILTER_MSTOOLBAR
311 virtual void Print( FILE* ) override
;
313 sal_Int16
getcCL() const { return cCL
; }
314 WString
& getName(){ return name
; }
315 bool IsEnabled() const;
316 bool IsMenuToolbar() const { return ( ( ltbtr
& 0x2000000 ) == 0x2000000 ); }
319 class MSFILTER_DLLPUBLIC SRECT final
: public TBBase
322 SRECT() : left(0), top(0), right(0), bottom(0) {}
327 bool Read( SvStream
&rS
) override
{ rS
.ReadInt16( left
).ReadInt16( top
).ReadInt16( right
).ReadInt16( bottom
); return true; }
328 #ifdef DEBUG_FILTER_MSTOOLBAR
329 virtual void Print( FILE* fo
) override
;
334 class MSFILTER_DLLPUBLIC TBVisualData final
: public TBBase
346 bool Read(SvStream
&rS
) override
;
347 #ifdef DEBUG_FILTER_MSTOOLBAR
348 virtual void Print( FILE* ) override
;
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */