/*  $Id: filedialog.cpp,v 1.16 2004/01/11 02:05:25 mbn Exp $
**
**  ClanLib Game SDK
**  Copyright (C) 2003  The ClanLib Team
**  For a total list of contributers see the file CREDITS.
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 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
**  Lesser General Public License for more details.
**
**  You should have received a copy of the GNU Lesser 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
**
*/

#include "precomp.h"
#include "API/GUI/filedialog.h"
#include "API/GUI/stylemanager.h"
#include "API/Core/XML/dom_element.h"
#include "filedialog_generic.h"

/////////////////////////////////////////////////////////////////////////////
// Construction:

CL_FileDialog::CL_FileDialog(
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Window(parent, style), impl(NULL)
{
	impl = new CL_FileDialog_Generic(this, "", "", "*");
}

CL_FileDialog::CL_FileDialog(
	const std::string &title,
	const std::string &file,
	const std::string &filter,
	CL_Component *parent,
	CL_StyleManager *style)
: CL_Window(parent, style), impl(NULL)
{
	impl = new CL_FileDialog_Generic(this, title, file, filter);
}

CL_FileDialog::~CL_FileDialog()
{
	delete impl;
}

const std::string CL_FileDialog::open(
	CL_Component *parent)
{
	CL_FileDialog filedialog("Open File", "", "*.*", parent);
	filedialog.run();

	return filedialog.get_file();
}

const std::string CL_FileDialog::open(
	const std::string &file,
	const std::string &filter,
	CL_Component *parent)
{
	CL_FileDialog filedialog("Open File", file, filter, parent);
	filedialog.run();

	return filedialog.get_file();
}

const std::string CL_FileDialog::save(
	CL_Component *parent)
{
	CL_FileDialog filedialog("Save File", "", "*.*", parent);
	filedialog.run();

	return filedialog.get_file();
}

const std::string CL_FileDialog::save(
	const std::string &file,
	const std::string &filter,
	CL_Component *parent)
{
	CL_FileDialog filedialog("Save File", file, filter, parent);
	filedialog.run();

	return filedialog.get_file();
}

/////////////////////////////////////////////////////////////////////////////
// Attributes:

const std::string &CL_FileDialog::get_file() const
{
	return impl->get_file();
}

const std::string &CL_FileDialog::get_filter() const
{
	return impl->get_filter();
}

const std::string &CL_FileDialog::get_dir() const
{
	return impl->get_dir();
}

const std::string &CL_FileDialog::get_path() const
{
	return impl->get_path();
}

bool CL_FileDialog::is_hidden_files_visible() const
{
	return impl->is_hidden_files_visible();
}

/////////////////////////////////////////////////////////////////////////////
// Operations:

void CL_FileDialog::set_file(const std::string &filename)
{
	impl->set_file(filename);
}

void CL_FileDialog::set_dir(const std::string &dir)
{
	impl->set_dir(dir);
}

void CL_FileDialog::set_filter(const std::string &filter)
{
	impl->set_filter(filter);
}

void CL_FileDialog::show_hidden_files(bool enable)
{
	impl->show_hidden_files(enable);
}

void CL_FileDialog::refresh()
{
	impl->refresh();
}

/////////////////////////////////////////////////////////////////////////////
// Signals:

CL_Signal_v1<const std::string &> &CL_FileDialog::sig_file_highlighted()
{
	return impl->sig_file_highlighted;
}

CL_Signal_v1<const std::string &> &CL_FileDialog::sig_file_selected()
{
	return impl->sig_file_selected;
}

CL_Signal_v1<const std::string &> &CL_FileDialog::sig_dir_entered()
{
	return impl->sig_dir_entered;
}
