// CASE2.cpp :
// Set Common Break point
#define  __cplusplus
#include "stdafx.h"
#include "tutorial.h"
#include "mainfrm.h"
#include "SRCWND.h"   
#include "Varwnd.h"
//#include "setbp.h"

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

extern BOOL g_bAuto;
/*-------------------------------------------------------*/
/*             How to use variable window                */
/*-------------------------------------------------------*/
void CMainFrame::HowToUseVarWnd(UINT *nCase)
{
 CPoint         pointDest;
 CPoint         pointSrc;
 CRect          rect;

 if(m_pVarWnd)
   { m_pVarWnd->SetFocus();
     SetWnd(m_pVarWnd);}

 if(m_pDlg)
   m_pDlg->SetFocus();    

   
 SetMouse(0);
 switch(* nCase)
   {
    case 1: 
         SetByUser(FALSE); 
         SetKey(0);
		 WriteMsg(IDS_VARIABLE_MSG,DOOROPEN,"Watch Variable");
		 ((CSrcWnd *)m_pWnd)->ChangToUseOperate(FALSE);
		 m_uMenuAct = UINT(ID_WINDOW_VARIABLE | ID_VARIABLE_ADD);
		 if(g_bAuto)    
		   {       
		    KillTimer(IDAUTO);
		    SetTimer(IDAUTO, 4000,NULL);
		    SetSysMouse(1);
		    SetSysKey(1);
		   } 
		 break;
	case 2: 
	     pointDest.x=323;
	     pointDest.y=32;   
	     GetCursorPos(&pointSrc); 
	     m_bPostToMain=1;
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(6,'W',13,2);
		 return;
	case 3:
	     pointDest.x=260;
	     pointDest.y=32;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(5,'A',1);
		 return; 
	case 4:
	     if(!m_pDlg)         
	       { break;
	         *nCase=100;}
         rect.SetRect(WinCxy.x+80    ,WinCxy.y+320+2-50,
                      WinCxy.x+4+330,WinCxy.y+320+80-2-20);
         OverMsg.SetPaintRect(rect);                        
	     ((CVarAddDlg *)m_pDlg)->SetCombo();
		 break;
	case 5:                              
	     if(!m_pDlg)         
	       { break;
	         *nCase=100;}
		 ((CVarAddDlg *)m_pDlg)->SetOk();
		 break;   
	case 6:
	     pointDest.x=WinCxy.x+350;
	     pointDest.y=WinCxy.y+100;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 ((CVarWnd *)m_pWnd)->GetListVar()->SetCurSel(0);
		 ((CVarWnd *)m_pWnd)->SetOpen();
		 m_pWnd->SetFocus();
		 break;
	case 7:
	     pointDest.x=WinCxy.x+350;
	     pointDest.y=WinCxy.y+100;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 ((CVarWnd *)m_pWnd)->GetListVar()->SetCurSel(0);
		 ((CVarWnd *)m_pWnd)->SetOpen();
		 m_pWnd->SetFocus();
		 break;
	case 8:
		 //WriteMsg(IDS_VARIABLE_STEP);
         m_pWnd->MDIDestroy();
         break;
    case 90:                        
         WriteMsg(IDS_SET_MAP_MSG2);   
         ((CSrcWnd *)m_pWnd)->ChangToUseOperate();
         SetKey(1); 
	     
	     SetByUser(TRUE);
         break;
    case 100: 
         if(EndCase(&bByUser,IDS_SRCGRP6_TUT1,nCase))
	       { 
	        ((CSrcWnd *)m_pWnd)->ChangToUseOperate(FALSE);
	        RestoreBk(MS_STEP);
	        m_uNextCaseID=3000;//ID_CASE_GO; 
	        PostMessage(WM_COMMAND,ID_NEXT,0L);
           }
         break;
    default:
		 SetNextAction(0);
		 RestoreBk(MS_STEP);
	     m_uNextCaseID=3000;//ID_CASE_GO; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
   }    
 SetMouse(1);  
}                  
/*-------------------------------------------------------*/
/*             How to step                               */
/*-------------------------------------------------------*/
void CMainFrame::HowToStep(UINT *nCase)
{
 CPoint         pointDest;
 CPoint         pointSrc;
 CRect          rect;

 SetMouse(0);    

 switch(* nCase)
   {
    case 1:              
         SetByUser(FALSE); 
         SetKey(0);
		 WriteMsg(IDS_STEP_OVER,DOOROPEN,"Step Over");
		 ((CSrcWnd *)m_pWnd)->ChangeMode(SR_SOURCE);   
		 ((CSrcWnd *)m_pWnd)->Step(16);   
		 ((CSrcWnd *)m_pWnd)->SetBP();
		 WndMouse(12,215,WM_LBUTTONDOWN,TRUE);
		 ((CSrcWnd *)m_pWnd)->ChangToUseOperate(FALSE);
		 m_uMenuAct = UINT(ID_RUN_STEPOVER|ID_RUN_STEPINTO);
		 if(g_bAuto)    
		   {       
		    KillTimer(IDAUTO);
		    SetTimer(IDAUTO, 4000,NULL);
		    SetSysMouse(1);
		    SetSysKey(1);
		   } 
		 break;
	case 2:	    
	     pointDest.x=374;
	     pointDest.y=53;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);//pointSrc);
		 ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetToolBar()->
		  PostMessage(WM_LBUTTONDOWN,0,MAKELONG(371,30));
		 ((CSrcWnd *)m_pWnd)->OnVRunStepover();
		 break;
    case 3:
	     pointDest.x=374;
	     pointDest.y=53;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetToolBar()->
		 PostMessage(WM_LBUTTONDOWN,0,MAKELONG(371,30));
		 ((CSrcWnd *)m_pWnd)->OnVRunStepover();
		 break;
    case 4: 
	     pointDest.x=374;
	     pointDest.y=53;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetToolBar()->
		 PostMessage(WM_LBUTTONDOWN,0,MAKELONG(371,30));
		 ((CSrcWnd *)m_pWnd)->OnVRunStepover();
		 break;
    case 5:
	     pointDest.x=374;
	     pointDest.y=53;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->GetToolBar()->
		 PostMessage(WM_LBUTTONDOWN,0,MAKELONG(371,30));
		 ((CSrcWnd *)m_pWnd)->OnVRunStepover();
		 break;
    case 6:
         SetKey(1);
		 SetNextAction(0);
	     m_uNextCaseID=ID_CASE_VARIABLE; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
    default:  
         SetKey(1);
		 SetNextAction(0);
	     m_uNextCaseID=ID_CASE_VARIABLE; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
   }    

 SetMouse(1);    
} 

/*-------------------------------------------------------*/
/*             How to select mode                        */
/*-------------------------------------------------------*/
void CMainFrame::HowToSelMode(UINT *nCase)
{
 CPoint         pointDest;
 CPoint         pointSrc;
 CRect          rect;

 SetMouse(0);    

 switch(* nCase)
   {
    case 1:              
         SetByUser(FALSE); 
         SetKey(0);
		 PostMessage(WM_COMMAND,ID_SHOW_SRC,0L);
		 WriteMsg(IDS_SEL_MODE_MSG1,DOOROPEN,"Select Mode");
		 m_uMenuAct = UINT(ID_VIEW_MIXED|ID_VIEW_SOURCEONLY);
		 if(g_bAuto)    
		   {       
		    KillTimer(IDAUTO);
		    SetTimer(IDAUTO, 4000,NULL);
		    SetSysMouse(1);
		    SetSysKey(1);
		   } 
		 break;
	case 2:	          
	     pointDest.x=102;
	     pointDest.y=32;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(2,'V',1);
		 return;
	case 3:
	     pointDest.x=102;
	     pointDest.y=32;   
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(2,'V',2);
		 return;
    case 40:
         SetKey(1); 
         //WriteMsg(IDS_SET_MAP_MSG2);  
         ((CSrcWnd *)m_pWnd)->ChangeMode(SR_ASSAMBLE);
         ((CSrcWnd *)m_pWnd)->ChangToUseOperate();
/*
	     SetByUser(TRUE);
	     if(m_pWnd)                   
	        m_pWnd->ShowWindow(SW_HIDE);
*/
         break; 
    case 50: 
		 SetNextAction(0);
	     m_uNextCaseID=ID_CASE_STEP; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
    default:
		 SetNextAction(0);
	     m_uNextCaseID=ID_CASE_STEP; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
   }    

 SetMouse(1);    
}
/*-------------------------------------------------------*/
/*           How to set common break point               */
/*-------------------------------------------------------*/
void CMainFrame::HowToSetBreakPoint(UINT *nCase)
{
 CPoint         pointDest;
 CPoint         pointSrc;
 CRect          rect;
 if(m_pDlg)
   {
    
    if((*nCase)>8)
      if(GetAMsgDlg())
        { 
         CloseDlg(GetAMsgDlg());
        /* 
         (*nCase)--;
         ((CMainFrame *)(AfxGetApp()->m_pMainWnd))->
          GetAMsgDlg()->SetFocus();
         MessageBeep(-1);
         return;
        */ 
        }   
  
     m_pDlg->SetFocus();    
   }                 
 SetMouse(0);    

 switch(* nCase)
   {
    case 1:              
         SetByUser(FALSE);
		 WriteMsg(IDS_SET_BP_MSG1,DOOROPEN,"Set Breakpoint");
		 m_uMenuAct = ID_RUN_BREAKPOINT;
		 if(g_bAuto)    
		   {       
		    KillTimer(IDAUTO);
		    SetTimer(IDAUTO, 4000,NULL);
		    SetSysMouse(1);
		    SetSysKey(1);
		   } 

		 break;

	case 2:	 
         rect.SetRect(WinCxy.x+6    ,WinCxy.y+370+4,
                      WinCxy.x+4+330,WinCxy.y+370+84);
         OverMsg.SetPaintRect(rect);             
         SetKey(0);//setKeyFilter
		 //Choose Map Menu Item
         StepMsg.SetFont(12,5,400);
         OverMsg.SetFont(16,6,200);
		 PostMessage(WM_COMMAND,ID_SHOW_SRC,0L);
		 return;
    case 3:	     
         ((CSrcWnd *)m_pWnd)->SetBP();
    	 WndMouse(12,32,WM_LBUTTONDOWN);
    	 SetNoteMsg(IDS_SET_BP_MOUSE,1);
		 break; 

	case 4:              
	     pointDest.x=200;
	     pointDest.y=32;   
	     ((CSrcWnd *)m_pWnd)->SetBP();
	     WndMouse(12,32,WM_LBUTTONDOWN,TRUE);
	     SetNoteMsg(IDS_SET_BP_MENU,1);
	     GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(4,'R',10,3);
         //////////////////////////////////////////////////////////////
         rect.SetRect(WinCxy.x+6    ,WinCxy.y+382,    /////////////////
                      WinCxy.x+6+327,WinCxy.y+382+70);/////////////////
         OverMsg.SetPaintRect(rect,FALSE);             
		 return; 
		 
	case 5:
	case 6:
	case 7:
	case 8:
	case 9:
	case 10:
	case 11:
	case 12:
	case 13:
	case 14:
	case 15:
	     if(m_pDlg)
		 {
		    m_pDlg->SetFocus();  
		   ((CBPDialog *)m_pDlg)->IntroduceBk(*nCase-4);  
		 }
		 if(*nCase==15)
		   { ((CSrcWnd *)m_pWnd)->SetBP();
		     WndMouse(12,32,WM_LBUTTONDOWN,1);    
		     delete m_pDlg;
		   }  
         break;

    case 160: 
         rect.SetRect(WinCxy.x+450,WinCxy.y+72,
	                  WinCxy.x+450+182,WinCxy.y+72+185);
	     StepMsg.SetPaintRect(rect);             
	     SetStepMsg(IDS_SRCGRP6_STEP,1);
	     WriteMsg(IDS_SRCGRP6_MSG);  
	    // WndMouse(12,32,WM_LBUTTONDOWN,TRUE);
         break; 
    case 16:      
         SetKey(1);
         ((CSrcWnd *)m_pWnd)->ChangToUseOperate();
         m_pDlg=0;
      /*   
	     SetByUser(TRUE);
	     if(m_pWnd)                   
	        m_pWnd->ShowWindow(SW_HIDE);
	   */     
         break;
    case 180: 
         if(EndCase(&bByUser,IDS_SRCGRP6_TUT1,nCase))
	       { 
	        ((CSrcWnd *)m_pWnd)->ChangToUseOperate(FALSE);
	        RestoreBk(MS_STEP);
	        m_uNextCaseID=ID_CASE_GO; 
	        PostMessage(WM_COMMAND,ID_NEXT,0L);
           }
         break;
    default:
		 SetNextAction(0); 
		 //((CSrcWnd *)m_pWnd)->ChangToUseOperate(FALSE);
		 RestoreBk(MS_STEP);
	     m_uNextCaseID=ID_CASE_GO; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
   }    

 SetMouse(1);    

}

/*-------------------------------------------------------*/
/*                go oparetion                           */
/*-------------------------------------------------------*/
void CMainFrame::HowToGo(UINT *nCase)
{
 CPoint         pointDest;
 CPoint         pointSrc;
 CRect          rect;

 SetMouse(0);    

 switch(* nCase)
   {
    case 1:    
         SetByUser(FALSE);
		 WriteMsg(IDS_GO_MSG1,DOOROPEN,"Go ");
		 m_uMenuAct = ID_RUN_GO;
		 if(g_bAuto)    
		   {       
		    KillTimer(IDAUTO);
		    SetTimer(IDAUTO, 4000,NULL);
		    SetSysMouse(1);
		    SetSysKey(1);
		   } 
		 break;

	case 2:	 
		 if(m_pWnd==NULL)
		    PostMessage(WM_COMMAND,ID_SHOW_SRC,0L);
		 else
		  {  
             ((CSrcWnd *)m_pWnd)->DeleteBp(NULL);
             ((CSrcWnd *)m_pWnd)->ChangToUseOperate(FALSE);
	         m_pWnd->ShowWindow(SW_HIDE);
	      }   

         rect.SetRect(WinCxy.x+6    ,WinCxy.y+370+4,
                      WinCxy.x+4+330,WinCxy.y+370+84);
         OverMsg.SetPaintRect(rect);                        
         SetKey(0);//setKeyFilter
		 //Choose Map Menu Item
         StepMsg.SetFont(12,5,400);
         OverMsg.SetFont(16,6,200);
		 return;
    case 3:      
         ((CSrcWnd *)m_pWnd)->SetBP();
    	 WndMouse(12,32,WM_LBUTTONDOWN);
    	 SetNoteMsg(IDS_SET_BP_MOUSE,1);
         break;
    case 4:
		 pointDest.x=206;
		 pointDest.y=30;
		 GetCursorPos(&pointSrc);
		 MoveCursor(pointDest,pointSrc);
		 DrapMenu(4,'R',1);
		 m_uMenuAct = ID_RUN_GO;
         return;
     case 50:                           
         rect.SetRect(WinCxy.x+450,WinCxy.y+72,
	                  WinCxy.x+450+182,WinCxy.y+72+185);
	     StepMsg.SetPaintRect(rect);             
	     SetStepMsg(IDS_GO_STEP,1);
	     WriteMsg(IDS_SRCGRP6_MSG);  
         break;  
     case 5:   
         SetKey(1);
         ((CSrcWnd *)m_pWnd)->ChangeMode(SR_ASSAMBLE);
         ((CSrcWnd *)m_pWnd)->ChangToUseOperate();
	     SetByUser(TRUE);
	     if(m_pWnd)                   
	       {
	         m_pWnd->DestroyWindow();//(SW_HIDE);
	         //delete m_pWnd;
	         m_pWnd=0;
	       }  
         break; 

    case 70: 
         if(EndCase(&bByUser,IDS_SET_MAP_TUT1,nCase))
	       {     
	        CloseWnd(m_pWnd);      
	        m_uNextCaseID=ID_CASE_MODE_SEL; 
	        PostMessage(WM_COMMAND,ID_NEXT,0L);
           }
         break;
    default:   
	     SetNextAction(0);
		 RestoreBk(MS_STEP);       
		 CloseWnd(m_pWnd);      
	     m_uNextCaseID=ID_CASE_MODE_SEL; 
	     PostMessage(WM_COMMAND,ID_NEXT,0L);
         break;
   }    

 SetMouse(1);    

}
