1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
30 #include <unotools/pathoptions.hxx>
31 #include <rtl/instance.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include "svx/gallery1.hxx"
34 #include "svx/galtheme.hxx"
35 #include "svx/galbrws.hxx"
36 #include "svx/gallery.hxx"
41 class theLockListener
: public rtl::Static
< SfxListener
, theLockListener
> {};
44 // -------------------
45 // - GalleryExplorer -
46 // -------------------
48 Gallery
* GalleryExplorer::ImplGetGallery()
50 static Gallery
* pGallery
= NULL
;
52 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
55 pGallery
= Gallery::GetGalleryInstance();
60 // ------------------------------------------------------------------------
62 GalleryExplorer
* GalleryExplorer::GetGallery()
64 static GalleryExplorer
* pThis
= NULL
;
66 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
68 // only create a dummy object which can be accessed
70 pThis
= new GalleryExplorer
;
75 // ------------------------------------------------------------------------
77 INetURLObject
GalleryExplorer::GetURL() const
79 return GALLERYBROWSER()->GetURL();
82 String
GalleryExplorer::GetFilterName() const
84 return GALLERYBROWSER()->GetFilterName();
87 // ------------------------------------------------------------------------
89 Graphic
GalleryExplorer::GetGraphic() const
91 return GALLERYBROWSER()->GetGraphic();
94 // ------------------------------------------------------------------------
96 sal_Bool
GalleryExplorer::IsLinkage() const
98 return GALLERYBROWSER()->IsLinkage();
101 // ------------------------------------------------------------------------
103 bool GalleryExplorer::FillThemeList( std::vector
<String
>& rThemeList
)
105 Gallery
* pGal
= ImplGetGallery();
109 for( sal_uIntPtr i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
111 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
113 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
114 rThemeList
.push_back(pEntry
->GetThemeName());
118 return !rThemeList
.empty();
121 // ------------------------------------------------------------------------
123 sal_Bool
GalleryExplorer::FillObjList( const String
& rThemeName
, std::vector
<String
> &rObjList
)
125 Gallery
* pGal
= ImplGetGallery();
129 SfxListener aListener
;
130 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
134 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
135 rObjList
.push_back( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::NO_DECODE
) );
137 pGal
->ReleaseTheme( pTheme
, aListener
);
141 return !rObjList
.empty();
144 // ------------------------------------------------------------------------
146 sal_Bool
GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<String
> &rObjList
)
148 Gallery
* pGal
= ImplGetGallery();
153 return FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
);
156 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<rtl::OUString
> &rObjList
)
158 std::vector
<String
> aObjList
;
159 if (!FillObjList(nThemeId
, aObjList
))
162 // Convert UniString to rtl::OUString.
163 std::vector
<rtl::OUString
> aList
;
164 aList
.reserve(aObjList
.size());
165 std::vector
<String
>::const_iterator it
= aObjList
.begin(), itEnd
= aObjList
.end();
166 for (; it
!= itEnd
; ++it
)
167 aList
.push_back(*it
);
169 rObjList
.swap(aList
);
173 // ------------------------------------------------------------------------
175 sal_Bool
GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< rtl::OUString
>& rList
)
177 Gallery
* pGal
= ImplGetGallery();
180 SfxListener aListener
;
181 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
185 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
187 SgaObject
* pObj
= pTheme
->AcquireObject( i
);
190 rtl::OUString
aTitle( pObj
->GetTitle() );
191 rList
.push_back( aTitle
);
192 pTheme
->ReleaseObject( pObj
);
195 pGal
->ReleaseTheme( pTheme
, aListener
);
198 return !rList
.empty();
201 // ------------------------------------------------------------------------
203 sal_Bool
GalleryExplorer::InsertURL( const String
& rThemeName
, const String
& rURL
)
205 return InsertURL( rThemeName
, rURL
, SGA_FORMAT_ALL
);
208 // ------------------------------------------------------------------------
210 sal_Bool
GalleryExplorer::InsertURL( sal_uIntPtr nThemeId
, const String
& rURL
)
212 return InsertURL( nThemeId
, rURL
, SGA_FORMAT_ALL
);
215 // ------------------------------------------------------------------------
217 sal_Bool
GalleryExplorer::InsertURL( const String
& rThemeName
, const String
& rURL
, const sal_uIntPtr
)
219 Gallery
* pGal
= ImplGetGallery();
220 sal_Bool bRet
= sal_False
;
224 SfxListener aListener
;
225 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
229 INetURLObject
aURL( rURL
);
230 DBG_ASSERT( aURL
.GetProtocol() != INET_PROT_NOT_VALID
, "invalid URL" );
231 bRet
= pTheme
->InsertURL( aURL
);
232 pGal
->ReleaseTheme( pTheme
, aListener
);
239 // ------------------------------------------------------------------------
241 sal_Bool
GalleryExplorer::InsertURL( sal_uIntPtr nThemeId
, const String
& rURL
, const sal_uIntPtr nSgaFormat
)
243 Gallery
* pGal
= ImplGetGallery();
244 return( pGal
? InsertURL( pGal
->GetThemeName( nThemeId
), rURL
, nSgaFormat
) : sal_False
);
247 // ------------------------------------------------------------------------
249 sal_Bool
GalleryExplorer::GetGraphicObj( const String
& rThemeName
, sal_uIntPtr nPos
,
250 Graphic
* pGraphic
, Bitmap
* pThumb
,
253 Gallery
* pGal
= ImplGetGallery();
254 sal_Bool bRet
= sal_False
;
258 SfxListener aListener
;
259 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
264 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
, bProgress
);
267 bRet
= bRet
|| pTheme
->GetThumb( nPos
, *pThumb
, bProgress
);
269 pGal
->ReleaseTheme( pTheme
, aListener
);
276 // ------------------------------------------------------------------------
278 sal_Bool
GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId
, sal_uIntPtr nPos
,
279 Graphic
* pGraphic
, Bitmap
* pThumb
,
282 Gallery
* pGal
= ImplGetGallery();
283 return( pGal
? GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
, pThumb
, bProgress
) : sal_False
);
286 // ------------------------------------------------------------------------
288 sal_uIntPtr
GalleryExplorer::GetSdrObjCount( const String
& rThemeName
)
290 Gallery
* pGal
= ImplGetGallery();
291 sal_uIntPtr nRet
= 0;
295 SfxListener aListener
;
296 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
300 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
301 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
304 pGal
->ReleaseTheme( pTheme
, aListener
);
311 // ------------------------------------------------------------------------
313 sal_uIntPtr
GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId
)
315 Gallery
* pGal
= ImplGetGallery();
316 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : sal_False
);
319 // ------------------------------------------------------------------------
321 sal_Bool
GalleryExplorer::GetSdrObj( const String
& rThemeName
, sal_uIntPtr nSdrModelPos
,
322 SdrModel
* pModel
, Bitmap
* pThumb
)
324 Gallery
* pGal
= ImplGetGallery();
325 sal_Bool bRet
= sal_False
;
329 SfxListener aListener
;
330 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
334 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
336 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
338 if( nActPos
++ == nSdrModelPos
)
341 bRet
= bRet
|| pTheme
->GetModel( i
, *pModel
, sal_False
);
344 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
349 pGal
->ReleaseTheme( pTheme
, aListener
);
356 // ------------------------------------------------------------------------
358 sal_Bool
GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId
, sal_uIntPtr nSdrModelPos
,
359 SdrModel
* pModel
, Bitmap
* pThumb
)
361 Gallery
* pGal
= ImplGetGallery();
362 return( pGal
? GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
) : sal_False
);
365 // -----------------------------------------------------------------------------
367 sal_Bool
GalleryExplorer::BeginLocking( const String
& rThemeName
)
369 Gallery
* pGal
= ImplGetGallery();
370 sal_Bool bRet
= sal_False
;
374 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener::get() );
386 // -----------------------------------------------------------------------------
388 sal_Bool
GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId
)
390 Gallery
* pGal
= ImplGetGallery();
391 return( pGal
? BeginLocking( pGal
->GetThemeName( nThemeId
) ) : sal_False
);
394 // -----------------------------------------------------------------------------
396 sal_Bool
GalleryExplorer::EndLocking( const String
& rThemeName
)
398 Gallery
* pGal
= ImplGetGallery();
399 sal_Bool bRet
= sal_False
;
403 SfxListener aListener
;
404 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
408 const sal_Bool bReleaseLockedTheme
= pTheme
->UnlockTheme();
410 // release acquired theme
411 pGal
->ReleaseTheme( pTheme
, aListener
);
413 if( bReleaseLockedTheme
)
415 // release locked theme
416 pGal
->ReleaseTheme( pTheme
, theLockListener::get() );
425 // -----------------------------------------------------------------------------
427 sal_Bool
GalleryExplorer::EndLocking( sal_uIntPtr nThemeId
)
429 Gallery
* pGal
= ImplGetGallery();
430 return( pGal
? EndLocking( pGal
->GetThemeName( nThemeId
) ) : sal_False
);
433 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */