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

对话框与窗口

开发平台:

Visual C++

  1. // XTPSkinObjectComboBox.cpp: implementation of the CXTPSkinObjectComboBox class.
  2. //
  3. // This file is a part of the XTREME SKINFRAMEWORK 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 "Common/XTPDrawHelpers.h"
  22. #include "XTPSkinObjectComboBox.h"
  23. #include "XTPSkinManager.h"
  24. #include "XTPSkinDrawTools.h"
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char THIS_FILE[]=__FILE__;
  28. #define new DEBUG_NEW
  29. #endif
  30. //////////////////////////////////////////////////////////////////////
  31. // Construction/Destruction
  32. //////////////////////////////////////////////////////////////////////
  33. IMPLEMENT_DYNCREATE(CXTPSkinObjectComboBox, CXTPSkinObjectFrame)
  34. CXTPSkinObjectComboBox::CXTPSkinObjectComboBox()
  35. {
  36. m_bHot = FALSE;
  37. m_bPushed = FALSE;
  38. m_strClassName = _T("COMBOBOX");
  39. m_nCtlColorMessage = WM_CTLCOLORLISTBOX;
  40. m_bPaint = FALSE;
  41. }
  42. CXTPSkinObjectComboBox::~CXTPSkinObjectComboBox()
  43. {
  44. }
  45. BEGIN_MESSAGE_MAP(CXTPSkinObjectComboBox, CXTPSkinObjectFrame)
  46. //{{AFX_MSG_MAP(CXTPSkinObjectComboBox)
  47. ON_WM_PAINT()
  48. ON_WM_ERASEBKGND()
  49. ON_WM_MOUSEMOVE()
  50. ON_WM_CREATE()
  51. ON_WM_SETFOCUS()
  52. ON_WM_KILLFOCUS()
  53. ON_WM_CAPTURECHANGED()
  54. //}}AFX_MSG_MAP
  55. ON_MESSAGE_VOID(WM_MOUSELEAVE, OnMouseLeave)
  56. ON_MESSAGE_VOID(BM_SETSTYLE, OnStyleChanged)
  57. ON_MESSAGE_VOID(WM_ENABLE, OnStyleChanged)
  58. ON_MESSAGE_VOID(WM_UPDATEUISTATE, OnStyleChanged)
  59. ON_MESSAGE(WM_PRINTCLIENT, OnPrintClient)
  60. ON_MESSAGE_VOID(WM_LBUTTONUP, OnStyleChanged)
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CXTPSkinObjectComboBox message handlers
  64. int CXTPSkinObjectComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
  65. {
  66. if (CXTPSkinObject::OnCreate(lpCreateStruct) == -1)
  67. return -1;
  68. Invalidate(FALSE);
  69. ModifyStyle(WS_BORDER, 0);
  70. ModifyStyleEx(WS_EX_CLIENTEDGE|WS_EX_STATICEDGE, 0, SWP_FRAMECHANGED);
  71. return 0;
  72. }
  73. LRESULT CXTPSkinObjectComboBox::OnPrintClient(WPARAM wParam, LPARAM lParam)
  74. {
  75. if (((lParam & PRF_CLIENT) == 0) || m_bPaint)
  76. return Default();
  77. CDC* pDC = CDC::FromHandle((HDC)wParam);
  78. if (pDC) OnDraw(pDC);
  79. return 1;
  80. }
  81. void CXTPSkinObjectComboBox::OnPaint()
  82. {
  83. CXTPSkinObjectPaintDC dc(this); // device context for painting
  84. OnDraw(&dc);
  85. }
  86. void CXTPSkinObjectComboBox::OnDraw(CDC* pDC)
  87. {
  88. if ((GetStyle() & 0x3) == CBS_SIMPLE || (GetStyle() & 0x3) == 0)
  89. {
  90. CXTPClientRect rcEdit(this);
  91. rcEdit.bottom = rcEdit.top + (int)SendMessage(CB_GETITEMHEIGHT, (WPARAM)-1) + 2 * GetSystemMetrics(SM_CYFIXEDFRAME);
  92. CXTPSkinManagerClass* pClass = m_pManager->GetSkinClass(_T("EDIT"));
  93. HBRUSH hBrush = GetClientBrush(pDC);
  94. if (pClass->GetThemeEnumValue(0, 0, TMT_BGTYPE) == BT_BORDERFILL)
  95. {
  96. COLORREF clrBorderColor = pClass->GetThemeColor(0, 0, TMT_BORDERCOLOR);
  97. pDC->Draw3dRect(rcEdit, clrBorderColor, clrBorderColor);
  98. rcEdit.DeflateRect(1, 1);
  99. XTPSkinFrameworkDrawFrame(pDC->GetSafeHdc(), &rcEdit, 1, hBrush);
  100. }
  101. else
  102. {
  103. pDC->Draw3dRect(rcEdit, m_pManager->GetMetrics()->m_clrEdgeShadow, m_pManager->GetMetrics()->m_clrEdgeHighLight);
  104. rcEdit.DeflateRect(1, 1);
  105. pDC->Draw3dRect(rcEdit, m_pManager->GetMetrics()->m_clrEdgeDkShadow, m_pManager->GetMetrics()->m_clrEdgeLight);
  106. }
  107. rcEdit.DeflateRect(1, 1);
  108. XTPSkinFrameworkDrawFrame(pDC->GetSafeHdc(), &rcEdit, 1, hBrush);
  109. return;
  110. }
  111. CRect rc;
  112. GetClientRect(&rc);
  113. BOOL bPressed = (GetKeyState(VK_LBUTTON) < 0) && SendMessage(CB_GETDROPPEDSTATE);
  114. BOOL bHot = m_bHot || (::GetCapture() == m_hWnd);
  115. BOOL bEnabled = IsWindowEnabled();
  116. BOOL bRightAlign = GetExStyle() & WS_EX_RIGHT;
  117. CXTPBufferDC memDC(*pDC, rc);
  118. int nMessage = GetClientBrushMessage();
  119. HBRUSH hBrush = FillBackground(&memDC, rc, nMessage);
  120. m_bPaint = TRUE;
  121. DefWindowProc( WM_PAINT, (WPARAM)memDC.m_hDC, 0 );
  122. m_bPaint = FALSE;
  123. CXTPSkinManagerClass* pClassComboBox = GetSkinManager()->GetSkinClass(_T("COMBOBOX"));
  124. memDC.SelectClipRgn(NULL);
  125. int nState = !bEnabled? CBXS_DISABLED: bPressed? CBXS_PRESSED: bHot? CBXS_HOT: CBXS_NORMAL;
  126. int nBGType = pClassComboBox->GetThemeEnumValue(0, nState, TMT_BGTYPE);
  127. int nThumbWidth = GetSystemMetrics(SM_CXVSCROLL);
  128. if (bRightAlign)
  129. ::FillRect(pDC->GetSafeHdc(), CRect(rc.left, rc.top, rc.left + nThumbWidth + 3, rc.bottom), hBrush);
  130. else
  131. ::FillRect(pDC->GetSafeHdc(), CRect(rc.right - nThumbWidth - 3, rc.top, rc.right, rc.bottom), hBrush);
  132. if (nBGType == BT_IMAGEFILE)
  133. {
  134. CRect rectClient(rc.left + 3, rc.top + 3, rc.right - nThumbWidth - 3, rc.bottom - 3);
  135. if (bRightAlign)
  136. rectClient.OffsetRect(nThumbWidth, 0);
  137. memDC.ExcludeClipRect(rectClient);
  138. pClassComboBox->DrawThemeBackground(&memDC, 0, nState, rc);
  139. }
  140. else if (nBGType == BT_BORDERFILL)
  141. {
  142. COLORREF clrBorderColor = pClassComboBox->GetThemeColor(0, nState, TMT_BORDERCOLOR);
  143. memDC.Draw3dRect(rc, clrBorderColor, clrBorderColor);
  144. rc.DeflateRect(1, 1);
  145. CRect rcClient(rc);
  146. if (bRightAlign) rcClient.left += nThumbWidth; else rcClient.right -= nThumbWidth;
  147. XTPSkinFrameworkDrawFrame(memDC, &rcClient, 2, hBrush);
  148. }
  149. CRect rcDropDownButton(rc);
  150. if (bRightAlign) rcDropDownButton.right = rcDropDownButton.left + nThumbWidth;
  151. else rcDropDownButton.left = rcDropDownButton.right - nThumbWidth;
  152. pClassComboBox->DrawThemeBackground(&memDC, CP_DROPDOWNBUTTON, nState, rcDropDownButton);
  153. }
  154. BOOL CXTPSkinObjectComboBox::OnEraseBkgnd(CDC* /*pDC*/)
  155. {
  156. return TRUE;
  157. }
  158. void CXTPSkinObjectComboBox::OnMouseLeave()
  159. {
  160. OnMouseMove(0,CPoint(-1, -1));
  161. }
  162. void CXTPSkinObjectComboBox::OnMouseMove(UINT /*nFlags*/, CPoint point)
  163. {
  164. Default();
  165. CRect rc;
  166. GetClientRect(&rc);
  167. BOOL bHot = rc.PtInRect(point);
  168. if (bHot != m_bHot)
  169. {
  170. m_bHot = bHot;
  171. Invalidate(FALSE);
  172. if (m_bHot)
  173. {
  174. TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, HOVER_DEFAULT};
  175. _TrackMouseEvent(&tme);
  176. }
  177. }
  178. }
  179. void CXTPSkinObjectComboBox::OnSetFocus(CWnd* pOldWnd)
  180. {
  181. CXTPSkinObject::OnSetFocus(pOldWnd);
  182. Invalidate(FALSE);
  183. }
  184. void CXTPSkinObjectComboBox::OnKillFocus(CWnd* pNewWnd)
  185. {
  186. CXTPSkinObject::OnKillFocus(pNewWnd);
  187. Invalidate(FALSE);
  188. }
  189. void CXTPSkinObjectComboBox::OnStyleChanged()
  190. {
  191. Default();
  192. Invalidate(FALSE);
  193. }
  194. void CXTPSkinObjectComboBox::OnCaptureChanged(CWnd* pWnd)
  195. {
  196. CXTPSkinObject::OnCaptureChanged(pWnd);
  197. Invalidate(FALSE);
  198. }
  199. int CXTPSkinObjectComboBox::GetClientBrushMessage()
  200. {
  201. CWnd* pwndEdit = GetWindow(GW_CHILD);
  202. int nMessage = !IsWindowEnabled() || (pwndEdit && pwndEdit->GetStyle() & ES_READONLY) ?
  203. WM_CTLCOLORSTATIC : WM_CTLCOLOREDIT;
  204. return nMessage;
  205. }
  206. //////////////////////////////////////////////////////////////////////////
  207. // CXTPSkinObjectDateTime
  208. IMPLEMENT_DYNCREATE(CXTPSkinObjectDateTime, CXTPSkinObjectComboBox)
  209. CXTPSkinObjectDateTime::CXTPSkinObjectDateTime()
  210. {
  211. }
  212. BEGIN_MESSAGE_MAP(CXTPSkinObjectDateTime, CXTPSkinObjectComboBox)
  213. //{{AFX_MSG_MAP(CXTPSkinObjectDateTime)
  214. ON_WM_CREATE()
  215. ON_WM_LBUTTONDOWN()
  216. //}}AFX_MSG_MAP(CXTPSkinObjectDateTime)
  217. END_MESSAGE_MAP()
  218. int CXTPSkinObjectDateTime::OnCreate(LPCREATESTRUCT lpCreateStruct)
  219. {
  220. if (CXTPSkinObject::OnCreate(lpCreateStruct) == -1)
  221. return -1;
  222. Invalidate(FALSE);
  223. return 0;
  224. }
  225. void CXTPSkinObjectDateTime::OnSkinChanged(BOOL bPrevState, BOOL bNewState)
  226. {
  227. CXTPSkinObjectFrame::OnSkinChanged(bPrevState, bNewState);
  228. }
  229. CRect CXTPSkinObjectDateTime::GetButtonRect()
  230. {
  231. CXTPClientRect rc(this);
  232. rc.left = rc.right - GetSystemMetrics(SM_CXVSCROLL);
  233. return rc;
  234. }
  235. void CXTPSkinObjectDateTime::OnDraw(CDC* pDC)
  236. {
  237. CRect rc;
  238. GetClientRect(&rc);
  239. BOOL bHot = m_bHot || (::GetCapture() == m_hWnd);
  240. BOOL bEnabled = IsWindowEnabled();
  241. CXTPBufferDC memDC(*pDC, rc);
  242. COLORREF clr = GetColor(IsWindowEnabled() ? COLOR_WINDOW : COLOR_3DFACE);
  243. memDC.FillSolidRect(rc, clr);
  244. if (m_bActiveX)
  245. {
  246. m_bPaint = TRUE;
  247. CXTPBufferDC dcMem2(*pDC, rc);
  248. DefWindowProc(WM_PAINT, (WPARAM)dcMem2.GetSafeHdc(), 0);
  249. dcMem2.Discard();
  250. m_bPaint = FALSE;
  251. }
  252. DefWindowProc( WM_PRINTCLIENT, (WPARAM)memDC.m_hDC, 0 );
  253. CXTPSkinManagerClass* pClassComboBox = GetSkinManager()->GetSkinClass(_T("COMBOBOX"));
  254. int nState = !bEnabled? CBXS_DISABLED: bHot? CBXS_HOT: CBXS_NORMAL;
  255. int nBGType = pClassComboBox->GetThemeEnumValue(0, nState, TMT_BGTYPE);
  256. int nThumbWidth = GetSystemMetrics(SM_CXVSCROLL);
  257. BOOL bVistaStyle = !m_bActiveX && XTPSystemVersion()->GetComCtlVersion() >= MAKELONG(10, 6);
  258. if (!bVistaStyle)
  259. {
  260. memDC.FillSolidRect(CRect(rc.right - nThumbWidth - 3, rc.top, rc.right, rc.bottom), clr);
  261. }
  262. if (bVistaStyle)
  263. {
  264. if (nBGType == BT_IMAGEFILE)
  265. {
  266. CRect rectClient(rc.left + 2, rc.top + 2, rc.right - 2, rc.bottom - 2);
  267. memDC.ExcludeClipRect(rectClient);
  268. pClassComboBox->DrawThemeBackground(&memDC, 0, nState, rc);
  269. }
  270. else if (nBGType == BT_BORDERFILL)
  271. {
  272. COLORREF clrBorderColor = pClassComboBox->GetThemeColor(0, nState, TMT_BORDERCOLOR);
  273. memDC.Draw3dRect(rc, clrBorderColor, clrBorderColor);
  274. rc.DeflateRect(1, 1);
  275. CRect rcClient(rc);
  276. memDC.Draw3dRect(&rcClient,clr, clr);
  277. }
  278. }
  279. memDC.SelectClipRgn(NULL);
  280. if (GetStyle() & DTS_SHOWNONE)
  281. {
  282. CRect rcCheck(rc);
  283. rcCheck.DeflateRect(1, 1);
  284. rcCheck.right = rcCheck.left + rcCheck.Height();
  285. memDC.FillSolidRect(rcCheck, clr);
  286. CXTPSkinManagerClass* pClassButton = GetSkinManager()->GetSkinClass(_T("BUTTON"));
  287. CSize size(13, 13);
  288. pClassButton->GetThemePartSize(BP_CHECKBOX, 0, NULL, TS_TRUE, &size);
  289. CRect rcMark(CPoint((rcCheck.left + rcCheck.right - size.cx) / 2,
  290. (rcCheck.top + rcCheck.bottom - size.cy) / 2), size);
  291. int nStateButton = !bEnabled ? CBS_UNCHECKEDDISABLED : CBS_UNCHECKEDNORMAL;
  292. SYSTEMTIME st;
  293. BOOL bChecked = SendMessage(DTM_GETSYSTEMTIME, 0, (LPARAM)&st) != GDT_NONE;
  294. if (bChecked)
  295. nStateButton += 4;
  296. pClassButton->DrawThemeBackground(&memDC, BP_CHECKBOX, nStateButton, &rcMark);
  297. }
  298. if (((GetStyle() & DTS_UPDOWN) == 0) && !bVistaStyle)
  299. {
  300. CRect rcButton = rc;
  301. rcButton.left = rcButton.right - GetSystemMetrics(SM_CXVSCROLL);
  302. memDC.FillSolidRect(rcButton.left, rcButton.top, rcButton.Width(), rcButton.Height(), clr);
  303. pClassComboBox->DrawThemeBackground(&memDC, CP_DROPDOWNBUTTON, nState, rcButton);
  304. }
  305. }
  306. int CXTPSkinObjectDateTime::GetClientBrushMessage()
  307. {
  308. return CXTPSkinObjectComboBox::GetClientBrushMessage();
  309. }
  310. void CXTPSkinObjectDateTime::OnLButtonDown(UINT nFlags, CPoint point)
  311. {
  312. if (IsWindowEnabled() && ((GetStyle() & DTS_UPDOWN) == 0) && GetButtonRect().PtInRect(point))
  313. {
  314. SetFocus();
  315. DefWindowProc(WM_SYSKEYDOWN, VK_DOWN, 0);
  316. return;
  317. }
  318. CXTPSkinObjectComboBox::OnLButtonDown(nFlags, point);
  319. }
  320. void CXTPSkinObjectDateTime::RefreshMetrics()
  321. {
  322. CXTPSkinObjectComboBox::RefreshMetrics();
  323. SendMessage(DTM_SETMCCOLOR, MCSC_BACKGROUND, (LPARAM)GetColor(COLOR_WINDOW));
  324. SendMessage(DTM_SETMCCOLOR, MCSC_MONTHBK, (LPARAM)GetColor(COLOR_WINDOW));
  325. SendMessage(DTM_SETMCCOLOR, MCSC_TEXT, (LPARAM)GetColor(COLOR_WINDOWTEXT));
  326. SendMessage(DTM_SETMCCOLOR, MCSC_TITLEBK, (LPARAM)GetColor(COLOR_ACTIVECAPTION));
  327. SendMessage(DTM_SETMCCOLOR, MCSC_TITLETEXT, (LPARAM)GetColor(COLOR_CAPTIONTEXT));
  328. SendMessage(DTM_SETMCCOLOR, MCSC_TRAILINGTEXT, (LPARAM)GetColor(COLOR_GRAYTEXT));
  329. }
  330. void CXTPSkinObjectDateTime::DrawFrame(CDC* pDC)
  331. {
  332. if (GetExStyle() & WS_EX_CLIENTEDGE)
  333. {
  334. BOOL bHot = m_bHot || (::GetCapture() == m_hWnd);
  335. BOOL bEnabled = IsWindowEnabled();
  336. CXTPSkinManagerClass* pClassComboBox = GetSkinManager()->GetSkinClass(_T("COMBOBOX"));
  337. int nState = !bEnabled? CBXS_DISABLED: bHot? CBXS_HOT: CBXS_NORMAL;
  338. int nBGType = pClassComboBox->GetThemeEnumValue(0, nState, TMT_BGTYPE);
  339. if (nBGType == BT_IMAGEFILE)
  340. {
  341. CXTPWindowRect rc(this);
  342. rc.OffsetRect(-rc.TopLeft());
  343. CRect rectClient(rc.left + 2, rc.top + 2, rc.right - 2, rc.bottom - 2);
  344. pDC->ExcludeClipRect(rectClient);
  345. pClassComboBox->DrawThemeBackground(pDC, 0, nState, rc);
  346. pDC->SelectClipRgn(NULL);
  347. return;
  348. }
  349. }
  350. CXTPSkinObjectComboBox::DrawFrame(pDC);
  351. }
  352. //////////////////////////////////////////////////////////////////////////
  353. // CXTPSkinObjectMonthCal
  354. IMPLEMENT_DYNCREATE(CXTPSkinObjectMonthCal, CXTPSkinObjectFrame)
  355. CXTPSkinObjectMonthCal::CXTPSkinObjectMonthCal()
  356. {
  357. }
  358. void CXTPSkinObjectMonthCal::RefreshMetrics()
  359. {
  360. CXTPSkinObjectFrame::RefreshMetrics();
  361. SendMessage(MCM_SETCOLOR, MCSC_BACKGROUND, (LPARAM)GetColor(COLOR_WINDOW));
  362. SendMessage(MCM_SETCOLOR, MCSC_MONTHBK, (LPARAM)GetColor(COLOR_WINDOW));
  363. SendMessage(MCM_SETCOLOR, MCSC_TEXT, (LPARAM)GetColor(COLOR_WINDOWTEXT));
  364. SendMessage(MCM_SETCOLOR, MCSC_TITLEBK, (LPARAM)GetColor(COLOR_ACTIVECAPTION));
  365. SendMessage(MCM_SETCOLOR, MCSC_TITLETEXT, (LPARAM)GetColor(COLOR_CAPTIONTEXT));
  366. SendMessage(MCM_SETCOLOR, MCSC_TRAILINGTEXT, (LPARAM)GetColor(COLOR_GRAYTEXT));
  367. }