// PathList.cpp : implementation file
//

#include "stdafx.h"
#include "tctb.h"
#include "PathList.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPathList property page

IMPLEMENT_DYNCREATE(CPathList, CPropertyPage)

CPathList::CPathList() : CPropertyPage(CPathList::IDD)
{
	//{{AFX_DATA_INIT(CPathList)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
Changed=FALSE;
}

CPathList::~CPathList()
{
}

void CPathList::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPathList)
	DDX_Control(pDX, IDC_PATHLIST, m_PList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPathList, CPropertyPage)
	//{{AFX_MSG_MAP(CPathList)
	ON_BN_CLICKED(IDC_ADDPATH, OnAddpath)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPathList message handlers

void ILFree(LPITEMIDLIST pidl); 

void CPathList::OnAddpath() 
{
		char pname[MAX_PATH];
	BROWSEINFO bi; 

	bi.hwndOwner = m_hWnd; 
	
	bi.pidlRoot = NULL; 
	bi.pszDisplayName = NULL; 
	bi.lpszTitle = "Choose New Path..."; 
	bi.ulFlags = BIF_RETURNONLYFSDIRS; 
	bi.lpfn = NULL; 
	bi.lParam = (LPARAM)this; 
	
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi); 
	
	
	if (SHGetPathFromIDList(pidl,pname))  
	{
		m_PList.AddString(pname);
		Changed=TRUE;
	}
	
	if (bi.pidlRoot) 
	{ 
		ILFree( const_cast< ITEMIDLIST* >( bi.pidlRoot ) );
	} 
	
	
}

void CPathList::GetPaths(CString &str)
{
int i;
CString tstr;
str="";

for(i=0;i<m_PList.GetCount();i++)
{
m_PList.GetText(i,tstr);
str+=tstr+";";
}

}

void CPathList::SetPaths(CString &str)
{
CString fstr,cstr;
fstr=str;
int idx;

while(fstr.GetLength()>0)
{
idx=fstr.FindOneOf(";");
cstr=fstr.Left(idx);
fstr=fstr.Right(fstr.GetLength()-(idx+1));
}

}


void CPathList::AddPath(CString &pth)
{
m_PList.AddString(pth);
Changed=TRUE;
}

CString CPathList::GetPath(int i)
{
CString str;
m_PList.GetText(i,str);
return str;
}

int CPathList::GetTotalPaths()
{
return m_PList.GetCount();
}
