// 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	  4
#define DONE_BUTTON		200
#define EDIT_PDESC		201
#define STATIC_202		202
#define STATIC_203		203

#define EDIT_PNUM		204


class NEdit : CEdit
{
	declare virtual OnChar( unsigned int nChar, int nRepCnt), int;
}

NEdit :: OnChar( unsigned int nChar, int nRepCnt), int
{		
	if(( nChar >= '0' && nChar <= '9' )||( nChar == 8 )) // decimal digits & backspace
		return false;
		
	int startsel, endsel, count;
	GetSel( startsel, endsel );
	string *text;
	int textlen;
	text = StrLower(GetText( ));
	nChar = ToAscii(StrLower(ToChar(nChar)));

	if(( nChar == '.' )||( nChar == ',' ))
		{
			// There can only be one '.' and it must be before the 'E'
			if( (StrFind( *text, "." ) == 0 ) && (StrFind( *text, "," ) == 0 ) 
					&& ( *text[startsel] != '+' ) && ( *text[startsel] != '-' ) )
				return false;
		}

	if( nChar == 'e' )
		{
			// There can only be one 'E', also, it can't be at the beginning of the number
			if( StrFind( *text, "e" ) == 0 && startsel != 0 )
				return false;
		}
		
	if( (nChar == '+') || (nChar == '-') )
		{
			count = StrFind(StrLeft(*text,1),"+") + sgn(StrFind(*text,"+",2))
							+ StrFind(StrLeft(*text,1),"-") + sgn(StrFind(*text,"-",2));
							
			// There can only a maximum of two (2) '+' or (2) '-' or one "+" and one "-"
			// and they must be at the beginning or behind an E
			if( (startsel == 0) && ((*text[0] != '+')&&(*text[0] != '-'))
					&& ( count < 2 ) )
				return false;

			if( (*text[startsel-1] == 'e') && (*text[startsel] != '+') && (*text[startsel] != '-')
						&& ( count < 2 ) )
				return false;
		}
	return true;
}


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;
	CEdit		*m_CEdit;

	// about pointers
	CButton		*m_abt_btn1;
	CStatic		*m_abt_txt;

	// project info pointers
	CControl	*m_proj_info[numProjectInfo];

	NEdit		NumEdit;	// numeric edit object used in limiting numeric input
}


TabDlg::OnClose(),int
{
	delete m_tab1;
	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);
	m_CEdit			= GetControl(EDIT_PNUM);

	// Initialize about pointers
	m_abt_txt	= GetControl(ABT_Static);
	m_abt_btn1	= GetControl(ABOUT_OK);

	// Initialize 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");

	// Show about
	m_abt_btn1->ShowWindow(SWSHOW);
	m_abt_txt->ShowWindow(SWSHOW);
	
	// Hide project info
	for ( i = 0; i < numProjectInfo; i++ )
		{ 
			m_proj_info[i]->ShowWindow(SWHIDE);
		}

	NumEdit.Create(Col2, TABHT+LSpc*3, 7*WTxt/4, LnHt, AES_LEFT, EDIT_PNUM, "", this);
	NumEdit.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);
							}
						NumEdit.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);
							}
						NumEdit.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);
					}
				NumEdit.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);
					}
				NumEdit.ShowWindow(SWHIDE);
				// about info
				m_tab1->SetFocusTab(0);
				m_abt_btn1->ShowWindow(SWSHOW);
				m_abt_txt->ShowWindow(SWSHOW);
			}

		case EDIT_PDESC:
	}
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 Number", Col0, TABHT+LSpc*3, WTxt, LnHt, StaticRght,0x0, STATIC_202);	
	AxiPile_Tabs.AddControl(CTBUTTON,"Done", Col5, TABHT+LSpc*1, Bttn_W, LnHt, 0x5000000B, 0x0, DONE_BUTTON);

	AxiPile_Tabs.DoModal();

return;
}
