1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "dbmm_module.hxx"
22 #include "dbmm_global.hrc"
23 #include "macromigrationdialog.hxx"
25 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
26 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
27 #include <com/sun/star/frame/XStorable.hpp>
29 #include <svtools/genericunodialog.hxx>
31 //........................................................................
34 //........................................................................
36 using ::com::sun::star::uno::Reference
;
37 using ::com::sun::star::uno::XInterface
;
38 using ::com::sun::star::uno::UNO_QUERY
;
39 using ::com::sun::star::uno::UNO_QUERY_THROW
;
40 using ::com::sun::star::uno::UNO_SET_THROW
;
41 using ::com::sun::star::uno::Exception
;
42 using ::com::sun::star::uno::RuntimeException
;
43 using ::com::sun::star::uno::Any
;
44 using ::com::sun::star::uno::makeAny
;
45 using ::com::sun::star::uno::XComponentContext
;
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::beans::XPropertySetInfo
;
48 using ::com::sun::star::beans::Property
;
49 using ::com::sun::star::ucb::AlreadyInitializedException
;
50 using ::com::sun::star::sdb::XOfficeDatabaseDocument
;
51 using ::com::sun::star::lang::IllegalArgumentException
;
52 using ::com::sun::star::frame::XStorable
;
54 //====================================================================
55 //= MacroMigrationDialogService
56 //====================================================================
57 class MacroMigrationDialogService
;
58 typedef ::svt::OGenericUnoDialog MacroMigrationDialogService_Base
;
59 typedef ::comphelper::OPropertyArrayUsageHelper
< MacroMigrationDialogService
> MacroMigrationDialogService_PBase
;
61 class MacroMigrationDialogService
62 :public MacroMigrationDialogService_Base
63 ,public MacroMigrationDialogService_PBase
64 ,public MacroMigrationModuleClient
67 MacroMigrationDialogService( const Reference
< XComponentContext
>& _rxContext
);
70 virtual Sequence
< sal_Int8
> SAL_CALL
getImplementationId() throw(RuntimeException
);
73 virtual OUString SAL_CALL
getImplementationName() throw(RuntimeException
);
74 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw(RuntimeException
);
77 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
);
80 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo() throw(RuntimeException
);
81 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper();
83 // OPropertyArrayUsageHelper
84 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
86 // helper for factories
87 static Reference
< XInterface
> SAL_CALL
Create( const Reference
< XComponentContext
>& _rxContext
);
88 static OUString SAL_CALL
getImplementationName_static() throw(RuntimeException
);
89 static Sequence
< OUString
> SAL_CALL
getSupportedServiceNames_static() throw(RuntimeException
);
92 ~MacroMigrationDialogService();
95 virtual Dialog
* createDialog( Window
* _pParent
);
96 virtual void destroyDialog();
99 Reference
<XComponentContext
> m_aContext
;
100 Reference
< XOfficeDatabaseDocument
> m_xDocument
;
103 //====================================================================
104 //= MacroMigrationDialogService
105 //====================================================================
106 //--------------------------------------------------------------------
107 MacroMigrationDialogService::MacroMigrationDialogService( const Reference
< XComponentContext
>& _rxContext
)
108 :MacroMigrationDialogService_Base( _rxContext
)
109 ,m_aContext( _rxContext
)
111 m_bNeedInitialization
= true;
114 //--------------------------------------------------------------------
115 MacroMigrationDialogService::~MacroMigrationDialogService()
117 // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor,
118 // so this virtual-method-call the base class does does not work, we're already dead then ...
121 ::osl::MutexGuard
aGuard( m_aMutex
);
127 //--------------------------------------------------------------------
128 Reference
< XInterface
> SAL_CALL
MacroMigrationDialogService::Create( const Reference
< XComponentContext
>& _rxContext
)
130 return *(new MacroMigrationDialogService( _rxContext
) );
133 //--------------------------------------------------------------------
134 Dialog
* MacroMigrationDialogService::createDialog( Window
* _pParent
)
136 return new MacroMigrationDialog( _pParent
, m_aContext
, m_xDocument
);
139 //--------------------------------------------------------------------
140 void MacroMigrationDialogService::destroyDialog()
142 MacroMigrationDialogService_Base::destroyDialog();
145 //--------------------------------------------------------------------
146 Sequence
< sal_Int8
> SAL_CALL
MacroMigrationDialogService::getImplementationId() throw(RuntimeException
)
148 static ::cppu::OImplementationId
* pId
= NULL
;
151 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
154 static ::cppu::OImplementationId aId
;
158 return pId
->getImplementationId();
161 //--------------------------------------------------------------------
162 OUString SAL_CALL
MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException
)
164 return OUString( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" );
167 //--------------------------------------------------------------------
168 Sequence
< OUString
> SAL_CALL
MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException
)
170 Sequence
< OUString
> aServices(1);
171 aServices
[0] = OUString( "com.sun.star.sdb.application.MacroMigrationWizard" );
175 //--------------------------------------------------------------------
176 OUString SAL_CALL
MacroMigrationDialogService::getImplementationName() throw(RuntimeException
)
178 return getImplementationName_static();
181 //--------------------------------------------------------------------
182 Sequence
< OUString
> SAL_CALL
MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException
)
184 return getSupportedServiceNames_static();
187 //--------------------------------------------------------------------
188 void SAL_CALL
MacroMigrationDialogService::initialize( const Sequence
< Any
>& _rArguments
) throw(Exception
, RuntimeException
)
190 ::osl::MutexGuard
aGuard( m_aMutex
);
191 if ( m_bInitialized
)
192 throw AlreadyInitializedException( OUString(), *this );
194 if ( _rArguments
.getLength() != 1 )
195 throw IllegalArgumentException(
196 OUString(MacroMigrationResId(STR_INVALID_NUMBER_ARGS
)),
201 m_xDocument
.set( _rArguments
[0], UNO_QUERY
);
202 if ( !m_xDocument
.is() )
203 throw IllegalArgumentException(
204 OUString(MacroMigrationResId(STR_NO_DATABASE
)),
209 Reference
< XStorable
> xDocStor( m_xDocument
, UNO_QUERY_THROW
);
210 if ( xDocStor
->isReadonly() )
211 throw IllegalArgumentException(
212 OUString(MacroMigrationResId(STR_NOT_READONLY
)),
217 m_bInitialized
= true;
220 //--------------------------------------------------------------------
221 Reference
< XPropertySetInfo
> SAL_CALL
MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException
)
223 return createPropertySetInfo( getInfoHelper() );
226 //--------------------------------------------------------------------
227 ::cppu::IPropertyArrayHelper
& SAL_CALL
MacroMigrationDialogService::getInfoHelper()
229 return *const_cast< MacroMigrationDialogService
* >( this )->getArrayHelper();
232 //--------------------------------------------------------------------
233 ::cppu::IPropertyArrayHelper
* MacroMigrationDialogService::createArrayHelper( ) const
235 Sequence
< Property
> aProps
;
236 describeProperties( aProps
);
237 return new ::cppu::OPropertyArrayHelper( aProps
);
240 //--------------------------------------------------------------------
241 void createRegistryInfo_MacroMigrationDialogService()
243 static OAutoRegistration
< MacroMigrationDialogService
> aAutoRegistration
;
246 //........................................................................
248 //........................................................................
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */