
///////////////////////////////////////////////////////////
//                                                       //
//                         SAGA                          //
//                                                       //
//      System for Automated Geoscientific Analyses      //
//                                                       //
//                    User Interface                     //
//                                                       //
//                    Program: SAGA                      //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//                 VIEW_Table_Control.h                  //
//                                                       //
//          Copyright (C) 2005 by Olaf Conrad            //
//                                                       //
//-------------------------------------------------------//
//                                                       //
// This file is part of 'SAGA - System for Automated     //
// Geoscientific Analyses'. SAGA is free software; you   //
// can redistribute it and/or modify it under the terms  //
// of the GNU General Public License as published by the //
// Free Software Foundation, either version 2 of the     //
// License, or (at your option) any later version.       //
//                                                       //
// SAGA 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 General Public        //
// License for more details.                             //
//                                                       //
// You should have received a copy of the GNU General    //
// Public License along with this program; if not, see   //
// <http://www.gnu.org/licenses/>.                       //
//                                                       //
//-------------------------------------------------------//
//                                                       //
//    contact:    Olaf Conrad                            //
//                Institute of Geography                 //
//                University of Hamburg                  //
//                Germany                                //
//                                                       //
//    e-mail:     oconrad@saga-gis.org                   //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Control_H
#define _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Control_H


///////////////////////////////////////////////////////////
//                                                       //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#include <wx/grid.h>


///////////////////////////////////////////////////////////
//                                                       //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
class CVIEW_Table_Control : public wxGrid
{
	DECLARE_CLASS(CVIEW_Table_Control)

public:
	CVIEW_Table_Control(wxWindow *pParent, class CSG_Table *pTable, int Constraint);
	virtual ~CVIEW_Table_Control(void);

	bool						Load				(const wxString &File_Name);
	bool						Save				(const wxString &File_Name, int Format = 0);

	bool						Update_Table		(void);
	bool						Update_Selection	(void);

	bool						Update_Float_Format	(void);

	virtual wxGridCellRenderer * GetDefaultRendererForCell  (int row, int col)  const;


protected:

	void						On_Selecting		(wxGridRangeSelectEvent &event);
	void						On_Selected			(wxGridRangeSelectEvent &event);

	void						On_Changed			(wxGridEvent &event);

	void						On_LClick			(wxGridEvent &event);
	void						On_LDClick			(wxGridEvent &event);
	void						On_LClick_Label		(wxGridEvent &event);
	void						On_LDClick_Label	(wxGridEvent &event);

	void						On_RClick			(wxGridEvent &event);
	void						On_RClick_Label		(wxGridEvent &event);

	void						On_Command			(wxCommandEvent  &event);
	void						On_Command_UI		(wxUpdateUIEvent &event);

	bool						On_Selection_Show	(void);
	bool						On_Selection_Clear	(void);

	bool						On_Cell_Open_App	(void);
	bool						On_Cell_Open_Data	(void);

	bool						On_Field_Add		(void);
	bool						On_Field_Move		(void);
	bool						On_Field_Del		(void);
	bool						On_Field_Hide		(void);
	bool						On_Field_Sort		(void);
	bool						On_Field_Rename		(void);
	bool						On_Field_Type		(void);
	bool						On_Field_Calc		(void);
	bool						On_Field_Geometry	(void);


private:

	int							m_Cursor;

	CSG_Table					*m_pTable;

	class CVIEW_Table_Data		*m_pData;

	CSG_Parameters				m_Field_Calc;


	bool						_Update_Records		(bool bViews = false);

	bool						_Update_Selection	(bool bViews = false);

	static int					_Parameter_Callback	(CSG_Parameter *pParameter, int Flags);


	DECLARE_EVENT_TABLE()
};


///////////////////////////////////////////////////////////
//                                                       //
//                                                       //
//                                                       //
///////////////////////////////////////////////////////////

//---------------------------------------------------------
#endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__VIEW_Table_Control_H
