-
Notifications
You must be signed in to change notification settings - Fork 1
/
IconButton.cpp
98 lines (80 loc) · 2.09 KB
/
IconButton.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyleft 2004 Chris Korda
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or any later version.
/*
chris korda
revision history:
rev date comments
00 21nov03 initial version
01 17jan04 ignore space so it can be used as an accelerator key
02 22feb04 add undo
pushbutton with up/down icons
*/
// IconButton.cpp : implementation file
//
#include "stdafx.h"
#include "Resource.h"
#include "IconButton.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CIconButton
CIconButton::CIconButton()
{
m_ResUp = 0;
m_ResDown = 0;
m_PrevCheck = -1;
}
CIconButton::~CIconButton()
{
}
void CIconButton::SetIcons(int ResUp, int ResDown)
{
m_ResUp = ResUp;
m_ResDown = ResDown;
}
void CIconButton::SaveUndoState(CUndoState& State)
{
State.m_Val.x.i = GetCheck();
}
void CIconButton::RestoreUndoState(const CUndoState& State)
{
SetCheck(State.m_Val.x.i);
GetParent()->SendMessage(WM_COMMAND,
MAKELONG(GetDlgCtrlID(), BN_CLICKED), (long)m_hWnd);
}
BEGIN_MESSAGE_MAP(CIconButton, CButton)
//{{AFX_MSG_MAP(CIconButton)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_KEYDOWN()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CIconButton message handlers
HBRUSH CIconButton::CtlColor(CDC* pDC, UINT nCtlColor)
{
int check = GetCheck();
if (check != m_PrevCheck) {
SetIcon(AfxGetApp()->LoadIcon(check ? m_ResDown : m_ResUp));
m_PrevCheck = check;
}
return NULL;
}
void CIconButton::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
switch (nChar) {
case VK_SPACE: // space is too useful an accelerator to waste on a button
return;
}
CButton::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CIconButton::OnLButtonDown(UINT nFlags, CPoint point)
{
NotifyUndoableEdit(0);
CButton::OnLButtonDown(nFlags, point);
}