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

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

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

class Fl_Image;
class Fl_Button;
class Fl_Check_Button;

namespace dj {

// Push button widget.
//
class PushButtonWidget : public Widget {
public:

  PushButtonWidget(const Str & in);
  ~PushButtonWidget();
  
  // Label.
  //
  void label(const Str &);
  const Str & label() const { return _label; }
  
  // Signals.
  //
  Signal<bool> & sig() { return _sig; }
  
  // Layout.
  //
  const Vec2i sizeHint() const;
  void resize(int, int, int, int);
  
private:

  DJ_FL_WIDGET_CALLBACK(PushButtonWidget, widgetCallback)

  Str _label;
  char * _labelAscii;
  
  Signal<bool> _sig;
  
  Fl_Button * _widget;
};

// Check button widget.
//
class CheckButtonWidget : public Widget {
public:

  CheckButtonWidget(const Str & = Str());
  ~CheckButtonWidget();
  
  // Value.
  //
  void set(bool);
  bool get() const { return _value; }
  
  // Label.
  //
  void label(const Str &);
  const Str & label() const { return _label; }
  
  // Signals.
  //
  Signal<bool> & sig() { return _sig; }
  
  // Layout.
  //
  const Vec2i sizeHint() const;
  void resize(int, int, int, int);
  
private:

  DJ_FL_WIDGET_CALLBACK(CheckButtonWidget, widgetCallback)
  void widgetUpdate();

  bool _value;
  Str _label;
  char * _labelAscii;
  
  Signal<bool> _sig;
  
  Fl_Check_Button * _widget;
  bool _callbacks;
};

// Tool button widget.
//
class ToolButtonWidget : public Widget {
public:

  ToolButtonWidget(const Str & icon, int iconMargin = 2);
  virtual ~ToolButtonWidget();
  virtual void die();
  
  // Value.
  //
  void set(bool);
  bool get() const { return _value; }
  
  // Type.
  //
  enum TYPE { PUSH, TOGGLE, RADIO, REPEAT };
  void type(TYPE);
  TYPE type() const { return _type; }
  
  // Icon.
  //
  void icon(Fl_Image *);
  void iconMargin(int);
  int iconMargin() const { return _iconMargin; }
  
  // Shortcut.
  //
  void shortcut(int);
  int shortcut() const { return _shortcut; }
  
  // Signals.
  //
  Signal<bool> & sig() { return _sig; }
  
  // Widget.
  //
  const Vec2i sizeHint() const;
  void draw();
  int handle(int);

private:

  void action();
  
  DJ_FL_CALLBACK(ToolButtonWidget, repeatCallback)

  bool _value;
  TYPE _type;
  bool _repeatActive;
  Fl_Image * _icon;
  int _iconMargin;
  int _shortcut;
  
  Signal<bool> _sig;
  
  bool _pressed, _inside;
};

}

#endif
