LibreOffice Module svx (master) 1
galexpl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <svx/gallery1.hxx>
22#include <svx/galtheme.hxx>
23#include <svx/gallery.hxx>
24#include <galobj.hxx>
25
26namespace
27{
28 SfxListener& theLockListener()
29 {
30 static SfxListener SINGLETON;
31 return SINGLETON;
32 }
33}
34
35
36bool GalleryExplorer::FillThemeList( std::vector<OUString>& rThemeList )
37{
39
40 if( pGal )
41 {
42 for( sal_uInt32 i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
43 {
44 const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
45
46 if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
47 rThemeList.push_back(pEntry->GetThemeName());
48 }
49 }
50
51 return !rThemeList.empty();
52}
53
54bool GalleryExplorer::FillObjList( std::u16string_view rThemeName, std::vector<OUString> &rObjList )
55{
57
58 if( pGal )
59 {
60 SfxListener aListener;
61 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
62
63 if( pTheme )
64 {
65 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
66 rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::DecodeMechanism::NONE ) );
67
68 pGal->ReleaseTheme( pTheme, aListener );
69 }
70 }
71
72 return !rObjList.empty();
73}
74
75bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<OUString> &rObjList )
76{
78
79 if (!pGal)
80 return false;
81
82 return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
83}
84
85bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList )
86{
88 if( pGal )
89 {
90 SfxListener aListener;
91 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
92
93 if( pTheme )
94 {
95 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
96 {
97 std::unique_ptr<SgaObject> pObj = pTheme->AcquireObject( i );
98 if ( pObj )
99 {
100 OUString aTitle( pObj->GetTitle() );
101 rList.push_back( aTitle );
102 }
103 }
104 pGal->ReleaseTheme( pTheme, aListener );
105 }
106 }
107 return !rList.empty();
108}
109
110bool GalleryExplorer::InsertURL( std::u16string_view rThemeName, std::u16string_view rURL )
111{
113 bool bRet = false;
114
115 if( pGal )
116 {
117 SfxListener aListener;
118 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
119
120 if( pTheme )
121 {
122 INetURLObject aURL( rURL );
123 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
124 bRet = pTheme->InsertURL( aURL );
125 pGal->ReleaseTheme( pTheme, aListener );
126 }
127 }
128
129 return bRet;
130}
131
132bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId, std::u16string_view rURL )
133{
135 return pGal && InsertURL( pGal->GetThemeName( nThemeId ), rURL );
136}
137
138bool GalleryExplorer::GetGraphicObj( std::u16string_view rThemeName, sal_uInt32 nPos,
139 Graphic* pGraphic )
140{
142 bool bRet = false;
143
144 if( pGal )
145 {
146 SfxListener aListener;
147 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
148
149 if( pTheme )
150 {
151 if( pGraphic )
152 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic );
153
154 pGal->ReleaseTheme( pTheme, aListener );
155 }
156 }
157
158 return bRet;
159}
160
161bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId, sal_uInt32 nPos,
162 Graphic* pGraphic )
163{
165 return pGal && GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic );
166}
167
168sal_uInt32 GalleryExplorer::GetSdrObjCount( std::u16string_view rThemeName )
169{
171 sal_uInt32 nRet = 0;
172
173 if( pGal )
174 {
175 SfxListener aListener;
176 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
177
178 if( pTheme )
179 {
180 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
181 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
182 nRet++;
183
184 pGal->ReleaseTheme( pTheme, aListener );
185 }
186 }
187
188 return nRet;
189}
190
191sal_uInt32 GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId )
192{
194 return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : 0 );
195}
196
197bool GalleryExplorer::GetSdrObj( std::u16string_view rThemeName, sal_uInt32 nSdrModelPos,
198 SdrModel* pModel, BitmapEx* pThumb )
199{
201 bool bRet = false;
202
203 if( pGal )
204 {
205 SfxListener aListener;
206 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
207
208 if( pTheme )
209 {
210 for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
211 {
212 if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) )
213 {
214 if( nActPos++ == nSdrModelPos )
215 {
216 if( pModel )
217 bRet = pTheme->GetModel(i, *pModel);
218
219 if( pThumb )
220 bRet = bRet || pTheme->GetThumb( i, *pThumb );
221 }
222 }
223 }
224
225 pGal->ReleaseTheme( pTheme, aListener );
226 }
227 }
228
229 return bRet;
230}
231
232bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId, sal_uInt32 nSdrModelPos,
233 SdrModel* pModel, BitmapEx* pThumb )
234{
236 return pGal && GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb );
237}
238
239bool GalleryExplorer::BeginLocking( std::u16string_view rThemeName )
240{
242 bool bRet = false;
243
244 if( pGal )
245 {
246 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener() );
247
248 if( pTheme )
249 {
250 pTheme->LockTheme();
251 bRet = true;
252 }
253 }
254
255 return bRet;
256}
257
258bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId )
259{
261 return pGal && BeginLocking( pGal->GetThemeName( nThemeId ) );
262}
263
264bool GalleryExplorer::EndLocking( std::u16string_view rThemeName )
265{
267 bool bRet = false;
268
269 if( pGal )
270 {
271 SfxListener aListener;
272 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
273
274 if( pTheme )
275 {
276 const bool bReleaseLockedTheme = pTheme->UnlockTheme();
277
278 // release acquired theme
279 pGal->ReleaseTheme( pTheme, aListener );
280
281 if( bReleaseLockedTheme )
282 {
283 // release locked theme
284 pGal->ReleaseTheme( pTheme, theLockListener() );
285 bRet = true;
286 }
287 }
288 }
289
290 return bRet;
291}
292
293bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId )
294{
296 return pGal && EndLocking( pGal->GetThemeName( nThemeId ) );
297}
298
299/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool FillThemeList(std::vector< OUString > &rThemeList)
Definition: galexpl.cxx:36
static bool EndLocking(std::u16string_view rThemeName)
Definition: galexpl.cxx:264
static sal_uInt32 GetSdrObjCount(std::u16string_view rThemeName)
Definition: galexpl.cxx:168
static bool FillObjListTitle(const sal_uInt32 nThemeId, std::vector< OUString > &rList)
Definition: galexpl.cxx:85
static bool GetGraphicObj(std::u16string_view rThemeName, sal_uInt32 nPos, Graphic *pGraphic)
Definition: galexpl.cxx:138
static bool GetSdrObj(std::u16string_view rThemeName, sal_uInt32 nSdrModelPos, SdrModel *pModel, BitmapEx *pThumb=nullptr)
Definition: galexpl.cxx:197
static bool FillObjList(std::u16string_view rThemeName, std::vector< OUString > &rObjList)
Definition: galexpl.cxx:54
static bool InsertURL(std::u16string_view rThemeName, std::u16string_view rURL)
Definition: galexpl.cxx:110
static bool BeginLocking(std::u16string_view rThemeName)
Definition: galexpl.cxx:239
const OUString & GetThemeName() const
Definition: gallery1.hxx:64
bool IsReadOnly() const
Definition: gallery1.hxx:66
bool IsHidden() const
Definition: gallery1.hxx:69
SAL_DLLPRIVATE void LockTheme()
Definition: galtheme.hxx:102
bool InsertURL(const INetURLObject &rURL, sal_uInt32 nInsertPos=SAL_MAX_UINT32)
Definition: galtheme.cxx:497
bool GetGraphic(sal_uInt32 nPos, Graphic &rGraphic)
Definition: galtheme.cxx:311
SAL_DLLPRIVATE const INetURLObject & GetObjectURL(sal_uInt32 nPos) const
Definition: galtheme.hxx:129
SAL_DLLPRIVATE sal_uInt32 GetObjectCount() const
Definition: galtheme.hxx:83
SAL_DLLPRIVATE bool UnlockTheme()
Definition: galtheme.cxx:95
SAL_DLLPRIVATE bool GetThumb(sal_uInt32 nPos, BitmapEx &rBmp)
Definition: galtheme.cxx:297
std::unique_ptr< SgaObject > AcquireObject(sal_uInt32 nPos)
Definition: galtheme.cxx:142
bool GetModel(sal_uInt32 nPos, SdrModel &rModel)
Definition: galtheme.cxx:437
SAL_DLLPRIVATE SgaObjKind GetObjectKind(sal_uInt32 nPos) const
Definition: galtheme.hxx:122
SAL_DLLPRIVATE OUString GetThemeName(sal_uInt32 nThemeId) const
Definition: gallery1.cxx:494
static Gallery * GetGalleryInstance()
Definition: gallery1.cxx:242
void ReleaseTheme(GalleryTheme *pTheme, SfxListener &rListener)
Definition: gallery1.cxx:711
size_t GetThemeCount() const
Definition: gallery1.hxx:123
SAL_DLLPRIVATE const GalleryThemeEntry * GetThemeInfo(size_t nPos)
Definition: gallery1.hxx:124
GalleryTheme * AcquireTheme(std::u16string_view rThemeName, SfxListener &rListener)
Definition: gallery1.cxx:697
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
int nCount
#define DBG_ASSERT(sCon, aError)
URL aURL
sal_uInt16 nPos
int i