/////////////////////////////////////////////////////////////////////////////
// Name:        No names yet.
// Purpose:     Contrib. demo
// Author:      Aleksandras Gluchovas
// Modified by:
// Created:     2000/02/08
// RCS-ID:      $Id: pm_prjtempl.h,v 1.2 2001/03/14 13:48:11 aleksandras Exp $
// Copyright:   (c) Aleksandras Gluchovas
// Licence:   	GPL (version 2.0 or later)
/////////////////////////////////////////////////////////////////////////////

#ifndef __PM_PRJTEMPL_G__
#define __PM_PRJTEMPL_G__

#include "wx/pmf/pm_gui.h"

#include "wx/dynarray.h"
#include "wx/dialog.h"

class wxPMProjectTypeTemplate;
class wxPMPrjCreatorItemData;

WX_DEFINE_ARRAY( wxPMProjectTypeTemplate*, PMProjectTypeTemplateListT );


/*
 * Completely custom compoenent, allows selectingn a type of new project
 * in a nice-looking dialog, presenting project-categories grouped
 * into a tree, where each leaf-item is "expanded" into a list of large
 * icons, Dialog also allows entry of name and directory for the new project
 */

class wxPMProjectCreatorDialog : public wxDialog
{
public:
	wxPMProjectCreatorDialog( wxWindow* pParent, 
							  const wxString& defaultName, 
							  const wxString& defaultDir,
							  bool createMasksForIamges = TRUE );

	wxPMProjectTypeTemplate* GetSelectedType();
	wxString GetProjectName();
	wxString GetDirectory();

	/*** static methods ***/

	// note: the ownership of the list elements is taken over here

	static void AddTemplates( PMProjectTypeTemplateListT& templates );
	static void RemoveAllTemplates();
	static PMProjectTypeTemplateListT& GetTemplates();

	static wxSize GetDialogLRUSize();
	static wxString GetLRUCategory();
	static void SetDefaultCategory( const wxString& cat );

	// event handlers

	void OnNew( wxCommandEvent& event );
	void OnCancel( wxCommandEvent& event );
	void OnHelp( wxCommandEvent& event );
	void OnBrowse( wxCommandEvent& event );
	void OnTreeItemSelected( wxTreeEvent& event );
	void OnText( wxCommandEvent& event );
	void OnSize( wxSizeEvent& event );

	enum EVENT_IDS
	{
		ID_NEW = 100,
		ID_HELP,
		ID_BROWSE,

		ID_NAME_TEXT,
		ID_CATEGORY_TREE,
	};

	DECLARE_EVENT_TABLE()

protected:
	wxString GetSubcategory( const wxString& category, size_t depth );

	wxPMPrjCreatorItemData* GetTreeDataForCategory( const wxString& category );

	virtual void LoadIcons( PMProjectTypeTemplateListT& templates );

	virtual size_t GetLastTokenLen( const wxString& text );
	virtual wxString ReplaceLastToken( const wxString& text, const wxString& newToken );


protected:
	wxString m_Directory;
	wxString m_Name;
	wxPMProjectTypeTemplate* m_pSelectedType;
	bool m_CreateMasks;

	wxTreeCtrl* m_pTree;
	wxListCtrl* m_pList;
	wxTextCtrl* m_pDescText;
	wxTextCtrl* m_pName;
	wxTextCtrl* m_pLocation;

	wxImageList* m_pCurImageList;
	wxImageList m_TreeImages;

	/*** static members ***/

	static PMProjectTypeTemplateListT m_Templates;

	static wxString m_LRUCategory;
	static wxSize   m_LRUDialogSize;

};

/*
 * appart from doc-template, this clas attributes addioanal
 * info about the project, which is then used by wxPMProjectCreatorDialog
 * to present the template in a more "atractive" ways
 */

class wxPMProjectTypeTemplate : public wxObject
{
public:
	wxPMProjectTypeTemplate( const wxString& category, const wxString& type,
							 const wxString& desc, const wxString& imageName,
							 wxDocTemplate* pDocTemplate  );

	wxString GetCategory();
	wxString GetType();
	wxString GetDescription();
	wxString GetImageName();
	wxDocTemplate* GetDocTemplate();

	wxBitmap& GetBitmap();

protected:
	wxString m_Category; // eg. "/Python/wxPython-Applications/";
	wxString m_Type;
	wxString m_Desc;
	wxString m_ImageName;
	wxBitmap m_Bmp;

	wxDocTemplate* m_pDocTemplate;
};

class wxPMPrjCreatorItemData : public wxTreeItemData
{
public:
	wxPMPrjCreatorItemData( const wxString& category = "" )

		: m_Category( category ) {}

	PMProjectTypeTemplateListT m_Templates;
	wxString m_Category;
};

/*
 * class used as a "surogate" document to be shown in 
 * the list of templates. When created, it automatically
 * displays wxPMProjectCreatorDialog for selection and
 * then creation of the actual project. The doc-tempalte
 * for this "document" can describe eg. as "Project".
 * Unlike for actual projects, template for this project
 * should have wxTEMPLATE_VISIBLE flag to allow selection
 * of it from wxWin's standard template-selection dialog
 */

class wxPMProjectCreatorTemplate : public wxDocTemplate
{
public:
    wxPMProjectCreatorTemplate(wxDocManager *manager,
							   const wxString& descr,
							   const wxString& filter,
							   const wxString& dir,
							   const wxString& ext,
							   const wxString& docTypeName,
							   const wxString& viewTypeName,
							   wxClassInfo *docClassInfo = (wxClassInfo *) NULL,
							   wxClassInfo *viewClassInfo = (wxClassInfo *)NULL,
							   long flags = wxDEFAULT_TEMPLATE_FLAGS);

	~wxPMProjectCreatorTemplate();

	// overriden method of wxDocTemplate
    virtual wxDocument *CreateDocument(const wxString& path, long flags = 0);
};

#endif // __PM_PRJTEMPL_G__