Mercurial > vba-clojure
comparison src/win32/ColorButton.cpp @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // ColorButton.cpp : implementation file | |
2 // | |
3 | |
4 #include "stdafx.h" | |
5 #include "ColorButton.h" | |
6 | |
7 bool ColorButton::isRegistered = false; | |
8 | |
9 ///////////////////////////////////////////////////////////////////////////// | |
10 // ColorButton | |
11 | |
12 ColorButton::ColorButton() | |
13 { | |
14 color = 0; | |
15 registerClass(); | |
16 } | |
17 | |
18 ColorButton::~ColorButton() | |
19 { | |
20 } | |
21 | |
22 | |
23 BEGIN_MESSAGE_MAP(ColorButton, CButton) | |
24 //{{AFX_MSG_MAP(ColorButton) | |
25 // NOTE - the ClassWizard will add and remove mapping macros here. | |
26 //}}AFX_MSG_MAP | |
27 END_MESSAGE_MAP() | |
28 | |
29 ///////////////////////////////////////////////////////////////////////////// | |
30 // ColorButton message handlers | |
31 | |
32 void ColorButton::PreSubclassWindow() | |
33 { | |
34 SetWindowLong(m_hWnd, GWL_STYLE, GetStyle() | BS_OWNERDRAW); | |
35 CWnd::PreSubclassWindow(); | |
36 } | |
37 | |
38 void ColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) | |
39 { | |
40 ASSERT(lpDrawItemStruct); | |
41 | |
42 int r = (color & 0x1f) << 3; | |
43 int g = (color & 0x3e0) >> 2; | |
44 int b = (color & 0x7c00) >> 7; | |
45 | |
46 HDC dc = lpDrawItemStruct->hDC; | |
47 UINT state = lpDrawItemStruct->itemState; | |
48 RECT rect = lpDrawItemStruct->rcItem; | |
49 | |
50 SIZE margins; | |
51 margins.cx = ::GetSystemMetrics(SM_CXEDGE); | |
52 margins.cy = ::GetSystemMetrics(SM_CYEDGE); | |
53 | |
54 if(GetState() & BST_PUSHED) | |
55 DrawEdge(dc, &rect, EDGE_SUNKEN, BF_RECT); | |
56 else | |
57 DrawEdge(dc, &rect, EDGE_RAISED, BF_RECT); | |
58 | |
59 InflateRect(&rect, -margins.cx, -margins.cy); | |
60 | |
61 HBRUSH br = CreateSolidBrush((state & ODS_DISABLED) ? | |
62 ::GetSysColor(COLOR_3DFACE) : RGB(r,g,b)); | |
63 | |
64 FillRect(dc, &rect, br); | |
65 | |
66 if(state & ODS_FOCUS) { | |
67 InflateRect(&rect, -1, -1); | |
68 DrawFocusRect(dc, &rect); | |
69 } | |
70 | |
71 DeleteObject(br); | |
72 } | |
73 | |
74 void ColorButton::setColor(u16 c) | |
75 { | |
76 color = c; | |
77 Invalidate(); | |
78 } | |
79 | |
80 void ColorButton::registerClass() | |
81 { | |
82 if(!isRegistered) { | |
83 WNDCLASS wc; | |
84 ZeroMemory(&wc, sizeof(wc)); | |
85 wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; | |
86 wc.lpfnWndProc = (WNDPROC)::DefWindowProc; | |
87 wc.hInstance = AfxGetInstanceHandle(); | |
88 wc.hIcon = LoadCursor(NULL, IDC_ARROW); | |
89 wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH); | |
90 wc.lpszMenuName = NULL; | |
91 wc.lpszClassName = "VbaColorButton"; | |
92 AfxRegisterClass(&wc); | |
93 isRegistered = true; | |
94 } | |
95 } |