/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     2000/01/20
// RCS-ID:      $Id: eventeditor.h,v 1.4 2001/04/25 02:48:13 georgetasker Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:     wxWindows license
/////////////////////////////////////////////////////////////////////////////

#ifndef __EVENTEDITOR_G__
#define __EVENTEDITOR_G__

#include "wx/event.h"
#include "wx/dialog.h"
#include "wx/dynarray.h"
#include "wx/hash.h"
#include "wx/listbox.h"
#include "wx/textctrl.h"
#include "wx/choice.h"

#include "wx/pmf/pm.h"
#include "eventinfo.h"

class wxSourceCodeDocument;
class ResDocument;

// import
class GenSourceProcessor;

class EventEditorService : public wxEvtHandler, public wxPMService
{
public:
	EventEditorService();
	~EventEditorService();

	// overriden methods of wxPMService
	virtual bool Start();
	virtual bool Stop();
	virtual wxObject* GetWxObject();

	virtual wxPMMergableMenuChain* GetMergableMenuChain();


	// other methods
	GenSourceProcessor& GetSrcProcessor();

	void EditEventBody( const wxString& id, const wxString& eventMacro );

	// event handlers

	enum EVENT_EDITOR_COMMAND_IDS
	{
		ID_NEW_SOURCE = 100,
		ID_SOURCE_SETTINGS,
		ID_EDIT_EVENTS,
		ID_EDIT_MEMBERS,
		ID_EDIT_WIDGET,
		ID_EDIT_MENU
	};

	void OnNewSource( wxCommandEvent& event );
	void OnSourceSettings( wxCommandEvent& event );
	void OnEditEvents( wxCommandEvent& event );
	void OnEditMembers( wxCommandEvent& event );
	void OnEditWidget( wxCommandEvent& event );
	void OnEditMenu( wxCommandEvent& event );

	void OnNewSourceUI( wxUpdateUIEvent& event );
	void OnSourceSettingsUI( wxUpdateUIEvent& event );
	void OnEditEventsUI( wxUpdateUIEvent& event );
	void OnEditMembersUI( wxUpdateUIEvent& event );
	void OnEditWidgetUI( wxUpdateUIEvent& event );
	void OnEditMenuUI( wxUpdateUIEvent& event );

	DECLARE_DYNAMIC_CLASS( EventEditorService )
	DECLARE_EVENT_TABLE()

protected:
	void DoEditSource( bool editMembers );

	bool ValidateDocument();
	bool ValidateDocument( wxUpdateUIEvent& event );
	bool ProcessDocument();
	bool ScanRelatedDocument( const wxString& fname );
	bool NeedsHeaderFile( const wxString& fname );
	bool IsHeaderFile( const wxString& fname );

	wxSourceCodeDocument* FindSourceDocument( const wxString& fname );
	ResDocument* FindResourceDocument( const wxString& fname );

	void ApplySourceChanges();
	void ApplyChangesToFile( const wxString& fname, const wxString& sourceText );
	void GotoSourceLine( const wxString& fname, int line, int col );

protected:
	GenSourceProcessor* mpProc;
	wxString			mSource;
};

class SourceConfigInfo
{
public:
	wxString mResFile;
	wxString mMenu;
	wxString mWindow;
	wxString mTemplate;
	wxString mFName;
	wxString mClassName;
	wxPMDocument* mpResDoc;

	SourceConfigInfo();
};

class SourceConfigDialog : public wxDialog
{
public:
	SourceConfigDialog( wxWindow* pParent, SourceConfigInfo* pCfgInfo, 
						EventEditorService* pSvc,
						const wxString& dlgTitle, bool selectTemplate );

	~SourceConfigDialog();

	void OnTemplateSelected( wxCommandEvent& event );
	void OnResFileSelected( wxCommandEvent& event );
	void OnOkButton( wxCommandEvent& event );
	void ExchangeValuesBack();

	DECLARE_EVENT_TABLE()

	enum
	{
		ID_TEMPLATE_LIST = 200,
		ID_RES_FILE_LIST
	};

protected:
	bool ValidateValues();
	void RefillAll();
	void RefillResLists();
	void RefillResFileList();

protected:
	EventEditorService* mpSvc;
	SourceConfigInfo* mpCfgInfo;
	bool mSelectTemplate;

	wxListBox* mpTemplates;
	wxChoice* mpResFiles;
	wxChoice* mpMenus;
	wxChoice* mpWindows;
	wxTextCtrl* mpFName;
	wxTextCtrl* mpClassName;

};

#endif // __EVENTEDITOR_G__