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_svtools.hxx" 30 #include <com/sun/star/embed/XHatchWindowController.hpp> 31 32 #include "hatchwindow.hxx" 33 #include "ipwin.hxx" 34 35 #include <toolkit/helper/convert.hxx> 36 #include <vos/mutex.hxx> 37 #include <vcl/svapp.hxx> 38 39 using namespace ::com::sun::star; 40 41 VCLXHatchWindow::VCLXHatchWindow() 42 : VCLXWindow() 43 , pHatchWindow(0) 44 { 45 } 46 47 VCLXHatchWindow::~VCLXHatchWindow() 48 { 49 } 50 51 void VCLXHatchWindow::initializeWindow( const uno::Reference< awt::XWindowPeer >& xParent, 52 const awt::Rectangle& aBounds, 53 const awt::Size& aSize ) 54 { 55 ::vos::OGuard aGuard( Application::GetSolarMutex() ); 56 57 Window* pParent = NULL; 58 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation( xParent ); 59 60 if ( pParentComponent ) 61 pParent = pParentComponent->GetWindow(); 62 63 OSL_ENSURE( pParent, "No parent window is provided!\n" ); 64 if ( !pParent ) 65 throw lang::IllegalArgumentException(); // TODO 66 67 pHatchWindow = new SvResizeWindow( pParent, this ); 68 pHatchWindow->SetPosSizePixel( aBounds.X, aBounds.Y, aBounds.Width, aBounds.Height ); 69 aHatchBorderSize = aSize; 70 pHatchWindow->SetHatchBorderPixel( Size( aSize.Width, aSize.Height ) ); 71 72 SetWindow( pHatchWindow ); 73 pHatchWindow->SetComponentInterface( this ); 74 75 //pHatchWindow->Show(); 76 } 77 78 void VCLXHatchWindow::QueryObjAreaPixel( Rectangle & aRect ) 79 { 80 if ( m_xController.is() ) 81 { 82 awt::Rectangle aUnoRequestRect = AWTRectangle( aRect ); 83 84 try { 85 awt::Rectangle aUnoResultRect = m_xController->calcAdjustedRectangle( aUnoRequestRect ); 86 aRect = VCLRectangle( aUnoResultRect ); 87 } 88 catch( uno::Exception& ) 89 { 90 OSL_ENSURE( sal_False, "Can't adjust rectangle size!\n" ); 91 } 92 } 93 } 94 95 void VCLXHatchWindow::RequestObjAreaPixel( const Rectangle & aRect ) 96 { 97 if ( m_xController.is() ) 98 { 99 awt::Rectangle aUnoRequestRect = AWTRectangle( aRect ); 100 101 try { 102 m_xController->requestPositioning( aUnoRequestRect ); 103 } 104 catch( uno::Exception& ) 105 { 106 OSL_ENSURE( sal_False, "Can't request resizing!\n" ); 107 } 108 } 109 } 110 111 void VCLXHatchWindow::InplaceDeactivate() 112 { 113 if ( m_xController.is() ) 114 { 115 // TODO: communicate with controller 116 } 117 } 118 119 120 uno::Any SAL_CALL VCLXHatchWindow::queryInterface( const uno::Type & rType ) 121 throw( uno::RuntimeException ) 122 { 123 // Attention: 124 // Don't use mutex or guard in this method!!! Is a method of XInterface. 125 126 uno::Any aReturn( ::cppu::queryInterface( rType, 127 static_cast< embed::XHatchWindow* >( this ) ) ); 128 129 if ( aReturn.hasValue() == sal_True ) 130 { 131 return aReturn ; 132 } 133 134 return VCLXWindow::queryInterface( rType ) ; 135 } 136 137 void SAL_CALL VCLXHatchWindow::acquire() 138 throw() 139 { 140 VCLXWindow::acquire(); 141 } 142 143 void SAL_CALL VCLXHatchWindow::release() 144 throw() 145 { 146 VCLXWindow::release(); 147 } 148 149 uno::Sequence< uno::Type > SAL_CALL VCLXHatchWindow::getTypes() 150 throw( uno::RuntimeException ) 151 { 152 static ::cppu::OTypeCollection* pTypeCollection = NULL ; 153 154 if ( pTypeCollection == NULL ) 155 { 156 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; 157 158 if ( pTypeCollection == NULL ) 159 { 160 static ::cppu::OTypeCollection aTypeCollection( 161 ::getCppuType(( const uno::Reference< embed::XHatchWindow >* )NULL ), 162 VCLXHatchWindow::getTypes() ); 163 164 pTypeCollection = &aTypeCollection ; 165 } 166 } 167 168 return pTypeCollection->getTypes() ; 169 } 170 171 uno::Sequence< sal_Int8 > SAL_CALL VCLXHatchWindow::getImplementationId() 172 throw( uno::RuntimeException ) 173 { 174 static ::cppu::OImplementationId* pID = NULL ; 175 176 if ( pID == NULL ) 177 { 178 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ) ; 179 180 if ( pID == NULL ) 181 { 182 static ::cppu::OImplementationId aID( sal_False ) ; 183 pID = &aID ; 184 } 185 } 186 187 return pID->getImplementationId() ; 188 } 189 190 ::com::sun::star::awt::Size SAL_CALL VCLXHatchWindow::getHatchBorderSize() throw (::com::sun::star::uno::RuntimeException) 191 { 192 return aHatchBorderSize; 193 } 194 195 void SAL_CALL VCLXHatchWindow::setHatchBorderSize( const ::com::sun::star::awt::Size& _hatchbordersize ) throw (::com::sun::star::uno::RuntimeException) 196 { 197 if ( pHatchWindow ) 198 { 199 aHatchBorderSize = _hatchbordersize; 200 pHatchWindow->SetHatchBorderPixel( Size( aHatchBorderSize.Width, aHatchBorderSize.Height ) ); 201 } 202 } 203 204 void SAL_CALL VCLXHatchWindow::setController( const uno::Reference< embed::XHatchWindowController >& xController ) 205 throw (uno::RuntimeException) 206 { 207 m_xController = xController; 208 } 209 210 void SAL_CALL VCLXHatchWindow::dispose() 211 throw (uno::RuntimeException) 212 { 213 pHatchWindow = 0; 214 VCLXWindow::dispose(); 215 } 216 217 void SAL_CALL VCLXHatchWindow::addEventListener( const uno::Reference< lang::XEventListener >& xListener ) 218 throw (uno::RuntimeException) 219 { 220 VCLXWindow::addEventListener( xListener ); 221 } 222 223 void SAL_CALL VCLXHatchWindow::removeEventListener( const uno::Reference< lang::XEventListener >& xListener ) 224 throw (uno::RuntimeException) 225 { 226 VCLXWindow::removeEventListener( xListener ); 227 } 228 229 void VCLXHatchWindow::Activated() 230 { 231 if ( m_xController.is() ) 232 m_xController->activated(); 233 } 234 235 void VCLXHatchWindow::Deactivated() 236 { 237 if ( m_xController.is() ) 238 m_xController->deactivated(); 239 } 240