1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <vcl/abstdlg.hxx>
23 #include <vcl/weld.hxx>
26 #include <type_traits>
30 // Templated base class storing the dialog pointer, and implementing Execute, StartExecuteAsync,
31 // and the shared constructor used by derived classes
32 template <class Base
, class Dialog
, template <class...> class Ptr
, bool Async
>
33 requires
std::is_base_of_v
<VclAbstractDialog
, Base
>&&
34 std::is_base_of_v
<weld::DialogController
, Dialog
> class AbstractDialogImpl_BASE
: public Base
37 explicit AbstractDialogImpl_BASE(Ptr
<Dialog
> p
)
38 : m_pDlg(std::move(p
))
41 template <typename
... Arg
>
42 requires
std::is_constructible_v
<Dialog
, Arg
...> explicit AbstractDialogImpl_BASE(Arg
&&... arg
)
43 : m_pDlg(make_dialog(std::forward
<Arg
>(arg
)...))
47 short Execute() override
{ return m_pDlg
->run(); }
49 bool StartExecuteAsync(VclAbstractDialog::AsyncContext
& rCtx
) override
52 return Dialog::runAsync(m_pDlg
, rCtx
.maEndDialogFn
);
54 return Base::StartExecuteAsync(rCtx
); // assert / fail
61 template <typename
... Arg
> static auto make_dialog(Arg
&&... arg
)
63 if constexpr (std::is_same_v
<Ptr
<void>, std::shared_ptr
<void>>)
64 return std::make_shared
<Dialog
>(std::forward
<Arg
>(arg
)...);
66 return std::make_unique
<Dialog
>(std::forward
<Arg
>(arg
)...);
70 // Base for synchronously called dialogs, using unique_ptr
71 template <class Base
, class Dialog
>
72 using AbstractDialogImpl_Sync
= AbstractDialogImpl_BASE
<Base
, Dialog
, std::unique_ptr
, false>;
74 // Base for synchronously called dialogs, using shared_ptr
75 template <class Base
, class Dialog
>
76 using AbstractDialogImpl_Sync_Shared
77 = AbstractDialogImpl_BASE
<Base
, Dialog
, std::shared_ptr
, false>;
79 // Base for asynchronously called dialogs
80 template <class Base
, class Dialog
>
81 using AbstractDialogImpl_Async
= AbstractDialogImpl_BASE
<Base
, Dialog
, std::shared_ptr
, true>;
84 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */