/*------------------------------------------------------------------------------
 src/lib/djWidget/djNumWidget.h

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

#ifndef DJ_NUM_WIDGET_H
#define DJ_NUM_WIDGET_H
#include <djWidget.h>

namespace dj {

class PushButtonWidget;
class ToolButtonWidget;
class TextWidget;

// Number input widget base.
//
class NumWidget : public Widget {
public:

  NumWidget();

  // Increment.
  //
  virtual void inc() = 0;
  virtual void incBig() = 0;
  virtual void dec() = 0;
  virtual void decBig() = 0;
  
  // Widget.
  //
  void toolWidget(bool);
  bool toolWidget() const { return _toolWidget; }
  virtual int handle(int);
  
protected:

  virtual DJ_CALLBACK(NumWidget, widgetCallback, const Str &)
  void widgetUpdate(const Str &);

private:

  DJ_CALLBACK(NumWidget, incCallback, bool)
  DJ_CALLBACK(NumWidget, decCallback, bool)
  void toolWidgetUpdate();

  bool _toolWidget;
  TextWidget * _widget;
  ToolButtonWidget * _incWidget, * _decWidget;
};

// Integer input widget.
//
class IntWidget : public NumWidget {
public:

  IntWidget();

  // Value.
  //
  void set(int);
  int get() const { return _value; }
  
  // Range.
  //
  void range(int min, int max);
  void min(int);
  void max(int);
  int min() const { return _min; }
  int max() const { return _max; }
  
  // Increment.
  //
  void inc(int inc, int dec);
  void inc();
  void incBig();
  void dec();
  void decBig();
  int inc() const { return _inc; }
  int dec() const { return _dec; }
  
  // Signals.
  //
  Signal<int> & sig() { return _sig; }
  
private:

  void widgetCallback(const Str &);
  void widgetUpdate();

  int _value;
  int _min, _max;
  int _inc, _dec;
  
  Signal<int> _sig;
};

// Floating point input widget.
//
class FloatWidget : public NumWidget {
public:

  FloatWidget();

  // Value.
  //  
  void set(double);
  double get() const { return _value; }
  
  // Range.
  //
  void range(double min, double max);
  void min(double);
  void max(double);
  double min() const { return _min; }
  double max() const { return _max; }
  
  // Increment.
  //
  void inc(double inc, double dec);
  void inc();
  void incBig();
  void dec();
  void decBig();
  double inc() const { return _inc; }
  double dec() const { return _dec; }
  
  // Signals.
  //
  Signal<double> & sig() { return _sig; }
  
private:

  void widgetCallback(const Str &);
  void widgetUpdate();

  double _value;
  double _min, _max;
  double _inc, _dec;

  Signal<double> _sig;
};

}

#endif
