22#include <rtl/ustrbuf.hxx>
24#include <osl/diagnose.h>
28#include <oox/token/properties.hxx>
29#include <oox/token/tokens.hxx>
34#include <com/sun/star/awt/XControlModel.hpp>
35#include <com/sun/star/beans/XPropertySet.hpp>
36#include <com/sun/star/form/FormComponentType.hpp>
37#include <com/sun/star/form/XFormComponent.hpp>
38#include <com/sun/star/frame/XFrame.hpp>
39#include <com/sun/star/frame/XModel.hpp>
40#include <com/sun/star/lang/XServiceInfo.hpp>
41#include <com/sun/star/awt/Size.hpp>
42#include <com/sun/star/uno/XComponentContext.hpp>
51using ::com::sun::star::form::XFormComponent;
52using ::com::sun::star::awt::XControlModel;
53using ::com::sun::star::awt::Size;
54using ::com::sun::star::frame::XModel;
55using ::com::sun::star::io::XOutputStream;
56using ::com::sun::star::io::XInputStream;
57using ::com::sun::star::beans::XPropertySet;
58using ::com::sun::star::uno::Reference;
59using ::com::sun::star::uno::UNO_QUERY;
60using ::com::sun::star::uno::XComponentContext;
61using ::com::sun::star::lang::XServiceInfo;
67const sal_uInt32 OLE_COLORTYPE_MASK = 0xFF000000;
68const sal_uInt32 OLE_COLORTYPE_CLIENT = 0x00000000;
69const sal_uInt32 OLE_COLORTYPE_PALETTE = 0x01000000;
70const sal_uInt32 OLE_COLORTYPE_BGR = 0x02000000;
71const sal_uInt32 OLE_COLORTYPE_SYSCOLOR = 0x80000000;
73const sal_uInt32 OLE_PALETTECOLOR_MASK = 0x0000FFFF;
74const sal_uInt32 OLE_SYSTEMCOLOR_MASK = 0x0000FFFF;
77sal_uInt32 lclSwapRedBlue( sal_uInt32 nColor )
79 return static_cast< sal_uInt32
>( (nColor & 0xFF00FF00) | ((nColor & 0x0000FF) << 16) | ((nColor & 0xFF0000) >> 16) );
83::Color lclDecodeBgrColor( sal_uInt32 nOleColor )
85 return ::Color( ColorTransparency, lclSwapRedBlue( nOleColor ) & 0xFFFFFF );
88const sal_uInt32 OLE_STDPIC_ID = 0x0000746C;
102const sal_Int16 TOGGLEBUTTON = -1;
103const sal_Int16 FORMULAFIELD = -2;
105typedef std::map< sal_Int16, GUIDCNamePair > GUIDCNamePairMap;
106class classIdToGUIDCNamePairMap
109 classIdToGUIDCNamePairMap();
111 static GUIDCNamePairMap&
get();
114classIdToGUIDCNamePairMap::classIdToGUIDCNamePairMap()
116 static IdCntrlData
const initialCntrlData[] =
119 { FormComponentType::COMMANDBUTTON,
126 { FormComponentType::FIXEDTEXT,
129 { FormComponentType::TEXTFIELD,
132 { FormComponentType::LISTBOX,
135 { FormComponentType::COMBOBOX,
138 { FormComponentType::CHECKBOX,
141 { FormComponentType::RADIOBUTTON,
144 { FormComponentType::IMAGECONTROL,
147 { FormComponentType::DATEFIELD,
150 { FormComponentType::TIMEFIELD,
153 { FormComponentType::NUMERICFIELD,
156 { FormComponentType::CURRENCYFIELD,
159 { FormComponentType::PATTERNFIELD,
165 { FormComponentType::IMAGEBUTTON,
168 { FormComponentType::SPINBUTTON,
171 { FormComponentType::SCROLLBAR,
175 int const length = std::size( initialCntrlData );
176 IdCntrlData
const *
pData = initialCntrlData;
181GUIDCNamePairMap& classIdToGUIDCNamePairMap::get()
183 static classIdToGUIDCNamePairMap theInst;
184 return theInst.mnIdToGUIDCNamePairMap;
187template<
typename Type >
188void lclAppendHex( OUStringBuffer& orBuffer,
Type nValue )
190 const sal_Int32 nWidth = 2 *
sizeof(
Type );
191 static const sal_Unicode spcHexChars[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
192 orBuffer.setLength( orBuffer.getLength() + nWidth );
193 for( sal_Int32 nCharIdx = orBuffer.getLength() - 1, nCharEnd = nCharIdx - nWidth; nCharIdx > nCharEnd; --nCharIdx,
nValue >>= 4 )
194 orBuffer[nCharIdx] = spcHexChars[ nValue & 0xF ];
217 const GraphicHelper& rGraphicHelper, sal_uInt32 nOleColor,
bool bDefaultColorBgr )
219 static const sal_Int32 spnSystemColors[] =
221 XML_scrollBar, XML_background, XML_activeCaption, XML_inactiveCaption,
222 XML_menu, XML_window, XML_windowFrame, XML_menuText,
223 XML_windowText, XML_captionText, XML_activeBorder, XML_inactiveBorder,
224 XML_appWorkspace, XML_highlight, XML_highlightText, XML_btnFace,
225 XML_btnShadow, XML_grayText, XML_btnText, XML_inactiveCaptionText,
226 XML_btnHighlight, XML_3dDkShadow, XML_3dLight, XML_infoText,
230 switch( nOleColor & OLE_COLORTYPE_MASK )
232 case OLE_COLORTYPE_CLIENT:
233 return bDefaultColorBgr ? lclDecodeBgrColor( nOleColor ) : rGraphicHelper.
getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
235 case OLE_COLORTYPE_PALETTE:
236 return rGraphicHelper.
getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
238 case OLE_COLORTYPE_BGR:
239 return lclDecodeBgrColor( nOleColor );
241 case OLE_COLORTYPE_SYSCOLOR:
244 OSL_FAIL(
"OleHelper::decodeOleColor - unknown color type" );
250 return OLE_COLORTYPE_BGR | lclSwapRedBlue(
static_cast< sal_uInt32
>( nRgbColor & 0xFFFFFF ) );
277 return aBuffer.makeStringAndClear();
285 OSL_ENSURE( bIsStdFont,
"OleHelper::importStdFont - unexpected header GUID, expected StdFont" );
299 OSL_ENSURE(
nVersion <= 1,
"OleHelper::importStdFont - wrong version" );
306 OSL_ENSURE( bIsStdPic,
"OleHelper::importStdPic - unexpected header GUID, expected StdPic" );
310 sal_uInt32 nStdPicId;
314 OSL_ENSURE( nStdPicId == OLE_STDPIC_ID,
"OleHelper::importStdPic - unexpected header version" );
315 return !rInStrm.
isEof() && (nStdPicId == OLE_STDPIC_ID) && (nBytes > 0) && (rInStrm.
readData( orGraphicData, nBytes ) == nBytes);
318static Reference< css::frame::XFrame >
lcl_getFrame(
const Reference< css::frame::XModel >& rxModel )
320 Reference< css::frame::XFrame >
xFrame;
323 Reference< css::frame::XController >
xController = rxModel->getCurrentController();
332 Reference< css::beans::XPropertySet > xProps( xCntrlModel, UNO_QUERY );
336 sal_Int16 nClassId = 0;
338 if ( !aPropSet.
getProperty( nClassId, PROP_ClassId ) )
349 if ( nClassId == FormComponentType::TEXTFIELD)
351 Reference< XServiceInfo > xInfo( xCntrlModel,
355 nClassId = FORMULAFIELD;
357 else if ( nClassId == FormComponentType::COMMANDBUTTON )
359 bool bToggle =
false;
360 if ( aPropSet.
getProperty( bToggle, PROP_Toggle ) && bToggle )
361 nClassId = TOGGLEBUTTON;
363 else if ( nClassId == FormComponentType::CONTROL )
365 Reference< XServiceInfo > xInfo( xCntrlModel,
367 if (xInfo->supportsService(
"com.sun.star.form.component.ImageControl" ) )
368 nClassId = FormComponentType::IMAGECONTROL;
371 GUIDCNamePairMap& cntrlMap = classIdToGUIDCNamePairMap::get();
372 GUIDCNamePairMap::iterator it = cntrlMap.find( nClassId );
373 if ( it != cntrlMap.end() )
376 maTypeName = OUString::createFromAscii( it->second.sName );
379 maGUID = OUString::createFromAscii( it->second.sGUID );
430 pModel->importBinaryModel( rInStrm );
431 rxFormComp.set(
mxCtx->getServiceManager()->createInstanceWithContext( pModel->getServiceName(),
mxCtx ), UNO_QUERY );
432 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
434 aControl.convertProperties( xCtlModel, aConv );
436 return rxFormComp.is();
442 sal_Int32 nStreamSize)
455 sal_Int32 nStreamSize)
457 if ( !rInStrm.
isEof() )
460 bool bOneOfHtmlControls =
false;
463 bOneOfHtmlControls =
true;
465 if ( bOneOfHtmlControls )
473 const int nGuidSize = 0x10;
475 sal_Int32 nBytesToRead = nStreamSize - nGuidSize;
476 while ( nBytesToRead )
477 nBytesToRead -= rInStrm.
readData( aDataSeq, nBytesToRead );
486 return rxFormComp.is();
490 Reference< XFormComponent > & rxFormComp )
508 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
509 if ( !
aName.isEmpty() && xCtlModel.is() )
516 return rxFormComp.is();
522bool MSConvertOCXControls::WriteOCXExcelKludgeStream(
const css::uno::Reference< css::frame::XModel >& rxModel,
const css::uno::Reference< css::io::XOutputStream >& xOutStrm,
const css::uno::Reference< css::awt::XControlModel > &rxControlModel,
const css::awt::Size& rSize,OUString &rName )
537 const Reference< XControlModel > &rxControlModel,
538 const css::awt::Size& rSize, OUString &rName)
551 xOleStg->SetClass(
aName, SotClipboardFormatId::EMBEDDED_OBJ_OLE, sFullName);
#define AX_GUID_SPINBUTTON
#define AX_GUID_SCROLLBAR
#define HTML_GUID_TEXTBOX
#define AX_GUID_COMMANDBUTTON
#define AX_GUID_TOGGLEBUTTON
#define AX_GUID_OPTIONBUTTON
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const SvGUID & GetCLSID() const
css::uno::Reference< css::frame::XModel > mxModel
Interface for binary output stream classes.
BinaryOutputStream & WriteUInt32(sal_uInt32 x)
BinaryOutputStream & WriteInt32(sal_Int32 x)
BinaryOutputStream & WriteUInt16(sal_uInt16 x)
void writeArray(Type *opnArray, sal_Int32 nElemCount)
void writeUnicodeArray(const OUString &rString)
bool isEof() const
Returns true, if the stream position is invalid (EOF).
Wraps a UNO output stream and provides convenient access functions.
virtual sal_Int64 size() const override
Returns the size of the stream, if wrapped stream is seekable, otherwise -1.
virtual void seek(sal_Int64 nPos) override
Seeks the stream to the passed position, if wrapped stream is seekable.
Provides helper functions for colors, device measurement conversion, graphics, and graphic objects ha...
virtual ::Color getPaletteColor(sal_Int32 nPaletteIdx) const
Derived classes may implement to resolve a palette index to an RGB color.
::Color getSystemColor(sal_Int32 nToken, ::Color nDefaultRgb=API_RGB_TRANSPARENT) const
Returns a system color specified by the passed XML token identifier.
A helper that maps property identifiers to property values.
bool setProperty(sal_Int32 nPropId, Type &&rValue)
Sets the specified property to the passed value.
A wrapper for a UNO property set.
void setProperties(const css::uno::Sequence< OUString > &rPropNames, const css::uno::Sequence< css::uno::Any > &rValues)
Puts the passed properties into the property set.
bool getProperty(Type &orValue, sal_Int32 nPropId) const
Gets the specified property from the property set.
A base class with useful helper functions for something that is able to convert ActiveX and ComCtl fo...
Base class for all models of form controls.
virtual void exportCompObj(BinaryOutputStream &)
Derived classes export CompObjStream contents.
AxPairData maSize
Size of the control in 1/100 mm.
virtual void exportBinaryModel(BinaryOutputStream &)
Derived classes export a form control model to the passed output stream.
A form control embedded in a document draw page.
static bool WriteOCXStream(const css::uno::Reference< css::frame::XModel > &rxModel, tools::SvRef< SotStorage > const &rSrc1, const css::uno::Reference< css::awt::XControlModel > &rControlModel, const css::awt::Size &rSize, OUString &rName)
bool ReadOCXStorage(tools::SvRef< SotStorage > const &rSrc1, css::uno::Reference< css::form::XFormComponent > &rxFormComp)
css::uno::Reference< css::uno::XComponentContext > mxCtx
bool importControlFromStream(::oox::BinaryInputStream &rInStrm, css::uno::Reference< css::form::XFormComponent > &rxFormComp, std::u16string_view rGuidString)
MSConvertOCXControls(const css::uno::Reference< css::frame::XModel > &rxModel)
bool ReadOCXCtlsStream(tools::SvRef< SotStorageStream > const &rSrc1, css::uno::Reference< css::form::XFormComponent > &rxFormComp, sal_Int32 nPos, sal_Int32 nSize)
::oox::GraphicHelper maGrfHelper
static bool WriteOCXExcelKludgeStream(const css::uno::Reference< css::frame::XModel > &rxModel, const css::uno::Reference< css::io::XOutputStream > &xOutStrm, const css::uno::Reference< css::awt::XControlModel > &rControlModel, const css::awt::Size &rSize, OUString &rName)
virtual ~MSConvertOCXControls() override
#define STATIC_ARRAY_SELECT(array, index, def)
Expands to the 'index'-th element of a STATIC data array, or to 'def', if 'index' is out of the array...
Reference< XComponentContext > mxCtx
std::unique_ptr< sal_Int32[]> pData
Reference< XComponentContext > getProcessComponentContext()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OOX_DLLPUBLIC OUString importGuid(BinaryInputStream &rInStrm)
Imports a GUID from the passed binary stream and returns its string representation (in uppercase char...
OOX_DLLPUBLIC::Color decodeOleColor(const GraphicHelper &rGraphicHelper, sal_uInt32 nOleColor, bool bDefaultColorBgr)
Returns the UNO RGB color from the passed encoded OLE color.
OOX_DLLPUBLIC void exportGuid(BinaryOutputStream &rOutStrm, const SvGlobalName &rId)
OOX_DLLPUBLIC bool importStdPic(StreamDataSequence &orGraphicData, BinaryInputStream &rInStrm)
Imports an OLE StdPic picture from the current position of the passed binary stream.
OOX_DLLPUBLIC bool importStdFont(StdFontInfo &orFontInfo, BinaryInputStream &rInStrm, bool bWithGuid)
Imports an OLE StdFont font structure from the current position of the passed binary stream.
OOX_DLLPUBLIC sal_uInt32 encodeOleColor(sal_Int32 nRgbColor)
Returns the OLE color from the passed UNO RGB color.
static Reference< css::frame::XFrame > lcl_getFrame(const Reference< css::frame::XModel > &rxModel)
const sal_uInt16 OLE_STDFONT_NORMAL
const sal_uInt8 WINDOWS_CHARSET_ANSI
const ::Color API_RGB_WHITE(0xFFFFFF)
White color for API calls.
std::shared_ptr< StorageBase > StorageRef
css::uno::Sequence< sal_Int8 > StreamDataSequence
const ::Color API_RGB_BLACK(0x000000)
Black color for API calls.
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
GUIDCNamePairMap mnIdToGUIDCNamePairMap
Stores data about a StdFont font structure.
sal_uInt8 mnFlags
Font flags.
sal_uInt32 mnHeight
Font height (1/10,000 points).
sal_uInt16 mnCharSet
Font charset.
sal_uInt16 mnWeight
Font weight (normal/bold).
OUString maName
Font name.
Reference< XController > xController
Reference< XFrame > xFrame
std::unique_ptr< char[]> aBuffer