diff options
author | Pranam Lashkari <lpranam@collabora.com> | 2020-12-20 17:46:44 +0530 |
---|---|---|
committer | Pranam Lashkari <lpranam@collabora.com> | 2020-12-30 09:03:20 +0100 |
commit | 2dea8fd43fa4080b3d048415bbbf9a9f7e93b70a (patch) | |
tree | 20f55020c5fa13a7510bea30ef36e21bb0c48e0e | |
parent | a6a3b9b665a874e98cedebbb2566d57285a40772 (diff) |
Stop modifying size values in sidebar when user still editing
Change-Id: I75e41e6b932ec7329789db27db266599f4de75ae
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108031
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
-rw-r--r-- | include/vcl/spinfld.hxx | 3 | ||||
-rw-r--r-- | svx/source/sidebar/possize/PosSizePropertyPanel.cxx | 105 | ||||
-rw-r--r-- | svx/source/sidebar/possize/PosSizePropertyPanel.hxx | 13 | ||||
-rw-r--r-- | vcl/source/control/spinfld.cxx | 14 |
4 files changed, 123 insertions, 12 deletions
diff --git a/include/vcl/spinfld.hxx b/include/vcl/spinfld.hxx index 8fb21f8605fd..d6a1c540b3e9 100644 --- a/include/vcl/spinfld.hxx +++ b/include/vcl/spinfld.hxx @@ -36,6 +36,7 @@ public: virtual void Up(); virtual void Down(); + virtual void Enter(); virtual void First(); virtual void Last(); @@ -51,6 +52,7 @@ public: void SetUpHdl( const Link<SpinField&,void>& rLink ) { maUpHdlLink = rLink; } void SetDownHdl( const Link<SpinField&,void>& rLink ) { maDownHdlLink = rLink; } + void SetEnterHdl( const Link<Control&,void>& rLink ) { maEnterHdlLink = rLink; } virtual Size CalcMinimumSize() const override; virtual Size CalcMinimumSizeForText(const OUString &rString) const override; @@ -83,6 +85,7 @@ private: AutoTimer maRepeatTimer; Link<SpinField&,void> maUpHdlLink; Link<SpinField&,void> maDownHdlLink; + Link<Control&,void> maEnterHdlLink; bool mbRepeat:1, mbSpin:1, mbInitialUp:1, diff --git a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx index e5cc427a0f2a..a85d44422499 100644 --- a/svx/source/sidebar/possize/PosSizePropertyPanel.cxx +++ b/svx/source/sidebar/possize/PosSizePropertyPanel.cxx @@ -190,12 +190,27 @@ namespace void PosSizePropertyPanel::Initialize() { //Position : Horizontal / Vertical - mpMtrPosX->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangePosXHdl ) ); - mpMtrPosY->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangePosYHdl ) ); + mpMtrPosX->SetLoseFocusHdl( LINK( this, PosSizePropertyPanel, ChangePosXHdl ) ); + mpMtrPosX->SetEnterHdl(LINK( this, PosSizePropertyPanel, ChangePosXHdl ) ); + mpMtrPosX->SetUpHdl( LINK( this, PosSizePropertyPanel, ChangePosXUpDownHdl ) ); + mpMtrPosX->SetDownHdl( LINK( this, PosSizePropertyPanel, ChangePosXUpDownHdl ) ); + + mpMtrPosY->SetLoseFocusHdl( LINK( this, PosSizePropertyPanel, ChangePosYHdl ) ); + mpMtrPosY->SetEnterHdl( LINK( this, PosSizePropertyPanel, ChangePosYHdl ) ); + mpMtrPosY->SetUpHdl( LINK( this, PosSizePropertyPanel, ChangePosYUpDownHdl ) ); + mpMtrPosY->SetDownHdl( LINK( this, PosSizePropertyPanel, ChangePosYUpDownHdl ) ); + //Size : Width / Height - mpMtrWidth->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangeWidthHdl ) ); - mpMtrHeight->SetModifyHdl( LINK( this, PosSizePropertyPanel, ChangeHeightHdl ) ); + mpMtrWidth->SetLoseFocusHdl( LINK( this, PosSizePropertyPanel, ChangeWidthHdl ) ); + mpMtrWidth->SetEnterHdl( LINK( this, PosSizePropertyPanel, ChangeWidthHdl ) ); + mpMtrWidth->SetUpHdl( LINK( this, PosSizePropertyPanel, ChangeWidthUpDownHdl ) ); + mpMtrWidth->SetDownHdl( LINK( this, PosSizePropertyPanel, ChangeWidthUpDownHdl ) ); + + mpMtrHeight->SetLoseFocusHdl( LINK( this, PosSizePropertyPanel, ChangeHeightHdl ) ); + mpMtrHeight->SetEnterHdl( LINK( this, PosSizePropertyPanel, ChangeHeightHdl ) ); + mpMtrHeight->SetUpHdl( LINK( this, PosSizePropertyPanel, ChangeHeightUpDownHdl ) ); + mpMtrHeight->SetDownHdl( LINK( this, PosSizePropertyPanel, ChangeHeightUpDownHdl ) ); //Size : Keep ratio mpCbxScale->SetClickHdl( LINK( this, PosSizePropertyPanel, ClickAutoHdl ) ); @@ -353,7 +368,7 @@ void PosSizePropertyPanel::HandleContextChange( } -IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeWidthHdl, Edit&, void ) +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeWidthHdl, Control&, void ) { if( mpCbxScale->IsChecked() && mpCbxScale->IsEnabled() ) @@ -374,8 +389,29 @@ IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeWidthHdl, Edit&, void ) executeSize(); } +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeWidthUpDownHdl, SpinField&, void ) +{ + if( mpCbxScale->IsChecked() && + mpCbxScale->IsEnabled() ) + { + long nHeight = static_cast<long>( (static_cast<double>(mlOldHeight) * static_cast<double>(mpMtrWidth->GetValue())) / static_cast<double>(mlOldWidth) ); + if( nHeight <= mpMtrHeight->GetMax( FieldUnit::NONE ) ) + { + mpMtrHeight->SetUserValue( nHeight, FieldUnit::NONE ); + } + else + { + nHeight = static_cast<long>(mpMtrHeight->GetMax( FieldUnit::NONE )); + mpMtrHeight->SetUserValue( nHeight ); + const long nWidth = static_cast<long>( (static_cast<double>(mlOldWidth) * static_cast<double>(nHeight)) / static_cast<double>(mlOldHeight) ); + mpMtrWidth->SetUserValue( nWidth, FieldUnit::NONE ); + } + } + executeSize(); +} -IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeHeightHdl, Edit&, void ) + +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeHeightHdl, Control&, void ) { if( mpCbxScale->IsChecked() && mpCbxScale->IsEnabled() ) @@ -396,8 +432,45 @@ IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeHeightHdl, Edit&, void ) executeSize(); } +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangeHeightUpDownHdl, SpinField&, void ) +{ + if( mpCbxScale->IsChecked() && + mpCbxScale->IsEnabled() ) + { + long nWidth = static_cast<long>( (static_cast<double>(mlOldWidth) * static_cast<double>(mpMtrHeight->GetValue())) / static_cast<double>(mlOldHeight) ); + if( nWidth <= mpMtrWidth->GetMax( FieldUnit::NONE ) ) + { + mpMtrWidth->SetUserValue( nWidth, FieldUnit::NONE ); + } + else + { + nWidth = static_cast<long>(mpMtrWidth->GetMax( FieldUnit::NONE )); + mpMtrWidth->SetUserValue( nWidth ); + const long nHeight = static_cast<long>( (static_cast<double>(mlOldHeight) * static_cast<double>(nWidth)) / static_cast<double>(mlOldWidth) ); + mpMtrHeight->SetUserValue( nHeight, FieldUnit::NONE ); + } + } + executeSize(); +} + + +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosXHdl, Control&, void ) +{ + if ( mpMtrPosX->IsValueModified()) + { + long lX = GetCoreValue( *mpMtrPosX, mePoolUnit ); + + Fraction aUIScale = mpView->GetModel()->GetUIScale(); + lX = long( lX * aUIScale ); + + SfxInt32Item aPosXItem( SID_ATTR_TRANSFORM_POS_X,static_cast<sal_uInt32>(lX)); + + GetBindings()->GetDispatcher()->ExecuteList( + SID_ATTR_TRANSFORM, SfxCallMode::RECORD, { &aPosXItem }); + } +} -IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosXHdl, Edit&, void ) +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosXUpDownHdl, SpinField&, void ) { if ( mpMtrPosX->IsValueModified()) { @@ -414,7 +487,23 @@ IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosXHdl, Edit&, void ) } -IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosYHdl, Edit&, void ) +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosYHdl, Control&, void ) +{ + if ( mpMtrPosY->IsValueModified() ) + { + long lY = GetCoreValue( *mpMtrPosY, mePoolUnit ); + + Fraction aUIScale = mpView->GetModel()->GetUIScale(); + lY = long( lY * aUIScale ); + + SfxInt32Item aPosYItem( SID_ATTR_TRANSFORM_POS_Y,static_cast<sal_uInt32>(lY)); + + GetBindings()->GetDispatcher()->ExecuteList( + SID_ATTR_TRANSFORM, SfxCallMode::RECORD, { &aPosYItem }); + } +} + +IMPL_LINK_NOARG( PosSizePropertyPanel, ChangePosYUpDownHdl, SpinField&, void ) { if ( mpMtrPosY->IsValueModified() ) { diff --git a/svx/source/sidebar/possize/PosSizePropertyPanel.hxx b/svx/source/sidebar/possize/PosSizePropertyPanel.hxx index 26854fa4873c..becbcef6da0d 100644 --- a/svx/source/sidebar/possize/PosSizePropertyPanel.hxx +++ b/svx/source/sidebar/possize/PosSizePropertyPanel.hxx @@ -20,6 +20,7 @@ #define INCLUDED_SVX_SOURCE_SIDEBAR_POSSIZE_POSSIZEPROPERTYPANEL_HXX #include <vcl/ctrl.hxx> +#include <vcl/spinfld.hxx> #include <sfx2/sidebar/SidebarPanelBase.hxx> #include <sfx2/sidebar/ControllerItem.hxx> #include <sfx2/sidebar/IContextChangeReceiver.hxx> @@ -157,10 +158,14 @@ private: css::uno::Reference<css::ui::XSidebar> mxSidebar; - DECL_LINK( ChangePosXHdl, Edit&, void ); - DECL_LINK( ChangePosYHdl, Edit&, void ); - DECL_LINK( ChangeWidthHdl, Edit&, void ); - DECL_LINK( ChangeHeightHdl, Edit&, void ); + DECL_LINK( ChangePosXHdl, Control&, void ); + DECL_LINK( ChangePosYHdl, Control&, void ); + DECL_LINK( ChangePosXUpDownHdl, SpinField&, void ); + DECL_LINK( ChangePosYUpDownHdl, SpinField&, void ); + DECL_LINK( ChangeWidthHdl, Control&, void ); + DECL_LINK( ChangeHeightHdl, Control&, void ); + DECL_LINK( ChangeWidthUpDownHdl, SpinField&, void ); + DECL_LINK( ChangeHeightUpDownHdl, SpinField&, void ); DECL_LINK( ClickAutoHdl, Button*, void ); DECL_LINK( AngleModifiedHdl, Edit&, void ); DECL_LINK( RotationHdl, svx::DialControl*, void ); diff --git a/vcl/source/control/spinfld.cxx b/vcl/source/control/spinfld.cxx index e4cac9a03766..f4660ce64dca 100644 --- a/vcl/source/control/spinfld.cxx +++ b/vcl/source/control/spinfld.cxx @@ -367,6 +367,11 @@ void SpinField::Down() ImplCallEventListenersAndHandler( VclEventId::SpinfieldDown, [this] () { maDownHdlLink.Call(*this); } ); } +void SpinField::Enter() +{ + ImplCallEventListenersAndHandler( VclEventId::EditModify, [this] () { maEnterHdlLink.Call(*this); } ); +} + void SpinField::First() { ImplCallEventListenersAndHandler(VclEventId::SpinfieldFirst, nullptr); @@ -541,6 +546,15 @@ bool SpinField::EventNotify(NotifyEvent& rNEvt) } } break; + case KEY_RETURN: + { + if (!nMod) + { + Enter(); + bDone = true; + } + } + break; } } } |