From 7735fef5dfd85a156d87bb8f3f0fae64d89f7ba4 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 1 May 2017 14:53:39 +0000 Subject: [PATCH] CtrlLib: Initial value of Edit*Spin is now zero if Min limit is default; EditIntSpin and EditIntSpin64 now rounding values like EditDoubleSpin git-svn-id: svn://ultimatepp.org/upp/trunk@11049 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/CtrlLib/EditCtrl.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/uppsrc/CtrlLib/EditCtrl.h b/uppsrc/CtrlLib/EditCtrl.h index 78e99d6bd..c1c8d93b0 100644 --- a/uppsrc/CtrlLib/EditCtrl.h +++ b/uppsrc/CtrlLib/EditCtrl.h @@ -339,12 +339,30 @@ public: template IncType WithSpin_DefaultIncValue() { return 1; } template <> inline double WithSpin_DefaultIncValue() { return 0.1; } +template IncType WithSpin_DefaultStartValue() { return 0; } +template <> inline Date WithSpin_DefaultStartValue() { return GetSysDate(); } +template <> inline Time WithSpin_DefaultStartValue() { return GetSysTime(); } + template void WithSpin_Add(DataType& value, IncType inc, DataType min, bool roundfrommin) { value += inc; } +template <> inline +void WithSpin_Add(int& value, int inc, int min, bool roundfrommin) { + if(roundfrommin) + value -= min; + if(inc < 0) { + inc = -inc; + value = (value - inc) / inc * inc; + } + else + value = (value + inc) / inc * inc; + if(roundfrommin) + value += min; +} + template <> inline void WithSpin_Add(double& value, double inc, double min, bool roundfrommin) { if(roundfrommin) @@ -447,7 +465,7 @@ void WithSpin::Inc() else { DataType min = Base::GetMin(); if(IsNull(min) || min <= Base::GetDefaultMin()) - Base::SetData(0); + Base::SetData(WithSpin_DefaultStartValue()); else Base::SetData(min); } @@ -472,7 +490,7 @@ void WithSpin::Dec() else { DataType max = Base::GetMax(); if(IsNull(max) || max >= Base::GetDefaultMax()) - Base::SetData(0); + Base::SetData(WithSpin_DefaultStartValue()); else Base::SetData(max); }