bump product version to 5.0.4.1
[LibreOffice.git] / oox / source / ole / olehelper.cxx
blobfa54529b533459c5586e8c90897a6e2de9b57231
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/ole/olehelper.hxx"
22 #include <rtl/ustrbuf.hxx>
23 #include <sot/storage.hxx>
24 #include <osl/diagnose.h>
25 #include "oox/helper/binaryinputstream.hxx"
26 #include "oox/helper/graphichelper.hxx"
27 #include "oox/token/tokens.hxx"
28 #include "oox/ole/axcontrol.hxx"
29 #include "oox/helper/propertymap.hxx"
30 #include "oox/helper/propertyset.hxx"
31 #include "oox/ole/olestorage.hxx"
33 #include <com/sun/star/beans/XPropertySet.hpp>
34 #include <com/sun/star/form/FormComponentType.hpp>
35 #include <com/sun/star/form/XFormsSupplier.hpp>
36 #include <com/sun/star/form/XForm.hpp>
37 #include <com/sun/star/lang/XServiceInfo.hpp>
38 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/awt/Size.hpp>
42 #include <tools/globname.hxx>
43 #include <unotools/streamwrap.hxx>
44 #include <comphelper/processfactory.hxx>
46 namespace oox {
47 namespace ole {
49 using ::com::sun::star::form::XFormComponent;
50 using ::com::sun::star::form::XForm;
51 using ::com::sun::star::awt::XControlModel;
52 using ::com::sun::star::awt::Size;
53 using ::com::sun::star::frame::XModel;
54 using ::com::sun::star::form::XFormsSupplier;
55 using ::com::sun::star::drawing::XDrawPage;
56 using ::com::sun::star::drawing::XDrawPageSupplier;
57 using ::com::sun::star::drawing::XShapes;
58 using ::com::sun::star::io::XOutputStream;
59 using ::com::sun::star::io::XInputStream;
60 using ::com::sun::star::beans::XPropertySet;
61 using ::com::sun::star::uno::Reference;
62 using ::com::sun::star::uno::XInterface;
63 using ::com::sun::star::uno::UNO_QUERY;
64 using ::com::sun::star::uno::Any;
65 using ::com::sun::star::uno::XComponentContext;
66 using ::com::sun::star::container::XIndexContainer;
67 using ::com::sun::star::container::XNameContainer;
68 using ::com::sun::star::lang::XMultiServiceFactory;
69 using ::com::sun::star::lang::XServiceInfo;
71 using namespace ::com::sun::star::form;
73 namespace {
75 const sal_uInt32 OLE_COLORTYPE_MASK = 0xFF000000;
76 const sal_uInt32 OLE_COLORTYPE_CLIENT = 0x00000000;
77 const sal_uInt32 OLE_COLORTYPE_PALETTE = 0x01000000;
78 const sal_uInt32 OLE_COLORTYPE_BGR = 0x02000000;
79 const sal_uInt32 OLE_COLORTYPE_SYSCOLOR = 0x80000000;
81 const sal_uInt32 OLE_PALETTECOLOR_MASK = 0x0000FFFF;
82 const sal_uInt32 OLE_SYSTEMCOLOR_MASK = 0x0000FFFF;
84 /** Swaps the red and blue component of the passed color. */
85 inline sal_uInt32 lclSwapRedBlue( sal_uInt32 nColor )
87 return static_cast< sal_uInt32 >( (nColor & 0xFF00FF00) | ((nColor & 0x0000FF) << 16) | ((nColor & 0xFF0000) >> 16) );
90 /** Returns the UNO RGB color from the passed encoded OLE BGR color. */
91 inline sal_Int32 lclDecodeBgrColor( sal_uInt32 nOleColor )
93 return static_cast< sal_Int32 >( lclSwapRedBlue( nOleColor ) & 0xFFFFFF );
96 const sal_uInt32 OLE_STDPIC_ID = 0x0000746C;
98 struct GUIDCNamePair
100 const char* sGUID;
101 const char* sName;
104 struct IdCntrlData
106 sal_Int16 nId;
107 GUIDCNamePair aData;
110 const sal_Int16 TOGGLEBUTTON = -1;
111 const sal_Int16 FORMULAFIELD = -2;
113 typedef std::map< sal_Int16, GUIDCNamePair > GUIDCNamePairMap;
114 class classIdToGUIDCNamePairMap
116 GUIDCNamePairMap mnIdToGUIDCNamePairMap;
117 classIdToGUIDCNamePairMap();
118 public:
119 static GUIDCNamePairMap& get();
122 classIdToGUIDCNamePairMap::classIdToGUIDCNamePairMap()
124 IdCntrlData initialCntrlData[] =
126 // Command button MUST be at index 0
127 { FormComponentType::COMMANDBUTTON,
128 { AX_GUID_COMMANDBUTTON, "CommandButton"} ,
130 // Toggle button MUST be at index 1
131 { TOGGLEBUTTON,
132 { AX_GUID_TOGGLEBUTTON, "ToggleButton"},
134 { FormComponentType::FIXEDTEXT,
135 { AX_GUID_LABEL, "Label"},
137 { FormComponentType::TEXTFIELD,
138 { AX_GUID_TEXTBOX, "TextBox"},
140 { FormComponentType::LISTBOX,
141 { AX_GUID_LISTBOX, "ListBox"},
143 { FormComponentType::COMBOBOX,
144 { AX_GUID_COMBOBOX, "ComboBox"},
146 { FormComponentType::CHECKBOX,
147 { AX_GUID_CHECKBOX, "CheckBox"},
149 { FormComponentType::RADIOBUTTON,
150 { AX_GUID_OPTIONBUTTON, "OptionButton"},
152 { FormComponentType::IMAGECONTROL,
153 { AX_GUID_IMAGE, "Image"},
155 { FormComponentType::DATEFIELD,
156 { AX_GUID_TEXTBOX, "TextBox"},
158 { FormComponentType::TIMEFIELD,
159 { AX_GUID_TEXTBOX, "TextBox"},
161 { FormComponentType::NUMERICFIELD,
162 { AX_GUID_TEXTBOX, "TextBox"},
164 { FormComponentType::CURRENCYFIELD,
165 { AX_GUID_TEXTBOX, "TextBox"},
167 { FormComponentType::PATTERNFIELD,
168 { AX_GUID_TEXTBOX, "TextBox"},
170 { FORMULAFIELD,
171 { AX_GUID_TEXTBOX, "TextBox"},
173 { FormComponentType::IMAGEBUTTON,
174 { AX_GUID_COMMANDBUTTON, "CommandButton"},
176 { FormComponentType::SPINBUTTON,
177 { AX_GUID_SPINBUTTON, "SpinButton"},
179 { FormComponentType::SCROLLBAR,
180 { AX_GUID_SCROLLBAR, "ScrollBar"},
183 int length = SAL_N_ELEMENTS( initialCntrlData );
184 IdCntrlData* pData = initialCntrlData;
185 for ( int index = 0; index < length; ++index, ++pData )
186 mnIdToGUIDCNamePairMap[ pData->nId ] = pData->aData;
189 GUIDCNamePairMap& classIdToGUIDCNamePairMap::get()
191 static classIdToGUIDCNamePairMap theInst;
192 return theInst.mnIdToGUIDCNamePairMap;
195 template< typename Type >
196 void lclAppendHex( OUStringBuffer& orBuffer, Type nValue )
198 const sal_Int32 nWidth = 2 * sizeof( Type );
199 static const sal_Unicode spcHexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
200 orBuffer.setLength( orBuffer.getLength() + nWidth );
201 for( sal_Int32 nCharIdx = orBuffer.getLength() - 1, nCharEnd = nCharIdx - nWidth; nCharIdx > nCharEnd; --nCharIdx, nValue >>= 4 )
202 orBuffer[nCharIdx] = spcHexChars[ nValue & 0xF ];
205 } // namespace
207 StdFontInfo::StdFontInfo() :
208 mnHeight( 0 ),
209 mnWeight( OLE_STDFONT_NORMAL ),
210 mnCharSet( WINDOWS_CHARSET_ANSI ),
211 mnFlags( 0 )
215 StdFontInfo::StdFontInfo( const OUString& rName, sal_uInt32 nHeight,
216 sal_uInt16 nWeight, sal_uInt16 nCharSet, sal_uInt8 nFlags ) :
217 maName( rName ),
218 mnHeight( nHeight ),
219 mnWeight( nWeight ),
220 mnCharSet( nCharSet ),
221 mnFlags( nFlags )
225 sal_Int32 OleHelper::decodeOleColor(
226 const GraphicHelper& rGraphicHelper, sal_uInt32 nOleColor, bool bDefaultColorBgr )
228 static const sal_Int32 spnSystemColors[] =
230 XML_scrollBar, XML_background, XML_activeCaption, XML_inactiveCaption,
231 XML_menu, XML_window, XML_windowFrame, XML_menuText,
232 XML_windowText, XML_captionText, XML_activeBorder, XML_inactiveBorder,
233 XML_appWorkspace, XML_highlight, XML_highlightText, XML_btnFace,
234 XML_btnShadow, XML_grayText, XML_btnText, XML_inactiveCaptionText,
235 XML_btnHighlight, XML_3dDkShadow, XML_3dLight, XML_infoText,
236 XML_infoBk
239 switch( nOleColor & OLE_COLORTYPE_MASK )
241 case OLE_COLORTYPE_CLIENT:
242 return bDefaultColorBgr ? lclDecodeBgrColor( nOleColor ) : rGraphicHelper.getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
244 case OLE_COLORTYPE_PALETTE:
245 return rGraphicHelper.getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
247 case OLE_COLORTYPE_BGR:
248 return lclDecodeBgrColor( nOleColor );
250 case OLE_COLORTYPE_SYSCOLOR:
251 return rGraphicHelper.getSystemColor( STATIC_ARRAY_SELECT( spnSystemColors, nOleColor & OLE_SYSTEMCOLOR_MASK, XML_TOKEN_INVALID ), API_RGB_WHITE );
253 OSL_FAIL( "OleHelper::decodeOleColor - unknown color type" );
254 return API_RGB_BLACK;
257 sal_uInt32 OleHelper::encodeOleColor( sal_Int32 nRgbColor )
259 return OLE_COLORTYPE_BGR | lclSwapRedBlue( static_cast< sal_uInt32 >( nRgbColor & 0xFFFFFF ) );
262 void OleHelper::exportGuid( BinaryOutputStream& rOStr, const SvGlobalName& rId )
264 rOStr.WriteUInt32( rId.GetCLSID().Data1 );
265 rOStr.WriteUInt16( rId.GetCLSID().Data2 );
266 rOStr.WriteUInt16( rId.GetCLSID().Data3 );
267 rOStr.writeArray( rId.GetCLSID().Data4, 8 );
270 OUString OleHelper::importGuid( BinaryInputStream& rInStrm )
272 OUStringBuffer aBuffer;
273 aBuffer.append( '{' );
274 lclAppendHex( aBuffer, rInStrm.readuInt32() );
275 aBuffer.append( '-' );
276 lclAppendHex( aBuffer, rInStrm.readuInt16() );
277 aBuffer.append( '-' );
278 lclAppendHex( aBuffer, rInStrm.readuInt16() );
279 aBuffer.append( '-' );
280 lclAppendHex( aBuffer, rInStrm.readuInt8() );
281 lclAppendHex( aBuffer, rInStrm.readuInt8() );
282 aBuffer.append( '-' );
283 for( int nIndex = 0; nIndex < 6; ++nIndex )
284 lclAppendHex( aBuffer, rInStrm.readuInt8() );
285 aBuffer.append( '}' );
286 return aBuffer.makeStringAndClear();
289 bool OleHelper::importStdFont( StdFontInfo& orFontInfo, BinaryInputStream& rInStrm, bool bWithGuid )
291 if( bWithGuid )
293 bool bIsStdFont = importGuid( rInStrm ) == OLE_GUID_STDFONT;
294 OSL_ENSURE( bIsStdFont, "OleHelper::importStdFont - unexpected header GUID, expected StdFont" );
295 if( !bIsStdFont )
296 return false;
299 sal_uInt8 nVersion, nNameLen;
300 nVersion = rInStrm.readuChar();
301 orFontInfo.mnCharSet = rInStrm.readuInt16();
302 orFontInfo.mnFlags = rInStrm.readuChar();
303 orFontInfo.mnWeight = rInStrm.readuInt16();
304 orFontInfo.mnHeight = rInStrm.readuInt32();
305 nNameLen = rInStrm.readuChar();
306 // according to spec the name is ASCII
307 orFontInfo.maName = rInStrm.readCharArrayUC( nNameLen, RTL_TEXTENCODING_ASCII_US );
308 OSL_ENSURE( nVersion <= 1, "OleHelper::importStdFont - wrong version" );
309 return !rInStrm.isEof() && (nVersion <= 1);
312 bool OleHelper::importStdPic( StreamDataSequence& orGraphicData, BinaryInputStream& rInStrm, bool bWithGuid )
314 if( bWithGuid )
316 bool bIsStdPic = importGuid( rInStrm ) == OLE_GUID_STDPIC;
317 OSL_ENSURE( bIsStdPic, "OleHelper::importStdPic - unexpected header GUID, expected StdPic" );
318 if( !bIsStdPic )
319 return false;
322 sal_uInt32 nStdPicId;
323 sal_Int32 nBytes;
324 nStdPicId = rInStrm.readuInt32();
325 nBytes = rInStrm.readInt32();
326 OSL_ENSURE( nStdPicId == OLE_STDPIC_ID, "OleHelper::importStdPic - unexpected header version" );
327 return !rInStrm.isEof() && (nStdPicId == OLE_STDPIC_ID) && (nBytes > 0) && (rInStrm.readData( orGraphicData, nBytes ) == nBytes);
330 Reference< ::com::sun::star::frame::XFrame >
331 lcl_getFrame( const Reference< ::com::sun::star::frame::XModel >& rxModel )
333 Reference< ::com::sun::star::frame::XFrame > xFrame;
334 if ( rxModel.is() )
336 Reference< ::com::sun::star::frame::XController > xController = rxModel->getCurrentController();
337 xFrame = xController.is() ? xController->getFrame() : NULL;
339 return xFrame;
342 class OleFormCtrlExportHelper
344 ::oox::ole::EmbeddedControl maControl;
345 ::oox::ole::ControlModelBase* mpModel;
346 ::oox::GraphicHelper maGrfHelper;
347 Reference< XModel > mxDocModel;
348 Reference< XControlModel > mxControlModel;
350 OUString maName;
351 OUString maTypeName;
352 OUString maFullName;
353 OUString maGUID;
354 public:
355 OleFormCtrlExportHelper( const Reference< XComponentContext >& rxCtx, const Reference< XModel >& xDocModel, const Reference< XControlModel >& xModel );
356 virtual ~OleFormCtrlExportHelper() { }
357 OUString getGUID()
359 OUString sResult;
360 if ( maGUID.getLength() > 2 )
361 sResult = maGUID.copy(1, maGUID.getLength() - 2 );
362 return sResult;
364 OUString getFullName() { return maFullName; }
365 OUString getTypeName() { return maTypeName; }
366 bool isValid() { return mpModel != NULL; }
367 void exportName( const Reference< XOutputStream >& rxOut );
368 void exportCompObj( const Reference< XOutputStream >& rxOut );
369 void exportControl( const Reference< XOutputStream >& rxOut, const ::com::sun::star::awt::Size& rSize );
371 OleFormCtrlExportHelper::OleFormCtrlExportHelper( const Reference< XComponentContext >& rxCtx, const Reference< XModel >& rxDocModel, const Reference< XControlModel >& xCntrlModel ) : maControl( "Unknown" ), mpModel( NULL ), maGrfHelper( rxCtx, lcl_getFrame( rxDocModel ), StorageRef() ), mxDocModel( rxDocModel ), mxControlModel( xCntrlModel )
373 // try to get the guid
374 Reference< com::sun::star::beans::XPropertySet > xProps( xCntrlModel, UNO_QUERY );
375 if ( xProps.is() )
377 sal_Int16 nClassId = 0;
378 PropertySet aPropSet( mxControlModel );
379 if ( aPropSet.getProperty( nClassId, PROP_ClassId ) )
381 /* pseudo ripped from legacy msocximex:
382 "There is a truly horrible thing with EditControls and FormattedField
383 Controls, they both pretend to have an EDITBOX ClassId for compatibility
384 reasons, at some stage in the future hopefully there will be a proper
385 FormulaField ClassId rather than this piggybacking two controls onto the
386 same ClassId, cmc." - when fixed the fake FORMULAFIELD id entry
387 and definition above can be removed/replaced
389 if ( nClassId == FormComponentType::TEXTFIELD)
391 Reference< XServiceInfo > xInfo( xCntrlModel,
392 UNO_QUERY);
393 if (xInfo->
394 supportsService( "com.sun.star.form.component.FormattedField" ) )
395 nClassId = FORMULAFIELD;
397 else if ( nClassId == FormComponentType::COMMANDBUTTON )
399 bool bToggle = false;
400 if ( aPropSet.getProperty( bToggle, PROP_Toggle ) && bToggle )
401 nClassId = TOGGLEBUTTON;
403 else if ( nClassId == FormComponentType::CONTROL )
405 Reference< XServiceInfo > xInfo( xCntrlModel,
406 UNO_QUERY);
407 if (xInfo->supportsService("com.sun.star.form.component.ImageControl" ) )
408 nClassId = FormComponentType::IMAGECONTROL;
411 GUIDCNamePairMap& cntrlMap = classIdToGUIDCNamePairMap::get();
412 GUIDCNamePairMap::iterator it = cntrlMap.find( nClassId );
413 if ( it != cntrlMap.end() )
415 aPropSet.getProperty(maName, PROP_Name );
416 maTypeName = OUString::createFromAscii( it->second.sName );
417 maFullName = "Microsoft Forms 2.0 " + maTypeName;
418 maControl = EmbeddedControl( maName );
419 maGUID = OUString::createFromAscii( it->second.sGUID );
420 mpModel = maControl.createModelFromGuid( maGUID );
426 void OleFormCtrlExportHelper::exportName( const Reference< XOutputStream >& rxOut )
428 oox::BinaryXOutputStream aOut( rxOut, false );
429 aOut.writeUnicodeArray( maName );
430 aOut.WriteInt32(0);
433 void OleFormCtrlExportHelper::exportCompObj( const Reference< XOutputStream >& rxOut )
435 oox::BinaryXOutputStream aOut( rxOut, false );
436 if ( mpModel )
437 mpModel->exportCompObj( aOut );
440 void OleFormCtrlExportHelper::exportControl( const Reference< XOutputStream >& rxOut, const Size& rSize )
442 oox::BinaryXOutputStream aOut( rxOut, false );
443 if ( mpModel )
445 ::oox::ole::ControlConverter aConv( mxDocModel, maGrfHelper );
446 maControl.convertFromProperties( mxControlModel, aConv );
447 mpModel->maSize.first = rSize.Width;
448 mpModel->maSize.second = rSize.Height;
449 mpModel->exportBinaryModel( aOut );
453 MSConvertOCXControls::MSConvertOCXControls( const Reference< ::com::sun::star::frame::XModel >& rxModel ) : SvxMSConvertOCXControls( rxModel ), mxCtx( comphelper::getProcessComponentContext() ), maGrfHelper( mxCtx, lcl_getFrame( rxModel ), StorageRef() )
457 MSConvertOCXControls::~MSConvertOCXControls()
461 bool
462 MSConvertOCXControls::importControlFromStream( ::oox::BinaryInputStream& rInStrm, Reference< XFormComponent >& rxFormComp, const OUString& rGuidString )
464 ::oox::ole::EmbeddedControl aControl( "Unknown" );
465 if( ::oox::ole::ControlModelBase* pModel = aControl.createModelFromGuid( rGuidString ) )
467 pModel->importBinaryModel( rInStrm );
468 rxFormComp.set( mxCtx->getServiceManager()->createInstanceWithContext( pModel->getServiceName(), mxCtx ), UNO_QUERY );
469 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
470 ::oox::ole::ControlConverter aConv( mxModel, maGrfHelper );
471 aControl.convertProperties( xCtlModel, aConv );
473 return rxFormComp.is();
476 bool
477 MSConvertOCXControls::ReadOCXCtlsStream( tools::SvRef<SotStorageStream>& rSrc1, Reference< XFormComponent > & rxFormComp,
478 sal_Int32 nPos,
479 sal_Int32 nStreamSize)
481 if ( rSrc1.Is() )
483 BinaryXInputStream aCtlsStrm( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper( *rSrc1 ) ), true );
484 aCtlsStrm.seek( nPos );
485 OUString aStrmClassId = ::oox::ole::OleHelper::importGuid( aCtlsStrm );
486 return importControlFromStream( aCtlsStrm, rxFormComp, aStrmClassId, nStreamSize );
488 return false;
491 bool MSConvertOCXControls::importControlFromStream( ::oox::BinaryInputStream& rInStrm, Reference< XFormComponent >& rxFormComp, const OUString& rStrmClassId,
492 sal_Int32 nStreamSize)
494 if ( !rInStrm.isEof() )
496 // Special processing for those html controls
497 bool bOneOfHtmlControls = false;
498 if ( rStrmClassId.toAsciiUpperCase() == HTML_GUID_SELECT
499 || rStrmClassId.toAsciiUpperCase() == HTML_GUID_TEXTBOX )
500 bOneOfHtmlControls = true;
502 if ( bOneOfHtmlControls )
504 // html controls don't seem have a handy record length following the GUID
505 // in the binary stream.
506 // Given the control stream length create a stream of nStreamSize bytes starting from
507 // nPos ( offset by the guid already read in )
508 if ( !nStreamSize )
509 return false;
510 const int nGuidSize = 0x10;
511 StreamDataSequence aDataSeq;
512 sal_Int32 nBytesToRead = nStreamSize - nGuidSize;
513 while ( nBytesToRead )
514 nBytesToRead -= rInStrm.readData( aDataSeq, nBytesToRead );
515 SequenceInputStream aInSeqStream( aDataSeq );
516 importControlFromStream( aInSeqStream, rxFormComp, rStrmClassId );
518 else
520 importControlFromStream( rInStrm, rxFormComp, rStrmClassId );
523 return rxFormComp.is();
526 bool MSConvertOCXControls::ReadOCXStorage( tools::SvRef<SotStorage>& xOleStg,
527 Reference< XFormComponent > & rxFormComp )
529 if ( xOleStg.Is() )
531 tools::SvRef<SotStorageStream> pNameStream = xOleStg->OpenSotStream( OUString("\3OCXNAME"));
532 BinaryXInputStream aNameStream( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper( *pNameStream ) ), true );
534 tools::SvRef<SotStorageStream> pContents = xOleStg->OpenSotStream( OUString("contents"));
535 BinaryXInputStream aInStrm( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper( *pContents ) ), true );
537 tools::SvRef<SotStorageStream> pClsStrm = xOleStg->OpenSotStream(OUString("\1CompObj"));
538 BinaryXInputStream aClsStrm( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper(*pClsStrm ) ), true );
539 aClsStrm.skip(12);
541 OUString aStrmClassId = ::oox::ole::OleHelper::importGuid( aClsStrm );
542 if ( importControlFromStream( aInStrm, rxFormComp, aStrmClassId, aInStrm.size() ) )
544 OUString aName = aNameStream.readNulUnicodeArray();
545 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
546 if ( !aName.isEmpty() && xCtlModel.is() )
548 PropertyMap aPropMap;
549 aPropMap.setProperty( PROP_Name, aName );
550 PropertySet aPropSet( xCtlModel );
551 aPropSet.setProperties( aPropMap );
553 return rxFormComp.is();
556 return false;
559 bool MSConvertOCXControls::WriteOCXExcelKludgeStream( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel >& rxModel, const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& xOutStrm, const com::sun::star::uno::Reference< com::sun::star::awt::XControlModel > &rxControlModel, const com::sun::star::awt::Size& rSize,OUString &rName )
561 OleFormCtrlExportHelper exportHelper( comphelper::getProcessComponentContext(), rxModel, rxControlModel );
562 if ( !exportHelper.isValid() )
563 return false;
564 rName = exportHelper.getTypeName();
565 SvGlobalName aName;
566 OUString sId = exportHelper.getGUID();
567 aName.MakeId(sId);
568 BinaryXOutputStream xOut( xOutStrm, false );
569 OleHelper::exportGuid( xOut, aName );
570 exportHelper.exportControl( xOutStrm, rSize );
571 return true;
574 bool MSConvertOCXControls::WriteOCXStream( const Reference< XModel >& rxModel, tools::SvRef<SotStorage> &xOleStg,
575 const Reference< XControlModel > &rxControlModel,
576 const com::sun::star::awt::Size& rSize, OUString &rName)
578 SvGlobalName aName;
580 OleFormCtrlExportHelper exportHelper( comphelper::getProcessComponentContext(), rxModel, rxControlModel );
582 if ( !exportHelper.isValid() )
583 return false;
585 OUString sId = exportHelper.getGUID();
586 aName.MakeId(sId);
588 OUString sFullName = exportHelper.getFullName();
589 rName = exportHelper.getTypeName();
590 xOleStg->SetClass( aName, SotClipboardFormatId::EMBEDDED_OBJ_OLE, sFullName);
592 tools::SvRef<SotStorageStream> pNameStream = xOleStg->OpenSotStream(OUString("\3OCXNAME"));
593 Reference< XOutputStream > xOut = new utl::OSeekableOutputStreamWrapper( *pNameStream );
594 exportHelper.exportName( xOut );
597 tools::SvRef<SotStorageStream> pObjStream = xOleStg->OpenSotStream(OUString("\1CompObj"));
598 Reference< XOutputStream > xOut = new utl::OSeekableOutputStreamWrapper( *pObjStream );
599 exportHelper.exportCompObj( xOut );
602 tools::SvRef<SotStorageStream> pContents = xOleStg->OpenSotStream(OUString("contents"));
603 Reference< XOutputStream > xOut = new utl::OSeekableOutputStreamWrapper( *pContents );
604 exportHelper.exportControl( xOut, rSize );
606 return true;
609 } // namespace ole
610 } // namespace oox
612 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */