lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / svx / source / gallery2 / galexpl.cxx
blobc19985c2227e7c87a837836c8bde1decd72e5657
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
27 #include "galobj.hxx"
29 namespace
31 class theLockListener : public rtl::Static< SfxListener, theLockListener > {};
34 // - GalleryExplorer -
36 bool GalleryExplorer::FillThemeList( std::vector<OUString>& rThemeList )
38 Gallery* pGal = ::Gallery::GetGalleryInstance();
40 if( pGal )
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();
58 if( pGal )
60 SfxListener aListener;
61 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
63 if( pTheme )
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();
79 if (!pGal)
80 return false;
82 return FillObjList( pGal->GetThemeName( nThemeId ), rObjList );
85 bool GalleryExplorer::FillObjListTitle( const sal_uInt32 nThemeId, std::vector< OUString >& rList )
87 Gallery* pGal = ::Gallery::GetGalleryInstance();
88 if( pGal )
90 SfxListener aListener;
91 GalleryTheme* pTheme = pGal->AcquireTheme( pGal->GetThemeName( nThemeId ), aListener );
93 if( pTheme )
95 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
97 SgaObject* pObj = pTheme->AcquireObject( i );
98 if ( pObj )
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();
114 bool bRet = false;
116 if( pGal )
118 SfxListener aListener;
119 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
121 if( pTheme )
123 INetURLObject aURL( rURL );
124 DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "invalid URL" );
125 bRet = pTheme->InsertURL( aURL );
126 pGal->ReleaseTheme( pTheme, aListener );
130 return bRet;
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,
141 bool bProgress )
143 Gallery* pGal = ::Gallery::GetGalleryInstance();
144 bool bRet = false;
146 if( pGal )
148 SfxListener aListener;
149 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
151 if( pTheme )
153 if( pGraphic )
154 bRet = bRet || pTheme->GetGraphic( nPos, *pGraphic, bProgress );
156 if( pThumb )
157 bRet = bRet || pTheme->GetThumb( nPos, *pThumb, bProgress );
159 pGal->ReleaseTheme( pTheme, aListener );
163 return bRet;
166 bool GalleryExplorer::GetGraphicObj( sal_uIntPtr nThemeId, sal_uIntPtr nPos,
167 Graphic* pGraphic, BitmapEx* pThumb,
168 bool bProgress )
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;
179 if( pGal )
181 SfxListener aListener;
182 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
184 if( pTheme )
186 for( sal_uIntPtr i = 0, nCount = pTheme->GetObjectCount(); i < nCount; i++ )
187 if( SGA_OBJ_SVDRAW == pTheme->GetObjectKind( i ) )
188 nRet++;
190 pGal->ReleaseTheme( pTheme, aListener );
194 return nRet;
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();
207 bool bRet = false;
209 if( pGal )
211 SfxListener aListener;
212 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
214 if( pTheme )
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 )
222 if( pModel )
223 bRet = bRet || pTheme->GetModel( i, *pModel, false );
225 if( pThumb )
226 bRet = bRet || pTheme->GetThumb( i, *pThumb );
231 pGal->ReleaseTheme( pTheme, aListener );
235 return bRet;
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();
248 bool bRet = false;
250 if( pGal )
252 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, theLockListener::get() );
254 if( pTheme )
256 pTheme->LockTheme();
257 bRet = true;
261 return bRet;
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();
273 bool bRet = false;
275 if( pGal )
277 SfxListener aListener;
278 GalleryTheme* pTheme = pGal->AcquireTheme( rThemeName, aListener );
280 if( pTheme )
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() );
291 bRet = true;
296 return bRet;
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: */