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