/src/libreoffice/include/svtools/genericunodialog.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <svtools/svtdllapi.h> |
23 | | |
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> |
27 | | |
28 | | #include <cppuhelper/implbase.hxx> |
29 | | #include <comphelper/uno3.hxx> |
30 | | #include <comphelper/propertycontainer.hxx> |
31 | | #include <comphelper/broadcasthelper.hxx> |
32 | | |
33 | | namespace com::sun::star::awt { class XWindow; } |
34 | | namespace com::sun::star::uno { class XComponentContext; } |
35 | | namespace weld { class DialogController; } |
36 | | |
37 | | |
38 | | namespace svt |
39 | | { |
40 | | |
41 | | |
42 | 0 | #define UNODIALOG_PROPERTY_ID_TITLE 1 |
43 | 0 | #define UNODIALOG_PROPERTY_ID_PARENT 2 |
44 | | |
45 | | inline constexpr OUString UNODIALOG_PROPERTY_TITLE = u"Title"_ustr; |
46 | | inline constexpr OUString UNODIALOG_PROPERTY_PARENT = u"ParentWindow"_ustr; |
47 | | |
48 | | typedef cppu::WeakImplHelper< css::ui::dialogs::XExecutableDialog, |
49 | | css::lang::XServiceInfo, |
50 | | css::lang::XInitialization > OGenericUnoDialogBase; |
51 | | |
52 | | /** abstract base class for implementing UNO objects representing dialogs (com.sun.star.awt::XDialog) |
53 | | */ |
54 | | class SVT_DLLPUBLIC OGenericUnoDialog |
55 | | :public OGenericUnoDialogBase |
56 | | ,public ::comphelper::OMutexAndBroadcastHelper |
57 | | ,public ::comphelper::OPropertyContainer |
58 | | { |
59 | | protected: |
60 | | std::unique_ptr<weld::DialogController> m_xDialog; /// the dialog to execute |
61 | | bool m_bExecuting : 1; /// we're currently executing the dialog |
62 | | bool m_bTitleAmbiguous : 1; /// m_sTitle has not been set yet |
63 | | bool m_bInitialized : 1; /// has "initialize" been called? |
64 | | |
65 | | // <properties> |
66 | | OUString m_sTitle; /// title of the dialog |
67 | | css::uno::Reference<css::awt::XWindow> m_xParent; /// parent window |
68 | | // </properties> |
69 | | |
70 | | css::uno::Reference<css::uno::XComponentContext> m_aContext; |
71 | | |
72 | | protected: |
73 | | OGenericUnoDialog(const css::uno::Reference< css::uno::XComponentContext >& _rxContext); |
74 | | virtual ~OGenericUnoDialog() override; |
75 | | |
76 | | public: |
77 | | // UNO |
78 | | DECLARE_UNO3_DEFAULTS(OGenericUnoDialog, OGenericUnoDialogBase) |
79 | | virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override; |
80 | | |
81 | | // XTypeProvider |
82 | | virtual css::uno::Sequence<css::uno::Type> SAL_CALL getTypes( ) override; |
83 | | virtual css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId( ) override = 0; |
84 | | |
85 | | // XServiceInfo |
86 | | virtual OUString SAL_CALL getImplementationName() override = 0; |
87 | | virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; |
88 | | virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override = 0; |
89 | | |
90 | | // OPropertySetHelper |
91 | | virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const css::uno::Any& rValue ) override; |
92 | | virtual sal_Bool SAL_CALL convertFastPropertyValue( css::uno::Any& rConvertedValue, css::uno::Any& rOldValue, sal_Int32 nHandle, const css::uno::Any& rValue) override; |
93 | | |
94 | | // XExecutableDialog |
95 | | virtual void SAL_CALL setTitle( const OUString& aTitle ) override; |
96 | | virtual sal_Int16 SAL_CALL execute( ) override; |
97 | | |
98 | | // XInitialization |
99 | | virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; |
100 | | |
101 | | protected: |
102 | | /** create the concrete dialog instance. Note that m_aMutex is not locked when this method get called, |
103 | | but the application-wide solar mutex is (to guard the not thread-safe ctor of the dialog). |
104 | | @param pParent the parent window for the new dialog |
105 | | */ |
106 | | virtual std::unique_ptr<weld::DialogController> createDialog(const css::uno::Reference<css::awt::XWindow>& rParent) = 0; |
107 | | |
108 | | /// called to destroy the dialog used. deletes m_pDialog and resets it to NULL |
109 | | void destroyDialog(); |
110 | | |
111 | | /** called after the dialog has been executed |
112 | | @param _nExecutionResult the execution result as returned by Dialog::Execute |
113 | | */ |
114 | 0 | virtual void executedDialog(sal_Int16 /*_nExecutionResult*/) { } |
115 | | |
116 | | /** smaller form of <method>initialize</method>.<p/> |
117 | | The <method>initialize</method> method is called with a sequence of com.sun.star.uno::Any's, |
118 | | which is split up into the single elements, which are passed to implInitialize. The default implementation |
119 | | tries to extract a com.sun.star.beans::PropertyValue from the value a pass it to the |
120 | | com.sun.star.beans::XPropertySet interface of the object. |
121 | | */ |
122 | | virtual void implInitialize(const css::uno::Any& _rValue); |
123 | | |
124 | | private: |
125 | | |
126 | | /** ensures that m_pDialog is not <NULL/> |
127 | | |
128 | | This method does nothing if m_pDialog is already non-<NULL/>. Else, it calls createDialog and does |
129 | | all necessary initializations of the new dialog instance. |
130 | | |
131 | | @precond |
132 | | m_aMutex is locked |
133 | | |
134 | | @return |
135 | | <TRUE/> if and only if m_pDialog is non-<NULL/> upon returning from the method. Note that the only |
136 | | case where m_pDialog is <NULL/> is when createDialog returned <NULL/>, which is will fire an assertion |
137 | | in non-product builds. |
138 | | */ |
139 | | bool impl_ensureDialog_lck(); |
140 | | }; |
141 | | |
142 | | /// helper class for guarding access to methods of an OGenericUnoDialog |
143 | | class UnoDialogEntryGuard |
144 | | { |
145 | | public: |
146 | | UnoDialogEntryGuard( OGenericUnoDialog& _rDialog ) |
147 | 0 | :m_aGuard( _rDialog.GetMutex() ) |
148 | 0 | { |
149 | 0 | } |
150 | | |
151 | | private: |
152 | | ::osl::MutexGuard m_aGuard; |
153 | | }; |
154 | | |
155 | | |
156 | | } // namespace svt |
157 | | |
158 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |