/src/libreoffice/svx/source/gallery2/galexpl.cxx
Line | Count | Source |
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 | | |
26 | | namespace |
27 | | { |
28 | | SfxListener& theLockListener() |
29 | 0 | { |
30 | 0 | static SfxListener SINGLETON; |
31 | 0 | return SINGLETON; |
32 | 0 | } |
33 | | } |
34 | | |
35 | | |
36 | | bool GalleryExplorer::FillThemeList( std::vector<OUString>& rThemeList ) |
37 | 0 | { |
38 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
39 | |
|
40 | 0 | if( pGal ) |
41 | 0 | { |
42 | 0 | for( sal_uInt32 i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ ) |
43 | 0 | { |
44 | 0 | const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i ); |
45 | |
|
46 | 0 | if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() ) |
47 | 0 | rThemeList.push_back(pEntry->GetThemeName()); |
48 | 0 | } |
49 | 0 | } |
50 | |
|
51 | 0 | return !rThemeList.empty(); |
52 | 0 | } |
53 | | |
54 | | bool GalleryExplorer::FillObjList( std::u16string_view rThemeName, std::vector<OUString> &rObjList ) |
55 | 0 | { |
56 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
57 | |
|
58 | 0 | if( pGal ) |
59 | 0 | { |
60 | 0 | SfxListener aListener; |
61 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); |
62 | |
|
63 | 0 | if( pTheme ) |
64 | 0 | { |
65 | 0 | for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) |
66 | 0 | rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); |
67 | |
|
68 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
69 | 0 | } |
70 | 0 | } |
71 | |
|
72 | 0 | return !rObjList.empty(); |
73 | 0 | } |
74 | | |
75 | | bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<OUString> &rObjList ) |
76 | 676 | { |
77 | 676 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
78 | | |
79 | 676 | if (!pGal) |
80 | 676 | return false; |
81 | | |
82 | 0 | return FillObjList( pGal->GetThemeName( nThemeId ), rObjList ); |
83 | 676 | } |
84 | | |
85 | | bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList ) |
86 | 0 | { |
87 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
88 | 0 | if( pGal ) |
89 | 0 | { |
90 | 0 | SfxListener aListener; |
91 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener ); |
92 | |
|
93 | 0 | if( pTheme ) |
94 | 0 | { |
95 | 0 | for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) |
96 | 0 | { |
97 | 0 | std::unique_ptr<SgaObject> pObj = pTheme->AcquireObject( i ); |
98 | 0 | if ( pObj ) |
99 | 0 | { |
100 | 0 | OUString aTitle( pObj->GetTitle() ); |
101 | 0 | rList.push_back( aTitle ); |
102 | 0 | } |
103 | 0 | } |
104 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
105 | 0 | } |
106 | 0 | } |
107 | 0 | return !rList.empty(); |
108 | 0 | } |
109 | | |
110 | | bool GalleryExplorer::InsertURL( std::u16string_view rThemeName, std::u16string_view rURL ) |
111 | 0 | { |
112 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
113 | 0 | bool bRet = false; |
114 | |
|
115 | 0 | if( pGal ) |
116 | 0 | { |
117 | 0 | SfxListener aListener; |
118 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); |
119 | |
|
120 | 0 | if( pTheme ) |
121 | 0 | { |
122 | 0 | INetURLObject aURL( rURL ); |
123 | 0 | DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" ); |
124 | 0 | bRet = pTheme->InsertURL( aURL ); |
125 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
126 | 0 | } |
127 | 0 | } |
128 | |
|
129 | 0 | return bRet; |
130 | 0 | } |
131 | | |
132 | | bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId, std::u16string_view rURL ) |
133 | 0 | { |
134 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
135 | 0 | return pGal && InsertURL( pGal->GetThemeName( nThemeId ), rURL ); |
136 | 0 | } |
137 | | |
138 | | bool GalleryExplorer::GetGraphicObj( std::u16string_view rThemeName, sal_uInt32 nPos, |
139 | | Graphic* pGraphic ) |
140 | 0 | { |
141 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
142 | 0 | bool bRet = false; |
143 | |
|
144 | 0 | if( pGal ) |
145 | 0 | { |
146 | 0 | SfxListener aListener; |
147 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); |
148 | |
|
149 | 0 | if( pTheme ) |
150 | 0 | { |
151 | 0 | if( pGraphic ) |
152 | 0 | bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic ); |
153 | |
|
154 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
155 | 0 | } |
156 | 0 | } |
157 | |
|
158 | 0 | return bRet; |
159 | 0 | } |
160 | | |
161 | | bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId, sal_uInt32 nPos, |
162 | | Graphic* pGraphic ) |
163 | 0 | { |
164 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
165 | 0 | return pGal && GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic ); |
166 | 0 | } |
167 | | |
168 | | sal_uInt32 GalleryExplorer::GetSdrObjCount( std::u16string_view rThemeName ) |
169 | 0 | { |
170 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
171 | 0 | sal_uInt32 nRet = 0; |
172 | |
|
173 | 0 | if( pGal ) |
174 | 0 | { |
175 | 0 | SfxListener aListener; |
176 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); |
177 | |
|
178 | 0 | if( pTheme ) |
179 | 0 | { |
180 | 0 | for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ ) |
181 | 0 | if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) ) |
182 | 0 | nRet++; |
183 | |
|
184 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
185 | 0 | } |
186 | 0 | } |
187 | |
|
188 | 0 | return nRet; |
189 | 0 | } |
190 | | |
191 | | sal_uInt32 GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId ) |
192 | 0 | { |
193 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
194 | 0 | return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : 0 ); |
195 | 0 | } |
196 | | |
197 | | bool GalleryExplorer::GetSdrObj( std::u16string_view rThemeName, sal_uInt32 nSdrModelPos, |
198 | | SdrModel* pModel, Bitmap* pThumb ) |
199 | 0 | { |
200 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
201 | 0 | bool bRet = false; |
202 | |
|
203 | 0 | if( pGal ) |
204 | 0 | { |
205 | 0 | SfxListener aListener; |
206 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); |
207 | |
|
208 | 0 | if( pTheme ) |
209 | 0 | { |
210 | 0 | for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ ) |
211 | 0 | { |
212 | 0 | if( SgaObjKind::SvDraw == pTheme->GetObjectKind( i ) ) |
213 | 0 | { |
214 | 0 | if( nActPos++ == nSdrModelPos ) |
215 | 0 | { |
216 | 0 | if( pModel ) |
217 | 0 | bRet = pTheme->GetModel(i, *pModel); |
218 | |
|
219 | 0 | if( pThumb ) |
220 | 0 | bRet = bRet || pTheme->GetThumb( i, *pThumb ); |
221 | 0 | } |
222 | 0 | } |
223 | 0 | } |
224 | |
|
225 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
226 | 0 | } |
227 | 0 | } |
228 | |
|
229 | 0 | return bRet; |
230 | 0 | } |
231 | | |
232 | | bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId, sal_uInt32 nSdrModelPos, |
233 | | SdrModel* pModel, Bitmap* pThumb ) |
234 | 0 | { |
235 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
236 | 0 | return pGal && GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ); |
237 | 0 | } |
238 | | |
239 | | bool GalleryExplorer::BeginLocking( std::u16string_view rThemeName ) |
240 | 0 | { |
241 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
242 | 0 | bool bRet = false; |
243 | |
|
244 | 0 | if( pGal ) |
245 | 0 | { |
246 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener() ); |
247 | |
|
248 | 0 | if( pTheme ) |
249 | 0 | { |
250 | 0 | pTheme->LockTheme(); |
251 | 0 | bRet = true; |
252 | 0 | } |
253 | 0 | } |
254 | |
|
255 | 0 | return bRet; |
256 | 0 | } |
257 | | |
258 | | bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId ) |
259 | 0 | { |
260 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
261 | 0 | return pGal && BeginLocking( pGal->GetThemeName( nThemeId ) ); |
262 | 0 | } |
263 | | |
264 | | bool GalleryExplorer::EndLocking( std::u16string_view rThemeName ) |
265 | 0 | { |
266 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
267 | 0 | bool bRet = false; |
268 | |
|
269 | 0 | if( pGal ) |
270 | 0 | { |
271 | 0 | SfxListener aListener; |
272 | 0 | GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener ); |
273 | |
|
274 | 0 | if( pTheme ) |
275 | 0 | { |
276 | 0 | const bool bReleaseLockedTheme = pTheme->UnlockTheme(); |
277 | | |
278 | | // release acquired theme |
279 | 0 | pGal->ReleaseTheme( pTheme, aListener ); |
280 | |
|
281 | 0 | if( bReleaseLockedTheme ) |
282 | 0 | { |
283 | | // release locked theme |
284 | 0 | pGal->ReleaseTheme( pTheme, theLockListener() ); |
285 | 0 | bRet = true; |
286 | 0 | } |
287 | 0 | } |
288 | 0 | } |
289 | |
|
290 | 0 | return bRet; |
291 | 0 | } |
292 | | |
293 | | bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId ) |
294 | 0 | { |
295 | 0 | Gallery* pGal = ::Gallery::GetGalleryInstance(); |
296 | 0 | return pGal && EndLocking( pGal->GetThemeName( nThemeId ) ); |
297 | 0 | } |
298 | | |
299 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |