GUI_OneNoteView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:11k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // GUI_OneNoteView.cpp : implementation of the CGUI_OneNoteView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "GUI_OneNote.h"
  22. #include "GUI_OneNoteDoc.h"
  23. #include "CntrItem.h"
  24. #include "GUI_OneNoteView.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CGUI_OneNoteView
  32. IMPLEMENT_DYNCREATE(CGUI_OneNoteView, CRichEditView)
  33. BEGIN_MESSAGE_MAP(CGUI_OneNoteView, CRichEditView)
  34. //{{AFX_MSG_MAP(CGUI_OneNoteView)
  35. // NOTE - the ClassWizard will add and remove mapping macros here.
  36. //    DO NOT EDIT what you see in these blocks of generated code!
  37. ON_WM_DESTROY()
  38. //}}AFX_MSG_MAP
  39. // Standard printing commands
  40. ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  41. ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  42. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  43. ON_COMMAND_RANGE(ID_EDIT_SELECT_PAGE, ID_FORMAT_NOTEFLAGS_DEFENITION, OnEmptyCommand)
  44. ON_COMMAND(ID_VIEW_BOLD, CRichEditView::OnCharBold)
  45. ON_COMMAND(ID_VIEW_ITALIC, CRichEditView::OnCharItalic)
  46. ON_COMMAND(ID_VIEW_UNDERLINE, CRichEditView::OnCharUnderline)
  47. ON_UPDATE_COMMAND_UI(ID_VIEW_BOLD, CRichEditView::OnUpdateCharBold)
  48. ON_UPDATE_COMMAND_UI(ID_VIEW_ITALIC, CRichEditView::OnUpdateCharItalic)
  49. ON_UPDATE_COMMAND_UI(ID_VIEW_UNDERLINE, CRichEditView::OnUpdateCharUnderline)
  50. ON_NOTIFY(XTP_FN_GETFORMAT, ID_EDIT_SIZE, OnGetCharFormat)
  51. ON_NOTIFY(XTP_FN_SETFORMAT, ID_EDIT_SIZE, OnSetCharFormat)
  52. ON_UPDATE_COMMAND_UI(ID_EDIT_SIZE, OnUpdateComboSize)
  53. ON_NOTIFY(XTP_FN_SETFORMAT, ID_EDIT_FONT, OnSetCharFormat)
  54. ON_UPDATE_COMMAND_UI(ID_EDIT_FONT, OnUpdateComboFont)
  55. ON_UPDATE_COMMAND_UI(ID_TOOLS_PENACTSAS_SELECT, OnUpdateSetCheck)
  56. ON_UPDATE_COMMAND_UI(ID_FORMAT_FONTCOLOR_SELECTOR, OnUpdateSelectorText)
  57. ON_XTP_EXECUTE(ID_FORMAT_FONTCOLOR_SELECTOR, OnSelectorText)
  58. ON_UPDATE_COMMAND_UI(ID_FORMAT_FONTCOLOR, OnUpdateText)
  59. ON_COMMAND(ID_FORMAT_FONTCOLOR, OnButtonText)
  60. ON_UPDATE_COMMAND_UI(ID_FORMAT_HIGHLIGHT_SELECTOR, OnUpdateSelectorBack)
  61. ON_XTP_EXECUTE(ID_FORMAT_HIGHLIGHT_SELECTOR, OnSelectorBack)
  62. ON_UPDATE_COMMAND_UI(ID_FORMAT_HIGHLIGHT, OnUpdateBack)
  63. ON_COMMAND(ID_FORMAT_HIGHLIGHT, OnButtonBack)
  64. ON_UPDATE_COMMAND_UI(XTP_IDS_AUTOMATIC, OnUpdateTextAuto)
  65. ON_COMMAND(XTP_IDS_AUTOMATIC, OnTextAuto)
  66. ON_UPDATE_COMMAND_UI(ID_FORMAT_HIGHLIGHT_NONE, OnUpdateBackNone)
  67. ON_COMMAND(ID_FORMAT_HIGHLIGHT_NONE, OnBackNone)
  68. END_MESSAGE_MAP()
  69. /////////////////////////////////////////////////////////////////////////////
  70. // CGUI_OneNoteView construction/destruction
  71. CGUI_OneNoteView::CGUI_OneNoteView()
  72. {
  73. m_clr = RGB(255, 0, 0);
  74. m_clrBack = RGB(255, 255, 100);
  75. }
  76. CGUI_OneNoteView::~CGUI_OneNoteView()
  77. {
  78. }
  79. BOOL CGUI_OneNoteView::PreCreateWindow(CREATESTRUCT& cs)
  80. {
  81. // TODO: Modify the Window class or styles here by modifying
  82. //  the CREATESTRUCT cs
  83. return CRichEditView::PreCreateWindow(cs);
  84. }
  85. void CGUI_OneNoteView::OnInitialUpdate()
  86. {
  87. USES_CONVERSION;
  88. CRichEditView::OnInitialUpdate();
  89. // Set the printing margins (720 twips = 1/2 inch).
  90. SetMargins(CRect(720, 720, 720, 720));
  91. CHARFORMAT cf;
  92. ZeroMemory(&cf, sizeof(CHARFORMAT));
  93. CString strDefFont = _T("Tahoma");
  94. cf.cbSize = sizeof(CHARFORMAT);
  95. cf.dwMask = CFM_BOLD |CFM_ITALIC | CFM_UNDERLINE | CFM_STRIKEOUT | CFM_SIZE |
  96. CFM_COLOR | CFM_OFFSET | CFM_PROTECTED | CFM_FACE;
  97. cf.dwEffects = CFE_AUTOCOLOR;
  98. cf.yHeight = 200; //10pt
  99. cf.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  100. #if (_RICHEDIT_VER >= 0x0200)
  101. lstrcpyn(cf.szFaceName, strDefFont, LF_FACESIZE);
  102. #else
  103. lstrcpynA(cf.szFaceName, T2A((LPTSTR) (LPCTSTR) strDefFont), LF_FACESIZE);
  104. #endif
  105. GetRichEditCtrl().SetDefaultCharFormat(cf);
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CGUI_OneNoteView printing
  109. BOOL CGUI_OneNoteView::OnPreparePrinting(CPrintInfo* pInfo)
  110. {
  111. // default preparation
  112. return DoPreparePrinting(pInfo);
  113. }
  114. void CGUI_OneNoteView::OnDestroy()
  115. {
  116. // Deactivate the item on destruction; this is important
  117. // when a splitter view is being used.
  118. CRichEditView::OnDestroy();
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CGUI_OneNoteView diagnostics
  122. #ifdef _DEBUG
  123. void CGUI_OneNoteView::AssertValid() const
  124. {
  125. CRichEditView::AssertValid();
  126. }
  127. void CGUI_OneNoteView::Dump(CDumpContext& dc) const
  128. {
  129. CRichEditView::Dump(dc);
  130. }
  131. CGUI_OneNoteDoc* CGUI_OneNoteView::GetDocument() // non-debug version is inline
  132. {
  133. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGUI_OneNoteDoc)));
  134. return (CGUI_OneNoteDoc*)m_pDocument;
  135. }
  136. #endif //_DEBUG
  137. /////////////////////////////////////////////////////////////////////////////
  138. // CGUI_OneNoteView message handlers
  139. void CGUI_OneNoteView::OnEmptyCommand(UINT)
  140. {
  141. }
  142. void CGUI_OneNoteView::OnUpdateSetCheck(CCmdUI* pCmdUI)
  143. {
  144. pCmdUI->SetCheck();
  145. }
  146. void CGUI_OneNoteView::OnGetCharFormat(NMHDR* pNMHDR, LRESULT* pRes)
  147. {
  148. ASSERT(pNMHDR != NULL);
  149. ASSERT(pRes != NULL);
  150. ((NMXTPCHARHDR*)pNMHDR)->cf = GetCharFormatSelection();
  151. *pRes = 1;
  152. }
  153. void CGUI_OneNoteView::OnSetCharFormat(NMHDR* pNMHDR, LRESULT* pRes)
  154. {
  155. ASSERT(pNMHDR != NULL);
  156. ASSERT(pRes != NULL);
  157. #if (_MSC_VER < 1300)
  158. CHARFORMAT& cf = ((NMXTPCHARHDR*)pNMHDR)->cf;
  159. #else
  160. CHARFORMAT2 cf;
  161. MEMCPY_S(&cf, &((NMXTPCHARHDR*)pNMHDR)->cf, sizeof(((NMXTPCHARHDR*)pNMHDR)->cf));
  162. #endif
  163. SetCharFormat(cf);
  164. *pRes = 1;
  165. }
  166. void CGUI_OneNoteView::OnUpdateComboFont(CCmdUI* pCmd)
  167. {
  168. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  169. if (pToolBar)
  170. {
  171. CXTPControlFontComboBox* pFontCombo = (CXTPControlFontComboBox*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  172. if (pFontCombo->GetType() == xtpControlComboBox)
  173. {
  174. pFontCombo->SetCharFormat((CHARFORMAT&)GetCharFormatSelection());
  175. }
  176. }
  177. pCmd->Enable(TRUE);
  178. }
  179. void CGUI_OneNoteView::OnUpdateComboSize(CCmdUI* pCmd)
  180. {
  181. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  182. if (pToolBar)
  183. {
  184. CXTPControlSizeComboBox* pSizeCombo = (CXTPControlSizeComboBox*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  185. if (pSizeCombo->GetType() == xtpControlComboBox)
  186. {
  187. CHARFORMAT& cf = GetCharFormatSelection();
  188. pSizeCombo->SetTwipSize( (cf.dwMask & CFM_SIZE) ? cf.yHeight : -1);
  189. }
  190. }
  191. pCmd->Enable(TRUE);
  192. }
  193. //////////////////////////////////////////////////////////////////////////
  194. void CGUI_OneNoteView::OnUpdateSelectorText(CCmdUI* pCmd)
  195. {
  196. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  197. if (pToolBar)
  198. {
  199. CHARFORMAT& cfm = GetCharFormatSelection( );
  200. CXTPControlColorSelector* pSelector = (CXTPControlColorSelector*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  201. pSelector->SetColor(cfm.dwEffects & CFE_AUTOCOLOR? -1: cfm.crTextColor);
  202. }
  203. pCmd->Enable(TRUE);
  204. }
  205. void CGUI_OneNoteView::OnButtonText()
  206. {
  207. CHARFORMAT& cfm = GetCharFormatSelection( );
  208. cfm.dwMask |= CFM_COLOR;
  209. cfm.dwEffects &= ~CFE_AUTOCOLOR ;
  210. cfm.crTextColor = m_clr;
  211. GetRichEditCtrl().SetSelectionCharFormat(cfm);
  212. }
  213. void CGUI_OneNoteView::OnSelectorText(NMHDR* pNMHDR, LRESULT* pResult)
  214. {
  215. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  216. CXTPControlColorSelector* pControl = (CXTPControlColorSelector*)tagNMCONTROL->pControl;
  217. m_clr = pControl->GetColor();
  218. OnButtonText();
  219. *pResult = 1;
  220. }
  221. void CGUI_OneNoteView::OnUpdateText(CCmdUI* pCmd)
  222. {
  223. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  224. if (pToolBar)
  225. {
  226. CXTPControlPopupColor* pPopup = DYNAMIC_DOWNCAST(CXTPControlPopupColor, pToolBar->GetControls()->GetAt(pCmd->m_nIndex));
  227. if (pPopup) pPopup->SetColor(m_clr);
  228. }
  229. pCmd->Enable(TRUE);
  230. }
  231. ///////////////////
  232. void CGUI_OneNoteView::OnUpdateSelectorBack(CCmdUI* pCmd)
  233. {
  234. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  235. if (pToolBar)
  236. {
  237. CHARFORMAT2 cfm;
  238. cfm.cbSize =  sizeof(CHARFORMAT2);
  239. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  240. CXTPControlColorSelector* pSelector = (CXTPControlColorSelector*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  241. pSelector->SetColor(cfm.dwEffects & CFE_AUTOBACKCOLOR? -1: cfm.crBackColor);
  242. }
  243. pCmd->Enable(TRUE);
  244. }
  245. void CGUI_OneNoteView::OnButtonBack()
  246. {
  247. CHARFORMAT2 cfm;
  248. cfm.cbSize =  sizeof(CHARFORMAT2);
  249. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  250. cfm.dwMask |= CFM_BACKCOLOR;
  251. cfm.dwEffects &= ~CFE_AUTOBACKCOLOR ;
  252. cfm.crBackColor = m_clrBack;
  253. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);
  254. }
  255. void CGUI_OneNoteView::OnSelectorBack(NMHDR* pNMHDR, LRESULT* pResult)
  256. {
  257. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  258. CXTPControlColorSelector* pControl = (CXTPControlColorSelector*)tagNMCONTROL->pControl;
  259. m_clrBack = pControl->GetColor();
  260. OnButtonBack();
  261. *pResult = 1;
  262. }
  263. void CGUI_OneNoteView::OnUpdateBack(CCmdUI* pCmd)
  264. {
  265. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  266. if (pToolBar)
  267. {
  268. CXTPControlPopupColor* pPopup = DYNAMIC_DOWNCAST(CXTPControlPopupColor, pToolBar->GetControls()->GetAt(pCmd->m_nIndex));
  269. if (pPopup) pPopup->SetColor(m_clrBack);
  270. }
  271. pCmd->Enable(TRUE);
  272. }
  273. void CGUI_OneNoteView::OnTextAuto()
  274. {
  275. CHARFORMAT& cfm = GetCharFormatSelection( );
  276. cfm.dwMask |= CFM_COLOR;
  277. cfm.dwEffects |= CFE_AUTOCOLOR ;
  278. GetRichEditCtrl().SetSelectionCharFormat(cfm);
  279. }
  280. void CGUI_OneNoteView::OnUpdateTextAuto(CCmdUI* pCmd)
  281. {
  282. CHARFORMAT& cfm = GetCharFormatSelection( );
  283. pCmd->SetCheck(cfm.dwEffects & CFE_AUTOCOLOR? TRUE: FALSE);
  284. }
  285. void CGUI_OneNoteView::OnBackNone()
  286. {
  287. CHARFORMAT2 cfm;
  288. cfm.cbSize =  sizeof(CHARFORMAT2);
  289. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  290. cfm.dwMask |= CFM_BACKCOLOR;
  291. cfm.dwEffects |= CFE_AUTOBACKCOLOR ;
  292. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);
  293. }
  294. void CGUI_OneNoteView::OnUpdateBackNone(CCmdUI* pCmd)
  295. {
  296. CHARFORMAT2 cfm;
  297. cfm.cbSize =  sizeof(CHARFORMAT2);
  298. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  299. pCmd->SetCheck(cfm.dwEffects & CFE_AUTOBACKCOLOR? TRUE: FALSE);
  300. }