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_dbaccess.hxx" 30 31 #include "dbmm_module.hxx" 32 #include "dbmm_global.hrc" 33 #include "macromigrationdialog.hxx" 34 35 /** === begin UNO includes === **/ 36 #include <com/sun/star/ucb/AlreadyInitializedException.hpp> 37 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp> 38 #include <com/sun/star/frame/XStorable.hpp> 39 /** === end UNO includes === **/ 40 41 #include <comphelper/componentcontext.hxx> 42 #include <svtools/genericunodialog.hxx> 43 44 //........................................................................ 45 namespace dbmm 46 { 47 //........................................................................ 48 49 /** === begin UNO using === **/ 50 using ::com::sun::star::uno::Reference; 51 using ::com::sun::star::uno::XInterface; 52 using ::com::sun::star::uno::UNO_QUERY; 53 using ::com::sun::star::uno::UNO_QUERY_THROW; 54 using ::com::sun::star::uno::UNO_SET_THROW; 55 using ::com::sun::star::uno::Exception; 56 using ::com::sun::star::uno::RuntimeException; 57 using ::com::sun::star::uno::Any; 58 using ::com::sun::star::uno::makeAny; 59 using ::com::sun::star::uno::XComponentContext; 60 using ::com::sun::star::uno::Sequence; 61 using ::com::sun::star::beans::XPropertySetInfo; 62 using ::com::sun::star::beans::Property; 63 using ::com::sun::star::ucb::AlreadyInitializedException; 64 using ::com::sun::star::sdb::XOfficeDatabaseDocument; 65 using ::com::sun::star::lang::IllegalArgumentException; 66 using ::com::sun::star::frame::XStorable; 67 /** === end UNO using === **/ 68 69 //==================================================================== 70 //= MacroMigrationDialogService 71 //==================================================================== 72 class MacroMigrationDialogService; 73 typedef ::svt::OGenericUnoDialog MacroMigrationDialogService_Base; 74 typedef ::comphelper::OPropertyArrayUsageHelper< MacroMigrationDialogService > MacroMigrationDialogService_PBase; 75 76 class MacroMigrationDialogService 77 :public MacroMigrationDialogService_Base 78 ,public MacroMigrationDialogService_PBase 79 ,public MacroMigrationModuleClient 80 { 81 public: 82 MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext ); 83 84 // XTypeProvider 85 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException); 86 87 // XServiceInfo 88 virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException); 89 virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException); 90 91 // XInitialization 92 virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ) throw(com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException); 93 94 // XPropertySet 95 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException); 96 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); 97 98 // OPropertyArrayUsageHelper 99 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const; 100 101 // helper for factories 102 static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& _rxContext ); 103 static ::rtl::OUString SAL_CALL getImplementationName_static() throw(RuntimeException); 104 static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static() throw(RuntimeException); 105 106 protected: 107 ~MacroMigrationDialogService(); 108 109 protected: 110 virtual Dialog* createDialog( Window* _pParent ); 111 virtual void destroyDialog(); 112 113 private: 114 ::comphelper::ComponentContext m_aContext; 115 Reference< XOfficeDatabaseDocument > m_xDocument; 116 }; 117 118 //==================================================================== 119 //= MacroMigrationDialogService 120 //==================================================================== 121 //-------------------------------------------------------------------- 122 MacroMigrationDialogService::MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext ) 123 :MacroMigrationDialogService_Base( _rxContext ) 124 ,m_aContext( _rxContext ) 125 { 126 m_bNeedInitialization = true; 127 } 128 129 //-------------------------------------------------------------------- 130 MacroMigrationDialogService::~MacroMigrationDialogService() 131 { 132 // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor, 133 // so this virtual-method-call the base class does does not work, we're already dead then ... 134 if ( m_pDialog ) 135 { 136 ::osl::MutexGuard aGuard( m_aMutex ); 137 if ( m_pDialog ) 138 destroyDialog(); 139 } 140 } 141 142 //-------------------------------------------------------------------- 143 Reference< XInterface > SAL_CALL MacroMigrationDialogService::Create( const Reference< XComponentContext >& _rxContext ) 144 { 145 return *(new MacroMigrationDialogService( _rxContext ) ); 146 } 147 148 //-------------------------------------------------------------------- 149 Dialog* MacroMigrationDialogService::createDialog( Window* _pParent ) 150 { 151 return new MacroMigrationDialog( _pParent, m_aContext, m_xDocument ); 152 } 153 154 //-------------------------------------------------------------------- 155 void MacroMigrationDialogService::destroyDialog() 156 { 157 MacroMigrationDialogService_Base::destroyDialog(); 158 } 159 160 //-------------------------------------------------------------------- 161 Sequence< sal_Int8 > SAL_CALL MacroMigrationDialogService::getImplementationId() throw(RuntimeException) 162 { 163 static ::cppu::OImplementationId* pId = NULL; 164 if ( !pId ) 165 { 166 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); 167 if ( !pId ) 168 { 169 static ::cppu::OImplementationId aId; 170 pId = &aId; 171 } 172 } 173 return pId->getImplementationId(); 174 } 175 176 //-------------------------------------------------------------------- 177 ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException) 178 { 179 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" ) ); 180 } 181 182 //-------------------------------------------------------------------- 183 Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException) 184 { 185 Sequence< ::rtl::OUString > aServices(1); 186 aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) ); 187 return aServices; 188 } 189 190 //-------------------------------------------------------------------- 191 ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName() throw(RuntimeException) 192 { 193 return getImplementationName_static(); 194 } 195 196 //-------------------------------------------------------------------- 197 Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException) 198 { 199 return getSupportedServiceNames_static(); 200 } 201 202 //-------------------------------------------------------------------- 203 void SAL_CALL MacroMigrationDialogService::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException) 204 { 205 ::osl::MutexGuard aGuard( m_aMutex ); 206 if ( m_bInitialized ) 207 throw AlreadyInitializedException( ::rtl::OUString(), *this ); 208 209 if ( _rArguments.getLength() != 1 ) 210 throw IllegalArgumentException( 211 String(MacroMigrationResId(STR_INVALID_NUMBER_ARGS)), 212 *this, 213 1 214 ); 215 216 m_xDocument.set( _rArguments[0], UNO_QUERY ); 217 if ( !m_xDocument.is() ) 218 throw IllegalArgumentException( 219 String(MacroMigrationResId(STR_NO_DATABASE)), 220 *this, 221 1 222 ); 223 224 Reference< XStorable > xDocStor( m_xDocument, UNO_QUERY_THROW ); 225 if ( xDocStor->isReadonly() ) 226 throw IllegalArgumentException( 227 String(MacroMigrationResId(STR_NOT_READONLY)), 228 *this, 229 1 230 ); 231 232 m_bInitialized = true; 233 } 234 235 //-------------------------------------------------------------------- 236 Reference< XPropertySetInfo > SAL_CALL MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException) 237 { 238 return createPropertySetInfo( getInfoHelper() ); 239 } 240 241 //-------------------------------------------------------------------- 242 ::cppu::IPropertyArrayHelper& SAL_CALL MacroMigrationDialogService::getInfoHelper() 243 { 244 return *const_cast< MacroMigrationDialogService* >( this )->getArrayHelper(); 245 } 246 247 //-------------------------------------------------------------------- 248 ::cppu::IPropertyArrayHelper* MacroMigrationDialogService::createArrayHelper( ) const 249 { 250 Sequence< Property > aProps; 251 describeProperties( aProps ); 252 return new ::cppu::OPropertyArrayHelper( aProps ); 253 } 254 255 //-------------------------------------------------------------------- 256 void createRegistryInfo_MacroMigrationDialogService() 257 { 258 static OAutoRegistration< MacroMigrationDialogService > aAutoRegistration; 259 } 260 261 //........................................................................ 262 } // namespace dbmm 263 //........................................................................ 264