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

对话框与窗口

开发平台:

Visual C++

  1. // CustomThemesView.cpp : implementation of the CCustomThemesView 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 "CustomThemes.h"
  22. #include "CustomThemesDoc.h"
  23. #include "CustomThemesView.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CCustomThemesView
  31. IMPLEMENT_DYNCREATE(CCustomThemesView, CRichEditView)
  32. BEGIN_MESSAGE_MAP(CCustomThemesView, CRichEditView)
  33. //{{AFX_MSG_MAP(CCustomThemesView)
  34. // NOTE - the ClassWizard will add and remove mapping macros here.
  35. //    DO NOT EDIT what you see in these blocks of generated code!
  36. ON_WM_CONTEXTMENU()
  37. ON_WM_RBUTTONDOWN()
  38. //}}AFX_MSG_MAP
  39. ON_COMMAND(ID_TOOLS_HEX, OnToolsHex)
  40. ON_UPDATE_COMMAND_UI(ID_TOOLS_HEX, OnUpdateToolsHex)
  41. ON_UPDATE_COMMAND_UI(ID_SELECTOR_TEXT, OnUpdateSelectorText)
  42. ON_XTP_EXECUTE(ID_SELECTOR_TEXT, OnSelectorText)
  43. ON_UPDATE_COMMAND_UI(ID_BUTTON_TEXT, OnUpdateText)
  44. ON_COMMAND(ID_BUTTON_TEXT, OnButtonText)
  45. ON_UPDATE_COMMAND_UI(ID_SELECTOR_BACK, OnUpdateSelectorBack)
  46. ON_XTP_EXECUTE(ID_SELECTOR_BACK, OnSelectorBack)
  47. ON_UPDATE_COMMAND_UI(ID_BUTTON_BACK, OnUpdateBack)
  48. ON_COMMAND(ID_BUTTON_BACK, OnButtonBack)
  49. ON_UPDATE_COMMAND_UI(ID_TEXT_AUTO, OnUpdateTextAuto)
  50. ON_COMMAND(ID_TEXT_AUTO, OnTextAuto)
  51. ON_UPDATE_COMMAND_UI(ID_BACK_NONE, OnUpdateBackNone)
  52. ON_COMMAND(ID_BACK_NONE, OnBackNone)
  53. ON_COMMAND(ID_TEXT_MORE, OnTextMore)
  54. ON_COMMAND(ID_BACK_MORE, OnBackMore)
  55. ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind)
  56. // Standard printing commands
  57. ON_COMMAND(ID_FILE_PRINT, CRichEditView::OnFilePrint)
  58. ON_COMMAND(ID_FILE_PRINT_EX, CRichEditView::OnFilePrint)
  59. ON_COMMAND(ID_FILE_PRINT_DIRECT, CRichEditView::OnFilePrint)
  60. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  61. ON_NOTIFY(XTP_FN_SETFORMAT, ID_COMBO_OWNERDRAW, OnSetCharFormat)
  62. ON_UPDATE_COMMAND_UI(ID_COMBO_OWNERDRAW, OnUpdateComboFont)
  63. ON_NOTIFY(XTP_FN_SETFORMAT, ID_COMBO_OWNERDRAW, OnSetCharFormat)
  64. ON_NOTIFY(XTP_FN_SETFORMAT, ID_COMBO_OWNERDRAW, OnSetCharFormat)
  65. ON_XTP_EXECUTE(ID_EDIT_FIND, OnEditFind)
  66. ON_NOTIFY(CBN_DROPDOWN, ID_EDIT_FIND, OnDropdownFindCombo)
  67. ON_NOTIFY(CBN_CLOSEUP, ID_EDIT_FIND, OnCloseupFindCombo)
  68. ON_NOTIFY(CBN_SELCHANGE, ID_EDIT_FIND, OnSelchangeFindCombo)
  69. ON_NOTIFY(CBN_SELENDOK, ID_EDIT_FIND, OnSelendokFindCombo)
  70. ON_NOTIFY(CBN_SETFOCUS, ID_EDIT_FIND, OnSetfocusFindCombo)
  71. ON_NOTIFY(CBN_SELENDCANCEL, ID_EDIT_FIND, OnSelendcancelFindCombo)
  72. ON_NOTIFY(CBN_KILLFOCUS, ID_EDIT_FIND, OnKillfocusFindCombo)
  73. ON_NOTIFY(CBN_EDITCHANGE, ID_EDIT_FIND, OnEditchangeFindCombo)
  74. ON_UPDATE_COMMAND_UI(ID_PARA_INDENT, OnUpdateIndentLeft)
  75. ON_XTP_EXECUTE(ID_PARA_INDENT, OnIndentLeft)
  76. ON_NOTIFY(XTP_FN_SPINUP, ID_PARA_INDENT, OnIndentLeftSpin)
  77. ON_NOTIFY(XTP_FN_SPINDOWN, ID_PARA_INDENT, OnIndentLeftSpin)
  78. END_MESSAGE_MAP()
  79. /////////////////////////////////////////////////////////////////////////////
  80. // CCustomThemesView construction/destruction
  81. CCustomThemesView::CCustomThemesView()
  82. {
  83. m_bCheck = TRUE;
  84. m_clr = RGB(255, 0, 0);
  85. m_clrBack = RGB(255, 255, 100);
  86. }
  87. CCustomThemesView::~CCustomThemesView()
  88. {
  89. }
  90. BOOL CCustomThemesView::PreCreateWindow(CREATESTRUCT& cs)
  91. {
  92. // TODO: Modify the Window class or styles here by modifying
  93. //  the CREATESTRUCT cs
  94. return CRichEditView::PreCreateWindow(cs);
  95. }
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CCustomThemesView drawing
  98. void CCustomThemesView::OnDraw(CDC* /*pDC*/)
  99. {
  100. CCustomThemesDoc* pDoc = GetDocument();
  101. ASSERT_VALID(pDoc);
  102. // TODO: add draw code for native data here
  103. }
  104. /////////////////////////////////////////////////////////////////////////////
  105. // CCustomThemesView printing
  106. BOOL CCustomThemesView::OnPreparePrinting(CPrintInfo* pInfo)
  107. {
  108. // default preparation
  109. return DoPreparePrinting(pInfo);
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CCustomThemesView diagnostics
  113. #ifdef _DEBUG
  114. void CCustomThemesView::AssertValid() const
  115. {
  116. CRichEditView::AssertValid();
  117. }
  118. void CCustomThemesView::Dump(CDumpContext& dc) const
  119. {
  120. CRichEditView::Dump(dc);
  121. }
  122. CCustomThemesDoc* CCustomThemesView::GetDocument() // non-debug version is inline
  123. {
  124. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCustomThemesDoc)));
  125. return (CCustomThemesDoc*)m_pDocument;
  126. }
  127. #endif //_DEBUG
  128. /////////////////////////////////////////////////////////////////////////////
  129. // CCustomThemesView message handlers
  130. void CCustomThemesView::OnToolsHex()
  131. {
  132. m_bCheck = !m_bCheck;
  133. }
  134. void CCustomThemesView::OnUpdateToolsHex(CCmdUI *pCmdUI)
  135. {
  136. pCmdUI->SetCheck(m_bCheck);
  137. }
  138. void CCustomThemesView::ShowContextMenu(CPoint point)
  139. {
  140. ClientToScreen(&point);
  141. ((CXTPMDIFrameWnd*)AfxGetMainWnd())->GetCommandBars()->
  142. TrackPopupMenu(IDR_CONTEXT_MENU, TPM_RIGHTBUTTON, point.x, point.y);
  143. }
  144. void CCustomThemesView::OnRButtonDown(UINT /*nFlags*/, CPoint point)
  145. {
  146. ShowContextMenu(point);
  147. }
  148. void CCustomThemesView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
  149. {
  150. ShowContextMenu(point);
  151. }
  152. void CCustomThemesView::OnUpdateSelectorText(CCmdUI* pCmdUI)
  153. {
  154. CXTPControlColorSelector* pSelector = DYNAMIC_DOWNCAST(CXTPControlColorSelector, CXTPControl::FromUI(pCmdUI));
  155. if (pSelector)
  156. {
  157. CHARFORMAT& cfm = GetCharFormatSelection( );
  158. pSelector->SetColor(cfm.dwEffects & CFE_AUTOCOLOR? -1: cfm.crTextColor);
  159. }
  160. pCmdUI->Enable(TRUE);
  161. }
  162. void CCustomThemesView::OnButtonText()
  163. {
  164. CHARFORMAT& cfm = GetCharFormatSelection( );
  165. cfm.dwMask |= CFM_COLOR;
  166. cfm.dwEffects &= ~CFE_AUTOCOLOR ;
  167. cfm.crTextColor = m_clr;
  168. GetRichEditCtrl().SetSelectionCharFormat(cfm);
  169. }
  170. void CCustomThemesView::OnSelectorText(NMHDR* pNMHDR, LRESULT* pResult)
  171. {
  172. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  173. CXTPControlColorSelector* pControl = (CXTPControlColorSelector*)tagNMCONTROL->pControl;
  174. m_clr = pControl->GetColor();
  175. OnButtonText();
  176. *pResult = 1;
  177. }
  178. void CCustomThemesView::OnUpdateText(CCmdUI* pCmdUI)
  179. {
  180. CXTPControlPopupColor* pPopup = DYNAMIC_DOWNCAST(CXTPControlPopupColor, CXTPControl::FromUI(pCmdUI));
  181. if (pPopup)
  182. {
  183. pPopup->SetColor(m_clr);
  184. }
  185. pCmdUI->Enable(TRUE);
  186. }
  187. ///////////////////
  188. void CCustomThemesView::OnUpdateSelectorBack(CCmdUI* pCmdUI)
  189. {
  190. CXTPControlColorSelector* pSelector = DYNAMIC_DOWNCAST(CXTPControlColorSelector, CXTPControl::FromUI(pCmdUI));
  191. if (pSelector)
  192. {
  193. CHARFORMAT2 cfm;
  194. cfm.cbSize =  sizeof(CHARFORMAT2);
  195. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  196. pSelector->SetColor(cfm.dwEffects & CFE_AUTOBACKCOLOR? -1: cfm.crBackColor);
  197. }
  198. pCmdUI->Enable(TRUE);
  199. }
  200. void CCustomThemesView::OnButtonBack()
  201. {
  202. CHARFORMAT2 cfm;
  203. cfm.cbSize =  sizeof(CHARFORMAT2);
  204. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  205. cfm.dwMask |= CFM_BACKCOLOR;
  206. cfm.dwEffects &= ~CFE_AUTOBACKCOLOR ;
  207. cfm.crBackColor = m_clrBack;
  208. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);
  209. }
  210. void CCustomThemesView::OnSelectorBack(NMHDR* pNMHDR, LRESULT* pResult)
  211. {
  212. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  213. CXTPControlColorSelector* pControl = (CXTPControlColorSelector*)tagNMCONTROL->pControl;
  214. m_clrBack = pControl->GetColor();
  215. OnButtonBack();
  216. *pResult = 1;
  217. }
  218. void CCustomThemesView::OnUpdateBack(CCmdUI* pCmdUI)
  219. {
  220. CXTPControlPopupColor* pPopup = DYNAMIC_DOWNCAST(CXTPControlPopupColor, CXTPControl::FromUI(pCmdUI));
  221. if (pPopup)
  222. {
  223. pPopup->SetColor(m_clrBack);
  224. }
  225. pCmdUI->Enable(TRUE);
  226. }
  227. void CCustomThemesView::OnTextAuto()
  228. {
  229. CHARFORMAT& cfm = GetCharFormatSelection( );
  230. cfm.dwMask |= CFM_COLOR;
  231. cfm.dwEffects |= CFE_AUTOCOLOR ;
  232. GetRichEditCtrl().SetSelectionCharFormat(cfm);
  233. }
  234. void CCustomThemesView::OnUpdateTextAuto(CCmdUI* pCmd)
  235. {
  236. CHARFORMAT& cfm = GetCharFormatSelection( );
  237. pCmd->SetCheck(cfm.dwEffects & CFE_AUTOCOLOR? TRUE: FALSE);
  238. }
  239. void CCustomThemesView::OnBackNone()
  240. {
  241. CHARFORMAT2 cfm;
  242. cfm.cbSize =  sizeof(CHARFORMAT2);
  243. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  244. cfm.dwMask |= CFM_BACKCOLOR;
  245. cfm.dwEffects |= CFE_AUTOBACKCOLOR ;
  246. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cfm);
  247. }
  248. void CCustomThemesView::OnUpdateBackNone(CCmdUI* pCmd)
  249. {
  250. CHARFORMAT2 cfm;
  251. cfm.cbSize =  sizeof(CHARFORMAT2);
  252. ::SendMessage(GetRichEditCtrl().GetSafeHwnd(), EM_GETCHARFORMAT, 1, (LPARAM)&cfm);
  253. pCmd->SetCheck(cfm.dwEffects & CFE_AUTOBACKCOLOR? TRUE: FALSE);
  254. }
  255. void CCustomThemesView::OnTextMore()
  256. {
  257. CColorDialog cd(m_clr);
  258. if (cd.DoModal())
  259. {
  260. m_clr = cd.GetColor();
  261. OnButtonText();
  262. }
  263. }
  264. void CCustomThemesView::OnBackMore()
  265. {
  266. CColorDialog cd(m_clrBack);
  267. if (cd.DoModal())
  268. {
  269. m_clrBack = cd.GetColor();
  270. OnButtonBack();
  271. }
  272. }
  273. void SendTrace(CString str)
  274. {
  275. TRACE(_T("Find combo notification: ") + str + "n");
  276. }
  277. void CCustomThemesView::OnEditFind(NMHDR* pNMHDR, LRESULT* pResult)
  278. {
  279. SendTrace(_T("CBN_XTP_EXECUTE"));
  280. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  281. CXTPControlComboBox* pControl = (CXTPControlComboBox*)tagNMCONTROL->pControl;
  282. if (pControl->GetType() == xtpControlComboBox)
  283. {
  284. CString strFind = pControl->GetEditText();
  285. if (!strFind.IsEmpty() && (pControl->GetEditHint() != strFind) && !FindText(strFind, TRUE,FALSE))
  286. {
  287. AfxMessageBox(_T("String not Found"));
  288. }
  289. *pResult = 1; // Handled;
  290. }
  291. }
  292. void CCustomThemesView::OnUpdateEditFind(CCmdUI* pCmd)
  293. {
  294. pCmd->Enable(TRUE);
  295. }
  296. void CCustomThemesView::OnSetCharFormat(NMHDR* pNMHDR, LRESULT* pRes)
  297. {
  298. ASSERT(pNMHDR != NULL);
  299. ASSERT(pRes != NULL);
  300. #if (_MSC_VER < 1300)
  301. CHARFORMAT& cf = ((NMXTPCHARHDR*)pNMHDR)->cf;
  302. #else
  303. CHARFORMAT2 cf;
  304. MEMCPY_S(&cf, &((NMXTPCHARHDR*)pNMHDR)->cf, sizeof(((NMXTPCHARHDR*)pNMHDR)->cf));
  305. #endif
  306. SetCharFormat(cf);
  307. *pRes = 1;
  308. }
  309. void CCustomThemesView::OnUpdateComboFont(CCmdUI* pCmd)
  310. {
  311. CXTPControlFontComboBox* pFontCombo = (CXTPControlFontComboBox*)CXTPControl::FromUI(pCmd);
  312. if (pFontCombo && pFontCombo->GetType() == xtpControlComboBox)
  313. {
  314. pFontCombo->SetCharFormat((CHARFORMAT&)GetCharFormatSelection());
  315. }
  316. pCmd->Enable(TRUE);
  317. }
  318. void CCustomThemesView::OnDropdownFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  319. {
  320. SendTrace(_T("CBN_DROPDOWN"));
  321. }
  322. void CCustomThemesView::OnCloseupFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  323. {
  324. SendTrace(_T("CBN_CLOSEUP"));
  325. }
  326. void CCustomThemesView::OnSelchangeFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  327. {
  328. SendTrace(_T("CBN_SELCHANGE"));
  329. }
  330. void CCustomThemesView::OnSelendokFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  331. {
  332. SendTrace(_T("CBN_SELENDOK"));
  333. }
  334. void CCustomThemesView::OnSetfocusFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  335. {
  336. SendTrace(_T("CBN_SETFOCUS"));
  337. }
  338. void CCustomThemesView::OnSelendcancelFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  339. {
  340. SendTrace(_T("CBN_SELENDCANCEL"));
  341. }
  342. void CCustomThemesView::OnKillfocusFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  343. {
  344. SendTrace(_T("CBN_KILLFOCUS"));
  345. }
  346. void CCustomThemesView::OnEditchangeFindCombo(NMHDR* /*pNMHDR*/, LRESULT* /*pRes*/) 
  347. {
  348. SendTrace(_T("CBN_EDITCHANGE"));
  349. }
  350. //////////////////////////////////////////////////////////////////////////
  351. CString FormatIndent(int nIndent)
  352. {
  353. CString strIndent;
  354. if (nIndent % 1000 == 0)
  355. strIndent.Format(_T("%0.0f""), (double)nIndent / 1000);
  356. else if (nIndent % 100 == 0)
  357. strIndent.Format(_T("%0.1f""), (double)nIndent / 1000);
  358. else
  359. strIndent.Format(_T("%0.2f""), (double)nIndent / 1000);
  360. return strIndent;
  361. }
  362. void CCustomThemesView::SetIndentLeft(long nIndentLeft)
  363. {
  364. if (nIndentLeft < -11000)
  365. nIndentLeft = -11000;
  366. if (nIndentLeft > 22000)
  367. nIndentLeft = 22000;
  368. PARAFORMAT pf;
  369. pf.cbSize = sizeof(PARAFORMAT);
  370. pf.dwMask =  PFM_STARTINDENT;
  371. pf.dxStartIndent = nIndentLeft;
  372. ::SendMessage(m_hWnd, EM_SETPARAFORMAT, 0, (LPARAM)&pf);
  373. }
  374. long CCustomThemesView::GetIndentLeft()
  375. {
  376. PARAFORMAT pf;
  377. pf.cbSize = sizeof(PARAFORMAT);
  378. pf.dwMask =  PFM_STARTINDENT;
  379. ::SendMessage(m_hWnd, EM_GETPARAFORMAT, 0, (LPARAM)&pf);
  380. return pf.dxStartIndent;
  381. }
  382. void CCustomThemesView::OnUpdateIndentLeft(CCmdUI* pCmdUI)
  383. {
  384. CXTPControlEdit* pControl = DYNAMIC_DOWNCAST(CXTPControlEdit, CXTPControl::FromUI(pCmdUI));
  385. if (pControl && !pControl->HasFocus())
  386. {
  387. pControl->SetEditText(FormatIndent(GetIndentLeft()));
  388. }
  389. pCmdUI->Enable(TRUE);
  390. }
  391. double _ttof(LPCTSTR lpszStr)
  392. {
  393. USES_CONVERSION;
  394. return atof(T2A((LPTSTR)lpszStr));
  395. }
  396. void CCustomThemesView::OnIndentLeft(NMHDR* pNMHDR, LRESULT* pResult)
  397. {
  398. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  399. CXTPControlEdit* pControl = DYNAMIC_DOWNCAST(CXTPControlEdit, tagNMCONTROL->pControl);
  400. if (pControl)
  401. {
  402. SetIndentLeft(int(_ttof(pControl->GetEditText()) * 1000));
  403. }
  404. *pResult = 1;
  405. }
  406. void CCustomThemesView::OnIndentLeftSpin(NMHDR* pNMHDR, LRESULT* pResult)
  407. {
  408. NMXTPUPDOWN* tagNMCONTROL = (NMXTPUPDOWN*)pNMHDR;
  409. CXTPControlEdit* pControl = DYNAMIC_DOWNCAST(CXTPControlEdit, tagNMCONTROL->pControl);
  410. if (pControl)
  411. {
  412. SetIndentLeft(int(_ttof(pControl->GetEditText()) * 1000) + tagNMCONTROL->iDelta * 100);
  413. pControl->SetEditText(FormatIndent(GetIndentLeft()));
  414. }
  415. *pResult = 1;
  416. }