1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sdext.hxx" 30 31 #include "PresenterSpritePane.hxx" 32 #include "PresenterGeometryHelper.hxx" 33 #include <com/sun/star/lang/XMultiComponentFactory.hpp> 34 #include <com/sun/star/rendering/CompositeOperation.hpp> 35 #include <osl/mutex.hxx> 36 37 using namespace ::com::sun::star; 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star::drawing::framework; 40 using ::rtl::OUString; 41 42 namespace sdext { namespace presenter { 43 44 //===== PresenterSpritePane ========================================================= 45 46 PresenterSpritePane::PresenterSpritePane (const Reference<XComponentContext>& rxContext, 47 const ::rtl::Reference<PresenterController>& rpPresenterController) 48 : PresenterPaneBase(rxContext, rpPresenterController), 49 mxParentWindow(), 50 mxParentCanvas(), 51 mpSprite(new PresenterSprite()) 52 { 53 Reference<lang::XMultiComponentFactory> xFactory ( 54 mxComponentContext->getServiceManager(), UNO_QUERY_THROW); 55 mxPresenterHelper = Reference<drawing::XPresenterHelper>( 56 xFactory->createInstanceWithContext( 57 OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper"), 58 mxComponentContext), 59 UNO_QUERY_THROW); 60 } 61 62 63 64 65 PresenterSpritePane::~PresenterSpritePane (void) 66 { 67 } 68 69 70 71 72 void PresenterSpritePane::disposing (void) 73 { 74 mpSprite->SetFactory(NULL); 75 mxParentWindow = NULL; 76 mxParentCanvas = NULL; 77 PresenterPaneBase::disposing(); 78 } 79 80 81 82 83 //----- XPane ----------------------------------------------------------------- 84 85 Reference<awt::XWindow> SAL_CALL PresenterSpritePane::getWindow (void) 86 throw (RuntimeException) 87 { 88 ThrowIfDisposed(); 89 return mxContentWindow; 90 } 91 92 93 94 95 Reference<rendering::XCanvas> SAL_CALL PresenterSpritePane::getCanvas (void) 96 throw (RuntimeException) 97 { 98 ThrowIfDisposed(); 99 100 if ( ! mxContentCanvas.is()) 101 UpdateCanvases(); 102 103 return mxContentCanvas; 104 } 105 106 107 108 109 //----- XWindowListener ------------------------------------------------------- 110 111 void SAL_CALL PresenterSpritePane::windowResized (const awt::WindowEvent& rEvent) 112 throw (RuntimeException) 113 { 114 (void)rEvent; 115 PresenterPaneBase::windowResized(rEvent); 116 117 mpSprite->Resize(geometry::RealSize2D(rEvent.Width, rEvent.Height)); 118 LayoutContextWindow(); 119 UpdateCanvases(); 120 } 121 122 123 124 125 126 void SAL_CALL PresenterSpritePane::windowMoved (const awt::WindowEvent& rEvent) 127 throw (RuntimeException) 128 { 129 (void)rEvent; 130 PresenterPaneBase::windowMoved(rEvent); 131 132 awt::Rectangle aBox ( 133 mxPresenterHelper->getWindowExtentsRelative(mxBorderWindow, mxParentWindow)); 134 mpSprite->MoveTo(geometry::RealPoint2D(aBox.X, aBox.Y)); 135 mpSprite->Update(); 136 } 137 138 139 140 141 void SAL_CALL PresenterSpritePane::windowShown (const lang::EventObject& rEvent) 142 throw (RuntimeException) 143 { 144 (void)rEvent; 145 PresenterPaneBase::windowShown(rEvent); 146 147 mpSprite->Show(); 148 ToTop(); 149 150 if (mxContentWindow.is()) 151 { 152 LayoutContextWindow(); 153 mxContentWindow->setVisible(sal_True); 154 } 155 } 156 157 158 159 160 void SAL_CALL PresenterSpritePane::windowHidden (const lang::EventObject& rEvent) 161 throw (RuntimeException) 162 { 163 (void)rEvent; 164 PresenterPaneBase::windowHidden(rEvent); 165 166 mpSprite->Hide(); 167 if (mxContentWindow.is()) 168 mxContentWindow->setVisible(sal_False); 169 } 170 171 172 173 174 //----- XPaintListener -------------------------------------------------------- 175 176 void SAL_CALL PresenterSpritePane::windowPaint (const awt::PaintEvent& rEvent) 177 throw (RuntimeException) 178 { 179 (void)rEvent; 180 ThrowIfDisposed(); 181 182 /* 183 Reference<rendering::XSpriteCanvas> xSpriteCanvas (mxParentCanvas, UNO_QUERY); 184 if (xSpriteCanvas.is()) 185 xSpriteCanvas->updateScreen(sal_False); 186 */ 187 } 188 189 190 191 192 //----------------------------------------------------------------------------- 193 194 195 ::boost::shared_ptr<PresenterSprite> PresenterSpritePane::GetSprite (void) 196 { 197 return mpSprite; 198 } 199 200 201 202 203 void PresenterSpritePane::ShowTransparentBorder (void) 204 { 205 } 206 207 208 209 210 void PresenterSpritePane::UpdateCanvases (void) 211 { 212 Reference<XComponent> xContentCanvasComponent (mxContentCanvas, UNO_QUERY); 213 if (xContentCanvasComponent.is()) 214 { 215 if (xContentCanvasComponent.is()) 216 xContentCanvasComponent->dispose(); 217 } 218 219 // The border canvas is the content canvas of the sprite. 220 mxBorderCanvas = mpSprite->GetCanvas(); 221 222 // The content canvas is a wrapper of the border canvas. 223 if (mxBorderCanvas.is()) 224 mxContentCanvas = mxPresenterHelper->createSharedCanvas( 225 mxParentCanvas, 226 mxParentWindow, 227 mxBorderCanvas, 228 mxBorderWindow, 229 mxContentWindow); 230 231 const awt::Rectangle aWindowBox (mxBorderWindow->getPosSize()); 232 PaintBorder(awt::Rectangle(0,0,aWindowBox.Width,aWindowBox.Height)); 233 } 234 235 236 237 238 void PresenterSpritePane::CreateCanvases ( 239 const css::uno::Reference<css::awt::XWindow>& rxParentWindow, 240 const css::uno::Reference<css::rendering::XSpriteCanvas>& rxParentCanvas) 241 { 242 OSL_ASSERT(!mxParentWindow.is() || mxParentWindow==rxParentWindow); 243 OSL_ASSERT(!mxParentCanvas.is() || mxParentCanvas==rxParentCanvas); 244 mxParentWindow = rxParentWindow; 245 mxParentCanvas = rxParentCanvas; 246 247 mpSprite->SetFactory(mxParentCanvas); 248 if (mxBorderWindow.is()) 249 { 250 const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize()); 251 mpSprite->Resize(geometry::RealSize2D(aBorderBox.Width, aBorderBox.Height)); 252 } 253 254 UpdateCanvases(); 255 } 256 257 258 259 260 } } // end of namespace ::sd::presenter 261