bump product version to 7.2.5.1
[LibreOffice.git] / svx / source / gallery2 / galexpl.cxx
blob83dc3b1688dd7bf43f1b7b5bd4b8deb4fd1345e7
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 <rtl/instance.hxx>
22 #include <svx/gallery1.hxx>
23 #include <svx/galtheme.hxx>
24 #include <svx/gallery.hxx>
25 #include <galobj.hxx>
27 namespace
29 class theLockListener : public rtl::Static< SfxListener, theLockListener > {};
33 bool GalleryExplorer::FillThemeList( std::vector<OUString>& rThemeList )
35 Gallery* pGal = ::Gallery::GetGalleryInstance();
37 if( pGal )
39 for( sal_uInt32 i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
41 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
43 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
44 rThemeList.push_back(pEntry->GetThemeName());
48 return !rThemeList.empty();
51 bool GalleryExplorer::FillObjList( std::u16string_view rThemeName, std::vector<OUString> &rObjList )
53 Gallery* pGal = ::Gallery::GetGalleryInstance();
55 if( pGal )
57 SfxListener aListener;
58 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
60 if( pTheme )
62 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
63 rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
65 pGal->ReleaseTheme( pTheme, aListener );
69 return !rObjList.empty();
72 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<OUString> &rObjList )
74 Gallery* pGal = ::Gallery::GetGalleryInstance();
76 if (!pGal)
77 return false;
79 return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
82 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList )
84 Gallery* pGal = ::Gallery::GetGalleryInstance();
85 if( pGal )
87 SfxListener aListener;
88 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
90 if( pTheme )
92 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
94 std::unique_ptr<SgaObject> pObj = pTheme->AcquireObject( i );
95 if ( pObj )
97 OUString aTitle( pObj->GetTitle() );
98 rList.push_back( aTitle );
101 pGal->ReleaseTheme( pTheme, aListener );
104 return !rList.empty();
107 bool GalleryExplorer::InsertURL( std::u16string_view rThemeName, const OUString& rURL )
109 Gallery* pGal = ::Gallery::GetGalleryInstance();
110 bool bRet = false;
112 if( pGal )
114 SfxListener aListener;
115 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
117 if( pTheme )
119 INetURLObject aURL( rURL );
120 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
121 bRet = pTheme->InsertURL( aURL );
122 pGal->ReleaseTheme( pTheme, aListener );
126 return bRet;
129 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId, const OUString& rURL )
131 Gallery* pGal = ::Gallery::GetGalleryInstance();
132 return pGal && InsertURL( pGal->GetThemeName( nThemeId ), rURL );
135 bool GalleryExplorer::GetGraphicObj( std::u16string_view rThemeName, sal_uInt32 nPos,
136 Graphic* pGraphic )
138 Gallery* pGal = ::Gallery::GetGalleryInstance();
139 bool bRet = false;
141 if( pGal )
143 SfxListener aListener;
144 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
146 if( pTheme )
148 if( pGraphic )
149 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic );
151 pGal->ReleaseTheme( pTheme, aListener );
155 return bRet;
158 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId, sal_uInt32 nPos,
159 Graphic* pGraphic )
161 Gallery* pGal = ::Gallery::GetGalleryInstance();
162 return pGal && GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic );
165 sal_uInt32 GalleryExplorer::GetSdrObjCount( std::u16string_view rThemeName )
167 Gallery* pGal = ::Gallery::GetGalleryInstance();
168 sal_uInt32 nRet = 0;
170 if( pGal )
172 SfxListener aListener;
173 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
175 if( pTheme )
177 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
178 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
179 nRet++;
181 pGal->ReleaseTheme( pTheme, aListener );
185 return nRet;
188 sal_uInt32 GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId )
190 Gallery* pGal = ::Gallery::GetGalleryInstance();
191 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : 0 );
194 bool GalleryExplorer::GetSdrObj( std::u16string_view rThemeName, sal_uInt32 nSdrModelPos,
195 SdrModel* pModel, BitmapEx* pThumb )
197 Gallery* pGal = ::Gallery::GetGalleryInstance();
198 bool bRet = false;
200 if( pGal )
202 SfxListener aListener;
203 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
205 if( pTheme )
207 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
209 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
211 if( nActPos++ == nSdrModelPos )
213 if( pModel )
214 bRet = pTheme->GetModel(i, *pModel);
216 if( pThumb )
217 bRet = bRet || pTheme->GetThumb( i, *pThumb );
222 pGal->ReleaseTheme( pTheme, aListener );
226 return bRet;
229 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId, sal_uInt32 nSdrModelPos,
230 SdrModel* pModel, BitmapEx* pThumb )
232 Gallery* pGal = ::Gallery::GetGalleryInstance();
233 return pGal && GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb );
236 bool GalleryExplorer::BeginLocking( std::u16string_view rThemeName )
238 Gallery* pGal = ::Gallery::GetGalleryInstance();
239 bool bRet = false;
241 if( pGal )
243 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
245 if( pTheme )
247 pTheme->LockTheme();
248 bRet = true;
252 return bRet;
255 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId )
257 Gallery* pGal = ::Gallery::GetGalleryInstance();
258 return pGal && BeginLocking( pGal->GetThemeName( nThemeId ) );
261 bool GalleryExplorer::EndLocking( std::u16string_view rThemeName )
263 Gallery* pGal = ::Gallery::GetGalleryInstance();
264 bool bRet = false;
266 if( pGal )
268 SfxListener aListener;
269 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
271 if( pTheme )
273 const bool bReleaseLockedTheme = pTheme->UnlockTheme();
275 // release acquired theme
276 pGal->ReleaseTheme( pTheme, aListener );
278 if( bReleaseLockedTheme )
280 // release locked theme
281 pGal->ReleaseTheme( pTheme, theLockListener::get() );
282 bRet = true;
287 return bRet;
290 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId )
292 Gallery* pGal = ::Gallery::GetGalleryInstance();
293 return pGal && EndLocking( pGal->GetThemeName( nThemeId ) );
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */