Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / svx / source / gallery2 / galexpl.cxx
blob5d05b80d7a61608bfc288b6c37f03cb8cf277df6
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 SgaObject* pObj = pTheme->AcquireObject( i );
97 if ( pObj )
99 OUString aTitle( pObj->GetTitle() );
100 rList.push_back( aTitle );
101 GalleryTheme::ReleaseObject( pObj );
104 pGal->ReleaseTheme( pTheme, aListener );
107 return !rList.empty();
110 bool GalleryExplorer::InsertURL( const OUString& rThemeName, const OUString& rURL )
112 Gallery* pGal = ::Gallery::GetGalleryInstance();
113 bool bRet = false;
115 if( pGal )
117 SfxListener aListener;
118 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
120 if( pTheme )
122 INetURLObject aURL( rURL );
123 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
124 bRet = pTheme->InsertURL( aURL );
125 pGal->ReleaseTheme( pTheme, aListener );
129 return bRet;
132 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId, const OUString& rURL )
134 Gallery* pGal = ::Gallery::GetGalleryInstance();
135 return pGal && InsertURL( pGal->GetThemeName( nThemeId ), rURL );
138 bool GalleryExplorer::GetGraphicObj( const OUString& rThemeName, sal_uInt32 nPos,
139 Graphic* pGraphic, BitmapEx* pThumb,
140 bool bProgress )
142 Gallery* pGal = ::Gallery::GetGalleryInstance();
143 bool bRet = false;
145 if( pGal )
147 SfxListener aListener;
148 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
150 if( pTheme )
152 if( pGraphic )
153 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
155 if( pThumb )
156 bRet = bRet || pTheme->GetThumb( nPos, *pThumb );
158 pGal->ReleaseTheme( pTheme, aListener );
162 return bRet;
165 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId, sal_uInt32 nPos,
166 Graphic* pGraphic, BitmapEx* pThumb,
167 bool bProgress )
169 Gallery* pGal = ::Gallery::GetGalleryInstance();
170 return pGal && GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress );
173 sal_uInt32 GalleryExplorer::GetSdrObjCount( const OUString& rThemeName )
175 Gallery* pGal = ::Gallery::GetGalleryInstance();
176 sal_uInt32 nRet = 0;
178 if( pGal )
180 SfxListener aListener;
181 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
183 if( pTheme )
185 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
186 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
187 nRet++;
189 pGal->ReleaseTheme( pTheme, aListener );
193 return nRet;
196 sal_uInt32 GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId )
198 Gallery* pGal = ::Gallery::GetGalleryInstance();
199 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : 0 );
202 bool GalleryExplorer::GetSdrObj( const OUString& rThemeName, sal_uInt32 nSdrModelPos,
203 SdrModel* pModel, BitmapEx* pThumb )
205 Gallery* pGal = ::Gallery::GetGalleryInstance();
206 bool bRet = false;
208 if( pGal )
210 SfxListener aListener;
211 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
213 if( pTheme )
215 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
217 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
219 if( nActPos++ == nSdrModelPos )
221 if( pModel )
222 bRet = bRet || pTheme->GetModel( i, *pModel );
224 if( pThumb )
225 bRet = bRet || pTheme->GetThumb( i, *pThumb );
230 pGal->ReleaseTheme( pTheme, aListener );
234 return bRet;
237 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId, sal_uInt32 nSdrModelPos,
238 SdrModel* pModel, BitmapEx* pThumb )
240 Gallery* pGal = ::Gallery::GetGalleryInstance();
241 return pGal && GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb );
244 bool GalleryExplorer::BeginLocking( const OUString& rThemeName )
246 Gallery* pGal = ::Gallery::GetGalleryInstance();
247 bool bRet = false;
249 if( pGal )
251 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
253 if( pTheme )
255 pTheme->LockTheme();
256 bRet = true;
260 return bRet;
263 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId )
265 Gallery* pGal = ::Gallery::GetGalleryInstance();
266 return pGal && BeginLocking( pGal->GetThemeName( nThemeId ) );
269 bool GalleryExplorer::EndLocking( const OUString& rThemeName )
271 Gallery* pGal = ::Gallery::GetGalleryInstance();
272 bool bRet = false;
274 if( pGal )
276 SfxListener aListener;
277 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
279 if( pTheme )
281 const bool bReleaseLockedTheme = pTheme->UnlockTheme();
283 // release acquired theme
284 pGal->ReleaseTheme( pTheme, aListener );
286 if( bReleaseLockedTheme )
288 // release locked theme
289 pGal->ReleaseTheme( pTheme, theLockListener::get() );
290 bRet = true;
295 return bRet;
298 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId )
300 Gallery* pGal = ::Gallery::GetGalleryInstance();
301 return pGal && EndLocking( pGal->GetThemeName( nThemeId ) );
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */