1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "dbmm_module.hxx"
32*cdf0e10cSrcweir #include "dbmm_global.hrc"
33*cdf0e10cSrcweir #include "macromigrationdialog.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir /** === begin UNO includes === **/
36*cdf0e10cSrcweir #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/frame/XStorable.hpp>
39*cdf0e10cSrcweir /** === end UNO includes === **/
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
42*cdf0e10cSrcweir #include <svtools/genericunodialog.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //........................................................................
45*cdf0e10cSrcweir namespace dbmm
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir //........................................................................
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 	/** === begin UNO using === **/
50*cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
51*cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
52*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
53*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
54*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
55*cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
56*cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
57*cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
58*cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
59*cdf0e10cSrcweir     using ::com::sun::star::uno::XComponentContext;
60*cdf0e10cSrcweir     using ::com::sun::star::uno::Sequence;
61*cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
62*cdf0e10cSrcweir     using ::com::sun::star::beans::Property;
63*cdf0e10cSrcweir     using ::com::sun::star::ucb::AlreadyInitializedException;
64*cdf0e10cSrcweir     using ::com::sun::star::sdb::XOfficeDatabaseDocument;
65*cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
66*cdf0e10cSrcweir     using ::com::sun::star::frame::XStorable;
67*cdf0e10cSrcweir 	/** === end UNO using === **/
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 	//====================================================================
70*cdf0e10cSrcweir 	//= MacroMigrationDialogService
71*cdf0e10cSrcweir 	//====================================================================
72*cdf0e10cSrcweir     class MacroMigrationDialogService;
73*cdf0e10cSrcweir     typedef ::svt::OGenericUnoDialog                                                MacroMigrationDialogService_Base;
74*cdf0e10cSrcweir     typedef ::comphelper::OPropertyArrayUsageHelper< MacroMigrationDialogService >  MacroMigrationDialogService_PBase;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     class MacroMigrationDialogService
77*cdf0e10cSrcweir                 :public MacroMigrationDialogService_Base
78*cdf0e10cSrcweir                 ,public MacroMigrationDialogService_PBase
79*cdf0e10cSrcweir                 ,public MacroMigrationModuleClient
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir     public:
82*cdf0e10cSrcweir         MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext );
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir         // XTypeProvider
85*cdf0e10cSrcweir 		virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 		// XServiceInfo
88*cdf0e10cSrcweir 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
89*cdf0e10cSrcweir         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir         // XInitialization
92*cdf0e10cSrcweir 		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*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	    // XPropertySet
95*cdf0e10cSrcweir 	    virtual Reference< XPropertySetInfo >  SAL_CALL getPropertySetInfo() throw(RuntimeException);
96*cdf0e10cSrcweir 	    virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	    // OPropertyArrayUsageHelper
99*cdf0e10cSrcweir 	    virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir         // helper for factories
102*cdf0e10cSrcweir         static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& _rxContext );
103*cdf0e10cSrcweir 		static ::rtl::OUString SAL_CALL getImplementationName_static() throw(RuntimeException);
104*cdf0e10cSrcweir         static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static() throw(RuntimeException);
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     protected:
107*cdf0e10cSrcweir         ~MacroMigrationDialogService();
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     protected:
110*cdf0e10cSrcweir 		virtual Dialog*	createDialog( Window* _pParent );
111*cdf0e10cSrcweir 	    virtual void destroyDialog();
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     private:
114*cdf0e10cSrcweir         ::comphelper::ComponentContext          m_aContext;
115*cdf0e10cSrcweir         Reference< XOfficeDatabaseDocument >    m_xDocument;
116*cdf0e10cSrcweir     };
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	//====================================================================
119*cdf0e10cSrcweir 	//= MacroMigrationDialogService
120*cdf0e10cSrcweir 	//====================================================================
121*cdf0e10cSrcweir 	//--------------------------------------------------------------------
122*cdf0e10cSrcweir     MacroMigrationDialogService::MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext )
123*cdf0e10cSrcweir         :MacroMigrationDialogService_Base( _rxContext )
124*cdf0e10cSrcweir         ,m_aContext( _rxContext )
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir         m_bNeedInitialization = true;
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir     //--------------------------------------------------------------------
130*cdf0e10cSrcweir     MacroMigrationDialogService::~MacroMigrationDialogService()
131*cdf0e10cSrcweir     {
132*cdf0e10cSrcweir         // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor,
133*cdf0e10cSrcweir         // so this virtual-method-call the base class does does not work, we're already dead then ...
134*cdf0e10cSrcweir         if ( m_pDialog )
135*cdf0e10cSrcweir         {
136*cdf0e10cSrcweir             ::osl::MutexGuard aGuard( m_aMutex );
137*cdf0e10cSrcweir             if ( m_pDialog )
138*cdf0e10cSrcweir                 destroyDialog();
139*cdf0e10cSrcweir         }
140*cdf0e10cSrcweir     }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir     //--------------------------------------------------------------------
143*cdf0e10cSrcweir     Reference< XInterface > SAL_CALL MacroMigrationDialogService::Create( const Reference< XComponentContext >& _rxContext )
144*cdf0e10cSrcweir     {
145*cdf0e10cSrcweir         return *(new MacroMigrationDialogService( _rxContext ) );
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     //--------------------------------------------------------------------
149*cdf0e10cSrcweir 	Dialog*	MacroMigrationDialogService::createDialog( Window* _pParent )
150*cdf0e10cSrcweir     {
151*cdf0e10cSrcweir         return new MacroMigrationDialog( _pParent, m_aContext, m_xDocument );
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     //--------------------------------------------------------------------
155*cdf0e10cSrcweir     void MacroMigrationDialogService::destroyDialog()
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir 	    MacroMigrationDialogService_Base::destroyDialog();
158*cdf0e10cSrcweir     }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir     //--------------------------------------------------------------------
161*cdf0e10cSrcweir     Sequence< sal_Int8 > SAL_CALL MacroMigrationDialogService::getImplementationId() throw(RuntimeException)
162*cdf0e10cSrcweir     {
163*cdf0e10cSrcweir         static ::cppu::OImplementationId* pId = NULL;
164*cdf0e10cSrcweir         if ( !pId )
165*cdf0e10cSrcweir         {
166*cdf0e10cSrcweir             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
167*cdf0e10cSrcweir             if ( !pId )
168*cdf0e10cSrcweir             {
169*cdf0e10cSrcweir                 static ::cppu::OImplementationId aId;
170*cdf0e10cSrcweir                 pId = &aId;
171*cdf0e10cSrcweir             }
172*cdf0e10cSrcweir         }
173*cdf0e10cSrcweir         return pId->getImplementationId();
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     //--------------------------------------------------------------------
177*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException)
178*cdf0e10cSrcweir     {
179*cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" ) );
180*cdf0e10cSrcweir     }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir     //--------------------------------------------------------------------
183*cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException)
184*cdf0e10cSrcweir     {
185*cdf0e10cSrcweir         Sequence< ::rtl::OUString > aServices(1);
186*cdf0e10cSrcweir         aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
187*cdf0e10cSrcweir         return aServices;
188*cdf0e10cSrcweir     }
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir     //--------------------------------------------------------------------
191*cdf0e10cSrcweir     ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName() throw(RuntimeException)
192*cdf0e10cSrcweir     {
193*cdf0e10cSrcweir         return getImplementationName_static();
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir     //--------------------------------------------------------------------
197*cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException)
198*cdf0e10cSrcweir     {
199*cdf0e10cSrcweir         return getSupportedServiceNames_static();
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     //--------------------------------------------------------------------
203*cdf0e10cSrcweir     void SAL_CALL MacroMigrationDialogService::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException)
204*cdf0e10cSrcweir     {
205*cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
206*cdf0e10cSrcweir         if ( m_bInitialized )
207*cdf0e10cSrcweir             throw AlreadyInitializedException( ::rtl::OUString(), *this );
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir         if ( _rArguments.getLength() != 1 )
210*cdf0e10cSrcweir             throw IllegalArgumentException(
211*cdf0e10cSrcweir                 String(MacroMigrationResId(STR_INVALID_NUMBER_ARGS)),
212*cdf0e10cSrcweir                 *this,
213*cdf0e10cSrcweir                 1
214*cdf0e10cSrcweir             );
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir         m_xDocument.set( _rArguments[0], UNO_QUERY );
217*cdf0e10cSrcweir         if ( !m_xDocument.is() )
218*cdf0e10cSrcweir             throw IllegalArgumentException(
219*cdf0e10cSrcweir                 String(MacroMigrationResId(STR_NO_DATABASE)),
220*cdf0e10cSrcweir                 *this,
221*cdf0e10cSrcweir                 1
222*cdf0e10cSrcweir             );
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir         Reference< XStorable > xDocStor( m_xDocument, UNO_QUERY_THROW );
225*cdf0e10cSrcweir         if ( xDocStor->isReadonly() )
226*cdf0e10cSrcweir             throw IllegalArgumentException(
227*cdf0e10cSrcweir                 String(MacroMigrationResId(STR_NOT_READONLY)),
228*cdf0e10cSrcweir                 *this,
229*cdf0e10cSrcweir                 1
230*cdf0e10cSrcweir             );
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir         m_bInitialized = true;
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     //--------------------------------------------------------------------
236*cdf0e10cSrcweir 	Reference< XPropertySetInfo > SAL_CALL MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException)
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir 	    return createPropertySetInfo( getInfoHelper() );
239*cdf0e10cSrcweir     }
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     //--------------------------------------------------------------------
242*cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper& SAL_CALL MacroMigrationDialogService::getInfoHelper()
243*cdf0e10cSrcweir     {
244*cdf0e10cSrcweir     	return *const_cast< MacroMigrationDialogService* >( this )->getArrayHelper();
245*cdf0e10cSrcweir     }
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir     //--------------------------------------------------------------------
248*cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper* MacroMigrationDialogService::createArrayHelper( ) const
249*cdf0e10cSrcweir     {
250*cdf0e10cSrcweir 	    Sequence< Property > aProps;
251*cdf0e10cSrcweir 	    describeProperties( aProps );
252*cdf0e10cSrcweir 	    return new ::cppu::OPropertyArrayHelper( aProps );
253*cdf0e10cSrcweir     }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     //--------------------------------------------------------------------
256*cdf0e10cSrcweir     void createRegistryInfo_MacroMigrationDialogService()
257*cdf0e10cSrcweir     {
258*cdf0e10cSrcweir         static OAutoRegistration< MacroMigrationDialogService > aAutoRegistration;
259*cdf0e10cSrcweir     }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir //........................................................................
262*cdf0e10cSrcweir } // namespace dbmm
263*cdf0e10cSrcweir //........................................................................
264