mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-09-05 17:44:55 -06:00
CtrlLib: Edit*Spin::RoundFromMin
git-svn-id: svn://ultimatepp.org/upp/trunk@11047 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
443e020644
commit
218c4988cc
2 changed files with 33 additions and 7 deletions
|
|
@ -68,6 +68,9 @@ public:
|
|||
int GetMin() const { return (int)minval; }
|
||||
int GetMax() const { return (int)maxval; }
|
||||
bool IsNotNull() const { return notnull; }
|
||||
|
||||
static int GetDefaultMin() { return -INT_MAX; }
|
||||
static int GetDefaultMax() { return INT_MAX; }
|
||||
|
||||
#ifdef flagSO
|
||||
ConvertInt(int minval = -INT_MAX, int maxval = INT_MAX, bool notnull = false);
|
||||
|
|
@ -88,6 +91,9 @@ struct ConvertInt64 : public ConvertInt {
|
|||
int64 GetMin() const { return minval; }
|
||||
int64 GetMax() const { return maxval; }
|
||||
|
||||
static int64 GetDefaultMin() { return -INT64_MAX; }
|
||||
static int64 GetDefaultMax() { return INT64_MAX; }
|
||||
|
||||
#ifdef flagSO
|
||||
ConvertInt64(int64 minval = -INT64_MAX, int64 maxval = INT64_MAX, bool notnull = false);
|
||||
virtual ~ConvertInt64();
|
||||
|
|
@ -120,6 +126,9 @@ public:
|
|||
double GetMax() const { return maxval; }
|
||||
bool IsNotNull() const { return notnull; }
|
||||
|
||||
static double GetDefaultMin() { return DOUBLE_NULL_LIM; }
|
||||
static double GetDefaultMax() { return -DOUBLE_NULL_LIM; }
|
||||
|
||||
ConvertDouble(double minval = DOUBLE_NULL_LIM, double maxval = -DOUBLE_NULL_LIM,
|
||||
bool notnull = false);
|
||||
#ifdef flagSO
|
||||
|
|
@ -151,6 +160,8 @@ public:
|
|||
Date GetMax() const { return maxval; }
|
||||
bool IsNotNull() const { return notnull; }
|
||||
|
||||
static Date GetDefaultMin() { return Date::Low(); }
|
||||
static Date GetDefaultMax() { return Date::High(); }
|
||||
|
||||
ConvertDate(Date minval = Date::Low(), Date maxval = Date::High(), bool notnull = false);
|
||||
virtual ~ConvertDate();
|
||||
|
|
@ -190,6 +201,9 @@ public:
|
|||
bool IsTimeAlways() const { return timealways; }
|
||||
bool IsDayEnd() const { return dayend; }
|
||||
|
||||
static Time GetDefaultMin() { return ToTime(Date::Low()); }
|
||||
static Time GetDefaultMax() { return ToTime(Date::High()); }
|
||||
|
||||
ConvertTime(Time minval = ToTime(Date::Low()), Time maxval = ToTime(Date::High()), bool notnull = false);
|
||||
virtual ~ConvertTime();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -340,19 +340,23 @@ template <class IncType> IncType WithSpin_DefaultIncValue() { return 1; }
|
|||
template <> inline double WithSpin_DefaultIncValue() { return 0.1; }
|
||||
|
||||
template <class DataType, class IncType>
|
||||
void WithSpin_Add(DataType& value, IncType inc)
|
||||
void WithSpin_Add(DataType& value, IncType inc, DataType min, bool roundfrommin)
|
||||
{
|
||||
value += inc;
|
||||
}
|
||||
|
||||
template <> inline
|
||||
void WithSpin_Add(double& value, double inc) {
|
||||
void WithSpin_Add(double& value, double inc, double min, bool roundfrommin) {
|
||||
if(roundfrommin)
|
||||
value -= min;
|
||||
if(inc < 0) {
|
||||
inc = -inc;
|
||||
value = (ceil(value / inc - inc / 100) - 1) * inc;
|
||||
}
|
||||
else
|
||||
value = (floor(value / inc + inc / 100) + 1) * inc;
|
||||
if(roundfrommin)
|
||||
value += min;
|
||||
}
|
||||
|
||||
template <class DataType, class Base, class IncType = DataType>
|
||||
|
|
@ -369,6 +373,7 @@ protected:
|
|||
private:
|
||||
SpinButtons sb;
|
||||
IncType inc;
|
||||
bool roundfrommin;
|
||||
|
||||
typedef WithSpin CLASSNAME;
|
||||
public:
|
||||
|
|
@ -381,6 +386,8 @@ public:
|
|||
|
||||
WithSpin& ShowSpin(bool s = true) { sb.Show(s); return *this; }
|
||||
bool IsSpinVisible() const { return sb.IsVisible(); }
|
||||
|
||||
WithSpin& RoundFromMin(bool b = true) { roundfrommin = b; return *this; }
|
||||
|
||||
SpinButtons& SpinButtonsObject() { return sb; }
|
||||
const SpinButtons& SpinButtonsObject() const { return sb; }
|
||||
|
|
@ -419,6 +426,7 @@ void WithSpin<DataType, Base, IncType>::Init()
|
|||
Ctrl::AddFrame(sb);
|
||||
sb.inc.WhenRepeat = sb.inc.WhenAction = THISBACK(Inc);
|
||||
sb.dec.WhenRepeat = sb.dec.WhenAction = THISBACK(Dec);
|
||||
roundfrommin = false;
|
||||
}
|
||||
|
||||
template <class DataType, class Base, class IncType>
|
||||
|
|
@ -430,7 +438,7 @@ void WithSpin<DataType, Base, IncType>::Inc()
|
|||
}
|
||||
DataType d = Base::GetData();
|
||||
if(!IsNull(d)) {
|
||||
WithSpin_Add(d, inc);
|
||||
WithSpin_Add(d, inc, Base::GetMin(), roundfrommin);
|
||||
if(IsNull(Base::GetMax()) || d <= Base::GetMax()) {
|
||||
Base::SetData(d);
|
||||
Ctrl::Action();
|
||||
|
|
@ -438,7 +446,9 @@ void WithSpin<DataType, Base, IncType>::Inc()
|
|||
}
|
||||
else {
|
||||
DataType min = Base::GetMin();
|
||||
if(!IsNull(min))
|
||||
if(IsNull(min) || min <= Base::GetDefaultMin())
|
||||
Base::SetData(0);
|
||||
else
|
||||
Base::SetData(min);
|
||||
}
|
||||
Ctrl::SetFocus();
|
||||
|
|
@ -453,7 +463,7 @@ void WithSpin<DataType, Base, IncType>::Dec()
|
|||
}
|
||||
DataType d = Base::GetData();
|
||||
if(!IsNull(d)) {
|
||||
WithSpin_Add(d, -inc);
|
||||
WithSpin_Add(d, -inc, Base::GetMin(), roundfrommin);
|
||||
if(IsNull(Base::GetMin()) || d >= Base::GetMin()) {
|
||||
Base::SetData(d);
|
||||
Ctrl::Action();
|
||||
|
|
@ -461,8 +471,10 @@ void WithSpin<DataType, Base, IncType>::Dec()
|
|||
}
|
||||
else {
|
||||
DataType max = Base::GetMax();
|
||||
if(!IsNull(max))
|
||||
Base::SetData(Base::maxval);
|
||||
if(IsNull(max) || max >= Base::GetDefaultMax())
|
||||
Base::SetData(0);
|
||||
else
|
||||
Base::SetData(max);
|
||||
}
|
||||
Ctrl::SetFocus();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue