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