Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / svtools / genericasyncunodialog.hxx
blob937f9778030de2711ea87b91aba8f10a721f173e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
23 #include <sfx2/tabdlg.hxx>
24 #include <svtools/genericunodialog.hxx>
25 #include <vcl/svapp.hxx>
27 using namespace css::uno;
29 namespace svt
31 typedef cppu::ImplInheritanceHelper<::svt::OGenericUnoDialog,
32 css::ui::dialogs::XAsynchronousExecutableDialog>
33 OGenericUnoAsyncDialogBase;
35 /** abstract base class for implementing UNO objects representing asynchronous dialogs
37 template <typename T> class OGenericUnoAsyncDialog : public OGenericUnoAsyncDialogBase
39 class UnoAsyncDialogEntryGuard
41 public:
42 UnoAsyncDialogEntryGuard(OGenericUnoAsyncDialog<T>& _rDialog)
43 : m_aGuard(_rDialog.GetMutex())
47 private:
48 ::osl::MutexGuard m_aGuard;
51 protected:
52 std::shared_ptr<T> m_xAsyncDialog;
54 protected:
55 OGenericUnoAsyncDialog(const css::uno::Reference<css::uno::XComponentContext>& _rxContext)
56 : OGenericUnoAsyncDialogBase(_rxContext)
60 public:
61 // XAsynchronousExecutableDialog
62 void SAL_CALL setDialogTitle(const OUString& aTitle) override
64 OGenericUnoDialog::setTitle(aTitle);
67 virtual void SAL_CALL startExecuteModal(
68 const css::uno::Reference<css::ui::dialogs::XDialogClosedListener>& xListener) override
70 SolarMutexGuard aSolarGuard;
73 UnoAsyncDialogEntryGuard aGuard(*this);
75 if (m_bExecuting)
76 throw RuntimeException("already executing the dialog (recursive call)", *this);
78 if (!m_xAsyncDialog)
80 m_xAsyncDialog = createAsyncDialog(m_xParent);
81 OSL_ENSURE(m_xAsyncDialog, "OGenericUnoAsyncDialog::startExecuteModal: "
82 "createAsyncDialog returned nonsense!");
83 if (!m_xAsyncDialog)
84 return;
86 // do some initialisations
87 if (!m_bTitleAmbiguous)
88 m_xAsyncDialog->set_title(m_sTitle);
91 m_bExecuting = true;
94 runAsync(xListener);
97 protected:
98 virtual std::shared_ptr<T>
99 createAsyncDialog(const css::uno::Reference<css::awt::XWindow>& /*rParent*/)
101 return nullptr;
104 void destroyAsyncDialog()
106 SolarMutexGuard aSolarGuard;
107 if (m_xAsyncDialog)
108 m_xAsyncDialog.reset();
111 virtual void
112 runAsync(const css::uno::Reference<css::ui::dialogs::XDialogClosedListener>& /*xListener*/)
116 virtual void executedAsyncDialog(std::shared_ptr<T> /*xAsyncDialog*/,
117 sal_Int32 /*_nExecutionResult*/)
122 } // namespace svt
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */