Index: trunk/ab5.0/abdev/abdev/WindowControl.cpp
===================================================================
--- trunk/ab5.0/abdev/abdev/WindowControl.cpp	(revision 624)
+++ trunk/ab5.0/abdev/abdev/WindowControl.cpp	(revision 625)
@@ -13,15 +13,16 @@
 #endif
 
-int GetWndInfoNum(char *name){
+int GetWndInfoNum( const std::string &name )
+{
 	for( int i=0;i<static_cast<int>(projectInfo.windowInfos.size());i++){
-		if(lstrcmpi(name,projectInfo.windowInfos[i]->GetName().c_str())==0) return i;
+		if(lstrcmpi(name.c_str(),projectInfo.windowInfos[i]->GetName().c_str())==0) return i;
 	}
 	return -1;
 }
-ActiveBasic::PM::WindowInfo *GetWndInfo( char *name )
+ActiveBasic::PM::WindowInfo *GetWndInfo( const std::string &name )
 {
 	BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
 	{
-		if(lstrcmpi(name,pWindowInfo->GetName().c_str())==0) return pWindowInfo;
+		if(lstrcmpi(name.c_str(),pWindowInfo->GetName().c_str())==0) return pWindowInfo;
 	}
 	return NULL;
@@ -66,5 +67,4 @@
 HGLOBAL Rad_GetChildInfoClipboardData(int WndNum,int WndInfoNum){
 	//ChildWindowInfo構造体をクリップボード用データ（pByteが示すバッファ）に変換する
-	extern MDIINFO MdiInfo[MAX_WNDNUM];
 	HGLOBAL hGlobal;
 	BYTE *pByte;
@@ -141,5 +141,4 @@
 void Rad_PasteChildInfoClipboardData(int WndNum,HGLOBAL hGlobal){
 	//hGlobalに格納されているクリップボードデータをRAD画面に挿入する
-	extern MDIINFO MdiInfo[MAX_WNDNUM];
 	BYTE *pByte;
 	int i2,i3,WndInfoNum;
@@ -307,4 +306,16 @@
 
 	return pBuf;
+}
+const std::string PermutationWndPgmTemplate( const std::string &templateFilePath, const std::string &projectName, const std::string &windowName, const std::string &handleName, const std::string &procName )
+{
+	Jenga::Common::SourceTemplate sourceTemplate( templateFilePath );
+	Jenga::Common::SourceTemplate::Values values;
+
+	values.Insert( "#name#", projectName );
+	values.Insert( "#window#", windowName );
+	values.Insert( "#handle#", handleName );
+	values.Insert( "#procedure#", procName );
+
+	return sourceTemplate.GetResult( values );
 }
 
@@ -535,7 +546,12 @@
 	}
 	else if(lstrcmp(MessageName,"Create")==0){
-		if(pWindowInfo->type==WNDTYPE_MODALDLG||pWindowInfo->type==WNDTYPE_MODELESSDLG)
+		if( pWindowInfo->IsModalDlg() || pWindowInfo->IsModelessDlg() )
+		{
 			sprintf(Command,"%sCase WM_INITDIALOG\r\n",spaces);
-		else sprintf(Command,"%sCase WM_CREATE\r\n",spaces);
+		}
+		else
+		{
+			sprintf(Command,"%sCase WM_CREATE\r\n",spaces);
+		}
 		i=lstrlen(Command);
 
@@ -833,12 +849,18 @@
 		sprintf(Command+i,"%s\tDim cancel=0 As Integer\r\n",spaces);
 		i+=lstrlen(Command+i);
-		if(bProcedureCall){
+		if(bProcedureCall)
+		{
 			sprintf(Command+i,"%s\t%s_%s(cancel)\r\n",spaces,pWindowInfo->GetName().c_str(),MessageName);
 			i+=lstrlen(Command+i);
 		}
-		if(pWindowInfo->type==WNDTYPE_MODALDLG)
+
+		if( pWindowInfo->IsModalDlg() )
+		{
 			sprintf(Command+i,"%s\tIf cancel=0 Then EndDialog(hWnd,0)\r\n",spaces);
+		}
 		else
+		{
 			sprintf(Command+i,"%s\tIf cancel=0 Then DestroyWindow(hWnd)\r\n",spaces);
+		}
 		return WM_CLOSE;
 	}
@@ -1362,5 +1384,6 @@
 	BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
 	{
-		if(pWindowInfo->type==WNDTYPE_MODALDLG){
+		if( pWindowInfo->IsModalDlg() )
+		{
 			if(sw1==0){
 				sprintf(buffer+i2,"\tIf lstrcmp(TemplateName,\"%s\")=0 Then\r\n",pWindowInfo->GetName().c_str());
@@ -1388,5 +1411,5 @@
 				sprintf(buffer+i2,"\t\tSetWindowLongPtr(%s,GWLP_WNDPROC,AddressOf(%s) As LONG_PTR)\r\n",
 					pWindowInfo->GetHandleName().c_str(),
-					pWindowInfo->CallBackName);
+					pWindowInfo->GetCallbackName().c_str());
 			}
 			else{
@@ -1461,5 +1484,6 @@
 	BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
 	{
-		if(pWindowInfo->type==WNDTYPE_MODELESSDLG){
+		if( pWindowInfo->IsModelessDlg() )
+		{
 			sprintf(buffer+i2,"\tIf lstrcmp(TemplateName,\"%s\")=0 Then\r\n",pWindowInfo->GetName().c_str());
 			i2+=lstrlen(buffer+i2);
@@ -1480,5 +1504,5 @@
 				sprintf(buffer+i2,"\t\tSetWindowLongPtr(%s,GWLP_WNDPROC,AddressOf(%s) As LONG_PTR)\r\n",
 					pWindowInfo->GetHandleName().c_str(),
-					pWindowInfo->CallBackName);
+					pWindowInfo->GetCallbackName().c_str());
 			}
 			else{
@@ -1534,5 +1558,6 @@
 	BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
 	{
-		if(pWindowInfo->type==WNDTYPE_DEFAULT){
+		if( pWindowInfo->IsDefaultWindow() )
+		{
 			//////////////////////
 			//通常ウィンドウ作成
@@ -1558,5 +1583,5 @@
 			i2+=lstrlen(buffer+i2);
 			if(bAvailUserProc[i])
-				sprintf(buffer+i2,"_RadSys_wcl.lpfnWndProc=AddressOf(%s)\r\n",pWindowInfo->CallBackName);
+				sprintf(buffer+i2,"_RadSys_wcl.lpfnWndProc=AddressOf(%s)\r\n",pWindowInfo->GetCallbackName().c_str());
 			else sprintf(buffer+i2,"_RadSys_wcl.lpfnWndProc=AddressOf(EventCall_%s)\r\n",pWindowInfo->GetName().c_str());
 			i2+=lstrlen(buffer+i2);
@@ -1631,5 +1656,4 @@
 {
 	extern HANDLE hHeap;
-	extern MDIINFO MdiInfo[MAX_WNDNUM];
 	int i,i2,size;
 	char *buffer,*temporary;
@@ -1638,9 +1662,7 @@
 	buffer=(char *)HeapAlloc(hHeap,0,GENERAL_SIZE*size);
 	i2=0;
-	BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, projectInfo.windowInfos )
+	BOOST_FOREACH( ActiveBasic::PM::WindowInfo *pWindowInfo, windowInfos )
 	{
 		sprintf(buffer+i2,"WINDOW:%s\r\n",pWindowInfo->GetName().c_str());
-		i2+=lstrlen(buffer+i2);
-		sprintf(buffer+i2,"    HANDLE    = %s\r\n",pWindowInfo->GetHandleName().c_str());
 		i2+=lstrlen(buffer+i2);
 		sprintf(buffer+i2,"    POINT     = %d,%d\r\n",pWindowInfo->pos.x,pWindowInfo->pos.y);
@@ -1684,9 +1706,5 @@
 		sprintf(buffer+i2,"    CLASS     = \"%s\"\r\n",pWindowInfo->GetClassName().c_str());
 		i2+=lstrlen(buffer+i2);
-		sprintf(buffer+i2,"    CALLBACK  = %s\r\n",pWindowInfo->CallBackName);
-		i2+=lstrlen(buffer+i2);
-		sprintf(buffer+i2,"    TYPE      = %d\r\n",pWindowInfo->type);
-		i2+=lstrlen(buffer+i2);
-		sprintf(buffer+i2,"    FILEPATH  = %s\r\n",pWindowInfo->filepath);
+		sprintf(buffer+i2,"    TYPE      = %d\r\n",(DWORD)pWindowInfo->GetType());
 		i2+=lstrlen(buffer+i2);
 		BOOST_FOREACH( const ActiveBasic::PM::ChildWindowInfo *pChildInfo, pWindowInfo->childWindowInfos )
@@ -1887,5 +1905,5 @@
 			}
 			else if(lstrcmpi(temporary,"HANDLE")==0&&i3==1){
-				projectInfo.windowInfos.back()->SetHandleName( temp2 );
+				//無視
 			}
 			else if(lstrcmpi(temporary,"POINT")==0&&i3==1){
@@ -1977,16 +1995,16 @@
 				}
 			}
-			else if(lstrcmpi(temporary,"CALLBACK")==0&&i3==1){
-				projectInfo.windowInfos.back()->CallBackName=(char *)HeapAlloc(hHeap,0,i2+1);
-				lstrcpy(projectInfo.windowInfos.back()->CallBackName,temp2);
+			else if(lstrcmpi(temporary,"CALLBACK")==0&&i3==1)
+			{
+				// 無視
 			}
 
 			//以前のバージョンとの互換用
-			else if(lstrcmpi(temporary,"DLGTMP")==0&&i3==1) projectInfo.windowInfos.back()->type=GetValue(temp2);
-
-			else if(lstrcmpi(temporary,"TYPE")==0&&i3==1) projectInfo.windowInfos.back()->type=GetValue(temp2);
-			else if(lstrcmpi(temporary,"FILEPATH")==0&&i3==1){
-				projectInfo.windowInfos.back()->filepath=(char *)HeapAlloc(hHeap,0,i2+1);
-				lstrcpy(projectInfo.windowInfos.back()->filepath,temp2);
+			else if(lstrcmpi(temporary,"DLGTMP")==0&&i3==1) projectInfo.windowInfos.back()->SetType( (ActiveBasic::PM::WindowType::EnumType)GetValue(temp2) );
+
+			else if(lstrcmpi(temporary,"TYPE")==0&&i3==1) projectInfo.windowInfos.back()->SetType( (ActiveBasic::PM::WindowType::EnumType)GetValue(temp2) );
+			else if(lstrcmpi(temporary,"FILEPATH")==0&&i3==1)
+			{
+				// 無視
 			}
 			else if(lstrcmpi(temporary,"ITEM")==0&&i3==1){
@@ -2082,7 +2100,5 @@
 struct NEW_WINDOW{
 	char name[MAX_PATH];
-	char HandleName[MAX_PATH];
-	char CallBackName[MAX_PATH];
-	BOOL type;
+	ActiveBasic::PM::WindowType::EnumType type;
 };
 NEW_WINDOW NewWindow;
@@ -2092,6 +2108,4 @@
 		case WM_INITDIALOG:
 			SetPosCenter(hwnd);
-			SendDlgItemMessage(hwnd,IDC_AUTOSET,BM_SETCHECK,BST_CHECKED,0);
-			SendMessage(hwnd,WM_COMMAND,IDC_AUTOSET,0);
 			SendDlgItemMessage(hwnd,IDC_MODALDLG,BM_SETCHECK,BST_CHECKED,0);
 			break;
@@ -2100,12 +2114,16 @@
 				case IDOK:
 					GetDlgItemText(hwnd,IDC_WINDOWNAME,NewWindow.name,MAX_PATH);
-					GetDlgItemText(hwnd,IDC_WINDOWHANDLE,NewWindow.HandleName,MAX_PATH);
-					GetDlgItemText(hwnd,IDC_WINDOWPROC,NewWindow.CallBackName,MAX_PATH);
 					if(SendDlgItemMessage(hwnd,IDC_DEFWINDOW,BM_GETCHECK,0,0))
-						NewWindow.type=WNDTYPE_DEFAULT;
+					{
+						NewWindow.type = ActiveBasic::PM::WindowType::Default;
+					}
 					else if(SendDlgItemMessage(hwnd,IDC_MODALDLG,BM_GETCHECK,0,0))
-						NewWindow.type=WNDTYPE_MODALDLG;
+					{
+						NewWindow.type = ActiveBasic::PM::WindowType::ModalDlg;
+					}
 					else if(SendDlgItemMessage(hwnd,IDC_MODELESSDLG,BM_GETCHECK,0,0))
-						NewWindow.type=WNDTYPE_MODELESSDLG;
+					{
+						NewWindow.type = ActiveBasic::PM::WindowType::ModelessDlg;
+					}
 					EndDialog(hwnd,1);
 					return 1;
@@ -2114,10 +2132,6 @@
 					return 1;
 				case IDC_WINDOWNAME:
-					if(HIWORD(wParam)==EN_CHANGE) SendMessage(hwnd,WM_COMMAND,IDC_AUTOSET,0);
-					return 1;
-				case IDC_AUTOSET:
-					if(SendDlgItemMessage(hwnd,IDC_AUTOSET,BM_GETCHECK,0,0)){
-						SendDlgItemMessage(hwnd,IDC_WINDOWHANDLE,EM_SETREADONLY,1,0);
-						SendDlgItemMessage(hwnd,IDC_WINDOWPROC,EM_SETREADONLY,1,0);
+					if(HIWORD(wParam)==EN_CHANGE)
+					{
 						GetDlgItemText(hwnd,IDC_WINDOWNAME,temporary,MAX_PATH);
 						if(temporary[0]){
@@ -2131,8 +2145,4 @@
 							SetDlgItemText(hwnd,IDC_WINDOWPROC,"");
 						}
-					}
-					else{
-						SendDlgItemMessage(hwnd,IDC_WINDOWHANDLE,EM_SETREADONLY,0,0);
-						SendDlgItemMessage(hwnd,IDC_WINDOWPROC,EM_SETREADONLY,0,0);
 					}
 					return 1;
@@ -2160,5 +2170,5 @@
 void Project_Window_Insert(void){
 	extern HANDLE hHeap;
-	char temporary[MAX_PATH],temp2[1024],*pTemp;
+	char temporary[MAX_PATH],temp2[1024];
 
 	if(!DialogBox(hResInst,MAKEINTRESOURCE(IDD_PROJECT_NEWWINDOW),hOwner,(DLGPROC)DlgProject_NewWindow)) return;
@@ -2179,16 +2189,4 @@
 			return;
 		}
-		if(lstrcmpi(NewWindow.HandleName,pWindowInfo->GetHandleName().c_str())==0){
-			//"\"%s\" ハンドルは既にプロジェクト内に存在します。"
-			sprintf(temporary,STRING_DUPLICATIONERROR_HANDLE_IN_PROJECT,pWindowInfo->GetHandleName().c_str());
-			MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
-			return;
-		}
-		if(lstrcmpi(NewWindow.CallBackName,pWindowInfo->CallBackName)==0){
-			//"\"%s\" プロシージャは既にプロジェクト内に存在します。"
-			sprintf(temporary,STRING_DUPLICATIONERROR_PROC_IN_PROJECT,pWindowInfo->CallBackName);
-			MessageBox(hOwner,temporary,STRING_ERROR,MB_OK|MB_ICONEXCLAMATION);
-			return;
-		}
 	}
 
@@ -2202,7 +2200,4 @@
 	//ウィンドウ名
 	projectInfo.windowInfos.back()->SetName( NewWindow.name );
-
-	//ハンドル名
-	projectInfo.windowInfos.back()->SetHandleName( NewWindow.HandleName );
 
 	//位置情報
@@ -2217,10 +2212,10 @@
 	//スタイル
 	switch(NewWindow.type){
-		case WNDTYPE_DEFAULT:
+		case ActiveBasic::PM::WindowType::Default:
 			//通常ウィンドウ
 			projectInfo.windowInfos.back()->SetStyle( WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX );
 			break;
-		case WNDTYPE_MODALDLG:
-		case WNDTYPE_MODELESSDLG:
+		case ActiveBasic::PM::WindowType::ModalDlg:
+		case ActiveBasic::PM::WindowType::ModelessDlg:
 			//ダイアログ テンプレート（最大化、最小化ボタンをなくして、細枠にする）
 			projectInfo.windowInfos.back()->SetStyle( WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU );
@@ -2247,16 +2242,7 @@
 	projectInfo.windowInfos.back()->SetClassName( temporary );
 
-	//コールバック関数名
-	projectInfo.windowInfos.back()->CallBackName=(char *)HeapAlloc(hHeap,0,lstrlen(NewWindow.CallBackName)+1);
-	lstrcpy(projectInfo.windowInfos.back()->CallBackName,NewWindow.CallBackName);
-
 	//タイプ識別
-	projectInfo.windowInfos.back()->type=NewWindow.type;
-
-
-	//メッセージ処理ファイル名
-	sprintf(temporary,"%s.ab",projectInfo.windowInfos.back()->GetName().c_str());
-	projectInfo.windowInfos.back()->filepath=(char *)HeapAlloc(hHeap,0,lstrlen(temporary)+1);
-	lstrcpy(projectInfo.windowInfos.back()->filepath,temporary);
+	projectInfo.windowInfos.back()->SetType( NewWindow.type );
+
 
 
@@ -2265,22 +2251,19 @@
 	//////////////////////////
 
-	//テンプレートを読み込む
-	const std::string newWindowTemplateSbpPath = ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\new_window_template.sbp";
-	pTemp = ReadBuffer( newWindowTemplateSbpPath );
-
-	//#name#をプロジェクト名に置換
-	pTemp=PermutationWndPgmTemplate(pTemp,
-		projectInfo.GetName().c_str(),
-		NewWindow.name,
-		NewWindow.HandleName,
-		NewWindow.CallBackName);
+	// テンプレートを使ってMainWnd.abを生成する
+	const std::string resultStr = PermutationWndPgmTemplate(
+		ActiveBasic::Common::Environment::GetAbdevSystemDirPath() + "\\new_window_template.sbp",
+		projectInfo.GetName(),
+		(std::string)NewWindow.name,
+		(std::string)"h" + NewWindow.name,
+		(std::string)NewWindow.name + "Proc"
+	);
 
 	sprintf(temporary,"%s%s.ab",projectInfo.GetWorkDir().GetPath().c_str(),projectInfo.windowInfos.back()->GetName().c_str());
 
 	//書き込み
-	WriteBuffer(temporary,pTemp,lstrlen(pTemp));
+	WriteBuffer(temporary,resultStr.c_str(),resultStr.size());
 	Project_File_Insert(temporary);
 
-	HeapDefaultFree(pTemp);
 
 
@@ -2309,5 +2292,4 @@
 void Project_Window_Delete(int WndInfoNum){
 	extern HANDLE hHeap;
-	extern MDIINFO MdiInfo[MAX_WNDNUM];
 	int i;
 
@@ -2315,14 +2297,10 @@
 
 	//ウィンドウが開かれている場合は閉じる
-	for(i=0;i<MAX_WNDNUM;i++){
-		if(MdiInfo[i].hwnd&&lstrcmpi(pWindowInfo->GetName().c_str(),MdiInfo[i].path)==0){
+	for(i=0;i<MdiInfo.size();i++){
+		if(MdiInfo[i].hwnd&&lstrcmpi(pWindowInfo->GetName().c_str(),MdiInfo[i].path.c_str())==0){
 			SendMessage(MdiInfo[i].hwnd,WM_CLOSE,0,0);
 			break;
 		}
 	}
-
-	//ウィンドウ情報のメモリを解放
-	HeapDefaultFree(pWindowInfo->filepath);
-	HeapDefaultFree(pWindowInfo->CallBackName);
 
 	//子ウィンドウのメモリを解放
