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
> {};
35 bool GalleryExplorer::FillThemeList( std::vector
<OUString
>& rThemeList
)
37 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
41 for( sal_uInt32 i
= 0, nCount
= pGal
->GetThemeCount(); i
< nCount
; i
++ )
43 const GalleryThemeEntry
* pEntry
= pGal
->GetThemeInfo( i
);
45 if( pEntry
&& !pEntry
->IsReadOnly() && !pEntry
->IsHidden() )
46 rThemeList
.push_back(pEntry
->GetThemeName());
50 return !rThemeList
.empty();
53 bool GalleryExplorer::FillObjList( const OUString
& rThemeName
, std::vector
<OUString
> &rObjList
)
55 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
59 SfxListener aListener
;
60 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
64 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
65 rObjList
.push_back( pTheme
->GetObjectURL( i
).GetMainURL( INetURLObject::DecodeMechanism::NONE
) );
67 pGal
->ReleaseTheme( pTheme
, aListener
);
71 return !rObjList
.empty();
74 bool GalleryExplorer::FillObjList( const sal_uInt32 nThemeId
, std::vector
<OUString
> &rObjList
)
76 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
81 return FillObjList( pGal
->GetThemeName( nThemeId
), rObjList
);
84 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId
, std::vector
< OUString
>& rList
)
86 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
89 SfxListener aListener
;
90 GalleryTheme
* pTheme
= pGal
->AcquireTheme( pGal
->GetThemeName( nThemeId
), aListener
);
94 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
96 SgaObject
* pObj
= pTheme
->AcquireObject( i
);
99 OUString
aTitle( pObj
->GetTitle() );
100 rList
.push_back( aTitle
);
101 GalleryTheme::ReleaseObject( pObj
);
104 pGal
->ReleaseTheme( pTheme
, aListener
);
107 return !rList
.empty();
110 bool GalleryExplorer::InsertURL( const OUString
& rThemeName
, const OUString
& rURL
)
112 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
117 SfxListener aListener
;
118 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
122 INetURLObject
aURL( rURL
);
123 DBG_ASSERT( aURL
.GetProtocol() != INetProtocol::NotValid
, "invalid URL" );
124 bRet
= pTheme
->InsertURL( aURL
);
125 pGal
->ReleaseTheme( pTheme
, aListener
);
132 bool GalleryExplorer::InsertURL( sal_uInt32 nThemeId
, const OUString
& rURL
)
134 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
135 return pGal
&& InsertURL( pGal
->GetThemeName( nThemeId
), rURL
);
138 bool GalleryExplorer::GetGraphicObj( const OUString
& rThemeName
, sal_uInt32 nPos
,
139 Graphic
* pGraphic
, BitmapEx
* pThumb
,
142 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
147 SfxListener aListener
;
148 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
153 bRet
= bRet
|| pTheme
->GetGraphic( nPos
, *pGraphic
, bProgress
);
156 bRet
= bRet
|| pTheme
->GetThumb( nPos
, *pThumb
);
158 pGal
->ReleaseTheme( pTheme
, aListener
);
165 bool GalleryExplorer::GetGraphicObj( sal_uInt32 nThemeId
, sal_uInt32 nPos
,
166 Graphic
* pGraphic
, BitmapEx
* pThumb
,
169 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
170 return pGal
&& GetGraphicObj( pGal
->GetThemeName( nThemeId
), nPos
, pGraphic
, pThumb
, bProgress
);
173 sal_uInt32
GalleryExplorer::GetSdrObjCount( const OUString
& rThemeName
)
175 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
180 SfxListener aListener
;
181 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
185 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(); i
< nCount
; i
++ )
186 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
189 pGal
->ReleaseTheme( pTheme
, aListener
);
196 sal_uInt32
GalleryExplorer::GetSdrObjCount( sal_uInt32 nThemeId
)
198 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
199 return( pGal
? GetSdrObjCount( pGal
->GetThemeName( nThemeId
) ) : 0 );
202 bool GalleryExplorer::GetSdrObj( const OUString
& rThemeName
, sal_uInt32 nSdrModelPos
,
203 SdrModel
* pModel
, BitmapEx
* pThumb
)
205 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
210 SfxListener aListener
;
211 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
215 for( sal_uInt32 i
= 0, nCount
= pTheme
->GetObjectCount(), nActPos
= 0; ( i
< nCount
) && !bRet
; i
++ )
217 if( SgaObjKind::SvDraw
== pTheme
->GetObjectKind( i
) )
219 if( nActPos
++ == nSdrModelPos
)
222 bRet
= bRet
|| pTheme
->GetModel( i
, *pModel
);
225 bRet
= bRet
|| pTheme
->GetThumb( i
, *pThumb
);
230 pGal
->ReleaseTheme( pTheme
, aListener
);
237 bool GalleryExplorer::GetSdrObj( sal_uInt32 nThemeId
, sal_uInt32 nSdrModelPos
,
238 SdrModel
* pModel
, BitmapEx
* pThumb
)
240 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
241 return pGal
&& GetSdrObj( pGal
->GetThemeName( nThemeId
), nSdrModelPos
, pModel
, pThumb
);
244 bool GalleryExplorer::BeginLocking( const OUString
& rThemeName
)
246 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
251 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, theLockListener::get() );
263 bool GalleryExplorer::BeginLocking( sal_uInt32 nThemeId
)
265 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
266 return pGal
&& BeginLocking( pGal
->GetThemeName( nThemeId
) );
269 bool GalleryExplorer::EndLocking( const OUString
& rThemeName
)
271 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
276 SfxListener aListener
;
277 GalleryTheme
* pTheme
= pGal
->AcquireTheme( rThemeName
, aListener
);
281 const bool bReleaseLockedTheme
= pTheme
->UnlockTheme();
283 // release acquired theme
284 pGal
->ReleaseTheme( pTheme
, aListener
);
286 if( bReleaseLockedTheme
)
288 // release locked theme
289 pGal
->ReleaseTheme( pTheme
, theLockListener::get() );
298 bool GalleryExplorer::EndLocking( sal_uInt32 nThemeId
)
300 Gallery
* pGal
= ::Gallery::GetGalleryInstance();
301 return pGal
&& EndLocking( pGal
->GetThemeName( nThemeId
) );
304 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */