diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-07-22 17:09:54 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-07-22 22:17:34 +0200 |
commit | e3bf5b17bf4b8c8a7abb2c524d0f0da34295766c (patch) | |
tree | 9b715ff390b89a4695bd029aea7daaf5d3a00e35 /svx | |
parent | 2943666a7737d57e4307a24e08b8fd000f50e6d1 (diff) |
split SvxFmAbsRecWin up to make a reusable piece
Change-Id: I3c9992d39f7dd45ac354b8e4087bacfd9715b234
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99246
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx')
-rw-r--r-- | svx/Library_svxcore.mk | 1 | ||||
-rw-r--r-- | svx/source/form/recorditemwindow.cxx | 89 | ||||
-rw-r--r-- | svx/source/form/tbxform.cxx | 66 | ||||
-rw-r--r-- | svx/source/inc/tbxform.hxx | 16 |
4 files changed, 95 insertions, 77 deletions
diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index 73d22cafee6c..bd9cf307393b 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -469,6 +469,7 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/form/navigatortree \ svx/source/form/navigatortreemodel \ svx/source/form/ParseContext \ + svx/source/form/recorditemwindow \ svx/source/form/sdbdatacolumn \ svx/source/form/sqlparserclient \ svx/source/form/typemap \ diff --git a/svx/source/form/recorditemwindow.cxx b/svx/source/form/recorditemwindow.cxx new file mode 100644 index 000000000000..26920ee2a42f --- /dev/null +++ b/svx/source/form/recorditemwindow.cxx @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <vcl/event.hxx> +#include <tbxform.hxx> + +RecordItemWindow::RecordItemWindow(vcl::Window* pParent) + : InterimItemWindow(pParent, "svx/ui/absrecbox.ui", "AbsRecBox") + , m_xWidget(m_xBuilder->weld_entry("entry")) +{ + InitControlBase(m_xWidget.get()); + + m_xWidget->connect_key_press(LINK(this, RecordItemWindow, KeyInputHdl)); + m_xWidget->connect_activate(LINK(this, RecordItemWindow, ActivatedHdl)); + m_xWidget->connect_focus_out(LINK(this, RecordItemWindow, FocusOutHdl)); + + SetSizePixel(m_xWidget->get_preferred_size()); +} + +void RecordItemWindow::dispose() +{ + m_xWidget.reset(); + InterimItemWindow::dispose(); +} + +RecordItemWindow::~RecordItemWindow() { disposeOnce(); } + +void RecordItemWindow::FirePosition(bool _bForce) +{ + if (!_bForce && !m_xWidget->get_value_changed_from_saved()) + return; + + sal_Int64 nRecord = m_xWidget->get_text().toInt64(); + if (nRecord < 1) + nRecord = 1; + + PositionFired(nRecord); + + m_xWidget->save_value(); +} + +IMPL_LINK_NOARG(RecordItemWindow, FocusOutHdl, weld::Widget&, void) { FirePosition(false); } + +IMPL_LINK(RecordItemWindow, KeyInputHdl, const KeyEvent&, rKEvt, bool) +{ + vcl::KeyCode aCode = rKEvt.GetKeyCode(); + bool bUp = (aCode.GetCode() == KEY_UP); + bool bDown = (aCode.GetCode() == KEY_DOWN); + + if (!aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() && (bUp || bDown)) + { + sal_Int64 nRecord = m_xWidget->get_text().toInt64(); + if (bUp) + ++nRecord; + else + --nRecord; + if (nRecord < 1) + nRecord = 1; + m_xWidget->set_text(OUString::number(nRecord)); + return true; + } + + return ChildKeyInput(rKEvt); +} + +IMPL_LINK_NOARG(RecordItemWindow, ActivatedHdl, weld::Entry&, bool) +{ + if (!m_xWidget->get_text().isEmpty()) + FirePosition(true); + return true; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/form/tbxform.cxx b/svx/source/form/tbxform.cxx index 26ff4ad7a0cf..97aac28af619 100644 --- a/svx/source/form/tbxform.cxx +++ b/svx/source/form/tbxform.cxx @@ -34,39 +34,13 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; SvxFmAbsRecWin::SvxFmAbsRecWin(vcl::Window* pParent, SfxToolBoxControl* pController) - : InterimItemWindow(pParent, "svx/ui/absrecbox.ui", "AbsRecBox") - , m_xWidget(m_xBuilder->weld_entry("entry")) + : RecordItemWindow(pParent) , m_pController(pController) { - InitControlBase(m_xWidget.get()); - - m_xWidget->connect_key_press(LINK(this, SvxFmAbsRecWin, KeyInputHdl)); - m_xWidget->connect_activate(LINK(this, SvxFmAbsRecWin, ActivatedHdl)); - m_xWidget->connect_focus_out(LINK(this, SvxFmAbsRecWin, FocusOutHdl)); - - SetSizePixel(m_xWidget->get_preferred_size()); } -void SvxFmAbsRecWin::dispose() +void SvxFmAbsRecWin::PositionFired(sal_Int64 nRecord) { - m_xWidget.reset(); - InterimItemWindow::dispose(); -} - -SvxFmAbsRecWin::~SvxFmAbsRecWin() -{ - disposeOnce(); -} - -void SvxFmAbsRecWin::FirePosition( bool _bForce ) -{ - if (!_bForce && !m_xWidget->get_value_changed_from_saved()) - return; - - sal_Int64 nRecord = m_xWidget->get_text().toInt64(); - if (nRecord < 1) - nRecord = 1; - SfxInt32Item aPositionParam( FN_PARAM_1, static_cast<sal_Int32>(nRecord) ); Any a; @@ -77,42 +51,6 @@ void SvxFmAbsRecWin::FirePosition( bool _bForce ) m_pController->Dispatch( ".uno:AbsoluteRecord", aArgs ); m_pController->updateStatus(); - - m_xWidget->save_value(); -} - -IMPL_LINK_NOARG(SvxFmAbsRecWin, FocusOutHdl, weld::Widget&, void) -{ - FirePosition( false ); -} - -IMPL_LINK(SvxFmAbsRecWin, KeyInputHdl, const KeyEvent&, rKEvt, bool) -{ - vcl::KeyCode aCode = rKEvt.GetKeyCode(); - bool bUp = (aCode.GetCode() == KEY_UP); - bool bDown = (aCode.GetCode() == KEY_DOWN); - - if (!aCode.IsShift() && !aCode.IsMod1() && !aCode.IsMod2() && (bUp || bDown)) - { - sal_Int64 nRecord = m_xWidget->get_text().toInt64(); - if (bUp) - ++nRecord; - else - --nRecord; - if (nRecord < 1) - nRecord = 1; - m_xWidget->set_text(OUString::number(nRecord)); - return true; - } - - return ChildKeyInput(rKEvt); -} - -IMPL_LINK_NOARG(SvxFmAbsRecWin, ActivatedHdl, weld::Entry&, bool) -{ - if (!m_xWidget->get_text().isEmpty()) - FirePosition( true ); - return true; } SFX_IMPL_TOOLBOX_CONTROL( SvxFmTbxCtlAbsRec, SfxInt32Item ); diff --git a/svx/source/inc/tbxform.hxx b/svx/source/inc/tbxform.hxx index 153fc0c74631..a167b51d42ea 100644 --- a/svx/source/inc/tbxform.hxx +++ b/svx/source/inc/tbxform.hxx @@ -20,25 +20,15 @@ #define INCLUDED_SVX_SOURCE_INC_TBXFORM_HXX #include <sfx2/tbxctrl.hxx> -#include <vcl/InterimItemWindow.hxx> +#include <svx/recorditemwindow.hxx> -class SvxFmAbsRecWin final : public InterimItemWindow +class SvxFmAbsRecWin final : public RecordItemWindow { public: SvxFmAbsRecWin( vcl::Window* _pParent, SfxToolBoxControl* _pController ); - virtual void dispose() override; - virtual ~SvxFmAbsRecWin() override; - - void set_text(const OUString& rText) { m_xWidget->set_text(rText); } private: - std::unique_ptr<weld::Entry> m_xWidget; - - DECL_LINK(KeyInputHdl, const KeyEvent&, bool); - DECL_LINK(ActivatedHdl, weld::Entry&, bool); - DECL_LINK(FocusOutHdl, weld::Widget&, void); // for invalidating our content when losing the focus - - void FirePosition( bool _bForce ); + virtual void PositionFired(sal_Int64 nRecord) override; SfxToolBoxControl* m_pController; }; |