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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
|
/* -*- 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 <rtl/ref.hxx>
#include <rtl/bootstrap.hxx>
#include <cppuhelper/bootstrap.hxx>
#include <cppuhelper/servicefactory.hxx>
#include <cppuhelper/interfacecontainer.hxx>
#include <cppuhelper/compbase1.hxx>
#include <cppuhelper/compbase2.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/broadcasthelper.hxx>
#include <comphelper/anytostring.hxx>
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/rendering/XCanvas.hpp>
#include <com/sun/star/rendering/XSpriteCanvas.hpp>
#include <com/sun/star/presentation/SlideShow.hpp>
#include <com/sun/star/presentation/XSlideShowView.hpp>
#include "com/sun/star/animations/TransitionType.hpp"
#include "com/sun/star/animations/TransitionSubType.hpp"
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/tools/canvastools.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <cppcanvas/vclfactory.hxx>
#include <cppcanvas/basegfxfactory.hxx>
#include <cppcanvas/polypolygon.hxx>
#include <canvas/canvastools.hxx>
#include <vcl/dialog.hxx>
#include <vcl/timer.hxx>
#include <vcl/window.hxx>
#include <vcl/svapp.hxx>
#include <stdio.h>
#include <unistd.h>
using namespace ::com::sun::star;
namespace {
typedef ::cppu::WeakComponentImplHelper1< presentation::XSlideShowView > ViewBase;
class View : public ::comphelper::OBaseMutex,
public ViewBase
{
public:
explicit View( const uno::Reference< rendering::XSpriteCanvas >& rCanvas ) :
ViewBase( m_aMutex ),
mxCanvas( rCanvas ),
maPaintListeners( m_aMutex ),
maTransformationListeners( m_aMutex ),
maMouseListeners( m_aMutex ),
maMouseMotionListeners( m_aMutex ),
maTransform(),
maSize()
{
}
void resize( const ::Size& rNewSize )
{
maSize = rNewSize;
const sal_Int32 nSize( std::min( rNewSize.Width(), rNewSize.Height() ) - 10);
maTransform = basegfx::tools::createScaleTranslateB2DHomMatrix(
nSize, nSize, (rNewSize.Width() - nSize) / 2, (rNewSize.Height() - nSize) / 2);
lang::EventObject aEvent( *this );
maTransformationListeners.notifyEach( &util::XModifyListener::modified,
aEvent );
}
void repaint()
{
awt::PaintEvent aEvent( *this,
awt::Rectangle(),
0 );
maPaintListeners.notifyEach( &awt::XPaintListener::windowPaint,
aEvent );
}
private:
virtual ~View() {}
virtual uno::Reference< rendering::XSpriteCanvas > SAL_CALL getCanvas( ) throw (uno::RuntimeException)
{
return mxCanvas;
}
virtual void SAL_CALL clear( ) throw (uno::RuntimeException)
{
::basegfx::B2DPolygon aPoly( ::basegfx::tools::createPolygonFromRect(
::basegfx::B2DRectangle(0.0,0.0,
maSize.Width(),
maSize.Height() )));
::cppcanvas::SpriteCanvasSharedPtr pCanvas(
::cppcanvas::VCLFactory::getInstance().createSpriteCanvas( mxCanvas ));
if( !pCanvas )
return;
::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
::cppcanvas::BaseGfxFactory::getInstance().createPolyPolygon( pCanvas,
aPoly ) );
if( !pPolyPoly )
return;
if( pPolyPoly )
{
pPolyPoly->setRGBAFillColor( 0x808080FFU );
pPolyPoly->draw();
}
}
virtual geometry::AffineMatrix2D SAL_CALL getTransformation( ) throw (uno::RuntimeException)
{
geometry::AffineMatrix2D aRes;
return basegfx::unotools::affineMatrixFromHomMatrix( aRes,
maTransform );
}
virtual void SAL_CALL addTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
{
maTransformationListeners.addInterface( xListener );
}
virtual void SAL_CALL removeTransformationChangedListener( const uno::Reference< util::XModifyListener >& xListener ) throw (uno::RuntimeException)
{
maTransformationListeners.removeInterface( xListener );
}
virtual void SAL_CALL addPaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
{
maPaintListeners.addInterface( xListener );
}
virtual void SAL_CALL removePaintListener( const uno::Reference< awt::XPaintListener >& xListener ) throw (uno::RuntimeException)
{
maPaintListeners.removeInterface( xListener );
}
virtual void SAL_CALL addMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
{
maMouseListeners.addInterface( xListener );
}
virtual void SAL_CALL removeMouseListener( const uno::Reference< awt::XMouseListener >& xListener ) throw (uno::RuntimeException)
{
maMouseListeners.removeInterface( xListener );
}
virtual void SAL_CALL addMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
{
maMouseMotionListeners.addInterface( xListener );
}
virtual void SAL_CALL removeMouseMotionListener( const uno::Reference< awt::XMouseMotionListener >& xListener ) throw (uno::RuntimeException)
{
maMouseMotionListeners.removeInterface( xListener );
}
virtual void SAL_CALL setMouseCursor( ::sal_Int16 /*nPointerShape*/ ) throw (uno::RuntimeException)
{
}
virtual awt::Rectangle SAL_CALL getCanvasArea( ) throw (uno::RuntimeException)
{
return awt::Rectangle(0,0,maSize.Width(),maSize.Height());
}
uno::Reference< rendering::XSpriteCanvas > mxCanvas;
::cppu::OInterfaceContainerHelper maPaintListeners;
::cppu::OInterfaceContainerHelper maTransformationListeners;
::cppu::OInterfaceContainerHelper maMouseListeners;
::cppu::OInterfaceContainerHelper maMouseMotionListeners;
basegfx::B2DHomMatrix maTransform;
Size maSize;
};
typedef ::cppu::WeakComponentImplHelper2< drawing::XDrawPage,
beans::XPropertySet > SlideBase;
class DummySlide : public ::comphelper::OBaseMutex,
public SlideBase
{
public:
DummySlide() : SlideBase( m_aMutex ) {}
private:
// XDrawPage
virtual void SAL_CALL add( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
{
}
virtual void SAL_CALL remove( const uno::Reference< drawing::XShape >& /*xShape*/ ) throw (uno::RuntimeException)
{
}
virtual ::sal_Int32 SAL_CALL getCount( ) throw (uno::RuntimeException)
{
return 0;
}
virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 /*Index*/ ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
{
return uno::Any();
}
virtual uno::Type SAL_CALL getElementType( ) throw (uno::RuntimeException)
{
return uno::Type();
}
virtual ::sal_Bool SAL_CALL hasElements( ) throw (uno::RuntimeException)
{
return false;
}
// XPropertySet
virtual uno::Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw (uno::RuntimeException)
{
return uno::Reference< beans::XPropertySetInfo >();
}
virtual void SAL_CALL setPropertyValue( const ::rtl::OUString& /*aPropertyName*/,
const uno::Any& /*aValue*/ ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
{
}
virtual uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
typedef ::canvas::tools::ValueMap< sal_Int16 > PropMapT;
// fixed PropertyValue map
static PropMapT::MapEntry lcl_propertyMap[] =
{
{"Height", 100},
{"MinimalFrameNumber", 50},
{"TransitionDuration", 10},
{"TransitionSubtype", animations::TransitionSubType::FROMTOPLEFT},
{"TransitionType", animations::TransitionType::PUSHWIPE},
{"Width", 100}
};
static PropMapT aMap( lcl_propertyMap,
SAL_N_ELEMENTS(lcl_propertyMap),
true );
sal_Int16 aRes;
if( !aMap.lookup( PropertyName, aRes ))
return uno::Any();
return uno::makeAny(aRes);
}
virtual void SAL_CALL addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}
virtual void SAL_CALL removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/,
const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}
virtual void SAL_CALL addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}
virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/,
const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
{
}
};
class DemoApp : public Application
{
public:
virtual void Main();
virtual sal_uInt16 Exception( sal_uInt16 nError );
};
class ChildWindow : public Window
{
public:
ChildWindow( Window* pParent );
virtual ~ChildWindow();
virtual void Paint( const Rectangle& rRect );
virtual void Resize();
void setShow( const uno::Reference< presentation::XSlideShow >& rShow ) { mxShow = rShow; init(); }
private:
void init();
rtl::Reference< View > mpView;
uno::Reference< presentation::XSlideShow > mxShow;
};
ChildWindow::ChildWindow( Window* pParent ) :
Window(pParent, WB_CLIPCHILDREN | WB_BORDER| WB_3DLOOK ),
mpView(),
mxShow()
{
EnablePaint( true );
Show();
}
ChildWindow::~ChildWindow()
{
if( mxShow.is() && mpView.is() )
mxShow->removeView( mpView.get() );
}
void ChildWindow::init()
{
try
{
if( !mpView.is() )
{
uno::Reference< rendering::XCanvas > xCanvas( GetCanvas(),
uno::UNO_QUERY_THROW );
uno::Reference< rendering::XSpriteCanvas > xSpriteCanvas( xCanvas,
uno::UNO_QUERY_THROW );
mpView = new View( xSpriteCanvas );
mpView->resize( GetSizePixel() );
if( mxShow.is() )
mxShow->addView( mpView.get() );
}
}
catch (const uno::Exception &e)
{
OSL_TRACE( "Exception '%s' thrown\n" ,
::rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
}
}
void ChildWindow::Paint( const Rectangle& /*rRect*/ )
{
try
{
if( mpView.is() )
mpView->repaint();
}
catch (const uno::Exception &e)
{
OSL_TRACE( "Exception '%s' thrown\n" ,
::rtl::OUStringToOString( e.Message,
RTL_TEXTENCODING_UTF8 ).getStr() );
}
}
void ChildWindow::Resize()
{
if( mpView.is() )
mpView->resize( GetSizePixel() );
}
class DemoWindow : public Dialog
{
public:
DemoWindow();
virtual void Paint( const Rectangle& rRect );
virtual void Resize();
private:
void init();
DECL_LINK( updateHdl, Timer* );
ChildWindow maLeftChild;
ChildWindow maRightTopChild;
ChildWindow maRightBottomChild;
uno::Reference< presentation::XSlideShow > mxShow;
AutoTimer maUpdateTimer;
bool mbSlideDisplayed;
};
DemoWindow::DemoWindow() :
Dialog((Window*)NULL),
maLeftChild( this ),
maRightTopChild( this ),
maRightBottomChild( this ),
mxShow(),
maUpdateTimer(),
mbSlideDisplayed( false )
{
SetText( rtl::OUString("Slideshow Demo" ) );
SetSizePixel( Size( 640, 480 ) );
EnablePaint( true );
maLeftChild.SetPosSizePixel( Point(), Size(320,480) );
maRightTopChild.SetPosSizePixel( Point(320,0), Size(320,240) );
maRightBottomChild.SetPosSizePixel( Point(320,240), Size(320,240) );
Show();
maUpdateTimer.SetTimeoutHdl(LINK(this, DemoWindow, updateHdl));
maUpdateTimer.SetTimeout( (sal_uLong)30 );
maUpdateTimer.Start();
}
void DemoWindow::init()
{
try
{
if( !mxShow.is() )
{
uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
mxShow.set( presentation::SlideShow::create(xContext),
uno::UNO_QUERY_THROW );
maLeftChild.setShow( mxShow );
maRightTopChild.setShow( mxShow );
maRightBottomChild.setShow( mxShow );
}
if( mxShow.is() && !mbSlideDisplayed )
{
uno::Reference< drawing::XDrawPage > xSlide( new DummySlide );
uno::Reference< drawing::XDrawPages > xDrawPages;
mxShow->displaySlide( xSlide,
uno::Reference< drawing::XDrawPagesSupplier >(),
uno::Reference< animations::XAnimationNode >(),
uno::Sequence< beans::PropertyValue >() );
mxShow->setProperty( beans::PropertyValue(
rtl::OUString("RehearseTimings"),
0,
uno::makeAny( sal_True ),
beans::PropertyState_DIRECT_VALUE ));
mbSlideDisplayed = true;
}
}
catch (const uno::Exception &e)
{
OSL_TRACE( "Exception '%s' thrown\n" ,
::rtl::OUStringToOString( e.Message,
RTL_TEXTENCODING_UTF8 ).getStr() );
}
}
IMPL_LINK_NOARG(DemoWindow, updateHdl)
{
init();
if( mxShow.is() )
{
double nTimeout;
mxShow->update(nTimeout);
}
return 0;
}
void DemoWindow::Paint( const Rectangle& /*rRect*/ )
{
init();
}
void DemoWindow::Resize()
{
// TODO
}
sal_uInt16 DemoApp::Exception( sal_uInt16 nError )
{
switch( nError & EXC_MAJORTYPE )
{
case EXC_RSCNOTLOADED:
Abort( "Error: could not load language resources.\nPlease check your installation.\n" );
break;
}
return 0;
}
void DemoApp::Main()
{
bool bHelp = false;
for( sal_uInt16 i = 0; i < GetCommandLineParamCount(); i++ )
{
::rtl::OUString aParam = GetCommandLineParam( i );
if( aParam == "--help" || aParam == "-h" )
bHelp = true;
}
if( bHelp )
{
printf( "demoshow - life Slideshow testbed\n" );
return;
}
// bootstrap UNO
uno::Reference< lang::XMultiServiceFactory > xFactory;
try
{
uno::Reference< uno::XComponentContext > xCtx = ::cppu::defaultBootstrap_InitialComponentContext();
xFactory = uno::Reference< lang::XMultiServiceFactory >( xCtx->getServiceManager(),
uno::UNO_QUERY );
if( xFactory.is() )
::comphelper::setProcessServiceFactory( xFactory );
}
catch( uno::RuntimeException& )
{
throw;
}
catch( uno::Exception& )
{
OSL_FAIL( rtl::OUStringToOString(
comphelper::anyToString( cppu::getCaughtException() ),
RTL_TEXTENCODING_UTF8 ).getStr() );
}
if( !xFactory.is() )
{
OSL_TRACE( "Could not bootstrap UNO, installation must be in disorder. Exiting." );
exit( 1 );
}
DemoWindow pWindow;
pWindow.Execute();
}
}
DemoApp aApp;
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|