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