1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: galexpl.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svtools/pathoptions.hxx>
35 #include <sfx2/viewfrm.hxx>
36 #include "gallery1.hxx"
37 #include "galtheme.hxx"
38 #include "galbrws.hxx"
39 #include "gallery.hxx"
45 static SfxListener aLockListener
;
47 // -------------------
48 // - GalleryExplorer -
49 // -------------------
51 Gallery
* GalleryExplorer::ImplGetGallery()
53 static Gallery
* pGallery
= NULL
;
55 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
58 pGallery
= Gallery::GetGalleryInstance();
63 // ------------------------------------------------------------------------
65 GalleryExplorer
* GalleryExplorer::GetGallery()
67 static GalleryExplorer
* pThis
= NULL
;
69 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
71 // only create a dummy object which can be accessed
73 pThis
= new GalleryExplorer
;
78 // ------------------------------------------------------------------------
80 INetURLObject
GalleryExplorer::GetURL() const
82 return GALLERYBROWSER()->GetURL();
85 String
GalleryExplorer::GetFilterName() const
87 return GALLERYBROWSER()->GetFilterName();
90 // ------------------------------------------------------------------------
92 Graphic
GalleryExplorer::GetGraphic() const
94 return GALLERYBROWSER()->GetGraphic();
97 // ------------------------------------------------------------------------
99 BOOL
GalleryExplorer::GetVCDrawModel( FmFormModel
& rModel
) const
101 return GALLERYBROWSER()->GetVCDrawModel( rModel
);
104 // ------------------------------------------------------------------------
106 BOOL
GalleryExplorer::IsLinkage() const
108 return GALLERYBROWSER()->IsLinkage();
111 // ------------------------------------------------------------------------
113 BOOL
GalleryExplorer::FillThemeList( List
& rThemeList
)
115 Gallery
* pGal
= ImplGetGallery();
119 for( ULONG i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
121 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
123 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
124 rThemeList
.Insert( new String( pEntry
->GetThemeName() ), LIST_APPEND
);
128 return( rThemeList
.Count() > 0 );
131 // ------------------------------------------------------------------------
133 BOOL
GalleryExplorer::FillObjList( const String
& rThemeName
, List
& rObjList
)
135 Gallery
* pGal
= ImplGetGallery();
139 SfxListener aListener
;
140 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
144 for( ULONG i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
145 rObjList
.Insert( new String( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::NO_DECODE
) ), LIST_APPEND
);
147 pGal
->ReleaseTheme( pTheme
, aListener
);
151 return( rObjList
.Count() > 0 );
154 // ------------------------------------------------------------------------
156 BOOL
GalleryExplorer::FillObjList( ULONG nThemeId
, List
& rObjList
)
158 Gallery
* pGal
= ImplGetGallery();
159 return( pGal
? FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
) : FALSE
);
162 // ------------------------------------------------------------------------
164 sal_Bool
GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< rtl::OUString
>& rList
)
166 Gallery
* pGal
= ImplGetGallery();
169 SfxListener aListener
;
170 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
174 for( ULONG i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
176 SgaObject
* pObj
= pTheme
->AcquireObject( i
);
179 rtl::OUString
aTitle( pObj
->GetTitle() );
180 rList
.push_back( aTitle
);
181 pTheme
->ReleaseObject( pObj
);
184 pGal
->ReleaseTheme( pTheme
, aListener
);
187 return( rList
.size() > 0 );
190 // ------------------------------------------------------------------------
192 BOOL
GalleryExplorer::InsertURL( const String
& rThemeName
, const String
& rURL
)
194 return InsertURL( rThemeName
, rURL
, SGA_FORMAT_ALL
);
197 // ------------------------------------------------------------------------
199 BOOL
GalleryExplorer::InsertURL( ULONG nThemeId
, const String
& rURL
)
201 return InsertURL( nThemeId
, rURL
, SGA_FORMAT_ALL
);
204 // ------------------------------------------------------------------------
206 BOOL
GalleryExplorer::InsertURL( const String
& rThemeName
, const String
& rURL
, const ULONG
)
208 Gallery
* pGal
= ImplGetGallery();
213 SfxListener aListener
;
214 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
218 INetURLObject
aURL( rURL
);
219 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
220 bRet
= pTheme
->InsertURL( aURL
);
221 pGal
->ReleaseTheme( pTheme
, aListener
);
228 // ------------------------------------------------------------------------
230 BOOL
GalleryExplorer::InsertURL( ULONG nThemeId
, const String
& rURL
, const ULONG nSgaFormat
)
232 Gallery
* pGal
= ImplGetGallery();
233 return( pGal
? InsertURL( pGal
->GetThemeName( nThemeId
), rURL
, nSgaFormat
) : FALSE
);
236 // ------------------------------------------------------------------------
238 ULONG
GalleryExplorer::GetObjCount( const String
& rThemeName
)
240 Gallery
* pGal
= ImplGetGallery();
245 SfxListener aListener
;
246 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
250 nRet
= pTheme
->GetObjectCount();
251 pGal
->ReleaseTheme( pTheme
, aListener
);
258 // ------------------------------------------------------------------------
260 ULONG
GalleryExplorer::GetObjCount( ULONG nThemeId
)
262 Gallery
* pGal
= ImplGetGallery();
263 return( pGal
? GetObjCount( pGal
->GetThemeName( nThemeId
) ) : FALSE
);
266 // ------------------------------------------------------------------------
268 BOOL
GalleryExplorer::GetGraphicObj( const String
& rThemeName
, ULONG nPos
,
269 Graphic
* pGraphic
, Bitmap
* pThumb
,
272 Gallery
* pGal
= ImplGetGallery();
277 SfxListener aListener
;
278 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
283 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
, bProgress
);
286 bRet
= bRet
|| pTheme
->GetThumb( nPos
, *pThumb
, bProgress
);
288 pGal
->ReleaseTheme( pTheme
, aListener
);
295 // ------------------------------------------------------------------------
297 BOOL
GalleryExplorer::GetGraphicObj( ULONG nThemeId
, ULONG nPos
,
298 Graphic
* pGraphic
, Bitmap
* pThumb
,
301 Gallery
* pGal
= ImplGetGallery();
302 return( pGal
? GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
, pThumb
, bProgress
) : FALSE
);
305 // ------------------------------------------------------------------------
307 BOOL
GalleryExplorer::InsertGraphicObj( const String
& rThemeName
, const Graphic
& rGraphic
)
309 Gallery
* pGal
= ImplGetGallery();
314 SfxListener aListener
;
315 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
319 bRet
= pTheme
->InsertGraphic( rGraphic
);
320 pGal
->ReleaseTheme( pTheme
, aListener
);
327 // ------------------------------------------------------------------------
329 BOOL
GalleryExplorer::InsertGraphicObj( ULONG nThemeId
, const Graphic
& rGraphic
)
331 Gallery
* pGal
= ImplGetGallery();
332 return( pGal
? InsertGraphicObj( pGal
->GetThemeName( nThemeId
), rGraphic
) : FALSE
);
335 // ------------------------------------------------------------------------
337 ULONG
GalleryExplorer::GetSdrObjCount( const String
& rThemeName
)
339 Gallery
* pGal
= ImplGetGallery();
344 SfxListener aListener
;
345 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
349 for( ULONG i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
350 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
353 pGal
->ReleaseTheme( pTheme
, aListener
);
360 // ------------------------------------------------------------------------
362 ULONG
GalleryExplorer::GetSdrObjCount( ULONG nThemeId
)
364 Gallery
* pGal
= ImplGetGallery();
365 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : FALSE
);
368 // ------------------------------------------------------------------------
370 BOOL
GalleryExplorer::GetSdrObj( const String
& rThemeName
, ULONG nSdrModelPos
,
371 SdrModel
* pModel
, Bitmap
* pThumb
)
373 Gallery
* pGal
= ImplGetGallery();
378 SfxListener aListener
;
379 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
383 for( ULONG i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
385 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
387 if( nActPos
++ == nSdrModelPos
)
390 bRet
= bRet
|| pTheme
->GetModel( i
, *pModel
, FALSE
);
393 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
398 pGal
->ReleaseTheme( pTheme
, aListener
);
405 // ------------------------------------------------------------------------
407 BOOL
GalleryExplorer::GetSdrObj( ULONG nThemeId
, ULONG nSdrModelPos
,
408 SdrModel
* pModel
, Bitmap
* pThumb
)
410 Gallery
* pGal
= ImplGetGallery();
411 return( pGal
? GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
) : FALSE
);
414 // ------------------------------------------------------------------------
416 BOOL
GalleryExplorer::InsertSdrObj( const String
& rThemeName
, FmFormModel
& rModel
)
418 Gallery
* pGal
= ImplGetGallery();
423 SfxListener aListener
;
424 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
428 bRet
= pTheme
->InsertModel( rModel
);
429 pGal
->ReleaseTheme( pTheme
, aListener
);
436 // ------------------------------------------------------------------------
438 BOOL
GalleryExplorer::InsertSdrObj( ULONG nThemeId
, FmFormModel
& rModel
)
440 Gallery
* pGal
= ImplGetGallery();
441 return( pGal
? InsertSdrObj( pGal
->GetThemeName( nThemeId
), rModel
) : FALSE
);
444 // -----------------------------------------------------------------------------
446 BOOL
GalleryExplorer::BeginLocking( const String
& rThemeName
)
448 Gallery
* pGal
= ImplGetGallery();
453 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aLockListener
);
465 // -----------------------------------------------------------------------------
467 BOOL
GalleryExplorer::BeginLocking( ULONG nThemeId
)
469 Gallery
* pGal
= ImplGetGallery();
470 return( pGal
? BeginLocking( pGal
->GetThemeName( nThemeId
) ) : FALSE
);
473 // -----------------------------------------------------------------------------
475 BOOL
GalleryExplorer::EndLocking( const String
& rThemeName
)
477 Gallery
* pGal
= ImplGetGallery();
482 SfxListener aListener
;
483 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
487 const BOOL bReleaseLockedTheme
= pTheme
->UnlockTheme();
489 // release acquired theme
490 pGal
->ReleaseTheme( pTheme
, aListener
);
492 if( bReleaseLockedTheme
)
494 // release locked theme
495 pGal
->ReleaseTheme( pTheme
, aLockListener
);
504 // -----------------------------------------------------------------------------
506 BOOL
GalleryExplorer::EndLocking( ULONG nThemeId
)
508 Gallery
* pGal
= ImplGetGallery();
509 return( pGal
? EndLocking( pGal
->GetThemeName( nThemeId
) ) : FALSE
);
512 // -----------------------------------------------------------------------------
514 BOOL
GalleryExplorer::DrawCentered( OutputDevice
* pOut
, const FmFormModel
& rModel
)
516 return SgaObjectSvDraw::DrawCentered( pOut
, rModel
);