Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <unotools/pathoptions.hxx>
31 : : #include <rtl/instance.hxx>
32 : : #include <sfx2/viewfrm.hxx>
33 : : #include "svx/gallery1.hxx"
34 : : #include "svx/galtheme.hxx"
35 : : #include "svx/galbrws.hxx"
36 : : #include "svx/gallery.hxx"
37 : : #include "galobj.hxx"
38 : :
39 : : namespace
40 : : {
41 : : class theLockListener : public rtl::Static< SfxListener, theLockListener > {};
42 : : }
43 : :
44 : : // -------------------
45 : : // - GalleryExplorer -
46 : : // -------------------
47 : :
48 : 0 : Gallery* GalleryExplorer::ImplGetGallery()
49 : : {
50 : : static Gallery* pGallery = NULL;
51 : :
52 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
53 : :
54 [ # # ]: 0 : if( !pGallery )
55 [ # # ]: 0 : pGallery = Gallery::GetGalleryInstance();
56 : :
57 [ # # ]: 0 : return pGallery;
58 : : }
59 : :
60 : : // ------------------------------------------------------------------------
61 : :
62 : 0 : GalleryExplorer* GalleryExplorer::GetGallery()
63 : : {
64 : : static GalleryExplorer* pThis = NULL;
65 : :
66 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
67 : :
68 : : // only create a dummy object which can be accessed
69 [ # # ]: 0 : if( !pThis )
70 [ # # ]: 0 : pThis = new GalleryExplorer;
71 : :
72 [ # # ]: 0 : return pThis;
73 : : }
74 : :
75 : : // ------------------------------------------------------------------------
76 : :
77 : 0 : INetURLObject GalleryExplorer::GetURL() const
78 : : {
79 : 0 : return GALLERYBROWSER()->GetURL();
80 : : }
81 : :
82 : 0 : String GalleryExplorer::GetFilterName() const
83 : : {
84 : 0 : return GALLERYBROWSER()->GetFilterName();
85 : : }
86 : :
87 : : // ------------------------------------------------------------------------
88 : :
89 : 0 : Graphic GalleryExplorer::GetGraphic() const
90 : : {
91 : 0 : return GALLERYBROWSER()->GetGraphic();
92 : : }
93 : :
94 : : // ------------------------------------------------------------------------
95 : :
96 : 0 : sal_Bool GalleryExplorer::IsLinkage() const
97 : : {
98 : 0 : return GALLERYBROWSER()->IsLinkage();
99 : : }
100 : :
101 : : // ------------------------------------------------------------------------
102 : :
103 : 0 : bool GalleryExplorer::FillThemeList( std::vector<String>& rThemeList )
104 : : {
105 : 0 : Gallery* pGal = ImplGetGallery();
106 : :
107 [ # # ]: 0 : if( pGal )
108 : : {
109 [ # # ]: 0 : for( sal_uIntPtr i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
110 : : {
111 : 0 : const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
112 : :
113 [ # # ][ # # ]: 0 : if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
[ # # ][ # # ]
114 [ # # ]: 0 : rThemeList.push_back(pEntry->GetThemeName());
115 : : }
116 : : }
117 : :
118 : 0 : return !rThemeList.empty();
119 : : }
120 : :
121 : : // ------------------------------------------------------------------------
122 : :
123 : 0 : sal_Bool GalleryExplorer::FillObjList( const String& rThemeName, std::vector<String> &rObjList )
124 : : {
125 : 0 : Gallery* pGal = ImplGetGallery();
126 : :
127 [ # # ]: 0 : if( pGal )
128 : : {
129 [ # # ]: 0 : SfxListener aListener;
130 [ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
131 : :
132 [ # # ]: 0 : if( pTheme )
133 : : {
134 [ # # ]: 0 : for( sal_uInt32 i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
135 [ # # ][ # # ]: 0 : rObjList.push_back( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) );
[ # # ][ # # ]
[ # # ]
136 : :
137 [ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
138 [ # # ]: 0 : }
139 : : }
140 : :
141 : 0 : return !rObjList.empty();
142 : : }
143 : :
144 : : // ------------------------------------------------------------------------
145 : :
146 : 0 : sal_Bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<String> &rObjList )
147 : : {
148 : 0 : Gallery* pGal = ImplGetGallery();
149 : :
150 [ # # ]: 0 : if (!pGal)
151 : 0 : return false;
152 : :
153 [ # # ][ # # ]: 0 : return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
[ # # ]
154 : : }
155 : :
156 : 0 : bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId, std::vector<rtl::OUString> &rObjList )
157 : : {
158 [ # # ]: 0 : std::vector<String> aObjList;
159 [ # # ][ # # ]: 0 : if (!FillObjList(nThemeId, aObjList))
160 : 0 : return false;
161 : :
162 : : // Convert UniString to rtl::OUString.
163 [ # # ]: 0 : std::vector<rtl::OUString> aList;
164 [ # # ]: 0 : aList.reserve(aObjList.size());
165 [ # # ][ # # ]: 0 : std::vector<String>::const_iterator it = aObjList.begin(), itEnd = aObjList.end();
166 [ # # ][ # # ]: 0 : for (; it != itEnd; ++it)
[ # # ]
167 [ # # ][ # # ]: 0 : aList.push_back(*it);
[ # # ]
168 : :
169 : 0 : rObjList.swap(aList);
170 : 0 : return true;
171 : : }
172 : :
173 : : // ------------------------------------------------------------------------
174 : :
175 : 0 : sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< rtl::OUString >& rList )
176 : : {
177 : 0 : Gallery* pGal = ImplGetGallery();
178 [ # # ]: 0 : if( pGal )
179 : : {
180 [ # # ]: 0 : SfxListener aListener;
181 [ # # ][ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
[ # # ][ # # ]
182 : :
183 [ # # ]: 0 : if( pTheme )
184 : : {
185 [ # # ]: 0 : for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
186 : : {
187 [ # # ]: 0 : SgaObject* pObj = pTheme->AcquireObject( i );
188 [ # # ]: 0 : if ( pObj )
189 : : {
190 [ # # ][ # # ]: 0 : rtl::OUString aTitle( pObj->GetTitle() );
[ # # ]
191 [ # # ]: 0 : rList.push_back( aTitle );
192 [ # # ]: 0 : pTheme->ReleaseObject( pObj );
193 : : }
194 : : }
195 [ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
196 [ # # ]: 0 : }
197 : : }
198 : 0 : return !rList.empty();
199 : : }
200 : :
201 : : // ------------------------------------------------------------------------
202 : :
203 : 0 : sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL )
204 : : {
205 : 0 : return InsertURL( rThemeName, rURL, SGA_FORMAT_ALL );
206 : : }
207 : :
208 : : // ------------------------------------------------------------------------
209 : :
210 : 0 : sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL )
211 : : {
212 : 0 : return InsertURL( nThemeId, rURL, SGA_FORMAT_ALL );
213 : : }
214 : :
215 : : // ------------------------------------------------------------------------
216 : :
217 : 0 : sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL, const sal_uIntPtr )
218 : : {
219 : 0 : Gallery* pGal = ImplGetGallery();
220 : 0 : sal_Bool bRet = sal_False;
221 : :
222 [ # # ]: 0 : if( pGal )
223 : : {
224 [ # # ]: 0 : SfxListener aListener;
225 [ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
226 : :
227 [ # # ]: 0 : if( pTheme )
228 : : {
229 [ # # ][ # # ]: 0 : INetURLObject aURL( rURL );
230 : : DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
231 [ # # ]: 0 : bRet = pTheme->InsertURL( aURL );
232 [ # # ][ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
233 [ # # ]: 0 : }
234 : : }
235 : :
236 : 0 : return bRet;
237 : : }
238 : :
239 : : // ------------------------------------------------------------------------
240 : :
241 : 0 : sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL, const sal_uIntPtr nSgaFormat )
242 : : {
243 : 0 : Gallery* pGal = ImplGetGallery();
244 [ # # ][ # # ]: 0 : return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL, nSgaFormat ) : sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
245 : : }
246 : :
247 : : // ------------------------------------------------------------------------
248 : :
249 : 0 : sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos,
250 : : Graphic* pGraphic, Bitmap* pThumb,
251 : : sal_Bool bProgress )
252 : : {
253 : 0 : Gallery* pGal = ImplGetGallery();
254 : 0 : sal_Bool bRet = sal_False;
255 : :
256 [ # # ]: 0 : if( pGal )
257 : : {
258 [ # # ]: 0 : SfxListener aListener;
259 [ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
260 : :
261 [ # # ]: 0 : if( pTheme )
262 : : {
263 [ # # ]: 0 : if( pGraphic )
264 [ # # ][ # # ]: 0 : bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
[ # # ]
265 : :
266 [ # # ]: 0 : if( pThumb )
267 [ # # ][ # # ]: 0 : bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress );
[ # # ]
268 : :
269 [ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
270 [ # # ]: 0 : }
271 : : }
272 : :
273 : 0 : return bRet;
274 : : }
275 : :
276 : : // ------------------------------------------------------------------------
277 : :
278 : 0 : sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos,
279 : : Graphic* pGraphic, Bitmap* pThumb,
280 : : sal_Bool bProgress )
281 : : {
282 : 0 : Gallery* pGal = ImplGetGallery();
283 [ # # ][ # # ]: 0 : return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
284 : : }
285 : :
286 : : // ------------------------------------------------------------------------
287 : :
288 : 0 : sal_uIntPtr GalleryExplorer::GetSdrObjCount( const String& rThemeName )
289 : : {
290 : 0 : Gallery* pGal = ImplGetGallery();
291 : 0 : sal_uIntPtr nRet = 0;
292 : :
293 [ # # ]: 0 : if( pGal )
294 : : {
295 [ # # ]: 0 : SfxListener aListener;
296 [ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
297 : :
298 [ # # ]: 0 : if( pTheme )
299 : : {
300 [ # # ]: 0 : for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
301 [ # # ][ # # ]: 0 : if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
302 : 0 : nRet++;
303 : :
304 [ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
305 [ # # ]: 0 : }
306 : : }
307 : :
308 : 0 : return nRet;
309 : : }
310 : :
311 : : // ------------------------------------------------------------------------
312 : :
313 : 0 : sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId )
314 : : {
315 : 0 : Gallery* pGal = ImplGetGallery();
316 [ # # ][ # # ]: 0 : return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
317 : : }
318 : :
319 : : // ------------------------------------------------------------------------
320 : :
321 : 0 : sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos,
322 : : SdrModel* pModel, Bitmap* pThumb )
323 : : {
324 : 0 : Gallery* pGal = ImplGetGallery();
325 : 0 : sal_Bool bRet = sal_False;
326 : :
327 [ # # ]: 0 : if( pGal )
328 : : {
329 [ # # ]: 0 : SfxListener aListener;
330 [ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
331 : :
332 [ # # ]: 0 : if( pTheme )
333 : : {
334 [ # # ][ # # ]: 0 : for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
[ # # ]
335 : : {
336 [ # # ][ # # ]: 0 : if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
337 : : {
338 [ # # ]: 0 : if( nActPos++ == nSdrModelPos )
339 : : {
340 [ # # ]: 0 : if( pModel )
341 [ # # ][ # # ]: 0 : bRet = bRet || pTheme->GetModel( i, *pModel, sal_False );
[ # # ]
342 : :
343 [ # # ]: 0 : if( pThumb )
344 [ # # ][ # # ]: 0 : bRet = bRet || pTheme->GetThumb( i, *pThumb );
[ # # ]
345 : : }
346 : : }
347 : : }
348 : :
349 [ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
350 [ # # ]: 0 : }
351 : : }
352 : :
353 : 0 : return bRet;
354 : : }
355 : :
356 : : // ------------------------------------------------------------------------
357 : :
358 : 0 : sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos,
359 : : SdrModel* pModel, Bitmap* pThumb )
360 : : {
361 : 0 : Gallery* pGal = ImplGetGallery();
362 [ # # ][ # # ]: 0 : return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
363 : : }
364 : :
365 : : // -----------------------------------------------------------------------------
366 : :
367 : 0 : sal_Bool GalleryExplorer::BeginLocking( const String& rThemeName )
368 : : {
369 : 0 : Gallery* pGal = ImplGetGallery();
370 : 0 : sal_Bool bRet = sal_False;
371 : :
372 [ # # ]: 0 : if( pGal )
373 : : {
374 : 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
375 : :
376 [ # # ]: 0 : if( pTheme )
377 : : {
378 : 0 : pTheme->LockTheme();
379 : 0 : bRet = sal_True;
380 : : }
381 : : }
382 : :
383 : 0 : return bRet;
384 : : }
385 : :
386 : : // -----------------------------------------------------------------------------
387 : :
388 : 0 : sal_Bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId )
389 : : {
390 : 0 : Gallery* pGal = ImplGetGallery();
391 [ # # ][ # # ]: 0 : return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
392 : : }
393 : :
394 : : // -----------------------------------------------------------------------------
395 : :
396 : 0 : sal_Bool GalleryExplorer::EndLocking( const String& rThemeName )
397 : : {
398 : 0 : Gallery* pGal = ImplGetGallery();
399 : 0 : sal_Bool bRet = sal_False;
400 : :
401 [ # # ]: 0 : if( pGal )
402 : : {
403 [ # # ]: 0 : SfxListener aListener;
404 [ # # ]: 0 : GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
405 : :
406 [ # # ]: 0 : if( pTheme )
407 : : {
408 [ # # ]: 0 : const sal_Bool bReleaseLockedTheme = pTheme->UnlockTheme();
409 : :
410 : : // release acquired theme
411 [ # # ]: 0 : pGal->ReleaseTheme( pTheme, aListener );
412 : :
413 [ # # ]: 0 : if( bReleaseLockedTheme )
414 : : {
415 : : // release locked theme
416 [ # # ][ # # ]: 0 : pGal->ReleaseTheme( pTheme, theLockListener::get() );
417 : 0 : bRet = sal_True;
418 : : }
419 [ # # ]: 0 : }
420 : : }
421 : :
422 : 0 : return bRet;
423 : : }
424 : :
425 : : // -----------------------------------------------------------------------------
426 : :
427 : 0 : sal_Bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId )
428 : : {
429 : 0 : Gallery* pGal = ImplGetGallery();
430 [ # # ][ # # ]: 0 : return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
[ # # ]
431 : : }
432 : :
433 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|