1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
31 class theLockListener
: public rtl::Static
< SfxListener
, theLockListener
> {};
34 // - GalleryExplorer -
36 bool GalleryExplorer::FillThemeList( std::vector
<OUString
>& rThemeList
)
38 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
42 for( sal_uIntPtr i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
44 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
46 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
47 rThemeList
.push_back(pEntry
->GetThemeName());
51 return !rThemeList
.empty();
54 bool GalleryExplorer::FillObjList( const OUString
& rThemeName
, std::vector
<OUString
> &rObjList
)
56 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
60 SfxListener aListener
;
61 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
65 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
66 rObjList
.push_back( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::NO_DECODE
) );
68 pGal
->ReleaseTheme( pTheme
, aListener
);
72 return !rObjList
.empty();
75 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<OUString
> &rObjList
)
77 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
82 return FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
);
85 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< OUString
>& rList
)
87 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
90 SfxListener aListener
;
91 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
95 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
97 SgaObject
* pObj
= pTheme
->AcquireObject( i
);
100 OUString
aTitle( pObj
->GetTitle() );
101 rList
.push_back( aTitle
);
102 GalleryTheme::ReleaseObject( pObj
);
105 pGal
->ReleaseTheme( pTheme
, aListener
);
108 return !rList
.empty();
111 bool GalleryExplorer::InsertURL( const OUString
& rThemeName
, const OUString
& rURL
)
113 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
118 SfxListener aListener
;
119 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
123 INetURLObject
aURL( rURL
);
124 DBG_ASSERT( aURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
125 bRet
= pTheme
->InsertURL( aURL
);
126 pGal
->ReleaseTheme( pTheme
, aListener
);
133 bool GalleryExplorer::InsertURL( sal_uIntPtr nThemeId
, const OUString
& rURL
)
135 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
136 return pGal
&& InsertURL( pGal
->GetThemeName( nThemeId
), rURL
);
139 bool GalleryExplorer::GetGraphicObj( const OUString
& rThemeName
, sal_uIntPtr nPos
,
140 Graphic
* pGraphic
, BitmapEx
* pThumb
,
143 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
148 SfxListener aListener
;
149 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
154 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
, bProgress
);
157 bRet
= bRet
|| pTheme
->GetThumb( nPos
, *pThumb
, bProgress
);
159 pGal
->ReleaseTheme( pTheme
, aListener
);
166 bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId
, sal_uIntPtr nPos
,
167 Graphic
* pGraphic
, BitmapEx
* pThumb
,
170 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
171 return pGal
&& GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
, pThumb
, bProgress
);
174 sal_uIntPtr
GalleryExplorer::GetSdrObjCount( const OUString
& rThemeName
)
176 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
177 sal_uIntPtr nRet
= 0;
181 SfxListener aListener
;
182 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
186 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
187 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
190 pGal
->ReleaseTheme( pTheme
, aListener
);
197 sal_uIntPtr
GalleryExplorer::GetSdrObjCount( sal_uIntPtr nThemeId
)
199 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
200 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : 0 );
203 bool GalleryExplorer::GetSdrObj( const OUString
& rThemeName
, sal_uIntPtr nSdrModelPos
,
204 SdrModel
* pModel
, BitmapEx
* pThumb
)
206 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
211 SfxListener aListener
;
212 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
216 for( sal_uIntPtr i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
218 if( SGA_OBJ_SVDRAW
== pTheme
->GetObjectKind( i
) )
220 if( nActPos
++ == nSdrModelPos
)
223 bRet
= bRet
|| pTheme
->GetModel( i
, *pModel
, false );
226 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
231 pGal
->ReleaseTheme( pTheme
, aListener
);
238 bool GalleryExplorer::GetSdrObj( sal_uIntPtr nThemeId
, sal_uIntPtr nSdrModelPos
,
239 SdrModel
* pModel
, BitmapEx
* pThumb
)
241 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
242 return pGal
&& GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
);
245 bool GalleryExplorer::BeginLocking( const OUString
& rThemeName
)
247 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
252 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener::get() );
264 bool GalleryExplorer::BeginLocking( sal_uIntPtr nThemeId
)
266 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
267 return pGal
&& BeginLocking( pGal
->GetThemeName( nThemeId
) );
270 bool GalleryExplorer::EndLocking( const OUString
& rThemeName
)
272 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
277 SfxListener aListener
;
278 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
282 const bool bReleaseLockedTheme
= pTheme
->UnlockTheme();
284 // release acquired theme
285 pGal
->ReleaseTheme( pTheme
, aListener
);
287 if( bReleaseLockedTheme
)
289 // release locked theme
290 pGal
->ReleaseTheme( pTheme
, theLockListener::get() );
299 bool GalleryExplorer::EndLocking( sal_uIntPtr nThemeId
)
301 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
302 return pGal
&& EndLocking( pGal
->GetThemeName( nThemeId
) );
305 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */