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_chart2.hxx" 26 27 #include "dlg_CreationWizard_UNO.hxx" 28 #include "dlg_CreationWizard.hxx" 29 #include "macros.hxx" 30 #include "servicenames.hxx" 31 #include "ContainerHelper.hxx" 32 #include "TimerTriggeredControllerLock.hxx" 33 #include <osl/mutex.hxx> 34 #include <vos/mutex.hxx> 35 // header for class Application 36 #include <vcl/svapp.hxx> 37 #include <toolkit/awt/vclxwindow.hxx> 38 // header for define RET_CANCEL 39 #include <vcl/msgbox.hxx> 40 // header for class OImplementationId 41 #include <cppuhelper/typeprovider.hxx> 42 #include <com/sun/star/awt/Point.hpp> 43 #include <com/sun/star/awt/Size.hpp> 44 #include <com/sun/star/beans/PropertyValue.hpp> 45 #include <com/sun/star/frame/XDesktop.hpp> 46 47 //............................................................................. 48 namespace chart 49 { 50 //............................................................................. 51 using namespace ::com::sun::star; 52 53 CreationWizardUnoDlg::CreationWizardUnoDlg( const uno::Reference< uno::XComponentContext >& xContext ) 54 : OComponentHelper( m_aMutex ) 55 , m_xChartModel( 0 ) 56 , m_xCC( xContext ) 57 , m_xParentWindow( 0 ) 58 , m_pDialog( 0 ) 59 , m_bUnlockControllersOnExecute(false) 60 { 61 uno::Reference< frame::XDesktop > xDesktop( 62 m_xCC->getServiceManager()->createInstanceWithContext( 63 C2U( "com.sun.star.frame.Desktop" ), m_xCC ), uno::UNO_QUERY ); 64 if( xDesktop.is() ) 65 { 66 uno::Reference< frame::XTerminateListener > xListener( this ); 67 xDesktop->addTerminateListener( xListener ); 68 } 69 } 70 CreationWizardUnoDlg::~CreationWizardUnoDlg() 71 { 72 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 73 if( m_pDialog ) 74 { 75 delete m_pDialog; 76 m_pDialog = 0; 77 } 78 } 79 //------------------------------------------------------------------------- 80 // lang::XServiceInfo 81 APPHELPER_XSERVICEINFO_IMPL(CreationWizardUnoDlg,CHART_WIZARD_DIALOG_SERVICE_IMPLEMENTATION_NAME) 82 83 uno::Sequence< rtl::OUString > CreationWizardUnoDlg 84 ::getSupportedServiceNames_Static() 85 { 86 uno::Sequence< rtl::OUString > aSNS( 1 ); 87 aSNS.getArray()[ 0 ] = CHART_WIZARD_DIALOG_SERVICE_NAME; 88 return aSNS; 89 } 90 91 //------------------------------------------------------------------------- 92 // XInterface 93 uno::Any SAL_CALL CreationWizardUnoDlg::queryInterface( const uno::Type& aType ) throw (uno::RuntimeException) 94 { 95 return OComponentHelper::queryInterface( aType ); 96 } 97 void SAL_CALL CreationWizardUnoDlg::acquire() throw () 98 { 99 OComponentHelper::acquire(); 100 } 101 void SAL_CALL CreationWizardUnoDlg::release() throw () 102 { 103 OComponentHelper::release(); 104 } 105 uno::Any SAL_CALL CreationWizardUnoDlg::queryAggregation( uno::Type const & rType ) throw (uno::RuntimeException) 106 { 107 if (rType == ::getCppuType( (uno::Reference< ui::dialogs::XExecutableDialog > const *)0 )) 108 { 109 void * p = static_cast< ui::dialogs::XExecutableDialog * >( this ); 110 return uno::Any( &p, rType ); 111 } 112 else if (rType == ::getCppuType( (uno::Reference< lang::XServiceInfo > const *)0 )) 113 { 114 void * p = static_cast< lang::XTypeProvider * >( this ); 115 return uno::Any( &p, rType ); 116 } 117 else if (rType == ::getCppuType( (uno::Reference< lang::XInitialization > const *)0 )) 118 { 119 void * p = static_cast< lang::XInitialization * >( this ); 120 return uno::Any( &p, rType ); 121 } 122 else if (rType == ::getCppuType( (uno::Reference< frame::XTerminateListener > const *)0 )) 123 { 124 void * p = static_cast< frame::XTerminateListener * >( this ); 125 return uno::Any( &p, rType ); 126 } 127 else if (rType == ::getCppuType( (uno::Reference< beans::XPropertySet > const *)0 )) 128 { 129 void * p = static_cast< beans::XPropertySet * >( this ); 130 return uno::Any( &p, rType ); 131 } 132 return OComponentHelper::queryAggregation( rType ); 133 } 134 135 //------------------------------------------------------------------------- 136 #define LCL_CPPUTYPE(t) (::getCppuType( reinterpret_cast< const uno::Reference<t> *>(0))) 137 138 uno::Sequence< uno::Type > CreationWizardUnoDlg::getTypes() throw(uno::RuntimeException) 139 { 140 static uno::Sequence< uno::Type > aTypeList; 141 142 // /-- 143 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 144 if( !aTypeList.getLength() ) 145 { 146 ::std::vector< uno::Type > aTypes; 147 aTypes.push_back( LCL_CPPUTYPE( lang::XComponent )); 148 aTypes.push_back( LCL_CPPUTYPE( lang::XTypeProvider )); 149 aTypes.push_back( LCL_CPPUTYPE( uno::XAggregation )); 150 aTypes.push_back( LCL_CPPUTYPE( uno::XWeak )); 151 aTypes.push_back( LCL_CPPUTYPE( lang::XServiceInfo )); 152 aTypes.push_back( LCL_CPPUTYPE( lang::XInitialization )); 153 aTypes.push_back( LCL_CPPUTYPE( frame::XTerminateListener )); 154 aTypes.push_back( LCL_CPPUTYPE( ui::dialogs::XExecutableDialog )); 155 aTypes.push_back( LCL_CPPUTYPE( beans::XPropertySet )); 156 aTypeList = ::chart::ContainerHelper::ContainerToSequence( aTypes ); 157 } 158 159 return aTypeList; 160 // \-- 161 } 162 uno::Sequence< sal_Int8 > SAL_CALL CreationWizardUnoDlg::getImplementationId( void ) throw( uno::RuntimeException ) 163 { 164 static uno::Sequence< sal_Int8 > aId; 165 if( aId.getLength() == 0 ) 166 { 167 aId.realloc( 16 ); 168 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True ); 169 } 170 return aId; 171 } 172 173 //------------------------------------------------------------------------- 174 175 // XTerminateListener 176 void SAL_CALL CreationWizardUnoDlg::queryTermination( const lang::EventObject& /*Event*/ ) throw( frame::TerminationVetoException, uno::RuntimeException) 177 { 178 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 179 180 // we will never give a veto here 181 if( m_pDialog && !m_pDialog->isClosable() ) 182 { 183 m_pDialog->ToTop(); 184 throw frame::TerminationVetoException(); 185 } 186 } 187 188 //------------------------------------------------------------------------- 189 190 void SAL_CALL CreationWizardUnoDlg::notifyTermination( const lang::EventObject& /*Event*/ ) throw (uno::RuntimeException) 191 { 192 // we are going down, so dispose us! 193 dispose(); 194 } 195 196 void SAL_CALL CreationWizardUnoDlg::disposing( const lang::EventObject& /*Source*/ ) throw (uno::RuntimeException) 197 { 198 //Listener should deregister himself and relaese all references to the closing object. 199 } 200 201 //------------------------------------------------------------------------- 202 void SAL_CALL CreationWizardUnoDlg::setTitle( const ::rtl::OUString& /*rTitle*/ ) throw(uno::RuntimeException) 203 { 204 } 205 //------------------------------------------------------------------------- 206 void CreationWizardUnoDlg::createDialogOnDemand() 207 { 208 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 209 if( !m_pDialog ) 210 { 211 Window* pParent = NULL; 212 if( !m_xParentWindow.is() && m_xChartModel.is() ) 213 { 214 uno::Reference< frame::XController > xController( 215 m_xChartModel->getCurrentController() ); 216 if( xController.is() ) 217 { 218 uno::Reference< frame::XFrame > xFrame( 219 xController->getFrame() ); 220 if(xFrame.is()) 221 m_xParentWindow = xFrame->getContainerWindow(); 222 } 223 } 224 if( m_xParentWindow.is() ) 225 { 226 VCLXWindow* pImplementation = VCLXWindow::GetImplementation(m_xParentWindow); 227 if (pImplementation) 228 pParent = pImplementation->GetWindow(); 229 } 230 uno::Reference< XComponent > xComp( this ); 231 if( m_xChartModel.is() ) 232 { 233 m_pDialog = new CreationWizard( pParent, m_xChartModel, m_xCC ); 234 m_pDialog->AddEventListener( LINK( this, CreationWizardUnoDlg, DialogEventHdl ) ); 235 } 236 } 237 } 238 //------------------------------------------------------------------------- 239 IMPL_LINK( CreationWizardUnoDlg, DialogEventHdl, VclWindowEvent*, pEvent ) 240 { 241 if(pEvent && (pEvent->GetId() == VCLEVENT_OBJECT_DYING) ) 242 m_pDialog = 0;//avoid duplicate destruction of m_pDialog 243 return 0; 244 } 245 246 //------------------------------------------------------------------------- 247 sal_Int16 SAL_CALL CreationWizardUnoDlg::execute( ) throw(uno::RuntimeException) 248 { 249 sal_Int16 nRet = RET_CANCEL; 250 { 251 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 252 createDialogOnDemand(); 253 if( !m_pDialog ) 254 return nRet; 255 TimerTriggeredControllerLock aTimerTriggeredControllerLock( m_xChartModel ); 256 if( m_bUnlockControllersOnExecute && m_xChartModel.is() ) 257 m_xChartModel->unlockControllers(); 258 nRet = m_pDialog->Execute(); 259 } 260 return nRet; 261 } 262 263 //------------------------------------------------------------------------- 264 void SAL_CALL CreationWizardUnoDlg::initialize( const uno::Sequence< uno::Any >& aArguments ) throw(uno::Exception, uno::RuntimeException) 265 { 266 const uno::Any* pArguments = aArguments.getConstArray(); 267 for(sal_Int32 i=0; i<aArguments.getLength(); ++i, ++pArguments) 268 { 269 beans::PropertyValue aProperty; 270 if(*pArguments >>= aProperty) 271 { 272 if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ParentWindow" ) ) == 0 ) 273 { 274 aProperty.Value >>= m_xParentWindow; 275 } 276 else if( aProperty.Name.compareToAscii( RTL_CONSTASCII_STRINGPARAM( "ChartModel" ) ) == 0 ) 277 { 278 aProperty.Value >>= m_xChartModel; 279 } 280 } 281 } 282 } 283 284 //------------------------------------------------------------------------- 285 // ____ OComponentHelper ____ 286 /// Called in dispose method after the listeners were notified. 287 void SAL_CALL CreationWizardUnoDlg::disposing() 288 { 289 m_xChartModel.clear(); 290 m_xParentWindow.clear(); 291 292 // /-- 293 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 294 if( m_pDialog ) 295 { 296 delete m_pDialog; 297 m_pDialog = 0; 298 } 299 300 try 301 { 302 uno::Reference< frame::XDesktop > xDesktop( 303 m_xCC->getServiceManager()->createInstanceWithContext( 304 C2U( "com.sun.star.frame.Desktop" ), m_xCC ), uno::UNO_QUERY ); 305 if( xDesktop.is() ) 306 { 307 uno::Reference< frame::XTerminateListener > xListener( this ); 308 xDesktop->removeTerminateListener( xListener ); 309 } 310 } 311 catch( const uno::Exception & ex ) 312 { 313 ASSERT_EXCEPTION( ex ); 314 } 315 // \-- 316 } 317 318 //XPropertySet 319 uno::Reference< beans::XPropertySetInfo > SAL_CALL CreationWizardUnoDlg::getPropertySetInfo() 320 throw (uno::RuntimeException) 321 { 322 OSL_ENSURE(false,"not implemented"); 323 return 0; 324 } 325 326 void SAL_CALL CreationWizardUnoDlg::setPropertyValue( const ::rtl::OUString& rPropertyName 327 , const uno::Any& rValue ) 328 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException 329 , lang::WrappedTargetException, uno::RuntimeException) 330 { 331 if( rPropertyName.equals(C2U("Position")) ) 332 { 333 awt::Point aPos; 334 if( ! (rValue >>= aPos) ) 335 throw lang::IllegalArgumentException( C2U("Property 'Position' requires value of type awt::Point"), 0, 0 ); 336 337 //set left upper outer corner relative to screen 338 //pixels, screen position 339 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 340 createDialogOnDemand(); 341 if( m_pDialog ) 342 { 343 m_pDialog->SetPosPixel( Point(0,0) ); 344 Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) ); 345 346 Point aNewOuterPos = Point( aPos.X - aRect.Left(), aPos.Y - aRect.Top() ); 347 m_pDialog->SetPosPixel( aNewOuterPos ); 348 } 349 } 350 else if( rPropertyName.equals(C2U("Size")) ) 351 { 352 //read only property, do nothing 353 } 354 else if( rPropertyName.equals(C2U("UnlockControllersOnExecute")) ) 355 { 356 if( ! (rValue >>= m_bUnlockControllersOnExecute) ) 357 throw lang::IllegalArgumentException( C2U("Property 'UnlockControllers' requires value of type boolean"), 0, 0 ); 358 } 359 else 360 throw beans::UnknownPropertyException( C2U("unknown property was tried to set to chart wizard"), 0 ); 361 } 362 363 uno::Any SAL_CALL CreationWizardUnoDlg::getPropertyValue( const ::rtl::OUString& rPropertyName ) 364 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 365 { 366 uno::Any aRet; 367 if( rPropertyName.equals(C2U("Position")) ) 368 { 369 //get left upper outer corner relative to screen 370 //pixels, screen position 371 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 372 createDialogOnDemand(); 373 if( m_pDialog ) 374 { 375 Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) ); 376 awt::Point aPoint(aRect.Left(),aRect.Top()); 377 aRet = uno::makeAny( aPoint ); 378 } 379 } 380 else if( rPropertyName.equals(C2U("Size")) ) 381 { 382 //get outer size inclusive decoration 383 //pixels, screen position 384 ::vos::OGuard aSolarGuard( Application::GetSolarMutex()); 385 createDialogOnDemand(); 386 if( m_pDialog ) 387 { 388 Rectangle aRect( m_pDialog->GetWindowExtentsRelative( 0 ) ); 389 awt::Size aSize(aRect.GetWidth(),aRect.GetHeight()); 390 aRet = uno::makeAny( aSize ); 391 } 392 } 393 else if( rPropertyName.equals(C2U("UnlockControllersOnExecute")) ) 394 { 395 aRet = uno::makeAny( m_bUnlockControllersOnExecute ); 396 } 397 else 398 throw beans::UnknownPropertyException( C2U("unknown property was tried to get from chart wizard"), 0 ); 399 return aRet; 400 } 401 402 void SAL_CALL CreationWizardUnoDlg::addPropertyChangeListener( 403 const ::rtl::OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* xListener */ ) 404 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 405 { 406 OSL_ENSURE(false,"not implemented"); 407 } 408 void SAL_CALL CreationWizardUnoDlg::removePropertyChangeListener( 409 const ::rtl::OUString& /* aPropertyName */, const uno::Reference< beans::XPropertyChangeListener >& /* aListener */ ) 410 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 411 { 412 OSL_ENSURE(false,"not implemented"); 413 } 414 415 void SAL_CALL CreationWizardUnoDlg::addVetoableChangeListener( const ::rtl::OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ ) 416 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 417 { 418 OSL_ENSURE(false,"not implemented"); 419 } 420 421 void SAL_CALL CreationWizardUnoDlg::removeVetoableChangeListener( const ::rtl::OUString& /* PropertyName */, const uno::Reference< beans::XVetoableChangeListener >& /* aListener */ ) 422 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 423 { 424 OSL_ENSURE(false,"not implemented"); 425 } 426 427 //............................................................................. 428 } //namespace chart 429 //............................................................................. 430