/src/libreoffice/include/svtools/genericasyncunodialog.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 <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp> |
23 | | #include <svtools/genericunodialog.hxx> |
24 | | #include <vcl/svapp.hxx> |
25 | | |
26 | | using namespace css::uno; |
27 | | |
28 | | namespace svt |
29 | | { |
30 | | typedef cppu::ImplInheritanceHelper<::svt::OGenericUnoDialog, |
31 | | css::ui::dialogs::XAsynchronousExecutableDialog> |
32 | | OGenericUnoAsyncDialogBase; |
33 | | |
34 | | /** abstract base class for implementing UNO objects representing asynchronous dialogs |
35 | | |
36 | | Contrary to StartExecuteAsync in VclAbstractDialog from include/vcl/abstdlg.hxx, |
37 | | the different methods are used in a special case when an import or export action |
38 | | wants to show a dialog, as part of a synchronous filter() API call. |
39 | | |
40 | | In this case it's not possible to move the "rest of the code" to an async |
41 | | callback, so that needs special handling. Luckily these dialogs are rather rare. |
42 | | */ |
43 | | template <typename T> class OGenericUnoAsyncDialog : public OGenericUnoAsyncDialogBase |
44 | | { |
45 | | class UnoAsyncDialogEntryGuard |
46 | | { |
47 | | public: |
48 | | UnoAsyncDialogEntryGuard(OGenericUnoAsyncDialog<T>& _rDialog) |
49 | 0 | : m_aGuard(_rDialog.GetMutex()) |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | | private: |
54 | | ::osl::MutexGuard m_aGuard; |
55 | | }; |
56 | | |
57 | | protected: |
58 | | std::shared_ptr<T> m_xAsyncDialog; |
59 | | |
60 | | protected: |
61 | | OGenericUnoAsyncDialog(const css::uno::Reference<css::uno::XComponentContext>& _rxContext) |
62 | 0 | : OGenericUnoAsyncDialogBase(_rxContext) |
63 | 0 | { |
64 | 0 | } |
65 | | |
66 | | public: |
67 | | // XAsynchronousExecutableDialog |
68 | | void SAL_CALL setDialogTitle(const OUString& aTitle) override |
69 | 0 | { |
70 | 0 | OGenericUnoDialog::setTitle(aTitle); |
71 | 0 | } |
72 | | |
73 | | virtual void SAL_CALL startExecuteModal( |
74 | | const css::uno::Reference<css::ui::dialogs::XDialogClosedListener>& xListener) override |
75 | 0 | { |
76 | 0 | SolarMutexGuard aSolarGuard; |
77 | |
|
78 | 0 | { |
79 | 0 | UnoAsyncDialogEntryGuard aGuard(*this); |
80 | |
|
81 | 0 | if (m_bExecuting) |
82 | 0 | throw RuntimeException("already executing the dialog (recursive call)", *this); |
83 | | |
84 | 0 | if (!m_xAsyncDialog) |
85 | 0 | { |
86 | 0 | m_xAsyncDialog = createAsyncDialog(m_xParent); |
87 | 0 | OSL_ENSURE(m_xAsyncDialog, "OGenericUnoAsyncDialog::startExecuteModal: " |
88 | 0 | "createAsyncDialog returned nonsense!"); |
89 | 0 | if (!m_xAsyncDialog) |
90 | 0 | return; |
91 | | |
92 | | // do some initialisations |
93 | 0 | if (!m_bTitleAmbiguous) |
94 | 0 | m_xAsyncDialog->set_title(m_sTitle); |
95 | 0 | } |
96 | | |
97 | 0 | m_bExecuting = true; |
98 | 0 | } |
99 | | |
100 | 0 | runAsync(xListener); |
101 | 0 | } |
102 | | |
103 | | protected: |
104 | | virtual std::shared_ptr<T> |
105 | | createAsyncDialog(const css::uno::Reference<css::awt::XWindow>& /*rParent*/) |
106 | 0 | { |
107 | 0 | return nullptr; |
108 | 0 | } |
109 | | |
110 | | void destroyAsyncDialog() |
111 | 0 | { |
112 | 0 | SolarMutexGuard aSolarGuard; |
113 | 0 | if (m_xAsyncDialog) |
114 | 0 | m_xAsyncDialog.reset(); |
115 | 0 | } |
116 | | |
117 | | virtual void |
118 | | runAsync(const css::uno::Reference<css::ui::dialogs::XDialogClosedListener>& /*xListener*/) |
119 | 0 | { |
120 | 0 | } |
121 | | |
122 | | virtual void executedAsyncDialog(std::shared_ptr<T> /*xAsyncDialog*/, |
123 | | sal_Int32 /*_nExecutionResult*/) |
124 | 0 | { |
125 | 0 | } |
126 | | }; |
127 | | |
128 | | } // namespace svt |
129 | | |
130 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |