// #################################
//
//           Prescribble
//
//        (C)opyright 2001 
//           by Kent Dahl 
//
//        MenThal@bigfoot.com
//  http://www.bigfoot.com/~MenThal/
//
//    Released under the GPL 
//     (Gnu Public License)
//
//       Use at own risk. 
//
// ##################################

#ifndef prescrib_fltk_hpp
#define prescrib_fltk_hpp



#include <FL/Fl_Double_Window.H>
#include <FL/Fl_Box.H>

#include <string>
#include <functional>

#include "prescribblearea.hpp"

class PresConfig;
class PrescribbleArea;
class PrescribbleApp;
class PresAppWindow;





//================
struct PresApp_Callback : public CallbackBase {
    PrescribbleApp *m_pThat;
    std::mem_fun1_t<int,PrescribbleApp,void*>  m_fptr;
    void *m_data;

    PresApp_Callback( PrescribbleApp *a_pThat,
                      int (PrescribbleApp::*a_pFunc)(void*),
                      void *a_data = 0);

    void callback();

};


//================

#ifdef FLPDA
//#include "modifiedFlek/my_Fl_App_Window.H" // bad hack
#include <Flek/Fl_App_Window.H>
#endif

class PresAppWindow :

#ifdef FLPDA
 public Fl_App_Window
#else
 public Fl_Double_Window 
#endif
  {
protected:
    PrescribbleApp *m_pApp;
public:
    PresAppWindow( int width, int height, 
                   const char* name, PrescribbleApp *pApp );

    int handle(int evt);
    int handleKeyboard(int evt);

 

};
//================


class PrescribbleApp : public PrescribbleNoteListener {

    typedef std::vector<PrescribbleNote*> NotesVector ;

    NotesVector m_notes;
    int m_currentNote;

public:
    PrescribbleArea *m_pArea;
    Fl_Window *m_pMainWindow;
    Fl_Button *m_pFeedback;
    char *m_pFeedbackString;

    Fl_Menu_Item *m_pToolboxMenu;
    Fl_Menu_Button *m_pEditMenuButton;



    Fl_Button *m_pUndoButton, *m_pRedoButton;
    Fl_Button *m_pLeftButton, *m_pRightButton;


    PresConfig m_config;

public:
    PresApp_Callback m_quitter, m_loader, m_loaderFrom, m_makeNew,
        m_saver, m_saverAs, m_about, 
        m_toPrev, m_toNext, m_inserter, m_appender, 
        m_noteForward, m_noteBackward,
        m_noteDelete;


public:
    
    PrescribbleApp( PresConfig &a_conf);
    virtual ~PrescribbleApp(){}
    void start();

    void resetDefaultNotes();
    void removeNotes();


    void writeto( ostream & out );

    int handleKeyboard(int evt);

    int saveNotes(void*);
    int saveNotesTo(void*);
    int loadNotesFrom(void*);
    int loadNotes(void*);

    int clearNotes(void*);

    int quit(void*);
    int about(void*);


    void setFeedbackLabel( const char* );
    void feedbackNotePage();

    int nextNote(void*);
    int prevNote(void*);

    int insertNote(void*);
    int deleteNote(void*);
    int moveNote(void*);
    
    void zoom(int);
    void toolSelect(int);

    Fl_Menu_Item* getFilePopupMenu();
    Fl_Menu_Item* getEditPopupMenu(PrescribbleArea *box);
    Fl_Window *createArea( );

   void updateUndoStatus(bool);
    void updateRedoStatus(bool);


};


#endif
