1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sdext.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "PresenterButton.hxx" 32*cdf0e10cSrcweir #include "PresenterCanvasHelper.hxx" 33*cdf0e10cSrcweir #include "PresenterController.hxx" 34*cdf0e10cSrcweir #include "PresenterGeometryHelper.hxx" 35*cdf0e10cSrcweir #include "PresenterPaintManager.hxx" 36*cdf0e10cSrcweir #include "PresenterUIPainter.hxx" 37*cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/awt/XWindowPeer.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/drawing/XPresenterHelper.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/rendering/TextDirection.hpp> 42*cdf0e10cSrcweir #include <boost/bind.hpp> 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using namespace ::com::sun::star; 45*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 46*cdf0e10cSrcweir using ::rtl::OUString; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir namespace sdext { namespace presenter { 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir const static double gnHorizontalBorder (15); 53*cdf0e10cSrcweir const static double gnVerticalBorder (5); 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir ::rtl::Reference<PresenterButton> PresenterButton::Create ( 58*cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext, 59*cdf0e10cSrcweir const ::rtl::Reference<PresenterController>& rpPresenterController, 60*cdf0e10cSrcweir const ::boost::shared_ptr<PresenterTheme>& rpTheme, 61*cdf0e10cSrcweir const css::uno::Reference<css::awt::XWindow>& rxParentWindow, 62*cdf0e10cSrcweir const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas, 63*cdf0e10cSrcweir const OUString& rsConfigurationName) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir Reference<beans::XPropertySet> xProperties (GetConfigurationProperties( 66*cdf0e10cSrcweir rxComponentContext, 67*cdf0e10cSrcweir rsConfigurationName)); 68*cdf0e10cSrcweir if (xProperties.is()) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir OUString sText; 71*cdf0e10cSrcweir OUString sAction; 72*cdf0e10cSrcweir PresenterConfigurationAccess::GetProperty(xProperties, A2S("Text")) >>= sText; 73*cdf0e10cSrcweir PresenterConfigurationAccess::GetProperty(xProperties, A2S("Action")) >>= sAction; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor pFont; 76*cdf0e10cSrcweir if (rpTheme.get() != NULL) 77*cdf0e10cSrcweir pFont = rpTheme->GetFont(A2S("ButtonFont")); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir PresenterTheme::SharedFontDescriptor pMouseOverFont; 80*cdf0e10cSrcweir if (rpTheme.get() != NULL) 81*cdf0e10cSrcweir pMouseOverFont = rpTheme->GetFont(A2S("ButtonMouseOverFont")); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir rtl::Reference<PresenterButton> pButton ( 84*cdf0e10cSrcweir new PresenterButton( 85*cdf0e10cSrcweir rxComponentContext, 86*cdf0e10cSrcweir rpPresenterController, 87*cdf0e10cSrcweir rpTheme, 88*cdf0e10cSrcweir rxParentWindow, 89*cdf0e10cSrcweir pFont, 90*cdf0e10cSrcweir pMouseOverFont, 91*cdf0e10cSrcweir sText, 92*cdf0e10cSrcweir sAction)); 93*cdf0e10cSrcweir pButton->SetCanvas(rxParentCanvas, rxParentWindow); 94*cdf0e10cSrcweir return pButton; 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir else 97*cdf0e10cSrcweir return NULL; 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir PresenterButton::PresenterButton ( 104*cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext, 105*cdf0e10cSrcweir const ::rtl::Reference<PresenterController>& rpPresenterController, 106*cdf0e10cSrcweir const ::boost::shared_ptr<PresenterTheme>& rpTheme, 107*cdf0e10cSrcweir const css::uno::Reference<css::awt::XWindow>& rxParentWindow, 108*cdf0e10cSrcweir const PresenterTheme::SharedFontDescriptor& rpFont, 109*cdf0e10cSrcweir const PresenterTheme::SharedFontDescriptor& rpMouseOverFont, 110*cdf0e10cSrcweir const OUString& rsText, 111*cdf0e10cSrcweir const OUString& rsAction) 112*cdf0e10cSrcweir : PresenterButtonInterfaceBase(m_aMutex), 113*cdf0e10cSrcweir mpPresenterController(rpPresenterController), 114*cdf0e10cSrcweir mpTheme(rpTheme), 115*cdf0e10cSrcweir mxWindow(), 116*cdf0e10cSrcweir mxCanvas(), 117*cdf0e10cSrcweir mxPresenterHelper(), 118*cdf0e10cSrcweir msText(rsText), 119*cdf0e10cSrcweir mpFont(rpFont), 120*cdf0e10cSrcweir mpMouseOverFont(rpMouseOverFont), 121*cdf0e10cSrcweir msAction(rsAction), 122*cdf0e10cSrcweir maCenter(), 123*cdf0e10cSrcweir maButtonSize(-1,-1), 124*cdf0e10cSrcweir meState(PresenterBitmapDescriptor::Normal), 125*cdf0e10cSrcweir mxNormalBitmap(), 126*cdf0e10cSrcweir mxMouseOverBitmap() 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir try 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir Reference<lang::XMultiComponentFactory> xFactory (rxComponentContext->getServiceManager()); 131*cdf0e10cSrcweir if ( ! xFactory.is()) 132*cdf0e10cSrcweir throw RuntimeException(); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir mxPresenterHelper = Reference<drawing::XPresenterHelper>( 135*cdf0e10cSrcweir xFactory->createInstanceWithContext( 136*cdf0e10cSrcweir OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"), 137*cdf0e10cSrcweir rxComponentContext), 138*cdf0e10cSrcweir UNO_QUERY_THROW); 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir if (mxPresenterHelper.is()) 141*cdf0e10cSrcweir mxWindow = mxPresenterHelper->createWindow(rxParentWindow, 142*cdf0e10cSrcweir sal_False, 143*cdf0e10cSrcweir sal_False, 144*cdf0e10cSrcweir sal_False, 145*cdf0e10cSrcweir sal_False); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // Make the background transparent. 148*cdf0e10cSrcweir Reference<awt::XWindowPeer> xPeer (mxWindow, UNO_QUERY_THROW); 149*cdf0e10cSrcweir if (xPeer.is()) 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir xPeer->setBackground(0xff000000); 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir mxWindow->setVisible(sal_True); 155*cdf0e10cSrcweir mxWindow->addWindowListener(this); 156*cdf0e10cSrcweir mxWindow->addPaintListener(this); 157*cdf0e10cSrcweir mxWindow->addMouseListener(this); 158*cdf0e10cSrcweir mxWindow->addMouseMotionListener(this); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir catch (RuntimeException&) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir PresenterButton::~PresenterButton (void) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir void SAL_CALL PresenterButton::disposing (void) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir if (mxCanvas.is()) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY); 180*cdf0e10cSrcweir mxCanvas = NULL; 181*cdf0e10cSrcweir if (xComponent.is()) 182*cdf0e10cSrcweir xComponent->dispose(); 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir if (mxWindow.is()) 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir mxWindow->removeWindowListener(this); 188*cdf0e10cSrcweir mxWindow->removePaintListener(this); 189*cdf0e10cSrcweir mxWindow->removeMouseListener(this); 190*cdf0e10cSrcweir mxWindow->removeMouseMotionListener(this); 191*cdf0e10cSrcweir Reference<lang::XComponent> xComponent (mxWindow, UNO_QUERY); 192*cdf0e10cSrcweir mxWindow = NULL; 193*cdf0e10cSrcweir if (xComponent.is()) 194*cdf0e10cSrcweir xComponent->dispose(); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir void PresenterButton::SetCenter (const css::geometry::RealPoint2D& rLocation) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir if (mxCanvas.is()) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir Invalidate(); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir maCenter = rLocation; 208*cdf0e10cSrcweir mxWindow->setPosSize( 209*cdf0e10cSrcweir sal_Int32(0.5 + maCenter.X - maButtonSize.Width/2), 210*cdf0e10cSrcweir sal_Int32(0.5 + maCenter.Y - maButtonSize.Height/2), 211*cdf0e10cSrcweir maButtonSize.Width, 212*cdf0e10cSrcweir maButtonSize.Height, 213*cdf0e10cSrcweir awt::PosSize::POSSIZE); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir Invalidate(); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir else 218*cdf0e10cSrcweir { 219*cdf0e10cSrcweir // The button can not be painted but we can at least store the new center. 220*cdf0e10cSrcweir maCenter = rLocation; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir void PresenterButton::SetCanvas ( 228*cdf0e10cSrcweir const css::uno::Reference<css::rendering::XCanvas>& rxParentCanvas, 229*cdf0e10cSrcweir const css::uno::Reference<css::awt::XWindow>& rxParentWindow) 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir if (mxCanvas.is()) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir Reference<lang::XComponent> xComponent (mxCanvas, UNO_QUERY); 234*cdf0e10cSrcweir mxCanvas = NULL; 235*cdf0e10cSrcweir if (xComponent.is()) 236*cdf0e10cSrcweir xComponent->dispose(); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir if (mxPresenterHelper.is() && rxParentCanvas.is() && rxParentWindow.is()) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir mxCanvas = mxPresenterHelper->createSharedCanvas ( 242*cdf0e10cSrcweir Reference<rendering::XSpriteCanvas>(rxParentCanvas, UNO_QUERY), 243*cdf0e10cSrcweir rxParentWindow, 244*cdf0e10cSrcweir rxParentCanvas, 245*cdf0e10cSrcweir rxParentWindow, 246*cdf0e10cSrcweir mxWindow); 247*cdf0e10cSrcweir if (mxCanvas.is()) 248*cdf0e10cSrcweir { 249*cdf0e10cSrcweir SetupButtonBitmaps(); 250*cdf0e10cSrcweir SetCenter(maCenter); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir } 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir css::geometry::IntegerSize2D PresenterButton::GetSize (void) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir if (maButtonSize.Width < 0) 261*cdf0e10cSrcweir CalculateButtonSize(); 262*cdf0e10cSrcweir return maButtonSize; 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir //----- XWindowListener ------------------------------------------------------- 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir void SAL_CALL PresenterButton::windowResized (const css::awt::WindowEvent& rEvent) 271*cdf0e10cSrcweir throw (css::uno::RuntimeException) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir (void)rEvent; 274*cdf0e10cSrcweir ThrowIfDisposed(); 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir void SAL_CALL PresenterButton::windowMoved (const css::awt::WindowEvent& rEvent) 282*cdf0e10cSrcweir throw (css::uno::RuntimeException) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir (void)rEvent; 285*cdf0e10cSrcweir ThrowIfDisposed(); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir void SAL_CALL PresenterButton::windowShown (const css::lang::EventObject& rEvent) 292*cdf0e10cSrcweir throw (css::uno::RuntimeException) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir (void)rEvent; 295*cdf0e10cSrcweir ThrowIfDisposed(); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir void SAL_CALL PresenterButton::windowHidden (const css::lang::EventObject& rEvent) 302*cdf0e10cSrcweir throw (css::uno::RuntimeException) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir (void)rEvent; 305*cdf0e10cSrcweir ThrowIfDisposed(); 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir //----- XPaintListener -------------------------------------------------------- 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir void SAL_CALL PresenterButton::windowPaint (const css::awt::PaintEvent& rEvent) 314*cdf0e10cSrcweir throw (css::uno::RuntimeException) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir ThrowIfDisposed(); 317*cdf0e10cSrcweir if (mxWindow.is() && mxCanvas.is()) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir Reference<rendering::XBitmap> xBitmap; 320*cdf0e10cSrcweir if (meState == PresenterBitmapDescriptor::MouseOver) 321*cdf0e10cSrcweir xBitmap = mxMouseOverBitmap; 322*cdf0e10cSrcweir else 323*cdf0e10cSrcweir xBitmap = mxNormalBitmap; 324*cdf0e10cSrcweir if ( ! xBitmap.is()) 325*cdf0e10cSrcweir return; 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir rendering::ViewState aViewState( 328*cdf0e10cSrcweir geometry::AffineMatrix2D(1,0,0, 0,1,0), 329*cdf0e10cSrcweir NULL); 330*cdf0e10cSrcweir rendering::RenderState aRenderState( 331*cdf0e10cSrcweir geometry::AffineMatrix2D(1,0,0, 0,1,0), 332*cdf0e10cSrcweir PresenterGeometryHelper::CreatePolygon(rEvent.UpdateRect, mxCanvas->getDevice()), 333*cdf0e10cSrcweir Sequence<double>(4), 334*cdf0e10cSrcweir rendering::CompositeOperation::SOURCE); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir mxCanvas->drawBitmap(xBitmap, aViewState, aRenderState); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxCanvas, UNO_QUERY); 339*cdf0e10cSrcweir if (xSpriteCanvas.is()) 340*cdf0e10cSrcweir xSpriteCanvas->updateScreen(sal_False); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir //----- XMouseListener -------------------------------------------------------- 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir void SAL_CALL PresenterButton::mousePressed (const css::awt::MouseEvent& rEvent) 350*cdf0e10cSrcweir throw(css::uno::RuntimeException) 351*cdf0e10cSrcweir { 352*cdf0e10cSrcweir (void)rEvent; 353*cdf0e10cSrcweir ThrowIfDisposed(); 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir meState = PresenterBitmapDescriptor::ButtonDown; 356*cdf0e10cSrcweir } 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseReleased (const css::awt::MouseEvent& rEvent) 362*cdf0e10cSrcweir throw(css::uno::RuntimeException) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir (void)rEvent; 365*cdf0e10cSrcweir ThrowIfDisposed(); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir if (meState == PresenterBitmapDescriptor::ButtonDown) 368*cdf0e10cSrcweir { 369*cdf0e10cSrcweir OSL_ASSERT(mpPresenterController.get()!=NULL); 370*cdf0e10cSrcweir mpPresenterController->DispatchUnoCommand(msAction); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir meState = PresenterBitmapDescriptor::Normal; 373*cdf0e10cSrcweir Invalidate(); 374*cdf0e10cSrcweir } 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseEntered (const css::awt::MouseEvent& rEvent) 381*cdf0e10cSrcweir throw(css::uno::RuntimeException) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir (void)rEvent; 384*cdf0e10cSrcweir ThrowIfDisposed(); 385*cdf0e10cSrcweir meState = PresenterBitmapDescriptor::MouseOver; 386*cdf0e10cSrcweir Invalidate(); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseExited (const css::awt::MouseEvent& rEvent) 393*cdf0e10cSrcweir throw(css::uno::RuntimeException) 394*cdf0e10cSrcweir { 395*cdf0e10cSrcweir (void)rEvent; 396*cdf0e10cSrcweir ThrowIfDisposed(); 397*cdf0e10cSrcweir meState = PresenterBitmapDescriptor::Normal; 398*cdf0e10cSrcweir Invalidate(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir //----- XMouseMotionListener -------------------------------------------------- 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseMoved (const css::awt::MouseEvent& rEvent) 408*cdf0e10cSrcweir throw (css::uno::RuntimeException) 409*cdf0e10cSrcweir { 410*cdf0e10cSrcweir (void)rEvent; 411*cdf0e10cSrcweir ThrowIfDisposed(); 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir void SAL_CALL PresenterButton::mouseDragged (const css::awt::MouseEvent& rEvent) 418*cdf0e10cSrcweir throw (css::uno::RuntimeException) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir (void)rEvent; 421*cdf0e10cSrcweir ThrowIfDisposed(); 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir 425*cdf0e10cSrcweir 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir //----- lang::XEventListener -------------------------------------------------- 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir void SAL_CALL PresenterButton::disposing (const css::lang::EventObject& rEvent) 430*cdf0e10cSrcweir throw (css::uno::RuntimeException) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir if (rEvent.Source == mxWindow) 433*cdf0e10cSrcweir mxWindow = NULL; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir //----------------------------------------------------------------------------- 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir css::geometry::IntegerSize2D PresenterButton::CalculateButtonSize (void) 442*cdf0e10cSrcweir { 443*cdf0e10cSrcweir if (mpFont.get()!=NULL && !mpFont->mxFont.is() && mxCanvas.is()) 444*cdf0e10cSrcweir mpFont->PrepareFont(mxCanvas); 445*cdf0e10cSrcweir if (mpFont.get()==NULL || !mpFont->mxFont.is()) 446*cdf0e10cSrcweir return geometry::IntegerSize2D(-1,-1); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir geometry::RealSize2D aTextSize (PresenterCanvasHelper::GetTextSize(mpFont->mxFont,msText)); 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir return geometry::IntegerSize2D ( 451*cdf0e10cSrcweir sal_Int32(0.5 + aTextSize.Width + 2*gnHorizontalBorder), 452*cdf0e10cSrcweir sal_Int32(0.5 + aTextSize.Height + 2*gnVerticalBorder)); 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir 458*cdf0e10cSrcweir void PresenterButton::RenderButton ( 459*cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxCanvas, 460*cdf0e10cSrcweir const geometry::IntegerSize2D& rSize, 461*cdf0e10cSrcweir const PresenterTheme::SharedFontDescriptor& rpFont, 462*cdf0e10cSrcweir const PresenterBitmapDescriptor::Mode eMode, 463*cdf0e10cSrcweir const SharedBitmapDescriptor& rpLeft, 464*cdf0e10cSrcweir const SharedBitmapDescriptor& rpCenter, 465*cdf0e10cSrcweir const SharedBitmapDescriptor& rpRight) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir if ( ! rxCanvas.is()) 468*cdf0e10cSrcweir return; 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir const awt::Rectangle aBox(0,0, rSize.Width, rSize.Height); 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir PresenterUIPainter::PaintHorizontalBitmapComposite ( 473*cdf0e10cSrcweir rxCanvas, 474*cdf0e10cSrcweir aBox, 475*cdf0e10cSrcweir aBox, 476*cdf0e10cSrcweir GetBitmap(rpLeft, eMode), 477*cdf0e10cSrcweir GetBitmap(rpCenter, eMode), 478*cdf0e10cSrcweir GetBitmap(rpRight, eMode)); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir if (rpFont.get()==NULL || ! rpFont->mxFont.is()) 481*cdf0e10cSrcweir return; 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir const rendering::StringContext aContext (msText, 0, msText.getLength()); 484*cdf0e10cSrcweir const Reference<rendering::XTextLayout> xLayout ( 485*cdf0e10cSrcweir rpFont->mxFont->createTextLayout(aContext,rendering::TextDirection::WEAK_LEFT_TO_RIGHT,0)); 486*cdf0e10cSrcweir const geometry::RealRectangle2D aTextBBox (xLayout->queryTextBounds()); 487*cdf0e10cSrcweir 488*cdf0e10cSrcweir rendering::RenderState aRenderState (geometry::AffineMatrix2D(1,0,0, 0,1,0), NULL, 489*cdf0e10cSrcweir Sequence<double>(4), rendering::CompositeOperation::SOURCE); 490*cdf0e10cSrcweir PresenterCanvasHelper::SetDeviceColor(aRenderState, rpFont->mnColor); 491*cdf0e10cSrcweir aRenderState.AffineTransform.m02 = (rSize.Width - aTextBBox.X2 + aTextBBox.X1)/2; 492*cdf0e10cSrcweir aRenderState.AffineTransform.m12 = (rSize.Height - aTextBBox.Y2 + aTextBBox.Y1)/2 - aTextBBox.Y1; 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir rxCanvas->drawText( 495*cdf0e10cSrcweir aContext, 496*cdf0e10cSrcweir rpFont->mxFont, 497*cdf0e10cSrcweir rendering::ViewState(geometry::AffineMatrix2D(1,0,0, 0,1,0), NULL), 498*cdf0e10cSrcweir aRenderState, 499*cdf0e10cSrcweir rendering::TextDirection::WEAK_LEFT_TO_RIGHT); 500*cdf0e10cSrcweir } 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir void PresenterButton::Invalidate (void) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir mpPresenterController->GetPaintManager()->Invalidate(mxWindow); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir Reference<rendering::XBitmap> PresenterButton::GetBitmap ( 514*cdf0e10cSrcweir const SharedBitmapDescriptor& mpIcon, 515*cdf0e10cSrcweir const PresenterBitmapDescriptor::Mode eMode) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir if (mpIcon.get() != NULL) 518*cdf0e10cSrcweir return mpIcon->GetBitmap(eMode); 519*cdf0e10cSrcweir else 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir OSL_ASSERT(mpIcon.get()!=NULL); 522*cdf0e10cSrcweir return NULL; 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir void PresenterButton::SetupButtonBitmaps (void) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir if ( ! mxCanvas.is()) 532*cdf0e10cSrcweir return; 533*cdf0e10cSrcweir if ( ! mxCanvas->getDevice().is()) 534*cdf0e10cSrcweir return; 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir // Get the bitmaps for the button border. 537*cdf0e10cSrcweir SharedBitmapDescriptor pLeftBitmap (mpTheme->GetBitmap(A2S("ButtonFrameLeft"))); 538*cdf0e10cSrcweir SharedBitmapDescriptor pCenterBitmap(mpTheme->GetBitmap(A2S("ButtonFrameCenter"))); 539*cdf0e10cSrcweir SharedBitmapDescriptor pRightBitmap(mpTheme->GetBitmap(A2S("ButtonFrameRight"))); 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir maButtonSize = CalculateButtonSize(); 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir if (maButtonSize.Height<=0 && maButtonSize.Width<= 0) 544*cdf0e10cSrcweir return; 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir mxNormalBitmap = mxCanvas->getDevice()->createCompatibleAlphaBitmap(maButtonSize); 547*cdf0e10cSrcweir Reference<rendering::XCanvas> xCanvas (mxNormalBitmap, UNO_QUERY); 548*cdf0e10cSrcweir if (xCanvas.is()) 549*cdf0e10cSrcweir RenderButton( 550*cdf0e10cSrcweir xCanvas, 551*cdf0e10cSrcweir maButtonSize, 552*cdf0e10cSrcweir mpFont, 553*cdf0e10cSrcweir PresenterBitmapDescriptor::Normal, 554*cdf0e10cSrcweir pLeftBitmap, 555*cdf0e10cSrcweir pCenterBitmap, 556*cdf0e10cSrcweir pRightBitmap); 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir mxMouseOverBitmap = mxCanvas->getDevice()->createCompatibleAlphaBitmap(maButtonSize); 559*cdf0e10cSrcweir xCanvas = Reference<rendering::XCanvas>(mxMouseOverBitmap, UNO_QUERY); 560*cdf0e10cSrcweir if (mpMouseOverFont.get()!=NULL && !mpMouseOverFont->mxFont.is() && mxCanvas.is()) 561*cdf0e10cSrcweir mpMouseOverFont->PrepareFont(mxCanvas); 562*cdf0e10cSrcweir if (xCanvas.is()) 563*cdf0e10cSrcweir RenderButton( 564*cdf0e10cSrcweir xCanvas, 565*cdf0e10cSrcweir maButtonSize, 566*cdf0e10cSrcweir mpMouseOverFont, 567*cdf0e10cSrcweir PresenterBitmapDescriptor::MouseOver, 568*cdf0e10cSrcweir pLeftBitmap, 569*cdf0e10cSrcweir pCenterBitmap, 570*cdf0e10cSrcweir pRightBitmap); 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir Reference<beans::XPropertySet> PresenterButton::GetConfigurationProperties ( 577*cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext, 578*cdf0e10cSrcweir const OUString& rsConfgurationName) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir PresenterConfigurationAccess aConfiguration ( 581*cdf0e10cSrcweir rxComponentContext, 582*cdf0e10cSrcweir PresenterConfigurationAccess::msPresenterScreenRootName, 583*cdf0e10cSrcweir PresenterConfigurationAccess::READ_ONLY); 584*cdf0e10cSrcweir return Reference<beans::XPropertySet>( 585*cdf0e10cSrcweir PresenterConfigurationAccess::Find ( 586*cdf0e10cSrcweir Reference<container::XNameAccess>( 587*cdf0e10cSrcweir aConfiguration.GetConfigurationNode(A2S("PresenterScreenSettings/Buttons")), 588*cdf0e10cSrcweir UNO_QUERY), 589*cdf0e10cSrcweir ::boost::bind(&PresenterConfigurationAccess::IsStringPropertyEqual, 590*cdf0e10cSrcweir rsConfgurationName, 591*cdf0e10cSrcweir A2S("Name"), 592*cdf0e10cSrcweir _2)), 593*cdf0e10cSrcweir UNO_QUERY); 594*cdf0e10cSrcweir } 595*cdf0e10cSrcweir 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir void PresenterButton::ThrowIfDisposed (void) const 600*cdf0e10cSrcweir throw (::com::sun::star::lang::DisposedException) 601*cdf0e10cSrcweir { 602*cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose) 603*cdf0e10cSrcweir { 604*cdf0e10cSrcweir throw lang::DisposedException ( 605*cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM( 606*cdf0e10cSrcweir "PresenterButton object has already been disposed")), 607*cdf0e10cSrcweir const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this))); 608*cdf0e10cSrcweir } 609*cdf0e10cSrcweir } 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir 612*cdf0e10cSrcweir } } // end of namespace sdext::presenter 613