/***************************************************************************
                          SIMPLY POWERFUL TOOLKIT (SPTK)
                               DEMO PROGRAMS SET
                          file_dialogs.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_ask.h>
#include <FL/Fl_Pixmap.h>
#include <stdio.h>

#include <locale.h>

#include <sptk3/cgui>
#include <sptk3/CFileOpenDialog.h>
#include <sptk3/CFileSaveDialog.h>
#include <sptk3/CDirOpenDialog.h>

using namespace sptk;

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

void file_open_dialog_cb(Fl_Widget *,void *) {
	CFileOpenDialog dialog;
	dialog.directory(".");
	dialog.addPattern("C++ Files","*.cpp;*.cxx");
	dialog.addPattern("VC++ Projects","*.dsp");
	dialog.fileName("file_dialog.cpp");
	if (dialog.execute())
       spInformation("Selected file:\n"+dialog.directory()+dialog.fileName());
}

void file_save_dialog_cb(Fl_Widget *,void *) {
	CFileSaveDialog dialog;
	dialog.directory(".");
	dialog.addPattern("C++ Files","*.cpp;*.cxx");
	dialog.addPattern("VC++ Projects","*.dsp");
    // Optionally, you can pre-select the file name
	// dialog.fileName("file_dialog.cpp");
	if (dialog.execute())
       spInformation("Selected file:\n"+dialog.directory()+dialog.fileName());
}

void dir_open_dialog_cb(Fl_Widget *,void *) {
	CDirOpenDialog dialog;
	dialog.directory(".");
	if (dialog.execute())
       spInformation("Selected directory:\n"+dialog.directory());
}

int main(int argc,char *argv[]) {

	CWindow w(200,150);

	CButton b1(SP_OPEN_BUTTON,SP_ALIGN_TOP,"Open File Dialog");
	b1.callback(file_open_dialog_cb);

	CButton b2(SP_SAVE_BUTTON,SP_ALIGN_TOP,"Save File Dialog");
	b2.callback(file_save_dialog_cb);

	CButton b3(SP_BROWSE_BUTTON,SP_ALIGN_TOP,"Open Directory Dialog");
	b3.callback(dir_open_dialog_cb);

	CButton b4(SP_EXIT_BUTTON,SP_ALIGN_BOTTOM);
	b4.callback(exit_cb);

    w.end();
	w.show(argc,argv);

	CThemes::set("OSX");

	return Fl::run();
}
