OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [testtool/] [win32/] [RunTestsSheet.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// RunTestsSheet.cpp : implementation file
23
//
24
 
25
#include "stdafx.h"
26
 
27
#include "eCosTest.h"
28
#include "eCosThreadUtils.h"
29
#include "eCosTrace.h"
30
#include "PropertiesDialog.h"
31
#include "ResetAttributes.h"
32
#include "RunTestsSheet.h"
33
#include "TestResource.h"
34
#include "X10.h"
35
 
36
#include <afxpriv.h>
37
 
38
static const UINT arIds []={IDOK,IDCANCEL,ID_APPLY_NOW,IDHELP};
39
 
40
 
41
#ifdef _DEBUG
42
#define new DEBUG_NEW
43
#undef THIS_FILE
44
static char THIS_FILE[] = __FILE__;
45
#endif
46
 
47
 
48
/////////////////////////////////////////////////////////////////////////////
49
// CRunTestsSheet
50
 
51
IMPLEMENT_DYNAMIC(CRunTestsSheet, CeCosPropertySheet)
52
 
53
CRunTestsSheet::CRunTestsSheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage, CBFunc pInitFunc, CRunTestsSheet **ppSheet)
54
:CeCosPropertySheet(pszCaption, pParentWnd, iSelectPage),
55
  m_pResource(NULL),
56
  m_pInitFunc(pInitFunc),
57
  m_bAllowResizing(false),
58
  m_cxMin(0),
59
  m_cyMin(0),
60
  m_Status(Stopped),
61
  m_bHideTarget(false),
62
  m_bHideRemoteControls(false),
63
  m_bModal(false),
64
  m_ppSheet(ppSheet),
65
  m_ep(CeCosTest::ExecutionParameters::RUN),
66
  m_nTimeout(900),
67
  m_nDownloadTimeout(120),
68
  m_nTimeoutType(TIMEOUT_AUTOMATIC),
69
  m_nDownloadTimeoutType(TIMEOUT_SPECIFIED),
70
  m_bRemote(false),
71
  m_bSerial(true),
72
  m_strPort(_T("COM1")),
73
  m_nBaud(38400),
74
  m_nLocalTCPIPPort(1),
75
  m_nReset(RESET_MANUAL),
76
  m_nResourcePort(1),
77
  m_nRemotePort(1),
78
  m_bFarmed(true)
79
{
80
  InitializeCriticalSection(&m_CS);
81
  AddPage(&executionpage);
82
  AddPage(&outputpage);
83
  AddPage(&summarypage);
84
 
85
}
86
 
87
CRunTestsSheet::~CRunTestsSheet()
88
{
89
  if(m_ppSheet){
90
    *m_ppSheet=0;
91
  }
92
  delete m_pResource;
93
  DeleteCriticalSection(&m_CS);
94
}
95
 
96
 
97
BEGIN_MESSAGE_MAP(CRunTestsSheet, CeCosPropertySheet)
98
//{{AFX_MSG_MAP(CRunTestsSheet)
99
ON_BN_CLICKED(IDOK, OnRun)
100
ON_BN_CLICKED(ID_APPLY_NOW, OnProperties)
101
ON_BN_CLICKED(IDCANCEL, OnClose)
102
ON_MESSAGE(WM_TESTOUTPUT, OnTestOutput)
103
ON_MESSAGE(WM_RUNCOMPLETE, OnTestsComplete)
104
ON_WM_SYSCOMMAND()
105
ON_WM_SIZE()
106
ON_WM_GETMINMAXINFO()
107
ON_WM_TIMER()
108
ON_MESSAGE(WM_KICKIDLE, OnKickIdle)
109
ON_WM_CREATE()
110
//}}AFX_MSG_MAP
111
END_MESSAGE_MAP()
112
 
113
/////////////////////////////////////////////////////////////////////////////
114
// CRunTestsSheet message handlers
115
 
116
BOOL CRunTestsSheet::OnInitDialog()
117
{
118
  if(!m_bHideTarget){
119
    m_prop.Add(_T("Platform"),m_strTarget);
120
  }
121
  m_prop.Add(_T("Active timeout"),m_nTimeout);
122
  m_prop.Add(_T("Download timeout"),m_nDownloadTimeout);
123
  m_prop.Add(_T("Active timeout type"),m_nTimeoutType);
124
  m_prop.Add(_T("Download timeout type"),m_nDownloadTimeoutType);
125
  m_prop.Add(_T("Remote"),m_bRemote);
126
  m_prop.Add(_T("Serial"),m_bSerial);
127
  m_prop.Add(_T("Port"),m_strPort);
128
  m_prop.Add(_T("Baud"),m_nBaud);
129
  m_prop.Add(_T("Local TCPIP Host"),m_strLocalTCPIPHost);
130
  m_prop.Add(_T("Local TCPIP Port"),m_nLocalTCPIPPort);
131
  m_prop.Add(_T("Reset Type"),m_nReset);
132
  m_prop.Add(_T("Reset String"),m_strReset);
133
  m_prop.Add(_T("Resource Host"),m_strResourceHost);
134
  m_prop.Add(_T("Resource Port"),m_nResourcePort);
135
  m_prop.Add(_T("Remote Host"),m_strRemoteHost);
136
  m_prop.Add(_T("Remote Port"),m_nRemotePort);
137
  m_prop.Add(_T("Recurse"),executionpage.m_bRecurse);
138
  //m_prop.Add(_T("Loadfromdir"),executionpage.m_strLoaddir);
139
  m_prop.Add(_T("Farmed"),m_bFarmed);
140
  m_prop.Add(_T("Extension"),executionpage.m_strExtension);
141
 
142
  CeCosTrace::SetOutput(TestOutputCallback,this);
143
  CeCosTrace::SetError (TestOutputCallback,this);
144
 
145
  // m_psh can only be used to set the small icon.  Set the large one here.
146
  m_psh.hIcon=AfxGetApp()->LoadIcon(IDR_TT_MAINFRAME);
147
  //sheet.m_psh.dwFlags|=PSH_USEHICON/*|PSH_HASHELP*/;
148
  if(m_psh.hIcon){
149
    SetIcon(m_psh.hIcon,FALSE);
150
    SetIcon(m_psh.hIcon,TRUE);
151
  }
152
  GetWindowRect(m_rcPrev);
153
#ifdef _DEBUG
154
  CeCosTrace::EnableTracing(CeCosTrace::TRACE_LEVEL_TRACE);
155
#endif
156
  CeCosTrace::SetInteractive(true);
157
 
158
  if(m_pInitFunc){
159
    m_pInitFunc(&m_prop,false);
160
  }
161
 
162
  GetDlgItem(IDCANCEL)->SetWindowText(_T("&Close"));
163
 
164
  m_nTestsToComplete=0;
165
  BOOL bResult = CeCosPropertySheet::OnInitDialog();
166
  SetDlgItemText(IDOK,_T("&Run"));
167
  SetDlgItemText(ID_APPLY_NOW,_T("&Properties"));
168
  GetDlgItem(ID_APPLY_NOW)->EnableWindow(TRUE);
169
  GetDlgItem(IDCANCEL)->EnableWindow(TRUE); // required for modeless case
170
 
171
  SetActivePage(&outputpage);
172
  SetActivePage(&summarypage);
173
  SetActivePage(&executionpage);
174
 
175
  if(m_pInitFunc){
176
    m_pInitFunc(&m_prop,false);
177
    outputpage.UpdateData(FALSE);
178
    summarypage.UpdateData(FALSE);
179
    executionpage.UpdateData(FALSE);
180
  }
181
  /*
182
  CString strCaption = _T("Output");
183
  TC_ITEM tcItem;
184
  tcItem.mask = TCIF_TEXT;
185
  tcItem.pszText = (LPTSTR)((LPCTSTR)strCaption);
186
  GetTabControl()->SetItem(2, &tcItem );
187
  strCaption=_T("Summary");
188
  GetTabControl()->SetItem(3, &tcItem );
189
  */
190
  // Allow resizing
191
 
192
  // WS_OVERLAPPEDWINDOW would preclude caption bar help button
193
  ModifyStyle(0,WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME ,0);
194
 
195
  CRect rect;
196
  GetWindowRect(rect);
197
  m_rcPrev=rect;
198
 
199
  m_cxMin=rect.Width();
200
  m_cyMin=rect.Height();
201
 
202
  m_bAllowResizing=true;
203
 
204
  WINDOWPLACEMENT wndpl;
205
  if (5==_stscanf(m_strPlacement,_T("%d %d %d %d %d"),&rect.left,&rect.top,&rect.right,&rect.bottom,&wndpl.showCmd)){
206
    CRect rcMax;
207
    SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)(RECT *)rcMax, 0);
208
 
209
    if(rect.Width()<100 || rect.Height()<100 || rect.Width()>rcMax.Width() || rect.Height()>rcMax.Height()){
210
      rect=CFrameWnd::rectDefault;
211
    }
212
 
213
    wndpl.length = sizeof(WINDOWPLACEMENT);
214
    wndpl.flags = 0;
215
 
216
    wndpl.ptMinPosition = CPoint(0, 0);
217
    wndpl.ptMaxPosition =CPoint(-::GetSystemMetrics(SM_CXBORDER),-::GetSystemMetrics(SM_CYBORDER));
218
    wndpl.rcNormalPosition = rect;
219
 
220
    // sets window's position and iconized/maximized status
221
    SetWindowPlacement(&wndpl);
222
  }
223
 
224
  // Hack: force an initial sizing (without which the tab control is badly sized)
225
  m_rcOffset.left=m_rcOffset.right=m_rcOffset.top=0;
226
 
227
  m_rcOffset.bottom=m_bModal?50:-50;
228
  MoveWindow(GetTabControl(),Stretch);
229
  for(int i=0;i<GetPageCount();i++){
230
    MoveWindow(GetPage(i),Stretch);
231
  }
232
#ifdef _DEBUG
233
    for(CWnd *p=GetWindow(GW_CHILD);p;p=p->GetWindow(GW_HWNDNEXT)){
234
      TCHAR buf[256];
235
      ::GetClassName(p->m_hWnd,buf,sizeof buf);
236
      TRACE(_T("Window %x id=%d class=%s\n"),p,p->GetDlgCtrlID(),buf);
237
    }
238
#endif
239
  for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){
240
    CWnd *pWnd=GetDlgItem(arIds[i]);
241
    if(pWnd){
242
      MoveWindow(pWnd,BottomRight);
243
      pWnd->ShowWindow(SW_SHOW); // necessary in the modeless case
244
    } else {
245
      TRACE(_T("Failed to find window id=%x\n"),arIds[i]);
246
    }
247
  }
248
 
249
  // hack to lay buttons out correctly in application case
250
  if(this==AfxGetMainWnd()){
251
    CRect rect1,rect2;
252
    GetDlgItem(IDOK)->GetWindowRect(rect1);
253
    GetDlgItem(IDCANCEL)->GetWindowRect(rect2);
254
    CRect rect(rect1);
255
    rect.left-=(rect2.left-rect1.left);
256
    rect.right-=(rect2.right-rect1.right);
257
    ScreenToClient(rect);
258
    GetDlgItem(ID_APPLY_NOW)->MoveWindow(rect);
259
    GetDlgItem(ID_APPLY_NOW)->ShowWindow(SW_SHOW);
260
  }
261
 
262
  if(!m_bModal){
263
    SetTimer(0,100,0);
264
  }
265
  BringWindowToTop();
266
  return bResult;
267
}
268
 
269
void CRunTestsSheet::OnRun()
270
{
271
 
272
  if(Running==m_Status){
273
    outputpage.AddLogMsg(_T("Run canceled"));
274
    m_Status=Stopping;
275
    EnterCriticalSection(&m_CS);
276
    m_nNextToSubmit=0x7fffffff;
277
    LeaveCriticalSection(&m_CS);
278
    CeCosTest::CancelAllInstances();
279
  } else {
280
    outputpage.UpdateData(TRUE);
281
    summarypage.UpdateData(TRUE);
282
    executionpage.UpdateData(TRUE);
283
    if(0==executionpage.SelectedTestCount()){
284
      MessageBox(_T("No tests have selected for execution"));
285
    } else {
286
      m_ep=CeCosTest::ExecutionParameters(
287
        CeCosTest::ExecutionParameters::RUN,
288
        m_strTarget,
289
        TIMEOUT_NONE==m_nTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==m_nTimeoutType?900000:1000*m_nTimeout,
290
        TIMEOUT_NONE==m_nDownloadTimeoutType?0x7fffffff:TIMEOUT_AUTOMATIC==m_nDownloadTimeoutType?0:1000*m_nDownloadTimeout);
291
      if(m_bRemote){
292
        CTestResource::SetResourceServer(CeCosSocket::HostPort(m_strResourceHost,m_nResourcePort));
293
        if(!CTestResource::Load()){
294
          MessageBox(_T("Could not connect to resource server"));
295
          return;
296
        }
297
      } else {
298
        const String strPort(m_bSerial?(LPCTSTR)m_strPort:CeCosSocket::HostPort(m_strLocalTCPIPHost,m_nLocalTCPIPPort));
299
        if(0==strPort.size()){
300
          m_pResource=new CTestResource(_T(""),m_ep.PlatformName());
301
        } else {
302
          int nBaud=m_bSerial?m_nBaud:0;
303
          if (RESET_X10!=m_nReset) {
304
            m_pResource=new CTestResource(_T(""),m_ep.PlatformName(),strPort,nBaud);
305
          } else {
306
            m_pResource=new CTestResource(_T(""),m_ep.PlatformName(),strPort,nBaud,m_strReset);
307
          }
308
        }
309
      }
310
      m_Status=Running;
311
      SetDlgItemText(IDOK,_T("&Stop"));
312
      m_nNextToSubmit=0;
313
      outputpage.AddLogMsg(_T("Run started"));
314
      SubmitTests();
315
    }
316
  }
317
}
318
 
319
struct Info {
320
  CRunTestsSheet *pSheet;
321
  CeCosTest      *pTest;
322
};
323
 
324
DWORD CRunTestsSheet::X10ThreadFunc (void *pParam)
325
{
326
  Info *pInfo=(Info *)pParam;
327
  String str;
328
  bool bOk=false;
329
  CResetAttributes::ResetResult n=pInfo->pSheet->m_pResource->Reset(str);
330
  if(CResetAttributes::RESET_OK!=n){
331
    str+=_T(">>> Could not reset target\n");
332
  }
333
  str+=_TCHAR('\n');
334
  LPTSTR pszCopy=new TCHAR[1+str.size()];
335
  _tcscpy(pszCopy,str);
336
  pInfo->pSheet->PostMessage(WM_TESTOUTPUT,(WPARAM)pszCopy,0);
337
 
338
  if(bOk){
339
    // we're already in a thread, so we can call the function directly
340
    pInfo->pTest->RunLocal();
341
  }
342
  RunCallback(pInfo);
343
  return 0;
344
}
345
 
346
void CALLBACK CRunTestsSheet::RunLocalFunc(void *pParam)
347
{
348
  ((Info *)pParam)->pTest->RunLocal();
349
}
350
 
351
void CALLBACK CRunTestsSheet::RunRemoteFunc(void *pParam)
352
{
353
  ((Info *)pParam)->pTest->RunRemote(NULL);
354
}
355
 
356
void CRunTestsSheet::SubmitTests()
357
{
358
  int nResources=m_bRemote?max(1,CTestResource::GetMatchCount (m_ep)):1;
359
  if(nResources>CeCosTest::InstanceCount){
360
    if(m_nNextToSubmit>=executionpage.SelectedTestCount()){
361
      return;
362
    }
363
    Info *pInfo=new Info;
364
    pInfo->pTest=new CeCosTest(m_ep, executionpage.SelectedTest(m_nNextToSubmit++));
365
    pInfo->pSheet=this;
366
    m_nTestsToComplete++;
367
    if(m_bRemote){
368
      CeCosThreadUtils::RunThread(RunRemoteFunc,pInfo,RunCallback,_T("RunRemoteFunc"));
369
    } else {
370
      bool bRun=false;
371
      switch((ResetType)m_nReset){
372
        case RESET_NONE:
373
          bRun=true;
374
          break;
375
        case RESET_X10:
376
          // Resetting can take a while, so spawn a thread
377
          bRun=false;
378
          {
379
            DWORD dwID;
380
            CloseHandle(CreateThread(0,0,X10ThreadFunc, pInfo, 0, &dwID));
381
          }
382
          break;
383
        case RESET_MANUAL:
384
          bRun=(IDOK==MessageBox(_T("Press OK when target is reset - cancel to abort run"),NULL,MB_OKCANCEL));
385
          if(!bRun){
386
            m_nNextToSubmit=executionpage.SelectedTestCount();
387
            RunCallback(pInfo);
388
          }
389
          break;
390
      }
391
      if(bRun){
392
        CeCosThreadUtils::RunThread(RunLocalFunc,pInfo,RunCallback,_T("RunLocalFunc"));
393
      }
394
    }
395
  }
396
}
397
 
398
void CRunTestsSheet::RunCallback(void *pParam)
399
{
400
  Info *pInfo=(Info *)pParam;
401
  CRunTestsSheet *pSheet=pInfo->pSheet;
402
  if(::IsWindow(pSheet->m_hWnd)){ //FIXME
403
    CeCosTest *pTest=pInfo->pTest;
404
    EnterCriticalSection(&pSheet->m_CS);
405
 
406
    pSheet->summarypage.AddResult(pTest);
407
    delete pTest;
408
 
409
    pSheet->m_nTestsToComplete--;
410
    pSheet->SubmitTests();
411
 
412
    if(0==pSheet->m_nTestsToComplete){
413
      // It would be nice to do this in the handler for WM_RUNCOMPLETE, but we must be in the CS
414
      delete pSheet->m_pResource;
415
      pSheet->m_pResource=0;
416
      pSheet->PostMessage(WM_RUNCOMPLETE,0,0);
417
    }
418
    LeaveCriticalSection(&pSheet->m_CS);
419
  }
420
  delete pInfo;
421
}
422
 
423
LRESULT CRunTestsSheet::OnTestsComplete(WPARAM wParam, LPARAM lParam)
424
{
425
  UNUSED_ALWAYS(wParam);
426
  UNUSED_ALWAYS(lParam);
427
  m_Status=Stopped;
428
  SetDlgItemText(IDOK,_T("&Run"));
429
  outputpage.AddLogMsg(_T("Run complete"));
430
  return 0;
431
}
432
 
433
void CALLBACK CRunTestsSheet::TestOutputCallback(void *pParam,LPCTSTR psz)
434
{
435
  CRunTestsSheet*pWnd=(CRunTestsSheet*)pParam;
436
  if(::IsWindow(pWnd->m_hWnd)){ //FIXME
437
    LPTSTR pszCopy=new TCHAR[1+_tcslen(psz)];
438
    _tcscpy(pszCopy,psz);
439
    pWnd->PostMessage(WM_TESTOUTPUT,(WPARAM)pszCopy,0);
440
  }
441
}
442
 
443
LRESULT CRunTestsSheet::OnTestOutput(WPARAM wParam, LPARAM lParam)
444
{
445
  UNUSED_ALWAYS(lParam);
446
  LPTSTR psz=(LPTSTR)wParam;
447
  outputpage.AddText(psz);
448
  delete [] psz;
449
  return 0;
450
}
451
 
452
void CRunTestsSheet::OnProperties()
453
{
454
  CPropertiesDialog dlg(m_bHideTarget,m_bHideRemoteControls);
455
  dlg.m_strTarget=m_strTarget;
456
  dlg.m_nTimeout=m_nTimeout;
457
  dlg.m_nDownloadTimeout=m_nDownloadTimeout;
458
  dlg.m_nTimeoutType=m_nTimeoutType;
459
  dlg.m_nDownloadTimeoutType=m_nDownloadTimeoutType;
460
  dlg.m_bRemote=m_bRemote;
461
  dlg.m_bSerial=m_bSerial;
462
  dlg.m_strPort=m_strPort;
463
  dlg.m_nBaud=m_nBaud;
464
  dlg.m_strLocalTCPIPHost=m_strLocalTCPIPHost;
465
  dlg.m_nLocalTCPIPPort=m_nLocalTCPIPPort;
466
  dlg.m_nReset=m_nReset;
467
  dlg.m_strReset=m_strReset;
468
  dlg.m_strResourceHost=m_strResourceHost;
469
  dlg.m_nResourcePort=m_nResourcePort;
470
  dlg.m_strRemoteHost=m_strRemoteHost;
471
  dlg.m_nRemotePort=m_nRemotePort;
472
  dlg.m_strPort=m_strPort;
473
  dlg.m_bFarmed=m_bFarmed;
474
  if(IDOK==dlg.DoModal()){
475
    m_strTarget=(LPCTSTR)dlg.m_strTarget;
476
    m_nTimeout=dlg.m_nTimeout;
477
    m_nDownloadTimeout=dlg.m_nDownloadTimeout;
478
    m_nTimeoutType=dlg.m_nTimeoutType;
479
    m_nDownloadTimeoutType=dlg.m_nDownloadTimeoutType;
480
    m_bRemote=dlg.m_bRemote;
481
    m_bSerial=dlg.m_bSerial;
482
    m_strPort=(LPCTSTR)dlg.m_strPort;
483
    m_nBaud=dlg.m_nBaud;
484
    m_strLocalTCPIPHost=(LPCTSTR)dlg.m_strLocalTCPIPHost;
485
    m_nLocalTCPIPPort=dlg.m_nLocalTCPIPPort;
486
    m_nReset=dlg.m_nReset;
487
    m_strReset=(LPCTSTR)dlg.m_strReset;
488
    m_strResourceHost=(LPCTSTR)dlg.m_strResourceHost;
489
    m_nResourcePort=dlg.m_nResourcePort;
490
    m_strRemoteHost=(LPCTSTR)dlg.m_strRemoteHost;
491
    m_nRemotePort=dlg.m_nRemotePort;
492
    m_bFarmed=dlg.m_bFarmed;
493
    if(m_pInitFunc){
494
      m_pInitFunc(&m_prop,true);
495
    }
496
  }
497
}
498
 
499
void CRunTestsSheet::OnClose()
500
{
501
  if(m_pInitFunc){
502
    WINDOWPLACEMENT wndpl;
503
    wndpl.length = sizeof(WINDOWPLACEMENT);
504
    GetWindowPlacement(&wndpl);
505
    if(!IsWindowVisible()){
506
                    wndpl.showCmd=SW_HIDE;
507
    }
508
    m_strPlacement.Format(_T("%d %d %d %d %d"),
509
      wndpl.rcNormalPosition.left,
510
      wndpl.rcNormalPosition.top,
511
      wndpl.rcNormalPosition.right,
512
      wndpl.rcNormalPosition.bottom,
513
      wndpl.showCmd);
514
    m_pInitFunc(&m_prop,true);
515
  }
516
  if(m_bModal){
517
    EndDialog(IDOK);
518
  } else {
519
    DestroyWindow();
520
  }
521
}
522
 
523
 
524
 
525
void CRunTestsSheet::OnSysCommand(UINT nID, LPARAM lParam)
526
{
527
  if(SC_CLOSE==nID){
528
    OnClose();
529
  } else {
530
    CeCosPropertySheet::OnSysCommand(nID, lParam);
531
  }
532
}
533
 
534
void CRunTestsSheet::OnSize(UINT nType, int cx, int cy)
535
{
536
  // WS_OVERLAPPEDWINDOW would preclude caption bar help button
537
  ModifyStyle(0,WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME ,0);
538
  CeCosPropertySheet::OnSize(nType, cx, cy);
539
  if(SIZE_MINIMIZED!=nType){
540
    CRect rect;
541
    GetWindowRect(rect);
542
    TRACE(_T("OnSize(%d) left=%d top=%d right=%d bottom=%d ar=%d\n"),nType,rect.left,rect.top,rect.right,rect.bottom,m_bAllowResizing);
543
 
544
    m_rcOffset.left  =rect.left-m_rcPrev.left;
545
    m_rcOffset.right =rect.right-m_rcPrev.right;
546
    m_rcOffset.top   =rect.top-m_rcPrev.top;
547
    m_rcOffset.bottom=rect.bottom-m_rcPrev.bottom;
548
 
549
    m_rcPrev=rect;
550
 
551
    if(m_bAllowResizing){
552
      cx=max(m_cxMin,cx);
553
      cy=max(m_cyMin,cy);
554
      MoveWindow(GetTabControl(),Stretch);
555
      CRect rc[sizeof(arIds)/sizeof(arIds[0])];
556
      CRect rcSheet;
557
      GetWindowRect(rcSheet);
558
      for(int i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){
559
        CWnd *pWnd=GetDlgItem(arIds[i]);
560
        if(pWnd){
561
          pWnd->GetWindowRect(rc[i]);
562
          ScreenToClient(rc[i]);
563
          MoveWindow(pWnd,BottomRight,FALSE);
564
        }
565
      }
566
 
567
      for(i=0;i<sizeof(arIds)/sizeof(arIds[0]);i++){
568
        CWnd *pWnd=GetDlgItem(arIds[i]);
569
        if(pWnd){
570
          pWnd->Invalidate();
571
          InvalidateRect(rc[i]);
572
        } else {
573
          TRACE(_T("Failed to find window id=%x\n"),arIds[i]);
574
        }
575
      }
576
 
577
      for(i=0;i<GetPageCount();i++){
578
        MoveWindow(GetPage(i),Stretch);
579
      }
580
 
581
    }
582
  }
583
}
584
 
585
void CRunTestsSheet::MoveWindow(CWnd *pWnd, AffinityType Affinity,bool bRepaint)
586
{
587
  if(m_bAllowResizing&&pWnd){
588
    TRACE(_T("MoveWindow left=%d top=%d right=%d bottom=%d\n"),m_rcOffset.left,m_rcOffset.top,m_rcOffset.right,m_rcOffset.bottom);
589
    CRect rect;
590
    pWnd->GetWindowRect(rect);
591
    pWnd->GetParent()->ScreenToClient(rect);
592
    TRACE(_T("           left=%d top=%d right=%d bottom=%d"),rect.left,rect.top,rect.right,rect.bottom);
593
    int nHeight=rect.Height();
594
    int nWidth=rect.Width();
595
 
596
    switch(Affinity){
597
    case BottomRight:
598
      rect.right +=m_rcOffset.Width();
599
      rect.bottom+=m_rcOffset.Height();
600
      rect.top =rect.bottom-nHeight;
601
      rect.left=rect.right -nWidth;
602
      break;
603
    case TopRight:
604
      rect.right +=m_rcOffset.Width();
605
      rect.left=rect.right -nWidth;
606
      break;
607
    case BottomLeft:
608
      rect.top +=m_rcOffset.Height();
609
      rect.right=rect.left+nWidth;
610
      break;
611
    case TopLeft:
612
      break;
613
    case Stretch:
614
      rect.right +=m_rcOffset.Width();
615
      rect.bottom+=m_rcOffset.Height();
616
      break;
617
    }
618
    TRACE(_T("        -> left=%d top=%d right=%d bottom=%d\n"),rect.left,rect.top,rect.right,rect.bottom);
619
    pWnd->MoveWindow(rect,bRepaint);
620
  }
621
}
622
 
623
void CRunTestsSheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
624
{
625
  lpMMI->ptMinTrackSize.x = m_cxMin;
626
  lpMMI->ptMinTrackSize.y = 175;
627
  CeCosPropertySheet::OnGetMinMaxInfo(lpMMI);
628
}
629
 
630
LRESULT CRunTestsSheet::OnKickIdle(WPARAM, LPARAM)
631
{
632
  // We could use WM_KICKIDLE to drive CMDUI messages, but in fact we just
633
  // use an OnKickIdle handler directly (here and in the pages) to control
634
  // button greying.
635
  bool bEnableRunStop=false;
636
  bool bEnableProperties=false;
637
  switch(m_Status){
638
  case Running:
639
    bEnableRunStop=true;
640
    break;
641
  case Stopping:
642
    bEnableProperties=true;
643
    break;
644
  case Stopped:
645
    bEnableRunStop=executionpage.SomeTestsSelected();
646
    bEnableProperties=true;
647
    break;
648
  }
649
  GetDlgItem(IDOK)->EnableWindow(bEnableRunStop);
650
  GetDlgItem(ID_APPLY_NOW)->EnableWindow(bEnableProperties);
651
  SendMessageToDescendants(WM_KICKIDLE, 0, 0, FALSE, FALSE);
652
  return 0;
653
}
654
 
655
BOOL CRunTestsSheet::PreTranslateMessage(MSG* pMsg)
656
{
657
  if(WM_KEYDOWN==pMsg->message && VK_ESCAPE==pMsg->wParam){
658
    return TRUE;// escape character handled
659
  }
660
  return CeCosPropertySheet::PreTranslateMessage(pMsg);
661
}
662
 
663
void CRunTestsSheet::SetTarget(LPCTSTR pszTarget)
664
{
665
  m_strTarget=pszTarget;
666
  m_bHideTarget=true;
667
}
668
 
669
void CRunTestsSheet::HideRemoteControls()
670
{
671
  m_bHideRemoteControls=true;
672
}
673
 
674
void CRunTestsSheet::Populate(LPCTSTR pszFile,bool bSelect/*=true*/)
675
{
676
  executionpage.m_arstrPreLoad.SetAt(pszFile,bSelect?this:0);
677
}
678
 
679
 
680
int CRunTestsSheet::DoModal()
681
{
682
  m_bModal=true;
683
  return CeCosPropertySheet::DoModal();
684
}
685
 
686
void CRunTestsSheet::PostNcDestroy()
687
{
688
  if(!m_bModal){
689
    delete this;
690
  } else {
691
    CeCosPropertySheet::PostNcDestroy();
692
  }
693
}
694
 
695
void CRunTestsSheet::OnTimer(UINT nIDEvent)
696
{
697
  SendMessage(WM_KICKIDLE,0,0);
698
  CeCosPropertySheet::OnTimer(nIDEvent);
699
}
700
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.