xref: /aoo41x/main/svx/source/gallery2/galexpl.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <unotools/pathoptions.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 // -----------
40 // - Statics -
41 // -----------
42 
43 static SfxListener aLockListener;
44 
45 // -------------------
46 // - GalleryExplorer -
47 // -------------------
48 
49 Gallery* GalleryExplorer::ImplGetGallery()
50 {
51 	static Gallery* pGallery = NULL;
52 
53     ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
54 
55 	if( !pGallery )
56 		pGallery = Gallery::GetGalleryInstance();
57 
58 	return pGallery;
59 }
60 
61 // ------------------------------------------------------------------------
62 
63 GalleryExplorer* GalleryExplorer::GetGallery()
64 {
65 	static GalleryExplorer* pThis = NULL;
66 
67     ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
68 
69 	// only create a dummy object which can be accessed
70 	if( !pThis )
71 		pThis = new GalleryExplorer;
72 
73 	return pThis;
74 }
75 
76 // ------------------------------------------------------------------------
77 
78 INetURLObject GalleryExplorer::GetURL() const
79 {
80 	return GALLERYBROWSER()->GetURL();
81 }
82 
83 String GalleryExplorer::GetFilterName() const
84 {
85 	return GALLERYBROWSER()->GetFilterName();
86 }
87 
88 // ------------------------------------------------------------------------
89 
90 Graphic GalleryExplorer::GetGraphic() const
91 {
92 	return GALLERYBROWSER()->GetGraphic();
93 }
94 
95 // ------------------------------------------------------------------------
96 
97 sal_Bool GalleryExplorer::GetVCDrawModel( FmFormModel& rModel ) const
98 {
99 	return GALLERYBROWSER()->GetVCDrawModel( rModel );
100 }
101 
102 // ------------------------------------------------------------------------
103 
104 sal_Bool GalleryExplorer::IsLinkage() const
105 {
106 	return GALLERYBROWSER()->IsLinkage();
107 }
108 
109 // ------------------------------------------------------------------------
110 
111 sal_Bool GalleryExplorer::FillThemeList( List& rThemeList )
112 {
113 	Gallery* pGal = ImplGetGallery();
114 
115 	if( pGal )
116 	{
117 		for( sal_uIntPtr i = 0, nCount = pGal->GetThemeCount(); i < nCount; i++ )
118 		{
119 			const GalleryThemeEntry* pEntry = pGal->GetThemeInfo( i );
120 
121 			if( pEntry && !pEntry->IsReadOnly() && !pEntry->IsHidden() )
122 				rThemeList.Insert( new String( pEntry->GetThemeName() ), LIST_APPEND );
123 		}
124 	}
125 
126 	return( rThemeList.Count() > 0 );
127 }
128 
129 // ------------------------------------------------------------------------
130 
131 sal_Bool GalleryExplorer::FillObjList( const String& rThemeName, List& rObjList )
132 {
133 	Gallery* pGal = ImplGetGallery();
134 
135 	if( pGal )
136 	{
137         SfxListener     aListener;
138         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
139 
140 		if( pTheme )
141 		{
142 			for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
143 				rObjList.Insert( new String( pTheme->GetObjectURL( i ).GetMainURL( INetURLObject::NO_DECODE ) ), LIST_APPEND );
144 
145 			pGal->ReleaseTheme( pTheme, aListener );
146 		}
147 	}
148 
149 	return( rObjList.Count() > 0 );
150 }
151 
152 // ------------------------------------------------------------------------
153 
154 sal_Bool GalleryExplorer::FillObjList( sal_uIntPtr nThemeId, List& rObjList )
155 {
156 	Gallery* pGal = ImplGetGallery();
157 	return( pGal ? FillObjList( pGal->GetThemeName( nThemeId ), rObjList ) : sal_False );
158 }
159 
160 // ------------------------------------------------------------------------
161 
162 sal_Bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< rtl::OUString >& rList )
163 {
164 	Gallery* pGal = ImplGetGallery();
165 	if( pGal )
166 	{
167         SfxListener     aListener;
168         GalleryTheme*   pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
169 
170         if( pTheme )
171 		{
172 			for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
173 			{
174 				SgaObject*	pObj = pTheme->AcquireObject( i );
175 				if ( pObj )
176 				{
177 					rtl::OUString aTitle( pObj->GetTitle() );
178 					rList.push_back( aTitle );
179 					pTheme->ReleaseObject( pObj );
180 				}
181 			}
182 			pGal->ReleaseTheme( pTheme, aListener );
183 		}
184 	}
185 	return( rList.size() > 0 );
186 }
187 
188 // ------------------------------------------------------------------------
189 
190 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL )
191 {
192 	return InsertURL( rThemeName, rURL, SGA_FORMAT_ALL );
193 }
194 
195 // ------------------------------------------------------------------------
196 
197 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL )
198 {
199 	return InsertURL( nThemeId, rURL, SGA_FORMAT_ALL );
200 }
201 
202 // ------------------------------------------------------------------------
203 
204 sal_Bool GalleryExplorer::InsertURL( const String& rThemeName, const String& rURL, const sal_uIntPtr )
205 {
206 	Gallery*	pGal = ImplGetGallery();
207 	sal_Bool		bRet = sal_False;
208 
209 	if( pGal )
210 	{
211         SfxListener   aListener;
212 		GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
213 
214 		if( pTheme )
215 		{
216 			INetURLObject aURL( rURL );
217 			DBG_ASSERT( aURL.GetProtocol() != INET_PROT_NOT_VALID, "invalid URL" );
218 			bRet = pTheme->InsertURL( aURL );
219 			pGal->ReleaseTheme( pTheme, aListener );
220 		}
221 	}
222 
223 	return bRet;
224 }
225 
226 // ------------------------------------------------------------------------
227 
228 sal_Bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId, const String& rURL, const sal_uIntPtr nSgaFormat )
229 {
230 	Gallery* pGal = ImplGetGallery();
231 	return( pGal ? InsertURL( pGal->GetThemeName( nThemeId ), rURL, nSgaFormat ) : sal_False );
232 }
233 
234 // ------------------------------------------------------------------------
235 
236 sal_uIntPtr GalleryExplorer::GetObjCount( const String& rThemeName )
237 {
238 	Gallery*	pGal = ImplGetGallery();
239 	sal_uIntPtr		nRet = 0;
240 
241 	if( pGal )
242 	{
243         SfxListener     aListener;
244         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
245 
246 		if( pTheme )
247 		{
248 			nRet = pTheme->GetObjectCount();
249 			pGal->ReleaseTheme( pTheme, aListener );
250 		}
251 	}
252 
253 	return nRet;
254 }
255 
256 // ------------------------------------------------------------------------
257 
258 sal_uIntPtr GalleryExplorer::GetObjCount( sal_uIntPtr nThemeId )
259 {
260 	Gallery* pGal = ImplGetGallery();
261 	return( pGal ? GetObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False );
262 }
263 
264 // ------------------------------------------------------------------------
265 
266 sal_Bool GalleryExplorer::GetGraphicObj( const String& rThemeName, sal_uIntPtr nPos,
267 									 Graphic* pGraphic, Bitmap* pThumb,
268 									 sal_Bool bProgress )
269 {
270 	Gallery*	pGal = ImplGetGallery();
271 	sal_Bool		bRet = sal_False;
272 
273 	if( pGal )
274 	{
275         SfxListener     aListener;
276         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
277 
278 		if( pTheme )
279 		{
280 			if( pGraphic )
281 				bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
282 
283 			if( pThumb )
284 				bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress );
285 
286 			pGal->ReleaseTheme( pTheme, aListener );
287 		}
288 	}
289 
290 	return bRet;
291 }
292 
293 // ------------------------------------------------------------------------
294 
295 sal_Bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos,
296 									 Graphic* pGraphic, Bitmap* pThumb,
297 									 sal_Bool bProgress )
298 {
299 	Gallery* pGal = ImplGetGallery();
300 	return( pGal ? GetGraphicObj( pGal->GetThemeName( nThemeId ), nPos, pGraphic, pThumb, bProgress ) : sal_False );
301 }
302 
303 // ------------------------------------------------------------------------
304 
305 sal_Bool GalleryExplorer::InsertGraphicObj( const String& rThemeName, const Graphic& rGraphic )
306 {
307 	Gallery*	pGal = ImplGetGallery();
308 	sal_Bool		bRet = sal_False;
309 
310 	if( pGal )
311 	{
312         SfxListener     aListener;
313         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
314 
315 		if( pTheme )
316 		{
317 			bRet = pTheme->InsertGraphic( rGraphic );
318 			pGal->ReleaseTheme( pTheme, aListener );
319 		}
320 	}
321 
322 	return bRet;
323 }
324 
325 // ------------------------------------------------------------------------
326 
327 sal_Bool GalleryExplorer::InsertGraphicObj( sal_uIntPtr nThemeId, const Graphic& rGraphic )
328 {
329 	Gallery* pGal = ImplGetGallery();
330 	return( pGal ? InsertGraphicObj( pGal->GetThemeName( nThemeId ), rGraphic ) : sal_False );
331 }
332 
333 // ------------------------------------------------------------------------
334 
335 sal_uIntPtr GalleryExplorer::GetSdrObjCount( const String& rThemeName )
336 {
337 	Gallery*	pGal = ImplGetGallery();
338 	sal_uIntPtr		nRet = 0;
339 
340 	if( pGal )
341 	{
342         SfxListener     aListener;
343         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
344 
345 		if( pTheme )
346 		{
347 			for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
348 				if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
349 					nRet++;
350 
351 			pGal->ReleaseTheme( pTheme, aListener );
352 		}
353 	}
354 
355 	return nRet;
356 }
357 
358 // ------------------------------------------------------------------------
359 
360 sal_uIntPtr GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId  )
361 {
362 	Gallery* pGal = ImplGetGallery();
363 	return( pGal ? GetSdrObjCount( pGal->GetThemeName( nThemeId ) ) : sal_False );
364 }
365 
366 // ------------------------------------------------------------------------
367 
368 sal_Bool GalleryExplorer::GetSdrObj( const String& rThemeName, sal_uIntPtr nSdrModelPos,
369 								 SdrModel* pModel, Bitmap* pThumb )
370 {
371 	Gallery*	pGal = ImplGetGallery();
372 	sal_Bool		bRet = sal_False;
373 
374 	if( pGal )
375 	{
376         SfxListener     aListener;
377         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
378 
379 		if( pTheme )
380 		{
381 			for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(), nActPos = 0; ( i < nCount ) && !bRet; i++ )
382 			{
383 				if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
384 				{
385 					if( nActPos++ == nSdrModelPos )
386 					{
387 						if( pModel )
388 							bRet = bRet || pTheme->GetModel( i, *pModel, sal_False );
389 
390 						if( pThumb )
391 							bRet = bRet || pTheme->GetThumb( i, *pThumb );
392 					}
393 				}
394 			}
395 
396 			pGal->ReleaseTheme( pTheme, aListener );
397 		}
398 	}
399 
400 	return bRet;
401 }
402 
403 // ------------------------------------------------------------------------
404 
405 sal_Bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId, sal_uIntPtr nSdrModelPos,
406 								 SdrModel* pModel, Bitmap* pThumb )
407 {
408 	Gallery* pGal = ImplGetGallery();
409 	return( pGal ? GetSdrObj( pGal->GetThemeName( nThemeId ), nSdrModelPos, pModel, pThumb ) : sal_False );
410 }
411 
412 // ------------------------------------------------------------------------
413 
414 sal_Bool GalleryExplorer::InsertSdrObj( const String& rThemeName, FmFormModel& rModel )
415 {
416 	Gallery*	pGal = ImplGetGallery();
417 	sal_Bool		bRet = sal_False;
418 
419 	if( pGal )
420 	{
421         SfxListener     aListener;
422         GalleryTheme*   pTheme = pGal->AcquireTheme( rThemeName, aListener );
423 
424 		if( pTheme )
425 		{
426 			bRet = pTheme->InsertModel( rModel );
427 			pGal->ReleaseTheme( pTheme, aListener );
428 		}
429 	}
430 
431 	return bRet;
432 }
433 
434 // ------------------------------------------------------------------------
435 
436 sal_Bool GalleryExplorer::InsertSdrObj( sal_uIntPtr nThemeId, FmFormModel& rModel )
437 {
438 	Gallery* pGal = ImplGetGallery();
439 	return( pGal ? InsertSdrObj( pGal->GetThemeName( nThemeId ), rModel ) : sal_False );
440 }
441 
442 // -----------------------------------------------------------------------------
443 
444 sal_Bool GalleryExplorer::BeginLocking( const String& rThemeName )
445 {
446 	Gallery*	pGal = ImplGetGallery();
447 	sal_Bool		bRet = sal_False;
448 
449 	if( pGal )
450 	{
451 		GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aLockListener );
452 
453 		if( pTheme )
454         {
455             pTheme->LockTheme();
456 			bRet = sal_True;
457         }
458 	}
459 
460 	return bRet;
461 }
462 
463 // -----------------------------------------------------------------------------
464 
465 sal_Bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId )
466 {
467 	Gallery* pGal = ImplGetGallery();
468 	return( pGal ? BeginLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
469 }
470 
471 // -----------------------------------------------------------------------------
472 
473 sal_Bool GalleryExplorer::EndLocking( const String& rThemeName )
474 {
475 	Gallery*	pGal = ImplGetGallery();
476 	sal_Bool		bRet = sal_False;
477 
478 	if( pGal )
479 	{
480         SfxListener   aListener;
481 		GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
482 
483 		if( pTheme )
484 		{
485             const sal_Bool bReleaseLockedTheme = pTheme->UnlockTheme();
486 
487 			// release acquired theme
488 			pGal->ReleaseTheme( pTheme, aListener );
489 
490             if( bReleaseLockedTheme )
491             {
492                 // release locked theme
493                 pGal->ReleaseTheme( pTheme, aLockListener );
494                 bRet = sal_True;
495             }
496 		}
497 	}
498 
499 	return bRet;
500 }
501 
502 // -----------------------------------------------------------------------------
503 
504 sal_Bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId )
505 {
506 	Gallery* pGal = ImplGetGallery();
507 	return( pGal ? EndLocking( pGal->GetThemeName( nThemeId ) ) : sal_False );
508 }
509 
510 // -----------------------------------------------------------------------------
511 
512 sal_Bool GalleryExplorer::DrawCentered( OutputDevice* pOut, const FmFormModel& rModel )
513 {
514 	return SgaObjectSvDraw::DrawCentered( pOut, rModel );
515 }
516