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 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626
|
/* -*- 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 "slideshowviewimpl.hxx"
#include "slideshowimpl.hxx"
#include <sdpage.hxx>
#include <vcl/svapp.hxx>
#include <com/sun/star/awt/Pointer.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/awt/XWindowPeer.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <cppcanvas/vclfactory.hxx>
#include <cppcanvas/basegfxfactory.hxx>
#include <basegfx/utils/canvastools.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <comphelper/processfactory.hxx>
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::WeakReference;
using ::com::sun::star::uno::Exception;
using namespace ::com::sun::star;
namespace sd
{
void SlideShowViewMouseListeners::notify( std::unique_lock<std::mutex>& rGuard, const WrappedMouseEvent& rEvent )
{
forEach(rGuard,
[&rEvent] (const Reference<css::awt::XMouseListener>& rListener)
{
switch( rEvent.meType )
{
case WrappedMouseEvent::PRESSED:
rListener->mousePressed( rEvent.maEvent );
break;
case WrappedMouseEvent::RELEASED:
rListener->mouseReleased( rEvent.maEvent );
break;
case WrappedMouseEvent::ENTERED:
rListener->mouseEntered( rEvent.maEvent );
break;
case WrappedMouseEvent::EXITED:
rListener->mouseExited( rEvent.maEvent );
break;
}
});
}
void SlideShowViewMouseMotionListeners::notify( std::unique_lock<std::mutex>& rGuard,const WrappedMouseMotionEvent& rEvent )
{
forEach(rGuard,
[&rEvent] (const Reference< awt::XMouseMotionListener >& rListener)
{
switch( rEvent.meType )
{
case WrappedMouseMotionEvent::DRAGGED:
rListener->mouseDragged( rEvent.maEvent );
break;
case WrappedMouseMotionEvent::MOVED:
rListener->mouseMoved( rEvent.maEvent );
break;
}
});
}
// SlideShowView
SlideShowView::SlideShowView( ShowWindow& rOutputWindow,
SdDrawDocument* pDoc,
AnimationMode eAnimationMode,
SlideshowImpl* pSlideShow,
bool bFullScreen )
: mpCanvas( ::cppcanvas::VCLFactory::createSpriteCanvas( rOutputWindow ) ),
mxWindow( VCLUnoHelper::GetInterface( &rOutputWindow ), uno::UNO_SET_THROW ),
mxWindowPeer( mxWindow, uno::UNO_QUERY_THROW ),
mpSlideShow( pSlideShow ),
mrOutputWindow( rOutputWindow ),
mpDoc( pDoc ),
mbIsMouseMotionListener( false ),
meAnimationMode( eAnimationMode ),
mbFirstPaint( true ),
mbMousePressedEaten( false )
{
mxWindow->addWindowListener( this );
mxWindow->addMouseListener( this );
mxPointer = awt::Pointer::create( ::comphelper::getProcessComponentContext() );
getTransformation();
// #i48939# only switch on kind of hacky scroll optimization, when
// running fullscreen. this minimizes the probability that other
// windows partially cover the show.
if( bFullScreen )
{
try
{
Reference< beans::XPropertySet > xCanvasProps( getCanvas(),
uno::UNO_QUERY_THROW );
xCanvasProps->setPropertyValue("UnsafeScrolling",
uno::Any( true ) );
}
catch( uno::Exception& )
{
}
}
mTranslationOffset.Width = 0;
mTranslationOffset.Height = 0;
}
// Dispose all internal references
void SlideShowView::disposing(std::unique_lock<std::mutex>& rGuard)
{
mpSlideShow = nullptr;
// deregister listeners
if( mxWindow.is() )
{
mxWindow->removeWindowListener( this );
mxWindow->removeMouseListener( this );
if( mbIsMouseMotionListener )
mxWindow->removeMouseMotionListener( this );
}
mpCanvas.reset();
mxWindow.clear();
// clear all listener containers
disposingImpl(rGuard);
}
// Disposing our broadcaster
void SAL_CALL SlideShowView::disposing( const lang::EventObject& )
{
std::unique_lock aGuard( m_aMutex );
disposingImpl(aGuard);
}
// Disposing our broadcaster
void SlideShowView::disposingImpl(std::unique_lock<std::mutex>& rGuard)
{
// notify all listeners that _we_ are going down (send a disposing()),
// then delete listener containers:
lang::EventObject const evt( static_cast<OWeakObject *>(this) );
if (!maViewListeners.empty())
{
auto tmp = std::move(maViewListeners);
rGuard.unlock();
for( const auto& rxListener : tmp )
{
Reference< util::XModifyListener > xListener( rxListener );
if( xListener.is() )
xListener->disposing( evt );
}
rGuard.lock();
}
if (maPaintListeners.getLength(rGuard))
{
maPaintListeners.disposeAndClear( rGuard, evt );
rGuard.lock();
}
if (maMouseListeners.getLength(rGuard))
{
maMouseListeners.disposeAndClear( rGuard, evt );
rGuard.lock();
}
if (maMouseMotionListeners.getLength(rGuard))
{
maMouseMotionListeners.disposeAndClear( rGuard, evt );
rGuard.lock();
}
}
void SlideShowView::paint( const awt::PaintEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if( mbFirstPaint )
{
mbFirstPaint = false;
SlideshowImpl* pSlideShow = mpSlideShow;
aGuard.unlock();
if( pSlideShow )
pSlideShow->onFirstPaint();
}
else
{
// Change event source, to enable listeners to match event
// with view
awt::PaintEvent aEvent( e );
aEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maPaintListeners.notifyEach( aGuard, &css::awt::XPaintListener::windowPaint, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
}
// XSlideShowView methods
Reference< rendering::XSpriteCanvas > SAL_CALL SlideShowView::getCanvas( )
{
std::unique_lock aGuard( m_aMutex );
return mpCanvas ? mpCanvas->getUNOSpriteCanvas() : Reference< rendering::XSpriteCanvas >();
}
void SAL_CALL SlideShowView::clear()
{
// paint background in black
std::unique_lock aGuard( m_aMutex );
SolarMutexGuard aSolarGuard;
// fill the bounds rectangle in black
const Size aWindowSize( mrOutputWindow.GetSizePixel() );
::basegfx::B2DPolygon aPoly( ::basegfx::utils::createPolygonFromRect(
::basegfx::B2DRectangle(0.0,0.0,
aWindowSize.Width(),
aWindowSize.Height() ) ) );
::cppcanvas::PolyPolygonSharedPtr pPolyPoly(
::cppcanvas::BaseGfxFactory::createPolyPolygon( mpCanvas, aPoly ) );
if( pPolyPoly )
{
pPolyPoly->setRGBAFillColor( 0x000000FFU );
pPolyPoly->draw();
}
}
geometry::IntegerSize2D SAL_CALL SlideShowView::getTranslationOffset( )
{
return mTranslationOffset;
}
geometry::AffineMatrix2D SAL_CALL SlideShowView::getTransformation( )
{
std::unique_lock aGuard( m_aMutex );
SolarMutexGuard aSolarGuard;
const Size& rTmpSize( mrOutputWindow.GetSizePixel() );
if (rTmpSize.IsEmpty())
{
return geometry::AffineMatrix2D (1,0,0,0,1,0);
}
const Size aWindowSize( mrOutputWindow.GetSizePixel() );
Size aOutputSize( aWindowSize );
if( meAnimationMode != ANIMATIONMODE_SHOW )
{
aOutputSize.setWidth( static_cast<::tools::Long>( aOutputSize.Width() / 1.03 ) );
aOutputSize.setHeight( static_cast<::tools::Long>( aOutputSize.Height() / 1.03 ) );
}
SdPage* pP = mpDoc->GetSdPage( 0, PageKind::Standard );
Size aPageSize( pP->GetSize() );
const double page_ratio = static_cast<double>(aPageSize.Width()) / static_cast<double>(aPageSize.Height());
const double output_ratio = static_cast<double>(aOutputSize.Width()) / static_cast<double>(aOutputSize.Height());
if( page_ratio > output_ratio )
{
aOutputSize.setHeight( ( aOutputSize.Width() * aPageSize.Height() ) / aPageSize.Width() );
}
else if( page_ratio < output_ratio )
{
aOutputSize.setWidth( ( aOutputSize.Height() * aPageSize.Width() ) / aPageSize.Height() );
}
Point aOutputOffset( ( aWindowSize.Width() - aOutputSize.Width() ) >> 1,
( aWindowSize.Height() - aOutputSize.Height() ) >> 1 );
// Reduce available width by one, as the slides might actually
// render one pixel wider and higher as aPageSize below specifies
// (when shapes of page size have visible border lines)
aOutputSize.AdjustWidth( -1 );
aOutputSize.AdjustHeight( -1 );
// Record mTranslationOffset
mTranslationOffset.Height = aOutputOffset.Y();
mTranslationOffset.Width = aOutputOffset.X();
// scale presentation into available window rect (minus 10%); center in the window
const basegfx::B2DHomMatrix aMatrix(basegfx::utils::createScaleTranslateB2DHomMatrix(
aOutputSize.Width(), aOutputSize.Height(), aOutputOffset.X(), aOutputOffset.Y()));
geometry::AffineMatrix2D aRes;
return ::basegfx::unotools::affineMatrixFromHomMatrix( aRes, aMatrix );
}
void SAL_CALL SlideShowView::addTransformationChangedListener( const Reference< util::XModifyListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
WeakReference< util::XModifyListener > xWeak( xListener );
if( std::find( maViewListeners.begin(), maViewListeners.end(), xWeak ) == maViewListeners.end() )
maViewListeners.push_back( xWeak );
}
void SAL_CALL SlideShowView::removeTransformationChangedListener( const Reference< util::XModifyListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
WeakReference< util::XModifyListener > xWeak( xListener );
auto aIter( std::find( maViewListeners.begin(), maViewListeners.end(), xWeak ) );
if( aIter != maViewListeners.end() )
maViewListeners.erase( aIter );
}
void SAL_CALL SlideShowView::addPaintListener( const Reference< awt::XPaintListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (!m_bDisposed)
maPaintListeners.addInterface( aGuard, xListener );
}
void SAL_CALL SlideShowView::removePaintListener( const Reference< awt::XPaintListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (!m_bDisposed)
maPaintListeners.removeInterface( aGuard, xListener );
}
void SAL_CALL SlideShowView::addMouseListener( const Reference< awt::XMouseListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (!m_bDisposed)
maMouseListeners.addInterface( aGuard, xListener );
}
void SAL_CALL SlideShowView::removeMouseListener( const Reference< awt::XMouseListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (!m_bDisposed)
maMouseListeners.removeInterface( aGuard, xListener );
}
void SAL_CALL SlideShowView::addMouseMotionListener( const Reference< awt::XMouseMotionListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
if( !mbIsMouseMotionListener && mxWindow.is() )
{
// delay motion event registration, until we really
// need it
mbIsMouseMotionListener = true;
mxWindow->addMouseMotionListener( this );
}
maMouseMotionListeners.addInterface( aGuard, xListener );
}
void SAL_CALL SlideShowView::removeMouseMotionListener( const Reference< awt::XMouseMotionListener >& xListener )
{
std::unique_lock aGuard( m_aMutex );
if (!m_bDisposed)
maMouseMotionListeners.removeInterface( aGuard, xListener );
// TODO(P1): Might be nice to deregister for mouse motion
// events, when the last listener is gone.
}
void SAL_CALL SlideShowView::setMouseCursor( sal_Int16 nPointerShape )
{
std::unique_lock aGuard( m_aMutex );
// forward to window
if( mxPointer.is() )
mxPointer->setType( nPointerShape );
if( mxWindowPeer.is() )
mxWindowPeer->setPointer( mxPointer );
}
awt::Rectangle SAL_CALL SlideShowView::getCanvasArea( )
{
awt::Rectangle aRectangle;
if( mxWindow.is() )
return mxWindow->getPosSize();
aRectangle.X = aRectangle.Y = aRectangle.Width = aRectangle.Height = 0;
return aRectangle;
}
void SlideShowView::updateimpl( std::unique_lock<std::mutex>& rGuard, SlideshowImpl* pSlideShow )
{
if( !pSlideShow )
return;
::rtl::Reference< SlideshowImpl > xKeepAlive( pSlideShow );
if( mbFirstPaint )
{
mbFirstPaint = false;
SlideshowImpl* pTmpSlideShow = mpSlideShow;
rGuard.unlock();
if( pTmpSlideShow )
pTmpSlideShow->onFirstPaint();
} else
rGuard.unlock();
pSlideShow->startUpdateTimer();
}
// XWindowListener methods
void SAL_CALL SlideShowView::windowResized( const awt::WindowEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
if (!maViewListeners.empty())
{
// Change event source, to enable listeners to match event
// with view
awt::WindowEvent aEvent( e );
aEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
auto aIter( maViewListeners.begin() );
while( aIter != maViewListeners.end() )
{
Reference< util::XModifyListener > xListener( *aIter );
if( xListener.is() )
{
aGuard.unlock();
xListener->modified( aEvent );
aGuard.lock();
++aIter;
}
else
{
aIter = maViewListeners.erase( aIter );
}
}
}
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
void SAL_CALL SlideShowView::windowMoved( const awt::WindowEvent& )
{
// ignored
}
void SAL_CALL SlideShowView::windowShown( const lang::EventObject& )
{
// ignored
}
void SAL_CALL SlideShowView::windowHidden( const lang::EventObject& )
{
// ignored
}
// XMouseListener implementation
void SAL_CALL SlideShowView::mousePressed( const awt::MouseEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
if( mpSlideShow && mpSlideShow->isInputFreezed() )
{
mbMousePressedEaten = true;
}
else
{
mbMousePressedEaten = false;
// Change event source, to enable listeners to match event
// with view
WrappedMouseEvent aEvent;
aEvent.meType = WrappedMouseEvent::PRESSED;
aEvent.maEvent = e;
aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maMouseListeners.notify( aGuard, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
}
void SAL_CALL SlideShowView::mouseReleased( const awt::MouseEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
if( mbMousePressedEaten )
{
// if mouse button down was ignored, also ignore mouse button up
mbMousePressedEaten = false;
}
else if( mpSlideShow && !mpSlideShow->isInputFreezed() )
{
// Change event source, to enable listeners to match event
// with view
WrappedMouseEvent aEvent;
aEvent.meType = WrappedMouseEvent::RELEASED;
aEvent.maEvent = e;
aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maMouseListeners.notify( aGuard, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
}
void SAL_CALL SlideShowView::mouseEntered( const awt::MouseEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
// Change event source, to enable listeners to match event
// with view
WrappedMouseEvent aEvent;
aEvent.meType = WrappedMouseEvent::ENTERED;
aEvent.maEvent = e;
aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maMouseListeners.notify( aGuard, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
void SAL_CALL SlideShowView::mouseExited( const awt::MouseEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
// Change event source, to enable listeners to match event
// with view
WrappedMouseEvent aEvent;
aEvent.meType = WrappedMouseEvent::EXITED;
aEvent.maEvent = e;
aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maMouseListeners.notify( aGuard, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
// XMouseMotionListener implementation
void SAL_CALL SlideShowView::mouseDragged( const awt::MouseEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
// Change event source, to enable listeners to match event
// with view
WrappedMouseMotionEvent aEvent;
aEvent.meType = WrappedMouseMotionEvent::DRAGGED;
aEvent.maEvent = e;
aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maMouseMotionListeners.notify( aGuard, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
void SAL_CALL SlideShowView::mouseMoved( const awt::MouseEvent& e )
{
std::unique_lock aGuard( m_aMutex );
if (m_bDisposed)
return;
// Change event source, to enable listeners to match event
// with view
WrappedMouseMotionEvent aEvent;
aEvent.meType = WrappedMouseMotionEvent::MOVED;
aEvent.maEvent = e;
aEvent.maEvent.Source = static_cast< ::cppu::OWeakObject* >( this );
maMouseMotionListeners.notify( aGuard, aEvent );
updateimpl( aGuard, mpSlideShow ); // warning: clears guard!
}
} // namespace ::sd
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|