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