196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
1096de5490SAndrew Rist  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1296de5490SAndrew Rist  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
1996de5490SAndrew Rist  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b63233d8Sdamjan #include "precompiled_dbmm.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "dbmm_module.hxx"
28cdf0e10cSrcweir #include "dbmm_global.hrc"
29cdf0e10cSrcweir #include "macromigrationdialog.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
33cdf0e10cSrcweir #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
34cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
35cdf0e10cSrcweir /** === end UNO includes === **/
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
38cdf0e10cSrcweir #include <svtools/genericunodialog.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //........................................................................
41cdf0e10cSrcweir namespace dbmm
42cdf0e10cSrcweir {
43cdf0e10cSrcweir //........................................................................
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	/** === begin UNO using === **/
46cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
53cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
54cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
55cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
56cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
57cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
58cdf0e10cSrcweir     using ::com::sun::star::beans::Property;
59cdf0e10cSrcweir     using ::com::sun::star::ucb::AlreadyInitializedException;
60cdf0e10cSrcweir     using ::com::sun::star::sdb::XOfficeDatabaseDocument;
61cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
62cdf0e10cSrcweir     using ::com::sun::star::frame::XStorable;
63cdf0e10cSrcweir 	/** === end UNO using === **/
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 	//====================================================================
66cdf0e10cSrcweir 	//= MacroMigrationDialogService
67cdf0e10cSrcweir 	//====================================================================
68cdf0e10cSrcweir     class MacroMigrationDialogService;
69cdf0e10cSrcweir     typedef ::svt::OGenericUnoDialog                                                MacroMigrationDialogService_Base;
70cdf0e10cSrcweir     typedef ::comphelper::OPropertyArrayUsageHelper< MacroMigrationDialogService >  MacroMigrationDialogService_PBase;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     class MacroMigrationDialogService
73cdf0e10cSrcweir                 :public MacroMigrationDialogService_Base
74cdf0e10cSrcweir                 ,public MacroMigrationDialogService_PBase
75cdf0e10cSrcweir                 ,public MacroMigrationModuleClient
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir     public:
78cdf0e10cSrcweir         MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir         // XTypeProvider
81cdf0e10cSrcweir 		virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 		// XServiceInfo
84cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
85cdf0e10cSrcweir         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
86cdf0e10cSrcweir 
87cdf0e10cSrcweir         // XInitialization
88cdf0e10cSrcweir 		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);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 	    // XPropertySet
91cdf0e10cSrcweir 	    virtual Reference< XPropertySetInfo >  SAL_CALL getPropertySetInfo() throw(RuntimeException);
92cdf0e10cSrcweir 	    virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	    // OPropertyArrayUsageHelper
95cdf0e10cSrcweir 	    virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         // helper for factories
98cdf0e10cSrcweir         static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& _rxContext );
99cdf0e10cSrcweir 		static ::rtl::OUString SAL_CALL getImplementationName_static() throw(RuntimeException);
100cdf0e10cSrcweir         static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static() throw(RuntimeException);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     protected:
103cdf0e10cSrcweir         ~MacroMigrationDialogService();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     protected:
106cdf0e10cSrcweir 		virtual Dialog*	createDialog( Window* _pParent );
107cdf0e10cSrcweir 	    virtual void destroyDialog();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     private:
110cdf0e10cSrcweir         ::comphelper::ComponentContext          m_aContext;
111cdf0e10cSrcweir         Reference< XOfficeDatabaseDocument >    m_xDocument;
112cdf0e10cSrcweir     };
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	//====================================================================
115cdf0e10cSrcweir 	//= MacroMigrationDialogService
116cdf0e10cSrcweir 	//====================================================================
117cdf0e10cSrcweir 	//--------------------------------------------------------------------
MacroMigrationDialogService(const Reference<XComponentContext> & _rxContext)118cdf0e10cSrcweir     MacroMigrationDialogService::MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext )
119cdf0e10cSrcweir         :MacroMigrationDialogService_Base( _rxContext )
120cdf0e10cSrcweir         ,m_aContext( _rxContext )
121cdf0e10cSrcweir     {
122cdf0e10cSrcweir         m_bNeedInitialization = true;
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     //--------------------------------------------------------------------
~MacroMigrationDialogService()126cdf0e10cSrcweir     MacroMigrationDialogService::~MacroMigrationDialogService()
127cdf0e10cSrcweir     {
128cdf0e10cSrcweir         // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor,
129cdf0e10cSrcweir         // so this virtual-method-call the base class does does not work, we're already dead then ...
130cdf0e10cSrcweir         if ( m_pDialog )
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
133cdf0e10cSrcweir             if ( m_pDialog )
134cdf0e10cSrcweir                 destroyDialog();
135cdf0e10cSrcweir         }
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     //--------------------------------------------------------------------
Create(const Reference<XComponentContext> & _rxContext)139cdf0e10cSrcweir     Reference< XInterface > SAL_CALL MacroMigrationDialogService::Create( const Reference< XComponentContext >& _rxContext )
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         return *(new MacroMigrationDialogService( _rxContext ) );
142cdf0e10cSrcweir     }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     //--------------------------------------------------------------------
createDialog(Window * _pParent)145cdf0e10cSrcweir 	Dialog*	MacroMigrationDialogService::createDialog( Window* _pParent )
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         return new MacroMigrationDialog( _pParent, m_aContext, m_xDocument );
148cdf0e10cSrcweir     }
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     //--------------------------------------------------------------------
destroyDialog()151cdf0e10cSrcweir     void MacroMigrationDialogService::destroyDialog()
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir 	    MacroMigrationDialogService_Base::destroyDialog();
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationId()157cdf0e10cSrcweir     Sequence< sal_Int8 > SAL_CALL MacroMigrationDialogService::getImplementationId() throw(RuntimeException)
158cdf0e10cSrcweir     {
159cdf0e10cSrcweir         static ::cppu::OImplementationId* pId = NULL;
160cdf0e10cSrcweir         if ( !pId )
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
163cdf0e10cSrcweir             if ( !pId )
164cdf0e10cSrcweir             {
165cdf0e10cSrcweir                 static ::cppu::OImplementationId aId;
166cdf0e10cSrcweir                 pId = &aId;
167cdf0e10cSrcweir             }
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir         return pId->getImplementationId();
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName_static()173cdf0e10cSrcweir     ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException)
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" ) );
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames_static()179cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException)
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         Sequence< ::rtl::OUString > aServices(1);
182cdf0e10cSrcweir         aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
183cdf0e10cSrcweir         return aServices;
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName()187cdf0e10cSrcweir     ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName() throw(RuntimeException)
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         return getImplementationName_static();
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames()193cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException)
194cdf0e10cSrcweir     {
195cdf0e10cSrcweir         return getSupportedServiceNames_static();
196cdf0e10cSrcweir     }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir     //--------------------------------------------------------------------
initialize(const Sequence<Any> & _rArguments)199cdf0e10cSrcweir     void SAL_CALL MacroMigrationDialogService::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException)
200cdf0e10cSrcweir     {
201cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
202cdf0e10cSrcweir         if ( m_bInitialized )
203cdf0e10cSrcweir             throw AlreadyInitializedException( ::rtl::OUString(), *this );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         if ( _rArguments.getLength() != 1 )
206cdf0e10cSrcweir             throw IllegalArgumentException(
207cdf0e10cSrcweir                 String(MacroMigrationResId(STR_INVALID_NUMBER_ARGS)),
208cdf0e10cSrcweir                 *this,
209cdf0e10cSrcweir                 1
210cdf0e10cSrcweir             );
211cdf0e10cSrcweir 
212cdf0e10cSrcweir         m_xDocument.set( _rArguments[0], UNO_QUERY );
213cdf0e10cSrcweir         if ( !m_xDocument.is() )
214cdf0e10cSrcweir             throw IllegalArgumentException(
215cdf0e10cSrcweir                 String(MacroMigrationResId(STR_NO_DATABASE)),
216cdf0e10cSrcweir                 *this,
217cdf0e10cSrcweir                 1
218cdf0e10cSrcweir             );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir         Reference< XStorable > xDocStor( m_xDocument, UNO_QUERY_THROW );
221cdf0e10cSrcweir         if ( xDocStor->isReadonly() )
222cdf0e10cSrcweir             throw IllegalArgumentException(
223cdf0e10cSrcweir                 String(MacroMigrationResId(STR_NOT_READONLY)),
224cdf0e10cSrcweir                 *this,
225cdf0e10cSrcweir                 1
226cdf0e10cSrcweir             );
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         m_bInitialized = true;
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     //--------------------------------------------------------------------
getPropertySetInfo()232cdf0e10cSrcweir 	Reference< XPropertySetInfo > SAL_CALL MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException)
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir 	    return createPropertySetInfo( getInfoHelper() );
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir     //--------------------------------------------------------------------
getInfoHelper()238cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper& SAL_CALL MacroMigrationDialogService::getInfoHelper()
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir     	return *const_cast< MacroMigrationDialogService* >( this )->getArrayHelper();
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     //--------------------------------------------------------------------
createArrayHelper() const244cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper* MacroMigrationDialogService::createArrayHelper( ) const
245cdf0e10cSrcweir     {
246cdf0e10cSrcweir 	    Sequence< Property > aProps;
247cdf0e10cSrcweir 	    describeProperties( aProps );
248cdf0e10cSrcweir 	    return new ::cppu::OPropertyArrayHelper( aProps );
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     //--------------------------------------------------------------------
createRegistryInfo_MacroMigrationDialogService()252cdf0e10cSrcweir     void createRegistryInfo_MacroMigrationDialogService()
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir         static OAutoRegistration< MacroMigrationDialogService > aAutoRegistration;
255cdf0e10cSrcweir     }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir //........................................................................
258cdf0e10cSrcweir } // namespace dbmm
259cdf0e10cSrcweir //........................................................................
260