Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/sidebar/PanelTitleBar.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 <sidebar/PanelTitleBar.hxx>
21
#include <sfx2/sidebar/Panel.hxx>
22
#include <sfx2/sidebar/Theme.hxx>
23
#include <sidebar/ControllerFactory.hxx>
24
25
using namespace css;
26
using namespace css::uno;
27
28
namespace sfx2::sidebar {
29
30
PanelTitleBar::PanelTitleBar(const OUString& rsTitle,
31
                             weld::Builder& rBuilder,
32
                             Panel* pPanel)
33
0
    : TitleBar(rBuilder, Theme::Color_PanelTitleBarBackground),
34
0
      mxExpander(rBuilder.weld_expander(u"expander"_ustr)),
35
0
      mpPanel(pPanel),
36
0
      msIdent(u"button"_ustr)
37
0
{
38
0
    mxExpander->set_label(rsTitle);
39
0
    mxExpander->connect_expanded(LINK(this, PanelTitleBar, ExpandHdl));
40
41
    // tdf#145801 lock the height to the size it needs with the "toolbar" button shown
42
    // so all of the titlebars are the same height if the "toolbar" is hidden in some
43
    // of them
44
0
    mxToolBox->show();
45
0
    mxTitlebar->set_size_request(-1, mxTitlebar->get_preferred_size().Height());
46
0
    mxToolBox->hide();
47
48
0
    assert(mpPanel);
49
50
0
    UpdateExpandedState();
51
0
}
52
53
void PanelTitleBar::SetTitle(const OUString& rsTitle)
54
0
{
55
0
    mxExpander->set_label(rsTitle);
56
0
}
57
58
OUString PanelTitleBar::GetTitle() const
59
0
{
60
0
    return mxExpander->get_label();
61
0
}
62
63
void PanelTitleBar::UpdateExpandedState()
64
0
{
65
0
    mxExpander->set_expanded(mpPanel->IsExpanded());
66
0
}
67
68
PanelTitleBar::~PanelTitleBar()
69
0
{
70
0
    Reference<lang::XComponent> xComponent(mxController, UNO_QUERY);
71
0
    if (xComponent.is())
72
0
        xComponent->dispose();
73
0
    mxController.clear();
74
0
    mpPanel = nullptr;
75
0
    mxExpander.reset();
76
0
}
77
78
void PanelTitleBar::SetMoreOptionsCommand(const OUString& rsCommandName,
79
                                          const css::uno::Reference<css::frame::XFrame>& rxFrame,
80
                                          const css::uno::Reference<css::frame::XController>& rxController)
81
0
{
82
0
    if (rsCommandName == msMoreOptionsCommand)
83
0
        return;
84
85
0
    if (!msMoreOptionsCommand.isEmpty())
86
0
        mxToolBox->hide();
87
88
0
    msMoreOptionsCommand = rsCommandName;
89
90
0
    if (msMoreOptionsCommand.isEmpty())
91
0
        return;
92
93
0
    msIdent = msMoreOptionsCommand;
94
0
    mxToolBox->set_item_ident(0, msIdent);
95
96
0
    Reference<lang::XComponent> xComponent(mxController, UNO_QUERY);
97
0
    if (xComponent.is())
98
0
        xComponent->dispose();
99
0
    mxController =
100
0
        ControllerFactory::CreateToolBoxController(
101
0
            *mxToolBox, mrBuilder, msMoreOptionsCommand, rxFrame, rxController, true);
102
103
0
    mxToolBox->show();
104
0
}
105
106
void PanelTitleBar::HandleToolBoxItemClick()
107
0
{
108
0
    if (!mxController)
109
0
        return;
110
0
    mxController->click();
111
0
    mxController->execute(0);
112
0
}
113
114
IMPL_LINK(PanelTitleBar, ExpandHdl, weld::Expander&, rExpander, void)
115
0
{
116
0
    if (!mpPanel)
117
0
        return;
118
0
    mpPanel->SetExpanded(rExpander.get_expanded());
119
0
}
120
121
} // end of namespace sfx2::sidebar
122
123
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */