LibreOffice Module dbaccess (master) 1
limitboxcontroller.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
11
12#include <com/sun/star/frame/XDispatchProvider.hpp>
13#include <com/sun/star/frame/XFrame.hpp>
14#include <com/sun/star/beans/PropertyValue.hpp>
15#include <com/sun/star/util/XURLTransformer.hpp>
16
19#include <vcl/event.hxx>
20#include <vcl/svapp.hxx>
21#include <vcl/window.hxx>
24
25#include <core_resource.hxx>
26#include <strings.hrc>
27
28using namespace ::com::sun::star;
29
30namespace
31{
32
34sal_Int64 const aDefLimitAry[] =
35{
36 5,
37 10,
38 20,
39 50
40};
41
42}
43
44namespace dbaui
45{
46
51class LimitBox final : public InterimItemWindow
52{
53public:
55 : InterimItemWindow(pParent, "dbaccess/ui/limitbox.ui", "LimitBox")
56 , m_pControl( pCtrl )
57 , m_xWidget(m_xBuilder->weld_combo_box("limit"))
58 {
60
62
63 m_xWidget->connect_key_press(LINK(this, LimitBox, KeyInputHdl));
64 m_xWidget->connect_entry_activate(LINK(this, LimitBox, ActivateHdl));
65 m_xWidget->connect_changed(LINK(this, LimitBox, ChangeHdl));
66 m_xWidget->connect_focus_out(LINK(this, LimitBox, FocusOutHdl));
67 m_xWidget->set_entry_width_chars(6);
68 SetSizePixel(m_xContainer->get_preferred_size());
69 }
70
71 virtual void dispose() override
72 {
73 m_xWidget.reset();
75 }
76
77 virtual ~LimitBox() override
78 {
80 }
81
82 void set_sensitive(bool bSensitive)
83 {
84 m_xWidget->set_sensitive(bSensitive);
85 }
86
87 void set_value(int nLimit)
88 {
89 if (nLimit < 0)
90 m_xWidget->set_active(0);
91 else
92 m_xWidget->set_entry_text(OUString::number(nLimit));
93 m_xWidget->save_value();
94 }
95
96private:
98 std::unique_ptr<weld::ComboBox> m_xWidget;
99
100 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
101 DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
102 DECL_LINK(ChangeHdl, weld::ComboBox&, void);
103 DECL_LINK(FocusOutHdl, weld::Widget&, void);
104
105 void Apply()
106 {
107 if (!m_xWidget->get_value_changed_from_saved())
108 return;
109 sal_Int64 nLimit;
110 OUString sActiveText = m_xWidget->get_active_text();
111 if (sActiveText == DBA_RES(STR_QUERY_LIMIT_ALL))
112 nLimit = -1;
113 else
114 {
115 nLimit = m_xWidget->get_active_text().toInt64();
116 if (nLimit < 0)
117 nLimit = -1;
118 }
119 set_value(nLimit);
120 m_pControl->dispatchCommand({ comphelper::makePropertyValue("DBLimit.Value", nLimit) });
121 }
122
125 {
126 m_xWidget->freeze();
127 m_xWidget->append_text(DBA_RES(STR_QUERY_LIMIT_ALL));
128 for (auto nIndex : aDefLimitAry)
129 {
130 m_xWidget->append_text(OUString::number(nIndex));
131 }
132 m_xWidget->thaw();
133 }
134};
135
136IMPL_LINK(LimitBox, KeyInputHdl, const KeyEvent&, rKEvt, bool)
137{
138 bool bHandled = false;
139 const sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
140 switch (nCode)
141 {
142 case KEY_ESCAPE:
143 m_xWidget->set_entry_text(m_xWidget->get_saved_value());
144 bHandled = true;
145 break;
146 case KEY_RETURN:
147 {
148 bHandled = ActivateHdl(*m_xWidget);
149 break;
150 }
151 }
152 return bHandled || ChildKeyInput(rKEvt);
153}
154
156{
157 if (!m_xWidget || m_xWidget->has_focus()) // comboboxes can be comprised of multiple widgets, ensure all have lost focus
158 return;
159 Apply();
160}
161
162IMPL_LINK(LimitBox, ChangeHdl, weld::ComboBox&, rComboBox, void)
163{
164 if (rComboBox.changed_by_direct_pick())
165 ActivateHdl(rComboBox);
166}
167
169{
170 GrabFocusToDocument();
171 Apply();
172 return true;
173}
174
176 const uno::Reference< uno::XComponentContext >& rxContext ) :
177 LimitBoxController_Base( rxContext,
178 uno::Reference< frame::XFrame >(),
179 ".uno:DBLimit" ),
180 m_xLimitBox( nullptr )
181{
182}
183
185{
186}
187
189OUString SAL_CALL LimitBoxController::getImplementationName()
190{
191 return "org.libreoffice.comp.dbu.LimitBoxController";
192}
193
194sal_Bool SAL_CALL LimitBoxController::supportsService(const OUString& _rServiceName)
195 {
196 const css::uno::Sequence< OUString > aSupported(getSupportedServiceNames());
197 for (const OUString& s : aSupported)
198 if (s == _rServiceName)
199 return true;
200
201 return false;
202 }
203
204css::uno::Sequence< OUString > SAL_CALL LimitBoxController::getSupportedServiceNames()
205{
206 return { "com.sun.star.frame.ToolbarController" };
207}
208
211{
213
214 SolarMutexGuard aSolarMutexGuard;
215 m_xLimitBox.disposeAndClear();
216}
217
220 const frame::FeatureStateEvent& rEvent )
221{
222 if ( !m_xLimitBox )
223 return;
224
225 SolarMutexGuard aSolarMutexGuard;
226 if ( rEvent.FeatureURL.Path == "DBLimit" )
227 {
228 if ( rEvent.IsEnabled )
229 {
230 m_xLimitBox->set_sensitive(true);
231 sal_Int64 nLimit = 0;
232 if (rEvent.State >>= nLimit)
233 m_xLimitBox->set_value(nLimit);
234 }
235 else
236 m_xLimitBox->set_sensitive(false);
237 }
238}
239
241void SAL_CALL LimitBoxController::execute( sal_Int16 /*KeyModifier*/ )
242{
243}
244
246{
247}
248
250{
251}
252
253uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createPopupWindow()
254{
255 return uno::Reference< awt::XWindow >();
256}
257
258uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createItemWindow(
259 const uno::Reference< awt::XWindow >& xParent )
260{
261 uno::Reference< awt::XWindow > xItemWindow;
262
263 VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( xParent );
264 if ( pParent )
265 {
266 SolarMutexGuard aSolarMutexGuard;
267 m_xLimitBox = VclPtr<LimitBox>::Create(pParent, this);
269 }
270
271 return xItemWindow;
272}
273
275 const uno::Sequence< beans::PropertyValue >& rArgs )
276{
277 uno::Reference< frame::XDispatchProvider > xDispatchProvider( m_xFrame, uno::UNO_QUERY );
278 if ( xDispatchProvider.is() )
279 {
280 util::URL aURL;
281 uno::Reference< frame::XDispatch > xDispatch;
282 uno::Reference< util::XURLTransformer > xURLTransformer = getURLTransformer();
283
284 aURL.Complete = ".uno:DBLimit";
285 xURLTransformer->parseStrict( aURL );
286 xDispatch = xDispatchProvider->queryDispatch( aURL, OUString(), 0 );
287 if ( xDispatch.is() )
288 xDispatch->dispatch( aURL, rArgs );
289 }
290}
291
292} // dbaui namespace
293
294extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
296 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const& )
297{
298 return cppu::acquire(new ::dbaui::LimitBoxController(context));
299}
300
301/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Image > m_xWidget
css::uno::Reference< css::lang::XComponent > m_xFrame
virtual void dispose() override
std::unique_ptr< weld::Builder > m_xBuilder
std::unique_ptr< weld::Container > m_xContainer
void InitControlBase(weld::Widget *pWidget)
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
static VclPtr< reference_type > Create(Arg &&... arg)
virtual ~LimitBoxController() override
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override
virtual void SAL_CALL dispose() override
XComponent.
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow(const css::uno::Reference< css::awt::XWindow > &Parent) override
virtual void SAL_CALL doubleClick() override
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
XStatusListener.
virtual void SAL_CALL execute(sal_Int16 KeyModifier) override
XToolbarController.
LimitBoxController(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
VclPtr< LimitBox > m_xLimitBox
void dispatchCommand(const css::uno::Sequence< css::beans::PropertyValue > &rArgs)
virtual void SAL_CALL click() override
Input box to add limit to an SQL query (maximum number of result's rows) This box is reachable on the...
virtual void dispose() override
DECL_LINK(KeyInputHdl, const KeyEvent &, bool)
DECL_LINK(FocusOutHdl, weld::Widget &, void)
virtual ~LimitBox() override
DECL_LINK(ActivateHdl, weld::ComboBox &, bool)
DECL_LINK(ChangeHdl, weld::ComboBox &, void)
std::unique_ptr< weld::ComboBox > m_xWidget
LimitBoxController * m_pControl
void LoadDefaultLimits()
Initialize entries.
LimitBox(vcl::Window *pParent, LimitBoxController *pCtrl)
void set_value(int nLimit)
void set_sensitive(bool bSensitive)
virtual void SAL_CALL dispose() override
virtual void SetSizePixel(const Size &rNewSize)
#define DBA_RES(id)
Reference< XDispatch > xDispatch
URL aURL
Definition: intercept.cxx:87
sal_Int32 nIndex
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_ESCAPE
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * org_libreoffice_comp_dbu_LimitBoxController_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
IMPL_LINK_NOARG(OApplicationController, OnClipboardChanged, TransferableDataHelper *, void)
IMPL_LINK(OApplicationController, OnSelectContainer, void *, _pType, void)
cppu::ImplInheritanceHelper< ::svt::ToolboxController, css::lang::XServiceInfo > LimitBoxController_Base
A ToolboxController to paste LimitBox onto the Query Design Toolbar It is communicating with querycon...
unsigned char sal_Bool