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

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

#ifndef DJ_WIDGET_BASE_H
#define DJ_WIDGET_BASE_H
#include <djColor.h>
#include <FL/Enumerations.H>

class Fl_Preferences;

namespace dj {

// Colors.
//
const Color colorFg();
const Color colorBg();
const Color colorBg2();

// Font.
//
Fl_Font font();
Fl_Font fontBold();
int fontSize();

// FLTK callback macros.
//
#define DJ_FL_CALLBACK(TYPE, NAME) \
  void NAME(); \
  static void NAME(void * that) \
    { static_cast<TYPE *>(that)->NAME(); }
#define DJ_FL_WIDGET_CALLBACK(TYPE, NAME) \
  void NAME(); \
  static void NAME(Fl_Widget *, void * that) \
    { static_cast<TYPE *>(that)->NAME(); }

// Signal.
//
template <class T>
class Signal {
public:

  Signal();

  typedef void (Callback)(void *, T);
  void set(void *, Callback *);
  void del(void *, Callback *);
  void emit(T);

private:

  void * _obj;
  Callback * _callback;
};

// Signal callback macro.
//
#define DJ_CALLBACK(TYPE, NAME, arg) \
  void NAME(arg); \
  static void NAME(void * that, arg data) \
    { static_cast<TYPE *>(that)->NAME(data); }
    
// Preferences.
//
class Prefs {
public:

  Prefs(const Str & name);
  Prefs(const Prefs &, const Str & group);
  Prefs(Prefs *, const Str & group);
  ~Prefs();
  
  void set(const Str &, bool);
  void set(const Str &, int);
  void set(const Str &, double);
  void set(const Str &, const Str &);
  void set(const Str &, const StrList &);
  void set(const Str &, const Color &);
  
  bool get(const Str &, bool *, bool defaultValue = false) const;
  bool get(const Str &, int *, int defaultValue = 0) const;
  bool get(const Str &, double *, double defaultValue = 0.0) const;
  bool get(const Str &, Str *, const Str & defaultValue = Str()) const;
  bool get(
    const Str &, StrList *, const StrList & defaultValue = StrList()
  ) const;
  bool get(
    const Str &, Color *, const Color & defaultValue = Color(0.0)
  ) const;
  
  const StrList nameList() const;
  
  void del(const Str &);
  
  void groupDel(const Str &);
  const StrList groupList() const;

private:

  Fl_Preferences * _prefs;
};

// Global dialogs.
//
void messageDialog(const Str &);
void questionDialog(const Str &, void *, Signal<bool>::Callback *);
void questionDialogDel(void *, Signal<bool>::Callback *);
void inputDialog(
  const Str & message, const Str & value,
  void *, Signal<const Str &>::Callback *
);
void inputDialogDel(void *, Signal<const Str &>::Callback *);

// Global file browser.
//
void fileBrowser(void *, Signal<const Str &>::Callback *);
void fileBrowserDel(void *, Signal<const Str &>::Callback *);

}

#include <djWidgetBase_.h>
#endif
