///////
/////// wxWorkshop's default configuration scripts
/////// used for generating source-code routines 
///////

// misc subscripts used from higher-level generation-rules

subscript = {

	name = event_entry_subscript
	content = 
[[	$(EVT_MACRO_NAME)( $(IF$(ID_1))XMLID("$(ID_1)"), $(END_IF)$(IF$(ID_2))XMLID("$(ID_2)"), $(END_IF)$(IF$(EVT_TYPE))$(EVT_TYPE), $(END_IF)$(CLASS_NAME)::$(METHOD_NAME) )
]]

}

subscript = {

	name = alt_impl_subscript
	content = [[
void $(CLASS_NAME)::$(METHOD_NAME)( $(EVENT_CLASS)& event )
{
}
]]
}

subscript = {

	name = py_event_entry_subscript
	content = 
[[	$(EVT_MACRO_NAME)( self, $(IF$(ID_1))XMLID("$(ID_1)"), $(END_IF)$(IF$(ID_2))XMLID("$(ID_2)"), $(END_IF)$(IF$(EVT_TYPE))$(EVT_TYPE), $(END_IF)$(CLASS_NAME)::$(METHOD_NAME) )
]]

}

subscript = {

	name = py_alt_impl_subscript
	content = [[
def $(METHOD_NAME)( self, event ):

]]
}

subscript = {

	name = event_method_imp_subscript
	content = 
[[$(@event_body_at[CUR_EVENT_NO,alt_impl_subscript])$(@inc_var[CUR_EVENT_NO])]]
}

subscript = {

	name = py_event_method_imp_subscript
	content = 
[[$(@event_body_at[CUR_EVENT_NO,py_alt_impl_subscript])$(@inc_var[CUR_EVENT_NO])]]
}

subscript = {

	name = event_method_decl_subscript
	content = 
[[	void $(METHOD_NAME)( $(EVENT_CLASS)& event );
]]
}

subscript = {

	name = file_info_subscript
	content = 
[[// { TEMPL = "$(TEMPL)" WND_RES = "$(WND_RES)" MENU_RES = "$(MENU_RES)" $(IF$(IS_HDR))IMP_FILE = "$(IMP_FILE)" $(END_IF)$(IF$(IS_IMP))DECL_FILE = "$(DECL_FILE)" $(END_IF)CLASS = "$(CLASS_NAME)" RES_FILE = "$(RES_FILE)" }
]]

}

subscript = {

	name = py_file_info_subscript
	content = 
[[# { TEMPL = "$(TEMPL)" WND_RES = "$(WND_RES)" MENU_RES = "$(MENU_RES)" $(IF$(IS_HDR))IMP_FILE = "$(IMP_FILE)" $(END_IF)$(IF$(IS_IMP))DECL_FILE = "$(DECL_FILE)" $(END_IF)CLASS = "$(CLASS_NAME)" RES_FILE = "$(RES_FILE)" }
]]

}

// ======================================================================== //

generation_rules = {

	name = "cpp_rules"
	
	// event-binding related tagged-block descriptions
	
	{
		tag = "EVT_TBL"
		collect_event_entries = true
		content = [[$(@event_list[event_entry_subscript])]]

	}
	
	{ 
		tag = "EVT_IMPS"
		collect_event_bodies = true
		content = 
[[$(@assign_var[CUR_EVENT_NO="0"])$(@event_list[event_method_imp_subscript])]]
		
	}
	
	{
		tag = "EVT_DECLS"
		content = [[$(@event_list[event_method_decl_subscript])]]
	}
	
	{
		tag = "INFO"
		content = [[$(@subscript[file_info_subscript])]]
	}
	
	// member-binding related tagged-block descriptions
	
	{
		tag = "MEMBER_DECLS"
		collect_members = true
		
		content = "$(@member_list[decl_source])"
	}
	{
		tag = "CTL_MEMBER_DECLS"
		collect_ctl_members = true
		
		content = "$(@member_list[ctl_decl_source])"
	}
	{
		tag = "MEMBER_INITS"
		content = "$(@member_list[init_source])"
	}
	{
		tag = "CTL_MEMBER_INITS"
		content = "$(@member_list[ctl_init_source])"
	}
	{
		tag = "MEMBER_VALUES_TO_CTL"
		content = "$(@member_list[to_ctl_source])"
	}
	{
		tag = "CTL_VALUES_TO_MEMBER"
		content = "$(@member_list[to_member_source])"
	}
	{
		tag = "GETTER_DECLS"
		collect_getters = true
		
		content = "$(@member_list[getter_decl_source])"
	}
	{
		tag = "SETTER_DECLS"
		collect_setters = true
		
		content = "$(@member_list[setter_decl_source])"
	}
	{
		tag = "GETTER_IMPLS"
		content = "$(@member_list[getter_imp_source])"
	}
	{
		tag = "SETTER_IMPLS"
		content = "$(@member_list[setter_imp_source])"
	}
}

///// now, the same for wxPython /////

generation_rules = {

	name = "python_rules"
	{
		tag = "EVT_TBL"
		collect_event_entries = true
		content = [[$(@event_list[py_event_entry_subscript])]]

	}
	
	{ 
		tag = "EVT_IMPS"
		collect_event_bodies = true
		content = 
[[$(@assign_var[CUR_EVENT_NO="0"])$(@event_list[py_event_method_imp_subscript])]]
		
	}
	
	{
		tag = "INFO"
		content = [[$(@subscript[py_file_info_subscript])]]
	}
}

///// some helper subscripts used in definition of "cpp_member_binding_rules" ////////

subscript = {
	name = ctl_decl_subscript
	content = [[	$(CTL_CLASS)* $(CTL_MEMBER_NAME); // { $(RES_NAME) $(CTL_MEMBER_NAME) }\n]]
}

subscript = {
	name = ctl_init_subscript
	content = [[	$(CTL_MEMBER_NAME) = ($(CTL_CLASS)*)FindWindow( XMLID( "$(RES_NAME)" ) );\n]]
}

subscript = {
	name = getter_name_hint
	content = "Get$(RES_NAME_FIRST_CAP)"
}

subscript = {
	name = setter_name_hint
	content = "Set$(RES_NAME_FIRST_CAP)"
}

subscript = {
	name = getter_decl_source
	content = [[	const $(TYPE)& $(GETTER_METHOD)() const; // { "$(RES_NAME)" $(GETTER_METHOD) }\n]]
}

subscript = {
	name = getter_imp_source
	content = [[const $(TYPE)& $(CLASS_NAME)::$(GETTER_METHOD)() const\n{ return $(MEMBER_NAME); }\n\n]]
}

subscript = {
	name = setter_decl_source
	content = [[	void $(SETTER_METHOD)( const $(TYPE)& value ); // { "$(RES_NAME)" $(SETTER_METHOD) }\n]]
}

subscript = {
	name = setter_imp_source
	content = [[void $(CLASS_NAME)::$(SETTER_METHOD)( const $(TYPE)& value )\n{ $(MEMBER_NAME) = value; }\n\n]]
}

subscript = {
	name = member_decl_subscript
	content = [[	$(TYPE) $(MEMBER_NAME); // { "$(RES_NAME)" $(TYPE) $(MEMBER_NAME) "$(INIT_VALUE)" }\n]]
}

// ======================================================================== //

binding_rules = {

	name = "cpp_member_binding_rules"
	
	{
		control_class = "wxTextCtrl"
		
		ctl_member_name_hint = "m_p$(RES_NAME_FIRST_CAP)"
		getter_name_hint = "Get$(RES_NAME_FIRST_CAP)"
		setter_name_hint = "Set$(RES_NAME_FIRST_CAP)"
		
		ctl_decl_source 	 = "$(@subscript[ctl_decl_subscript])"
		ctl_init_source		 = "$(@subscript[ctl_init_subscript])"
			
		can_have_member = true

		setter_name_hint   = "$(@subscript[setter_name_hint])"
		getter_name_hint   = "$(@subscript[getter_name_hint])"
		setter_decl_source = "$(@subscript[setter_decl_source])"
		getter_decl_source = "$(@subscript[getter_decl_source])"
		setter_imp_source  = "$(@subscript[setter_imp_source])"
		getter_imp_source  = "$(@subscript[getter_imp_source])"

		{
			bound_as = "wxString"
			
			member_name_hint = "m_$(RES_NAME_FIRST_CAP)"
			
    		decl_source = "$(@subscript[member_decl_subscript])"
    			
			init_source =
				[[	$(MEMBER_NAME) = _("$(INIT_VALUE)");\n]]
				
			to_ctl_source = 
				[[	$(CTL_MEMBER_NAME)->SetValue( $(MEMBER_NAME) );\n]]
				
			to_member_source = 
				[[	$(MEMBER_NAME) = $(CTL_MEMBER_NAME)->GetValue();\n]]
		}
			
		{
			bound_as = "double"
			
			member_name_hint = "m_$(RES_NAME_FIRST_CAP)"
			
    		decl_source = "$(@subscript[member_decl_subscript])"
    			
			init_source =
				[[	$(MEMBER_NAME) = $(INIT_VALUE);\n]]
				
			to_ctl_source = 
				[[	$(CTL_MEMBER_NAME)->SetValue( wxString() << $(MEMBER_NAME) );\n]]
				
			to_member_source = 
				[[	sscanf( $(CTL_MEMBER_NAME)->GetValue(), "%f", &$(MEMBER_NAME) );\n]]
		}

		{
			bound_as = "int"
			
			member_name_hint = "m_$(RES_NAME_FIRST_CAP)"
			
    		decl_source = "$(@subscript[member_decl_subscript])"
    			
			init_source =
				[[	$(MEMBER_NAME) = $(INIT_VALUE);\n]]
				
			to_ctl_source = 
				[[	$(CTL_MEMBER_NAME)->SetValue( wxString() << $(MEMBER_NAME) );\n]]
				
			to_member_source = 
				[[	sscanf( $(CTL_MEMBER_NAME)->GetValue(), "%d", &$(MEMBER_NAME) );\n]]
		}

		{
			bound_as = "long"
			
			member_name_hint = "m_$(RES_NAME_FIRST_CAP)"
			
    		decl_source = "$(@subscript[member_decl_subscript])"
    			
			init_source =
				[[	$(MEMBER_NAME) = $(INIT_VALUE);\n]]
				
			to_ctl_source = 
				[[	$(CTL_MEMBER_NAME)->SetValue( wxString() << $(MEMBER_NAME) );\n]]
				
			to_member_source = 
				[[	sscanf( $(CTL_MEMBER_NAME)->GetValue(), "%d", &$(MEMBER_NAME) );\n]]
		}
	}
	
	{
		control_class = "wxCheckBox"
		
		ctl_member_name_hint = "m_p$(RES_NAME_FIRST_CAP)"
		getter_name_hint = "Get$(RES_NAME_FIRST_CAP)"
		setter_name_hint = "Set$(RES_NAME_FIRST_CAP)"

		ctl_decl_source 	 = "$(@subscript[ctl_decl_subscript])"
		ctl_init_source		 = "$(@subscript[ctl_init_subscript])"
		
		can_have_member = true
		
		setter_name_hint   = "$(@subscript[setter_name_hint])"
		getter_name_hint   = "$(@subscript[getter_name_hint])"
		setter_decl_source = "$(@subscript[setter_decl_source])"
		getter_decl_source = "$(@subscript[getter_decl_source])"
		setter_imp_source  = "$(@subscript[setter_imp_source])"
		getter_imp_source  = "$(@subscript[getter_imp_source])"

		{
			bound_as = "bool"
			
			member_name_hint = "m_$(RES_NAME_FIRST_CAP)"
			
    		decl_source = "$(@subscript[member_decl_subscript])"
    			
			init_source =
				[[	$(MEMBER_NAME) = $(INIT_VALUE);\n]]
				
			to_ctl_source = 
				[[	$(CTL_MEMBER_NAME)->SetValue( $(MEMBER_NAME) );\n]]
				
			to_member_source = 
				[[	$(MEMBER_NAME) = $(CTL_MEMBER_NAME)->GetValue(), "%f", &$(MEMBER_NAME) );\n]]
		}

		{
			bound_as = "wxString"
			
			member_name_hint = "m_$(RES_NAME_FIRST_CAP)"
			
    		decl_source = "$(@subscript[member_decl_subscript])"
    			
			init_source =
				[[	$(MEMBER_NAME) = _("$(INIT_VALUE)");\n]]
				
			to_ctl_source = 
				[[	$(CTL_MEMBER_NAME)->SetValue( $(MEMBER_NAME) == "true" );\n]]
				
			to_member_source = 
				[[	$(MEMBER_NAME) = $(CTL_MEMBER_NAME)->GetValue() ? "true" : "false";\n]]
		}
	}

	{
		control_class = "wxButton"
		
		ctl_member_name_hint = "m_p$(RES_NAME_FIRST_CAP)"

		ctl_decl_source      = "$(@subscript[ctl_decl_subscript])"
		ctl_init_source      = "$(@subscript[ctl_init_subscript])"
		
		can_have_member = false
		
		// no variable bounding rules for wxButton (only ctontrol-pointer binding)
	}
	
	// END of binding_rules (cpp)	
}	

// ======================================================================== //

source_template = {
	
	name = "Dialog for C++"
	language = "C++"
	has_header = true
	header_ext = ".h"
	imp_ext = ".cpp"
	rules = cpp_rules
	binding_rules = cpp_member_binding_rules
	
	header_source = 
		[[$(@assign_var[BASE_CLASS="wxDialog"])$(@subscript[cpp_header_subscript])]]

	implementation_source = 
		[[$(@assign_var[BASE_CLASS="wxDialog"])$(@subscript[cpp_implementation_subscript])]]
}

// ======================================================================== //

source_template = {
	
	name = "MainFrame for C++"
	language = "C++"
	has_header = true
	header_ext = ".h"
	imp_ext = ".cpp"
	rules = cpp_rules
	binding_rules = cpp_member_binding_rules
	
	header_source = 
		[[$(@assign_var[BASE_CLASS="wxFrame"])$(@subscript[cpp_header_subscript])]]

	implementation_source = 
		[[$(@assign_var[BASE_CLASS="wxFrame"])$(@subscript[cpp_implementation_subscript])]]
}

// ======================================================================== //

source_template = {
	
	name = "wxWindows C++ Application"
	language = "C++"
	has_header = true
	header_ext = ".h"
	imp_ext = ".cpp"
	rules = cpp_rules
	binding_rules = cpp_member_binding_rules
	
	header_source = 
		[[$(@assign_var[BASE_CLASS="wxFrame"])$(@subscript[cpp_header_subscript])]]

	implementation_source = 
		[[$(@assign_var[BASE_CLASS="wxFrame"])$(@subscript[cpp_implementation_subscript])]]
}    

// ======================================================================== //

// ======================================================================== //

source_template = {
	
	name = "wxPython application (experimental)"
	language = "Python"
	has_header = FALSE
	imp_ext = ".py"
	rules = python_rules
	binding_rules = cpp_member_binding_rules // TBD:: bindings for Python!
	
	implementation_source = 
		[[$(@assign_var[BASE_CLASS="wxFrame"])$(@subscript[py_implementation_subscript])]]
}

// ======================================================================== //

source_template = {
	
	name = "My template (C++)"
	language = "C++"
	has_header = true
	header_ext = ".h"
	imp_ext = ".cpp"
	rules = cpp_rules
	
	header_source = 
		[[$(@assign_var[BASE_CLASS="wxFoo"])$(@subscript[cpp_header_subscript])]]

	implementation_source = 
		[[$(@assign_var[BASE_CLASS="wxFoo"])$(@subscript[cpp_implementation_subscript])]]
}    

// ======================================================================== //

subscript = {

	name = source_heading_comments
	content = 
[[/////////////////////////////////////////////////////////////////////////////
// Name:        $(FNAME)
// Purpose:     
// Author:      
// Modified by:
// Created:     $(DATE)
// RCS-ID:      $Id: config_srctempl.txt,v 1.1.1.1 2000/12/23 00:35:21 aleksandras Exp $
// Copyright:   (c) 
// Licence:   	
/////////////////////////////////////////////////////////////////////////////
]]
}

// ======================================================================== //

subscript = {

	name = py_source_heading_comments
	content = 
[[#---------------------------------------------------------------------------
# Name:        $(FNAME)
# Purpose:     
# Author:      
# Modified by:
# Created:     $(DATE)
# RCS-ID:      $Id: config_srctempl.txt,v 1.1.1.1 2000/12/23 00:35:21 aleksandras Exp $
# Copyright:   (c) 
# Licence:   	
#---------------------------------------------------------------------------
]]
}

// ======================================================================== //
	
subscript = {

	name = cpp_header_subscript
	content =
[[#ifndef __$(FNAME_CAPITALIZED)_G__
#define __$(FNAME_CAPITALIZED)_G__

#include "wx/wx.h"

// %%INFO-{
$(@subscript[file_info_subscript])
// %%INFO-}

class $(CLASS_NAME) : public $(BASE_CLASS)
{
public:
	$(CLASS_NAME)( wxWindow* parent );
	~$(CLASS_NAME)();

	void ExchangeValues( bool toControls );
	
	// %%EVT_DECLS-{
	// %%EVT_DECLS-}	

	// %%GETTER_DECLS-{
	// %%GETTER_DECLS-}

	// %%SETTER_DECLS-{
	// %%SETTER_DECLS-}
	
	DECLARE_EVENT_TABLE()

protected:
	// %%MEMBER_DECLS-{
	// %%MEMBER_DECLS-}

	// %%CTL_MEMBER_DECLS-{
	// %%CTL_MEMBER_DECLS-}
};

#endif // __$(FNAME_CAPITALIZED)_G__
]]

}

// ======================================================================== //

subscript = {

	name = cpp_implementation_subscript
	content =
[[$(@subscript[source_heading_comments])

// %%INFO-{
$(@subscript[file_info_subscript])
// %%INFO-}

#ifdef __GNUG__
    #pragma implementation "$(IMP_FILE)"
    #pragma interface "$(DECL_FILE)"
#endif

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif

#include "$(DECL_FILE)"
#include "wx/xml/xmlres.h"
#include "wx/xml/xml.h"

/***** Implementation for class $(CLASS_NAME) *****/

BEGIN_EVENT_TABLE( $(CLASS_NAME), $(BASE_CLASS) )

// %%EVT_TBL-{
// %%EVT_TBL-}

END_EVENT_TABLE()

$(CLASS_NAME)::$(CLASS_NAME)( wxWindow* parent )

	: $(BASE_CLASS( parent, -1 )
{
    wxTheXmlResource->LoadPanel( this, NULL, "$(WND_RES)" );
    
	// %%MEMBER_INITS-{
	// %%MEMBER_INITS-}

	// %%CTL_MEMBER_INITS-{
	// %%CTL_MEMBER_INITS-}
	
	ExchangeValues( TRUE );	
}

$(CLASS_NAME)::~$(CLASS_NAME)()
{
}

void $(CLASS_NAME)::ExchangeValues( bool toControls )
{
	if ( toControls )
	{
	// %%MEMBER_VALUES_TO_CTL-{
	// %%MEMBER_VALUES_TO_CTL-}
	}
	else
	{
	// %%CTL_VALUES_TO_MEMBER-{
	// %%CTL_VALUES_TO_MEMBER-}
	}
}

// %%EVT_IMPS-{
// %%EVT_IMPS-}

// %%GETTER_IMPLS-{
// %%GETTER_IMPLS-}

// %%SETTER_IMPLS-{
// %%SETTER_IMPLS-}
]]
}


// ======================================================================== //

subscript = {

	name = py_implementation_subscript
	content =
[[#!/usr/bin/python

from wxPython.wx import *

$(@subscript[py_source_heading_comments])

# %%INFO-{
$(@subscript[py_file_info_subscript])
# %%INFO-}

class $(CLASS_NAME)($(BASE_CLASS)):
    def __init__(self, parent, id, title=''):
        $(BASE_CLASS).__init__(self, parent, id, title, wxPyDefaultPosition,
                         wxPyDefaultSize )

        self.mainmenu = wxMenuBar()

# %%EVT_TBL-{
# %%EVT_TBL-}

# %%EVT_IMPS-{
# %%EVT_IMPS-}

# if running standalone

if __name__ == '__main__':
    class MyApp(wxApp):
        def OnInit(self):
            frame = $(CLASS_NAME)(NULL, -1, "wxPython application")
            frame.Show(true)
            self.SetTopWindow(frame)
            return true

    app = MyApp(0)
    app.MainLoop()

]]
}