/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     2000/02/08
// RCS-ID:      $Id: membereditor.h,v 1.4 2001/04/04 12:42:37 aleksandras Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:   	GPL (version 2.0 or later)
/////////////////////////////////////////////////////////////////////////////

#ifndef __MEMBEREDITOR_G__
#define __MEMBEREDITOR_G__

#include "wx/grid.h"
#include "wx/notebook.h"
#include "eventinfo.h"

class GenSourceProcessor;
class ResourceItemInfoListT;

enum
{
	ID_DELETE_FUN = 120,
	ID_ADD_FUN,
	ID_EDIT_CODE,

	ID_IDS_BOX,
	ID_EVENTS_BOX,
	ID_FUN_BOX,
};

class EventEditorPanel : public wxPanel
{
public:
	EventEditorPanel( wxWindow* pParent, 
					   const wxString& itemName,
					   ResourceItemInfo* pParentRes,
					   EventEntryInfo* pEntry,
					   EventEntryInfoListT* pEntries,
					   ResourceItemInfoListT* pResItems );
	~EventEditorPanel();

	void OnIDSelected( wxCommandEvent& event );
	void OnEventSelected( wxCommandEvent& event );
	void OnTableEntrySelected( wxCommandEvent& event );

	void OnAddFunction( wxCommandEvent& event );
	void OnDeleteFunction( wxCommandEvent& event );
	void OnEditCode( wxCommandEvent& event );

	void DiscardChanges();

	EventEntryInfo* GetSelectedEntry();

protected:
	void UpdateButtons( bool canRemove, bool canAdd );
	void RefillIdsBox();
	void RefillEventsBox();
	void RefillEntriesBox();
	wxString FormatEntryName( EventEntryInfo& entry );
	void AddEventToList( EventInfo& evt );
	void UnselectMethod();
	bool EventIsHandled( EventInfo& evt );

protected:
	DECLARE_EVENT_TABLE()

	wxListBox* mpIdsList;
	wxListBox* mpEventsList;
	wxListBox* mpEntriesList;

	wxButton*  mpAddBtn;
	wxButton*  mpDeleteBtn;
	wxButton*  mpEditBtn;

	EventInfoListT mCurEvents;
	EventInfo* mpCurEvent;
	EventInfo* mpSelectEvent;

	EventEntryInfo* mpSelectedEntry;
	EventEntryInfo* mpCurEntry;
	ResourceItemInfo* mpCurResInfo;

	ResourceItemInfoListT* mpResItems;
	EventEntryInfoListT* mpEntries;

	ResourceItemInfo* mpParentRes;

	EventEntryInfoListT mOriginalEntries;
};

class MemberEditorGrid : public wxGrid
{
public:
	MemberEditorGrid( wxWindow* pParent, 
					  GenSourceProcessor* pProc );
	~MemberEditorGrid();

	void DiscardChanges();

	// event handlers

	void OnCellLeftClick( wxGridEvent& event );
	void OnCellRightClick( wxGridEvent& event );
	void OnColSize( wxGridEvent& event );
	void OnCellValueChanged( wxGridEvent& event );

	void OnIdle( wxIdleEvent& event );
	void OnSize( wxSizeEvent& event );

	void OnChoice( wxCommandEvent& event );

	DECLARE_EVENT_TABLE()

protected:
	void AdjustColumnSizes();
	void RefillRow( int row );
	wxString GetDefautlValueForCell( int row, int col );
	bool IsReadOnlyColumn( int col );
	void SetItemValue( int row, int col, const wxString& value );

	enum COL_IDS
	{
		COL_RES_NAME = 0,
		COL_RES_CLASS,
		COL_CTL_MEMBER,
		COL_MEMBER_TYPE,
		COL_MEMBER,
		COL_MEMBER_INIT_VALUE,
		COL_GETTER,
		COL_SETTER,
		LAST_COLUMN = COL_SETTER
	};

	const wxColour READ_ONLY_CELL_BG;
	const wxColour EMPTY_CELL_BG;
	const wxColour FILLED_CELL_BG;

	void DecorateCell( int row, int col, bool isFilled, bool isReadOnly );

protected:
	GenSourceProcessor* mpProc;

	wxGridCellAttr* mpReadOnlyAttr;
	wxGridCellAttr* mpReadOnlyAttr1;
	wxGridCellAttr* mpEmptyAttr;
	wxGridCellAttr* mpFilledAttr;

	ResourceItemInfoListT* mpItems;
	ResourceItemInfoListT* mpOrignialItems;

	bool				   mLeftClicked;
	bool				   mApplyPending;
};

class SourceWizardDialog : public wxDialog
{
public:
	SourceWizardDialog( wxWindow* pParent, GenSourceProcessor* pProc, 
						ResourceItemInfo* pParentRes,
						bool showMembersPane );

	void OnEditCode( wxCommandEvent& event );
	void OnOk( wxCommandEvent& event );

	void OnSize( wxSizeEvent& event );

	MemberEditorGrid* GetMemberEditor();
	EventEditorPanel* GetEventEditor();

	DECLARE_EVENT_TABLE()

protected:
	GenSourceProcessor* mpProc;
	wxNotebook*			mpNotebook;
	wxButton*			mpApplyBtn;
	wxButton*			mpCancelBtn;

	MemberEditorGrid*   mpMemberEditor;
	EventEditorPanel*   mpEventEditor;
};

#endif // __MEMBEREDITOR_G__