// #################################
//
//           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. 
//
// ##################################

#include "prescrib_flpda.hpp"

#include <flpda/Widget_Factory.h>





PrescribblePDAApp::PrescribblePDAApp( PresConfig &a_conf)
    : PrescribbleApp( a_conf ){ }


    
Fl_Window *PrescribblePDAApp::createArea( )
{
    Fl_App_Window *window 
        //= new PresAppWindow( XSIZE, YSIZE,"Prescribble", this);
        = Widget_Factory::new_window("Prescribble");
            // |- messes up the keys...

    m_pMainWindow = window;
    
    
    Fl_Scroll *scroll = new Fl_Scroll(0,0,XSIZE,YSIZE-MENUYSIZE);
    
/* 
   PresAppWindow *internalwin 
   = new PresAppWindow( XSIZE, YSIZE- MENUYSIZE,
   "Prescribble", this);
   
   window->add( internalwin );
*/

    PrescribbleArea *box 
        = new PrescribbleArea( m_notes[m_currentNote], 
                               0,0, 
                               XSIZE *2, YSIZE *2,
                               m_config );
    
    m_pArea = box;
//            internalwin->end();
    
    scroll->end();
    window->resizable(scroll);
    window->end();
    
    Fl_Dockable_Window* toolbar = WidgetFactory::new_toolbar();
    
    
    
    Fl_Menu_Button *mbut
//                 = new Fl_Menu_Button(              
//                     0,YSIZE-MENUYSIZE, XSIZE/6,MENUYSIZE,
//                     "File"
//                     );
        
        = Widget_Factory::new_menu_button( 
//                    "File",
            0,YSIZE-MENUYSIZE,
            "File"
            );
    //        (static_cast<Fl_Widget*>(mbut))
    //           ->size( XSIZE/6, Widget_Factory::buttonheight() );
    
    
    //mbut->labelsize(8);
    
    
    
    static Fl_Menu_Item filePopupMenu[] =
    {
        { "Quit",0, &CallbackBase::cb, &m_quitter,
          FL_MENU_DIVIDER},
        { "Save As...",0, &CallbackBase::cb, &m_saverAs },
        { "Save",0, &CallbackBase::cb, &m_saver },
        { "Load",0, &CallbackBase::cb, &m_loader, },
        { "Load from...",0, &CallbackBase::cb, &m_loaderFrom,
          FL_MENU_DIVIDER },
        { "About",0, &CallbackBase::cb, &m_about },
        
        
//                { "...", 0, 0,0, FL_SUBMENU },
//                { "Save",0, &CallbackBase::cb, &m_saver },
//                { "Load",0, &CallbackBase::cb, &m_loader },
//                {0},

        {0}
    };
    mbut->menu(filePopupMenu);
    
    
    
    
//             mbut->add("Quit","", &CallbackBase::cb, &m_quitter, 
//                       FL_MENU_DIVIDER );
//             mbut->add("Save","", &CallbackBase::cb, &m_saver   );
//             mbut->add("Load","", &CallbackBase::cb, &m_loader  );
    
    
    mbut
        //= new Fl_Menu_Button(
        = Widget_Factory::new_menu_button( 
            XSIZE/6 ,YSIZE-MENUYSIZE, // XSIZE/6,MENUYSIZE,
            "Edit"
            );
    //mbut->labelsize(8);
    //  (static_cast<Fl_Widget*>(mbut))
    //     ->size( XSIZE/6, Widget_Factory::buttonheight() );
    
    static Fl_Menu_Item editPopupMenu[] =
    {
        {"Clear",0,&CallbackBase::cb,&box->m_cleaner},
        {"Erase",0,&CallbackBase::cb,&box->m_eraser,
         FL_MENU_DIVIDER},
        {"Undo",0,&CallbackBase::cb,&box->m_undoer},
        {"Redo",0,&CallbackBase::cb,&box->m_redoer,
         FL_MENU_DIVIDER},
        {"New note",0,&CallbackBase::cb,&m_inserter },
        {"Redraw",0,&CallbackBase::cb,&box->m_redrawer},
        
        {0}
    };
    mbut->menu( editPopupMenu );
    




    new Fl_Box( FL_NO_BOX, 0,0,6,6,"");//spacing
    
    
    
    
    // UNDO
    Fl_Button *but
        = Widget_Factory::new_button( 
//                = new Fl_Button(
            2*XSIZE/6 + XSIZE/(6*2*2)  ,YSIZE-MENUYSIZE, 
            //                  XSIZE/(6*2),MENUYSIZE,
            "@|<"
            );
    but->labelsize(8);
    but->size( XSIZE/(6*2), Widget_Factory::buttonheight() );
    but->labeltype(FL_SYMBOL_LABEL);
    but->callback( &CallbackBase::cb,&box->m_undoer );
    
    
    // REDO
    but
        = Widget_Factory::new_button( 
//                = new Fl_Button(
            2*XSIZE/6 + XSIZE/(6*2*2/3) ,YSIZE-MENUYSIZE, 
//                    XSIZE/(6*2),MENUYSIZE,
            "@>|"
            );
    but->labelsize(8);
    but->size( XSIZE/(6*2), Widget_Factory::buttonheight() );
    but->labeltype(FL_SYMBOL_LABEL);
    but->callback( &CallbackBase::cb,&box->m_redoer );
    
    
    
    new Fl_Box( FL_NO_BOX, 0,0,6,6,""); //spacing
    
    
    // PREV
    but 
        = Widget_Factory::new_button( 
//                = new Fl_Button(
            4*XSIZE/6 ,YSIZE-MENUYSIZE, 
//                    XSIZE/(6*2),MENUYSIZE,
            "@<-");
    but->size( XSIZE/(6*2), Widget_Factory::buttonheight() );
    but->callback( &PresApp_Callback::cb, &m_toPrev );
    but->labeltype(FL_SYMBOL_LABEL);
    

    
    //FEEDBACK
    m_pFeedback
        = new Fl_Button( //FL_DOWN_BOX,
            4*XSIZE/6+XSIZE/(6*2) ,YSIZE-MENUYSIZE, 
            XSIZE-2*XSIZE/(6*2)-4*XSIZE/6,MENUYSIZE,
            "...");
    m_pFeedback->labelsize(8);
    m_pFeedback->size( XSIZE-2*XSIZE/(6*2)-4*XSIZE/6, 
                       Widget_Factory::buttonheight() );
    m_pFeedback->callback(&CallbackBase::cb,&box->m_redrawer);
    feedbackNotePage();
    

    
    // NEXT
    but 
        = Widget_Factory::new_button( 
//                = new Fl_Button(
            XSIZE-XSIZE/(6*2) ,YSIZE-MENUYSIZE, 
//                    XSIZE/(6*2),MENUYSIZE,
            "@->");
    but->labeltype(FL_SYMBOL_LABEL);
    but->size( XSIZE/(6*2), Widget_Factory::buttonheight() );
    but->callback( &PresApp_Callback::cb, &m_toNext );
    
    

    
//            Fl_Page_UpDown_Button* pb = WidgetFactory::new_pagekey();
    //browser->page_updown_button(pb);
    
    
    toolbar->end();
    window->add_dockable(toolbar, 1);
    
    
//            window->end();
    Fl::visual(FL_DOUBLE|FL_INDEX);
    window->show();
    return window;
}
//};


