Coverage Report

Created: 2025-12-08 09:28

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