15b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 35b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 45b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 55b190011SAndrew Rist * distributed with this work for additional information 65b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 75b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 85b190011SAndrew Rist * "License"); you may not use this file except in compliance 95b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 115b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 135b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 145b190011SAndrew Rist * software distributed under the License is distributed on an 155b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165b190011SAndrew Rist * KIND, either express or implied. See the License for the 175b190011SAndrew Rist * specific language governing permissions and limitations 185b190011SAndrew Rist * under the License. 19cdf0e10cSrcweir * 205b190011SAndrew Rist *************************************************************/ 215b190011SAndrew Rist 225b190011SAndrew 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> 38*79e0a548SAriel Constenla-Haile #include <vcl/imagerepository.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace ::com::sun::star; 41cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42cdf0e10cSrcweir using ::rtl::OUString; 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace sd { namespace presenter { 45cdf0e10cSrcweir 46cdf0e10cSrcweir //===== Service =============================================================== 47cdf0e10cSrcweir 48cdf0e10cSrcweir Reference<XInterface> SAL_CALL PresenterHelperService_createInstance ( 49cdf0e10cSrcweir const Reference<XComponentContext>& rxContext) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir return Reference<XInterface>(static_cast<XWeak*>(new PresenterHelper(rxContext))); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir 57cdf0e10cSrcweir ::rtl::OUString PresenterHelperService_getImplementationName (void) 58cdf0e10cSrcweir throw(RuntimeException) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"); 61cdf0e10cSrcweir } 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir 65cdf0e10cSrcweir 66cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL PresenterHelperService_getSupportedServiceNames (void) 67cdf0e10cSrcweir throw (RuntimeException) 68cdf0e10cSrcweir { 69cdf0e10cSrcweir static const ::rtl::OUString sServiceName( 70cdf0e10cSrcweir ::rtl::OUString::createFromAscii("com.sun.star.drawing.PresenterHelper")); 71cdf0e10cSrcweir return Sequence<rtl::OUString>(&sServiceName, 1); 72cdf0e10cSrcweir } 73cdf0e10cSrcweir 74cdf0e10cSrcweir 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir //===== PresenterHelper ======================================================= 78cdf0e10cSrcweir 79cdf0e10cSrcweir PresenterHelper::PresenterHelper ( 80cdf0e10cSrcweir const Reference<XComponentContext>& rxContext) 81cdf0e10cSrcweir : PresenterHelperInterfaceBase(m_aMutex), 82cdf0e10cSrcweir mxComponentContext(rxContext) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir 87cdf0e10cSrcweir 88cdf0e10cSrcweir PresenterHelper::~PresenterHelper (void) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir 93cdf0e10cSrcweir 94cdf0e10cSrcweir 95cdf0e10cSrcweir //----- XInitialize ----------------------------------------------------------- 96cdf0e10cSrcweir 97cdf0e10cSrcweir void SAL_CALL PresenterHelper::initialize (const Sequence<Any>& rArguments) 98cdf0e10cSrcweir throw(Exception,RuntimeException) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir (void)rArguments; 101cdf0e10cSrcweir } 102cdf0e10cSrcweir 103cdf0e10cSrcweir 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir //----- XPaneHelper ---------------------------------------------------- 107cdf0e10cSrcweir 108cdf0e10cSrcweir Reference<awt::XWindow> SAL_CALL PresenterHelper::createWindow ( 109cdf0e10cSrcweir const Reference<awt::XWindow>& rxParentWindow, 110cdf0e10cSrcweir sal_Bool bCreateSystemChildWindow, 111cdf0e10cSrcweir sal_Bool bInitiallyVisible, 112cdf0e10cSrcweir sal_Bool bEnableChildTransparentMode, 113cdf0e10cSrcweir sal_Bool bEnableParentClip) 114cdf0e10cSrcweir throw (css::uno::RuntimeException) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir ::Window* pParentWindow = VCLUnoHelper::GetWindow(rxParentWindow); 117cdf0e10cSrcweir 118cdf0e10cSrcweir // Create a new window. 119cdf0e10cSrcweir ::Window* pWindow = NULL; 120cdf0e10cSrcweir if (bCreateSystemChildWindow) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir pWindow = new WorkWindow(pParentWindow, WB_SYSTEMCHILDWINDOW); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir else 125cdf0e10cSrcweir { 126cdf0e10cSrcweir pWindow = new ::Window(pParentWindow); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir Reference<awt::XWindow> xWindow (pWindow->GetComponentInterface(), UNO_QUERY); 129cdf0e10cSrcweir 130cdf0e10cSrcweir if (bEnableChildTransparentMode) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir // Make the frame window transparent and make the parent able to 133cdf0e10cSrcweir // draw behind it. 134cdf0e10cSrcweir if (pParentWindow != NULL) 135cdf0e10cSrcweir pParentWindow->EnableChildTransparentMode(sal_True); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir if (pWindow != NULL) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir pWindow->Show(bInitiallyVisible); 141cdf0e10cSrcweir 142cdf0e10cSrcweir pWindow->SetMapMode(MAP_PIXEL); 143cdf0e10cSrcweir pWindow->SetBackground(); 144cdf0e10cSrcweir if ( ! bEnableParentClip) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir pWindow->SetParentClipMode(PARENTCLIPMODE_NOCLIP); 147cdf0e10cSrcweir pWindow->SetPaintTransparent(sal_True); 148cdf0e10cSrcweir } 149cdf0e10cSrcweir else 150cdf0e10cSrcweir { 151cdf0e10cSrcweir pWindow->SetParentClipMode(PARENTCLIPMODE_CLIP); 152cdf0e10cSrcweir pWindow->SetPaintTransparent(sal_False); 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir return xWindow; 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162cdf0e10cSrcweir 163cdf0e10cSrcweir Reference<rendering::XCanvas> SAL_CALL PresenterHelper::createSharedCanvas ( 164cdf0e10cSrcweir const Reference<rendering::XSpriteCanvas>& rxUpdateCanvas, 165cdf0e10cSrcweir const Reference<awt::XWindow>& rxUpdateWindow, 166cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxSharedCanvas, 167cdf0e10cSrcweir const Reference<awt::XWindow>& rxSharedWindow, 168cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow) 169cdf0e10cSrcweir throw (css::uno::RuntimeException) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if ( ! rxSharedCanvas.is() 172cdf0e10cSrcweir || ! rxSharedWindow.is() 173cdf0e10cSrcweir || ! rxWindow.is()) 174cdf0e10cSrcweir { 175cdf0e10cSrcweir throw RuntimeException( 176cdf0e10cSrcweir OUString::createFromAscii("illegal argument"), 177cdf0e10cSrcweir Reference<XInterface>(static_cast<XWeak*>(this))); 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir if (rxWindow == rxSharedWindow) 181cdf0e10cSrcweir return rxSharedCanvas; 182cdf0e10cSrcweir else 183cdf0e10cSrcweir return new PresenterCanvas( 184cdf0e10cSrcweir rxUpdateCanvas, 185cdf0e10cSrcweir rxUpdateWindow, 186cdf0e10cSrcweir rxSharedCanvas, 187cdf0e10cSrcweir rxSharedWindow, 188cdf0e10cSrcweir rxWindow); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir 192cdf0e10cSrcweir 193cdf0e10cSrcweir 194cdf0e10cSrcweir Reference<rendering::XCanvas> SAL_CALL PresenterHelper::createCanvas ( 195cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow, 196cdf0e10cSrcweir sal_Int16 nRequestedCanvasFeatures, 197cdf0e10cSrcweir const OUString& rsOptionalCanvasServiceName) 198cdf0e10cSrcweir throw (css::uno::RuntimeException) 199cdf0e10cSrcweir { 200cdf0e10cSrcweir (void)nRequestedCanvasFeatures; 201cdf0e10cSrcweir 202cdf0e10cSrcweir // No shared window is given or an explicit canvas service name is 203cdf0e10cSrcweir // specified. Create a new canvas. 204cdf0e10cSrcweir ::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); 205cdf0e10cSrcweir if (pWindow != NULL) 206cdf0e10cSrcweir { 207cdf0e10cSrcweir Sequence<Any> aArg (5); 208cdf0e10cSrcweir 209cdf0e10cSrcweir // common: first any is VCL pointer to window (for VCL canvas) 210cdf0e10cSrcweir aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow)); 211cdf0e10cSrcweir aArg[1] = Any(); 212cdf0e10cSrcweir aArg[2] = makeAny(::com::sun::star::awt::Rectangle()); 213cdf0e10cSrcweir aArg[3] = makeAny(sal_False); 214cdf0e10cSrcweir aArg[4] = makeAny(rxWindow); 215cdf0e10cSrcweir 216cdf0e10cSrcweir Reference<lang::XMultiServiceFactory> xFactory ( 217cdf0e10cSrcweir mxComponentContext->getServiceManager(), UNO_QUERY_THROW); 218cdf0e10cSrcweir return Reference<rendering::XCanvas>( 219cdf0e10cSrcweir xFactory->createInstanceWithArguments( 220cdf0e10cSrcweir rsOptionalCanvasServiceName.getLength()>0 221cdf0e10cSrcweir ? rsOptionalCanvasServiceName 222cdf0e10cSrcweir : OUString::createFromAscii("com.sun.star.rendering.VCLCanvas"), 223cdf0e10cSrcweir aArg), 224cdf0e10cSrcweir UNO_QUERY); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir else 227cdf0e10cSrcweir throw RuntimeException(); 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir 231cdf0e10cSrcweir 232cdf0e10cSrcweir 233cdf0e10cSrcweir void SAL_CALL PresenterHelper::toTop ( 234cdf0e10cSrcweir const Reference<awt::XWindow>& rxWindow) 235cdf0e10cSrcweir throw (css::uno::RuntimeException) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir ::Window* pWindow = VCLUnoHelper::GetWindow(rxWindow); 238cdf0e10cSrcweir if (pWindow != NULL) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir pWindow->ToTop(); 241cdf0e10cSrcweir pWindow->SetZOrder(NULL, WINDOW_ZORDER_LAST); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir 246cdf0e10cSrcweir 247cdf0e10cSrcweir 248cdf0e10cSrcweir Reference<rendering::XBitmap> SAL_CALL PresenterHelper::loadBitmap ( 249cdf0e10cSrcweir const OUString& rsURL, 250cdf0e10cSrcweir const Reference<rendering::XCanvas>& rxCanvas) 251cdf0e10cSrcweir throw (RuntimeException) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir if ( ! rxCanvas.is()) 254cdf0e10cSrcweir return NULL; 255cdf0e10cSrcweir 256cdf0e10cSrcweir ::osl::MutexGuard aGuard (::osl::Mutex::getGlobalMutex()); 257cdf0e10cSrcweir 258cdf0e10cSrcweir if (mpGraphicFilter.get() == NULL) 259cdf0e10cSrcweir mpGraphicFilter.reset(new GraphicFilter(sal_False)); 260cdf0e10cSrcweir 261cdf0e10cSrcweir const cppcanvas::CanvasSharedPtr pCanvas ( 262cdf0e10cSrcweir cppcanvas::VCLFactory::getInstance().createCanvas( 263cdf0e10cSrcweir Reference<css::rendering::XBitmapCanvas>(rxCanvas,UNO_QUERY))); 264cdf0e10cSrcweir 265cdf0e10cSrcweir if (pCanvas.get()!=NULL && rsURL.getLength()>0 && mpGraphicFilter.get()!=NULL) 266cdf0e10cSrcweir { 267*79e0a548SAriel Constenla-Haile sal_Int32 nIndex = 0; 268*79e0a548SAriel Constenla-Haile if( rsURL.getToken( 0, '/', nIndex ).equalsAsciiL( 269*79e0a548SAriel Constenla-Haile RTL_CONSTASCII_STRINGPARAM( "private:graphicrepository" ) ) ) 270cdf0e10cSrcweir { 271*79e0a548SAriel Constenla-Haile OUString sPathName( rsURL.copy( nIndex ) ); 272*79e0a548SAriel Constenla-Haile BitmapEx aBitmap; 273*79e0a548SAriel Constenla-Haile if ( ::vcl::ImageRepository::loadImage( sPathName, aBitmap, false ) 274*79e0a548SAriel Constenla-Haile && !aBitmap.IsEmpty() ) 275cdf0e10cSrcweir return cppcanvas::VCLFactory::getInstance().createBitmap( 276cdf0e10cSrcweir pCanvas, 277*79e0a548SAriel Constenla-Haile aBitmap)->getUNOBitmap(); 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