update ooo310-m15
[ooovba.git] / applied_patches / 0365-controls-with-images-import.diff
blobf1182e8da7127c81215cded3c480a4138f3ac94d
1 --- svx/inc/svx/msocximex.hxx.bak 2008-09-01 10:18:35.000000000 +0800
2 +++ svx/inc/svx/msocximex.hxx 2008-09-01 10:35:13.000000000 +0800
3 @@ -32,6 +32,7 @@
5 #include <sot/storage.hxx>
6 #include <tools/debug.hxx>
7 +#include <com/sun/star/graphic/XGraphicObject.hpp>
9 //!! no such defines in global namespaces - it will break other existing code that uses the same define!!
10 //#ifndef C2U
11 @@ -327,14 +328,13 @@ public:
12 nMultiState(0), nValueLen(0), nCaptionLen(0), nVertPos(1), nHorzPos(7),
13 nSpecialEffect(2), nIcon(0), nPicture(0), nAccelerator(0), nGroupNameLen(0),
14 pValue(0), pCaption(0), pGroupName(0), nIconLen(0), pIcon(0),
15 - nPictureLen(0), pPicture(0) {}
16 + nPictureLen(0) {}
18 ~OCX_ModernControl() {
19 if (pValue) delete[] pValue;
20 if (pCaption) delete[] pCaption;
21 if (pGroupName) delete[] pGroupName;
22 if (pIcon) delete[] pIcon;
23 - if (pPicture) delete[] pPicture;
25 sal_Bool Read(SotStorageStream *pS);
27 @@ -417,7 +417,8 @@ public:
29 sal_uInt8 pPictureHeader[20];
30 sal_uInt32 nPictureLen;
31 - sal_uInt8 *pPicture;
32 + ::rtl::OUString sImageUrl;
33 + com::sun::star::uno::Reference< com::sun::star::graphic::XGraphicObject> mxGrfObj;
37 @@ -466,6 +467,7 @@ public:
39 bool bAutoSize;
40 ::rtl::OUString sImageUrl;
41 + com::sun::star::uno::Reference< com::sun::star::graphic::XGraphicObject> mxGrfObj;
42 sal_Bool Read(SotStorageStream *pS);
44 using OCX_Control::Import; // to not hide the other two import methods
45 @@ -817,7 +819,6 @@ public:
47 delete[] pCaption;
48 delete[] pIcon;
49 - delete[] pPicture;
52 virtual sal_Bool Read(SvStorageStream *pS);
53 @@ -881,7 +882,8 @@ public:
55 sal_uInt8 pPictureHeader[20];
56 sal_uInt32 nPictureLen;
57 - sal_uInt8 *pPicture;
58 + ::rtl::OUString sImageUrl;
59 + com::sun::star::uno::Reference< com::sun::star::graphic::XGraphicObject> mxGrfObj;
60 private:
61 com::sun::star::uno::Reference<
62 com::sun::star::uno::XComponentContext> mxCtx;
63 @@ -1076,7 +1078,7 @@ public:
64 fEnabled(1), fLocked(0), fBackStyle(1), fWordWrap(0), fAutoSize(0),
65 nCaptionLen(0), nVertPos(1), nHorzPos(7), nMousePointer(0), nPicture(0),
66 nAccelerator(0), nIcon(0), pCaption(0), nIconLen(0), pIcon(0), nPictureLen(0),
67 - pPicture(0), mbTakeFocus( true )
68 + mbTakeFocus( true )
70 msFormType = rtl::OUString::createFromAscii("com.sun.star.form.component.CommandButton");
71 msDialogType = rtl::OUString::createFromAscii("com.sun.star.awt.UnoControlButtonModel");
72 @@ -1087,7 +1089,6 @@ public:
73 ~OCX_CommandButton() {
74 if (pCaption) delete[] pCaption;
75 if (pIcon) delete[] pIcon;
76 - if (pPicture) delete[] pPicture;
78 sal_Bool Read(SotStorageStream *pS);
80 @@ -1130,7 +1131,8 @@ public:
82 sal_uInt8 pPictureHeader[20];
83 sal_uInt32 nPictureLen;
84 - sal_uInt8 *pPicture;
85 + ::rtl::OUString sImageUrl;
86 + com::sun::star::uno::Reference< com::sun::star::graphic::XGraphicObject> mxGrfObj;
88 bool mbTakeFocus;
90 @@ -1248,7 +1250,7 @@ public:
92 sal_uInt8 pPictureHeader[20];
93 sal_uInt32 nPictureLen;
94 - sal_uInt8 *pPicture;
95 + sal_uInt8 *pPicture;
97 static OCX_Control *Create() { return new OCX_Label;}
99 --- svx/source/msfilter/msocximex.cxx.bak 2008-09-01 10:18:35.000000000 +0800
100 +++ svx/source/msfilter/msocximex.cxx 2008-09-01 10:54:52.000000000 +0800
101 @@ -79,6 +79,12 @@
103 #include <algorithm>
104 #include <memory>
105 +#include <com/sun/star/graphic/GraphicObject.hpp>
106 +#include <com/sun/star/graphic/XGraphicProvider.hpp>
107 +#include <com/sun/star/graphic/XGraphic.hpp>
108 +#include <com/sun/star/io/XInputStream.hpp>
109 +#include <comphelper/componentcontext.hxx>
110 +#include <unotools/streamwrap.hxx>
112 #ifndef C2S
113 #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
114 @@ -102,6 +108,7 @@ using namespace cppu;
117 #define WW8_ASCII2STR(s) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(s))
118 +#define GRAPHOBJ_URLPREFIX "vnd.sun.star.GraphicObject:"
121 static char sWW8_form[] = "WW-Standard";
122 @@ -130,126 +137,48 @@ long ReadAlign(SvStorageStream *pS, long
123 return 0;
127 // NP - Images in controls in OO2.0/SO8 exist as links, e.g. they are not part of the document so are
128 // referenced externally. On import from ms document try to save images for controls here.
129 // Images are stored in directory called temp in the user installation directory. Next version of OO/SO
130 // hopefully will address this issue and allow a choice e.g. images for controls to be stored as links
131 // or embeded in the document.
133 -// [out]location path to the stream to where the image is to be stored,
134 -// if same name exists in folder then this function calcuates a new name
135 -// [in] data raw bytes of image to be stored.
136 -// [in] dataLen no. byte to be stored
138 -// returns, true if successful
140 -bool storePictureInFileSystem( OUString& location, sal_uInt8* data, sal_uInt32 dataLen )
141 +uno::Reference< graphic::XGraphicObject> lcl_readGraphicObject( SotStorageStream *pS )
143 - bool result = true;
144 - OUString origPath = location;
145 - try
147 - uno::Reference<lang::XMultiServiceFactory > xMSF( ::comphelper::getProcessServiceFactory(),
148 - uno::UNO_QUERY_THROW );
149 - uno::Reference< com::sun::star::ucb::XSimpleFileAccess> xSFA( xMSF->createInstance(
150 - S2U("com.sun.star.ucb.SimpleFileAccess" ) ),
151 - uno::UNO_QUERY_THROW );
152 - OUString ext;
153 - sal_Int32 index = 0;
154 - while ( xSFA->exists( location ) )
156 - ext = OUString::valueOf( ++index );
157 - location = origPath + ext;
160 - SvStream* pStream = ::utl::UcbStreamHelper::CreateStream( location, STREAM_WRITE | STREAM_TRUNC );
161 - if ( pStream )
163 - pStream->Write(data, dataLen);
164 - delete pStream;
166 - else
168 - result = false;
171 - catch( uno::Exception& )
173 - result = false;
175 - return result;
176 + uno::Reference< graphic::XGraphicObject > xGrfObj;
177 + uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory();
178 + if( xServiceManager.is() )
180 + try
182 + // use the GraphicProvider service to get the XGraphic
183 + uno::Reference< graphic::XGraphicProvider > xGraphProvider(
184 + xServiceManager->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.graphic.GraphicProvider" ) ), uno::UNO_QUERY );
185 + if( xGraphProvider.is() )
187 + uno::Reference< io::XInputStream > xStream( new utl::OInputStreamWrapper( *pS ) );
188 + if( xStream.is() )
190 + uno::Sequence< beans::PropertyValue > aMediaProps( 1 );
191 + aMediaProps[0].Name = ::rtl::OUString::createFromAscii( "InputStream" );
192 + aMediaProps[0].Value <<= xStream;
193 + uno::Reference< graphic::XGraphic > xGraphic = xGraphProvider->queryGraphic( aMediaProps );
194 + if( xGraphic.is() )
196 + // create an XGraphicObject
197 + ::comphelper::ComponentContext aContext( xServiceManager );
198 + xGrfObj = graphic::GraphicObject::create( aContext.getUNOContext() );
199 + xGrfObj->setGraphic(xGraphic);
204 + catch( uno::Exception& )
208 + return xGrfObj;
211 -// NP - Images in controls in OO2.0/SO8 exist as links, e.g. they are not part of the document so are
212 -// referenced externally. On import from ms document try to save images from controls here so this
213 -// at least a macro programmer has a chance to accessed them manually later. Next version of OO/SO
214 -// hopefully will address this issue.
215 -// Images will be stored in a top level folder in the document package, folder is named "MigratedImages"
217 -// [in] pDocSh* the document shell.
218 -// [in] name name of stream image to stored in.
219 -// [in] data raw bytes of image to be stored.
220 -// [in] dataLen no. byte to be stored
222 -bool storePictureInDoc( SfxObjectShell* pDocSh, OUString& name, sal_uInt8* data, sal_uInt32 dataLen )
224 - uno::Reference < embed::XStorage > xStor;
225 - if (pDocSh)
227 - xStor = pDocSh->GetStorage();
228 - if( xStor.is() )
230 - try
232 - uno::Reference< embed::XStorage > xPictures = xStor->openStorageElement(
233 - OUString( RTL_CONSTASCII_USTRINGPARAM( "MigratedImages" ) ),
234 - embed::ElementModes::READWRITE );
235 - uno::Reference< beans::XPropertySet > xPropSet( xPictures, uno::UNO_QUERY );
237 - // Set media type of folder MigratedImages to something ( that is unknown ) so that
238 - // it will get copied to exported OO/SO format after SaveAs
239 - if ( xPropSet.is() )
241 - OUString aMediaType = C2U("MigrationImages");
242 - uno::Any a;
243 - a <<= aMediaType;
244 - xPropSet->setPropertyValue( C2U("MediaType"), a );
247 - uno::Reference< io::XStream > xObjReplStr = xPictures->openStreamElement(
248 - name,
249 - embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
250 - uno::Reference< io::XOutputStream > xOutStream( xObjReplStr->getOutputStream(), uno::UNO_QUERY_THROW );
251 - uno::Sequence< sal_Int8 > imageBytes( (sal_Int8*)data, dataLen );
252 - xOutStream->writeBytes( imageBytes );
253 - xOutStream->closeOutput();
255 - uno::Reference< embed::XTransactedObject > xTransact( xPictures, uno::UNO_QUERY );
256 - if ( xTransact.is() )
258 - xTransact->commit();
261 - catch( uno::Exception& )
263 - return false;
267 - else
269 - // no storage something wrong
270 - return false;
273 - else
275 - //No doc shell
276 - return false;
278 - return true;
281 long WriteAlign(SvStorageStream *pS, int nAmount)
283 @@ -1243,6 +1172,12 @@ sal_Bool OCX_CommandButton::Import( com:
284 rPropSet->setPropertyValue( WW8_ASCII2STR( "FocusOnClick" ), aTmp );
286 aFontData.Import(rPropSet);
288 + if ( sImageUrl.getLength() )
290 + aTmp <<= sImageUrl;
291 + rPropSet->setPropertyValue( WW8_ASCII2STR("ImageURL"), aTmp);
293 return sal_True;
296 @@ -1564,7 +1599,11 @@ sal_Bool OCX_OptionButton::Import(com::s
297 aTmp <<= lclCreateOUString( pGroupName, nGroupNameLen );
298 rPropSet->setPropertyValue( WW8_ASCII2STR("GroupName"), aTmp);
301 + if ( sImageUrl.getLength() )
303 + aTmp <<= sImageUrl;
304 + rPropSet->setPropertyValue( WW8_ASCII2STR("ImageURL"), aTmp);
306 aFontData.Import(rPropSet);
307 return sal_True;
309 @@ -2198,6 +2139,12 @@ sal_Bool OCX_ToggleButton::Import(com::s
312 aFontData.Import(rPropSet);
314 + if ( sImageUrl.getLength() )
316 + aTmp <<= sImageUrl;
317 + rPropSet->setPropertyValue( WW8_ASCII2STR("ImageURL"), aTmp);
319 return sal_True;
322 @@ -3051,8 +2998,15 @@ sal_Bool OCX_ModernControl::Read(SvStora
324 pS->Read(pPictureHeader,20);
325 *pS >> nPictureLen;
326 - pPicture = new sal_uInt8[nPictureLen];
327 - pS->Read(pPicture,nPictureLen);
328 + long imagePos = pS->Tell();
329 + mxGrfObj = lcl_readGraphicObject( pS );
330 + if( mxGrfObj.is() )
332 + sImageUrl = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( GRAPHOBJ_URLPREFIX ) );
333 + sImageUrl = sImageUrl + mxGrfObj->getUniqueID();
335 + // make sure the stream position should be pointing after the image
336 + pS->Seek( imagePos + nPictureLen );
339 return sal_True;
340 @@ -3362,8 +3316,15 @@ sal_Bool OCX_CommandButton::Read(SvStora
342 pS->Read(pPictureHeader,20);
343 *pS >> nPictureLen;
344 - pPicture = new sal_uInt8[nPictureLen];
345 - pS->Read(pPicture,nPictureLen);
346 + long imagePos = pS->Tell();
347 + mxGrfObj = lcl_readGraphicObject( pS );
348 + if( mxGrfObj.is() )
350 + sImageUrl = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( GRAPHOBJ_URLPREFIX ) );
351 + sImageUrl = sImageUrl + mxGrfObj->getUniqueID();
353 + // make sure the stream position should be pointing after the image
354 + pS->Seek( imagePos + nPictureLen );
357 return sal_True;
358 @@ -4140,8 +4101,7 @@ OCX_UserForm::OCX_UserForm( SotStorageRe
359 nKeepScrollBarsVisible(3), nCycle(0), nBorderStyle(0), nSpecialEffect(0),
360 nPicture(0), nPictureAlignment(2), nPictureSizeMode(0),
361 bPictureTiling(FALSE), nAccelerator(0), nIcon(0), pCaption(0),
362 - nScrollWidth(0), nScrollHeight(0), nScrollLeft(0), nScrollTop(0), nIconLen(0), pIcon(0), nPictureLen(0),
363 - pPicture(0)
364 + nScrollWidth(0), nScrollHeight(0), nScrollLeft(0), nScrollTop(0), nIconLen(0), pIcon(0), nPictureLen(0)
366 mnForeColor = 0x80000012;
367 mnBackColor = 0x8000000F;
368 @@ -4275,8 +4235,15 @@ sal_Bool OCX_UserForm::Read(SvStorageStr
370 pS->Read(pPictureHeader,20);
371 *pS >> nPictureLen;
372 - pPicture = new sal_uInt8[nPictureLen];
373 - pS->Read(pPicture,nPictureLen);
374 + long imagePos = pS->Tell();
375 + mxGrfObj = lcl_readGraphicObject( pS );
376 + if( mxGrfObj.is() )
378 + sImageUrl = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( GRAPHOBJ_URLPREFIX ) );
379 + sImageUrl = sImageUrl + mxGrfObj->getUniqueID();
381 + // make sure the stream position should be pointing after the image
382 + pS->Seek( imagePos + nPictureLen );
385 ReadAlign( pS, pS->Tell() - nStart, 4);
386 @@ -4338,6 +4305,19 @@ sal_Bool OCX_UserForm::Import(
387 rLib->replaceByName(sName, aSourceAny);
388 else
389 rLib->insertByName(sName, aSourceAny);
391 + if ( sImageUrl.getLength() )
393 + aTmp <<= sImageUrl;
394 + try
396 + xDialogPropSet->setPropertyValue( WW8_ASCII2STR("ImageURL"), aTmp);
398 + catch( uno::Exception& )
400 + OSL_TRACE("OCX_UserForm::Import, Image fails to import");
403 return sal_True;
406 @@ -5016,12 +4996,6 @@ sal_Bool OCX_TabStrip::ReadFontData(SotS
408 sal_Bool OCX_Image::Read(SotStorageStream *pS)
410 - if ( !bSetInDialog )
412 - // preserve the present behavior at the moment.
413 - // only import image control for UserForms
414 - return sal_False;
416 ULONG nStart = pS->Tell();
417 *pS >> nIdentifier;
418 DBG_ASSERT(nStandardId==nIdentifier,
419 @@ -5125,16 +5099,14 @@ sal_Bool OCX_Image::Read(SotStorageStrea
421 long imagePos = pS->Tell();
423 - pS->Seek( imagePos );
425 - sImageUrl = C2U("vnd.sun.star.expand:${$BRAND_BASE_DIR/program/") + C2U( SAL_CONFIGFILE( "bootstrap" ) ) + C2U("::UserInstallation}/user/temp/") + sName;
427 - sal_uInt8* pImage = new sal_uInt8[ nImageLen ];
428 - pS->Read(pImage, nImageLen);
429 - bool result = storePictureInFileSystem( sImageUrl, pImage, nImageLen );
430 - OUString pictName = sImageUrl.copy( sImageUrl.lastIndexOf('/') + 1 );
431 - result = storePictureInDoc( pDocSh, pictName, pImage, nImageLen );
432 - delete pImage;
433 + mxGrfObj = lcl_readGraphicObject( pS );
434 + if( mxGrfObj.is() )
436 + sImageUrl = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( GRAPHOBJ_URLPREFIX ) );
437 + sImageUrl = sImageUrl + mxGrfObj->getUniqueID();
439 + // make sure the stream position should be pointing after the image
440 + pS->Seek( imagePos + nImageLen );
442 return sal_True;