Coverage Report

Created: 2026-04-09 11:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/sidebar/Sidebar.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 <sfx2/sidebar/Sidebar.hxx>
21
#include <sfx2/sidebar/SidebarController.hxx>
22
#include <sfx2/sidebar/ResourceManager.hxx>
23
#include <sfx2/sidebar/SidebarDockingWindow.hxx>
24
#include <sidebar/PanelDescriptor.hxx>
25
#include <sidebar/Tools.hxx>
26
#include <sfx2/sidebar/FocusManager.hxx>
27
#include <sfx2/childwin.hxx>
28
#include <sfx2/sfxsids.hrc>
29
#include <sfx2/viewfrm.hxx>
30
#include <sfx2/viewsh.hxx>
31
#include <com/sun/star/frame/XDispatch.hpp>
32
33
using namespace css;
34
35
namespace sfx2::sidebar {
36
37
void Sidebar::ShowDeck(std::u16string_view rsDeckId, SfxViewFrame* pViewFrame, bool bToggle)
38
0
{
39
0
    if (!pViewFrame)
40
0
        return;
41
42
0
    SfxChildWindow* pSidebarChildWindow = pViewFrame->GetChildWindow(SID_SIDEBAR);
43
0
    bool bInitiallyVisible = pSidebarChildWindow && pSidebarChildWindow->IsVisible();
44
0
    if (!bInitiallyVisible)
45
0
        pViewFrame->ShowChildWindow(SID_SIDEBAR);
46
47
0
    SidebarController* pController =
48
0
            SidebarController::GetSidebarControllerForFrame(pViewFrame->GetFrame().GetFrameInterface());
49
0
    if (!pController)
50
0
        return;
51
52
0
    if (bToggle && bInitiallyVisible && pController->IsDeckVisible(rsDeckId))
53
0
    {
54
        // close the sidebar if it was already visible and showing this sidebar deck
55
0
        const util::URL aURL(Tools::GetURL(u".uno:Sidebar"_ustr));
56
0
        css::uno::Reference<frame::XDispatch> xDispatch(Tools::GetDispatch(pViewFrame->GetFrame().GetFrameInterface(), aURL));
57
0
        if (xDispatch.is())
58
0
            xDispatch->dispatch(aURL, css::uno::Sequence<beans::PropertyValue>());
59
0
    }
60
0
    else
61
0
    {
62
0
        pController->OpenThenSwitchToDeck(rsDeckId);
63
0
        pController->GetFocusManager().GrabFocusPanel();
64
0
    }
65
0
}
66
67
void Sidebar::ShowPanel (
68
    std::u16string_view rsPanelId,
69
    const css::uno::Reference<frame::XFrame>& rxFrame, bool bFocus)
70
0
{
71
0
    SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
72
0
    if (!pController)
73
0
        return;
74
75
0
    std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
76
77
0
    if (!xPanelDescriptor)
78
0
        return;
79
80
    // This should be a lot more sophisticated:
81
    // - Make the deck switching asynchronous
82
    // - Make sure to use a context that really shows the panel
83
84
    // All that is not necessary for the current use cases so let's
85
    // keep it simple for the time being.
86
0
    pController->OpenThenSwitchToDeck(xPanelDescriptor->msDeckId);
87
88
0
    if (bFocus)
89
0
        pController->GetFocusManager().GrabFocusPanel();
90
0
}
91
92
void Sidebar::TogglePanel (
93
    std::u16string_view rsPanelId,
94
    const css::uno::Reference<frame::XFrame>& rxFrame)
95
0
{
96
0
    SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
97
0
    if (!pController)
98
0
        return;
99
100
0
    std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
101
102
0
    if (!xPanelDescriptor)
103
0
        return;
104
105
    // This should be a lot more sophisticated:
106
    // - Make the deck switching asynchronous
107
    // - Make sure to use a context that really shows the panel
108
109
    // All that is not necessary for the current use cases so let's
110
    // keep it simple for the time being.
111
0
    pController->OpenThenToggleDeck(xPanelDescriptor->msDeckId);
112
0
}
113
114
bool Sidebar::IsPanelVisible(
115
    std::u16string_view rsPanelId,
116
    const css::uno::Reference<frame::XFrame>& rxFrame)
117
0
{
118
0
    SidebarController* pController = SidebarController::GetSidebarControllerForFrame(rxFrame);
119
0
    if (!pController)
120
0
        return false;
121
122
0
    std::shared_ptr<PanelDescriptor> xPanelDescriptor = pController->GetResourceManager()->GetPanelDescriptor(rsPanelId);
123
0
    if (!xPanelDescriptor)
124
0
        return false;
125
126
0
    return pController->IsDeckVisible(xPanelDescriptor->msDeckId);
127
0
}
128
129
bool Sidebar::Setup(std::u16string_view sidebarDeckId)
130
0
{
131
0
    SfxViewShell* pViewShell = SfxViewShell::Current();
132
0
    SfxViewFrame* pViewFrame = pViewShell ? &pViewShell->GetViewFrame() : nullptr;
133
0
    if (pViewFrame)
134
0
    {
135
0
        if (!pViewFrame->GetChildWindow(SID_SIDEBAR))
136
0
            pViewFrame->SetChildWindow(SID_SIDEBAR, false /* create it */, true /* focus */);
137
138
0
        pViewFrame->ShowChildWindow(SID_SIDEBAR, true);
139
140
        // Force synchronous population of panels
141
0
        SfxChildWindow *pChild = pViewFrame->GetChildWindow(SID_SIDEBAR);
142
0
        if (!pChild)
143
0
            return false;
144
145
0
        auto pDockingWin = dynamic_cast<sfx2::sidebar::SidebarDockingWindow *>(pChild->GetWindow());
146
0
        if (!pDockingWin)
147
0
            return false;
148
149
0
        pViewFrame->ShowChildWindow( SID_SIDEBAR );
150
151
0
        const rtl::Reference<sfx2::sidebar::SidebarController>& xController
152
0
            = pDockingWin->GetOrCreateSidebarController();
153
154
0
        xController->FadeIn();
155
0
        xController->RequestOpenDeck();
156
157
0
        if (!sidebarDeckId.empty())
158
0
        {
159
0
            xController->SwitchToDeck(sidebarDeckId);
160
0
        }
161
0
        else
162
0
        {
163
0
            xController->SwitchToDefaultDeck();
164
0
        }
165
166
0
        pDockingWin->SyncUpdate();
167
0
        return true;
168
0
    }
169
0
    else
170
0
        return false;
171
0
}
172
173
} // end of namespace sfx2::sidebar
174
175
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */