template WithSpin::WithSpin() : inc(WithSpin_DefaultIncValue()) { Init(); } template WithSpin::WithSpin(IncType inc) : inc(inc) { Init(); } template WithSpin::WithSpin(DataType min, DataType max, IncType inc) : inc(WithSpin_DefaultIncValue()) { Base::MinMax(min, max); Init(); } template void WithSpin::Init() { style = &SpinButtons::StyleDefault(); } template WithSpin& WithSpin::OnSides(bool b) { SetSpinStyle(b ? SpinButtons::StyleOnSides() : SpinButtons::StyleDefault()); Base::RefreshLayout(); return *this; } template void WithSpin::Inc() { if(Ctrl::IsReadOnly()) { BeepExclamation(); return; } DataType d = Base::GetData(); if(!IsNull(d)) { WithSpin_Add(d, inc, Base::GetMin(), roundfrommin); if(IsNull(Base::GetMax()) || d <= Base::GetMax()) { Base::SetData(d); Ctrl::Action(); } } else { DataType min = Base::GetMin(); if(IsNull(min) || min <= Base::GetDefaultMin()) Base::SetData(WithSpin_DefaultStartValue()); else Base::SetData(min); } Ctrl::SetFocus(); } template void WithSpin::Dec() { if(Ctrl::IsReadOnly()) { BeepExclamation(); return; } DataType d = Base::GetData(); if(!IsNull(d)) { WithSpin_Add(d, -inc, Base::GetMin(), roundfrommin); if(IsNull(Base::GetMin()) || d >= Base::GetMin()) { Base::SetData(d); Ctrl::Action(); } } else { DataType max = Base::GetMax(); if(IsNull(max) || max >= Base::GetDefaultMax()) Base::SetData(WithSpin_DefaultStartValue()); else Base::SetData(max); } Ctrl::SetFocus(); } template bool WithSpin::Key(dword key, int repcnt) { if(keys) { if(key == K_UP) { Inc(); return true; } if(key == K_DOWN) { Dec(); return true; } } return Base::Key(key, repcnt); } template Image WithSpin::MouseEvent(int event, Point p, int zdelta, dword keyflags) { if(ButtonsMouseEvent(this, event, p)) return Image::Arrow(); return Base::MouseEvent(event, p, zdelta, keyflags); } template void WithSpin::MouseWheel(Point, int zdelta, dword) { if(mousewheel) { if(zdelta < 0) Dec(); else Inc(); } } template void WithSpin::CancelMode() { Base::CancelMode(); ButtonsCancelMode(); } template int WithSpin::GetSpaceLeft() const { if(!visible) return 0; return style->onsides ? min(Base::GetSize().cx / 2, style->width) - style->over : 0; } template int WithSpin::GetSpaceRight() const { if(!visible) return 0; return min(Base::GetSize().cx / 2, style->width) - style->over; } template void WithSpin::EditCapture() { buttons_capture = false; } template bool WithSpin::HasEditCapture() { return Base::HasCapture() && !buttons_capture; } template void WithSpin::ButtonPush(int i) { if(i) Inc(); else Dec(); } template void WithSpin::ButtonRepeat(int i) { ButtonPush(i); } template void WithSpin::PaintSpace(Draw& w) { PaintButtons(w, this); } template int WithSpin::ButtonCount() const { return visible ? 2 : 0; } template Rect WithSpin::ButtonRect(int i) const { Rect rect = Base::GetSize(); int h = rect.GetHeight(); int h7 = min(rect.GetWidth() / 2, style->width); int h7o = h7 - style->over; if(style->onsides) return i ? RectC(rect.left - style->over, rect.top, h7, h) : RectC(rect.right - h7o, rect.top, h7, h); int h2 = h / 2; return i ? RectC(rect.right - h7o, rect.top, h7, h2) : RectC(rect.right - h7o, rect.top + h2, h7, h - h2); } template const Button::Style& WithSpin::ButtonStyle(int i) const { return i ? style->inc : style->dec; }