comparison host/tools/testtool/win32/ExecutionPage.cpp @ 76:435cced73e2f ecos-v1_3_1-release

eCos v1.3.1 merged from eCos master repository on 2000-03-27-23:22:51-BST
author jlarmour
date Tue, 28 Mar 2000 14:10:45 +0000
parents
children 6736c52df507
comparison
equal deleted inserted replaced
75:41bf073c0c32 76:435cced73e2f
1 //####COPYRIGHTBEGIN####
2 //
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
5 //
6 // This program is part of the eCos host tools.
7 //
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)
11 // any later version.
12 //
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
16 // more details.
17 //
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.
21 //
22 // ----------------------------------------------------------------------------
23 //
24 //####COPYRIGHTEND####
25 // ExecutionPage.cpp : implementation file
26 //
27 #include "stdafx.h"
28 #include "ExecutionPage.h"
29 #include "shlobj.h"
30 #include "RunTestsSheet.h"
31 #include <afxpriv.h> // for WM_KICKIDLE
32 #ifdef _DEBUG
33 #define new DEBUG_NEW
34 #undef THIS_FILE
35 static char THIS_FILE[] = __FILE__;
36 #endif
37
38 /////////////////////////////////////////////////////////////////////////////
39 // CExecutionPage property page
40
41 const UINT arIds []={IDC_TT_SELECT_ALL,IDC_TT_UNSELECT_ALL,IDC_TT_ADD, IDC_TT_FOLDER, IDC_TT_REMOVE};
42
43 IMPLEMENT_DYNCREATE(CExecutionPage, CeCosPropertyPage)
44
45 CExecutionPage::CExecutionPage() :
46 CeCosPropertyPage(IDD_TT_EXECUTION_PAGE)
47 {
48 GetCurrentDirectory(MAX_PATH,m_strFolder.GetBuffer(MAX_PATH));
49 m_strFolder.ReleaseBuffer();
50 //{{AFX_DATA_INIT(CExecutionPage)
51 // NOTE: the ClassWizard will add member initialization here
52 //}}AFX_DATA_INIT
53 }
54
55 CExecutionPage::~CExecutionPage()
56 {
57 }
58
59 void CExecutionPage::DoDataExchange(CDataExchange* pDX)
60 {
61 CeCosPropertyPage::DoDataExchange(pDX);
62 //{{AFX_DATA_MAP(CExecutionPage)
63 DDX_Control(pDX, IDC_TT_RUNTESTS_LIST, m_List);
64 //}}AFX_DATA_MAP
65 }
66
67
68 BEGIN_MESSAGE_MAP(CExecutionPage, CeCosPropertyPage)
69 //{{AFX_MSG_MAP(CExecutionPage)
70 ON_BN_CLICKED(IDC_TT_FOLDER, OnFolder)
71 ON_BN_CLICKED(IDC_TT_SELECT_ALL, OnSelectAll)
72 ON_BN_CLICKED(IDC_TT_UNSELECT_ALL, OnUnselectAll)
73 ON_BN_CLICKED(IDC_TT_ADD, OnAdd)
74 ON_BN_CLICKED(IDC_TT_REMOVE, OnRemove)
75 ON_WM_SIZE()
76 ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
77 ON_WM_CHAR()
78 //}}AFX_MSG_MAP
79 END_MESSAGE_MAP()
80
81 /////////////////////////////////////////////////////////////////////////////
82 // CExecutionPage message handlers
83 CExecutionPage *CExecutionPage::pDlg=NULL;
84 LRESULT CALLBACK CExecutionPage::WindowProcNew(HWND hwnd,UINT message, WPARAM wParam, LPARAM lParam)
85 {
86 if (message == WM_COMMAND) {
87 switch(wParam){
88 case MAKEWPARAM(IDC_TT_RECURSE,BN_CLICKED):
89 pDlg->m_bRecurse ^= 1;
90 pDlg->m_Button.SetCheck(pDlg->m_bRecurse);
91 return 0;
92 case MAKEWPARAM(IDC_TT_EXTENSION,EN_CHANGE):
93 pDlg->m_Combo.GetWindowText(pDlg->m_strExtension);
94 return 0;
95 default:
96 break;
97 }
98 }
99 return CallWindowProc(pDlg->m_wndProc, hwnd, message, wParam, lParam);
100 }
101
102 int CALLBACK CExecutionPage::CBBrowseCallbackProc( HWND hwnd,
103 UINT uMsg,
104 LPARAM lParam,
105 LPARAM lpData
106 )
107 {
108 pDlg=(CExecutionPage *)lpData;
109 switch(uMsg){
110 case BFFM_INITIALIZED:
111 {
112 ::SendMessage(hwnd,BFFM_SETSELECTION,TRUE,(LPARAM)(LPCTSTR)pDlg->m_strFolder);
113 CWnd *pWnd=CWnd::FromHandle(hwnd);
114 pWnd->SetWindowText(_T("Add Files from Folder"));
115
116 // Get rect of IDCANCEL button to the right
117 CRect rect,rect1,rect2;
118 pWnd->GetDlgItem(IDCANCEL)->GetWindowRect(&rect1);
119 pWnd->GetWindowRect(&rect2);
120 int nDlgMargin=rect2.right-rect1.right;
121 int nButtonHeight=rect1.Height();
122 rect.left=rect.top=nDlgMargin;
123 rect.right=rect.left+6*nButtonHeight;
124 rect.bottom=rect.top+(10*nButtonHeight)/14;
125 WPARAM wFont=(WPARAM)GetStockObject(DEFAULT_GUI_FONT);
126 pDlg->m_Button.CreateEx(0,_T("BUTTON"),NULL, WS_VISIBLE|WS_CHILD|BS_CHECKBOX, rect, pWnd, IDC_TT_RECURSE);
127 pDlg->m_Button.SetWindowText(_T("&Add from subfolders"));
128 pDlg->m_Button.SendMessage(WM_SETFONT, wFont, 0);
129 pDlg->m_Button.SetCheck(pDlg->m_bRecurse);
130
131 rect.left=rect.right+(4*nButtonHeight)/14;
132 rect.right=rect.left+3*nButtonHeight;
133 rect.bottom+=2*GetSystemMetrics(SM_CYBORDER)+4;
134 pDlg->m_Static.Create(_T("Files of type:"),WS_VISIBLE|WS_CHILD|SS_LEFT, rect, pWnd);
135 pDlg->m_Static.SendMessage(WM_SETFONT, wFont, 0);
136 rect.bottom-=2*GetSystemMetrics(SM_CYBORDER)+4;
137
138 rect.left=rect.right+(4*nButtonHeight)/14;
139 rect.right=rect.left+3*nButtonHeight;
140 //rect.bottom=rect.top+2*nButtonHeight;
141 rect.top=rect.bottom-(12*nButtonHeight)/14;
142 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);
143 //pDlg->m_Combo.AddString(pDlg->m_strExtension);
144 //pDlg->m_Combo.SetCurSel(0);
145 pDlg->m_Combo.SetWindowText(pDlg->m_strExtension);
146 pDlg->m_Combo.SendMessage(WM_SETFONT, wFont, 0);
147
148 pDlg->m_wndProc = (WNDPROC)SetWindowLong(hwnd, GWL_WNDPROC, (long)WindowProcNew);
149
150 }
151 case BFFM_SELCHANGED:
152 {
153 // Change the cwd such that if the New button is used, we know where we are to start from
154 ITEMIDLIST *iil=(ITEMIDLIST *)lParam;
155 CString strFolder;
156 SHGetPathFromIDList(iil,strFolder.GetBuffer(MAX_PATH));
157 strFolder.ReleaseBuffer();
158 SetCurrentDirectory(strFolder);
159 }
160 break;
161 default:
162 ;
163 }
164
165 return 0;
166 }
167
168 void CExecutionPage::OnFolder()
169 {
170
171 BROWSEINFO bi;
172 bi.hwndOwner = GetSafeHwnd();
173 bi.pidlRoot = NULL;
174 bi.pszDisplayName = m_strFolder.GetBuffer(MAX_PATH);
175 bi.lpszTitle = _T("");
176 bi.ulFlags = BIF_RETURNONLYFSDIRS|BIF_STATUSTEXT/*|0x0010 BIF_EDITBOX*/;
177 bi.lpfn = (BFFCALLBACK)CBBrowseCallbackProc;
178 bi.lParam = (LPARAM)this;
179
180 bool bSaveRecurse=m_bRecurse;
181 LPITEMIDLIST iil = SHBrowseForFolder(&bi);
182 m_strFolder.ReleaseBuffer();
183 if(iil){
184 SHGetPathFromIDList(iil,m_strFolder.GetBuffer(MAX_PATH));
185 m_strFolder.ReleaseBuffer();
186 SetModified();
187 FillListBox(m_strFolder);
188 } else {
189 m_bRecurse=bSaveRecurse;
190 }
191
192 }
193
194 /*
195 void CExecutionPage::OnRefresh()
196 {
197 FillListBox(m_strFolder);
198 }
199 */
200
201 void CExecutionPage::FillListBox(LPCTSTR pszFolder)
202 {
203 CWaitCursor wait;
204 CString strOldFolder;
205 ::GetCurrentDirectory(MAX_PATH,strOldFolder.GetBuffer(MAX_PATH));
206 strOldFolder.ReleaseBuffer();
207
208 if(::SetCurrentDirectory(pszFolder)){
209 int nCount=m_List.GetCount();
210 m_List.Dir(DDL_READWRITE,m_strExtension);
211 for(int i=nCount;i<m_List.GetCount();i++){
212 TCHAR strFull[1+MAX_PATH];
213 CString str;
214 m_List.GetText(i,str);
215 TCHAR *pFile;
216 ::GetFullPathName(str,MAX_PATH,strFull,&pFile);
217 m_List.DeleteString(i);
218 if(LB_ERR==m_List.FindStringExact(-1,strFull)){
219 m_List.InsertString(i,strFull);
220 m_List.SetCheck(i,TRUE);
221 } else {
222 --i;
223 }
224 }
225 if(m_bRecurse){
226 CFileFind finder;
227 BOOL bMore=finder.FindFile();
228 while (bMore) {
229 bMore = finder.FindNextFile();
230 if(finder.IsDirectory() && !finder.IsDots()){
231 FillListBox(finder.GetFileName());
232 }
233 }
234 }
235 ::SetCurrentDirectory(strOldFolder);
236 }
237 GetDlgItem(IDC_TT_SELECT_ALL)->EnableWindow(m_List.GetCount()>0);
238 GetDlgItem(IDC_TT_UNSELECT_ALL)->EnableWindow(m_List.GetCount()>0);
239 }
240
241 void CExecutionPage::OnSelectAll()
242 {
243 for(int i=0;i<m_List.GetCount();i++){
244 m_List.SetCheck(i,TRUE);
245 }
246 }
247
248 void CExecutionPage::OnUnselectAll()
249 {
250 for(int i=0;i<m_List.GetCount();i++){
251 m_List.SetCheck(i,FALSE);
252 }
253 }
254
255 bool CExecutionPage::IsSelected(int i)
256 {
257 return TRUE==m_List.GetCheck(i);
258 }
259
260 void CExecutionPage::OnAdd()
261 {
262 CFileDialog dlg(TRUE, _T("exe"), _T("*.exe"), OFN_ALLOWMULTISELECT|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_PATHMUSTEXIST,
263 _T("Executables(*.exe)\0*.exe\0"));
264 dlg.m_ofn.lpstrTitle=_T("Add");
265 if(IDOK==dlg.DoModal()){
266 LPCTSTR pszDir=dlg.m_ofn.lpstrFile;
267 DWORD dwAttr=GetFileAttributes(pszDir);
268 if(0xFFFFFFFF!=dwAttr){
269 bool bErr=false;
270 if(dwAttr&FILE_ATTRIBUTE_DIRECTORY){
271 for(LPCTSTR c=pszDir+_tcslen(pszDir)+1;_TCHAR('\0')!=*c;c+=_tcslen(c)+1){
272 CString str(pszDir);
273 str+=_TCHAR('\\');
274 str+=c;
275 if(LB_ERR==m_List.FindStringExact(-1,str)){
276 m_List.SetCheck(m_List.AddString(str),TRUE);
277 } else {
278 bErr=true;
279 }
280 }
281 } else {
282 if(LB_ERR==m_List.FindStringExact(-1,pszDir)){
283 m_List.SetCheck(m_List.AddString(pszDir),TRUE);
284 } else {
285 bErr=true;
286 }
287 }
288 if(bErr){
289 MessageBox(_T("One or more of the files was already present"));
290 }
291 }
292 }
293 GetDlgItem(IDC_TT_SELECT_ALL)->EnableWindow(m_List.GetCount()>0);
294 GetDlgItem(IDC_TT_UNSELECT_ALL)->EnableWindow(m_List.GetCount()>0);
295 }
296
297
298 int CExecutionPage::SelectedTestCount()
299 {
300 int n=0;
301 if(IsWindow(m_List.m_hWnd)){
302 for(int i=0;i<m_List.GetCount();i++){
303 n+=m_List.GetCheck(i);
304 }
305 }
306 return n;
307 }
308
309 CString CExecutionPage::SelectedTest(int nIndex)
310 {
311 CString str;
312 for(int i=0;i<m_List.GetCount();i++){
313 if(m_List.GetCheck(i)){
314 if(0==nIndex--){
315 m_List.GetText(i,str);
316 break;
317 }
318 }
319 }
320 return str;
321
322 }
323
324 BOOL CExecutionPage::OnInitDialog()
325 {
326 CeCosPropertyPage::OnInitDialog();
327 for(POSITION pos = m_arstrPreLoad.GetStartPosition(); pos != NULL; ){
328 CString strFile;
329 void *p;
330 m_arstrPreLoad.GetNextAssoc( pos, strFile,p);
331 m_List.SetCheck(m_List.AddString(strFile),0!=p);
332 }
333 return TRUE; // return TRUE unless you set the focus to a control
334 // EXCEPTION: OCX Property Pages should return FALSE
335 }
336
337 void CExecutionPage::OnSize(UINT nType, int cx, int cy)
338 {
339 CRect rect;
340 GetClientRect(rect);
341 CeCosPropertyPage::OnSize(nType, cx, cy);
342
343 CWnd *pWnd=GetDlgItem(IDC_TT_RUNTESTS_LIST);
344 if(pWnd){
345 ((CRunTestsSheet*)GetParent())->MoveWindow(pWnd,CRunTestsSheet::Stretch);
346 const int nWnds=sizeof(arIds)/sizeof(arIds[0]);
347 CRect rc[nWnds];
348
349 CWnd *pWnd0=GetDlgItem(arIds[0]);
350 ((CRunTestsSheet*)GetParent())->MoveWindow(pWnd0,CRunTestsSheet::TopLeft);
351 CWnd *pWndn=GetDlgItem(arIds[nWnds-1]);
352 ((CRunTestsSheet*)GetParent())->MoveWindow(pWndn,CRunTestsSheet::TopRight);
353
354 CRect rect0;
355 pWnd0->GetWindowRect(rect0);
356 ScreenToClient(rect0);
357
358 CRect rectn;
359 pWndn->GetWindowRect(rectn);
360 ScreenToClient(rectn);
361
362 int nSpacing=(rectn.left-rect0.left)/(nWnds-1);
363 for(int i=1;i<nWnds-1;i++){
364 CRect rect;
365 rect.left=rect0.left+i*nSpacing;
366 rect.right=rect.left+rect0.Width();
367 rect.top=rect0.top;
368 rect.bottom=rect0.bottom;
369 pWnd=GetDlgItem(arIds[i]);
370 pWnd->GetWindowRect(rc[i]);
371 ScreenToClient(rc[i]);
372 pWnd->MoveWindow(rect);
373 }
374
375 for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){
376 InvalidateRect(rc[i]);
377 GetDlgItem(arIds[i])->Invalidate();
378 }
379
380 }
381 }
382
383 LRESULT CExecutionPage::OnKickIdle(WPARAM, LPARAM)
384 {
385 if(IsWindow(m_List.m_hWnd)){
386 int n=m_List.GetCount();
387 bool bSelectAll=false;
388 bool bUnSelectAll=false;
389 if(n>0){
390 bool bPrev=false;
391 for(int i=0;i<n;i++){
392 bool bCheck=(TRUE==m_List.GetCheck(i));
393 if(bCheck){
394 bUnSelectAll=true;
395 } else {
396 bSelectAll=true;
397 }
398 if(i>0 && bCheck!=bPrev){
399 break;
400 }
401 bPrev=bCheck;
402 }
403 }
404 GetDlgItem(IDC_TT_SELECT_ALL)->EnableWindow(bSelectAll);
405 GetDlgItem(IDC_TT_UNSELECT_ALL)->EnableWindow(bUnSelectAll);
406 }
407 return 0;
408 }
409
410 bool CExecutionPage::SomeTestsSelected()
411 {
412 bool b=0;
413 if(IsWindow(m_List.m_hWnd)){
414 for(int i=0;i<m_List.GetCount();i++){
415 if(m_List.GetCheck(i)){
416 b=true;
417 break;
418 }
419 }
420 }
421 return b;
422
423 }
424
425 void CExecutionPage::OnRemove()
426 {
427 m_List.SendMessage(WM_COMMAND,IDC_TT_REMOVE,0);
428 }