Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/urlobj.hxx>
31 : : #include <tools/vcompat.hxx>
32 : : #include <unotools/streamwrap.hxx>
33 : : #include <unotools/ucbstreamhelper.hxx>
34 : : #include <unotools/tempfile.hxx>
35 : : #include <unotools/localfilehelper.hxx>
36 : : #include <ucbhelper/content.hxx>
37 : : #include <sot/storage.hxx>
38 : : #include <sot/formats.hxx>
39 : : #include <sot/filelist.hxx>
40 : : #include <vcl/virdev.hxx>
41 : : #include <vcl/cvtgrf.hxx>
42 : : #include <svl/itempool.hxx>
43 : : #include <sfx2/docfile.hxx>
44 : : #include <avmedia/mediawindow.hxx>
45 : : #include <svx/svdograf.hxx>
46 : : #include <svx/fmpage.hxx>
47 : : #include "codec.hxx"
48 : : #include <svx/unomodel.hxx>
49 : : #include <svx/fmmodel.hxx>
50 : : #include <svx/fmview.hxx>
51 : : #include "svx/galmisc.hxx"
52 : : #include "svx/galtheme.hxx"
53 : : #include <com/sun/star/sdbc/XResultSet.hpp>
54 : : #include <com/sun/star/ucb/XContentAccess.hpp>
55 : : #include <com/sun/star/io/XInputStream.hpp>
56 : : #include "galobj.hxx"
57 : : #include <svx/gallery1.hxx>
58 : : #include "galtheme.hrc"
59 : : #include <vcl/lstbox.hxx>
60 : : #include "gallerydrawmodel.hxx"
61 : :
62 : : // --------------
63 : : // - Namespaces -
64 : : // --------------
65 : :
66 : : using namespace ::rtl;
67 : : using namespace ::com::sun::star;
68 : :
69 : : // ------------
70 : : // - SgaTheme -
71 : : // ------------
72 : :
73 : 0 : GalleryTheme::GalleryTheme( Gallery* pGallery, GalleryThemeEntry* pThemeEntry ) :
74 : : pParent ( pGallery ),
75 : : pThm ( pThemeEntry ),
76 : : mnThemeLockCount ( 0 ),
77 : : mnBroadcasterLockCount( 0 ),
78 : : nDragPos ( 0 ),
79 [ # # ][ # # ]: 0 : bDragging ( sal_False )
80 : : {
81 [ # # ]: 0 : ImplCreateSvDrawStorage();
82 : 0 : }
83 : :
84 : : // ------------------------------------------------------------------------
85 : :
86 [ # # ][ # # ]: 0 : GalleryTheme::~GalleryTheme()
87 : : {
88 [ # # ]: 0 : ImplWrite();
89 : :
90 [ # # ]: 0 : for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
91 : : {
92 : 0 : GalleryObject* pEntry = aObjectList[ i ];
93 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
94 [ # # ][ # # ]: 0 : delete pEntry;
95 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
96 : : }
97 : 0 : aObjectList.clear();
98 [ # # ]: 0 : }
99 : :
100 : : // ------------------------------------------------------------------------
101 : :
102 : 0 : void GalleryTheme::ImplCreateSvDrawStorage()
103 : : {
104 [ # # ][ # # ]: 0 : aSvDrawStorageRef = new SvStorage( sal_False, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), pThm->IsReadOnly() ? STREAM_READ : STREAM_STD_READWRITE );
[ # # ][ # # ]
[ # # ][ # # ]
105 : : // #i50423# ReadOnly may not been set though the file can't be written (because of security reasons)
106 [ # # ][ # # ]: 0 : if ( ( aSvDrawStorageRef->GetError() != ERRCODE_NONE ) && !pThm->IsReadOnly() )
[ # # ]
107 [ # # ][ # # ]: 0 : aSvDrawStorageRef = new SvStorage( sal_False, GetSdvURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
[ # # ][ # # ]
[ # # ]
108 : 0 : }
109 : :
110 : : // ------------------------------------------------------------------------
111 : :
112 : 0 : sal_Bool GalleryTheme::ImplWriteSgaObject( const SgaObject& rObj, size_t nPos, GalleryObject* pExistentEntry )
113 : : {
114 [ # # ][ # # ]: 0 : SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
[ # # ]
115 : 0 : sal_Bool bRet = sal_False;
116 : :
117 [ # # ]: 0 : if( pOStm )
118 : : {
119 : 0 : const sal_uInt32 nOffset = pOStm->Seek( STREAM_SEEK_TO_END );
120 : :
121 : 0 : rObj.WriteData( *pOStm, m_aDestDir );
122 : :
123 [ # # ]: 0 : if( !pOStm->GetError() )
124 : : {
125 : : GalleryObject* pEntry;
126 : :
127 [ # # ]: 0 : if( !pExistentEntry )
128 : : {
129 [ # # ][ # # ]: 0 : pEntry = new GalleryObject;
130 [ # # ]: 0 : if ( nPos < aObjectList.size() )
131 : : {
132 : 0 : GalleryObjectList::iterator it = aObjectList.begin();
133 [ # # ]: 0 : ::std::advance( it, nPos );
134 [ # # ]: 0 : aObjectList.insert( it, pEntry );
135 : : }
136 : : else
137 [ # # ]: 0 : aObjectList.push_back( pEntry );
138 : : }
139 : : else
140 : 0 : pEntry = pExistentEntry;
141 : :
142 [ # # ]: 0 : pEntry->aURL = rObj.GetURL();
143 : 0 : pEntry->nOffset = nOffset;
144 [ # # ]: 0 : pEntry->eObjKind = rObj.GetObjKind();
145 : 0 : bRet = sal_True;
146 : : }
147 : :
148 [ # # ]: 0 : delete pOStm;
149 : : }
150 : :
151 : 0 : return bRet;
152 : : }
153 : :
154 : : // ------------------------------------------------------------------------
155 : :
156 : 0 : SgaObject* GalleryTheme::ImplReadSgaObject( GalleryObject* pEntry )
157 : : {
158 : 0 : SgaObject* pSgaObj = NULL;
159 : :
160 [ # # ]: 0 : if( pEntry )
161 : : {
162 [ # # ][ # # ]: 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( GetSdgURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
[ # # ]
163 : :
164 [ # # ]: 0 : if( pIStm )
165 : : {
166 : : sal_uInt32 nInventor;
167 : :
168 : : // Ueberpruefen, ob das File ein gueltiges SGA-File ist
169 [ # # ]: 0 : pIStm->Seek( pEntry->nOffset );
170 [ # # ]: 0 : *pIStm >> nInventor;
171 : :
172 [ # # ]: 0 : if( nInventor == COMPAT_FORMAT( 'S', 'G', 'A', '3' ) )
173 : : {
174 [ # # ]: 0 : pIStm->Seek( pEntry->nOffset );
175 : :
176 [ # # # # : 0 : switch( pEntry->eObjKind )
# # ]
177 : : {
178 [ # # ][ # # ]: 0 : case( SGA_OBJ_BMP ): pSgaObj = new SgaObjectBmp(); break;
179 [ # # ][ # # ]: 0 : case( SGA_OBJ_ANIM ): pSgaObj = new SgaObjectAnim(); break;
180 [ # # ][ # # ]: 0 : case( SGA_OBJ_INET ): pSgaObj = new SgaObjectINet(); break;
181 [ # # ][ # # ]: 0 : case( SGA_OBJ_SVDRAW ): pSgaObj = new SgaObjectSvDraw(); break;
182 [ # # ][ # # ]: 0 : case( SGA_OBJ_SOUND ): pSgaObj = new SgaObjectSound(); break;
183 : :
184 : : default:
185 : 0 : break;
186 : : }
187 : :
188 [ # # ]: 0 : if( pSgaObj )
189 : : {
190 [ # # ]: 0 : *pIStm >> *pSgaObj;
191 [ # # ]: 0 : pSgaObj->ImplUpdateURL( pEntry->aURL );
192 : : }
193 : : }
194 : :
195 [ # # ][ # # ]: 0 : delete pIStm;
196 : : }
197 : : }
198 : :
199 : 0 : return pSgaObj;
200 : : }
201 : :
202 : : // ------------------------------------------------------------------------
203 : :
204 : 0 : void GalleryTheme::ImplWrite()
205 : : {
206 [ # # ]: 0 : if( IsModified() )
207 : : {
208 [ # # ]: 0 : INetURLObject aPathURL( GetThmURL() );
209 : :
210 [ # # ]: 0 : aPathURL.removeSegment();
211 [ # # ]: 0 : aPathURL.removeFinalSlash();
212 : :
213 : : DBG_ASSERT( aPathURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
214 : :
215 [ # # ][ # # ]: 0 : if( FileExists( aPathURL ) || CreateDir( aPathURL ) )
[ # # ][ # # ]
[ # # ]
216 : : {
217 : : #ifdef UNX
218 [ # # ][ # # ]: 0 : SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_COPY_ON_SYMLINK | STREAM_TRUNC );
[ # # ][ # # ]
219 : : #else
220 : : SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( GetThmURL().GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
221 : : #endif
222 : :
223 [ # # ]: 0 : if( pOStm )
224 : : {
225 [ # # ]: 0 : *pOStm << *this;
226 [ # # ][ # # ]: 0 : delete pOStm;
227 : : }
228 : :
229 : 0 : ImplSetModified( sal_False );
230 [ # # ]: 0 : }
231 : : }
232 : 0 : }
233 : :
234 : : // ------------------------------------------------------------------------
235 : :
236 : 0 : const GalleryObject* GalleryTheme::ImplGetGalleryObject( const INetURLObject& rURL )
237 : : {
238 [ # # ]: 0 : for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
239 [ # # ]: 0 : if ( aObjectList[ i ]->aURL == rURL )
240 : 0 : return aObjectList[ i ];
241 : 0 : return NULL;
242 : : }
243 : :
244 : : // ------------------------------------------------------------------------
245 : :
246 : 0 : INetURLObject GalleryTheme::ImplGetURL( const GalleryObject* pObject ) const
247 : : {
248 : 0 : INetURLObject aURL;
249 : :
250 [ # # ]: 0 : if( pObject )
251 [ # # ]: 0 : aURL = pObject->aURL;
252 : :
253 : 0 : return aURL;
254 : : }
255 : :
256 : : // ------------------------------------------------------------------------
257 : :
258 : 0 : INetURLObject GalleryTheme::ImplCreateUniqueURL( SgaObjKind eObjKind, sal_uIntPtr nFormat )
259 : : {
260 [ # # ]: 0 : INetURLObject aDir( GetParent()->GetUserURL() );
261 [ # # ]: 0 : INetURLObject aInfoFileURL( GetParent()->GetUserURL() );
262 [ # # ]: 0 : INetURLObject aNewURL;
263 : 0 : sal_uInt32 nNextNumber = 1999;
264 : 0 : sal_Char const* pExt = NULL;
265 : : sal_Bool bExists;
266 : :
267 [ # # ][ # # ]: 0 : aDir.Append( String( RTL_CONSTASCII_USTRINGPARAM( "dragdrop" ) ) );
[ # # ][ # # ]
268 [ # # ]: 0 : CreateDir( aDir );
269 : :
270 [ # # ][ # # ]: 0 : aInfoFileURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( "sdddndx1" ) ) );
[ # # ][ # # ]
271 : :
272 : : // read next possible number
273 [ # # ][ # # ]: 0 : if( FileExists( aInfoFileURL ) )
274 : : {
275 [ # # ][ # # ]: 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
[ # # ][ # # ]
276 : :
277 [ # # ]: 0 : if( pIStm )
278 : : {
279 [ # # ]: 0 : *pIStm >> nNextNumber;
280 [ # # ][ # # ]: 0 : delete pIStm;
281 : : }
282 : : }
283 : :
284 : : // create extension
285 [ # # ]: 0 : if( nFormat )
286 : : {
287 [ # # # # : 0 : switch( nFormat )
# # # # #
# # ]
288 : : {
289 : 0 : case( CVT_BMP ): pExt = ".bmp"; break;
290 : 0 : case( CVT_GIF ): pExt = ".gif"; break;
291 : 0 : case( CVT_JPG ): pExt = ".jpg"; break;
292 : 0 : case( CVT_MET ): pExt = ".met"; break;
293 : 0 : case( CVT_PCT ): pExt = ".pct"; break;
294 : 0 : case( CVT_PNG ): pExt = ".png"; break;
295 : 0 : case( CVT_SVM ): pExt = ".svm"; break;
296 : 0 : case( CVT_TIF ): pExt = ".tif"; break;
297 : 0 : case( CVT_WMF ): pExt = ".wmf"; break;
298 : 0 : case( CVT_EMF ): pExt = ".emf"; break;
299 : :
300 : : default:
301 : 0 : pExt = ".grf";
302 : 0 : break;
303 : : }
304 : : }
305 : :
306 [ # # ]: 0 : do
307 : : {
308 : : // get URL
309 [ # # ]: 0 : if( SGA_OBJ_SVDRAW == eObjKind )
310 : : {
311 [ # # ]: 0 : String aFileName( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/dd" ) );
312 [ # # ][ # # ]: 0 : aNewURL = INetURLObject( aFileName += String::CreateFromInt32( ++nNextNumber % 99999999 ), INET_PROT_PRIV_SOFFICE );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
313 : :
314 : 0 : bExists = sal_False;
315 : :
316 [ # # ]: 0 : for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
317 [ # # ][ # # ]: 0 : if ( aObjectList[ i ]->aURL == aNewURL )
318 : : {
319 : 0 : bExists = sal_True;
320 : 0 : break;
321 [ # # ]: 0 : }
322 : : }
323 : : else
324 : : {
325 [ # # ]: 0 : String aFileName( RTL_CONSTASCII_USTRINGPARAM( "dd" ) );
326 : :
327 [ # # ][ # # ]: 0 : aFileName += String::CreateFromInt32( ++nNextNumber % 999999 );
[ # # ]
328 [ # # ][ # # ]: 0 : aFileName += String( pExt, RTL_TEXTENCODING_ASCII_US );
[ # # ]
329 : :
330 [ # # ]: 0 : aNewURL = aDir;
331 [ # # ][ # # ]: 0 : aNewURL.Append( aFileName );
332 : :
333 [ # # ][ # # ]: 0 : bExists = FileExists( aNewURL );
334 : : }
335 : : }
336 : : while( bExists );
337 : :
338 : : // write updated number
339 [ # # ][ # # ]: 0 : SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aInfoFileURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE );
[ # # ][ # # ]
340 : :
341 [ # # ]: 0 : if( pOStm )
342 : : {
343 [ # # ]: 0 : *pOStm << nNextNumber;
344 [ # # ][ # # ]: 0 : delete pOStm;
345 : : }
346 : :
347 [ # # ][ # # ]: 0 : return aNewURL;
348 : : }
349 : :
350 : : // ------------------------------------------------------------------------
351 : :
352 : 0 : void GalleryTheme::ImplBroadcast( sal_uIntPtr nUpdatePos )
353 : : {
354 [ # # ]: 0 : if( !IsBroadcasterLocked() )
355 : : {
356 [ # # ][ # # ]: 0 : if( GetObjectCount() && ( nUpdatePos >= GetObjectCount() ) )
[ # # ]
357 : 0 : nUpdatePos = GetObjectCount() - 1;
358 : :
359 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_THEME_UPDATEVIEW, GetName(), nUpdatePos ) );
[ # # ]
360 : : }
361 : 0 : }
362 : :
363 : : // ------------------------------------------------------------------------
364 : :
365 : 0 : sal_Bool GalleryTheme::UnlockTheme()
366 : : {
367 : : DBG_ASSERT( mnThemeLockCount, "Theme is not locked" );
368 : :
369 : 0 : sal_Bool bRet = sal_False;
370 : :
371 [ # # ]: 0 : if( mnThemeLockCount )
372 : : {
373 : 0 : --mnThemeLockCount;
374 : 0 : bRet = sal_True;
375 : : }
376 : :
377 : 0 : return bRet;
378 : : }
379 : :
380 : : // ------------------------------------------------------------------------
381 : :
382 : 0 : void GalleryTheme::UnlockBroadcaster( sal_uIntPtr nUpdatePos )
383 : : {
384 : : DBG_ASSERT( mnBroadcasterLockCount, "Broadcaster is not locked" );
385 : :
386 [ # # ][ # # ]: 0 : if( mnBroadcasterLockCount && !--mnBroadcasterLockCount )
[ # # ]
387 : 0 : ImplBroadcast( nUpdatePos );
388 : 0 : }
389 : :
390 : : // ------------------------------------------------------------------------
391 : :
392 : 0 : bool GalleryTheme::InsertObject( const SgaObject& rObj, sal_uIntPtr nInsertPos )
393 : : {
394 : 0 : sal_Bool bRet = sal_False;
395 : :
396 [ # # ]: 0 : if( rObj.IsValid() )
397 : : {
398 : 0 : GalleryObject* pFoundEntry = NULL;
399 : 0 : size_t iFoundPos = 0;
400 [ # # ]: 0 : for ( size_t n = aObjectList.size(); iFoundPos < n; ++iFoundPos )
401 : : {
402 [ # # ]: 0 : if ( aObjectList[ iFoundPos ]->aURL == rObj.GetURL() )
403 : : {
404 : 0 : pFoundEntry = aObjectList[ iFoundPos ];
405 : 0 : break;
406 : : }
407 : : }
408 : :
409 [ # # ]: 0 : if( pFoundEntry )
410 : : {
411 [ # # ]: 0 : GalleryObject aNewEntry;
412 : :
413 : : // update title of new object if neccessary
414 [ # # ][ # # ]: 0 : if( !rObj.GetTitle().Len() )
[ # # ]
415 : : {
416 [ # # ]: 0 : SgaObject* pOldObj = ImplReadSgaObject( pFoundEntry );
417 : :
418 [ # # ]: 0 : if( pOldObj )
419 : : {
420 [ # # ][ # # ]: 0 : ( (SgaObject&) rObj ).SetTitle( pOldObj->GetTitle() );
[ # # ]
421 [ # # ][ # # ]: 0 : delete pOldObj;
422 : : }
423 : : }
424 [ # # ][ # # ]: 0 : else if( rObj.GetTitle() == String( RTL_CONSTASCII_USTRINGPARAM( "__<empty>__" ) ) )
[ # # ][ # # ]
[ # # ][ # # ]
425 [ # # ][ # # ]: 0 : ( (SgaObject&) rObj ).SetTitle( String() );
[ # # ]
426 : :
427 [ # # ]: 0 : ImplWriteSgaObject( rObj, nInsertPos, &aNewEntry );
428 [ # # ]: 0 : pFoundEntry->nOffset = aNewEntry.nOffset;
429 : : }
430 : : else
431 : 0 : ImplWriteSgaObject( rObj, nInsertPos, NULL );
432 : :
433 : 0 : ImplSetModified( bRet = sal_True );
434 [ # # ]: 0 : ImplBroadcast( pFoundEntry ? iFoundPos : nInsertPos );
435 : : }
436 : :
437 : 0 : return bRet;
438 : : }
439 : :
440 : : // ------------------------------------------------------------------------
441 : :
442 : 0 : SgaObject* GalleryTheme::AcquireObject( size_t nPos )
443 : : {
444 : 0 : return ImplReadSgaObject( aObjectList[ nPos ] );
445 : : }
446 : :
447 : : // ------------------------------------------------------------------------
448 : :
449 : 0 : void GalleryTheme::ReleaseObject( SgaObject* pObject )
450 : : {
451 [ # # ]: 0 : delete pObject;
452 : 0 : }
453 : :
454 : : // ------------------------------------------------------------------------
455 : :
456 : 0 : bool GalleryTheme::RemoveObject( size_t nPos )
457 : : {
458 : 0 : GalleryObject* pEntry = NULL;
459 [ # # ]: 0 : if ( nPos < aObjectList.size() )
460 : : {
461 : 0 : GalleryObjectList::iterator it = aObjectList.begin();
462 [ # # ]: 0 : ::std::advance( it, nPos );
463 : 0 : pEntry = *it;
464 [ # # ]: 0 : aObjectList.erase( it );
465 : : }
466 : :
467 [ # # ]: 0 : if( aObjectList.empty() )
468 : 0 : KillFile( GetSdgURL() );
469 : :
470 [ # # ]: 0 : if( pEntry )
471 : : {
472 [ # # ]: 0 : if( SGA_OBJ_SVDRAW == pEntry->eObjKind )
473 [ # # ][ # # ]: 0 : aSvDrawStorageRef->Remove( pEntry->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
[ # # ]
474 : :
475 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
[ # # ]
476 [ # # ]: 0 : delete pEntry;
477 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
[ # # ]
478 : :
479 : 0 : ImplSetModified( sal_True );
480 : 0 : ImplBroadcast( nPos );
481 : : }
482 : :
483 : 0 : return( pEntry != NULL );
484 : : }
485 : :
486 : : // ------------------------------------------------------------------------
487 : :
488 : 0 : bool GalleryTheme::ChangeObjectPos( size_t nOldPos, size_t nNewPos )
489 : : {
490 : 0 : sal_Bool bRet = sal_False;
491 : :
492 [ # # # # ]: 0 : if( nOldPos != nNewPos
[ # # ]
493 : 0 : && nOldPos < aObjectList.size()
494 : : )
495 : : {
496 : 0 : GalleryObject* pEntry = aObjectList[ nOldPos ];
497 : :
498 : 0 : GalleryObjectList::iterator it = aObjectList.begin();
499 [ # # ]: 0 : ::std::advance( it, nNewPos );
500 [ # # ]: 0 : aObjectList.insert( it, pEntry );
501 : :
502 [ # # ]: 0 : if( nNewPos < nOldPos ) nOldPos++;
503 : :
504 : 0 : it = aObjectList.begin();
505 [ # # ]: 0 : ::std::advance( it, nOldPos );
506 [ # # ]: 0 : aObjectList.erase( it );
507 : :
508 : 0 : ImplSetModified( bRet = sal_True );
509 [ # # ][ # # ]: 0 : ImplBroadcast( ( nNewPos < nOldPos ) ? nNewPos : ( nNewPos - 1 ) );
510 : : }
511 : :
512 : 0 : return bRet;
513 : : }
514 : :
515 : : // ------------------------------------------------------------------------
516 : :
517 : 0 : void GalleryTheme::Actualize( const Link& rActualizeLink, GalleryProgress* pProgress )
518 : : {
519 [ # # ]: 0 : if( !IsReadOnly() )
520 : : {
521 [ # # ]: 0 : Graphic aGraphic;
522 [ # # ]: 0 : String aFormat;
523 : : GalleryObject* pEntry;
524 : 0 : const size_t nCount = aObjectList.size();
525 : :
526 : 0 : LockBroadcaster();
527 : 0 : bAbortActualize = sal_False;
528 : :
529 : : // LoeschFlag zuruecksetzen
530 [ # # ]: 0 : for (size_t i = 0; i < nCount; i++)
531 : 0 : aObjectList[ i ]->bDummy = sal_False;
532 : :
533 [ # # ][ # # ]: 0 : for(size_t i = 0; ( i < nCount ) && !bAbortActualize; i++)
[ # # ]
534 : : {
535 [ # # ]: 0 : if( pProgress )
536 [ # # ]: 0 : pProgress->Update( i, nCount - 1 );
537 : :
538 : 0 : pEntry = aObjectList[ i ];
539 : :
540 [ # # ]: 0 : const INetURLObject aURL( pEntry->aURL );
541 : :
542 [ # # ]: 0 : rActualizeLink.Call( (void*) &aURL );
543 : :
544 : : // SvDraw-Objekte werden spaeter aktualisiert
545 [ # # ]: 0 : if( pEntry->eObjKind != SGA_OBJ_SVDRAW )
546 : : {
547 : : // Hier muss noch etwas eingebaut werden,
548 : : // das Files auf den ensprechenden Eintrag matched
549 : : // Grafiken als Grafik-Objekte in die Gallery aufnehmen
550 [ # # ]: 0 : if( pEntry->eObjKind == SGA_OBJ_SOUND )
551 : : {
552 [ # # ]: 0 : SgaObjectSound aObjSound( aURL );
553 [ # # ][ # # ]: 0 : if( !InsertObject( aObjSound ) )
554 [ # # ]: 0 : pEntry->bDummy = sal_True;
555 : : }
556 : : else
557 : : {
558 [ # # ]: 0 : aGraphic.Clear();
559 : :
560 [ # # ][ # # ]: 0 : if ( GalleryGraphicImport( aURL, aGraphic, aFormat ) )
561 : : {
562 : : SgaObject* pNewObj;
563 : :
564 [ # # ]: 0 : if ( SGA_OBJ_INET == pEntry->eObjKind )
565 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, aURL, aFormat );
566 [ # # ][ # # ]: 0 : else if ( aGraphic.IsAnimated() )
567 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, aURL, aFormat );
568 : : else
569 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, aURL, aFormat );
570 : :
571 [ # # ][ # # ]: 0 : if( !InsertObject( *pNewObj ) )
572 : 0 : pEntry->bDummy = sal_True;
573 : :
574 [ # # ][ # # ]: 0 : delete pNewObj;
575 : : }
576 : : else
577 : 0 : pEntry->bDummy = sal_True; // Loesch-Flag setzen
578 : : }
579 : : }
580 : : else
581 : : {
582 [ # # ]: 0 : if ( aSvDrawStorageRef.Is() )
583 : : {
584 [ # # ]: 0 : const String aStmName( GetSvDrawStreamNameFromURL( pEntry->aURL ) );
585 [ # # ]: 0 : SvStorageStreamRef pIStm = aSvDrawStorageRef->OpenSotStream( aStmName, STREAM_READ );
586 : :
587 [ # # ][ # # ]: 0 : if( pIStm && !pIStm->GetError() )
[ # # ]
588 : : {
589 [ # # ]: 0 : pIStm->SetBufferSize( 16384 );
590 : :
591 [ # # ]: 0 : SgaObjectSvDraw aNewObj( *pIStm, pEntry->aURL );
592 : :
593 [ # # ][ # # ]: 0 : if( !InsertObject( aNewObj ) )
594 : 0 : pEntry->bDummy = sal_True;
595 : :
596 [ # # ][ # # ]: 0 : pIStm->SetBufferSize( 0L );
597 [ # # ][ # # ]: 0 : }
598 : : }
599 : : }
600 [ # # ]: 0 : }
601 : :
602 : : // remove all entries with set flag
603 [ # # ]: 0 : for ( size_t i = 0; i < aObjectList.size(); )
604 : : {
605 : 0 : pEntry = aObjectList[ i ];
606 [ # # ]: 0 : if( pEntry->bDummy )
607 : : {
608 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pEntry ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
609 : 0 : GalleryObjectList::iterator it = aObjectList.begin();
610 [ # # ]: 0 : ::std::advance( it, i );
611 [ # # ]: 0 : aObjectList.erase( it );
612 [ # # ][ # # ]: 0 : delete pEntry;
613 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uLong >( pEntry ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
614 : : }
615 : 0 : else ++i;
616 : : }
617 : :
618 : : // update theme
619 [ # # ]: 0 : ::utl::TempFile aTmp;
620 [ # # ][ # # ]: 0 : INetURLObject aInURL( GetSdgURL() );
621 [ # # ][ # # ]: 0 : INetURLObject aTmpURL( aTmp.GetURL() );
[ # # ][ # # ]
622 : :
623 : : DBG_ASSERT( aInURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
624 : : DBG_ASSERT( aTmpURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
625 : :
626 [ # # ][ # # ]: 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( aInURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
[ # # ][ # # ]
627 [ # # ][ # # ]: 0 : SvStream* pTmpStm = ::utl::UcbStreamHelper::CreateStream( aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
[ # # ][ # # ]
628 : :
629 [ # # ][ # # ]: 0 : if( pIStm && pTmpStm )
630 : : {
631 [ # # ]: 0 : for ( size_t i = 0, n = aObjectList.size(); i < n; ++i )
632 : : {
633 : 0 : pEntry = aObjectList[ i ];
634 : : SgaObject* pObj;
635 : :
636 [ # # # # : 0 : switch( pEntry->eObjKind )
# # ]
637 : : {
638 [ # # ][ # # ]: 0 : case( SGA_OBJ_BMP ): pObj = new SgaObjectBmp(); break;
639 [ # # ][ # # ]: 0 : case( SGA_OBJ_ANIM ): pObj = new SgaObjectAnim(); break;
640 [ # # ][ # # ]: 0 : case( SGA_OBJ_INET ): pObj = new SgaObjectINet(); break;
641 [ # # ][ # # ]: 0 : case( SGA_OBJ_SVDRAW ): pObj = new SgaObjectSvDraw(); break;
642 [ # # ][ # # ]: 0 : case (SGA_OBJ_SOUND): pObj = new SgaObjectSound(); break;
643 : :
644 : : default:
645 : 0 : pObj = NULL;
646 : 0 : break;
647 : : }
648 : :
649 [ # # ]: 0 : if( pObj )
650 : : {
651 [ # # ]: 0 : pIStm->Seek( pEntry->nOffset );
652 [ # # ]: 0 : *pIStm >> *pObj;
653 : 0 : pEntry->nOffset = pTmpStm->Tell();
654 [ # # ]: 0 : *pTmpStm << *pObj;
655 [ # # ][ # # ]: 0 : delete pObj;
656 : : }
657 : : }
658 : : }
659 : : else
660 : : {
661 : : OSL_FAIL( "File(s) could not be opened" );
662 : : }
663 : :
664 [ # # ][ # # ]: 0 : delete pIStm;
665 [ # # ][ # # ]: 0 : delete pTmpStm;
666 : :
667 [ # # ]: 0 : CopyFile( aTmpURL, aInURL );
668 [ # # ]: 0 : KillFile( aTmpURL );
669 : :
670 : 0 : sal_uIntPtr nStorErr = 0;
671 : :
672 : : {
673 [ # # ][ # # ]: 0 : SvStorageRef aTempStorageRef( new SvStorage( sal_False, aTmpURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_STD_READWRITE ) );
[ # # ][ # # ]
[ # # ]
674 [ # # ]: 0 : aSvDrawStorageRef->CopyTo( aTempStorageRef );
675 [ # # ]: 0 : nStorErr = aSvDrawStorageRef->GetError();
676 : : }
677 : :
678 [ # # ]: 0 : if( !nStorErr )
679 : : {
680 [ # # ]: 0 : aSvDrawStorageRef.Clear();
681 [ # # ]: 0 : CopyFile( aTmpURL, GetSdvURL() );
682 [ # # ]: 0 : ImplCreateSvDrawStorage();
683 : : }
684 : :
685 [ # # ]: 0 : KillFile( aTmpURL );
686 : 0 : ImplSetModified( sal_True );
687 [ # # ]: 0 : ImplWrite();
688 [ # # ][ # # ]: 0 : UnlockBroadcaster();
[ # # ][ # # ]
[ # # ][ # # ]
689 : : }
690 : 0 : }
691 : :
692 : : // ------------------------------------------------------------------------
693 : :
694 : 0 : GalleryThemeEntry* GalleryTheme::CreateThemeEntry( const INetURLObject& rURL, sal_Bool bReadOnly )
695 : : {
696 : : DBG_ASSERT( rURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
697 : :
698 : 0 : GalleryThemeEntry* pRet = NULL;
699 : :
700 [ # # ]: 0 : if( FileExists( rURL ) )
701 : : {
702 [ # # ][ # # ]: 0 : SvStream* pIStm = ::utl::UcbStreamHelper::CreateStream( rURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_READ );
[ # # ]
703 : :
704 [ # # ]: 0 : if( pIStm )
705 : : {
706 [ # # ]: 0 : String aThemeName;
707 : : sal_uInt16 nVersion;
708 : 0 : sal_Bool bThemeNameFromResource = sal_False;
709 : :
710 [ # # ]: 0 : *pIStm >> nVersion;
711 : :
712 [ # # ]: 0 : if( nVersion <= 0x00ff )
713 : : {
714 : 0 : sal_uInt32 nThemeId = 0;
715 : :
716 [ # # ]: 0 : rtl::OString aTmpStr = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(*pIStm);
717 [ # # ][ # # ]: 0 : aThemeName = rtl::OStringToOUString(aTmpStr, RTL_TEXTENCODING_UTF8);
718 : :
719 : : // Charakterkonvertierung durchfuehren
720 [ # # ]: 0 : if( nVersion >= 0x0004 )
721 : : {
722 : : sal_uInt32 nCount;
723 : : sal_uInt16 nTemp16;
724 : :
725 [ # # ][ # # ]: 0 : *pIStm >> nCount >> nTemp16;
726 [ # # ]: 0 : pIStm->Seek( STREAM_SEEK_TO_END );
727 : :
728 : : // pruefen, ob es sich um eine neuere Version handelt;
729 : : // daher um 520Bytes (8Bytes Kennung + 512Bytes Reserverpuffer ) zurueckspringen,
730 : : // falls dies ueberhaupt moeglich ist
731 [ # # ]: 0 : if( pIStm->Tell() >= 520 )
732 : : {
733 : : sal_uInt32 nId1, nId2;
734 : :
735 [ # # ]: 0 : pIStm->SeekRel( -520 );
736 [ # # ][ # # ]: 0 : *pIStm >> nId1 >> nId2;
737 : :
738 [ # # ][ # # ]: 0 : if( nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
739 : : nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
740 : : {
741 [ # # ][ # # ]: 0 : VersionCompat* pCompat = new VersionCompat( *pIStm, STREAM_READ );
742 : :
743 [ # # ]: 0 : *pIStm >> nThemeId;
744 : :
745 [ # # ]: 0 : if( pCompat->GetVersion() >= 2 )
746 : : {
747 [ # # ]: 0 : *pIStm >> bThemeNameFromResource;
748 : : }
749 : :
750 [ # # ][ # # ]: 0 : delete pCompat;
751 : : }
752 : : }
753 : : }
754 : :
755 [ # # ]: 0 : INetURLObject aPathURL( rURL );
756 : :
757 [ # # ]: 0 : aPathURL.removeSegment();
758 [ # # ]: 0 : aPathURL.removeFinalSlash();
759 : : pRet = new GalleryThemeEntry( aPathURL, aThemeName,
760 [ # # ][ # # ]: 0 : String(rURL.GetBase()).Copy( 2, 6 ).ToInt32(),
[ # # ][ # # ]
[ # # ][ # # ]
761 : : bReadOnly, sal_False, nThemeId,
762 [ # # ]: 0 : bThemeNameFromResource );
[ # # # # ]
763 : : }
764 : :
765 [ # # ][ # # ]: 0 : delete pIStm;
[ # # ]
766 : : }
767 : : }
768 : :
769 : 0 : return pRet;
770 : : }
771 : :
772 : : // -----------------------------------------------------------------------------
773 : :
774 : 0 : sal_Bool GalleryTheme::GetThumb( sal_uIntPtr nPos, Bitmap& rBmp, sal_Bool )
775 : : {
776 : 0 : SgaObject* pObj = AcquireObject( nPos );
777 : 0 : sal_Bool bRet = sal_False;
778 : :
779 [ # # ]: 0 : if( pObj )
780 : : {
781 [ # # ]: 0 : rBmp = pObj->GetThumbBmp();
782 : 0 : ReleaseObject( pObj );
783 : 0 : bRet = sal_True;
784 : : }
785 : :
786 : 0 : return bRet;
787 : : }
788 : :
789 : : // -----------------------------------------------------------------------------
790 : :
791 : 0 : sal_Bool GalleryTheme::GetGraphic( sal_uIntPtr nPos, Graphic& rGraphic, sal_Bool bProgress )
792 : : {
793 : 0 : const GalleryObject* pObject = ImplGetGalleryObject( nPos );
794 : 0 : sal_Bool bRet = sal_False;
795 : :
796 [ # # ]: 0 : if( pObject )
797 : : {
798 [ # # ]: 0 : const INetURLObject aURL( ImplGetURL( pObject ) );
799 : :
800 [ # # # # ]: 0 : switch( pObject->eObjKind )
801 : : {
802 : : case( SGA_OBJ_BMP ):
803 : : case( SGA_OBJ_ANIM ):
804 : : case( SGA_OBJ_INET ):
805 : : {
806 [ # # ]: 0 : String aFilterDummy;
807 [ # # ][ # # ]: 0 : bRet = ( GalleryGraphicImport( aURL, rGraphic, aFilterDummy, bProgress ) != SGA_IMPORT_NONE );
808 : : }
809 : 0 : break;
810 : :
811 : : case( SGA_OBJ_SVDRAW ):
812 : : {
813 [ # # ]: 0 : SvxGalleryDrawModel aModel;
814 : :
815 [ # # ]: 0 : if( aModel.GetModel() )
816 : : {
817 [ # # ][ # # ]: 0 : if( GetModel( nPos, *aModel.GetModel(), bProgress ) )
818 : : {
819 [ # # ]: 0 : ImageMap aIMap;
820 : :
821 [ # # ][ # # ]: 0 : if( CreateIMapGraphic( *aModel.GetModel(), rGraphic, aIMap ) )
822 : 0 : bRet = sal_True;
823 : : else
824 : : {
825 [ # # ]: 0 : VirtualDevice aVDev;
826 [ # # ][ # # ]: 0 : aVDev.SetMapMode( MapMode( MAP_100TH_MM ) );
[ # # ]
827 [ # # ]: 0 : FmFormView aView( aModel.GetModel(), &aVDev );
828 : :
829 [ # # ]: 0 : aView.hideMarkHandles();
830 [ # # ][ # # ]: 0 : aView.ShowSdrPage(aView.GetModel()->GetPage(0));
831 [ # # ]: 0 : aView.MarkAll();
832 [ # # ][ # # ]: 0 : rGraphic = aView.GetAllMarkedGraphic();
[ # # ]
833 [ # # ][ # # ]: 0 : bRet = sal_True;
834 [ # # ]: 0 : }
835 : : }
836 [ # # ]: 0 : }
837 : : }
838 : 0 : break;
839 : :
840 : : case( SGA_OBJ_SOUND ):
841 : : {
842 [ # # ]: 0 : SgaObject* pObj = AcquireObject( nPos );
843 : :
844 [ # # ]: 0 : if( pObj )
845 : : {
846 [ # # ]: 0 : Bitmap aBmp( pObj->GetThumbBmp() );
847 [ # # ]: 0 : aBmp.Replace( COL_LIGHTMAGENTA, COL_WHITE );
848 [ # # ][ # # ]: 0 : rGraphic = aBmp;
[ # # ]
849 [ # # ]: 0 : ReleaseObject( pObj );
850 [ # # ]: 0 : bRet = sal_True;
851 : : }
852 : : }
853 : 0 : break;
854 : :
855 : : default:
856 : 0 : break;
857 [ # # ]: 0 : }
858 : : }
859 : :
860 : 0 : return bRet;
861 : : }
862 : :
863 : : // -----------------------------------------------------------------------------
864 : :
865 : 0 : sal_Bool GalleryTheme::InsertGraphic( const Graphic& rGraphic, sal_uIntPtr nInsertPos )
866 : : {
867 : 0 : sal_Bool bRet = sal_False;
868 : :
869 [ # # ]: 0 : if( rGraphic.GetType() != GRAPHIC_NONE )
870 : : {
871 : 0 : sal_uIntPtr nExportFormat = CVT_UNKNOWN;
872 [ # # ]: 0 : const GfxLink aGfxLink( ( (Graphic&) rGraphic ).GetLink() );
873 : :
874 [ # # ][ # # ]: 0 : if( aGfxLink.GetDataSize() )
875 : : {
876 [ # # ][ # # : 0 : switch( aGfxLink.GetType() )
# # # # #
# # # ]
877 : : {
878 : 0 : case( GFX_LINK_TYPE_EPS_BUFFER ): nExportFormat = CVT_SVM; break;
879 : 0 : case( GFX_LINK_TYPE_NATIVE_GIF ): nExportFormat = CVT_GIF; break;
880 : 0 : case( GFX_LINK_TYPE_NATIVE_JPG ): nExportFormat = CVT_JPG; break;
881 : 0 : case( GFX_LINK_TYPE_NATIVE_PNG ): nExportFormat = CVT_PNG; break;
882 : 0 : case( GFX_LINK_TYPE_NATIVE_TIF ): nExportFormat = CVT_TIF; break;
883 : 0 : case( GFX_LINK_TYPE_NATIVE_WMF ): nExportFormat = CVT_WMF; break;
884 : 0 : case( GFX_LINK_TYPE_NATIVE_MET ): nExportFormat = CVT_MET; break;
885 : 0 : case( GFX_LINK_TYPE_NATIVE_PCT ): nExportFormat = CVT_PCT; break;
886 : 0 : case( GFX_LINK_TYPE_NATIVE_SVG ): nExportFormat = CVT_SVG; break;
887 : : default:
888 : 0 : break;
889 : : }
890 : : }
891 : : else
892 : : {
893 [ # # ][ # # ]: 0 : if( rGraphic.GetType() == GRAPHIC_BITMAP )
894 : : {
895 [ # # ][ # # ]: 0 : if( rGraphic.IsAnimated() )
896 : 0 : nExportFormat = CVT_GIF;
897 : : else
898 : 0 : nExportFormat = CVT_PNG;
899 : : }
900 : : else
901 : 0 : nExportFormat = CVT_SVM;
902 : : }
903 : :
904 [ # # ]: 0 : const INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_BMP, nExportFormat ) );
905 [ # # ][ # # ]: 0 : SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURL.GetMainURL( INetURLObject::NO_DECODE ), STREAM_WRITE | STREAM_TRUNC );
[ # # ][ # # ]
906 : :
907 [ # # ]: 0 : if( pOStm )
908 : : {
909 : 0 : pOStm->SetVersion( SOFFICE_FILEFORMAT_50 );
910 : :
911 [ # # ]: 0 : if( CVT_SVM == nExportFormat )
912 : : {
913 [ # # ][ # # ]: 0 : GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
914 : :
915 [ # # ]: 0 : aMtf.Write( *pOStm );
916 [ # # ]: 0 : bRet = ( pOStm->GetError() == ERRCODE_NONE );
917 : : }
918 : : else
919 : : {
920 [ # # ][ # # ]: 0 : if( aGfxLink.GetDataSize() && aGfxLink.GetData() )
[ # # ][ # # ]
[ # # ]
921 : : {
922 [ # # ][ # # ]: 0 : pOStm->Write( aGfxLink.GetData(), aGfxLink.GetDataSize() );
[ # # ]
923 : 0 : bRet = ( pOStm->GetError() == ERRCODE_NONE );
924 : : }
925 : : else
926 [ # # ]: 0 : bRet = ( GraphicConverter::Export( *pOStm, rGraphic, nExportFormat ) == ERRCODE_NONE );
927 : : }
928 : :
929 [ # # ][ # # ]: 0 : delete pOStm;
930 : : }
931 : :
932 [ # # ]: 0 : if( bRet )
933 : : {
934 [ # # ][ # # ]: 0 : const SgaObjectBmp aObjBmp( aURL.GetMainURL( INetURLObject::NO_DECODE ) );
[ # # ][ # # ]
935 [ # # ][ # # ]: 0 : InsertObject( aObjBmp, nInsertPos );
936 [ # # ][ # # ]: 0 : }
937 : : }
938 : :
939 : 0 : return bRet;
940 : : }
941 : :
942 : : // -----------------------------------------------------------------------------
943 : :
944 : 0 : sal_Bool GalleryTheme::GetModel( sal_uIntPtr nPos, SdrModel& rModel, sal_Bool )
945 : : {
946 : 0 : const GalleryObject* pObject = ImplGetGalleryObject( nPos );
947 : 0 : sal_Bool bRet = sal_False;
948 : :
949 [ # # ][ # # ]: 0 : if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
950 : : {
951 [ # # ]: 0 : const INetURLObject aURL( ImplGetURL( pObject ) );
952 [ # # ]: 0 : SvStorageRef xStor( GetSvDrawStorage() );
953 : :
954 [ # # ]: 0 : if( xStor.Is() )
955 : : {
956 [ # # ]: 0 : const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
957 [ # # ]: 0 : SvStorageStreamRef xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
958 : :
959 [ # # ][ # # ]: 0 : if( xIStm.Is() && !xIStm->GetError() )
[ # # ]
960 : : {
961 [ # # ]: 0 : xIStm->SetBufferSize( STREAMBUF_SIZE );
962 [ # # ]: 0 : bRet = GallerySvDrawImport( *xIStm, rModel );
963 [ # # ]: 0 : xIStm->SetBufferSize( 0L );
964 [ # # ][ # # ]: 0 : }
965 [ # # ][ # # ]: 0 : }
966 : : }
967 : :
968 : 0 : return bRet;
969 : : }
970 : :
971 : : // -----------------------------------------------------------------------------
972 : :
973 : 0 : sal_Bool GalleryTheme::InsertModel( const FmFormModel& rModel, sal_uIntPtr nInsertPos )
974 : : {
975 [ # # ]: 0 : INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
976 [ # # ]: 0 : SvStorageRef xStor( GetSvDrawStorage() );
977 : 0 : sal_Bool bRet = sal_False;
978 : :
979 [ # # ]: 0 : if( xStor.Is() )
980 : : {
981 [ # # ]: 0 : const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
982 [ # # ]: 0 : SvStorageStreamRef xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
983 : :
984 [ # # ][ # # ]: 0 : if( xOStm.Is() && !xOStm->GetError() )
[ # # ]
985 : : {
986 [ # # ]: 0 : SvMemoryStream aMemStm( 65535, 65535 );
987 : 0 : FmFormModel* pFormModel = (FmFormModel*) &rModel;
988 : :
989 [ # # ]: 0 : pFormModel->BurnInStyleSheetAttributes();
990 : :
991 : : {
992 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( aMemStm ) );
[ # # ]
993 : :
994 [ # # ]: 0 : if( xDocOut.is() )
995 [ # # ]: 0 : SvxDrawingLayerExport( pFormModel, xDocOut );
996 : : }
997 : :
998 [ # # ]: 0 : aMemStm.Seek( 0 );
999 : :
1000 [ # # ]: 0 : xOStm->SetBufferSize( 16348 );
1001 [ # # ]: 0 : GalleryCodec aCodec( *xOStm );
1002 [ # # ]: 0 : aCodec.Write( aMemStm );
1003 : :
1004 [ # # ]: 0 : if( !xOStm->GetError() )
1005 : : {
1006 [ # # ]: 0 : SgaObjectSvDraw aObjSvDraw( rModel, aURL );
1007 [ # # ][ # # ]: 0 : bRet = InsertObject( aObjSvDraw, nInsertPos );
1008 : : }
1009 : :
1010 [ # # ]: 0 : xOStm->SetBufferSize( 0L );
1011 [ # # ][ # # ]: 0 : xOStm->Commit();
[ # # ]
1012 [ # # ][ # # ]: 0 : }
1013 : : }
1014 : :
1015 [ # # ][ # # ]: 0 : return bRet;
1016 : : }
1017 : :
1018 : : // -----------------------------------------------------------------------------
1019 : :
1020 : 0 : sal_Bool GalleryTheme::GetModelStream( sal_uIntPtr nPos, SotStorageStreamRef& rxModelStream, sal_Bool )
1021 : : {
1022 : 0 : const GalleryObject* pObject = ImplGetGalleryObject( nPos );
1023 : 0 : sal_Bool bRet = sal_False;
1024 : :
1025 [ # # ][ # # ]: 0 : if( pObject && ( SGA_OBJ_SVDRAW == pObject->eObjKind ) )
1026 : : {
1027 [ # # ]: 0 : const INetURLObject aURL( ImplGetURL( pObject ) );
1028 [ # # ]: 0 : SvStorageRef xStor( GetSvDrawStorage() );
1029 : :
1030 [ # # ]: 0 : if( xStor.Is() )
1031 : : {
1032 [ # # ]: 0 : const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1033 [ # # ]: 0 : SvStorageStreamRef xIStm( xStor->OpenSotStream( aStmName, STREAM_READ ) );
1034 : :
1035 [ # # ][ # # ]: 0 : if( xIStm.Is() && !xIStm->GetError() )
[ # # ]
1036 : : {
1037 : 0 : sal_uInt32 nVersion = 0;
1038 : :
1039 [ # # ]: 0 : xIStm->SetBufferSize( 16348 );
1040 : :
1041 [ # # ][ # # ]: 0 : if( GalleryCodec::IsCoded( *xIStm, nVersion ) )
1042 : : {
1043 [ # # ]: 0 : SvxGalleryDrawModel aModel;
1044 : :
1045 [ # # ]: 0 : if( aModel.GetModel() )
1046 : : {
1047 [ # # ][ # # ]: 0 : if( GallerySvDrawImport( *xIStm, *aModel.GetModel() ) )
1048 : : {
1049 [ # # ]: 0 : aModel.GetModel()->BurnInStyleSheetAttributes();
1050 : :
1051 : : {
1052 [ # # ][ # # ]: 0 : uno::Reference< io::XOutputStream > xDocOut( new utl::OOutputStreamWrapper( *rxModelStream ) );
[ # # ]
1053 : :
1054 [ # # ][ # # ]: 0 : if( SvxDrawingLayerExport( aModel.GetModel(), xDocOut ) )
1055 [ # # ]: 0 : rxModelStream->Commit();
1056 : : }
1057 : : }
1058 : :
1059 : 0 : bRet = ( rxModelStream->GetError() == ERRCODE_NONE );
1060 [ # # ]: 0 : }
1061 : : }
1062 : :
1063 [ # # ]: 0 : xIStm->SetBufferSize( 0 );
1064 [ # # ][ # # ]: 0 : }
1065 [ # # ][ # # ]: 0 : }
1066 : : }
1067 : :
1068 : 0 : return bRet;
1069 : : }
1070 : :
1071 : : // -----------------------------------------------------------------------------
1072 : :
1073 : 0 : sal_Bool GalleryTheme::InsertModelStream( const SotStorageStreamRef& rxModelStream, sal_uIntPtr nInsertPos )
1074 : : {
1075 [ # # ]: 0 : INetURLObject aURL( ImplCreateUniqueURL( SGA_OBJ_SVDRAW ) );
1076 [ # # ]: 0 : SvStorageRef xStor( GetSvDrawStorage() );
1077 : 0 : sal_Bool bRet = sal_False;
1078 : :
1079 [ # # ]: 0 : if( xStor.Is() )
1080 : : {
1081 [ # # ]: 0 : const String aStmName( GetSvDrawStreamNameFromURL( aURL ) );
1082 [ # # ]: 0 : SvStorageStreamRef xOStm( xStor->OpenSotStream( aStmName, STREAM_WRITE | STREAM_TRUNC ) );
1083 : :
1084 [ # # ][ # # ]: 0 : if( xOStm.Is() && !xOStm->GetError() )
[ # # ]
1085 : : {
1086 [ # # ]: 0 : GalleryCodec aCodec( *xOStm );
1087 [ # # ]: 0 : SvMemoryStream aMemStm( 65535, 65535 );
1088 : :
1089 [ # # ]: 0 : xOStm->SetBufferSize( 16348 );
1090 [ # # ]: 0 : aCodec.Write( *rxModelStream );
1091 : :
1092 [ # # ]: 0 : if( !xOStm->GetError() )
1093 : : {
1094 [ # # ]: 0 : xOStm->Seek( 0 );
1095 [ # # ]: 0 : SgaObjectSvDraw aObjSvDraw( *xOStm, aURL );
1096 [ # # ][ # # ]: 0 : bRet = InsertObject( aObjSvDraw, nInsertPos );
1097 : : }
1098 : :
1099 [ # # ]: 0 : xOStm->SetBufferSize( 0L );
1100 [ # # ][ # # ]: 0 : xOStm->Commit();
[ # # ]
1101 [ # # ][ # # ]: 0 : }
1102 : : }
1103 : :
1104 [ # # ][ # # ]: 0 : return bRet;
1105 : : }
1106 : :
1107 : : // -----------------------------------------------------------------------------
1108 : :
1109 : 0 : sal_Bool GalleryTheme::GetURL( sal_uIntPtr nPos, INetURLObject& rURL, sal_Bool )
1110 : : {
1111 : 0 : const GalleryObject* pObject = ImplGetGalleryObject( nPos );
1112 : 0 : sal_Bool bRet = sal_False;
1113 : :
1114 [ # # ]: 0 : if( pObject )
1115 : : {
1116 [ # # ]: 0 : rURL = INetURLObject( ImplGetURL( pObject ) );
1117 : 0 : bRet = sal_True;
1118 : : }
1119 : :
1120 : 0 : return bRet;
1121 : : }
1122 : :
1123 : : // -----------------------------------------------------------------------------
1124 : :
1125 : 0 : sal_Bool GalleryTheme::InsertURL( const INetURLObject& rURL, sal_uIntPtr nInsertPos )
1126 : : {
1127 [ # # ]: 0 : Graphic aGraphic;
1128 [ # # ]: 0 : String aFormat;
1129 : 0 : SgaObject* pNewObj = NULL;
1130 [ # # ]: 0 : const sal_uInt16 nImportRet = GalleryGraphicImport( rURL, aGraphic, aFormat );
1131 : 0 : sal_Bool bRet = sal_False;
1132 : :
1133 [ # # ]: 0 : if( nImportRet != SGA_IMPORT_NONE )
1134 : : {
1135 [ # # ]: 0 : if ( SGA_IMPORT_INET == nImportRet )
1136 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectINet( aGraphic, rURL, aFormat );
1137 [ # # ][ # # ]: 0 : else if ( aGraphic.IsAnimated() )
1138 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectAnim( aGraphic, rURL, aFormat );
1139 : : else
1140 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectBmp( aGraphic, rURL, aFormat );
1141 : : }
1142 [ # # ][ # # ]: 0 : else if( ::avmedia::MediaWindow::isMediaURL( rURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) ) )
[ # # ]
1143 [ # # ][ # # ]: 0 : pNewObj = (SgaObject*) new SgaObjectSound( rURL );
1144 : :
1145 [ # # ][ # # ]: 0 : if( pNewObj && InsertObject( *pNewObj, nInsertPos ) )
[ # # ][ # # ]
1146 : 0 : bRet = sal_True;
1147 : :
1148 [ # # ][ # # ]: 0 : delete pNewObj;
1149 : :
1150 [ # # ][ # # ]: 0 : return bRet;
1151 : : }
1152 : :
1153 : : // -----------------------------------------------------------------------------
1154 : :
1155 : 0 : sal_Bool GalleryTheme::InsertFileOrDirURL( const INetURLObject& rFileOrDirURL, sal_uIntPtr nInsertPos )
1156 : : {
1157 [ # # ]: 0 : INetURLObject aURL;
1158 [ # # ]: 0 : ::std::vector< INetURLObject > aURLVector;
1159 : 0 : sal_Bool bRet = sal_False;
1160 : :
1161 : : try
1162 : : {
1163 [ # # ][ # # ]: 0 : ::ucbhelper::Content aCnt( rFileOrDirURL.GetMainURL( INetURLObject::NO_DECODE ), uno::Reference< ucb::XCommandEnvironment >() );
1164 : 0 : sal_Bool bFolder = false;
1165 : :
1166 [ # # ]: 0 : aCnt.getPropertyValue( OUString("IsFolder") ) >>= bFolder;
1167 : :
1168 [ # # ]: 0 : if( bFolder )
1169 : : {
1170 [ # # ]: 0 : uno::Sequence< OUString > aProps( 1 );
1171 [ # # ]: 0 : aProps.getArray()[ 0 ] = OUString("Url");
1172 [ # # ]: 0 : uno::Reference< sdbc::XResultSet > xResultSet( aCnt.createCursor( aProps, ::ucbhelper::INCLUDE_DOCUMENTS_ONLY ) );
1173 [ # # ]: 0 : uno::Reference< ucb::XContentAccess > xContentAccess( xResultSet, uno::UNO_QUERY );
1174 [ # # ]: 0 : if( xContentAccess.is() )
1175 : : {
1176 [ # # ][ # # ]: 0 : while( xResultSet->next() )
[ # # ]
1177 : : {
1178 [ # # ][ # # ]: 0 : aURL.SetSmartURL( xContentAccess->queryContentIdentifierString() );
[ # # ]
1179 [ # # ]: 0 : aURLVector.push_back( aURL );
1180 : : }
1181 [ # # ]: 0 : }
1182 : : }
1183 : : else
1184 [ # # ][ # # ]: 0 : aURLVector.push_back( rFileOrDirURL );
[ # # # # ]
1185 : : }
1186 [ # # ]: 0 : catch( const ucb::ContentCreationException& )
1187 : : {
1188 : : }
1189 [ # # ]: 0 : catch( const uno::RuntimeException& )
1190 : : {
1191 : : }
1192 [ # # ]: 0 : catch( const uno::Exception& )
1193 : : {
1194 : : }
1195 : :
1196 [ # # ][ # # ]: 0 : ::std::vector< INetURLObject >::const_iterator aIter( aURLVector.begin() ), aEnd( aURLVector.end() );
1197 : :
1198 [ # # ][ # # ]: 0 : while( aIter != aEnd )
1199 [ # # ][ # # ]: 0 : bRet = bRet || InsertURL( *aIter++, nInsertPos );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1200 : :
1201 [ # # ]: 0 : return bRet;
1202 : : }
1203 : :
1204 : : // -----------------------------------------------------------------------------
1205 : :
1206 : 0 : sal_Bool GalleryTheme::InsertTransferable( const uno::Reference< datatransfer::XTransferable >& rxTransferable, sal_uIntPtr nInsertPos )
1207 : : {
1208 : 0 : sal_Bool bRet = sal_False;
1209 : :
1210 [ # # ]: 0 : if( rxTransferable.is() )
1211 : : {
1212 [ # # ]: 0 : TransferableDataHelper aDataHelper( rxTransferable );
1213 : 0 : Graphic* pGraphic = NULL;
1214 : :
1215 [ # # ][ # # ]: 0 : if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_DRAWING ) )
1216 : : {
1217 : 0 : SotStorageStreamRef xModelStm;
1218 : :
1219 [ # # ][ # # ]: 0 : if( aDataHelper.GetSotStorageStream( SOT_FORMATSTR_ID_DRAWING, xModelStm ) )
1220 [ # # ][ # # ]: 0 : bRet = InsertModelStream( xModelStm, nInsertPos );
1221 : : }
1222 [ # # ][ # # ]: 0 : else if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) ||
[ # # ][ # # ]
1223 [ # # ]: 0 : aDataHelper.HasFormat( FORMAT_FILE ) )
1224 : : {
1225 [ # # ]: 0 : FileList aFileList;
1226 : :
1227 [ # # ][ # # ]: 0 : if( aDataHelper.HasFormat( SOT_FORMAT_FILE_LIST ) )
1228 [ # # ]: 0 : aDataHelper.GetFileList( SOT_FORMAT_FILE_LIST, aFileList );
1229 : : else
1230 : : {
1231 [ # # ]: 0 : String aFile;
1232 : :
1233 [ # # ]: 0 : aDataHelper.GetString( FORMAT_FILE, aFile );
1234 : :
1235 [ # # ]: 0 : if( aFile.Len() )
1236 [ # # ][ # # ]: 0 : aFileList.AppendFile( aFile );
1237 : : }
1238 : :
1239 [ # # ][ # # ]: 0 : for( sal_uInt32 i = 0, nCount = aFileList.Count(); i < nCount; ++i )
1240 : : {
1241 [ # # ]: 0 : const String aFile( aFileList.GetFile( i ) );
1242 [ # # ][ # # ]: 0 : INetURLObject aURL( aFile );
1243 : :
1244 [ # # ]: 0 : if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
1245 : : {
1246 : 0 : rtl::OUString aLocalURL;
1247 : :
1248 [ # # ][ # # ]: 0 : if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aLocalURL ) )
[ # # ]
1249 [ # # ][ # # ]: 0 : aURL = INetURLObject( aLocalURL );
[ # # ]
1250 : : }
1251 : :
1252 [ # # ]: 0 : if( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1253 [ # # ]: 0 : bRet = InsertFileOrDirURL( aURL, nInsertPos );
1254 [ # # ][ # # ]: 0 : }
[ # # ]
1255 : : }
1256 : : else
1257 : : {
1258 [ # # ]: 0 : Graphic aGraphic;
1259 : 0 : sal_uIntPtr nFormat = 0;
1260 : :
1261 [ # # ][ # # ]: 0 : if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVXB ) )
1262 : 0 : nFormat = SOT_FORMATSTR_ID_SVXB;
1263 [ # # ][ # # ]: 0 : else if( aDataHelper.HasFormat( FORMAT_GDIMETAFILE ) )
1264 : 0 : nFormat = FORMAT_GDIMETAFILE;
1265 [ # # ][ # # ]: 0 : else if( aDataHelper.HasFormat( FORMAT_BITMAP ) )
1266 : 0 : nFormat = FORMAT_BITMAP;
1267 : :
1268 [ # # ][ # # ]: 0 : if( nFormat && aDataHelper.GetGraphic( nFormat, aGraphic ) )
[ # # ][ # # ]
1269 [ # # ][ # # ]: 0 : pGraphic = new Graphic( aGraphic );
[ # # ]
1270 : : }
1271 : :
1272 [ # # ]: 0 : if( pGraphic )
1273 : : {
1274 : 0 : bRet = sal_False;
1275 : :
1276 [ # # ][ # # ]: 0 : if( aDataHelper.HasFormat( SOT_FORMATSTR_ID_SVIM ) )
1277 : : {
1278 : :
1279 [ # # ]: 0 : ImageMap aImageMap;
1280 : :
1281 : : // according to KA we don't need a BaseURL here
1282 [ # # ][ # # ]: 0 : if( aDataHelper.GetImageMap( SOT_FORMATSTR_ID_SVIM, aImageMap ) )
1283 : : {
1284 [ # # ]: 0 : SvxGalleryDrawModel aModel;
1285 : :
1286 [ # # ]: 0 : if( aModel.GetModel() )
1287 : : {
1288 [ # # ]: 0 : SgaUserDataFactory aFactory;
1289 : :
1290 [ # # ]: 0 : SdrPage* pPage = aModel.GetModel()->GetPage(0);
1291 [ # # ][ # # ]: 0 : SdrGrafObj* pGrafObj = new SdrGrafObj( *pGraphic );
1292 : :
1293 [ # # ][ # # ]: 0 : pGrafObj->AppendUserData( new SgaIMapInfo( aImageMap ) );
[ # # ]
1294 [ # # ]: 0 : pPage->InsertObject( pGrafObj );
1295 [ # # ][ # # ]: 0 : bRet = InsertModel( *aModel.GetModel(), nInsertPos );
1296 [ # # ]: 0 : }
1297 [ # # ]: 0 : }
1298 : : }
1299 : :
1300 [ # # ]: 0 : if( !bRet )
1301 [ # # ]: 0 : bRet = InsertGraphic( *pGraphic, nInsertPos );
1302 : :
1303 [ # # ][ # # ]: 0 : delete pGraphic;
1304 [ # # ]: 0 : }
1305 : : }
1306 : :
1307 : 0 : return bRet;
1308 : : }
1309 : :
1310 : : // -----------------------------------------------------------------------------
1311 : :
1312 : 0 : void GalleryTheme::CopyToClipboard( Window* pWindow, sal_uIntPtr nPos )
1313 : : {
1314 [ # # ]: 0 : GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, false );
1315 : 0 : pTransferable->CopyToClipboard( pWindow );
1316 : 0 : }
1317 : :
1318 : : // -----------------------------------------------------------------------------
1319 : :
1320 : 0 : void GalleryTheme::StartDrag( Window* pWindow, sal_uIntPtr nPos )
1321 : : {
1322 [ # # ]: 0 : GalleryTransferable* pTransferable = new GalleryTransferable( this, nPos, true );
1323 : 0 : pTransferable->StartDrag( pWindow, DND_ACTION_COPY | DND_ACTION_LINK );
1324 : 0 : }
1325 : :
1326 : : // -----------------------------------------------------------------------------
1327 : :
1328 : 0 : SvStream& GalleryTheme::WriteData( SvStream& rOStm ) const
1329 : : {
1330 [ # # ]: 0 : const INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
1331 [ # # ]: 0 : const INetURLObject aRelURL2( GetParent()->GetUserURL() );
1332 [ # # ][ # # ]: 0 : INetURLObject aNewURL, aTempURL;
1333 : 0 : sal_uInt32 nCount = GetObjectCount();
1334 : : sal_Bool bRel;
1335 : :
1336 [ # # ]: 0 : rOStm << (sal_uInt16) 0x0004;
1337 [ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, GetRealName(), RTL_TEXTENCODING_UTF8);
1338 [ # # ][ # # ]: 0 : rOStm << nCount << (sal_uInt16) osl_getThreadTextEncoding();
[ # # ]
1339 : :
1340 [ # # ]: 0 : for( sal_uInt32 i = 0; i < nCount; i++ )
1341 : : {
1342 [ # # ]: 0 : const GalleryObject* pObj = ImplGetGalleryObject( i );
1343 [ # # ]: 0 : String aPath;
1344 : :
1345 [ # # ]: 0 : if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1346 : : {
1347 [ # # ][ # # ]: 0 : aPath = GetSvDrawStreamNameFromURL( pObj->aURL );
[ # # ]
1348 : 0 : bRel = sal_False;
1349 : : }
1350 : : else
1351 : : {
1352 [ # # ][ # # ]: 0 : aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1353 [ # # ][ # # ]: 0 : bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL1.GetMainURL( INetURLObject::NO_DECODE ) ));
[ # # ][ # # ]
[ # # ][ # # ]
1354 : :
1355 [ # # ][ # # ]: 0 : if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # ]
1356 : : {
1357 [ # # ][ # # ]: 0 : aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1358 [ # # ][ # # ]: 0 : aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL1.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
[ # # ]
1359 : : }
1360 : : else
1361 : : {
1362 [ # # ][ # # ]: 0 : aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1363 [ # # ][ # # ]: 0 : bRel = ( ( aPath.Erase( sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) ) ) == String(aRelURL2.GetMainURL( INetURLObject::NO_DECODE ) ));
[ # # ][ # # ]
[ # # ][ # # ]
1364 : :
1365 [ # # ][ # # ]: 0 : if( bRel && ( pObj->aURL.GetMainURL( INetURLObject::NO_DECODE ).getLength() > ( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() + 1 ) ) )
[ # # ][ # # ]
[ # # ][ # #
# # # # ]
[ # # ]
1366 : : {
1367 [ # # ][ # # ]: 0 : aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1368 [ # # ][ # # ]: 0 : aPath = aPath.Erase( 0, sal::static_int_cast< xub_StrLen >( aRelURL2.GetMainURL( INetURLObject::NO_DECODE ).getLength() ) );
[ # # ]
1369 : : }
1370 : : else
1371 [ # # ][ # # ]: 0 : aPath = pObj->aURL.GetMainURL( INetURLObject::NO_DECODE );
1372 : : }
1373 : : }
1374 : :
1375 [ # # ][ # # ]: 0 : aPath.SearchAndReplace(m_aDestDir, String());
[ # # ]
1376 [ # # ]: 0 : rOStm << bRel;
1377 [ # # ][ # # ]: 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rOStm, aPath, RTL_TEXTENCODING_UTF8);
1378 [ # # ][ # # ]: 0 : rOStm << pObj->nOffset << (sal_uInt16) pObj->eObjKind;
1379 [ # # ]: 0 : }
1380 : :
1381 : : // neuerdings wird ein 512-Byte-Reservepuffer gechrieben;
1382 : : // um diesen zu erkennen werden zwei sal_uIntPtr-Ids geschrieben
1383 [ # # ][ # # ]: 0 : rOStm << COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) << COMPAT_FORMAT( 'E', 'S', 'R', 'V' );
1384 : :
1385 : 0 : const long nReservePos = rOStm.Tell();
1386 [ # # ][ # # ]: 0 : VersionCompat* pCompat = new VersionCompat( rOStm, STREAM_WRITE, 2 );
1387 : :
1388 [ # # ][ # # ]: 0 : rOStm << (sal_uInt32) GetId() << IsThemeNameFromResource(); // ab Version 2
[ # # ]
1389 : :
1390 [ # # ][ # # ]: 0 : delete pCompat;
1391 : :
1392 : : // Rest des Puffers auffuellen
1393 : 0 : const long nRest = Max( 512L - ( (long) rOStm.Tell() - nReservePos ), 0L );
1394 : :
1395 [ # # ]: 0 : if( nRest )
1396 : : {
1397 [ # # ]: 0 : char* pReserve = new char[ nRest ];
1398 : 0 : memset( pReserve, 0, nRest );
1399 [ # # ]: 0 : rOStm.Write( pReserve, nRest );
1400 [ # # ]: 0 : delete[] pReserve;
1401 : : }
1402 : :
1403 [ # # ][ # # ]: 0 : return rOStm;
[ # # ][ # # ]
1404 : : }
1405 : :
1406 : : // ------------------------------------------------------------------------
1407 : :
1408 : 0 : SvStream& GalleryTheme::ReadData( SvStream& rIStm )
1409 : : {
1410 : : sal_uInt32 nCount;
1411 : : sal_uInt16 nVersion;
1412 [ # # ]: 0 : String aThemeName;
1413 : : rtl_TextEncoding nTextEncoding;
1414 : :
1415 [ # # ]: 0 : rIStm >> nVersion;
1416 [ # # ]: 0 : rtl::OString aTmpStr = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm);
1417 [ # # ]: 0 : rIStm >> nCount;
1418 : :
1419 [ # # ]: 0 : if( nVersion >= 0x0004 )
1420 : : {
1421 : : sal_uInt16 nTmp16;
1422 [ # # ]: 0 : rIStm >> nTmp16;
1423 : 0 : nTextEncoding = (rtl_TextEncoding) nTmp16;
1424 : : }
1425 : : else
1426 : 0 : nTextEncoding = RTL_TEXTENCODING_UTF8;
1427 : :
1428 [ # # ][ # # ]: 0 : aThemeName = rtl::OStringToOUString(aTmpStr, nTextEncoding);
1429 : :
1430 [ # # ]: 0 : if( nCount <= ( 1L << 14 ) )
1431 : : {
1432 : : GalleryObject* pObj;
1433 [ # # ]: 0 : INetURLObject aRelURL1( GetParent()->GetRelativeURL() );
1434 [ # # ]: 0 : INetURLObject aRelURL2( GetParent()->GetUserURL() );
1435 : : sal_uInt32 nId1, nId2;
1436 : : sal_Bool bRel;
1437 : :
1438 [ # # ]: 0 : for( size_t i = 0, n = aObjectList.size(); i < n; ++i )
1439 : : {
1440 : 0 : pObj = aObjectList[ i ];
1441 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_CLOSE_OBJECT, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
1442 [ # # ][ # # ]: 0 : delete pObj;
1443 [ # # ][ # # ]: 0 : Broadcast( GalleryHint( GALLERY_HINT_OBJECT_REMOVED, GetName(), reinterpret_cast< sal_uIntPtr >( pObj ) ) );
[ # # ][ # # ]
[ # # ][ # # ]
1444 : : }
1445 : 0 : aObjectList.clear();
1446 : :
1447 [ # # ]: 0 : for( sal_uInt32 i = 0; i < nCount; i++ )
1448 : : {
1449 [ # # ][ # # ]: 0 : pObj = new GalleryObject;
1450 : :
1451 [ # # ]: 0 : String aFileName;
1452 [ # # ]: 0 : String aPath;
1453 : : sal_uInt16 nTemp;
1454 : :
1455 [ # # ]: 0 : rIStm >> bRel;
1456 [ # # ]: 0 : rtl::OString aTempFileName = read_lenPrefixed_uInt8s_ToOString<sal_uInt16>(rIStm);
1457 [ # # ]: 0 : rIStm >> pObj->nOffset;
1458 [ # # ]: 0 : rIStm >> nTemp; pObj->eObjKind = (SgaObjKind) nTemp;
1459 : :
1460 [ # # ][ # # ]: 0 : aFileName = rtl::OStringToOUString(aTempFileName, osl_getThreadTextEncoding());
[ # # ]
1461 : :
1462 [ # # ]: 0 : if( bRel )
1463 : : {
1464 [ # # ]: 0 : aFileName.SearchAndReplaceAll( '\\', '/' );
1465 [ # # ][ # # ]: 0 : aPath = aRelURL1.GetMainURL( INetURLObject::NO_DECODE );
1466 : :
1467 [ # # ]: 0 : if( aFileName.GetChar( 0 ) != '/' )
1468 [ # # ]: 0 : aPath += '/';
1469 : :
1470 [ # # ]: 0 : aPath += aFileName;
1471 : :
1472 [ # # ][ # # ]: 0 : pObj->aURL = INetURLObject( aPath );
[ # # ][ # # ]
1473 : :
1474 [ # # ][ # # ]: 0 : if( !FileExists( pObj->aURL ) )
1475 : : {
1476 [ # # ][ # # ]: 0 : aPath = aRelURL2.GetMainURL( INetURLObject::NO_DECODE );
1477 : :
1478 [ # # ]: 0 : if( aFileName.GetChar( 0 ) != '/' )
1479 [ # # ]: 0 : aPath += '/';
1480 : :
1481 [ # # ]: 0 : aPath += aFileName;
1482 : :
1483 : : // assign this URL, even in the case it is not valid (#94482)
1484 [ # # ][ # # ]: 0 : pObj->aURL = INetURLObject( aPath );
[ # # ][ # # ]
1485 : : }
1486 : : }
1487 : : else
1488 : : {
1489 [ # # ]: 0 : if( SGA_OBJ_SVDRAW == pObj->eObjKind )
1490 : : {
1491 [ # # ][ # # ]: 0 : const static String aBaseURLStr( RTL_CONSTASCII_USTRINGPARAM( "gallery/svdraw/" ) );
[ # # ][ # # ]
1492 : :
1493 [ # # ]: 0 : String aDummyURL( aBaseURLStr );
1494 [ # # ][ # # ]: 0 : pObj->aURL = INetURLObject( aDummyURL += aFileName, INET_PROT_PRIV_SOFFICE );
[ # # ][ # # ]
[ # # ][ # # ]
1495 : : }
1496 : : else
1497 : : {
1498 : 0 : rtl::OUString aLocalURL;
1499 : :
1500 [ # # ][ # # ]: 0 : pObj->aURL = INetURLObject( aFileName );
[ # # ][ # # ]
1501 : :
1502 [ # # ][ # # ]: 0 : if( ( pObj->aURL.GetProtocol() == INET_PROT_NOT_VALID ) &&
[ # # ]
1503 [ # # ][ # # ]: 0 : ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFileName, aLocalURL ) )
[ # # ][ # # ]
1504 : : {
1505 [ # # ][ # # ]: 0 : pObj->aURL = INetURLObject( aLocalURL );
[ # # ]
1506 : 0 : }
1507 : : }
1508 : : }
1509 : :
1510 [ # # ]: 0 : aObjectList.push_back( pObj );
1511 [ # # ][ # # ]: 0 : }
1512 : :
1513 [ # # ][ # # ]: 0 : rIStm >> nId1 >> nId2;
1514 : :
1515 : : // in neueren Versionen befindet sich am Ende ein 512-Byte-Reservepuffer;
1516 : : // die Daten befinden sich am Anfang dieses Puffers und
1517 : : // sind durch eine VersionCompat geklammert
1518 [ # # ][ # # ]: 0 : if( !rIStm.IsEof() &&
[ # # ][ # # ]
1519 : : nId1 == COMPAT_FORMAT( 'G', 'A', 'L', 'R' ) &&
1520 : : nId2 == COMPAT_FORMAT( 'E', 'S', 'R', 'V' ) )
1521 : : {
1522 [ # # ][ # # ]: 0 : VersionCompat* pCompat = new VersionCompat( rIStm, STREAM_READ );
1523 : : sal_uInt32 nTemp32;
1524 : 0 : sal_Bool bThemeNameFromResource = sal_False;
1525 : :
1526 [ # # ]: 0 : rIStm >> nTemp32;
1527 : :
1528 [ # # ]: 0 : if( pCompat->GetVersion() >= 2 )
1529 : : {
1530 [ # # ]: 0 : rIStm >> bThemeNameFromResource;
1531 : : }
1532 : :
1533 [ # # ]: 0 : SetId( nTemp32, bThemeNameFromResource );
1534 [ # # ][ # # ]: 0 : delete pCompat;
1535 [ # # ][ # # ]: 0 : }
1536 : : }
1537 : : else
1538 [ # # ]: 0 : rIStm.SetError( SVSTREAM_READ_ERROR );
1539 : :
1540 : 0 : ImplSetModified( sal_False );
1541 : :
1542 [ # # ]: 0 : return rIStm;
1543 : : }
1544 : :
1545 : : // ------------------------------------------------------------------------
1546 : :
1547 : 0 : SvStream& operator<<( SvStream& rOut, const GalleryTheme& rTheme )
1548 : : {
1549 : 0 : return rTheme.WriteData( rOut );
1550 : : }
1551 : :
1552 : : // ------------------------------------------------------------------------
1553 : :
1554 : 0 : SvStream& operator>>( SvStream& rIn, GalleryTheme& rTheme )
1555 : : {
1556 : 0 : return rTheme.ReadData( rIn );
1557 : : }
1558 : :
1559 : 0 : void GalleryTheme::ImplSetModified( sal_Bool bModified )
1560 : 0 : { pThm->SetModified( bModified ); }
1561 : :
1562 : 0 : const rtl::OUString& GalleryTheme::GetRealName() const { return pThm->GetThemeName(); }
1563 : 0 : const INetURLObject& GalleryTheme::GetThmURL() const { return pThm->GetThmURL(); }
1564 : 0 : const INetURLObject& GalleryTheme::GetSdgURL() const { return pThm->GetSdgURL(); }
1565 : 0 : const INetURLObject& GalleryTheme::GetSdvURL() const { return pThm->GetSdvURL(); }
1566 : 0 : sal_uInt32 GalleryTheme::GetId() const { return pThm->GetId(); }
1567 : 0 : void GalleryTheme::SetId( sal_uInt32 nNewId, sal_Bool bResetThemeName ) { pThm->SetId( nNewId, bResetThemeName ); }
1568 : 0 : sal_Bool GalleryTheme::IsThemeNameFromResource() const { return pThm->IsNameFromResource(); }
1569 : 0 : sal_Bool GalleryTheme::IsReadOnly() const { return pThm->IsReadOnly(); }
1570 : 0 : sal_Bool GalleryTheme::IsDefault() const { return pThm->IsDefault(); }
1571 : 0 : sal_Bool GalleryTheme::IsModified() const { return pThm->IsModified(); }
1572 : 0 : const rtl::OUString& GalleryTheme::GetName() const { return pThm->GetThemeName(); }
1573 : :
1574 : 0 : void GalleryTheme::InsertAllThemes( ListBox& rListBox )
1575 : : {
1576 [ # # ]: 0 : for( sal_uInt16 i = RID_GALLERYSTR_THEME_FIRST; i <= RID_GALLERYSTR_THEME_LAST; i++ )
1577 [ # # ][ # # ]: 0 : rListBox.InsertEntry(GAL_RESSTR(i));
[ # # ][ # # ]
1578 : 0 : }
1579 : :
1580 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|