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

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

#ifndef DJ_APP_H
#define DJ_APP_H
#include <djImageApp.h>
#include <djIcon.h>
#include <djFileBrowser.h>
#include <djImageOpWidget.h>
#include <djImageIoWidget.h>

class Fl_Window;

namespace dj {

class MessageDialog;
class QuestionDialog;
class InputDialog;

// Widget application.
//
class App : public dj::ImageApp {
public:

  App(const Str & name, int & argc, char ** argv);
  virtual ~App();
  
  // Execution.
  //
  virtual int exec();
  virtual void exit();
  virtual void valid(bool);
  bool isValid() const { return _valid; }
  
  // Messages.
  //
  virtual void error(const Str &) const;
  virtual void print(const Str &) const;
  
  // Plugins.
  //
  ImageOpWidgetFactory & imageOpWidget() { return _imageOpWidgetFactory; }
  ImageLoadWidgetFactory & imageLoadWidget() { return _imageLoadWidgetFactory; }
  ImageSaveWidgetFactory & imageSaveWidget() { return _imageSaveWidgetFactory; }
  
  // Look.
  //
  void colorFg(const Color &);
  void colorBg(const Color &);
  void colorBg2(const Color &);
  void font(Fl_Font);
  void fontBold(Fl_Font);
  void fontSize(int);
  void layoutSpacing(int);
  void layoutMargin(int);
  void layoutWidgetMargin(int);
  void layoutButtonSize(int);
  void layoutThumbnailSize(int);
  const Color & colorFg() const { return _colorFg; }
  const Color & colorBg() const { return _colorBg; }
  const Color & colorBg2() const { return _colorBg2; }
  Fl_Font font() const { return _font; }
  Fl_Font fontBold() const { return _fontBold; }
  int fontSize() const { return _fontSize; }
  int layoutSpacing() const { return _layoutSpacing; }
  int layoutMargin() const { return _layoutMargin; }
  int layoutWidgetMargin() const { return _layoutWidgetMargin; }
  int layoutButtonSize() const { return _layoutButtonSize; }
  int layoutThumbnailSize() const { return _layoutThumbnailSize; }
  IconFactory & icon() { return _iconFactory; }
  
  // Dialogs.
  //
  MessageDialog * messageDialog() { return _messageDialog; }
  QuestionDialog * questionDialog() { return _questionDialog; }
  InputDialog * inputDialog() { return _inputDialog; }
  FileBrowserDialog * fileBrowser() { return _fileBrowser; }
  FileBrowserDialog * fileBrowser() const { return _fileBrowser; }
  
  // Tooltips.
  //
  void tooltips(bool);
  bool tooltips() const { return _tooltips; }
  
  // Preferences.
  //
  Prefs & prefs() { return _prefs; }
  bool prefsInit() const { return _prefsInit; }
  
  // XXX Keep track of windows for application exit.
  //
  void windowAdd(Fl_Window *);
  void windowDel(Fl_Window *);

protected:

  void imageFactoryInit();
  void prefsSet();
  void prefsGet();
  void tooltipsUpdate();
  
private:

  bool _valid;
  
  ImageOpWidgetFactory _imageOpWidgetFactory;
  ImageLoadWidgetFactory _imageLoadWidgetFactory;
  ImageSaveWidgetFactory _imageSaveWidgetFactory;
  
  Color _colorFg, _colorBg, _colorBg2;
  Fl_Font _font, _fontBold;
  int _fontSize;
  int _layoutSpacing, _layoutMargin, _layoutWidgetMargin, _layoutButtonSize,
    _layoutThumbnailSize;
  IconFactory _iconFactory;
  
  MessageDialog * _messageDialog;
  QuestionDialog * _questionDialog;
  InputDialog * _inputDialog;
  FileBrowserDialog * _fileBrowser;
  List<Fl_Window *> _windowList;
  
  bool _tooltips;
  
  Prefs _prefs;
  bool _prefsInit;
};

// Global application pointer.
//
#define djApp (static_cast<dj::App *>(djImageApp))

}

#endif
