Coverage Report

Created: 2026-05-16 09:25

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/framework/source/uielement/FixedTextToolbarController.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 <uielement/FixedTextToolbarController.hxx>
21
22
#include <comphelper/propertyvalue.hxx>
23
#include <vcl/toolbox.hxx>
24
#include <vcl/InterimItemWindow.hxx>
25
#include <vcl/svapp.hxx>
26
#include <vcl/weld/weld.hxx>
27
#include <vcl/weld/Builder.hxx>
28
29
using namespace ::com::sun::star;
30
using namespace ::com::sun::star::uno;
31
using namespace ::com::sun::star::beans;
32
using namespace ::com::sun::star::frame;
33
34
namespace framework
35
{
36
class FixedTextControl final : public InterimItemWindow
37
{
38
public:
39
    FixedTextControl(vcl::Window* pParent);
40
    virtual ~FixedTextControl() override;
41
    virtual void dispose() override;
42
0
    OUString get_label() const { return m_xWidget->get_label(); }
43
0
    void set_label(const OUString& rLabel) { return m_xWidget->set_label(rLabel); }
44
    DECL_LINK(KeyInputHdl, const ::KeyEvent&, bool);
45
46
private:
47
    std::unique_ptr<weld::Label> m_xWidget;
48
};
49
50
FixedTextControl::FixedTextControl(vcl::Window* pParent)
51
0
    : InterimItemWindow(pParent, u"svt/ui/fixedtextcontrol.ui"_ustr, u"FixedTextControl"_ustr)
52
0
    , m_xWidget(m_xBuilder->weld_label(u"label"_ustr))
53
0
{
54
0
    InitControlBase(m_xWidget.get());
55
56
0
    m_xWidget->connect_key_press(LINK(this, FixedTextControl, KeyInputHdl));
57
0
}
Unexecuted instantiation: framework::FixedTextControl::FixedTextControl(vcl::Window*)
Unexecuted instantiation: framework::FixedTextControl::FixedTextControl(vcl::Window*)
58
59
IMPL_LINK(FixedTextControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool)
60
0
{
61
0
    return ChildKeyInput(rKEvt);
62
0
}
63
64
0
FixedTextControl::~FixedTextControl() { disposeOnce(); }
65
66
void FixedTextControl::dispose()
67
0
{
68
0
    m_xWidget.reset();
69
0
    InterimItemWindow::dispose();
70
0
}
71
72
FixedTextToolbarController::FixedTextToolbarController(
73
    const Reference<XComponentContext>& rxContext, const Reference<XFrame>& rFrame,
74
    ToolBox* pToolbar, ToolBoxItemId nID, const OUString& aCommand)
75
0
    : ComplexToolbarController(rxContext, rFrame, pToolbar, nID, aCommand)
76
0
{
77
0
    m_pFixedTextControl = VclPtr<FixedTextControl>::Create(m_xToolbar);
78
0
    m_xToolbar->SetItemWindow(m_nID, m_pFixedTextControl);
79
0
    m_xToolbar->SetItemBits(m_nID, ToolBoxItemBits::AUTOSIZE | m_xToolbar->GetItemBits(m_nID));
80
0
}
81
82
void SAL_CALL FixedTextToolbarController::dispose()
83
0
{
84
0
    SolarMutexGuard aSolarMutexGuard;
85
0
    m_xToolbar->SetItemWindow(m_nID, nullptr);
86
0
    m_pFixedTextControl.disposeAndClear();
87
0
    ComplexToolbarController::dispose();
88
0
}
89
90
Sequence<PropertyValue> FixedTextToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
91
0
{
92
0
    const OUString aSelectedText = m_pFixedTextControl->get_label();
93
94
    // Add key modifier to argument list
95
0
    Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue(u"KeyModifier"_ustr, KeyModifier),
96
0
                                   comphelper::makePropertyValue(u"Text"_ustr, aSelectedText) };
97
0
    return aArgs;
98
0
}
99
100
void FixedTextToolbarController::executeControlCommand(
101
    const css::frame::ControlCommand& rControlCommand)
102
0
{
103
0
    SolarMutexGuard aSolarMutexGuard;
104
105
0
    if (rControlCommand.Command != "SetText")
106
0
        return;
107
108
0
    for (const NamedValue& rArg : rControlCommand.Arguments)
109
0
    {
110
0
        if (rArg.Name == "Text")
111
0
        {
112
0
            OUString aText;
113
0
            rArg.Value >>= aText;
114
0
            m_pFixedTextControl->set_label(aText);
115
0
            m_pFixedTextControl->SetSizePixel(m_pFixedTextControl->get_preferred_size());
116
117
            // send notification
118
0
            notifyTextChanged(aText);
119
0
            break;
120
0
        }
121
0
    }
122
0
}
123
124
} // namespace
125
126
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */