Line data Source code
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 <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/galbrws.hxx"
27 : #include "svx/gallery.hxx"
28 : #include "galobj.hxx"
29 :
30 : namespace
31 : {
32 : class theLockListener : public rtl::Static< SfxListener, theLockListener > {};
33 : }
34 :
35 : // -------------------
36 : // - GalleryExplorer -
37 : // -------------------
38 :
39 0 : bool GalleryExplorer::FillThemeList( std::vector<String>& rThemeList )
40 : {
41 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
42 :
43 0 : if( pGal )
44 : {
45 0 : for( sal_uIntPtr i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
46 : {
47 0 : const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
48 :
49 0 : if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
50 0 : rThemeList.push_back(pEntry->GetThemeName());
51 : }
52 : }
53 :
54 0 : return !rThemeList.empty();
55 : }
56 :
57 : // ------------------------------------------------------------------------
58 :
59 0 : sal_Bool GalleryExplorer::FillObjList( const String& rThemeName, std::vector<String> &rObjList )
60 : {
61 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
62 :
63 0 : if( pGal )
64 : {
65 0 : SfxListener aListener;
66 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
67 :
68 0 : if( pTheme )
69 : {
70 0 : for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
71 0 : rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) );
72 :
73 0 : pGal->ReleaseTheme( pTheme, aListener );
74 0 : }
75 : }
76 :
77 0 : return !rObjList.empty();
78 : }
79 :
80 : // ------------------------------------------------------------------------
81 :
82 0 : sal_Bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<String> &rObjList )
83 : {
84 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
85 :
86 0 : if (!pGal)
87 0 : return false;
88 :
89 0 : return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
90 : }
91 :
92 0 : bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<OUString> &rObjList )
93 : {
94 0 : std::vector<String> aObjList;
95 0 : if (!FillObjList(nThemeId, aObjList))
96 0 : return false;
97 :
98 0 : std::vector<OUString> aList;
99 0 : aList.reserve(aObjList.size());
100 0 : std::vector<String>::const_iterator it = aObjList.begin(), itEnd = aObjList.end();
101 0 : for (; it != itEnd; ++it)
102 0 : aList.push_back(*it);
103 :
104 0 : rObjList.swap(aList);
105 0 : return true;
106 : }
107 :
108 : // ------------------------------------------------------------------------
109 :
110 0 : sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList )
111 : {
112 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
113 0 : if( pGal )
114 : {
115 0 : SfxListener aListener;
116 0 : GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
117 :
118 0 : if( pTheme )
119 : {
120 0 : for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
121 : {
122 0 : SgaObject* pObj = pTheme->AcquireObject( i );
123 0 : if ( pObj )
124 : {
125 0 : OUString aTitle( pObj->GetTitle() );
126 0 : rList.push_back( aTitle );
127 0 : pTheme->ReleaseObject( pObj );
128 : }
129 : }
130 0 : pGal->ReleaseTheme( pTheme, aListener );
131 0 : }
132 : }
133 0 : return !rList.empty();
134 : }
135 :
136 : // ------------------------------------------------------------------------
137 :
138 0 : sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL )
139 : {
140 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
141 0 : sal_Bool bRet = sal_False;
142 :
143 0 : if( pGal )
144 : {
145 0 : SfxListener aListener;
146 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
147 :
148 0 : if( pTheme )
149 : {
150 0 : INetURLObject aURL( rURL );
151 : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
152 0 : bRet = pTheme->InsertURL( aURL );
153 0 : pGal->ReleaseTheme( pTheme, aListener );
154 0 : }
155 : }
156 :
157 0 : return bRet;
158 : }
159 :
160 : // ------------------------------------------------------------------------
161 :
162 0 : sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL )
163 : {
164 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
165 0 : return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL ) : sal_False );
166 : }
167 :
168 : // ------------------------------------------------------------------------
169 :
170 0 : sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos,
171 : Graphic* pGraphic, BitmapEx* pThumb,
172 : sal_Bool bProgress )
173 : {
174 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
175 0 : sal_Bool bRet = sal_False;
176 :
177 0 : if( pGal )
178 : {
179 0 : SfxListener aListener;
180 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
181 :
182 0 : if( pTheme )
183 : {
184 0 : if( pGraphic )
185 0 : bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
186 :
187 0 : if( pThumb )
188 0 : bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress );
189 :
190 0 : pGal->ReleaseTheme( pTheme, aListener );
191 0 : }
192 : }
193 :
194 0 : return bRet;
195 : }
196 :
197 : // ------------------------------------------------------------------------
198 :
199 0 : sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos,
200 : Graphic* pGraphic, BitmapEx* pThumb,
201 : sal_Bool bProgress )
202 : {
203 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
204 0 : return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : sal_False );
205 : }
206 :
207 : // ------------------------------------------------------------------------
208 :
209 0 : sal_uIntPtr GalleryExplorer::GetSdrObjCount( const String& rThemeName )
210 : {
211 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
212 0 : sal_uIntPtr nRet = 0;
213 :
214 0 : if( pGal )
215 : {
216 0 : SfxListener aListener;
217 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
218 :
219 0 : if( pTheme )
220 : {
221 0 : for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
222 0 : if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
223 0 : nRet++;
224 :
225 0 : pGal->ReleaseTheme( pTheme, aListener );
226 0 : }
227 : }
228 :
229 0 : return nRet;
230 : }
231 :
232 : // ------------------------------------------------------------------------
233 :
234 0 : sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId )
235 : {
236 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
237 0 : return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False );
238 : }
239 :
240 : // ------------------------------------------------------------------------
241 :
242 0 : sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos,
243 : SdrModel* pModel, BitmapEx* pThumb )
244 : {
245 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
246 0 : sal_Bool bRet = sal_False;
247 :
248 0 : if( pGal )
249 : {
250 0 : SfxListener aListener;
251 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
252 :
253 0 : if( pTheme )
254 : {
255 0 : for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
256 : {
257 0 : if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
258 : {
259 0 : if( nActPos++ == nSdrModelPos )
260 : {
261 0 : if( pModel )
262 0 : bRet = bRet || pTheme->GetModel( i, *pModel, sal_False );
263 :
264 0 : if( pThumb )
265 0 : bRet = bRet || pTheme->GetThumb( i, *pThumb );
266 : }
267 : }
268 : }
269 :
270 0 : pGal->ReleaseTheme( pTheme, aListener );
271 0 : }
272 : }
273 :
274 0 : return bRet;
275 : }
276 :
277 : // ------------------------------------------------------------------------
278 :
279 0 : sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos,
280 : SdrModel* pModel, BitmapEx* pThumb )
281 : {
282 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
283 0 : return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False );
284 : }
285 :
286 : // -----------------------------------------------------------------------------
287 :
288 0 : sal_Bool GalleryExplorer::BeginLocking( const String& rThemeName )
289 : {
290 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
291 0 : sal_Bool bRet = sal_False;
292 :
293 0 : if( pGal )
294 : {
295 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
296 :
297 0 : if( pTheme )
298 : {
299 0 : pTheme->LockTheme();
300 0 : bRet = sal_True;
301 : }
302 : }
303 :
304 0 : return bRet;
305 : }
306 :
307 : // -----------------------------------------------------------------------------
308 :
309 0 : sal_Bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId )
310 : {
311 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
312 0 : return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
313 : }
314 :
315 : // -----------------------------------------------------------------------------
316 :
317 0 : sal_Bool GalleryExplorer::EndLocking( const String& rThemeName )
318 : {
319 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
320 0 : sal_Bool bRet = sal_False;
321 :
322 0 : if( pGal )
323 : {
324 0 : SfxListener aListener;
325 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
326 :
327 0 : if( pTheme )
328 : {
329 0 : const sal_Bool bReleaseLockedTheme = pTheme->UnlockTheme();
330 :
331 : // release acquired theme
332 0 : pGal->ReleaseTheme( pTheme, aListener );
333 :
334 0 : if( bReleaseLockedTheme )
335 : {
336 : // release locked theme
337 0 : pGal->ReleaseTheme( pTheme, theLockListener::get() );
338 0 : bRet = sal_True;
339 : }
340 0 : }
341 : }
342 :
343 0 : return bRet;
344 : }
345 :
346 : // -----------------------------------------------------------------------------
347 :
348 0 : sal_Bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId )
349 : {
350 0 : Gallery* pGal = ::Gallery::GetGalleryInstance();
351 0 : return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
352 258 : }
353 :
354 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|