/*------------------------------------------------------------------------------
 src/lib/djWidget/intWidget.cxx

 Copyright (c) 2004-2006 Darby Johnston.
 All rights reserved.
 Use is subject to license terms.
------------------------------------------------------------------------------*/

//#define DJ_DBG
#include "djNumWidget.h"
#include <djTextWidget.h>

namespace dj {

IntWidget::IntWidget() :
  _value(0),
  _min(-1000000), _max(1000000),
  _inc(1), _dec(-1)
{
  widgetUpdate();
}

void IntWidget::set(int in)
{
  const int tmp = clamp(in, _min, _max);
  if (tmp == _value) return;
  _value = tmp;
  _sig.emit(_value);
  widgetUpdate();
}

void IntWidget::range(int min, int max)
{
  if (min == _min && max == _max) return;
  _min = min;
  _max = max;
  set(_value);
}

void IntWidget::min(int in)
{
  if (in == _min) return;
  _min = in;
  set(_value);
}

void IntWidget::max(int in)
{
  if (in == _max) return;
  _max = in;
  set(_value);
}

void IntWidget::inc(int inc, int dec)
{
  _inc = inc;
  _dec = dec;
}

void IntWidget::inc() { set(_value + _inc); }
void IntWidget::incBig() { set(_value + _inc * 10); }
void IntWidget::dec() { set(_value + _dec); }
void IntWidget::decBig() { set(_value + _dec * 10); }

void IntWidget::widgetCallback(const Str & in) { set(toInt(in)); }
void IntWidget::widgetUpdate() { NumWidget::widgetUpdate(toStr(_value)); }

}
