diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-02-06 10:59:19 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-02-06 18:17:02 +0100 |
commit | 97a5da96159f28de0b846de7dd94d2880251e8b3 (patch) | |
tree | 091f4334ff184047376240a4deb5bfb9b0da5b1e /svx/source | |
parent | bf2f1adfd2e4725518147657c6b57eb5697a29d5 (diff) |
weld SvxMetricField
split off SdPagesField as its not really a MetricSpinButton and can
be a SpinButton with a custom output function.
while I'm at it use ngettext to provide better plurals for the output.
Change-Id: Idc9ce0513c9fce60c8713c7361fd40f0dbd01f64
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88100
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'svx/source')
-rw-r--r-- | svx/source/inc/InterimItemWindow.hxx | 35 | ||||
-rw-r--r-- | svx/source/sidebar/paragraph/ParaSpacingWindow.hxx | 2 | ||||
-rw-r--r-- | svx/source/tbxctrls/itemwin.cxx | 118 | ||||
-rw-r--r-- | svx/source/tbxctrls/linewidthctrl.cxx | 13 | ||||
-rw-r--r-- | svx/source/tbxctrls/tbunocontroller.cxx | 2 |
5 files changed, 61 insertions, 109 deletions
diff --git a/svx/source/inc/InterimItemWindow.hxx b/svx/source/inc/InterimItemWindow.hxx deleted file mode 100644 index 715cf41fc020..000000000000 --- a/svx/source/inc/InterimItemWindow.hxx +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * 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/. - */ - -#pragma once - -#include <vcl/layout.hxx> - -class InterimItemWindow : public Control -{ -public: - virtual ~InterimItemWindow() override; - virtual void dispose() override; - - virtual void Resize() override; - virtual Size GetOptimalSize() const override; - -protected: - InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription, const OString& rID); - - // pass keystrokes from our child window through this to handle focus changes correctly - // returns true if keystroke is consumed - bool ChildKeyInput(const KeyEvent& rKEvt); - - std::unique_ptr<weld::Builder> m_xBuilder; - VclPtr<vcl::Window> m_xVclContentArea; - std::unique_ptr<weld::Container> m_xContainer; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx b/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx index af103d5d1f8a..b09f5addf8c6 100644 --- a/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx +++ b/svx/source/sidebar/paragraph/ParaSpacingWindow.hxx @@ -21,8 +21,8 @@ #include <editeng/ulspitem.hxx> #include <vcl/EnumContext.hxx> +#include <svx/InterimItemWindow.hxx> #include <svx/relfld.hxx> -#include <InterimItemWindow.hxx> using namespace com::sun::star; diff --git a/svx/source/tbxctrls/itemwin.cxx b/svx/source/tbxctrls/itemwin.cxx index 0baf9407b01e..e0ac4cdbfb8d 100644 --- a/svx/source/tbxctrls/itemwin.cxx +++ b/svx/source/tbxctrls/itemwin.cxx @@ -58,41 +58,56 @@ using namespace ::com::sun::star::beans; SvxMetricField::SvxMetricField( vcl::Window* pParent, const Reference< XFrame >& rFrame ) - : MetricField(pParent, WB_BORDER | WB_SPIN | WB_REPEAT) - , aCurTxt() + : InterimItemWindow(pParent, "svx/ui/metricfieldbox.ui", "MetricFieldBox") + , m_xWidget(m_xBuilder->weld_metric_spin_button("metricfield", FieldUnit::MM)) + , nCurValue(0) , ePoolUnit(MapUnit::MapCM) + , eDlgUnit(SfxModule::GetModuleFieldUnit(rFrame)) , mxFrame(rFrame) { - Size aSize( CalcMinimumSize() ); - SetSizePixel( aSize ); - aLogicalSize = PixelToLogic(aSize, MapMode(MapUnit::MapAppFont)); - SetUnit( FieldUnit::MM ); - SetDecimalDigits( 2 ); - SetMax( 5000 ); - SetMin( 0 ); - SetLast( 5000 ); - SetFirst( 0 ); - - eDlgUnit = SfxModule::GetModuleFieldUnit( mxFrame ); - SetFieldUnit( *this, eDlgUnit ); - Show(); + m_xWidget->set_range(0, 5000, FieldUnit::NONE); + m_xWidget->connect_value_changed(LINK(this, SvxMetricField, ModifyHdl)); + m_xWidget->connect_focus_in(LINK(this, SvxMetricField, FocusInHdl)); + m_xWidget->get_widget().connect_key_press(LINK(this, SvxMetricField, KeyInputHdl)); + + SetFieldUnit(*m_xWidget, eDlgUnit); + + SetSizePixel(m_xWidget->get_preferred_size()); +} + +void SvxMetricField::dispose() +{ + m_xWidget.reset(); + InterimItemWindow::dispose(); +} + +SvxMetricField::~SvxMetricField() +{ + disposeOnce(); +} + +void SvxMetricField::set_sensitive(bool bSensitive) +{ + Enable(bSensitive); + m_xWidget->set_sensitive(bSensitive); + if (!bSensitive) + m_xWidget->set_text(""); } void SvxMetricField::Update( const XLineWidthItem* pItem ) { if ( pItem ) { - if ( pItem->GetValue() != GetCoreValue( *this, ePoolUnit ) ) - SetMetricValue( *this, pItem->GetValue(), ePoolUnit ); + if (pItem->GetValue() != GetCoreValue(*m_xWidget, ePoolUnit)) + SetMetricValue(*m_xWidget, pItem->GetValue(), ePoolUnit); } else - SetText( "" ); + m_xWidget->set_text(""); } -void SvxMetricField::Modify() +IMPL_LINK_NOARG(SvxMetricField, ModifyHdl, weld::MetricSpinButton&, void) { - MetricField::Modify(); - long nTmp = GetCoreValue( *this, ePoolUnit ); + auto nTmp = GetCoreValue(*m_xWidget, ePoolUnit); XLineWidthItem aLineWidthItem( nTmp ); Any a; @@ -126,59 +141,30 @@ void SvxMetricField::RefreshDlgUnit() if ( eDlgUnit != eTmpUnit ) { eDlgUnit = eTmpUnit; - SetFieldUnit( *this, eDlgUnit ); + SetFieldUnit(*m_xWidget, eDlgUnit); } } -bool SvxMetricField::PreNotify( NotifyEvent& rNEvt ) +IMPL_LINK_NOARG(SvxMetricField, FocusInHdl, weld::Widget&, void) { - MouseNotifyEvent nType = rNEvt.GetType(); - - if ( MouseNotifyEvent::MOUSEBUTTONDOWN == nType || MouseNotifyEvent::GETFOCUS == nType ) - aCurTxt = GetText(); - - return MetricField::PreNotify( rNEvt ); + nCurValue = m_xWidget->get_value(FieldUnit::NONE); } - -bool SvxMetricField::EventNotify( NotifyEvent& rNEvt ) +IMPL_LINK(SvxMetricField, KeyInputHdl, const KeyEvent&, rKEvt, bool) { - bool bHandled = MetricField::EventNotify( rNEvt ); + bool bHandled = false; - if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT ) - { - const KeyEvent* pKEvt = rNEvt.GetKeyEvent(); - const vcl::KeyCode& rKey = pKEvt->GetKeyCode(); - SfxViewShell* pSh = SfxViewShell::Current(); - - if ( rKey.GetModifier() && rKey.GetGroup() != KEYGROUP_CURSOR && pSh ) - (void)pSh->KeyInput( *pKEvt ); - else - { - bool bHandledInside = false; - - switch ( rKey.GetCode() ) - { - case KEY_RETURN: - Reformat(); - bHandledInside = true; - break; - - case KEY_ESCAPE: - SetText( aCurTxt ); - bHandled = true; - break; - } + sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); - if ( bHandledInside ) - { - bHandled = true; - Modify(); - ReleaseFocus_Impl(); - } - } + if (nCode == KEY_ESCAPE) + { + m_xWidget->set_value(nCurValue, FieldUnit::NONE); + ModifyHdl(*m_xWidget); + ReleaseFocus_Impl(); + bHandled = true; } - return bHandled; + + return bHandled || ChildKeyInput(rKEvt); } void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt ) @@ -186,10 +172,10 @@ void SvxMetricField::DataChanged( const DataChangedEvent& rDCEvt ) if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) ) { - SetSizePixel(LogicToPixel(aLogicalSize, MapMode(MapUnit::MapAppFont))); + SetSizePixel(m_xWidget->get_preferred_size()); } - MetricField::DataChanged( rDCEvt ); + InterimItemWindow::DataChanged( rDCEvt ); } SvxFillTypeBox::SvxFillTypeBox( vcl::Window* pParent ) : diff --git a/svx/source/tbxctrls/linewidthctrl.cxx b/svx/source/tbxctrls/linewidthctrl.cxx index 0a6d75446819..61f48a0293e5 100644 --- a/svx/source/tbxctrls/linewidthctrl.cxx +++ b/svx/source/tbxctrls/linewidthctrl.cxx @@ -83,12 +83,11 @@ void SvxLineWidthToolBoxControl::StateChanged( { if ( eState == SfxItemState::DISABLED ) { - pFld->Disable(); - pFld->SetText( "" ); + pFld->set_sensitive(false); } else { - pFld->Enable(); + pFld->set_sensitive(true); if ( eState == SfxItemState::DEFAULT ) { @@ -107,10 +106,12 @@ void SvxLineWidthToolBoxControl::StateChanged( } } - -VclPtr<vcl::Window> SvxLineWidthToolBoxControl::CreateItemWindow( vcl::Window *pParent ) +VclPtr<vcl::Window> SvxLineWidthToolBoxControl::CreateItemWindow(vcl::Window *pParent) { - return VclPtr<SvxMetricField>::Create( pParent, m_xFrame ).get(); + VclPtr<SvxMetricField> pWindow = VclPtr<SvxMetricField>::Create(pParent, m_xFrame); + pWindow->Show(); + + return pWindow; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/tbxctrls/tbunocontroller.cxx b/svx/source/tbxctrls/tbunocontroller.cxx index 125543a55e88..fda45184209f 100644 --- a/svx/source/tbxctrls/tbunocontroller.cxx +++ b/svx/source/tbxctrls/tbunocontroller.cxx @@ -41,7 +41,7 @@ #include <sfx2/sidebar/SidebarToolBox.hxx> #include <boost/property_tree/ptree.hpp> -#include <InterimItemWindow.hxx> +#include <svx/InterimItemWindow.hxx> using namespace ::com::sun::star; |