SQLView.cpp
资源名称:ISQL_src.zip [点击查看]
上传用户:jsxglz
上传日期:2007-01-03
资源大小:117k
文件大小:5k
源码类别:
SQL Server
开发平台:
Visual C++
- // SQLView.cpp : implementation of the CSQLView class
- //
- #include "stdafx.h"
- #include "InteractiveSQL.h"
- #include "InteractiveSQLDoc.h"
- #include "CntrItem.h"
- #include "SQLView.h"
- #include "MainFrm.h"
- #include "resource.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSQLView
- IMPLEMENT_DYNCREATE(CSQLView, CRichEditView)
- BEGIN_MESSAGE_MAP(CSQLView, CRichEditView)
- //{{AFX_MSG_MAP(CSQLView)
- ON_WM_DESTROY()
- ON_COMMAND(ID_SQL_EXECUTE, OnSqlExecute)
- ON_UPDATE_COMMAND_UI(ID_VIEW_WRAP_WORD, OnUpdateViewWrapWord)
- ON_COMMAND(ID_VIEW_WRAP_WORD, OnViewWrapWord)
- ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
- ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
- ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSQLView construction/destruction
- CSQLView::CSQLView()
- {
- m_nWordWrap = WrapToWindow;
- LOGFONT logFont;
- memset(&logFont, 0, sizeof(logFont));
- logFont.lfHeight = -15;
- logFont.lfWeight = 400;
- strcpy(logFont.lfFaceName, "Courier");
- if(!m_font.CreateFontIndirect(&logFont))
- TRACE("Could Not create font.n");
- }
- CSQLView::~CSQLView()
- {
- if(m_font.m_hObject)
- {
- m_font.Detach();
- m_font.m_hObject = NULL;
- }
- }
- BOOL CSQLView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CRichEditView::PreCreateWindow(cs);
- }
- void CSQLView::OnInitialUpdate()
- {
- CRichEditView::OnInitialUpdate();
- if(m_font.m_hObject)
- GetRichEditCtrl().SetFont(&m_font);
- SetMargins(CRect(720, 720, 720, 720));
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSQLView printing
- BOOL CSQLView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- return DoPreparePrinting(pInfo);
- }
- void CSQLView::OnDestroy()
- {
- // Deactivate the item on destruction; this is important
- // when a splitter view is being used.
- CRichEditView::OnDestroy();
- COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
- if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
- {
- pActiveItem->Deactivate();
- ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSQLView diagnostics
- #ifdef _DEBUG
- void CSQLView::AssertValid() const
- {
- CRichEditView::AssertValid();
- }
- void CSQLView::Dump(CDumpContext& dc) const
- {
- CRichEditView::Dump(dc);
- }
- CInteractiveSQLDoc* CSQLView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CInteractiveSQLDoc)));
- return (CInteractiveSQLDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CSQLView message handlers
- void CSQLView::OnSqlExecute()
- {
- ((CMainFrame*)AfxGetMainWnd())->OnSqlExecute();
- }
- void CSQLView::OnUpdateViewWrapWord(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_nWordWrap == WrapToWindow);
- }
- void CSQLView::OnViewWrapWord()
- {
- m_nWordWrap = (m_nWordWrap == WrapNone) ? WrapToWindow : WrapNone;
- WrapChanged();
- }
- void CSQLView::OnFilePrint()
- {
- CWaitCursor wait;
- CRichEditView::OnFilePrint();
- }
- void CSQLView::OnUpdateFilePrint(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetRichEditCtrl().GetTextLength());
- }
- void CSQLView::OnEditClear()
- {
- GetRichEditCtrl().SetWindowText(NULL);
- }
- void CSQLView::OnUpdateEditClear(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetRichEditCtrl().GetTextLength());
- }
- HMENU CSQLView::GetContextMenu(WORD /*wSelType*/, LPOLEOBJECT /*lpOleObj*/,
- CHARRANGE* /*lpChrg*/)
- {
- CMenu menu;
- if(menu.LoadMenu(IDR_RCLICK))
- {
- CMenu* pMenu = menu.GetSubMenu(0);
- ASSERT(pMenu);
- CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
- ASSERT(pFrame);
- int nLength = GetRichEditCtrl().GetTextLength();
- if(!pFrame->m_database.IsOpen() || !nLength || pFrame->m_bExecuting)
- pMenu->EnableMenuItem(ID_SQL_EXECUTE, MF_BYCOMMAND | MF_GRAYED);
- CString sBuff;
- sBuff = GetRichEditCtrl().GetSelText();
- if(sBuff.IsEmpty())
- {
- pMenu->EnableMenuItem(ID_EDIT_CUT, MF_BYCOMMAND | MF_GRAYED);
- pMenu->EnableMenuItem(ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
- }
- if(!GetRichEditCtrl().CanPaste())
- pMenu->EnableMenuItem(ID_EDIT_PASTE, MF_BYCOMMAND | MF_GRAYED);
- if(!GetRichEditCtrl().CanUndo())
- pMenu->EnableMenuItem(ID_EDIT_UNDO, MF_BYCOMMAND | MF_GRAYED);
- if(!nLength)
- {
- pMenu->EnableMenuItem(ID_EDIT_CLEAR, MF_BYCOMMAND | MF_GRAYED);
- pMenu->EnableMenuItem(ID_EDIT_SELECT_ALL, MF_BYCOMMAND | MF_GRAYED);
- }
- CPoint point;
- ::GetCursorPos(&point);
- pMenu->TrackPopupMenu(0, point.x, point.y, this);
- }
- return NULL;
- }