diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-02-17 16:22:49 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-02-17 21:34:53 +0100 |
commit | d031002b326c4ba1c012a152beb53f08ee1354ea (patch) | |
tree | f3faab7686fc9377dc84c90e1ae029188a84e17e /dbaccess/source/ui/querydesign | |
parent | 2cdab992c6faeb98a1cbef7615f4cc7ce0d3f04d (diff) |
weld LimitBox Item Window
also merge dbaui::LimitBox with dbaui::LimitBoxImpl
Change-Id: Idd01e71d6afe817971223b46611c622a82883304
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88870
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'dbaccess/source/ui/querydesign')
-rw-r--r-- | dbaccess/source/ui/querydesign/LimitBox.cxx | 110 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/limitboxcontroller.cxx | 200 | ||||
-rw-r--r-- | dbaccess/source/ui/querydesign/limitboxcontroller.hxx | 4 |
3 files changed, 148 insertions, 166 deletions
diff --git a/dbaccess/source/ui/querydesign/LimitBox.cxx b/dbaccess/source/ui/querydesign/LimitBox.cxx deleted file mode 100644 index 89aa4f02a7c7..000000000000 --- a/dbaccess/source/ui/querydesign/LimitBox.cxx +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- 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/. - */ - -#include <LimitBox.hxx> -#include <strings.hrc> -#include <core_resource.hxx> - -#define ALL_STRING DBA_RES(STR_QUERY_LIMIT_ALL) -#define ALL_INT -1 - -namespace global{ - -/// Default values -sal_Int64 const aDefLimitAry[] = -{ - 5, - 10, - 20, - 50 -}; - -} - -namespace dbaui -{ - - -LimitBox::LimitBox( vcl::Window* pParent ) - : NumericBox( pParent, WB_DROPDOWN | WB_VSCROLL ) -{ - SetShowTrailingZeros( false ); - SetDecimalDigits( 0 ); - SetMin( -1 ); - SetMax( SAL_MAX_INT64 ); - LoadDefaultLimits(); - - Size aSize( - GetSizePixel().Width(), - CalcWindowSizePixel(GetEntryCount() + 1) ); - SetSizePixel(aSize); -} - -OUString LimitBox::CreateFieldText( sal_Int64 nValue ) const -{ - if( nValue == ALL_INT ) - return ALL_STRING; - else - return NumericBox::CreateFieldText( nValue ); -} - -void LimitBox::Reformat() -{ - - if( GetText() == ALL_STRING ) - { - SetValue( ALL_INT ); - } - ///Reformat only when text is not All - else - { - ///Not allow user to type in -1 - if( GetText() == "-1" ) - { - Undo(); - } - else - NumericBox::Reformat(); - } -} - -void LimitBox::ReformatAll() -{ - ///First entry is All, which do not need numeric reformat - if ( GetEntryCount() > 0 ) - { - RemoveEntryAt( 0 ); - NumericBox::ReformatAll(); - InsertValue( ALL_INT, 0); - } - else - { - NumericBox::ReformatAll(); - } -} - -Size LimitBox::GetOptimalSize() const -{ - return CalcBlockSize(10,1); -} - -///Initialize entries -void LimitBox::LoadDefaultLimits() -{ - InsertValue( ALL_INT ); - - for(long nIndex : global::aDefLimitAry) - { - InsertValue( nIndex ); - } -} - -} ///dbaui namespace - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dbaccess/source/ui/querydesign/limitboxcontroller.cxx b/dbaccess/source/ui/querydesign/limitboxcontroller.cxx index c07e093869d3..ffcee79520d7 100644 --- a/dbaccess/source/ui/querydesign/limitboxcontroller.cxx +++ b/dbaccess/source/ui/querydesign/limitboxcontroller.cxx @@ -14,6 +14,7 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/util/XURLTransformer.hpp> +#include <sfx2/InterimItemWindow.hxx> #include <vcl/event.hxx> #include <vcl/svapp.hxx> #include <vcl/window.hxx> @@ -21,77 +22,171 @@ #include <cppuhelper/queryinterface.hxx> #include <comphelper/processfactory.hxx> -#include <LimitBox.hxx> +#include <core_resource.hxx> #include <dbu_reghelper.hxx> - +#include <strings.hrc> using namespace ::com::sun::star; -namespace dbaui +namespace { -class LimitBoxImpl: public LimitBox +/// Default values +sal_Int64 const aDefLimitAry[] = { - public: - LimitBoxImpl( vcl::Window* pParent, LimitBoxController* pCtrl ); + 5, + 10, + 20, + 50 +}; - virtual bool EventNotify( NotifyEvent& rNEvt ) override; +} - private: - LimitBoxController* m_pControl; -}; +namespace dbaui +{ -LimitBoxImpl::LimitBoxImpl( vcl::Window* pParent, LimitBoxController* pCtrl ) - : LimitBox( pParent ) - , m_pControl( pCtrl ) +/** + * Input box to add limit to an SQL query (maximum number of result's rows) + * This box is reachable on the Query Design Toolbar + */ +class LimitBox final : public InterimItemWindow { -} +public: + LimitBox(vcl::Window* pParent, LimitBoxController* pCtrl) + : InterimItemWindow(pParent, "dbaccess/ui/limitbox.ui", "LimitBox") + , m_pControl( pCtrl ) + , m_xWidget(m_xBuilder->weld_combo_box("limit")) + { + LoadDefaultLimits(); + + m_xWidget->connect_key_press(LINK(this, LimitBox, KeyInputHdl)); + m_xWidget->connect_entry_activate(LINK(this, LimitBox, ActivateHdl)); + m_xWidget->connect_changed(LINK(this, LimitBox, ChangeHdl)); + m_xWidget->connect_focus_out(LINK(this, LimitBox, FocusOutHdl)); + m_xWidget->set_entry_width_chars(6); + SetSizePixel(m_xContainer->get_preferred_size()); + } + + virtual void dispose() override + { + m_xWidget.reset(); + InterimItemWindow::dispose(); + } + + virtual ~LimitBox() override + { + disposeOnce(); + } + + void set_sensitive(bool bSensitive) + { + m_xWidget->set_sensitive(bSensitive); + } + + virtual void GetFocus() override + { + if (m_xWidget) + m_xWidget->grab_focus(); + InterimItemWindow::GetFocus(); + } + + void set_value(int nLimit) + { + if (nLimit < 0) + m_xWidget->set_active(0); + else + m_xWidget->set_entry_text(OUString::number(nLimit)); + m_xWidget->save_value(); + } -bool LimitBoxImpl::EventNotify( NotifyEvent& rNEvt ) +private: + LimitBoxController* m_pControl; + std::unique_ptr<weld::ComboBox> m_xWidget; + + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + DECL_LINK(ActivateHdl, weld::ComboBox&, bool); + DECL_LINK(ChangeHdl, weld::ComboBox&, void); + DECL_LINK(FocusOutHdl, weld::Widget&, void); + + void Apply() + { + if (!m_xWidget->get_value_changed_from_saved()) + return; + uno::Sequence< beans::PropertyValue > aArgs( 1 ); + aArgs[0].Name = "DBLimit.Value"; + sal_Int64 nLimit; + OUString sActiveText = m_xWidget->get_active_text(); + if (sActiveText == DBA_RES(STR_QUERY_LIMIT_ALL)) + nLimit = -1; + else + { + nLimit = m_xWidget->get_active_text().toInt64(); + if (nLimit < 0) + nLimit = -1; + } + set_value(nLimit); + aArgs[0].Value <<= nLimit; + m_pControl->dispatchCommand( aArgs ); + } + + ///Initialize entries + void LoadDefaultLimits() + { + m_xWidget->freeze(); + m_xWidget->append_text(DBA_RES(STR_QUERY_LIMIT_ALL)); + for (auto nIndex : aDefLimitAry) + { + m_xWidget->append_text(OUString::number(nIndex)); + } + m_xWidget->thaw(); + } +}; + +IMPL_LINK(LimitBox, KeyInputHdl, const KeyEvent&, rKEvt, bool) { bool bHandled = false; - switch ( rNEvt.GetType() ) + const sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); + switch (nCode) { - case MouseNotifyEvent::LOSEFOCUS: - { - bHandled = LimitBox::EventNotify(rNEvt); - uno::Sequence< beans::PropertyValue > aArgs( 1 ); - aArgs[0].Name = "DBLimit.Value"; - aArgs[0].Value <<= GetValue(); - m_pControl->dispatchCommand( aArgs ); + case KEY_ESCAPE: + m_xWidget->set_entry_text(m_xWidget->get_saved_value()); + bHandled = true; break; - } - case MouseNotifyEvent::KEYINPUT: + case KEY_RETURN: { - const sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode(); - switch ( nCode ) - { - case KEY_ESCAPE: - Undo(); - [[fallthrough]]; - case KEY_RETURN: - GrabFocusToDocument(); - bHandled = true; - break; - case KEY_TAB: - Select(); - break; - } + bHandled = ActivateHdl(*m_xWidget); break; } - default: - break; } - return bHandled || LimitBox::EventNotify(rNEvt); + return bHandled || ChildKeyInput(rKEvt); } +IMPL_LINK_NOARG(LimitBox, FocusOutHdl, weld::Widget&, void) +{ + if (!m_xWidget || m_xWidget->has_focus()) // comboboxes can be comprised of multiple widgets, ensure all have lost focus + return; + Apply(); +} + +IMPL_LINK(LimitBox, ChangeHdl, weld::ComboBox&, rComboBox, void) +{ + if (rComboBox.changed_by_direct_pick()) + ActivateHdl(rComboBox); +} + +IMPL_LINK_NOARG(LimitBox, ActivateHdl, weld::ComboBox&, bool) +{ + GrabFocusToDocument(); + Apply(); + return true; +} LimitBoxController::LimitBoxController( const uno::Reference< uno::XComponentContext >& rxContext ) : svt::ToolboxController( rxContext, uno::Reference< frame::XFrame >(), ".uno:DBLimit" ), - m_pLimitBox( nullptr ) + m_xLimitBox( nullptr ) { } @@ -137,29 +232,27 @@ void SAL_CALL LimitBoxController::dispose() svt::ToolboxController::dispose(); SolarMutexGuard aSolarMutexGuard; - m_pLimitBox.disposeAndClear(); + m_xLimitBox.disposeAndClear(); } /// XStatusListener void SAL_CALL LimitBoxController::statusChanged( const frame::FeatureStateEvent& rEvent ) { - if ( m_pLimitBox ) + if ( m_xLimitBox ) { SolarMutexGuard aSolarMutexGuard; if ( rEvent.FeatureURL.Path == "DBLimit" ) { if ( rEvent.IsEnabled ) { - m_pLimitBox->Enable(); + m_xLimitBox->set_sensitive(true); sal_Int64 nLimit = 0; - if ( rEvent.State >>= nLimit ) - { - m_pLimitBox->SetValue( nLimit ); - } + if (rEvent.State >>= nLimit) + m_xLimitBox->set_value(nLimit); } else - m_pLimitBox->Disable(); + m_xLimitBox->set_sensitive(false); } } } @@ -191,9 +284,8 @@ uno::Reference< awt::XWindow > SAL_CALL LimitBoxController::createItemWindow( if ( pParent ) { SolarMutexGuard aSolarMutexGuard; - m_pLimitBox = VclPtr<LimitBoxImpl>::Create(pParent, this); - m_pLimitBox->SetSizePixel(m_pLimitBox->CalcBlockSize(6,1)); - xItemWindow = VCLUnoHelper::GetInterface( m_pLimitBox ); + m_xLimitBox = VclPtr<LimitBox>::Create(pParent, this); + xItemWindow = VCLUnoHelper::GetInterface(m_xLimitBox); } return xItemWindow; diff --git a/dbaccess/source/ui/querydesign/limitboxcontroller.hxx b/dbaccess/source/ui/querydesign/limitboxcontroller.hxx index 721b9cc56ef7..49ee2afae411 100644 --- a/dbaccess/source/ui/querydesign/limitboxcontroller.hxx +++ b/dbaccess/source/ui/querydesign/limitboxcontroller.hxx @@ -20,7 +20,7 @@ namespace dbaui { -class LimitBoxImpl; +class LimitBox; /** * A ToolboxController to paste LimitBox onto the Query Design Toolbar @@ -66,7 +66,7 @@ class LimitBoxController: public svt::ToolboxController, using svt::ToolboxController::dispatchCommand; private: - VclPtr<LimitBoxImpl> m_pLimitBox; + VclPtr<LimitBox> m_xLimitBox; }; } ///dbaui namespace |