LibreOffice Module framework (master) 1
FixedTextToolbarController.cxx
Go to the documentation of this file.
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
21
23#include <vcl/toolbox.hxx>
25#include <vcl/svapp.hxx>
26
27using namespace ::com::sun::star;
28using namespace ::com::sun::star::awt;
29using namespace ::com::sun::star::uno;
30using namespace ::com::sun::star::beans;
31using namespace ::com::sun::star::lang;
32using namespace ::com::sun::star::frame;
33using namespace ::com::sun::star::util;
34
35namespace framework
36{
38{
39public:
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);
46
47private:
48 std::unique_ptr<weld::Label> m_xWidget;
49};
50
52 : InterimItemWindow(pParent, "svt/ui/fixedtextcontrol.ui", "FixedTextControl")
53 , m_xWidget(m_xBuilder->weld_label("label"))
54{
56
57 m_xWidget->connect_key_press(LINK(this, FixedTextControl, KeyInputHdl));
58}
59
60IMPL_LINK(FixedTextControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool)
61{
62 return ChildKeyInput(rKEvt);
63}
64
66
68{
69 m_xWidget.reset();
71}
72
74 const Reference<XComponentContext>& rxContext, const Reference<XFrame>& rFrame,
75 ToolBox* pToolbar, ToolBoxItemId nID, const OUString& aCommand)
76 : ComplexToolbarController(rxContext, rFrame, pToolbar, nID, aCommand)
77{
79 m_xToolbar->SetItemWindow(m_nID, m_pFixedTextControl);
80 m_xToolbar->SetItemBits(m_nID, ToolBoxItemBits::AUTOSIZE | m_xToolbar->GetItemBits(m_nID));
81}
82
84{
85 SolarMutexGuard aSolarMutexGuard;
86 m_xToolbar->SetItemWindow(m_nID, nullptr);
87 m_pFixedTextControl.disposeAndClear();
89}
90
91Sequence<PropertyValue> FixedTextToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
92{
93 const OUString aSelectedText = m_pFixedTextControl->get_label();
94
95 // Add key modifier to argument list
96 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("KeyModifier", KeyModifier),
97 comphelper::makePropertyValue("Text", aSelectedText) };
98 return aArgs;
99}
100
102 const css::frame::ControlCommand& rControlCommand)
103{
104 SolarMutexGuard aSolarMutexGuard;
105
106 if (rControlCommand.Command != "SetText")
107 return;
108
109 for (const NamedValue& rArg : rControlCommand.Arguments)
110 {
111 if (rArg.Name == "Text")
112 {
113 OUString aText;
114 rArg.Value >>= aText;
115 m_pFixedTextControl->set_label(aText);
116 m_pFixedTextControl->SetSizePixel(m_pFixedTextControl->get_preferred_size());
117
118 // send notification
119 notifyTextChanged(aText);
120 break;
121 }
122 }
123}
124
125} // namespace
126
127/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
virtual void dispose() override
void InitControlBase(weld::Widget *pWidget)
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void SAL_CALL dispose() override
void set_label(const OUString &rLabel)
DECL_LINK(KeyInputHdl, const ::KeyEvent &, bool)
std::unique_ptr< weld::Label > m_xWidget
virtual css::uno::Sequence< css::beans::PropertyValue > getExecuteArgs(sal_Int16 KeyModifier) const override
FixedTextToolbarController(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rFrame, ToolBox *pToolBar, ToolBoxItemId nID, const OUString &aCommand)
virtual void executeControlCommand(const css::frame::ControlCommand &rControlCommand) override
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPL_LINK(WindowCommandDispatch, impl_notifyCommand, VclWindowEvent &, rEvent, void)
OUString aCommand