Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/notify/hintpost.cxx
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
#include <hintpost.hxx>
21
22
#include <sfx2/request.hxx>
23
#include <sfx2/lokhelper.hxx>
24
#include <utility>
25
#include <vcl/svapp.hxx>
26
#include <comphelper/lok.hxx>
27
28
SfxHintPoster::SfxHintPoster(SfxDispatcher* aLink)
29
4.29k
    : m_Link(aLink)
30
4.29k
{
31
4.29k
}
32
33
4.26k
SfxHintPoster::~SfxHintPoster() {}
34
35
void SfxHintPoster::Post(std::unique_ptr<SfxRequest> pHintToPost)
36
0
{
37
0
    if (comphelper::LibreOfficeKit::isActive())
38
0
    {
39
        // Store the LOK view at the time of posting, so we can restore it later.
40
0
        if (SfxLokHelper::isSettingView())
41
0
        {
42
            // This would be bad, setView() should not trigger new posted hints, otherwise this will
43
            // never end if the view doesn't match when we execute the posted hint.
44
0
            SAL_WARN("sfx.notify", "SfxHintPoster::Post: posting new hint during setting a view");
45
0
        }
46
47
0
        pHintToPost->SetLokViewId(SfxLokHelper::getCurrentView());
48
0
    }
49
50
0
    Application::PostUserEvent((LINK(this, SfxHintPoster, DoEvent_Impl)), pHintToPost.release());
51
0
    AddFirstRef();
52
0
}
53
54
IMPL_LINK(SfxHintPoster, DoEvent_Impl, void*, pPostedHint, void)
55
0
{
56
0
    auto pRequest = static_cast<SfxRequest*>(pPostedHint);
57
0
    if (m_Link)
58
0
    {
59
0
        bool bSetView = false;
60
0
        int nOldId = -1;
61
0
        if (comphelper::LibreOfficeKit::isActive())
62
0
        {
63
0
            int nNewId = pRequest->GetLokViewId();
64
0
            nOldId = SfxLokHelper::getCurrentView();
65
0
            if (nNewId != -1 && nNewId != nOldId)
66
0
            {
67
                // The current view ID is not the one that was active when posting the hint, switch
68
                // to it.
69
0
                SfxLokHelper::setView(nNewId);
70
0
                bSetView = true;
71
0
            }
72
0
        }
73
74
0
        m_Link->PostMsgHandler(std::unique_ptr<SfxRequest>(pRequest));
75
76
0
        if (bSetView)
77
0
        {
78
0
            SfxLokHelper::setView(nOldId);
79
0
        }
80
0
    }
81
0
    else
82
0
        delete pRequest;
83
0
    ReleaseRef();
84
0
}
85
86
4.26k
void SfxHintPoster::ClearLink() { m_Link = nullptr; }
87
88
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */