1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // ExecutionPage.cpp : implementation file
28 #include "ExecutionPage.h"
30 #include "RunTestsSheet.h"
31 #include <afxpriv.h> // for WM_KICKIDLE
35 static char THIS_FILE[] = __FILE__;
38 /////////////////////////////////////////////////////////////////////////////
39 // CExecutionPage property page
41 const UINT arIds []={IDC_TT_SELECT_ALL,IDC_TT_UNSELECT_ALL,IDC_TT_ADD, IDC_TT_FOLDER, IDC_TT_REMOVE};
43 IMPLEMENT_DYNCREATE(CExecutionPage, CeCosPropertyPage)
45 CExecutionPage::CExecutionPage() :
46 CeCosPropertyPage(IDD_TT_EXECUTION_PAGE),
47 m_strExtension(_T("*.exe"))
49 GetCurrentDirectory(MAX_PATH,m_strFolder.GetBuffer(MAX_PATH));
50 m_strFolder.ReleaseBuffer();
51 //{{AFX_DATA_INIT(CExecutionPage)
52 // NOTE: the ClassWizard will add member initialization here
56 CExecutionPage::~CExecutionPage()
60 void CExecutionPage::DoDataExchange(CDataExchange* pDX)
62 CeCosPropertyPage::DoDataExchange(pDX);
63 //{{AFX_DATA_MAP(CExecutionPage)
64 DDX_Control(pDX, IDC_TT_RUNTESTS_LIST, m_List);
69 BEGIN_MESSAGE_MAP(CExecutionPage, CeCosPropertyPage)
70 //{{AFX_MSG_MAP(CExecutionPage)
71 ON_BN_CLICKED(IDC_TT_FOLDER, OnFolder)
72 ON_BN_CLICKED(IDC_TT_SELECT_ALL, OnSelectAll)
73 ON_BN_CLICKED(IDC_TT_UNSELECT_ALL, OnUnselectAll)
74 ON_BN_CLICKED(IDC_TT_ADD, OnAdd)
75 ON_BN_CLICKED(IDC_TT_REMOVE, OnRemove)
77 ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
82 /////////////////////////////////////////////////////////////////////////////
83 // CExecutionPage message handlers
84 CExecutionPage *CExecutionPage::pDlg=NULL;
85 LRESULT CALLBACK CExecutionPage::WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
87 if (message == WM_COMMAND) {
89 case MAKEWPARAM(IDC_TT_RECURSE,BN_CLICKED):
90 pDlg->m_bRecurse ^= 1;
91 pDlg->m_Button.SetCheck(pDlg->m_bRecurse);
93 case MAKEWPARAM(IDC_TT_EXTENSION,EN_CHANGE):
96 pDlg->m_Combo.GetWindowText(str);
97 pDlg->m_strExtension=(LPCTSTR)str;
104 return CallWindowProc(pDlg->m_wndProc, hwnd, message, wParam, lParam);
107 int CALLBACK CExecutionPage::CBBrowseCallbackProc( HWND hwnd,
113 pDlg=(CExecutionPage *)lpData;
115 case BFFM_INITIALIZED:
117 ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)(LPCTSTR)pDlg->m_strFolder);
118 CWnd *pWnd=CWnd::FromHandle(hwnd);
119 pWnd->SetWindowText(_T("Add Files from Folder"));
121 // Get rect of IDCANCEL button to the right
122 CRect rect,rect1,rect2;
123 pWnd->GetDlgItem(IDCANCEL)->GetWindowRect(&rect1);
124 pWnd->GetWindowRect(&rect2);
125 int nDlgMargin=rect2.right-rect1.right;
126 int nButtonHeight=rect1.Height();
127 rect.left=rect.top=nDlgMargin;
128 rect.right=rect.left+6*nButtonHeight;
129 rect.bottom=rect.top+(10*nButtonHeight)/14;
130 WPARAM wFont=(WPARAM)GetStockObject(DEFAULT_GUI_FONT);
131 pDlg->m_Button.CreateEx(0,_T("BUTTON"),NULL, WS_VISIBLE|WS_CHILD|BS_CHECKBOX, rect, pWnd, IDC_TT_RECURSE);
132 pDlg->m_Button.SetWindowText(_T("&Add from subfolders"));
133 pDlg->m_Button.SendMessage(WM_SETFONT, wFont, 0);
134 pDlg->m_Button.SetCheck(pDlg->m_bRecurse);
136 rect.left=rect.right+(4*nButtonHeight)/14;
137 rect.right=rect.left+3*nButtonHeight;
138 rect.bottom+=2*GetSystemMetrics(SM_CYBORDER)+4;
139 pDlg->m_Static.Create(_T("Files of type:"),WS_VISIBLE|WS_CHILD|SS_LEFT, rect, pWnd);
140 pDlg->m_Static.SendMessage(WM_SETFONT, wFont, 0);
141 rect.bottom-=2*GetSystemMetrics(SM_CYBORDER)+4;
143 rect.left=rect.right+(4*nButtonHeight)/14;
144 rect.right=rect.left+3*nButtonHeight;
145 //rect.bottom=rect.top+2*nButtonHeight;
146 rect.top=rect.bottom-(12*nButtonHeight)/14;
147 pDlg->m_Combo.CreateEx(WS_EX_CLIENTEDGE,_T("Edit"),NULL,WS_VISIBLE|WS_CHILD|WS_BORDER|ES_LEFT/*|CBS_DROPDOWN*/, rect, pWnd, IDC_TT_EXTENSION);
148 //pDlg->m_Combo.AddString(pDlg->m_strExtension);
149 //pDlg->m_Combo.SetCurSel(0);
150 pDlg->m_Combo.SetWindowText(pDlg->m_strExtension);
151 pDlg->m_Combo.SendMessage(WM_SETFONT, wFont, 0);
153 pDlg->m_wndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (long)WindowProcNew);
156 case BFFM_SELCHANGED:
158 // Change the cwd such that if the New button is used, we know where we are to start from
159 ITEMIDLIST *iil=(ITEMIDLIST *)lParam;
161 SHGetPathFromIDList(iil,strFolder.GetBuffer(MAX_PATH));
162 strFolder.ReleaseBuffer();
163 SetCurrentDirectory(strFolder);
173 void CExecutionPage::OnFolder()
177 bi.hwndOwner = GetSafeHwnd();
179 bi.pszDisplayName = m_strFolder.GetBuffer(MAX_PATH);
180 bi.lpszTitle = _T("");
181 bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT/*|0x0010 BIF_EDITBOX*/;
182 bi.lpfn = (BFFCALLBACK)CBBrowseCallbackProc;
183 bi.lParam = (LPARAM)this;
185 bool bSaveRecurse=m_bRecurse;
186 LPITEMIDLIST iil = SHBrowseForFolder(&bi);
187 m_strFolder.ReleaseBuffer();
189 SHGetPathFromIDList(iil,m_strFolder.GetBuffer(MAX_PATH));
190 m_strFolder.ReleaseBuffer();
192 FillListBox(m_strFolder);
194 m_bRecurse=bSaveRecurse;
200 void CExecutionPage::OnRefresh()
202 FillListBox(m_strFolder);
206 void CExecutionPage::FillListBox(LPCTSTR pszFolder)
209 CString strOldFolder;
210 ::GetCurrentDirectory(MAX_PATH,strOldFolder.GetBuffer(MAX_PATH));
211 strOldFolder.ReleaseBuffer();
213 if(::SetCurrentDirectory(pszFolder)){
214 int nCount=m_List.GetCount();
215 m_List.Dir(DDL_READWRITE,m_strExtension);
216 for(int i=nCount;i<m_List.GetCount();i++){
217 TCHAR strFull[1+MAX_PATH];
219 m_List.GetText(i,str);
221 ::GetFullPathName(str,MAX_PATH,strFull,&pFile);
222 m_List.DeleteString(i);
223 if(LB_ERR==m_List.FindStringExact(-1,strFull)){
224 m_List.InsertString(i,strFull);
225 m_List.SetCheck(i,TRUE);
232 BOOL bMore=finder.FindFile();
234 bMore = finder.FindNextFile();
235 if(finder.IsDirectory() && !finder.IsDots()){
236 FillListBox(finder.GetFileName());
240 ::SetCurrentDirectory(strOldFolder);
242 GetDlgItem(IDC_TT_SELECT_ALL)->EnableWindow(m_List.GetCount()>0);
243 GetDlgItem(IDC_TT_UNSELECT_ALL)->EnableWindow(m_List.GetCount()>0);
246 void CExecutionPage::OnSelectAll()
248 for(int i=0;i<m_List.GetCount();i++){
249 m_List.SetCheck(i,TRUE);
253 void CExecutionPage::OnUnselectAll()
255 for(int i=0;i<m_List.GetCount();i++){
256 m_List.SetCheck(i,FALSE);
260 bool CExecutionPage::IsSelected(int i)
262 return TRUE==m_List.GetCheck(i);
265 void CExecutionPage::OnAdd()
267 CFileDialog dlg(TRUE, _T("exe"), _T("*.exe"), OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
268 _T("Executables(*.exe)\0*.exe\0"));
269 dlg.m_ofn.lpstrTitle=_T("Add");
270 if(IDOK==dlg.DoModal()){
271 LPCTSTR pszDir=dlg.m_ofn.lpstrFile;
272 DWORD dwAttr=GetFileAttributes(pszDir);
273 if(0xFFFFFFFF!=dwAttr){
275 if(dwAttr&FILE_ATTRIBUTE_DIRECTORY){
276 for(LPCTSTR c=pszDir+_tcslen(pszDir)+1;_TCHAR('\0')!=*c;c+=_tcslen(c)+1){
280 if(LB_ERR==m_List.FindStringExact(-1,str)){
281 m_List.SetCheck(m_List.AddString(str),TRUE);
287 if(LB_ERR==m_List.FindStringExact(-1,pszDir)){
288 m_List.SetCheck(m_List.AddString(pszDir),TRUE);
294 MessageBox(_T("One or more of the files was already present"));
298 GetDlgItem(IDC_TT_SELECT_ALL)->EnableWindow(m_List.GetCount()>0);
299 GetDlgItem(IDC_TT_UNSELECT_ALL)->EnableWindow(m_List.GetCount()>0);
303 int CExecutionPage::SelectedTestCount()
306 if(IsWindow(m_List.m_hWnd)){
307 for(int i=0;i<m_List.GetCount();i++){
308 n+=m_List.GetCheck(i);
314 CString CExecutionPage::SelectedTest(int nIndex)
317 for(int i=0;i<m_List.GetCount();i++){
318 if(m_List.GetCheck(i)){
320 m_List.GetText(i,str);
329 BOOL CExecutionPage::OnInitDialog()
331 CeCosPropertyPage::OnInitDialog();
332 for(POSITION pos = m_arstrPreLoad.GetStartPosition(); pos != NULL; ){
335 m_arstrPreLoad.GetNextAssoc( pos, strFile,p);
336 m_List.SetCheck(m_List.AddString(strFile),0!=p);
338 return TRUE; // return TRUE unless you set the focus to a control
339 // EXCEPTION: OCX Property Pages should return FALSE
342 void CExecutionPage::OnSize(UINT nType, int cx, int cy)
346 CeCosPropertyPage::OnSize(nType, cx, cy);
348 CWnd *pWnd=GetDlgItem(IDC_TT_RUNTESTS_LIST);
350 ((CRunTestsSheet*)GetParent())->MoveWindow(pWnd,CRunTestsSheet::Stretch);
351 const int nWnds=sizeof(arIds)/sizeof(arIds[0]);
354 CWnd *pWnd0=GetDlgItem(arIds[0]);
355 ((CRunTestsSheet*)GetParent())->MoveWindow(pWnd0,CRunTestsSheet::TopLeft);
356 CWnd *pWndn=GetDlgItem(arIds[nWnds-1]);
357 ((CRunTestsSheet*)GetParent())->MoveWindow(pWndn,CRunTestsSheet::TopRight);
360 pWnd0->GetWindowRect(rect0);
361 ScreenToClient(rect0);
364 pWndn->GetWindowRect(rectn);
365 ScreenToClient(rectn);
367 int nSpacing=(rectn.left-rect0.left)/(nWnds-1);
368 for(int i=1;i<nWnds-1;i++){
370 rect.left=rect0.left+i*nSpacing;
371 rect.right=rect.left+rect0.Width();
373 rect.bottom=rect0.bottom;
374 pWnd=GetDlgItem(arIds[i]);
375 pWnd->GetWindowRect(rc[i]);
376 ScreenToClient(rc[i]);
377 pWnd->MoveWindow(rect);
380 for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){
381 InvalidateRect(rc[i]);
382 GetDlgItem(arIds[i])->Invalidate();
388 LRESULT CExecutionPage::OnKickIdle(WPARAM, LPARAM)
390 if(IsWindow(m_List.m_hWnd)){
391 int n=m_List.GetCount();
392 bool bSelectAll=false;
393 bool bUnSelectAll=false;
396 for(int i=0;i<n;i++){
397 bool bCheck=(TRUE==m_List.GetCheck(i));
403 if(i>0 && bCheck!=bPrev){
409 GetDlgItem(IDC_TT_SELECT_ALL)->EnableWindow(bSelectAll);
410 GetDlgItem(IDC_TT_UNSELECT_ALL)->EnableWindow(bUnSelectAll);
415 bool CExecutionPage::SomeTestsSelected()
418 if(IsWindow(m_List.m_hWnd)){
419 for(int i=0;i<m_List.GetCount();i++){
420 if(m_List.GetCheck(i)){
430 void CExecutionPage::OnRemove()
432 m_List.SendMessage(WM_COMMAND,IDC_TT_REMOVE,0);