📄 sdbmsdemoview.cpp
字号:
// SdbmsDemoView.cpp : implementation of the CSdbmsDemoView class
//
#include "stdafx.h"
#include "SdbmsDemo.h"
#include "MainFrm.h"
#include "SdbmsDemoDoc.h"
#include "SdbmsDemoView.h"
#include "sdbms_sql.h"
#include "editcmd.h"
extern char *g_strSQL;
extern CSdbms g_sdbms;
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSdbmsDemoView
IMPLEMENT_DYNCREATE(CSdbmsDemoView, CCrystalEditView)
BEGIN_MESSAGE_MAP(CSdbmsDemoView, CCrystalEditView)
//{{AFX_MSG_MAP(CSdbmsDemoView)
ON_WM_CONTEXTMENU()
ON_COMMAND(ID_DEBUG_EXECUTE, OnDebugExecute)
ON_UPDATE_COMMAND_UI(ID_DEBUG_EXECUTE, OnUpdateDebugExecute)
ON_COMMAND(ID_DEBUG_GO, OnDebugGo)
ON_UPDATE_COMMAND_UI(ID_DEBUG_GO, OnUpdateDebugGo)
ON_COMMAND(ID_DEBUG_BREAKPOINT, OnDebugBreakpoint)
ON_UPDATE_COMMAND_UI(ID_DEBUG_BREAKPOINT, OnUpdateDebugBreakpoint)
ON_COMMAND(ID_DEBUG_RESTART, OnDebugRestart)
ON_UPDATE_COMMAND_UI(ID_DEBUG_RESTART, OnUpdateDebugRestart)
ON_COMMAND(ID_DEBUG_STOP, OnDebugStop)
ON_UPDATE_COMMAND_UI(ID_DEBUG_STOP, OnUpdateDebugStop)
ON_COMMAND(ID_DEBUG_SHOW_STATEMENT, OnDebugShowStatement)
ON_UPDATE_COMMAND_UI(ID_DEBUG_SHOW_STATEMENT, OnUpdateDebugShowStatement)
ON_COMMAND(ID_DEBUG_STEP_OVER, OnDebugStepOver)
ON_UPDATE_COMMAND_UI(ID_DEBUG_STEP_OVER, OnUpdateDebugStepOver)
ON_COMMAND(ID_DEBUG_RUN_TO_CURSOR, OnDebugRunToCursor)
ON_UPDATE_COMMAND_UI(ID_DEBUG_RUN_TO_CURSOR, OnUpdateDebugRunToCursor)
ON_WM_CHAR()
//}}AFX_MSG_MAP
ON_COMMAND(ID_EDIT_DELETE, OnEditDelete)
ON_COMMAND(ID_EDIT_DELETE_BACK, OnEditDeleteBack)
ON_UPDATE_COMMAND_UI(ID_INDICATOR_POSITION, OnUpdateIndicatorPosition)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSdbmsDemoView construction/destruction
CSdbmsDemoView::CSdbmsDemoView()
{
// TODO: add construction code here
m_bExecuting = FALSE;
m_bBeginDebug = FALSE;
m_nCurLine = 0;
}
CSdbmsDemoView::~CSdbmsDemoView()
{
}
/////////////////////////////////////////////////////////////////////////////
// CSdbmsDemoView diagnostics
#ifdef _DEBUG
void CSdbmsDemoView::AssertValid() const
{
CCrystalEditView::AssertValid();
}
void CSdbmsDemoView::Dump(CDumpContext& dc) const
{
CCrystalEditView::Dump(dc);
}
CSdbmsDemoDoc* CSdbmsDemoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSdbmsDemoDoc)));
return (CSdbmsDemoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSdbmsDemoView message handlers
void CSdbmsDemoView::OnInitialUpdate()
{
CCrystalEditView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
}
CCrystalTextBuffer *CSdbmsDemoView::LocateTextBuffer()
{
return &GetDocument()->m_xTextBuffer;
}
COLORREF CSdbmsDemoView::GetColor(int nColorIndex)
{
switch (nColorIndex)
{
case COLORINDEX_WHITESPACE:
case COLORINDEX_BKGND:
return ::GetSysColor(COLOR_WINDOW);
case COLORINDEX_NORMALTEXT:
return ::GetSysColor(COLOR_WINDOWTEXT);
case COLORINDEX_SELMARGIN:
return ::GetSysColor(COLOR_SCROLLBAR);
case COLORINDEX_PREPROCESSOR:
return RGB(0, 128, 192);
case COLORINDEX_COMMENT:
return RGB(0, 128, 0); //Modified by ChangMing
//return RGB(128, 128, 128);
// [JRT]: Enabled Support For Numbers...
case COLORINDEX_NUMBER:
return RGB(0x80, 0x00, 0x00);
// [JRT]: Support For C/C++ Operators
case COLORINDEX_OPERATOR:
return RGB(0x00, 0x00, 0x00);
case COLORINDEX_KEYWORD:
return RGB(0, 0, 255);
case COLORINDEX_SELBKGND:
return RGB(0, 0, 0);
case COLORINDEX_SELTEXT:
return RGB(255, 255, 255);
// Added by ChangMing
}
return RGB(255, 0, 0);
}
void CSdbmsDemoView::OnContextMenu(CWnd* pWnd, CPoint point)
{
// TODO: Add your message handler code here
if (pWnd->m_hWnd == this->m_hWnd)
{
CMenu popupMenu;
popupMenu.LoadMenu(IDR_POPUP_EDIT);
CMenu *pSubMenu = popupMenu.GetSubMenu(0);
pSubMenu->TrackPopupMenu(0, point.x, point.y, this);
}
}
void CSdbmsDemoView::OnDebugExecute()
{
// TODO: Add your command handler code here
Init();
CString strText;
CPoint ptStart(0,0), ptEnd;
int nLineCount = GetLineCount();
ptEnd.y = nLineCount-1;
ptEnd.x = GetLineLength(ptEnd.y);
if (ptEnd.x == 0 && ptEnd.y == 0)
return;
GetText(ptStart, ptEnd, strText);
g_strSQL = (LPSTR)(LPCTSTR)strText;
yyparse();
}
void CSdbmsDemoView::OnUpdateDebugExecute(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(!m_bExecuting);
}
void CSdbmsDemoView::OnDebugGo()
{
// TODO: Add your command handler code here
if (!m_bBeginDebug)
{
m_bExecuting = TRUE;
m_bBeginDebug = TRUE;
m_nCurLine = 0;
AdjustBreakpoints();
Init();
if (m_pTextBuffer->GetLineFlags(0) & LF_BREAKPOINT) //第一行是否设置了断点
{
m_pTextBuffer->SetLineFlag(0, LF_EXECUTION, TRUE);
SetCursorPos(CPoint(0, m_nCurLine));
EnsureVisible(CPoint(0, m_nCurLine));
return;
}
}
RunToLine(GetLineCount());
}
void CSdbmsDemoView::OnUpdateDebugGo(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
}
void CSdbmsDemoView::OnDebugBreakpoint()
{
// TODO: Add your command handler code here
CPoint ptCurPos = GetCursorPos();
bool bSet = TRUE;
if (m_pTextBuffer->GetLineFlags(ptCurPos.y) & LF_BREAKPOINT)
bSet = FALSE;
else if (m_pTextBuffer->GetLineFlags(ptCurPos.y) & LF_INVALID_BREAKPOINT)
{
m_pTextBuffer->SetLineFlag(ptCurPos.y, LF_INVALID_BREAKPOINT, FALSE);
bSet = TRUE;
}
m_pTextBuffer->SetLineFlag(ptCurPos.y, LF_BREAKPOINT, bSet, FALSE);
}
void CSdbmsDemoView::OnUpdateDebugBreakpoint(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
}
void CSdbmsDemoView::OnDebugRestart()
{
// TODO: Add your command handler code here
m_bExecuting = TRUE;
m_bBeginDebug = TRUE;
m_nCurLine = 0;
AdjustBreakpoints();
Init();
m_pTextBuffer->SetLineFlag(0, LF_EXECUTION, TRUE);
SetCursorPos(CPoint(0, m_nCurLine));
EnsureVisible(CPoint(0, m_nCurLine));
}
void CSdbmsDemoView::OnUpdateDebugRestart(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
}
void CSdbmsDemoView::OnDebugStop()
{
// TODO: Add your command handler code here
m_bExecuting = FALSE;
m_bBeginDebug = FALSE;
m_pTextBuffer->SetLineFlag(-1, LF_EXECUTION, FALSE);//清除运行标志
m_nCurLine = 0;
}
void CSdbmsDemoView::OnUpdateDebugStop(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bExecuting);
}
void CSdbmsDemoView::OnDebugShowStatement()
{
// TODO: Add your command handler code here
ASSERT(m_nCurLine < GetLineCount());
SetCursorPos(CPoint(0, m_nCurLine));
ScrollToLine(m_nCurLine);
}
void CSdbmsDemoView::OnUpdateDebugShowStatement(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable(m_bExecuting);
}
void CSdbmsDemoView::OnDebugStepOver()
{
// TODO: Add your command handler code here
if (!m_bBeginDebug)
{
m_bExecuting = TRUE;
m_bBeginDebug = TRUE;
m_nCurLine = 0;
AdjustBreakpoints();
Init();
Trim(); //去掉空行及注释行
if (m_nCurLine == GetLineCount())
{
m_bExecuting = FALSE;
m_bBeginDebug = FALSE;
m_nCurLine = 0;
}
else
{
m_pTextBuffer->SetLineFlag(m_nCurLine, LF_EXECUTION, TRUE);
SetCursorPos(CPoint(0, m_nCurLine));
EnsureVisible(CPoint(0, m_nCurLine));
}
return;
}
CString strText;
while (m_nCurLine < GetLineCount() && strText.IsEmpty())
strText = GetCurValidLine();
Trim(); //去掉空行及注释行
g_strSQL = (LPSTR)(LPCTSTR)strText;
yyparse();
if (m_nCurLine >= GetLineCount())
{
m_bExecuting = FALSE;
m_bBeginDebug = FALSE;
m_pTextBuffer->SetLineFlag(-1, LF_EXECUTION, FALSE);//清除运行标志
m_nCurLine = 0;
}
else
{
m_pTextBuffer->SetLineFlag(m_nCurLine, LF_EXECUTION, TRUE);
SetCursorPos(CPoint(0, m_nCurLine));
EnsureVisible(CPoint(0, m_nCurLine));
}
}
void CSdbmsDemoView::OnUpdateDebugStepOver(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->Enable();
}
void CSdbmsDemoView::OnDebugRunToCursor()
{
// TODO: Add your command handler code here
if (!m_bBeginDebug)
{
m_bExecuting = TRUE;
m_bBeginDebug = TRUE;
m_nCurLine = 0;
AdjustBreakpoints();
Init();
if (m_pTextBuffer->GetLineFlags(0) & LF_BREAKPOINT) //第一行是否设置了断点
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -