1*01aa44aaSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*01aa44aaSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*01aa44aaSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*01aa44aaSAndrew Rist * distributed with this work for additional information 6*01aa44aaSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*01aa44aaSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*01aa44aaSAndrew Rist * "License"); you may not use this file except in compliance 9*01aa44aaSAndrew Rist * with the License. You may obtain a copy of the License at 10*01aa44aaSAndrew Rist * 11*01aa44aaSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*01aa44aaSAndrew Rist * 13*01aa44aaSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*01aa44aaSAndrew Rist * software distributed under the License is distributed on an 15*01aa44aaSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*01aa44aaSAndrew Rist * KIND, either express or implied. See the License for the 17*01aa44aaSAndrew Rist * specific language governing permissions and limitations 18*01aa44aaSAndrew Rist * under the License. 19*01aa44aaSAndrew Rist * 20*01aa44aaSAndrew Rist *************************************************************/ 21*01aa44aaSAndrew Rist 22*01aa44aaSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _SVT_GENERICUNODIALOG_HXX_ 25cdf0e10cSrcweir #define _SVT_GENERICUNODIALOG_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "svtools/svtdllapi.h" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 30cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 31cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 32cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp> 33cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 36cdf0e10cSrcweir #include <com/sun/star/lang/NotInitializedException.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 39cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx> 40cdf0e10cSrcweir #include <comphelper/proparrhlp.hxx> 41cdf0e10cSrcweir #include <comphelper/uno3.hxx> 42cdf0e10cSrcweir #include <comphelper/propertycontainer.hxx> 43cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx> 44cdf0e10cSrcweir #include <comphelper/componentcontext.hxx> 45cdf0e10cSrcweir #include <tools/link.hxx> 46cdf0e10cSrcweir 47cdf0e10cSrcweir class Dialog; 48cdf0e10cSrcweir class Window; 49cdf0e10cSrcweir class VclWindowEvent; 50cdf0e10cSrcweir 51cdf0e10cSrcweir //......................................................................... 52cdf0e10cSrcweir namespace svt 53cdf0e10cSrcweir { 54cdf0e10cSrcweir //......................................................................... 55cdf0e10cSrcweir 56cdf0e10cSrcweir //========================================================================= 57cdf0e10cSrcweir #define UNODIALOG_PROPERTY_ID_TITLE 1 58cdf0e10cSrcweir #define UNODIALOG_PROPERTY_ID_PARENT 2 59cdf0e10cSrcweir 60cdf0e10cSrcweir #define UNODIALOG_PROPERTY_TITLE "Title" 61cdf0e10cSrcweir #define UNODIALOG_PROPERTY_PARENT "ParentWindow" 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir //========================================================================= 65cdf0e10cSrcweir typedef ::cppu::WeakImplHelper3 < com::sun::star::ui::dialogs::XExecutableDialog 66cdf0e10cSrcweir , com::sun::star::lang::XServiceInfo 67cdf0e10cSrcweir , com::sun::star::lang::XInitialization 68cdf0e10cSrcweir > OGenericUnoDialogBase; 69cdf0e10cSrcweir 70cdf0e10cSrcweir /** abstract base class for implementing UNO objects representing dialogs (<type scope="com.sun.star.awt">XDialog</type>) 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir class SVT_DLLPUBLIC OGenericUnoDialog 73cdf0e10cSrcweir :public OGenericUnoDialogBase 74cdf0e10cSrcweir ,public ::comphelper::OMutexAndBroadcastHelper 75cdf0e10cSrcweir ,public ::comphelper::OPropertyContainer 76cdf0e10cSrcweir { 77cdf0e10cSrcweir private: 78cdf0e10cSrcweir ::osl::Mutex m_aExecutionMutex; /// acess safety for execute/cancel 79cdf0e10cSrcweir 80cdf0e10cSrcweir protected: 81cdf0e10cSrcweir Dialog* m_pDialog; /// the dialog to execute 82cdf0e10cSrcweir sal_Bool m_bExecuting : 1; /// we're currently executing the dialog 83cdf0e10cSrcweir sal_Bool m_bCanceled : 1; /// endDialog was called while we were executing 84cdf0e10cSrcweir sal_Bool m_bTitleAmbiguous : 1; /// m_sTitle has not been set yet 85cdf0e10cSrcweir bool m_bInitialized : 1; /// has "initialize" been called? 86cdf0e10cSrcweir bool m_bNeedInitialization : 1; /// do we need to be initialized before any other API call is allowed? 87cdf0e10cSrcweir 88cdf0e10cSrcweir // <properties> 89cdf0e10cSrcweir ::rtl::OUString m_sTitle; /// title of the dialog 90cdf0e10cSrcweir com::sun::star::uno::Reference<com::sun::star::awt::XWindow> m_xParent; /// parent window 91cdf0e10cSrcweir // </properties> 92cdf0e10cSrcweir 93cdf0e10cSrcweir ::comphelper::ComponentContext m_aContext; 94cdf0e10cSrcweir 95cdf0e10cSrcweir public: needInitialization() const96cdf0e10cSrcweir inline bool needInitialization() const { return m_bNeedInitialization && !m_bInitialized; } 97cdf0e10cSrcweir 98cdf0e10cSrcweir protected: 99cdf0e10cSrcweir OGenericUnoDialog(const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& _rxORB); 100cdf0e10cSrcweir OGenericUnoDialog(const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& _rxContext); 101cdf0e10cSrcweir virtual ~OGenericUnoDialog(); 102cdf0e10cSrcweir 103cdf0e10cSrcweir public: 104cdf0e10cSrcweir // UNO 105cdf0e10cSrcweir DECLARE_UNO3_DEFAULTS(OGenericUnoDialog, OGenericUnoDialogBase); 106cdf0e10cSrcweir virtual com::sun::star::uno::Any SAL_CALL queryInterface(const com::sun::star::uno::Type& _rType) throw (com::sun::star::uno::RuntimeException); 107cdf0e10cSrcweir 108cdf0e10cSrcweir // XTypeProvider 109cdf0e10cSrcweir virtual com::sun::star::uno::Sequence<com::sun::star::uno::Type> SAL_CALL getTypes( ) throw(com::sun::star::uno::RuntimeException); 110cdf0e10cSrcweir virtual com::sun::star::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) throw(com::sun::star::uno::RuntimeException) = 0; 111cdf0e10cSrcweir 112cdf0e10cSrcweir // XServiceInfo 113cdf0e10cSrcweir virtual ::rtl::OUString SAL_CALL getImplementationName() throw(com::sun::star::uno::RuntimeException) = 0; 114cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw(com::sun::star::uno::RuntimeException); 115cdf0e10cSrcweir virtual ::comphelper::StringSequence SAL_CALL getSupportedServiceNames() throw(com::sun::star::uno::RuntimeException) = 0; 116cdf0e10cSrcweir 117cdf0e10cSrcweir // OPropertySetHelper 118cdf0e10cSrcweir virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any& rValue ) throw(com::sun::star::uno::Exception); 119cdf0e10cSrcweir virtual sal_Bool SAL_CALL convertFastPropertyValue( com::sun::star::uno::Any& rConvertedValue, com::sun::star::uno::Any& rOldValue, sal_Int32 nHandle, const com::sun::star::uno::Any& rValue) throw(com::sun::star::lang::IllegalArgumentException); 120cdf0e10cSrcweir 121cdf0e10cSrcweir // XExecutableDialog 122cdf0e10cSrcweir virtual void SAL_CALL setTitle( const ::rtl::OUString& aTitle ) throw(::com::sun::star::uno::RuntimeException); 123cdf0e10cSrcweir virtual sal_Int16 SAL_CALL execute( ) throw(::com::sun::star::uno::RuntimeException); 124cdf0e10cSrcweir 125cdf0e10cSrcweir // XInitialization 126cdf0e10cSrcweir 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); 127cdf0e10cSrcweir 128cdf0e10cSrcweir protected: 129cdf0e10cSrcweir /** create the concret dialog instance. note that m_aMutex is not locked when this method get's called, 130cdf0e10cSrcweir but the application-wide solar mutex is (to guard the not thread-safe ctor of the dialog). 131cdf0e10cSrcweir @param pParent the parent window for the new dialog 132cdf0e10cSrcweir */ 133cdf0e10cSrcweir virtual Dialog* createDialog(Window* _pParent) = 0; 134cdf0e10cSrcweir 135cdf0e10cSrcweir /// called to destroy the dialog used. the default implementation just deletes m_pDialog and resets it to NULL 136cdf0e10cSrcweir virtual void destroyDialog(); 137cdf0e10cSrcweir 138cdf0e10cSrcweir /** called after the dialog has been executed 139cdf0e10cSrcweir @param _nExecutionResult the execution result as returned by Dialog::Execute 140cdf0e10cSrcweir */ executedDialog(sal_Int16)141cdf0e10cSrcweir virtual void executedDialog(sal_Int16 /*_nExecutionResult*/) { } 142cdf0e10cSrcweir 143cdf0e10cSrcweir /** smaller form of <method>initialize</method>.<p/> 144cdf0e10cSrcweir The <method>initialize</method> method is called with a sequence of <type scope="com.sun.star.uno">Any</type>'s, 145cdf0e10cSrcweir which is split up into the single elements, which are passed to implInitialize. The default implementation 146cdf0e10cSrcweir tries to exract an <type scope="com.sun.star.beans">PropertyValue</type> from the value an pass it to the 147cdf0e10cSrcweir <type scope="com.sun.star.beans">XPropertySet</type> interface of the object. 148cdf0e10cSrcweir */ 149cdf0e10cSrcweir virtual void implInitialize(const com::sun::star::uno::Any& _rValue); 150cdf0e10cSrcweir 151cdf0e10cSrcweir private: 152cdf0e10cSrcweir DECL_LINK( OnDialogDying, VclWindowEvent* ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir /** ensures that m_pDialog is not <NULL/> 155cdf0e10cSrcweir 156cdf0e10cSrcweir This method does nothing if m_pDialog is already non-<NULL/>. Else, it calls createDialog and does 157cdf0e10cSrcweir all necessary initializations of the new dialog instance. 158cdf0e10cSrcweir 159cdf0e10cSrcweir @precond 160cdf0e10cSrcweir m_aMutex is locked 161cdf0e10cSrcweir 162cdf0e10cSrcweir @return 163cdf0e10cSrcweir <TRUE/> if and only if m_pDialog is non-<NULL/> upon returning from the method. Note that the only 164cdf0e10cSrcweir case where m_pDialog is <NULL/> is when createDialog returned <NULL/>, which is will fire an assertion 165cdf0e10cSrcweir in non-product builds. 166cdf0e10cSrcweir */ 167cdf0e10cSrcweir bool impl_ensureDialog_lck(); 168cdf0e10cSrcweir }; 169cdf0e10cSrcweir 170cdf0e10cSrcweir /// helper class for guarding access to methods of a OGenericUnoDialog 171cdf0e10cSrcweir class UnoDialogEntryGuard 172cdf0e10cSrcweir { 173cdf0e10cSrcweir public: UnoDialogEntryGuard(OGenericUnoDialog & _rDialog)174cdf0e10cSrcweir UnoDialogEntryGuard( OGenericUnoDialog& _rDialog ) 175cdf0e10cSrcweir :m_aGuard( _rDialog.GetMutex() ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir if ( _rDialog.needInitialization() ) 178cdf0e10cSrcweir throw ::com::sun::star::lang::NotInitializedException(); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir private: 182cdf0e10cSrcweir ::osl::MutexGuard m_aGuard; 183cdf0e10cSrcweir }; 184cdf0e10cSrcweir 185cdf0e10cSrcweir //......................................................................... 186cdf0e10cSrcweir } // namespace svt 187cdf0e10cSrcweir //......................................................................... 188cdf0e10cSrcweir 189cdf0e10cSrcweir #endif // _SVT_GENERICUNODIALOG_HXX_ 190cdf0e10cSrcweir 191