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