tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sfx2 / source / sidebar / AsynchronousCall.cxx
blob3377c1bb31c2f14ca868b72329c25011ad3ef23e
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 #include <sfx2/sidebar/AsynchronousCall.hxx>
21 #include <utility>
22 #include <vcl/svapp.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <sfx2/lokhelper.hxx>
26 namespace sfx2::sidebar {
28 AsynchronousCall::AsynchronousCall (const SfxViewFrame* pViewFrame, Action aAction)
29 : maAction(std::move(aAction)),
30 mnCallId(nullptr),
31 mpViewFrame(pViewFrame)
35 AsynchronousCall::~AsynchronousCall()
37 CancelRequest();
40 void AsynchronousCall::RequestCall()
42 if (mnCallId == nullptr)
44 Link<void*,void> aLink (LINK(this, AsynchronousCall, HandleUserCall));
45 mnCallId = Application::PostUserEvent(aLink);
49 void AsynchronousCall::CancelRequest()
51 if (mnCallId != nullptr)
53 Application::RemoveUserEvent(mnCallId);
54 mnCallId = nullptr;
58 void AsynchronousCall::Sync()
60 if (mnCallId != nullptr) {
61 SfxLokLanguageGuard aGuard(mpViewFrame ? mpViewFrame->GetViewShell() : nullptr);
62 maAction();
63 CancelRequest();
67 IMPL_LINK_NOARG(AsynchronousCall, HandleUserCall, void*, void )
69 mnCallId = nullptr;
70 if (maAction)
72 SfxLokLanguageGuard aGuard(mpViewFrame ? mpViewFrame->GetViewShell() : nullptr);
73 maAction();
77 } // end of namespace sfx2::sidebar
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */