/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                               DEMO PROGRAMS SET
                          dialog_test.cpp  -  description
                             -------------------
    begin                : January 3, 2003
    copyright            : (C) 2003-2006 by Alexey S.Parshin
    email                : alexeyp@gmail.com
 ***************************************************************************/

/***************************************************************************
   This library is free software; you can redistribute it and/or modify it 
   under the terms of the GNU Library General Public License as published by
   the Free Software Foundation; either version 2 of the License, or (at 
   your option) any later version.

   This library is distributed in the hope that it will be useful, but 
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
   General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; if not, write to the Free Software Foundation, 
   Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

   Please report all bugs and problems to "alexeyp@gmail.com"
 ***************************************************************************/

#ifdef __BORLANDC__
#include <vcl.h>
#pragma hdrstop
#endif

#include <FL/Fl.h>
#include <FL/Fl_Pixmap.h>
#include <stdio.h>

#include <sptk3/cgui>

using namespace std;
using namespace sptk;

void example_dialog_cb(Fl_Widget *w,void *) {
   CButton *btn = dynamic_cast<CButton *>(w);
   if (btn) 
      spInformation(string(btn->label())+" button was pressed.\nIt is different from <B>Ok</B> and <B>Cancel</B> buttons that are processed by default.");
}

void exit_cb(Fl_Widget *w,void *) {
   w->window()->hide();
}

class CExampleDialog : public CDialog {
public:
   CExampleDialog() : CDialog(300,250,"Example Dialog") {
      CInput *inp;

      newPage("Company",true);

      inp = new CInput("Company Name:");
      inp->fieldName("company_name");

      inp = new CIntegerInput("Company Size:");
      inp->fieldName("company_size");

      CComboBox *cb = new CComboBox("Business Type:");
      cb->fieldName("business_type");
      cb->addColumn("business type",VAR_STRING,120);
      cb->addRow(1,"Agriculture");
      cb->addRow(2,"Education");
      cb->addRow(3,"Hardware");
      cb->addRow(4,"Software");

      CDateInput* dateInput = new CDateInput("Established");
      dateInput->fieldName("established");

      newScroll("Contact Info",true);

      inp = new CInput("First Name:");
      inp->fieldName("first_name");

      inp = new CInput("Last Name:");
      inp->fieldName("last_name");

      inp = new CFloatInput("Age:");
      inp->fieldName("age");

      inp = new CMemoInput("Notes:",100);
      inp->fieldName("notes");

      addExtraButton(SP_SEND_BUTTON,"E-mail",example_dialog_cb);

      end();
   }

};

void dialog_cb(Fl_Widget *,void *) {
   CExampleDialog dialog;

   try {
      CDateTime now = CDateTime::Now();

      dialog["company_name"] = "Tiny Soft";
      dialog["company_size"] = 2;
      dialog["business_type"] = "Software";
      dialog["established"] = now;
      dialog["first_name"] = "John";
      dialog["last_name"] = "Doe";
      dialog["age"] = 35.2;
      dialog["notes"] = "Heavy duty worker. Family Guy. Good Friend.";
   }
   catch (exception& e) {
      puts(e.what());
   }

   if (dialog.showModal()) {
      cout <<
      (string) dialog["company_name"] << ", has " <<
      (int) dialog["company_size"] << " employees (" <<
      (string) dialog["business_type"] << "), established " <<
      (string) dialog["established"] << endl;
   }
}

int main(int argc,char *argv[]) {
   CWindow w(200,150);

   CButton b2(SP_EXIT_BUTTON);
   b2.callback(exit_cb);

   CButton b1(SP_EDIT_BUTTON,SP_ALIGN_RIGHT,"Show Dialog");
   b1.callback(dialog_cb);

   w.end();
   w.show();

   if (argc > 1) {
#ifdef _WIN32
      CThemes::set(argv[1]);
#else
      CThemes::set(argv[1]);
#endif
   }

   return Fl::run();
}
