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 .
20 #ifndef INCLUDED_SVTOOLS_GENERICUNODIALOG_HXX
21 #define INCLUDED_SVTOOLS_GENERICUNODIALOG_HXX
23 #include <svtools/svtdllapi.h>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/awt/XWindow.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/lang/NotInitializedException.hpp>
34 #include <cppuhelper/implbase.hxx>
35 #include <cppuhelper/propshlp.hxx>
36 #include <comphelper/proparrhlp.hxx>
37 #include <comphelper/uno3.hxx>
38 #include <comphelper/propertycontainer.hxx>
39 #include <comphelper/broadcasthelper.hxx>
40 #include <tools/link.hxx>
41 #include <vcl/vclptr.hxx>
44 namespace vcl
{ class Window
; }
52 #define UNODIALOG_PROPERTY_ID_TITLE 1
53 #define UNODIALOG_PROPERTY_ID_PARENT 2
55 #define UNODIALOG_PROPERTY_TITLE "Title"
56 #define UNODIALOG_PROPERTY_PARENT "ParentWindow"
59 typedef cppu::WeakImplHelper
< css::ui::dialogs::XExecutableDialog
,
60 css::lang::XServiceInfo
,
61 css::lang::XInitialization
> OGenericUnoDialogBase
;
63 /** abstract base class for implementing UNO objects representing dialogs (com.sun.star.awt::XDialog)
65 class SVT_DLLPUBLIC OGenericUnoDialog
66 :public OGenericUnoDialogBase
67 ,public ::comphelper::OMutexAndBroadcastHelper
68 ,public ::comphelper::OPropertyContainer
71 VclPtr
<Dialog
> m_pDialog
; /// the dialog to execute
72 bool m_bExecuting
: 1; /// we're currently executing the dialog
73 bool m_bTitleAmbiguous
: 1; /// m_sTitle has not been set yet
74 bool m_bInitialized
: 1; /// has "initialize" been called?
75 bool m_bNeedInitialization
: 1; /// do we need to be initialized before any other API call is allowed?
78 OUString m_sTitle
; /// title of the dialog
79 css::uno::Reference
<css::awt::XWindow
> m_xParent
; /// parent window
82 css::uno::Reference
<css::uno::XComponentContext
> m_aContext
;
85 bool needInitialization() const { return m_bNeedInitialization
&& !m_bInitialized
; }
88 OGenericUnoDialog(const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
89 virtual ~OGenericUnoDialog() override
;
93 DECLARE_UNO3_DEFAULTS(OGenericUnoDialog
, OGenericUnoDialogBase
)
94 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) override
;
97 virtual css::uno::Sequence
<css::uno::Type
> SAL_CALL
getTypes( ) override
;
98 virtual css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId( ) override
= 0;
101 virtual OUString SAL_CALL
getImplementationName() override
= 0;
102 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
103 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
= 0;
105 // OPropertySetHelper
106 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
107 virtual sal_Bool SAL_CALL
convertFastPropertyValue( css::uno::Any
& rConvertedValue
, css::uno::Any
& rOldValue
, sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
110 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) override
;
111 virtual sal_Int16 SAL_CALL
execute( ) override
;
114 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
117 /** create the concrete dialog instance. note that m_aMutex is not locked when this method get's called,
118 but the application-wide solar mutex is (to guard the not thread-safe ctor of the dialog).
119 @param pParent the parent window for the new dialog
121 virtual VclPtr
<Dialog
> createDialog(vcl::Window
* _pParent
) = 0;
123 /// called to destroy the dialog used. deletes m_pDialog and resets it to NULL
124 void destroyDialog();
126 /** called after the dialog has been executed
127 @param _nExecutionResult the execution result as returned by Dialog::Execute
129 virtual void executedDialog(sal_Int16
/*_nExecutionResult*/) { }
131 /** smaller form of <method>initialize</method>.<p/>
132 The <method>initialize</method> method is called with a sequence of com.sun.star.uno::Any's,
133 which is split up into the single elements, which are passed to implInitialize. The default implementation
134 tries to extract an com.sun.star.beans::PropertyValue from the value an pass it to the
135 com.sun.star.beans::XPropertySet interface of the object.
137 virtual void implInitialize(const css::uno::Any
& _rValue
);
140 DECL_LINK( OnDialogDying
, VclWindowEvent
&, void );
142 /** ensures that m_pDialog is not <NULL/>
144 This method does nothing if m_pDialog is already non-<NULL/>. Else, it calls createDialog and does
145 all necessary initializations of the new dialog instance.
151 <TRUE/> if and only if m_pDialog is non-<NULL/> upon returning from the method. Note that the only
152 case where m_pDialog is <NULL/> is when createDialog returned <NULL/>, which is will fire an assertion
153 in non-product builds.
155 bool impl_ensureDialog_lck();
158 /// helper class for guarding access to methods of a OGenericUnoDialog
159 class UnoDialogEntryGuard
162 UnoDialogEntryGuard( OGenericUnoDialog
& _rDialog
)
163 :m_aGuard( _rDialog
.GetMutex() )
165 if ( _rDialog
.needInitialization() )
166 throw css::lang::NotInitializedException();
170 ::osl::MutexGuard m_aGuard
;
177 #endif // INCLUDED_SVTOOLS_GENERICUNODIALOG_HXX
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */