LibreOffice Module framework (master) 1
edittoolbarcontroller.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
22#include <com/sun/star/beans/PropertyValue.hpp>
23
27#include <vcl/svapp.hxx>
28#include <vcl/toolbox.hxx>
29#include <vcl/event.hxx>
30
31using namespace ::com::sun::star;
32using namespace css::uno;
33using namespace css::beans;
34using namespace css::lang;
35using namespace css::frame;
36using namespace css::util;
37
38namespace framework
39{
40
41// Wrapper class to notify controller about events from edit.
42// Unfortunaltly the events are notified through virtual methods instead
43// of Listeners.
44
45class EditControl final : public InterimItemWindow
46{
47public:
48 EditControl(vcl::Window* pParent, EditToolbarController* pEditToolbarController);
49 virtual ~EditControl() override;
50 virtual void dispose() override;
51
52 OUString get_text() const { return m_xWidget->get_text(); }
53 void set_text(const OUString& rText) { m_xWidget->set_text(rText); }
54
55private:
56 std::unique_ptr<weld::Entry> m_xWidget;
58
59 DECL_LINK(FocusInHdl, weld::Widget&, void);
60 DECL_LINK(FocusOutHdl, weld::Widget&, void);
61 DECL_LINK(ModifyHdl, weld::Entry&, void);
62 DECL_LINK(ActivateHdl, weld::Entry&, bool);
63 DECL_LINK(KeyInputHdl, const ::KeyEvent&, bool);
64};
65
67 : InterimItemWindow(pParent, "svt/ui/editcontrol.ui", "EditControl")
68 , m_xWidget(m_xBuilder->weld_entry("entry"))
69 , m_pEditToolbarController(pEditToolbarController)
70{
71 OUString sEmpty;
72 m_xWidget->set_help_id(sEmpty);
73 m_xContainer->set_help_id(sEmpty);
74
76
77 m_xWidget->connect_focus_in(LINK(this, EditControl, FocusInHdl));
78 m_xWidget->connect_focus_out(LINK(this, EditControl, FocusOutHdl));
79 m_xWidget->connect_changed(LINK(this, EditControl, ModifyHdl));
80 m_xWidget->connect_activate(LINK(this, EditControl, ActivateHdl));
81 m_xWidget->connect_key_press(LINK(this, EditControl, KeyInputHdl));
82
84}
85
86IMPL_LINK(EditControl, KeyInputHdl, const ::KeyEvent&, rKEvt, bool)
87{
88 return ChildKeyInput(rKEvt);
89}
90
92{
94}
95
97{
99 m_xWidget.reset();
101}
102
104{
105 if (m_pEditToolbarController)
106 m_pEditToolbarController->Modify();
107}
108
110{
111 if (m_pEditToolbarController)
112 m_pEditToolbarController->GetFocus();
113}
114
116{
117 if ( m_pEditToolbarController )
118 m_pEditToolbarController->LoseFocus();
119}
120
122{
123 if (m_pEditToolbarController)
124 m_pEditToolbarController->Activate();
125 return true;
126}
127
129 const Reference< XComponentContext >& rxContext,
130 const Reference< XFrame >& rFrame,
131 ToolBox* pToolbar,
132 ToolBoxItemId nID,
133 sal_Int32 nWidth,
134 const OUString& aCommand ) :
135 ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
136 , m_pEditControl( nullptr )
137{
139 if ( nWidth == 0 )
140 nWidth = 100;
141
142 // EditControl ctor has set a suitable height already
143 auto nHeight = m_pEditControl->GetSizePixel().Height();
144
145 m_pEditControl->SetSizePixel( ::Size( nWidth, nHeight ));
146 m_xToolbar->SetItemWindow( m_nID, m_pEditControl );
147}
148
150{
151}
152
154{
155 SolarMutexGuard aSolarMutexGuard;
156
157 m_xToolbar->SetItemWindow( m_nID, nullptr );
159
161}
162
163Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
164{
165 OUString aSelectedText = m_pEditControl->get_text();
166
167 // Add key modifier to argument list
168 Sequence<PropertyValue> aArgs{ comphelper::makePropertyValue("KeyModifier", KeyModifier),
169 comphelper::makePropertyValue("Text", aSelectedText) };
170 return aArgs;
171}
172
174{
176}
177
179{
181}
182
184{
186}
187
189{
190 // Call execute only with non-empty text
191 if (!m_pEditControl->get_text().isEmpty())
192 execute(0);
193}
194
195void EditToolbarController::executeControlCommand( const css::frame::ControlCommand& rControlCommand )
196{
197 if ( !rControlCommand.Command.startsWith( "SetText" ))
198 return;
199
200 for ( const NamedValue& rArg : rControlCommand.Arguments )
201 {
202 if ( rArg.Name.startsWith( "Text" ))
203 {
204 OUString aText;
205 rArg.Value >>= aText;
206 m_pEditControl->set_text(aText);
207
208 // send notification
209 notifyTextChanged( aText );
210 break;
211 }
212 }
213}
214
215} // namespace
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
virtual void dispose() override
std::unique_ptr< weld::Container > m_xContainer
void InitControlBase(weld::Widget *pWidget)
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void SAL_CALL dispose() override
virtual void SAL_CALL execute(sal_Int16 KeyModifier) override
std::unique_ptr< weld::Entry > m_xWidget
EditControl(vcl::Window *pParent, EditToolbarController *pEditToolbarController)
DECL_LINK(ModifyHdl, weld::Entry &, void)
void set_text(const OUString &rText)
DECL_LINK(FocusInHdl, weld::Widget &, void)
DECL_LINK(KeyInputHdl, const ::KeyEvent &, bool)
virtual void dispose() override
EditToolbarController * m_pEditToolbarController
DECL_LINK(FocusOutHdl, weld::Widget &, void)
DECL_LINK(ActivateHdl, weld::Entry &, bool)
virtual ~EditControl() override
virtual css::uno::Sequence< css::beans::PropertyValue > getExecuteArgs(sal_Int16 KeyModifier) const override
virtual void SAL_CALL dispose() override
EditToolbarController(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &rFrame, ToolBox *pToolBar, ToolBoxItemId nID, sal_Int32 nWidth, const OUString &aCommand)
virtual void executeControlCommand(const css::frame::ControlCommand &rControlCommand) override
virtual void SetSizePixel(const Size &rNewSize)
Size get_preferred_size() const
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
IMPL_LINK(WindowCommandDispatch, impl_notifyCommand, VclWindowEvent &, rEvent, void)
IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone *, void)
asynchronous callback @descr We start all actions inside this object asynchronous (see comments there...
const OUString sEmpty
OUString aCommand