SQLView.cpp
上传用户:jsxglz
上传日期:2007-01-03
资源大小:117k
文件大小:5k
源码类别:

SQL Server

开发平台:

Visual C++

  1. // SQLView.cpp : implementation of the CSQLView class
  2. //
  3. #include "stdafx.h"
  4. #include "InteractiveSQL.h"
  5. #include "InteractiveSQLDoc.h"
  6. #include "CntrItem.h"
  7. #include "SQLView.h"
  8. #include "MainFrm.h"
  9. #include "resource.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CSQLView
  17. IMPLEMENT_DYNCREATE(CSQLView, CRichEditView)
  18. BEGIN_MESSAGE_MAP(CSQLView, CRichEditView)
  19. //{{AFX_MSG_MAP(CSQLView)
  20. ON_WM_DESTROY()
  21. ON_COMMAND(ID_SQL_EXECUTE, OnSqlExecute)
  22. ON_UPDATE_COMMAND_UI(ID_VIEW_WRAP_WORD, OnUpdateViewWrapWord)
  23. ON_COMMAND(ID_VIEW_WRAP_WORD, OnViewWrapWord)
  24. ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  25. ON_UPDATE_COMMAND_UI(ID_FILE_PRINT, OnUpdateFilePrint)
  26. ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
  27. ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditClear)
  28. //}}AFX_MSG_MAP
  29. // Standard printing commands
  30. ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  31. END_MESSAGE_MAP()
  32. /////////////////////////////////////////////////////////////////////////////
  33. // CSQLView construction/destruction
  34. CSQLView::CSQLView()
  35. {
  36. m_nWordWrap = WrapToWindow;
  37. LOGFONT logFont;
  38. memset(&logFont, 0, sizeof(logFont));
  39. logFont.lfHeight = -15;
  40. logFont.lfWeight = 400;
  41. strcpy(logFont.lfFaceName, "Courier");
  42. if(!m_font.CreateFontIndirect(&logFont))
  43. TRACE("Could Not create font.n");
  44. }
  45. CSQLView::~CSQLView()
  46. {
  47. if(m_font.m_hObject)
  48. {
  49. m_font.Detach();
  50. m_font.m_hObject = NULL;
  51. }
  52. }
  53. BOOL CSQLView::PreCreateWindow(CREATESTRUCT& cs)
  54. {
  55. // TODO: Modify the Window class or styles here by modifying
  56. //  the CREATESTRUCT cs
  57. return CRichEditView::PreCreateWindow(cs);
  58. }
  59. void CSQLView::OnInitialUpdate()
  60. {
  61. CRichEditView::OnInitialUpdate();
  62. if(m_font.m_hObject)
  63. GetRichEditCtrl().SetFont(&m_font);
  64. SetMargins(CRect(720, 720, 720, 720));
  65. }
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CSQLView printing
  68. BOOL CSQLView::OnPreparePrinting(CPrintInfo* pInfo)
  69. {
  70. return DoPreparePrinting(pInfo);
  71. }
  72. void CSQLView::OnDestroy()
  73. {
  74. // Deactivate the item on destruction; this is important
  75. // when a splitter view is being used.
  76.    CRichEditView::OnDestroy();
  77.    COleClientItem* pActiveItem = GetDocument()->GetInPlaceActiveItem(this);
  78.    if (pActiveItem != NULL && pActiveItem->GetActiveView() == this)
  79.    {
  80.       pActiveItem->Deactivate();
  81.       ASSERT(GetDocument()->GetInPlaceActiveItem(this) == NULL);
  82.    }
  83. }
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CSQLView diagnostics
  86. #ifdef _DEBUG
  87. void CSQLView::AssertValid() const
  88. {
  89. CRichEditView::AssertValid();
  90. }
  91. void CSQLView::Dump(CDumpContext& dc) const
  92. {
  93. CRichEditView::Dump(dc);
  94. }
  95. CInteractiveSQLDoc* CSQLView::GetDocument() // non-debug version is inline
  96. {
  97. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CInteractiveSQLDoc)));
  98. return (CInteractiveSQLDoc*)m_pDocument;
  99. }
  100. #endif //_DEBUG
  101. /////////////////////////////////////////////////////////////////////////////
  102. // CSQLView message handlers
  103. void CSQLView::OnSqlExecute() 
  104. {
  105. ((CMainFrame*)AfxGetMainWnd())->OnSqlExecute();
  106. }
  107. void CSQLView::OnUpdateViewWrapWord(CCmdUI* pCmdUI) 
  108. {
  109. pCmdUI->SetCheck(m_nWordWrap == WrapToWindow);
  110. }
  111. void CSQLView::OnViewWrapWord() 
  112. {
  113. m_nWordWrap = (m_nWordWrap == WrapNone) ? WrapToWindow : WrapNone;
  114. WrapChanged();
  115. }
  116. void CSQLView::OnFilePrint() 
  117. {
  118. CWaitCursor wait;
  119. CRichEditView::OnFilePrint();
  120. }
  121. void CSQLView::OnUpdateFilePrint(CCmdUI* pCmdUI) 
  122. {
  123. pCmdUI->Enable(GetRichEditCtrl().GetTextLength());
  124. }
  125. void CSQLView::OnEditClear() 
  126. {
  127. GetRichEditCtrl().SetWindowText(NULL);
  128. }
  129. void CSQLView::OnUpdateEditClear(CCmdUI* pCmdUI) 
  130. {
  131. pCmdUI->Enable(GetRichEditCtrl().GetTextLength());
  132. }
  133. HMENU CSQLView::GetContextMenu(WORD /*wSelType*/, LPOLEOBJECT /*lpOleObj*/,
  134.    CHARRANGE* /*lpChrg*/)
  135. {
  136. CMenu menu;
  137. if(menu.LoadMenu(IDR_RCLICK))
  138. {
  139. CMenu* pMenu = menu.GetSubMenu(0);
  140. ASSERT(pMenu);
  141. CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
  142. ASSERT(pFrame);
  143. int nLength = GetRichEditCtrl().GetTextLength();
  144. if(!pFrame->m_database.IsOpen() || !nLength || pFrame->m_bExecuting)
  145. pMenu->EnableMenuItem(ID_SQL_EXECUTE, MF_BYCOMMAND | MF_GRAYED);
  146. CString sBuff;
  147. sBuff = GetRichEditCtrl().GetSelText();
  148. if(sBuff.IsEmpty())
  149. {
  150. pMenu->EnableMenuItem(ID_EDIT_CUT, MF_BYCOMMAND | MF_GRAYED);
  151. pMenu->EnableMenuItem(ID_EDIT_COPY, MF_BYCOMMAND | MF_GRAYED);
  152. }
  153. if(!GetRichEditCtrl().CanPaste())
  154. pMenu->EnableMenuItem(ID_EDIT_PASTE, MF_BYCOMMAND | MF_GRAYED);
  155. if(!GetRichEditCtrl().CanUndo())
  156. pMenu->EnableMenuItem(ID_EDIT_UNDO, MF_BYCOMMAND | MF_GRAYED);
  157. if(!nLength)
  158. {
  159. pMenu->EnableMenuItem(ID_EDIT_CLEAR, MF_BYCOMMAND | MF_GRAYED);
  160. pMenu->EnableMenuItem(ID_EDIT_SELECT_ALL, MF_BYCOMMAND | MF_GRAYED);
  161. }
  162. CPoint point;
  163. ::GetCursorPos(&point);
  164. pMenu->TrackPopupMenu(0, point.x, point.y, this);
  165. }
  166. return NULL;
  167. }