1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <uielement/FixedTextToolbarController.hxx>
22 #include <comphelper/propertyvalue.hxx>
23 #include <vcl/toolbox.hxx>
24 #include <vcl/InterimItemWindow.hxx>
25 #include <vcl/svapp.hxx>
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::awt
;
29 using namespace ::com::sun::star::uno
;
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::lang
;
32 using namespace ::com::sun::star::frame
;
33 using namespace ::com::sun::star::util
;
37 class FixedTextControl final
: public InterimItemWindow
40 FixedTextControl(vcl::Window
* pParent
);
41 virtual ~FixedTextControl() override
;
42 virtual void dispose() override
;
43 OUString
get_label() const { return m_xWidget
->get_label(); }
44 void set_label(const OUString
& rLabel
) { return m_xWidget
->set_label(rLabel
); }
45 DECL_LINK(KeyInputHdl
, const ::KeyEvent
&, bool);
48 std::unique_ptr
<weld::Label
> m_xWidget
;
51 FixedTextControl::FixedTextControl(vcl::Window
* pParent
)
52 : InterimItemWindow(pParent
, "svt/ui/fixedtextcontrol.ui", "FixedTextControl")
53 , m_xWidget(m_xBuilder
->weld_label("label"))
55 InitControlBase(m_xWidget
.get());
57 m_xWidget
->connect_key_press(LINK(this, FixedTextControl
, KeyInputHdl
));
60 IMPL_LINK(FixedTextControl
, KeyInputHdl
, const ::KeyEvent
&, rKEvt
, bool)
62 return ChildKeyInput(rKEvt
);
65 FixedTextControl::~FixedTextControl() { disposeOnce(); }
67 void FixedTextControl::dispose()
70 InterimItemWindow::dispose();
73 FixedTextToolbarController::FixedTextToolbarController(
74 const Reference
<XComponentContext
>& rxContext
, const Reference
<XFrame
>& rFrame
,
75 ToolBox
* pToolbar
, ToolBoxItemId nID
, const OUString
& aCommand
)
76 : ComplexToolbarController(rxContext
, rFrame
, pToolbar
, nID
, aCommand
)
78 m_pFixedTextControl
= VclPtr
<FixedTextControl
>::Create(m_xToolbar
);
79 m_xToolbar
->SetItemWindow(m_nID
, m_pFixedTextControl
);
80 m_xToolbar
->SetItemBits(m_nID
, ToolBoxItemBits::AUTOSIZE
| m_xToolbar
->GetItemBits(m_nID
));
83 void SAL_CALL
FixedTextToolbarController::dispose()
85 SolarMutexGuard aSolarMutexGuard
;
86 m_xToolbar
->SetItemWindow(m_nID
, nullptr);
87 m_pFixedTextControl
.disposeAndClear();
88 ComplexToolbarController::dispose();
91 Sequence
<PropertyValue
> FixedTextToolbarController::getExecuteArgs(sal_Int16 KeyModifier
) const
93 const OUString aSelectedText
= m_pFixedTextControl
->get_label();
95 // Add key modifier to argument list
96 Sequence
<PropertyValue
> aArgs
{ comphelper::makePropertyValue("KeyModifier", KeyModifier
),
97 comphelper::makePropertyValue("Text", aSelectedText
) };
101 void FixedTextToolbarController::executeControlCommand(
102 const css::frame::ControlCommand
& rControlCommand
)
104 SolarMutexGuard aSolarMutexGuard
;
106 if (rControlCommand
.Command
!= "SetText")
109 for (const NamedValue
& rArg
: rControlCommand
.Arguments
)
111 if (rArg
.Name
== "Text")
114 rArg
.Value
>>= aText
;
115 m_pFixedTextControl
->set_label(aText
);
116 m_pFixedTextControl
->SetSizePixel(m_pFixedTextControl
->get_preferred_size());
119 notifyTextChanged(aText
);
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */