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>
50using ::com::sun::star::form::XFormComponent;
51using ::com::sun::star::awt::XControlModel;
52using ::com::sun::star::awt::Size;
53using ::com::sun::star::frame::XModel;
54using ::com::sun::star::io::XOutputStream;
55using ::com::sun::star::io::XInputStream;
56using ::com::sun::star::beans::XPropertySet;
57using ::com::sun::star::uno::Reference;
58using ::com::sun::star::uno::UNO_QUERY;
59using ::com::sun::star::uno::XComponentContext;
60using ::com::sun::star::lang::XServiceInfo;
66const sal_uInt32 OLE_COLORTYPE_MASK = 0xFF000000;
67const sal_uInt32 OLE_COLORTYPE_CLIENT = 0x00000000;
68const sal_uInt32 OLE_COLORTYPE_PALETTE = 0x01000000;
69const sal_uInt32 OLE_COLORTYPE_BGR = 0x02000000;
70const sal_uInt32 OLE_COLORTYPE_SYSCOLOR = 0x80000000;
72const sal_uInt32 OLE_PALETTECOLOR_MASK = 0x0000FFFF;
73const sal_uInt32 OLE_SYSTEMCOLOR_MASK = 0x0000FFFF;
76sal_uInt32 lclSwapRedBlue( sal_uInt32 nColor )
78 return static_cast< sal_uInt32
>( (nColor & 0xFF00FF00) | ((nColor & 0x0000FF) << 16) | ((nColor & 0xFF0000) >> 16) );
82::Color lclDecodeBgrColor( sal_uInt32 nOleColor )
84 return ::Color( ColorTransparency, lclSwapRedBlue( nOleColor ) & 0xFFFFFF );
87const sal_uInt32 OLE_STDPIC_ID = 0x0000746C;
101const sal_Int16 TOGGLEBUTTON = -1;
102const sal_Int16 FORMULAFIELD = -2;
104typedef std::map< sal_Int16, GUIDCNamePair > GUIDCNamePairMap;
105class classIdToGUIDCNamePairMap
108 classIdToGUIDCNamePairMap();
110 static GUIDCNamePairMap&
get();
113classIdToGUIDCNamePairMap::classIdToGUIDCNamePairMap()
115 static IdCntrlData
const initialCntrlData[] =
118 { FormComponentType::COMMANDBUTTON,
125 { FormComponentType::FIXEDTEXT,
128 { FormComponentType::TEXTFIELD,
131 { FormComponentType::LISTBOX,
134 { FormComponentType::COMBOBOX,
137 { FormComponentType::CHECKBOX,
140 { FormComponentType::RADIOBUTTON,
143 { FormComponentType::IMAGECONTROL,
146 { FormComponentType::DATEFIELD,
149 { FormComponentType::TIMEFIELD,
152 { FormComponentType::NUMERICFIELD,
155 { FormComponentType::CURRENCYFIELD,
158 { FormComponentType::PATTERNFIELD,
164 { FormComponentType::IMAGEBUTTON,
167 { FormComponentType::SPINBUTTON,
170 { FormComponentType::SCROLLBAR,
175 IdCntrlData
const *
pData = initialCntrlData;
180GUIDCNamePairMap& classIdToGUIDCNamePairMap::get()
182 static classIdToGUIDCNamePairMap theInst;
183 return theInst.mnIdToGUIDCNamePairMap;
186template<
typename Type >
187void lclAppendHex( OUStringBuffer& orBuffer,
Type nValue )
189 const sal_Int32 nWidth = 2 *
sizeof(
Type );
190 static const sal_Unicode spcHexChars[] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
191 orBuffer.setLength( orBuffer.getLength() + nWidth );
192 for( sal_Int32 nCharIdx = orBuffer.getLength() - 1, nCharEnd = nCharIdx - nWidth; nCharIdx > nCharEnd; --nCharIdx,
nValue >>= 4 )
193 orBuffer[nCharIdx] = spcHexChars[ nValue & 0xF ];
216 const GraphicHelper& rGraphicHelper, sal_uInt32 nOleColor,
bool bDefaultColorBgr )
218 static const sal_Int32 spnSystemColors[] =
220 XML_scrollBar, XML_background, XML_activeCaption, XML_inactiveCaption,
221 XML_menu, XML_window, XML_windowFrame, XML_menuText,
222 XML_windowText, XML_captionText, XML_activeBorder, XML_inactiveBorder,
223 XML_appWorkspace, XML_highlight, XML_highlightText, XML_btnFace,
224 XML_btnShadow, XML_grayText, XML_btnText, XML_inactiveCaptionText,
225 XML_btnHighlight, XML_3dDkShadow, XML_3dLight, XML_infoText,
229 switch( nOleColor & OLE_COLORTYPE_MASK )
231 case OLE_COLORTYPE_CLIENT:
232 return bDefaultColorBgr ? lclDecodeBgrColor( nOleColor ) : rGraphicHelper.
getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
234 case OLE_COLORTYPE_PALETTE:
235 return rGraphicHelper.
getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
237 case OLE_COLORTYPE_BGR:
238 return lclDecodeBgrColor( nOleColor );
240 case OLE_COLORTYPE_SYSCOLOR:
243 OSL_FAIL(
"OleHelper::decodeOleColor - unknown color type" );
249 return OLE_COLORTYPE_BGR | lclSwapRedBlue(
static_cast< sal_uInt32
>( nRgbColor & 0xFFFFFF ) );
276 return aBuffer.makeStringAndClear();
284 OSL_ENSURE( bIsStdFont,
"OleHelper::importStdFont - unexpected header GUID, expected StdFont" );
298 OSL_ENSURE(
nVersion <= 1,
"OleHelper::importStdFont - wrong version" );
305 OSL_ENSURE( bIsStdPic,
"OleHelper::importStdPic - unexpected header GUID, expected StdPic" );
309 sal_uInt32 nStdPicId;
313 OSL_ENSURE( nStdPicId == OLE_STDPIC_ID,
"OleHelper::importStdPic - unexpected header version" );
314 return !rInStrm.
isEof() && (nStdPicId == OLE_STDPIC_ID) && (nBytes > 0) && (rInStrm.
readData( orGraphicData, nBytes ) == nBytes);
317static Reference< css::frame::XFrame >
lcl_getFrame(
const Reference< css::frame::XModel >& rxModel )
319 Reference< css::frame::XFrame >
xFrame;
322 Reference< css::frame::XController >
xController = rxModel->getCurrentController();
331 Reference< css::beans::XPropertySet > xProps( xCntrlModel, UNO_QUERY );
335 sal_Int16 nClassId = 0;
337 if ( !aPropSet.
getProperty( nClassId, PROP_ClassId ) )
348 if ( nClassId == FormComponentType::TEXTFIELD)
350 Reference< XServiceInfo > xInfo( xCntrlModel,
354 nClassId = FORMULAFIELD;
356 else if ( nClassId == FormComponentType::COMMANDBUTTON )
358 bool bToggle =
false;
359 if ( aPropSet.
getProperty( bToggle, PROP_Toggle ) && bToggle )
360 nClassId = TOGGLEBUTTON;
362 else if ( nClassId == FormComponentType::CONTROL )
364 Reference< XServiceInfo > xInfo( xCntrlModel,
366 if (xInfo->supportsService(
"com.sun.star.form.component.ImageControl" ) )
367 nClassId = FormComponentType::IMAGECONTROL;
370 GUIDCNamePairMap& cntrlMap = classIdToGUIDCNamePairMap::get();
371 GUIDCNamePairMap::iterator it = cntrlMap.find( nClassId );
372 if ( it != cntrlMap.end() )
375 maTypeName = OUString::createFromAscii( it->second.sName );
378 maGUID = OUString::createFromAscii( it->second.sGUID );
429 pModel->importBinaryModel( rInStrm );
430 rxFormComp.set(
mxCtx->getServiceManager()->createInstanceWithContext( pModel->getServiceName(),
mxCtx ), UNO_QUERY );
431 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
433 aControl.convertProperties( xCtlModel, aConv );
435 return rxFormComp.is();
441 sal_Int32 nStreamSize)
454 sal_Int32 nStreamSize)
456 if ( !rInStrm.
isEof() )
459 bool bOneOfHtmlControls =
false;
462 bOneOfHtmlControls =
true;
464 if ( bOneOfHtmlControls )
472 const int nGuidSize = 0x10;
474 sal_Int32 nBytesToRead = nStreamSize - nGuidSize;
475 while ( nBytesToRead )
476 nBytesToRead -= rInStrm.
readData( aDataSeq, nBytesToRead );
485 return rxFormComp.is();
489 Reference< XFormComponent > & rxFormComp )
507 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
508 if ( !
aName.isEmpty() && xCtlModel.is() )
515 return rxFormComp.is();
521bool 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 )
536 const Reference< XControlModel > &rxControlModel,
537 const css::awt::Size& rSize, OUString &rName)
550 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
#define SAL_N_ELEMENTS(arr)
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