GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / oox / source / ole / olehelper.cxx
blobcf1f3beb8954dfe87355be76dfa69cc12686ff5b
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 "oox/helper/binaryinputstream.hxx"
24 #include "oox/helper/graphichelper.hxx"
25 #include "oox/token/tokens.hxx"
26 #include "oox/ole/axcontrol.hxx"
27 #include "oox/helper/propertymap.hxx"
28 #include "oox/helper/propertyset.hxx"
29 #include "oox/ole/olestorage.hxx"
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/form/FormComponentType.hpp>
33 #include <com/sun/star/form/XFormsSupplier.hpp>
34 #include <com/sun/star/form/XForm.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <com/sun/star/awt/Size.hpp>
40 #include <tools/globname.hxx>
41 #include <unotools/streamwrap.hxx>
42 #include <comphelper/processfactory.hxx>
44 namespace oox {
45 namespace ole {
47 // ============================================================================
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 // ============================================================================
75 namespace {
77 const sal_uInt32 OLE_COLORTYPE_MASK = 0xFF000000;
78 const sal_uInt32 OLE_COLORTYPE_CLIENT = 0x00000000;
79 const sal_uInt32 OLE_COLORTYPE_PALETTE = 0x01000000;
80 const sal_uInt32 OLE_COLORTYPE_BGR = 0x02000000;
81 const sal_uInt32 OLE_COLORTYPE_SYSCOLOR = 0x80000000;
83 const sal_uInt32 OLE_PALETTECOLOR_MASK = 0x0000FFFF;
84 const sal_uInt32 OLE_SYSTEMCOLOR_MASK = 0x0000FFFF;
87 /** Swaps the red and blue component of the passed color. */
88 inline sal_uInt32 lclSwapRedBlue( sal_uInt32 nColor )
90 return static_cast< sal_uInt32 >( (nColor & 0xFF00FF00) | ((nColor & 0x0000FF) << 16) | ((nColor & 0xFF0000) >> 16) );
93 /** Returns the UNO RGB color from the passed encoded OLE BGR color. */
94 inline sal_Int32 lclDecodeBgrColor( sal_uInt32 nOleColor )
96 return static_cast< sal_Int32 >( lclSwapRedBlue( nOleColor ) & 0xFFFFFF );
99 // ----------------------------------------------------------------------------
101 const sal_uInt32 OLE_STDPIC_ID = 0x0000746C;
103 struct GUIDCNamePair
105 const char* sGUID;
106 const char* sName;
109 struct IdCntrlData
111 sal_Int16 nId;
112 GUIDCNamePair aData;
115 const sal_Int16 TOGGLEBUTTON = -1;
116 const sal_Int16 FORMULAFIELD = -2;
118 typedef std::map< sal_Int16, GUIDCNamePair > GUIDCNamePairMap;
119 class classIdToGUIDCNamePairMap
121 GUIDCNamePairMap mnIdToGUIDCNamePairMap;
122 classIdToGUIDCNamePairMap();
123 public:
124 static GUIDCNamePairMap& get();
127 classIdToGUIDCNamePairMap::classIdToGUIDCNamePairMap()
129 IdCntrlData initialCntrlData[] =
131 // Command button MUST be at index 0
132 { FormComponentType::COMMANDBUTTON,
133 { AX_GUID_COMMANDBUTTON, "CommandButton"} ,
135 // Toggle button MUST be at index 1
136 { TOGGLEBUTTON,
137 { AX_GUID_TOGGLEBUTTON, "ToggleButton"},
139 { FormComponentType::FIXEDTEXT,
140 { AX_GUID_LABEL, "Label"},
142 { FormComponentType::TEXTFIELD,
143 { AX_GUID_TEXTBOX, "TextBox"},
145 { FormComponentType::LISTBOX,
146 { AX_GUID_LISTBOX, "ListBox"},
148 { FormComponentType::COMBOBOX,
149 { AX_GUID_COMBOBOX, "ComboBox"},
151 { FormComponentType::CHECKBOX,
152 { AX_GUID_CHECKBOX, "CheckBox"},
154 { FormComponentType::RADIOBUTTON,
155 { AX_GUID_OPTIONBUTTON, "OptionButton"},
157 { FormComponentType::IMAGECONTROL,
158 { AX_GUID_IMAGE, "Image"},
160 { FormComponentType::DATEFIELD,
161 { AX_GUID_TEXTBOX, "TextBox"},
163 { FormComponentType::TIMEFIELD,
164 { AX_GUID_TEXTBOX, "TextBox"},
166 { FormComponentType::NUMERICFIELD,
167 { AX_GUID_TEXTBOX, "TextBox"},
169 { FormComponentType::CURRENCYFIELD,
170 { AX_GUID_TEXTBOX, "TextBox"},
172 { FormComponentType::PATTERNFIELD,
173 { AX_GUID_TEXTBOX, "TextBox"},
175 { FORMULAFIELD,
176 { AX_GUID_TEXTBOX, "TextBox"},
178 { FormComponentType::IMAGEBUTTON,
179 { AX_GUID_COMMANDBUTTON, "CommandButton"},
181 { FormComponentType::SPINBUTTON,
182 { AX_GUID_SPINBUTTON, "SpinButton"},
184 { FormComponentType::SCROLLBAR,
185 { AX_GUID_SCROLLBAR, "ScrollBar"},
188 int length = SAL_N_ELEMENTS( initialCntrlData );
189 IdCntrlData* pData = initialCntrlData;
190 for ( int index = 0; index < length; ++index, ++pData )
191 mnIdToGUIDCNamePairMap[ pData->nId ] = pData->aData;
194 GUIDCNamePairMap& classIdToGUIDCNamePairMap::get()
196 static classIdToGUIDCNamePairMap theInst;
197 return theInst.mnIdToGUIDCNamePairMap;
200 // ----------------------------------------------------------------------------
202 template< typename Type >
203 void lclAppendHex( OUStringBuffer& orBuffer, Type nValue )
205 const sal_Int32 nWidth = 2 * sizeof( Type );
206 static const sal_Unicode spcHexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
207 orBuffer.setLength( orBuffer.getLength() + nWidth );
208 for( sal_Int32 nCharIdx = orBuffer.getLength() - 1, nCharEnd = nCharIdx - nWidth; nCharIdx > nCharEnd; --nCharIdx, nValue >>= 4 )
209 orBuffer[nCharIdx] = spcHexChars[ nValue & 0xF ];
212 } // namespace
214 // ============================================================================
216 StdFontInfo::StdFontInfo() :
217 mnHeight( 0 ),
218 mnWeight( OLE_STDFONT_NORMAL ),
219 mnCharSet( WINDOWS_CHARSET_ANSI ),
220 mnFlags( 0 )
224 StdFontInfo::StdFontInfo( const OUString& rName, sal_uInt32 nHeight,
225 sal_uInt16 nWeight, sal_uInt16 nCharSet, sal_uInt8 nFlags ) :
226 maName( rName ),
227 mnHeight( nHeight ),
228 mnWeight( nWeight ),
229 mnCharSet( nCharSet ),
230 mnFlags( nFlags )
234 // ============================================================================
236 sal_Int32 OleHelper::decodeOleColor(
237 const GraphicHelper& rGraphicHelper, sal_uInt32 nOleColor, bool bDefaultColorBgr )
239 static const sal_Int32 spnSystemColors[] =
241 XML_scrollBar, XML_background, XML_activeCaption, XML_inactiveCaption,
242 XML_menu, XML_window, XML_windowFrame, XML_menuText,
243 XML_windowText, XML_captionText, XML_activeBorder, XML_inactiveBorder,
244 XML_appWorkspace, XML_highlight, XML_highlightText, XML_btnFace,
245 XML_btnShadow, XML_grayText, XML_btnText, XML_inactiveCaptionText,
246 XML_btnHighlight, XML_3dDkShadow, XML_3dLight, XML_infoText,
247 XML_infoBk
250 switch( nOleColor & OLE_COLORTYPE_MASK )
252 case OLE_COLORTYPE_CLIENT:
253 return bDefaultColorBgr ? lclDecodeBgrColor( nOleColor ) : rGraphicHelper.getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
255 case OLE_COLORTYPE_PALETTE:
256 return rGraphicHelper.getPaletteColor( nOleColor & OLE_PALETTECOLOR_MASK );
258 case OLE_COLORTYPE_BGR:
259 return lclDecodeBgrColor( nOleColor );
261 case OLE_COLORTYPE_SYSCOLOR:
262 return rGraphicHelper.getSystemColor( STATIC_ARRAY_SELECT( spnSystemColors, nOleColor & OLE_SYSTEMCOLOR_MASK, XML_TOKEN_INVALID ), API_RGB_WHITE );
264 OSL_FAIL( "OleHelper::decodeOleColor - unknown color type" );
265 return API_RGB_BLACK;
268 sal_uInt32 OleHelper::encodeOleColor( sal_Int32 nRgbColor )
270 return OLE_COLORTYPE_BGR | lclSwapRedBlue( static_cast< sal_uInt32 >( nRgbColor & 0xFFFFFF ) );
273 void OleHelper::exportGuid( BinaryOutputStream& rOStr, const SvGlobalName& rId )
275 const sal_uInt8* pBytes = rId.GetBytes();
276 sal_uInt32 a;
277 memcpy(&a, pBytes, sizeof(sal_uInt32));
278 rOStr<< a;
280 sal_uInt16 b;
281 memcpy(&b, pBytes+4, sizeof(sal_uInt16));
282 rOStr << b;
284 memcpy(&b, pBytes+6, sizeof(sal_uInt16));
285 rOStr << b;
287 rOStr.writeArray( (sal_uInt8 *)&pBytes[ 8 ], 8 );
289 OUString OleHelper::importGuid( BinaryInputStream& rInStrm )
291 OUStringBuffer aBuffer;
292 aBuffer.append( '{' );
293 lclAppendHex( aBuffer, rInStrm.readuInt32() );
294 aBuffer.append( '-' );
295 lclAppendHex( aBuffer, rInStrm.readuInt16() );
296 aBuffer.append( '-' );
297 lclAppendHex( aBuffer, rInStrm.readuInt16() );
298 aBuffer.append( '-' );
299 lclAppendHex( aBuffer, rInStrm.readuInt8() );
300 lclAppendHex( aBuffer, rInStrm.readuInt8() );
301 aBuffer.append( '-' );
302 for( int nIndex = 0; nIndex < 6; ++nIndex )
303 lclAppendHex( aBuffer, rInStrm.readuInt8() );
304 aBuffer.append( '}' );
305 return aBuffer.makeStringAndClear();
308 bool OleHelper::importStdFont( StdFontInfo& orFontInfo, BinaryInputStream& rInStrm, bool bWithGuid )
310 if( bWithGuid )
312 bool bIsStdFont = importGuid( rInStrm ) == OLE_GUID_STDFONT;
313 OSL_ENSURE( bIsStdFont, "OleHelper::importStdFont - unexpected header GUID, expected StdFont" );
314 if( !bIsStdFont )
315 return false;
318 sal_uInt8 nVersion, nNameLen;
319 rInStrm >> nVersion >> orFontInfo.mnCharSet >> orFontInfo.mnFlags >> orFontInfo.mnWeight >> orFontInfo.mnHeight >> nNameLen;
320 // according to spec the name is ASCII
321 orFontInfo.maName = rInStrm.readCharArrayUC( nNameLen, RTL_TEXTENCODING_ASCII_US );
322 OSL_ENSURE( nVersion <= 1, "OleHelper::importStdFont - wrong version" );
323 return !rInStrm.isEof() && (nVersion <= 1);
326 bool OleHelper::importStdPic( StreamDataSequence& orGraphicData, BinaryInputStream& rInStrm, bool bWithGuid )
328 if( bWithGuid )
330 bool bIsStdPic = importGuid( rInStrm ) == OLE_GUID_STDPIC;
331 OSL_ENSURE( bIsStdPic, "OleHelper::importStdPic - unexpected header GUID, expected StdPic" );
332 if( !bIsStdPic )
333 return false;
336 sal_uInt32 nStdPicId;
337 sal_Int32 nBytes;
338 rInStrm >> nStdPicId >> nBytes;
339 OSL_ENSURE( nStdPicId == OLE_STDPIC_ID, "OleHelper::importStdPic - unexpected header version" );
340 return !rInStrm.isEof() && (nStdPicId == OLE_STDPIC_ID) && (nBytes > 0) && (rInStrm.readData( orGraphicData, nBytes ) == nBytes);
343 Reference< ::com::sun::star::frame::XFrame >
344 lcl_getFrame( const Reference< ::com::sun::star::frame::XModel >& rxModel )
346 Reference< ::com::sun::star::frame::XFrame > xFrame;
347 if ( rxModel.is() )
349 Reference< ::com::sun::star::frame::XController > xController = rxModel->getCurrentController();
350 xFrame = xController.is() ? xController->getFrame() : NULL;
352 return xFrame;
355 class OleFormCtrlExportHelper
357 ::oox::ole::EmbeddedControl maControl;
358 ::oox::ole::ControlModelBase* mpModel;
359 ::oox::GraphicHelper maGrfHelper;
360 Reference< XModel > mxDocModel;
361 Reference< XControlModel > mxControlModel;
363 OUString maName;
364 OUString maTypeName;
365 OUString maFullName;
366 OUString maGUID;
367 public:
368 OleFormCtrlExportHelper( const Reference< XComponentContext >& rxCtx, const Reference< XModel >& xDocModel, const Reference< XControlModel >& xModel );
369 virtual ~OleFormCtrlExportHelper() { }
370 virtual OUString getGUID()
372 OUString sResult;
373 if ( maGUID.getLength() > 2 )
374 sResult = maGUID.copy(1, maGUID.getLength() - 2 );
375 return sResult;
377 OUString getFullName() { return maFullName; }
378 OUString getTypeName() { return maTypeName; }
379 bool isValid() { return mpModel != NULL; }
380 void exportName( const Reference< XOutputStream >& rxOut );
381 void exportCompObj( const Reference< XOutputStream >& rxOut );
382 void exportControl( const Reference< XOutputStream >& rxOut, const ::com::sun::star::awt::Size& rSize );
384 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 )
386 // try to get the guid
387 Reference< com::sun::star::beans::XPropertySet > xProps( xCntrlModel, UNO_QUERY );
388 if ( xProps.is() )
390 sal_Int16 nClassId = 0;
391 PropertySet aPropSet( mxControlModel );
392 if ( aPropSet.getProperty( nClassId, PROP_ClassId ) )
394 /* psuedo ripped from legacy msocximex:
395 "There is a truly horrible thing with EditControls and FormattedField
396 Controls, they both pretend to have an EDITBOX ClassId for compability
397 reasons, at some stage in the future hopefully there will be a proper
398 FormulaField ClassId rather than this piggybacking two controls onto the
399 same ClassId, cmc." - when fixed the fake FORMULAFIELD id entry
400 and definition above can be removed/replaced
402 if ( nClassId == FormComponentType::TEXTFIELD)
404 Reference< XServiceInfo > xInfo( xCntrlModel,
405 UNO_QUERY);
406 if (xInfo->
407 supportsService( "com.sun.star.form.component.FormattedField" ) )
408 nClassId = FORMULAFIELD;
410 else if ( nClassId == FormComponentType::COMMANDBUTTON )
412 bool bToggle = false;
413 aPropSet.getProperty( bToggle, PROP_Toggle );
414 if ( bToggle )
415 nClassId = TOGGLEBUTTON;
417 else if ( nClassId == FormComponentType::CONTROL )
419 Reference< XServiceInfo > xInfo( xCntrlModel,
420 UNO_QUERY);
421 if (xInfo->supportsService("com.sun.star.form.component.ImageControl" ) )
422 nClassId = FormComponentType::IMAGECONTROL;
425 GUIDCNamePairMap& cntrlMap = classIdToGUIDCNamePairMap::get();
426 GUIDCNamePairMap::iterator it = cntrlMap.find( nClassId );
427 if ( it != cntrlMap.end() )
429 aPropSet.getProperty(maName, PROP_Name );
430 maTypeName = OUString::createFromAscii( it->second.sName );
431 maFullName = "Microsoft Forms 2.0 " + maTypeName;
432 maControl = EmbeddedControl( maName );
433 maGUID = OUString::createFromAscii( it->second.sGUID );
434 mpModel = maControl.createModelFromGuid( maGUID );
440 void OleFormCtrlExportHelper::exportName( const Reference< XOutputStream >& rxOut )
442 oox::BinaryXOutputStream aOut( rxOut, false );
443 aOut.writeUnicodeArray( maName );
444 aOut << sal_Int32(0);
447 void OleFormCtrlExportHelper::exportCompObj( const Reference< XOutputStream >& rxOut )
449 oox::BinaryXOutputStream aOut( rxOut, false );
450 if ( mpModel )
451 mpModel->exportCompObj( aOut );
454 void OleFormCtrlExportHelper::exportControl( const Reference< XOutputStream >& rxOut, const Size& rSize )
456 oox::BinaryXOutputStream aOut( rxOut, false );
457 if ( mpModel )
459 ::oox::ole::ControlConverter aConv( mxDocModel, maGrfHelper );
460 maControl.convertFromProperties( mxControlModel, aConv );
461 mpModel->maSize.first = rSize.Width;
462 mpModel->maSize.second = rSize.Height;
463 mpModel->exportBinaryModel( aOut );
467 MSConvertOCXControls::MSConvertOCXControls( const Reference< ::com::sun::star::frame::XModel >& rxModel ) : SvxMSConvertOCXControls( rxModel ), mxCtx( comphelper::getProcessComponentContext() ), maGrfHelper( mxCtx, lcl_getFrame( rxModel ), StorageRef() )
471 MSConvertOCXControls::~MSConvertOCXControls()
475 bool
476 MSConvertOCXControls::importControlFromStream( ::oox::BinaryInputStream& rInStrm, Reference< XFormComponent >& rxFormComp, const OUString& rGuidString )
478 ::oox::ole::EmbeddedControl aControl( "Unknown" );
479 if( ::oox::ole::ControlModelBase* pModel = aControl.createModelFromGuid( rGuidString ) )
481 pModel->importBinaryModel( rInStrm );
482 rxFormComp.set( mxCtx->getServiceManager()->createInstanceWithContext( pModel->getServiceName(), mxCtx ), UNO_QUERY );
483 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
484 ::oox::ole::ControlConverter aConv( mxModel, maGrfHelper );
485 aControl.convertProperties( xCtlModel, aConv );
487 return rxFormComp.is();
490 sal_Bool
491 MSConvertOCXControls::ReadOCXCtlsStream( SotStorageStreamRef& rSrc1, Reference< XFormComponent > & rxFormComp,
492 sal_Int32 nPos,
493 sal_Int32 nStreamSize)
495 if ( rSrc1.Is() )
497 BinaryXInputStream aCtlsStrm( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper( *rSrc1 ) ), true );
498 aCtlsStrm.seek( nPos );
499 OUString aStrmClassId = ::oox::ole::OleHelper::importGuid( aCtlsStrm );
500 return importControlFromStream( aCtlsStrm, rxFormComp, aStrmClassId, nStreamSize );
502 return sal_False;
505 bool MSConvertOCXControls::importControlFromStream( ::oox::BinaryInputStream& rInStrm, Reference< XFormComponent >& rxFormComp, const OUString& rStrmClassId,
506 sal_Int32 nStreamSize)
508 if ( !rInStrm.isEof() )
510 // Special processing for those html controls
511 bool bOneOfHtmlControls = false;
512 if ( rStrmClassId.toAsciiUpperCase().equalsAscii( HTML_GUID_SELECT )
513 || rStrmClassId.toAsciiUpperCase().equalsAscii( HTML_GUID_TEXTBOX ) )
514 bOneOfHtmlControls = false;
516 if ( bOneOfHtmlControls )
518 // html controls don't seem have a handy record length following the GUID
519 // in the binary stream.
520 // Given the control stream length create a stream of nStreamSize bytes starting from
521 // nPos ( offset by the guid already read in )
522 if ( !nStreamSize )
523 return false;
524 const int nGuidSize = 0x10;
525 StreamDataSequence aDataSeq;
526 sal_Int32 nBytesToRead = nStreamSize - nGuidSize;
527 while ( nBytesToRead )
528 nBytesToRead -= rInStrm.readData( aDataSeq, nBytesToRead );
529 SequenceInputStream aInSeqStream( aDataSeq );
530 importControlFromStream( aInSeqStream, rxFormComp, rStrmClassId );
532 else
534 importControlFromStream( rInStrm, rxFormComp, rStrmClassId );
537 return rxFormComp.is();
540 sal_Bool MSConvertOCXControls::ReadOCXStorage( SotStorageRef& xOleStg,
541 Reference< XFormComponent > & rxFormComp )
543 if ( xOleStg.Is() )
545 SvStorageStreamRef pNameStream = xOleStg->OpenSotStream( OUString("\3OCXNAME"));
546 BinaryXInputStream aNameStream( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper( *pNameStream ) ), true );
548 SvStorageStreamRef pContents = xOleStg->OpenSotStream( OUString("contents"));
549 BinaryXInputStream aInStrm( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper( *pContents ) ), true );
552 SvStorageStreamRef pClsStrm = xOleStg->OpenSotStream(OUString("\1CompObj"));
553 BinaryXInputStream aClsStrm( Reference< XInputStream >( new utl::OSeekableInputStreamWrapper(*pClsStrm ) ), true );
554 aClsStrm.skip(12);
556 OUString aStrmClassId = ::oox::ole::OleHelper::importGuid( aClsStrm );
557 if ( importControlFromStream( aInStrm, rxFormComp, aStrmClassId, aInStrm.size() ) )
559 OUString aName = aNameStream.readNulUnicodeArray();
560 Reference< XControlModel > xCtlModel( rxFormComp, UNO_QUERY );
561 if ( !aName.isEmpty() && xCtlModel.is() )
563 PropertyMap aPropMap;
564 aPropMap.setProperty( PROP_Name, aName );
565 PropertySet aPropSet( xCtlModel );
566 aPropSet.setProperties( aPropMap );
568 return rxFormComp.is();
571 return sal_False;
574 sal_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 )
576 OleFormCtrlExportHelper exportHelper( comphelper::getProcessComponentContext(), rxModel, rxControlModel );
577 if ( !exportHelper.isValid() )
578 return sal_False;
579 rName = exportHelper.getTypeName();
580 SvGlobalName aName;
581 OUString sId = exportHelper.getGUID();
582 aName.MakeId(sId);
583 BinaryXOutputStream xOut( xOutStrm, false );
584 OleHelper::exportGuid( xOut, aName );
585 exportHelper.exportControl( xOutStrm, rSize );
586 return sal_True;
589 sal_Bool MSConvertOCXControls::WriteOCXStream( const Reference< XModel >& rxModel, SotStorageRef &xOleStg,
590 const Reference< XControlModel > &rxControlModel,
591 const com::sun::star::awt::Size& rSize, OUString &rName)
593 SvGlobalName aName;
595 OleFormCtrlExportHelper exportHelper( comphelper::getProcessComponentContext(), rxModel, rxControlModel );
597 if ( !exportHelper.isValid() )
598 return sal_False;
600 OUString sId = exportHelper.getGUID();
601 aName.MakeId(sId);
603 OUString sFullName = exportHelper.getFullName();
604 rName = exportHelper.getTypeName();
605 xOleStg->SetClass( aName,0x5C,sFullName);
607 SvStorageStreamRef pNameStream = xOleStg->OpenSotStream(OUString("\3OCXNAME"));
608 Reference< XOutputStream > xOut = new utl::OSeekableOutputStreamWrapper( *pNameStream );
609 exportHelper.exportName( xOut );
612 SvStorageStreamRef pObjStream = xOleStg->OpenSotStream(OUString("\1CompObj"));
613 Reference< XOutputStream > xOut = new utl::OSeekableOutputStreamWrapper( *pObjStream );
614 exportHelper.exportCompObj( xOut );
617 SvStorageStreamRef pContents = xOleStg->OpenSotStream(OUString("contents"));
618 Reference< XOutputStream > xOut = new utl::OSeekableOutputStreamWrapper( *pContents );
619 exportHelper.exportControl( xOut, rSize );
621 return sal_True;
624 #ifdef SvxMSConvertOCXControlsRemoved
625 const Reference< com::sun::star::lang::XMultiServiceFactory > & MSConvertOCXControls::GetServiceFactory()
627 if ( !mxServiceFactory.is() && mxModel.is() )
628 mxServiceFactory.set( mxModel, UNO_QUERY );
629 return mxServiceFactory;
632 const Reference< XIndexContainer >&
633 MSConvertOCXControls::GetFormComps()
635 if( !mxFormComps.is() )
637 GetDrawPage();
638 if( mxDrawPage.is() )
640 Reference< XFormsSupplier > xFormsSupplier( mxDrawPage,
641 UNO_QUERY );
642 OSL_ENSURE( xFormsSupplier.is(),
643 "not able to get XFormsSupplier from XDrawPage" );
645 Reference< XNameContainer > xNameCont =
646 xFormsSupplier->getForms();
648 OUString sStdName = "WW-Standard";
649 OUString sName( sStdName );
650 sal_uInt16 n = 0;
652 while( xNameCont->hasByName( sName ) )
654 sName = sStdName;
655 sName += OUString::number(++n);
658 const Reference< XMultiServiceFactory > &rServiceFactory
659 = GetServiceFactory();
660 if( !rServiceFactory.is() )
661 return mxFormComps;
663 Reference< XInterface > xCreate =
664 rServiceFactory->createInstance("com.sun.star.form.component.Form");
665 if( xCreate.is() )
667 Reference< XPropertySet > xFormPropSet( xCreate,
668 UNO_QUERY );
670 Any aTmp(&sName,getCppuType((OUString *)0));
671 xFormPropSet->setPropertyValue( "Name", aTmp );
673 Reference< XForm > xForm( xCreate, UNO_QUERY );
674 OSL_ENSURE(xForm.is(), "No Form?");
676 Reference< XIndexContainer > xForms( xNameCont,
677 UNO_QUERY );
678 OSL_ENSURE( xForms.is(), "XForms not available" );
680 aTmp.setValue( &xForm,
681 ::getCppuType((Reference < XForm >*)0));
682 xForms->insertByIndex( xForms->getCount(), aTmp );
684 mxFormComps = Reference< XIndexContainer >
685 (xCreate, UNO_QUERY);
690 return mxFormComps;
692 const Reference< XDrawPage >& MSConvertOCXControls::GetDrawPage()
694 if( !mxDrawPage.is() && mxModel.is() )
696 Reference< XDrawPageSupplier > xTxtDoc(mxModel, UNO_QUERY);
697 OSL_ENSURE( xTxtDoc.is(),"no XDrawPageSupplier from XModel");
698 mxDrawPage = xTxtDoc->getDrawPage();
699 OSL_ENSURE( mxDrawPage.is(), "no XDrawPage" );
701 return mxDrawPage;
704 const Reference< XShapes >& MSConvertOCXControls::GetShapes()
706 if( !mxShapes.is() )
708 GetDrawPage();
709 if( mxDrawPage.is() )
712 mxShapes = Reference< XShapes >(mxDrawPage,
713 UNO_QUERY);
714 OSL_ENSURE( mxShapes.is(), "no XShapes from XDrawPage" );
717 return mxShapes;
719 #endif
720 // ============================================================================
722 } // namespace ole
723 } // namespace oox
725 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */