summaryrefslogtreecommitdiffabout
path: root/ColorButton.cpp
Unidiff
Diffstat (limited to 'ColorButton.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--ColorButton.cpp92
1 files changed, 92 insertions, 0 deletions
diff --git a/ColorButton.cpp b/ColorButton.cpp
new file mode 100644
index 0000000..d702875
--- a/dev/null
+++ b/ColorButton.cpp
@@ -0,0 +1,92 @@
1// ColorButton.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "T42.h"
6#include "ColorButton.h"
7
8#ifdef _DEBUG
9#define new DEBUG_NEW
10#undef THIS_FILE
11static char THIS_FILE[] = __FILE__;
12#endif
13
14/////////////////////////////////////////////////////////////////////////////
15// CColorButton
16
17CColorButton::CColorButton()
18{
19}
20
21CColorButton::~CColorButton()
22{
23}
24
25
26BEGIN_MESSAGE_MAP(CColorButton, CButton)
27 //{{AFX_MSG_MAP(CColorButton)
28 //}}AFX_MSG_MAP
29END_MESSAGE_MAP()
30
31/////////////////////////////////////////////////////////////////////////////
32// CColorButton message handlers
33
34
35void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
36{
37 ASSERT(lpDrawItemStruct->CtlType==ODT_BUTTON);
38CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
39CRect rc(lpDrawItemStruct->rcItem);
40 pDC->DrawFrameControl(
41 &rc,
42 DFC_BUTTON,
43 DFCS_BUTTONPUSH|(
44 (lpDrawItemStruct->itemState&ODS_DISABLED)
45 ? DFCS_INACTIVE
46 : (
47 (lpDrawItemStruct->itemState&ODS_SELECTED)
48 ? DFCS_PUSHED
49 : 0
50 )
51 )|DFCS_ADJUSTRECT
52 );
53 if(!(lpDrawItemStruct->itemState&ODS_DISABLED)){
54 CBrush b(m_Color);
55 pDC->FillRect(rc,&b);
56 if(lpDrawItemStruct->itemState&ODS_FOCUS)
57 pDC->DrawFocusRect(rc);
58 }
59CString txt;
60 GetWindowText(txt);
61 if((lpDrawItemStruct->itemState&ODS_DISABLED)){
62 CSize sz = pDC->GetOutputTextExtent(txt);
63 if(txt.Find('&')>=0)
64 sz.cx-=pDC->GetOutputTextExtent("&",1).cx;
65 CRect rcc;
66 rcc.top=rcc.bottom=rc.CenterPoint().y;
67 rcc.left=rcc.right=rc.CenterPoint().x;
68 rcc.InflateRect(sz.cx/2,sz.cy/2);
69 pDC->DrawState(rcc.TopLeft(),rcc.Size(),(LPCTSTR)txt,DST_PREFIXTEXT|DSS_DISABLED,TRUE,0,(HBRUSH)NULL);
70 }else{
71 COLORREF ocol = pDC->SetTextColor(/*RGB(255,255,255)^*/~m_Color);
72 int omo = pDC->SetBkMode(TRANSPARENT);
73 pDC->DrawText(txt,&rc,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
74 pDC->SetBkMode(omo);
75 pDC->SetTextColor(ocol);
76 }
77}
78
79COLORREF CColorButton::SelectColor(COLORREF color)
80{
81CColorDialog cd(color,CC_RGBINIT,this);
82 if(cd.DoModal()==IDOK)
83 return cd.GetColor();
84 else
85 return color;
86}
87
88void CColorButton::SetColor()
89{
90 m_Color=SelectColor(m_Color);
91 Invalidate();
92}