
:void Wm_Size()
{
	#define	w_Prop	150
	#define	h_Out	120
	#define	h_Tab	32
	#define	h_Proj	250
	dword	h_Tbar, h_Sbar, h_Edit;
	RECT	Rct;

	SendMessage(hToolBar,TB_AUTOSIZE,0,0);
	MoveWindow(hStatus,0,0,0,0,TRUE);

	GetClientRect(hToolBar,#Rct);
	h_Tbar =	Rct.bottom;

	GetClientRect(hStatus,#Rct);
	h_Sbar =	Rct.bottom;

	GetClientRect(hWnd,#Rct);
	h_Edit = Rct.bottom - h_Tbar - h_Sbar;

	//	-----------------------------
	//	drop edit window by	2 pixels
	//	to display toolbar properly
	//	-----------------------------
	h_Tbar += 2;
	h_Edit -= 2;
	
	MoveWindow(hREd,w_Prop,h_Tbar+h_Tab,Rct.right-w_Prop,h_Edit-h_Out-h_Tab,TRUE);
	MoveWindow(hProject,0,h_Tbar+h_Tab,w_Prop,h_Proj,TRUE);
	MoveWindow(hProperty,0,h_Tbar+h_Tab+h_Proj,w_Prop,h_Edit-h_Tab-h_Proj,TRUE);
	MoveWindow(hOut,w_Prop,h_Tbar + h_Edit - h_Out,Rct.right-w_Prop,h_Out,TRUE);
	MoveWindow(hTab,0,h_Tbar,Rct.right,h_Tab,TRUE);
}
void	Wm_Create(dword	hWnd)
{
	Do_ToolBar(hWnd);
	Do_Status(hWnd);
		
	hREd = CreateWindowEx(WS_EX_CLIENTEDGE,#szRAEditClass,NULL,WS_CHILD	| WS_VISIBLE | STYLE_NOBACKBUFFER,0,0,0,0,hWnd,NULL,hInstance,0);
	hProperty =	CreateWindowEx(WS_EX_CLIENTEDGE,"LISTBOX",NULL,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_CHILD | WS_VISIBLE,0,0,0,0,hWnd,NULL,hInstance,0);
	hProject =	CreateWindowEx(WS_EX_CLIENTEDGE,"LISTBOX",NULL,LBS_SORT | LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_CHILD | WS_VISIBLE,0,0,0,0,hWnd,NULL,hInstance,0);
	hOut = CreateWindowEx(WS_EX_CLIENTEDGE,#szRAEditClass,NULL,WS_CHILD	| WS_VISIBLE | STYLE_NOBACKBUFFER |	STYLE_NOCOLLAPSE | STYLE_NOLINENUMBER,0,0,0,0,hWnd,NULL,hInstance,0);
	hTab = CreateWindowEx(WS_EX_WINDOWEDGE, WC_TABCONTROL ,NULL,WS_CHILD | WS_VISIBLE| WS_CLIPSIBLINGS ,0,0,0,0,hWnd,NULL,hInstance,0);
	
	lpfnhEditProc =	SendMessage(hREd, REM_SUBCLASS,0 ,#hEditProc);
	PropertyOldProc = SetWindowLong(hProperty,GWL_WNDPROC, #PropertyProc);
	ProjectOldProc = SetWindowLong(hProject,GWL_WNDPROC, #ProjectProc);
	hfDefault =	GetStockObject(DEFAULT_GUI_FONT);
	SendMessage(hREd, WM_SETFONT, hfDefault	,0);

	InitFileStruct(hWnd);
	lstrcpy(#FileName,#NewFile);			
		
	lstrcpy(#lfnt.lfFaceName,#szFont);
	lfnt.lfHeight =	-12;
	lfnt.lfWeight =	400;
	hLnrFont = CreateFontIndirect(#lfnt);
	hFont =	CreateFontIndirect(#lfnt);
	SendMessage(hProject,WM_SETFONT,hFont,0);
	SendMessage(hProperty,WM_SETFONT,hFont,0);
	SendMessage(hOut,WM_SETFONT,hFont,0);
	SendMessage(hTab,WM_SETFONT,hFont,0);
	
	SendMessage(hREd,REM_SETCHARTAB,3Bh,2);		// --- disable ; as	comment
	SendMessage(hREd,REM_SETCHARTAB,2Fh,6);		// --- enable // as	comment
	SetKeyWords(hREd);
	SetFormat(hREd);
	SendMessage(hREd,REM_SETCOLOR,0,#col);
	SendMessage(hWnd,WM_SIZE,0,0);
	TabToolAdd(hREd,#FileName);
	SetWinCaption(#FileName);
	SetFocus(hREd);
}

dword	Wm_Command(dword hREd,uMsg,	wParam,	lParam)
{
	int		wmId;
	
	wmId = LOWORD(wParam);
	PUSH	EDI
	switch (wmId)
	{
	case IDC_TBB_NEW:
	case IDM_FILE_NEW:
		CreateNew();
		break;			
	CASE IDC_TBB_OPEN:
	CASE IDM_FILE_OPEN:
		FileOpen();
		break;

	CASE IDC_TBB_SAVE:
	CASE IDM_FILE_SAVE:
		FileSave(hREd);
		break;
	case IDM_FILE_SAVEAS:
		FileSave(hREd);
		break;
	case IDM_FILE_SAVEALL:
		UpdateAll(SAVE_ALL);
		break;
	case IDM_FILE_CLOSE:
		Confirmation(hREd,#FileName);
		IF(EAX == IDYES) FileSave(hREd);
		IF(EAX == IDCANCEL)break;
		DestroyWindow(hREd);
		TabToolDel(hREd);
		Refresh();
		break;
	case IDM_FILE_EXIT:
		SendMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE,NULL);
		break;
	case IDC_TBB_UNDO:
	case IDM_EDIT_UNDO:
		SendMessage(hREd, EM_UNDO, 0, 0);
		break;
	case IDC_TBB_REDO:
		SendMessage(hREd, EM_REDO, 0, 0);
		break;
	case IDC_TBB_CUT:
	case IDM_EDIT_CUT:
		SendMessage(hREd,WM_CUT,0,0);
		break;
	case IDC_TBB_COPY:
	case IDM_EDIT_COPY:
		SendMessage(hREd, WM_COPY, 0, 0);
		break;
	case IDC_TBB_PASTE:
	case IDM_EDIT_PASTE:
		SendMessage(hREd,WM_PASTE,0,0);
		break;
	case IDC_TBB_FIND:
	case IDM_EDIT_FINDTEXT:
		DialogBoxParam(hInstance,frmFind,hWnd,#SearchProc,0);
		break;
	case IDM_EDIT_FINDNEXT:
		TextFind(hREd, #SearchText,	TextLen);
		break;
	case IDM_EDIT_SELECTALL:
		Select_All(hREd);
		break;
	case IDC_TBB_REPLACE:
//		DialogBoxParam(hInstance,frmReplace,hWnd,#ReplaceProc,0);
		MessageBox(hWnd, "Not Finish Yet", #AppName,MB_OK);
		break;
	case IDM_PROJECT_OPEN:
		OpenProject();
		break;
	case IDM_PROJECT_SAVE:
		SaveProject();
		break;
	case IDM_PROJECT_ADD:
		AddFile();
		break;
	case IDM_PROJECT_DEL:
		DelFile();
		break;
	case IDM_PROJECT_CLOSE:
		CloseProject();
		break;
	case IDC_TBB_COMPILE:
	case IDM_PROJECT_COMPILE:
		UpdateAll(SAVE_ALL);
		IF(ProjectName ==NULL) lstrcpy(#CompileName,#FileName);
		ELSE
		{
			lstrcpy(#CompileName,#ProjectName);
			RemoveFileExt(#CompileName);
			lstrcat(#CompileName,".c--");
		}
		Compiles(hWnd,hOut,#CompileName,Compile,TRUE);
		break;
	case IDC_TBB_RUN:
	case IDM_PROJECT_RUN:
		IF(ProjectName ==NULL) lstrcpy(#CompileName,#FileName);
		ELSE
			lstrcpy(#CompileName,#ProjectName);
		run(#CompileName);
		break;	
	case IDM_OPTION_FONT:
		SetFont(hWnd);
		break;
	case IDM_HELP_ABOUT:
		MessageBox(hWnd,#About,"C--IDE",MB_OK);
		break;
	case IDC_TBB_PRINT:
		MessageBox(hWnd, "This portion not complete yet. Anyone can help?",	"Print Dialog",	MB_OK);
		BREAK;
	case 0fffdh:
		SendMessage(hREd,REM_EXPANDALL,0,0);
		SendMessage(hREd,EM_SCROLLCARET,0,0);
		BREAK;
	case 0fffch:
		SendMessage(hREd,REM_COLLAPSEALL,0,#blocks);
		SendMessage(hREd,EM_SCROLLCARET,0,0);
		BREAK;

	default:
		POP		EDI
		RETURN DefWindowProc(hWnd, uMsg, wParam, lParam);
	}
	POP		EDI
}

void	Wm_Notify(dword	lParam)
{
	EDX	= lParam;
	EAX	= EDX.NMHDR.code;
	switch	(EAX)
	{
	case EN_SELCHANGE:
		EDI	= EDX;
		EAX	= EDI.RASELCHANGE.chrg.cpMin;
		sub		EAX, EDI.RASELCHANGE.cpLine
//		ShowPos(EDI.RASELCHANGE.line,EAX);
		if(EDI.RASELCHANGE.seltyp==SEL_OBJECT)
		{
			SendMessage(hREd,REM_GETBOOKMARK,EDI.RASELCHANGE.line,0);
			SWITCH	(EAX)
			{
			case 1:
				//Collapse
				SendMessage(hREd,REM_COLLAPSE,EDI.RASELCHANGE.line,#blocks);
/*				ESI	= #	blocks;
				EDX	= DSDWORD [ESI];
				while(EDX)
				{
					mov		EDX,EDX.RABLOCKDEF.lpszStart
					SendMessage(hREd,REM_ISLINE,EDI.RASELCHANGE.line,EDX);
					IF(EAX!=-1)
					{
						EDX	= DSDWORD [ESI];
						SendMessage(hREd,REM_COLLAPSE,EDI.RASELCHANGE.line,EDX);
						break;
					}
					ESI	+= 4;
					EDX	= DSDWORD [ESI];
				}
*/				BREAK;
			CASE 2:
				//Expand
				SendMessage(hREd,REM_EXPAND,EDI.RASELCHANGE.line,0);
				BREAK;
			CASE 8:
				//Expand hidden	lines
				SendMessage(hREd,REM_EXPAND,EDI.RASELCHANGE.line,0);
				BREAK;
			default:
				//Clear	bookmark
				SendMessage(hREd,REM_SETBOOKMARK,EDI.RASELCHANGE.line,0);
			}
		}
/*		else
		{
//			//Just to test REM_ISCHARPOS message
//			SendMessage,hREd,REM_ISCHARPOS,[EDI].RASELCHANGE.chrg.cpMin,0
//			if(EAX)
//				MessageBeep,0FFFFFFFFh
//			
			if(( EDI.RASELCHANGE.fchanged) && (!EDI.RASELCHANGE.nWordGroup))
			{
//				SendMessage(hREd,REM_SETCOMMENTBLOCKS,#	szCmntStart,# szCmntEnd);
			  OnceMore:
				SendMessage(hREd,REM_GETBOOKMARK,nLastLine,0);
				EBX	= EAX;
				ESI	= #	blocks;
				ECX	= DSDWORD [ESI];
				while(ECX)
				{
					mov		EDX,ECX.RABLOCKDEF.flag
					and		EDX,BD_DIVIDERLINE
					push	EDX
					mov		ECX,ECX.RABLOCKDEF.lpszStart
					SendMessage(hREd,REM_ISLINE,nLastLine,ECX);
					pop		EDX
					IF(EAX!=-1)	break;
					add		ESI,4
					mov		ECX,DSDWORD	[ESI]
				}
				if(EAX==-1)
				{
					if((EBX==1)	|| (EBX==2))
					{
						if(EBX==2)
							SendMessage(hREd,REM_EXPAND,nLastLine,0);
						SendMessage(hREd,REM_SETBOOKMARK,nLastLine,0);
						SendMessage(hREd,REM_SETDIVIDERLINE,nLastLine,FALSE);
					}
				}
				else
				{
					xor		EAX,EAX
					mov		ECX,DSDWORD	[ESI]
					test	ECX.RABLOCKDEF.flag,BD_NONESTING
					if(!ZERO?)
					{
						push	EDX
						SendMessage(hREd,REM_ISINBLOCK,nLastLine,ECX);
						pop		EDX
					}
					if(!EAX)
					{
						push	EDX
						mov		EDX,nLastLine
						inc		EDX
						SendMessage(hREd,REM_ISLINEHIDDEN,EDX,0);
						if(EAX)
							SendMessage(hREd,REM_SETBOOKMARK,nLastLine,2);
						else
							SendMessage(hREd,REM_SETBOOKMARK,nLastLine,1);
						POP		EDX
						SendMessage(hREd,REM_SETDIVIDERLINE,nLastLine,EDX);
					}
				}
				mov		EAX,EDI.RASELCHANGE.line
				if(EAX>nLastLine)
				{
					inc		nLastLine
					jmp		OnceMore
				}
				if(EAX<nLastLine)
				{
					dec		nLastLine
					jmp		OnceMore
				}
			}
			mov		EAX,EDI.RASELCHANGE.line
			mov		nLastLine,EAX
		}
		mov		fTimer,2
		break;
*/		BREAK;
	case TTN_NEEDTEXT:	//Toolbar tooltip
		EDX.TOOLTIPTEXT.lpszText = ToolTips(EDX.NMHDR.idFrom);
		BREAK;
	case TCN_SELCHANGE:
		TabToolActivate();
		break;
	}
	SendMessage(hREd,REM_SETCOMMENTBLOCKS,"/*","*/");
}
