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 .
22 #include <svtools/svtdllapi.h>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
28 #include <cppuhelper/implbase.hxx>
29 #include <comphelper/uno3.hxx>
30 #include <comphelper/propertycontainer.hxx>
31 #include <comphelper/broadcasthelper.hxx>
32 #include <vcl/weld.hxx>
34 namespace com :: sun :: star :: awt
{ class XWindow
; }
35 namespace com :: sun :: star :: uno
{ class XComponentContext
; }
44 #define UNODIALOG_PROPERTY_ID_TITLE 1
45 #define UNODIALOG_PROPERTY_ID_PARENT 2
47 inline constexpr OUStringLiteral UNODIALOG_PROPERTY_TITLE
= u
"Title";
48 inline constexpr OUStringLiteral UNODIALOG_PROPERTY_PARENT
= u
"ParentWindow";
50 typedef cppu::WeakImplHelper
< css::ui::dialogs::XExecutableDialog
,
51 css::lang::XServiceInfo
,
52 css::lang::XInitialization
> OGenericUnoDialogBase
;
54 /** abstract base class for implementing UNO objects representing dialogs (com.sun.star.awt::XDialog)
56 class SVT_DLLPUBLIC OGenericUnoDialog
57 :public OGenericUnoDialogBase
58 ,public ::comphelper::OMutexAndBroadcastHelper
59 ,public ::comphelper::OPropertyContainer
62 std::unique_ptr
<weld::DialogController
> m_xDialog
; /// the dialog to execute
63 bool m_bExecuting
: 1; /// we're currently executing the dialog
64 bool m_bTitleAmbiguous
: 1; /// m_sTitle has not been set yet
65 bool m_bInitialized
: 1; /// has "initialize" been called?
68 OUString m_sTitle
; /// title of the dialog
69 css::uno::Reference
<css::awt::XWindow
> m_xParent
; /// parent window
72 css::uno::Reference
<css::uno::XComponentContext
> m_aContext
;
75 OGenericUnoDialog(const css::uno::Reference
< css::uno::XComponentContext
>& _rxContext
);
76 virtual ~OGenericUnoDialog() override
;
80 DECLARE_UNO3_DEFAULTS(OGenericUnoDialog
, OGenericUnoDialogBase
)
81 virtual css::uno::Any SAL_CALL
queryInterface(const css::uno::Type
& _rType
) override
;
84 virtual css::uno::Sequence
<css::uno::Type
> SAL_CALL
getTypes( ) override
;
85 virtual css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId( ) override
= 0;
88 virtual OUString SAL_CALL
getImplementationName() override
= 0;
89 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
90 virtual css::uno::Sequence
<OUString
> SAL_CALL
getSupportedServiceNames() override
= 0;
93 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
94 virtual sal_Bool SAL_CALL
convertFastPropertyValue( css::uno::Any
& rConvertedValue
, css::uno::Any
& rOldValue
, sal_Int32 nHandle
, const css::uno::Any
& rValue
) override
;
97 virtual void SAL_CALL
setTitle( const OUString
& aTitle
) override
;
98 virtual sal_Int16 SAL_CALL
execute( ) override
;
101 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
104 /** create the concrete dialog instance. Note that m_aMutex is not locked when this method get called,
105 but the application-wide solar mutex is (to guard the not thread-safe ctor of the dialog).
106 @param pParent the parent window for the new dialog
108 virtual std::unique_ptr
<weld::DialogController
> createDialog(const css::uno::Reference
<css::awt::XWindow
>& rParent
) = 0;
110 /// called to destroy the dialog used. deletes m_pDialog and resets it to NULL
111 void destroyDialog();
113 /** called after the dialog has been executed
114 @param _nExecutionResult the execution result as returned by Dialog::Execute
116 virtual void executedDialog(sal_Int16
/*_nExecutionResult*/) { }
118 /** smaller form of <method>initialize</method>.<p/>
119 The <method>initialize</method> method is called with a sequence of com.sun.star.uno::Any's,
120 which is split up into the single elements, which are passed to implInitialize. The default implementation
121 tries to extract a com.sun.star.beans::PropertyValue from the value a pass it to the
122 com.sun.star.beans::XPropertySet interface of the object.
124 virtual void implInitialize(const css::uno::Any
& _rValue
);
128 /** ensures that m_pDialog is not <NULL/>
130 This method does nothing if m_pDialog is already non-<NULL/>. Else, it calls createDialog and does
131 all necessary initializations of the new dialog instance.
137 <TRUE/> if and only if m_pDialog is non-<NULL/> upon returning from the method. Note that the only
138 case where m_pDialog is <NULL/> is when createDialog returned <NULL/>, which is will fire an assertion
139 in non-product builds.
141 bool impl_ensureDialog_lck();
144 /// helper class for guarding access to methods of an OGenericUnoDialog
145 class UnoDialogEntryGuard
148 UnoDialogEntryGuard( OGenericUnoDialog
& _rDialog
)
149 :m_aGuard( _rDialog
.GetMutex() )
154 ::osl::MutexGuard m_aGuard
;
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */