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