
/***************************************************************************
**
**    $Header:   D:/ECB2S/SRC/LOG/TRCGTDLG.CPP   1.2.1.4   17 Apr 1997 16:07:26   ZJRD  $
**
**    $Log:   D:/ECB2S/SRC/LOG/TRCGTDLG.CPP  $
** 
**    Rev 1.2.1.4   17 Apr 1997 16:07:26   ZJRD
** No change.
** 
**    Rev 1.2.1.3   16 Apr 1997 10:42:12   ZJRD
** No change.
** 
**    Rev 1.2.1.2   10 Apr 1997 15:47:52   ZJRD
** No change.
** 
**    Rev 1.2.1.1   03 Apr 1997 15:27:00   ZJRD
** No change.
** 
**    Rev 1.2.1.0   28 Mar 1997 10:30:18   ZJRD
** easy pack sld 2.09d
** 
**    Rev 1.1   19 Mar 1997 11:39:36   ZJRD
** No change.
** 
**    Rev 1.0   12 Mar 1997 14:52:44   ZJRD
** Initial revision.
** 
**    Rev 1.7.1.0.1.2   09 Dec 1996 10:14:54   ZJRD
** EasyPack/SLD Version 2.0P
** 
**    Rev 1.7.1.0.1.0   11 Nov 1996 12:58:10   ZJRD
** EasyPack/SLD Version 2.01
** 
**    Rev 1.7.1.4   09 Sep 1996 13:15:16   ZJRD
** No change.
** 
**    Rev 1.7.1.3   05 Sep 1996 11:26:48   ZJRD
** No change.
** 
**    Rev 1.7.1.2   02 Sep 1996 09:53:54   ZJRD
** No change.
** 
**    Rev 1.7.1.1   28 Aug 1996 15:47:30   ZJRD
** No change.
** 
**    Rev 1.7.1.0   12 Aug 1996 10:52:12   ZJRD
** EasyPack/SLD Version 1.98
** 
**    Rev 1.5   05 Jun 1996 14:55:34   ZJRD
** No change.
** 
**    Rev 1.4   29 May 1996 09:38:14   ZJRD
** No change.
** 
**    Rev 1.3   16 May 1996 09:00:30   ZJRD
** No change.
** 
**    Rev 1.2   10 May 1996 09:14:58   ZJRD
** No change.
** 
**    Rev 1.1   02 May 1996 10:22:48   ZJRD
** EasyPack/SLD Version 1.92
** 
**    Rev 1.31   18 Apr 1996 13:02:34   Shirley
** No change.
** 
**    Rev 1.30   12 Apr 1996 10:36:40   Shirley
** EasyPack/SLD Version 1.90
** 
**    Rev 1.28   15 Feb 1996 08:49:38   Shirley
** No change.
** 
**    Rev 1.27   12 Feb 1996 14:02:08   Shirley
** No change.
** 
**    Rev 1.26   06 Feb 1996 15:27:22   Shirley
** No change.
** 
**    Rev 1.25   06 Feb 1996 13:43:00   Shirley
** No change.
** 
**    Rev 1.24   01 Feb 1996 10:15:52   Shirley
** No change.
** 
**    Rev 1.23   26 Jan 1996 09:12:44   Shirley
** No change.
** 
**    Rev 1.22   25 Jan 1996 13:13:24   Shirley
** No change.
** 
**    Rev 1.21   24 Jan 1996 10:39:10   Shirley
** No change.
** 
**    Rev 1.20   23 Jan 1996 11:28:00   Shirley
** No change.
** 
**    Rev 1.19   18 Jan 1996 10:09:56   Shirley
** No change.
** 
**    Rev 1.18   15 Jan 1996 16:16:12   Shirley
** No change.
** 
**    Rev 1.17   04 Jan 1996 11:11:44   Shirley
** No change.
** 
**    Rev 1.16   30 Nov 1995 09:08:22   Shirley
** No change.
** 
**    Rev 1.15   28 Nov 1995 15:34:54   Shirley
** No change.
** 
**    Rev 1.14   21 Nov 1995 11:22:38   Shirley
** No change.
** 
**    Rev 1.13   13 Nov 1995 09:27:58   Shirley
** No change.
** 
**    Rev 1.12   12 Nov 1995 11:31:30   Shirley
** No change.
** 
**    Rev 1.11   08 Nov 1995 16:28:04   Shirley
** No change.
** 
**    Rev 1.10   08 Nov 1995 12:41:18   Shirley
** No change.
** 
**    Rev 1.9   02 Nov 1995 10:03:16   Shirley
** No change.
** 
**    Rev 1.8   27 Oct 1995 16:46:26   Shirley
** No change.
** 
**    Rev 1.7   27 Oct 1995 13:48:46   Shirley
** EasyPack/SLD Version 0.1g
** 
**    Rev 1.4   13 Oct 1995 13:20:58   Shirley
** No change.
** 
**    Rev 1.3   29 Sep 1995 09:53:16   Shirley
** No change.
** 
**    Rev 1.2   20 Sep 1995 10:54:46   Shirley
** EasyPack/SLD Version 0.1b
** 
**    Rev 1.1   15 Sep 1995 09:49:16   Shirley
** EasyPack/SLDV0.1a 
** 
**    Rev 1.0   07 Sep 1995 09:54:16   Shirley
** Initial revision.
**
****************************************************************************/

/////////////////////////////////////////////////////////////////////////////
//
//  File name:  TRCGTDLG.CPP
//
//  Description:The implement file for the class: CTrcGtdlg
//
//  Author:     Lane Li
//
//  Date:       09/10/95
//
//  Modification:
//
//      1. 09/10/95, Initial version
//
//
//  Copyright (C) 1995 Microtek International. All rights reserved.
//
/////////////////////////////////////////////////////////////////////////////

// trcgtdlg.cpp : implementation file
//

#include "stdafx.h"       
#include "resource.h"
#include "xview.h"
#include "lanecom.h"
#include "spin.h"
#include "myedit.h"
#include "trcgtdlg.h"
#include "stdlib.h"
#include "trcserve.h"
#include "uicom.h"

#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTrcGtdlg dialog
                     

CTrcGtdlg::CTrcGtdlg(CWnd* pParent /*=NULL*/)
    : CDialog(CTrcGtdlg::IDD, pParent)
{
    //{{AFX_DATA_INIT(CTrcGtdlg)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
    CMyEdit::m_edit2=NULL;
    CMyEdit::m_edit1=NULL;
}

void CTrcGtdlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CTrcGtdlg)
        // NOTE: the ClassWizard will add DDX and DDV calls here
    //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTrcGtdlg, CDialog)
    //{{AFX_MSG_MAP(CTrcGtdlg)
    ON_BN_CLICKED(IDC_TRC_GOTO_OK, OnTrcGotoOk)
    ON_BN_CLICKED(IDC_TRC_GOTO_CANCEL, OnTrcGotoCancel)
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CTrcGtdlg message handlers

void CTrcGtdlg::OnTrcGotoOk()
{
    // TODO: Add your control notification handler code here   
    char text[20];
    char text2[20];
    long result1;
    int result;   
    BOOL bOk;
    long lvalue;
    int i, len;      
    CWnd* ctrl;

    bOk = TRUE; 
    GetDlgItemText(IDC_TRC_GOTO_COMBO, text, 7);
    if ((text[0]=='0')&&((text[1]=='x')||(text[1]=='X')))
    {
        i=2;
        len=strlen(text);
        while(text[i]=='0')
        	i++;
        if(text[i]=='\0')
        	i--;
        if(i!=2)
        	{
        	 memmove(&text[2], &text[i], len-i);
        	 text[2+len-i]='\0';
        	} 
        lvalue = strtol(text,NULL,16);
        if ((lvalue>0xffff)||(lvalue<0)) bOk = FALSE;
        _ultoa(lvalue,text2 , 16);
        if (lstrcmpi(text2,text+2)!=0)
            bOk = FALSE;
        if (bOk) result = (int)lvalue;
    }
    else
    {
        i=0;
        len=strlen(text);
        while(text[i]=='0')
        	i++;
        if(text[i]=='\0')
        	i--;
        if(i!=0)
        	{
        	 memmove(&text[0], &text[i], len-i);
        	 text[len-i]='\0';
        	} 
        lvalue = strtol(text,NULL,10);
        if ((lvalue>0xffff)||(lvalue<0)) bOk = FALSE;
        _ultoa(lvalue,text2 , 10);
        if (lstrcmpi(text2,text)!=0)
            bOk = FALSE;
        if (bOk) result = lvalue;
    }
    if (m_lastFrame<result||result<0)
    	bOk=FALSE;	
    if (!bOk)
    {   
        MessageBeep(-1);
        MessageBox("Input Error",NULL,MB_OK|MB_ICONEXCLAMATION);
        ctrl = GetDlgItem(IDC_TRC_GOTO_COMBO);
        ((CEdit *)ctrl)->SetFocus();
        ((CEdit *)ctrl)->SetSel(0,-1);
        return;
    }
    EndDialog(result);
}

void CTrcGtdlg::OnTrcGotoCancel()
{
    // TODO: Add your control notification handler code here
    EndDialog(-1);
    
}

BOOL CTrcGtdlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    CenterWindow();
    
    // TODO: Add extra initialization here
    char text[50];

    sprintf(text+2,"%x",nPrevGotoFrameNo);
    text[0]='0';
    text[1]='x';
    SetDlgItemText(IDC_TRC_GOTO_COMBO,text);

    m_edit.SubclassEdit(IDC_TRC_GOTO_COMBO, this, PES_NUMBERS);
    UINT lastFrame;
    int nErrorID = ICE_OK;
    if(g_bTraceClear)
    	lastFrame=0;
    else
    	AbiGetTraceLastFrame(&lastFrame);
    if (ICE_OK != nErrorID)
    {
        lastFrame = 0;
    }                     
    if (lastFrame>0) lastFrame--;
    if (lastFrame>32767) lastFrame = 32767;
    if (lastFrame>1) m_edit.SetRange(0, (int)lastFrame);
    else m_edit.SetRange(0,0);
    sprintf(text,"Frame [0 - %d/0x%X]",lastFrame,lastFrame);
    m_lastFrame=lastFrame;
    SetDlgItemText(IDC_TRC_GOTO_STATIC,text);

    RECT rect;
    m_edit.GetWindowRect(&rect);
    ScreenToClient(&rect);
//    rect.left = 255;
//    rect.top = 41;
//    rect.right = 270;
//    rect.bottom = 61;
    rect.left = rect.right + 2;
    rect.right = rect.left + 15;
    m_spin.Create(WS_VISIBLE | WS_CHILD | MSS_VERTICAL,
        rect,this,IDC_TRC_GOTO_COMBO);
    m_spin.SetAssociate(&m_edit);
    m_edit.SetFocus();
    m_edit.SetSel(0,-1);
    return FALSE;  // return TRUE  unless you set the focus to a control
}
