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 #include "precompiled_sd.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "PresenterHelper.hxx" 31*cdf0e10cSrcweir #include "CanvasUpdateRequester.hxx" 32*cdf0e10cSrcweir #include "PresenterCanvas.hxx" 33*cdf0e10cSrcweir #include <cppcanvas/vclfactory.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/awt/WindowClass.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/awt/WindowDescriptor.hpp> 37*cdf0e10cSrcweir #include <osl/file.hxx> 38*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx> 39*cdf0e10cSrcweir #include <vcl/svapp.hxx> 40*cdf0e10cSrcweir #include <vcl/window.hxx> 41*cdf0e10cSrcweir #include <vcl/wrkwin.hxx> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir using namespace ::com::sun::star; 44*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45*cdf0e10cSrcweir using ::rtl::OUString; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir namespace sd { namespace presenter { 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //===== Service =============================================================== 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir Reference<XInterface> SAL_CALL PresenterHelperService_createInstance ( 52*cdf0e10cSrcweir const Reference<XComponentContext>& rxContext) 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir return Reference<XInterface>(static_cast<XWeak*>(new PresenterHelper(rxContext))); 55*cdf0e10cSrcweir } 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir ::rtl::OUString PresenterHelperService_getImplementationName (void) 61*cdf0e10cSrcweir throw(RuntimeException) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL PresenterHelperService_getSupportedServiceNames (void) 70*cdf0e10cSrcweir throw (RuntimeException) 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir static const ::rtl::OUString sServiceName( 73*cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.drawing.PresenterHelper")); 74*cdf0e10cSrcweir return Sequence<rtl::OUString>(&sServiceName, 1); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir //===== PresenterHelper ======================================================= 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir PresenterHelper::PresenterHelper ( 83*cdf0e10cSrcweir const Reference<XComponentContext>& rxContext) 84*cdf0e10cSrcweir : PresenterHelperInterfaceBase(m_aMutex), 85*cdf0e10cSrcweir mxComponentContext(rxContext) 86*cdf0e10cSrcweir { 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir PresenterHelper::~PresenterHelper (void) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir //----- XInitialize ----------------------------------------------------------- 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir void SAL_CALL PresenterHelper::initialize (const Sequence<Any>& rArguments) 101*cdf0e10cSrcweir throw(Exception,RuntimeException) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir (void)rArguments; 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir //----- XPaneHelper ---------------------------------------------------- 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir Reference<awt::XWindow> SAL_CALL PresenterHelper::createWindow ( 112*cdf0e10cSrcweir const Reference<awt::XWindow>& rxParentWindow, 113*cdf0e10cSrcweir sal_Bool bCreateSystemChildWindow, 114*cdf0e10cSrcweir sal_Bool bInitiallyVisible, 115*cdf0e10cSrcweir sal_Bool bEnableChildTransparentMode, 116*cdf0e10cSrcweir sal_Bool bEnableParentClip) 117*cdf0e10cSrcweir throw (css::uno::RuntimeException) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir ::Window* pParentWindow = VCLUnoHelper::GetWindow(rxParentWindow); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // Create a new window. 122*cdf0e10cSrcweir ::Window* pWindow = NULL; 123*cdf0e10cSrcweir if (bCreateSystemChildWindow) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir pWindow = new WorkWindow(pParentWindow, WB_SYSTEMCHILDWINDOW); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir else 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir pWindow = new ::Window(pParentWindow); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir Reference<awt::XWindow> xWindow (pWindow->GetComponentInterface(), UNO_QUERY); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir if (bEnableChildTransparentMode) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir // Make the frame window transparent and make the parent able to 136*cdf0e10cSrcweir // draw behind it. 137*cdf0e10cSrcweir if (pParentWindow != NULL) 138*cdf0e10cSrcweir pParentWindow->EnableChildTransparentMode(sal_True); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir if (pWindow != NULL) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir pWindow->Show(bInitiallyVisible); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir pWindow->SetMapMode(MAP_PIXEL); 146*cdf0e10cSrcweir pWindow->SetBackground(); 147*cdf0e10cSrcweir if ( ! bEnableParentClip) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir pWindow->SetParentClipMode(PARENTCLIPMODE_NOCLIP); 150*cdf0e10cSrcweir pWindow->SetPaintTransparent(sal_True); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir else 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir pWindow->SetParentClipMode(PARENTCLIPMODE_CLIP); 155*cdf0e10cSrcweir pWindow->SetPaintTransparent(sal_False); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir return xWindow; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir Reference<rendering::XCanvas> SAL_CALL PresenterHelper::createSharedCanvas ( 167*cdf0e10cSrcweir const Reference<rendering::XSpriteCanvas>& rxUpdateCanvas, 168*cdf0e10cSrcweir const Reference<awt::XWindow>& rxUpdateWindow, 169*cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxSharedCanvas, 170*cdf0e10cSrcweir const Reference<awt::XWindow>& rxSharedWindow, 171*cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow) 172*cdf0e10cSrcweir throw (css::uno::RuntimeException) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir if ( ! rxSharedCanvas.is() 175*cdf0e10cSrcweir || ! rxSharedWindow.is() 176*cdf0e10cSrcweir || ! rxWindow.is()) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir throw RuntimeException( 179*cdf0e10cSrcweir OUString::createFromAscii("illegal argument"), 180*cdf0e10cSrcweir Reference<XInterface>(static_cast<XWeak*>(this))); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir if (rxWindow == rxSharedWindow) 184*cdf0e10cSrcweir return rxSharedCanvas; 185*cdf0e10cSrcweir else 186*cdf0e10cSrcweir return new PresenterCanvas( 187*cdf0e10cSrcweir rxUpdateCanvas, 188*cdf0e10cSrcweir rxUpdateWindow, 189*cdf0e10cSrcweir rxSharedCanvas, 190*cdf0e10cSrcweir rxSharedWindow, 191*cdf0e10cSrcweir rxWindow); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir Reference<rendering::XCanvas> SAL_CALL PresenterHelper::createCanvas ( 198*cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow, 199*cdf0e10cSrcweir sal_Int16 nRequestedCanvasFeatures, 200*cdf0e10cSrcweir const OUString& rsOptionalCanvasServiceName) 201*cdf0e10cSrcweir throw (css::uno::RuntimeException) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir (void)nRequestedCanvasFeatures; 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir // No shared window is given or an explicit canvas service name is 206*cdf0e10cSrcweir // specified. Create a new canvas. 207*cdf0e10cSrcweir ::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); 208*cdf0e10cSrcweir if (pWindow != NULL) 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir Sequence<Any> aArg (5); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir // common: first any is VCL pointer to window (for VCL canvas) 213*cdf0e10cSrcweir aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow)); 214*cdf0e10cSrcweir aArg[1] = Any(); 215*cdf0e10cSrcweir aArg[2] = makeAny(::com::sun::star::awt::Rectangle()); 216*cdf0e10cSrcweir aArg[3] = makeAny(sal_False); 217*cdf0e10cSrcweir aArg[4] = makeAny(rxWindow); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir Reference<lang::XMultiServiceFactory> xFactory ( 220*cdf0e10cSrcweir mxComponentContext->getServiceManager(), UNO_QUERY_THROW); 221*cdf0e10cSrcweir return Reference<rendering::XCanvas>( 222*cdf0e10cSrcweir xFactory->createInstanceWithArguments( 223*cdf0e10cSrcweir rsOptionalCanvasServiceName.getLength()>0 224*cdf0e10cSrcweir ? rsOptionalCanvasServiceName 225*cdf0e10cSrcweir : OUString::createFromAscii("com.sun.star.rendering.VCLCanvas"), 226*cdf0e10cSrcweir aArg), 227*cdf0e10cSrcweir UNO_QUERY); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir else 230*cdf0e10cSrcweir throw RuntimeException(); 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir void SAL_CALL PresenterHelper::toTop ( 237*cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow) 238*cdf0e10cSrcweir throw (css::uno::RuntimeException) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir ::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); 241*cdf0e10cSrcweir if (pWindow != NULL) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir pWindow->ToTop(); 244*cdf0e10cSrcweir pWindow->SetZOrder(NULL, WINDOW_ZORDER_LAST); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir Reference<rendering::XBitmap> SAL_CALL PresenterHelper::loadBitmap ( 252*cdf0e10cSrcweir const OUString& rsURL, 253*cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxCanvas) 254*cdf0e10cSrcweir throw (RuntimeException) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir if ( ! rxCanvas.is()) 257*cdf0e10cSrcweir return NULL; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex()); 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir if (mpGraphicFilter.get() == NULL) 262*cdf0e10cSrcweir mpGraphicFilter.reset(new GraphicFilter(sal_False)); 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir const cppcanvas::CanvasSharedPtr pCanvas ( 265*cdf0e10cSrcweir cppcanvas::VCLFactory::getInstance().createCanvas( 266*cdf0e10cSrcweir Reference<css::rendering::XBitmapCanvas>(rxCanvas,UNO_QUERY))); 267*cdf0e10cSrcweir 268*cdf0e10cSrcweir if (pCanvas.get()!=NULL && rsURL.getLength()>0 && mpGraphicFilter.get()!=NULL) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir Graphic aGraphic; 271*cdf0e10cSrcweir OUString sFileName; 272*cdf0e10cSrcweir if (osl::FileBase::getSystemPathFromFileURL(rsURL, sFileName) 273*cdf0e10cSrcweir == osl::FileBase::E_None) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir if (mpGraphicFilter->ImportGraphic(aGraphic, rsURL) == GRFILTER_OK) 276*cdf0e10cSrcweir { 277*cdf0e10cSrcweir BitmapEx aBitmapEx (aGraphic.GetBitmapEx()); 278*cdf0e10cSrcweir return cppcanvas::VCLFactory::getInstance().createBitmap( 279*cdf0e10cSrcweir pCanvas, 280*cdf0e10cSrcweir aBitmapEx)->getUNOBitmap(); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir return NULL; 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir void SAL_CALL PresenterHelper::captureMouse ( 293*cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow) 294*cdf0e10cSrcweir throw (RuntimeException) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex()); 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // Capture the mouse (if not already done.) 299*cdf0e10cSrcweir ::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); 300*cdf0e10cSrcweir if (pWindow != NULL && ! pWindow->IsMouseCaptured()) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir pWindow->CaptureMouse(); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir void SAL_CALL PresenterHelper::releaseMouse (const Reference<awt::XWindow>& rxWindow) 310*cdf0e10cSrcweir throw (RuntimeException) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex()); 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir // Release the mouse (if not already done.) 315*cdf0e10cSrcweir ::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); 316*cdf0e10cSrcweir if (pWindow != NULL && pWindow->IsMouseCaptured()) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir pWindow->ReleaseMouse(); 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir awt::Rectangle PresenterHelper::getWindowExtentsRelative ( 326*cdf0e10cSrcweir const Reference<awt::XWindow>& rxChildWindow, 327*cdf0e10cSrcweir const Reference<awt::XWindow>& rxParentWindow) 328*cdf0e10cSrcweir throw (RuntimeException) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir ::Window* pChildWindow = VCLUnoHelper::GetWindow(rxChildWindow); 331*cdf0e10cSrcweir ::Window* pParentWindow = VCLUnoHelper::GetWindow(rxParentWindow); 332*cdf0e10cSrcweir if (pChildWindow!=NULL && pParentWindow!=NULL) 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir Rectangle aBox (pChildWindow->GetWindowExtentsRelative(pParentWindow)); 335*cdf0e10cSrcweir return awt::Rectangle(aBox.Left(),aBox.Top(),aBox.GetWidth(),aBox.GetHeight()); 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir else 338*cdf0e10cSrcweir return awt::Rectangle(); 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir } } // end of namespace ::sd::presenter 344