Mercurial > vba-linux
diff 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 |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/ColorButton.cpp Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,95 @@ 1.4 +// ColorButton.cpp : implementation file 1.5 +// 1.6 + 1.7 +#include "stdafx.h" 1.8 +#include "ColorButton.h" 1.9 + 1.10 +bool ColorButton::isRegistered = false; 1.11 + 1.12 +///////////////////////////////////////////////////////////////////////////// 1.13 +// ColorButton 1.14 + 1.15 +ColorButton::ColorButton() 1.16 +{ 1.17 + color = 0; 1.18 + registerClass(); 1.19 +} 1.20 + 1.21 +ColorButton::~ColorButton() 1.22 +{ 1.23 +} 1.24 + 1.25 + 1.26 +BEGIN_MESSAGE_MAP(ColorButton, CButton) 1.27 + //{{AFX_MSG_MAP(ColorButton) 1.28 + // NOTE - the ClassWizard will add and remove mapping macros here. 1.29 + //}}AFX_MSG_MAP 1.30 + END_MESSAGE_MAP() 1.31 + 1.32 + ///////////////////////////////////////////////////////////////////////////// 1.33 +// ColorButton message handlers 1.34 + 1.35 +void ColorButton::PreSubclassWindow() 1.36 +{ 1.37 + SetWindowLong(m_hWnd, GWL_STYLE, GetStyle() | BS_OWNERDRAW); 1.38 + CWnd::PreSubclassWindow(); 1.39 +} 1.40 + 1.41 +void ColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 1.42 +{ 1.43 + ASSERT(lpDrawItemStruct); 1.44 + 1.45 + int r = (color & 0x1f) << 3; 1.46 + int g = (color & 0x3e0) >> 2; 1.47 + int b = (color & 0x7c00) >> 7; 1.48 + 1.49 + HDC dc = lpDrawItemStruct->hDC; 1.50 + UINT state = lpDrawItemStruct->itemState; 1.51 + RECT rect = lpDrawItemStruct->rcItem; 1.52 + 1.53 + SIZE margins; 1.54 + margins.cx = ::GetSystemMetrics(SM_CXEDGE); 1.55 + margins.cy = ::GetSystemMetrics(SM_CYEDGE); 1.56 + 1.57 + if(GetState() & BST_PUSHED) 1.58 + DrawEdge(dc, &rect, EDGE_SUNKEN, BF_RECT); 1.59 + else 1.60 + DrawEdge(dc, &rect, EDGE_RAISED, BF_RECT); 1.61 + 1.62 + InflateRect(&rect, -margins.cx, -margins.cy); 1.63 + 1.64 + HBRUSH br = CreateSolidBrush((state & ODS_DISABLED) ? 1.65 + ::GetSysColor(COLOR_3DFACE) : RGB(r,g,b)); 1.66 + 1.67 + FillRect(dc, &rect, br); 1.68 + 1.69 + if(state & ODS_FOCUS) { 1.70 + InflateRect(&rect, -1, -1); 1.71 + DrawFocusRect(dc, &rect); 1.72 + } 1.73 + 1.74 + DeleteObject(br); 1.75 +} 1.76 + 1.77 +void ColorButton::setColor(u16 c) 1.78 +{ 1.79 + color = c; 1.80 + Invalidate(); 1.81 +} 1.82 + 1.83 +void ColorButton::registerClass() 1.84 +{ 1.85 + if(!isRegistered) { 1.86 + WNDCLASS wc; 1.87 + ZeroMemory(&wc, sizeof(wc)); 1.88 + wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS; 1.89 + wc.lpfnWndProc = (WNDPROC)::DefWindowProc; 1.90 + wc.hInstance = AfxGetInstanceHandle(); 1.91 + wc.hIcon = LoadCursor(NULL, IDC_ARROW); 1.92 + wc.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH); 1.93 + wc.lpszMenuName = NULL; 1.94 + wc.lpszClassName = "VbaColorButton"; 1.95 + AfxRegisterClass(&wc); 1.96 + isRegistered = true; 1.97 + } 1.98 +}