author | Michael Krelin <hacker@klever.net> | 2004-07-05 01:53:09 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2004-07-05 01:53:09 (UTC) |
commit | 955d4e00adc9f39ab93bf21f07506eb75b013c70 (patch) (unidiff) | |
tree | 92493a2c9ac206b822e24a9e5a6f6b1589be6afb /ColorButton.cpp | |
download | T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.zip T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.tar.gz T42-955d4e00adc9f39ab93bf21f07506eb75b013c70.tar.bz2 |
initial commit into svn repository
git-svn-id: http://svn.klever.net/kin/T42/trunk@1 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | ColorButton.cpp | 92 |
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 | ||
11 | static char THIS_FILE[] = __FILE__; | ||
12 | #endif | ||
13 | |||
14 | ///////////////////////////////////////////////////////////////////////////// | ||
15 | // CColorButton | ||
16 | |||
17 | CColorButton::CColorButton() | ||
18 | { | ||
19 | } | ||
20 | |||
21 | CColorButton::~CColorButton() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | |||
26 | BEGIN_MESSAGE_MAP(CColorButton, CButton) | ||
27 | //{{AFX_MSG_MAP(CColorButton) | ||
28 | //}}AFX_MSG_MAP | ||
29 | END_MESSAGE_MAP() | ||
30 | |||
31 | ///////////////////////////////////////////////////////////////////////////// | ||
32 | // CColorButton message handlers | ||
33 | |||
34 | |||
35 | void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) | ||
36 | { | ||
37 | ASSERT(lpDrawItemStruct->CtlType==ODT_BUTTON); | ||
38 | CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC); | ||
39 | CRect 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 | } | ||
59 | CString 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 | |||
79 | COLORREF CColorButton::SelectColor(COLORREF color) | ||
80 | { | ||
81 | CColorDialog cd(color,CC_RGBINIT,this); | ||
82 | if(cd.DoModal()==IDOK) | ||
83 | return cd.GetColor(); | ||
84 | else | ||
85 | return color; | ||
86 | } | ||
87 | |||
88 | void CColorButton::SetColor() | ||
89 | { | ||
90 | m_Color=SelectColor(m_Color); | ||
91 | Invalidate(); | ||
92 | } | ||