1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <algorithm>
#include "unogaltheme.hxx"
#include "unogalitem.hxx"
#include <svx/galtheme.hxx>
#include <svx/gallery1.hxx>
#include <svx/galmisc.hxx>
#include <svx/fmmodel.hxx>
#include <svx/svdpage.hxx>
#include <svx/unopage.hxx>
#include <vcl/svapp.hxx>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <cppuhelper/supportsservice.hxx>
using namespace ::com::sun::star;
namespace unogallery {
GalleryTheme::GalleryTheme( const OUString& rThemeName )
{
mpGallery = ::Gallery::GetGalleryInstance();
mpTheme = ( mpGallery ? mpGallery->AcquireTheme( rThemeName, *this ) : nullptr );
if( mpGallery )
StartListening( *mpGallery );
}
GalleryTheme::~GalleryTheme()
{
const SolarMutexGuard aGuard;
DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" );
implReleaseItems( nullptr );
if( mpGallery )
{
EndListening( *mpGallery );
if( mpTheme )
mpGallery->ReleaseTheme( mpTheme, *this );
}
}
OUString SAL_CALL GalleryTheme::getImplementationName()
{
return "com.sun.star.comp.gallery.GalleryTheme";
}
sal_Bool SAL_CALL GalleryTheme::supportsService( const OUString& ServiceName )
{
return cppu::supportsService( this, ServiceName );
}
uno::Sequence< OUString > SAL_CALL GalleryTheme::getSupportedServiceNames()
{
return { "com.sun.star.gallery.GalleryTheme" };
}
uno::Sequence< uno::Type > SAL_CALL GalleryTheme::getTypes()
{
static const uno::Sequence aTypes {
cppu::UnoType<lang::XServiceInfo>::get(),
cppu::UnoType<lang::XTypeProvider>::get(),
cppu::UnoType<container::XElementAccess>::get(),
cppu::UnoType<container::XIndexAccess>::get(),
cppu::UnoType<gallery::XGalleryTheme>::get(),
};
return aTypes;
}
uno::Sequence< sal_Int8 > SAL_CALL GalleryTheme::getImplementationId()
{
return css::uno::Sequence<sal_Int8>();
}
uno::Type SAL_CALL GalleryTheme::getElementType()
{
return cppu::UnoType<gallery::XGalleryItem>::get();
}
sal_Bool SAL_CALL GalleryTheme::hasElements()
{
const SolarMutexGuard aGuard;
return( ( mpTheme != nullptr ) && ( mpTheme->GetObjectCount() > 0 ) );
}
sal_Int32 SAL_CALL GalleryTheme::getCount()
{
const SolarMutexGuard aGuard;
return( mpTheme ? mpTheme->GetObjectCount() : 0 );
}
uno::Any SAL_CALL GalleryTheme::getByIndex( ::sal_Int32 nIndex )
{
const SolarMutexGuard aGuard;
uno::Any aRet;
if( mpTheme )
{
if( ( nIndex < 0 ) || ( nIndex >= getCount() ) )
{
throw lang::IndexOutOfBoundsException();
}
const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( nIndex );
if( pObj )
aRet <<= uno::Reference< gallery::XGalleryItem >( new GalleryItem( *this, *pObj ) );
}
return aRet;
}
OUString SAL_CALL GalleryTheme::getName( )
{
const SolarMutexGuard aGuard;
OUString aRet;
if( mpTheme )
aRet = mpTheme->GetName();
return aRet;
}
void SAL_CALL GalleryTheme::update( )
{
const SolarMutexGuard aGuard;
if( mpTheme )
{
const Link<const INetURLObject&, void> aDummyLink;
mpTheme->Actualize( aDummyLink );
}
}
::sal_Int32 SAL_CALL GalleryTheme::insertURLByIndex(<--- The function 'insertURLByIndex' is never used.
const OUString& rURL, ::sal_Int32 nIndex )
{
const SolarMutexGuard aGuard;
sal_Int32 nRet = -1;
if( mpTheme )
{
try
{
const INetURLObject aURL( rURL );
nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
if( ( aURL.GetProtocol() != INetProtocol::NotValid ) && mpTheme->InsertURL( aURL, nIndex ) )
{
const GalleryObject* pObj = mpTheme->ImplGetGalleryObject( aURL );
if( pObj )
nRet = mpTheme->ImplGetGalleryObjectPos( pObj );
}
}
catch( ... )
{
}
}
return nRet;
}
::sal_Int32 SAL_CALL GalleryTheme::insertGraphicByIndex(
const uno::Reference< graphic::XGraphic >& rxGraphic, sal_Int32 nIndex )
{
const SolarMutexGuard aGuard;
sal_Int32 nRet = -1;
if( mpTheme )
{
try
{
const Graphic aGraphic( rxGraphic );
nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
if( mpTheme->InsertGraphic( aGraphic, nIndex ) )
nRet = nIndex;
}
catch( ... )
{
}
}
return nRet;
}
::sal_Int32 SAL_CALL GalleryTheme::insertDrawingByIndex(
const uno::Reference< lang::XComponent >& Drawing, sal_Int32 nIndex )
{
const SolarMutexGuard aGuard;
sal_Int32 nRet = -1;
if( mpTheme )
{
GalleryDrawingModel* pModel = comphelper::getUnoTunnelImplementation<GalleryDrawingModel>( Drawing );
if( pModel && dynamic_cast<const FmFormModel*>(pModel->GetDoc()) )
{
// Here we're inserting something that's already a gallery theme drawing
nIndex = ::std::max( ::std::min( nIndex, getCount() ), sal_Int32( 0 ) );
if( mpTheme->InsertModel( *static_cast< FmFormModel* >( pModel->GetDoc() ), nIndex ) )
nRet = nIndex;
}
else if (!pModel)
{
// #i80184# Try to do the right thing and make a Gallery drawing out
// of an ordinary Drawing if possible.
try
{
uno::Reference< drawing::XDrawPagesSupplier > xDrawPagesSupplier( Drawing, uno::UNO_QUERY_THROW );
uno::Reference< drawing::XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), uno::UNO_SET_THROW );
uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
SvxDrawPage* pUnoPage = xPage.is() ? comphelper::getUnoTunnelImplementation<SvxDrawPage>( xPage ) : nullptr;
SdrModel* pOrigModel = pUnoPage ? &pUnoPage->GetSdrPage()->getSdrModelFromSdrPage() : nullptr;
SdrPage* pOrigPage = pUnoPage ? pUnoPage->GetSdrPage() : nullptr;
if (pOrigPage && pOrigModel)
{
FmFormModel* pTmpModel = new FmFormModel(&pOrigModel->GetItemPool());
// Clone to new target SdrModel
SdrPage* pNewPage(pOrigPage->CloneSdrPage(*pTmpModel));
pTmpModel->InsertPage(pNewPage, 0);
uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pTmpModel ) );
pTmpModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
nRet = insertDrawingByIndex( xDrawing, nIndex );
return nRet;
}
}
catch (...)
{
}
}
}
return nRet;
}
void SAL_CALL GalleryTheme::removeByIndex( sal_Int32 nIndex )
{
const SolarMutexGuard aGuard;
if( mpTheme )
{
if( ( nIndex < 0 ) || ( nIndex >= getCount() ) )
throw lang::IndexOutOfBoundsException();
mpTheme->RemoveObject( nIndex );
}
}
void GalleryTheme::Notify( SfxBroadcaster&, const SfxHint& rHint )
{
const SolarMutexGuard aGuard;
const GalleryHint& rGalleryHint = static_cast< const GalleryHint& >( rHint );
switch( rGalleryHint.GetType() )
{
case GalleryHintType::CLOSE_THEME:
{
DBG_ASSERT( !mpTheme || mpGallery, "Theme is living without Gallery" );
implReleaseItems( nullptr );
if( mpGallery && mpTheme )
{
mpGallery->ReleaseTheme( mpTheme, *this );
mpTheme = nullptr;
}
}
break;
case GalleryHintType::CLOSE_OBJECT:
{
GalleryObject* pObj = static_cast< GalleryObject* >( rGalleryHint.GetData1() );
if( pObj )
implReleaseItems( pObj );
}
break;
default:
break;
}
}
void GalleryTheme::implReleaseItems( GalleryObject const * pObj )
{
const SolarMutexGuard aGuard;
for( GalleryItemVector::iterator aIter = maItemVector.begin(); aIter != maItemVector.end(); )
{
if( !pObj || ( (*aIter)->implGetObject() == pObj ) )
{
(*aIter)->implSetInvalid();
aIter = maItemVector.erase( aIter );
}
else
++aIter;
}
}
void GalleryTheme::implRegisterGalleryItem( ::unogallery::GalleryItem& rItem )
{
const SolarMutexGuard aGuard;
maItemVector.push_back( &rItem );
}
void GalleryTheme::implDeregisterGalleryItem( ::unogallery::GalleryItem& rItem )
{
const SolarMutexGuard aGuard;
maItemVector.erase(std::remove(maItemVector.begin(), maItemVector.end(), &rItem), maItemVector.end());
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|