Bump version to 6.4-15
[LibreOffice.git] / svx / source / gallery2 / galexpl.cxx
blob1f5122fd97b517f162ab9d95e7b03e254694794e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <unotools/pathoptions.hxx>
22 #include <rtl/instance.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <svx/gallery1.hxx>
25 #include <svx/galtheme.hxx>
26 #include <svx/gallery.hxx>
27 #include <galobj.hxx>
29 namespace
31 class theLockListener : public rtl::Static< SfxListener, theLockListener > {};
35 bool GalleryExplorer::FillThemeList( std::vector<OUString>& rThemeList )
37 Gallery* pGal = ::Gallery::GetGalleryInstance();
39 if( pGal )
41 for( sal_uInt32 i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
43 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
45 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
46 rThemeList.push_back(pEntry->GetThemeName());
50 return !rThemeList.empty();
53 bool GalleryExplorer::FillObjList( const OUString& rThemeName, std::vector<OUString> &rObjList )
55 Gallery* pGal = ::Gallery::GetGalleryInstance();
57 if( pGal )
59 SfxListener aListener;
60 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
62 if( pTheme )
64 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
65 rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
67 pGal->ReleaseTheme( pTheme, aListener );
71 return !rObjList.empty();
74 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<OUString> &rObjList )
76 Gallery* pGal = ::Gallery::GetGalleryInstance();
78 if (!pGal)
79 return false;
81 return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
84 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList )
86 Gallery* pGal = ::Gallery::GetGalleryInstance();
87 if( pGal )
89 SfxListener aListener;
90 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
92 if( pTheme )
94 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
96 std::unique_ptr<SgaObject> pObj = pTheme->AcquireObject( i );
97 if ( pObj )
99 OUString aTitle( pObj->GetTitle() );
100 rList.push_back( aTitle );
103 pGal->ReleaseTheme( pTheme, aListener );
106 return !rList.empty();
109 bool GalleryExplorer::InsertURL( const OUString& rThemeName, const OUString& rURL )
111 Gallery* pGal = ::Gallery::GetGalleryInstance();
112 bool bRet = false;
114 if( pGal )
116 SfxListener aListener;
117 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
119 if( pTheme )
121 INetURLObject aURL( rURL );
122 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
123 bRet = pTheme->InsertURL( aURL );
124 pGal->ReleaseTheme( pTheme, aListener );
128 return bRet;
131 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId, const OUString& rURL )
133 Gallery* pGal = ::Gallery::GetGalleryInstance();
134 return pGal && InsertURL( pGal->GetThemeName( nThemeId ), rURL );
137 bool GalleryExplorer::GetGraphicObj( const OUString& rThemeName, sal_uInt32 nPos,
138 Graphic* pGraphic )
140 Gallery* pGal = ::Gallery::GetGalleryInstance();
141 bool bRet = false;
143 if( pGal )
145 SfxListener aListener;
146 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
148 if( pTheme )
150 if( pGraphic )
151 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic );
153 pGal->ReleaseTheme( pTheme, aListener );
157 return bRet;
160 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId, sal_uInt32 nPos,
161 Graphic* pGraphic )
163 Gallery* pGal = ::Gallery::GetGalleryInstance();
164 return pGal && GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic );
167 sal_uInt32 GalleryExplorer::GetSdrObjCount( const OUString& rThemeName )
169 Gallery* pGal = ::Gallery::GetGalleryInstance();
170 sal_uInt32 nRet = 0;
172 if( pGal )
174 SfxListener aListener;
175 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
177 if( pTheme )
179 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
180 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
181 nRet++;
183 pGal->ReleaseTheme( pTheme, aListener );
187 return nRet;
190 sal_uInt32 GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId )
192 Gallery* pGal = ::Gallery::GetGalleryInstance();
193 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : 0 );
196 bool GalleryExplorer::GetSdrObj( const OUString& rThemeName, sal_uInt32 nSdrModelPos,
197 SdrModel* pModel, BitmapEx* pThumb )
199 Gallery* pGal = ::Gallery::GetGalleryInstance();
200 bool bRet = false;
202 if( pGal )
204 SfxListener aListener;
205 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
207 if( pTheme )
209 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
211 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
213 if( nActPos++ == nSdrModelPos )
215 if( pModel )
216 bRet = pTheme->GetModel(i, *pModel);
218 if( pThumb )
219 bRet = bRet || pTheme->GetThumb( i, *pThumb );
224 pGal->ReleaseTheme( pTheme, aListener );
228 return bRet;
231 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId, sal_uInt32 nSdrModelPos,
232 SdrModel* pModel, BitmapEx* pThumb )
234 Gallery* pGal = ::Gallery::GetGalleryInstance();
235 return pGal && GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb );
238 bool GalleryExplorer::BeginLocking( const OUString& rThemeName )
240 Gallery* pGal = ::Gallery::GetGalleryInstance();
241 bool bRet = false;
243 if( pGal )
245 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
247 if( pTheme )
249 pTheme->LockTheme();
250 bRet = true;
254 return bRet;
257 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId )
259 Gallery* pGal = ::Gallery::GetGalleryInstance();
260 return pGal && BeginLocking( pGal->GetThemeName( nThemeId ) );
263 bool GalleryExplorer::EndLocking( const OUString& rThemeName )
265 Gallery* pGal = ::Gallery::GetGalleryInstance();
266 bool bRet = false;
268 if( pGal )
270 SfxListener aListener;
271 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
273 if( pTheme )
275 const bool bReleaseLockedTheme = pTheme->UnlockTheme();
277 // release acquired theme
278 pGal->ReleaseTheme( pTheme, aListener );
280 if( bReleaseLockedTheme )
282 // release locked theme
283 pGal->ReleaseTheme( pTheme, theLockListener::get() );
284 bRet = true;
289 return bRet;
292 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId )
294 Gallery* pGal = ::Gallery::GetGalleryInstance();
295 return pGal && EndLocking( pGal->GetThemeName( nThemeId ) );
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */