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 <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
23 #include <svtools/genericunodialog.hxx>
24 #include <vcl/svapp.hxx>
26 using namespace css::uno
;
30 typedef cppu::ImplInheritanceHelper
<::svt::OGenericUnoDialog
,
31 css::ui::dialogs::XAsynchronousExecutableDialog
>
32 OGenericUnoAsyncDialogBase
;
34 /** abstract base class for implementing UNO objects representing asynchronous dialogs
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.
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.
43 template <typename T
> class OGenericUnoAsyncDialog
: public OGenericUnoAsyncDialogBase
45 class UnoAsyncDialogEntryGuard
48 UnoAsyncDialogEntryGuard(OGenericUnoAsyncDialog
<T
>& _rDialog
)
49 : m_aGuard(_rDialog
.GetMutex())
54 ::osl::MutexGuard m_aGuard
;
58 std::shared_ptr
<T
> m_xAsyncDialog
;
61 OGenericUnoAsyncDialog(const css::uno::Reference
<css::uno::XComponentContext
>& _rxContext
)
62 : OGenericUnoAsyncDialogBase(_rxContext
)
67 // XAsynchronousExecutableDialog
68 void SAL_CALL
setDialogTitle(const OUString
& aTitle
) override
70 OGenericUnoDialog::setTitle(aTitle
);
73 virtual void SAL_CALL
startExecuteModal(
74 const css::uno::Reference
<css::ui::dialogs::XDialogClosedListener
>& xListener
) override
76 SolarMutexGuard aSolarGuard
;
79 UnoAsyncDialogEntryGuard
aGuard(*this);
82 throw RuntimeException("already executing the dialog (recursive call)", *this);
86 m_xAsyncDialog
= createAsyncDialog(m_xParent
);
87 OSL_ENSURE(m_xAsyncDialog
, "OGenericUnoAsyncDialog::startExecuteModal: "
88 "createAsyncDialog returned nonsense!");
92 // do some initialisations
93 if (!m_bTitleAmbiguous
)
94 m_xAsyncDialog
->set_title(m_sTitle
);
104 virtual std::shared_ptr
<T
>
105 createAsyncDialog(const css::uno::Reference
<css::awt::XWindow
>& /*rParent*/)
110 void destroyAsyncDialog()
112 SolarMutexGuard aSolarGuard
;
114 m_xAsyncDialog
.reset();
118 runAsync(const css::uno::Reference
<css::ui::dialogs::XDialogClosedListener
>& /*xListener*/)
122 virtual void executedAsyncDialog(std::shared_ptr
<T
> /*xAsyncDialog*/,
123 sal_Int32
/*_nExecutionResult*/)
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */