// Tab_NEdit.src
// modifies CEdit to limit input to numbers and decimals "."

#define TAB_1		  1
#define PROG_TITLE "AxiPile (c)2007  -  compiled: 03/03/07"

#define WIDTH  		500
#define HEIGHT 		480
#define TABHT		 70

#define DwgWidth	320
#define DwgHeight	HEIGHT-TABHT-20
#define BrickWdth	DwgWidth-10
#define BrickHt		DwgHeight-30

#define LnHt		 20
#define LSpc		  5 * LnHt / 4
#define CntrlW		 70
#define Bttn_W		 50
#define WTxt		120
#define SPIN		 30
#define SCHEM_w		 80

#define Col0 40
#define Col1 125
#define Col2 170
#define Col3 230
#define Col4 300
#define Col5 400
#define Col6 480

#define StaticLeft   0x50000000   // multiline left justify
#define StaticCntr   0x50000001   // multiline center justify
#define StaticRght   0x50000002   // multiline right justify


// About
#define ABT_Static	101
#define ABOUT_OK	102
#define ABT_Text_11 "AxiPile (c) 2007\n\nUniversity of Nevada, Reno\n\nJohn M. Siino,\nSherif Elfass\nand\nGary Norris"
#define ABT_W 200
#define ABT_H 160


// Project Info
#define numProjectInfo	  5
#define DONE_BUTTON		200
#define EDIT_PDESC		201
#define EDIT_PNUM		202
#define STATIC_203		203
#define STATIC_204		204



DECLARE IMPORT,SetPropA(hwnd as unsigned int,lpString as STRING,hData as unsigned int),INT;

class NEdit : CEdit
{
	declare checkChar( unsigned int ch )
	{
		int startsel, endsel;
		string *text;
		int textlen;
		
		GetSel( startsel, endsel );
		text = GetText( );
		
		if( ch >= '0' && ch <= '9' ) // decimal digits
			return false;
		if( ch == 8 ) // backspace
			return false;
		if( ch == '.' )
		{
			// Is there already a '.'? Only accept one.
			if( strfind( *text, "." ) == 0 ) 
				return false;
		}
		if( ch == 'e' || ch == 'E' )
		{
			// There can only be one 'E'
			// Also, it can't be at the beginning of the number
			if( strfind( *text, "E" ) == 0 && strfind( *text, "e" ) == 0 && startsel != 0 )
				return false;
		}
		if( ch == '+' || ch == '-' )
		{
			// There must be an 'E' before this, or it must be at the beginning
			if( startsel == 0 ) return false;
			if( *text[startsel - 1] == 'E' || *text[startsel - 1] == 'e' ) return false;
		}
		return true;
	}
	
	declare virtual OnChar(unsigned int nChar, int nRepCnt), int
	{
		return checkChar( nChar );
	}
}

class TabDlg : CDialog
{
	declare OnInitDialog(),int;
	declare OnClose(),int;
	declare OnControl(int nID, int nNotifyCode, unsigned int hControl), int;

	//member pointers to copy the control class pointers into.
	CTabCtrl *m_tab1;

	NEdit    *m_NEdit;		// generic edit pointer used in testing/correcting numeric input
	CEdit    *m_CEdit;

	// about pointers
	CButton  *m_abt_btn1;
	CStatic  *m_abt_txt;

	// project info pointers
	CControl *m_proj_info[numProjectInfo];
}


TabDlg::OnClose(),int
{

	delete m_tab1;
	delete m_NEdit;
	delete m_CEdit;
	
	delete m_abt_btn1;
	delete m_abt_txt;

	for(i = 0; i<4; i++)
	{
		delete m_proj_info[i];
	}

	CloseDialog(TAB_1);
return true;
}


// 	Initialize all objects, pointers and controls (objects, tabs, etc.)
TabDlg::OnInitDialog(), int
{
	m_tab1			= GetControl(TAB_1);

	TotalDepth		= 10;


	m_NEdit			= new(NEdit, 1);
	m_CEdit			= GetControl(EDIT_PNUM);
	m_NEdit->m_hWnd	= m_CEdit->m_hWnd;
	SetPropA(m_NEdit->m_hWnd,"THIS",m_NEdit+0);
	
	// about pointers
	m_abt_txt	= GetControl(ABT_Static);
	m_abt_btn1	= GetControl(ABOUT_OK);

	// project info pointers
	for ( int i = 0; i < numProjectInfo; i++ )
		{ 
			m_proj_info[i] = GetControl(200+i);
		}

	// Initialize any controls here
		m_tab1->SetFont("Arial",10,400,0);
		m_tab1->SetColor(RGB(0,0,0), RGB(255,255,255));
		m_tab1->InsertTab(0,"About");
		m_tab1->InsertTab(1,"Project Info");

	// about
		m_abt_btn1->ShowWindow(SWSHOW);
		m_abt_txt->ShowWindow(SWSHOW);
	// project info
		for ( i = 0; i < numProjectInfo; i++ )
			{ 
				m_proj_info[i]->ShowWindow(SWHIDE);
			}

	CenterWindow();

return true;
}


TabDlg::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
	select nID
	{
		case TAB_1:
			if(nNotifyCode = TCNSELCHANGE)
			{
				nTab = m_tab1->GetSelectedTab();

				select (nTab)				// 	start Tab tests
				{
					case 0:
						// about
						m_abt_btn1->ShowWindow(SWSHOW);
						m_abt_txt->ShowWindow(SWSHOW);

						// project info
						for ( i = 0; i < numProjectInfo; i++ )
							{ 
								m_proj_info[i]->ShowWindow(SWHIDE);
							}

					case 1:
						// about
						m_abt_btn1->ShowWindow(SWHIDE);
						m_abt_txt->ShowWindow(SWHIDE);
						// project info
						for ( i = 0; i < numProjectInfo; i++ )
							{ 
								m_proj_info[i]->ShowWindow(SWSHOW);
							}
				}
			}
			return false;

		// 	start About Tab tests
		case ABOUT_OK:				// button clicked
			if(nNotifyCode = 0)
			{
				// about
				m_abt_btn1->ShowWindow(SWHIDE);
				m_abt_txt->ShowWindow(SWHIDE);
				// project info tab
				m_tab1->SetFocusTab(1);
				for ( i = 0; i < numProjectInfo; i++ )
					{ 
						m_proj_info[i]->ShowWindow(SWSHOW);
					}
			}


		// 		start Project Info Tab tests
		case DONE_BUTTON:			// button clicked
			if(nNotifyCode = 0)
			{
				// project info
				for ( i = 0; i < numProjectInfo; i++ )
					{ 
						m_proj_info[i]->ShowWindow(SWHIDE);
					}
				// about info
				m_tab1->SetFocusTab(0);
				m_abt_btn1->ShowWindow(SWSHOW);
				m_abt_txt->ShowWindow(SWSHOW);
			}
	}

return true;
}


global sub main()
{
	TabDlg AxiPile_Tabs;

	AxiPile_Tabs.Create(0, 0, WIDTH+DwgWidth, HEIGHT+20, 0x80C80080, 0, PROG_TITLE, 0);

	AxiPile_Tabs.AddControl(CTTABCTRL, "", 2, 32, WIDTH+DwgWidth-4, HEIGHT-24, 0x54000000, 0x0, TAB_1);

	// About Tab
	AxiPile_Tabs.AddControl(CTSTATIC, ABT_Text_11, WIDTH/2-ABT_W/2, HEIGHT/2-ABT_H/2, ABT_W, ABT_H, 0x50000101, 0x0, ABT_Static);
	AxiPile_Tabs.AddControl(CTBUTTON, "OK", WIDTH/2-Bttn_W/2, HEIGHT/2+ABT_H/2+LnHt, Bttn_W, LnHt, 0x5000000B, 0x0, ABOUT_OK);

	// Project Info Tab
	AxiPile_Tabs.AddControl(CTSTATIC,"Description", Col0, TABHT+LSpc*1, WTxt, LnHt, StaticRght,0x0, STATIC_203);
	AxiPile_Tabs.AddControl(CTEDIT,"", Col2, TABHT+LSpc*1, 7*WTxt/4, LnHt+LSpc, 0x50A10004, 0x200, EDIT_PDESC);
	
	AxiPile_Tabs.AddControl(CTSTATIC,"Project Name", Col0, TABHT+LSpc*3, WTxt, LnHt, StaticRght,0x0, STATIC_204);
	AxiPile_Tabs.AddControl(CTEDIT,"", Col2, TABHT+LSpc*3, 7*WTxt/4, LnHt, 0x50810000, 0x200, EDIT_PNUM);

	AxiPile_Tabs.AddControl(CTBUTTON,"Done", Col5, TABHT+LSpc*1, Bttn_W, LnHt, 0x5000000B, 0x0, DONE_BUTTON);

	AxiPile_Tabs.DoModal();

return;
}
