-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIButton.cpp
More file actions
223 lines (194 loc) · 5.91 KB
/
UIButton.cpp
File metadata and controls
223 lines (194 loc) · 5.91 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "StdAfx.h"
#include "UIButton.h"
/////////////////////////////////////////////////////////////////////////////////////
//
//
CButtonUI::CButtonUI() : m_cxWidth(0), m_uButtonState(0), m_uTextStyle(DT_SINGLELINE | DT_CENTER)
{
m_szPadding.cx = 4;
m_szPadding.cy = 0;
}
LPCTSTR CButtonUI::GetClass() const
{
return _T("ButtonUI");
}
UINT CButtonUI::GetControlFlags() const
{
return UIFLAG_TABSTOP;
}
void CButtonUI::Event(TEventUI& event)
{
if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK )
{
if( ::PtInRect(&m_rcItem, event.ptMouse) && IsEnabled() ) {
m_uButtonState |= UISTATE_PUSHED | UISTATE_CAPTURED;
Invalidate();
}
}
if( event.Type == UIEVENT_MOUSEMOVE )
{
if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
if( ::PtInRect(&m_rcItem, event.ptMouse) ) m_uButtonState |= UISTATE_PUSHED;
else m_uButtonState &= ~UISTATE_PUSHED;
Invalidate();
}
}
if( event.Type == UIEVENT_BUTTONUP )
{
if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
if( ::PtInRect(&m_rcItem, event.ptMouse) ) Activate();
m_uButtonState &= ~(UISTATE_PUSHED | UISTATE_CAPTURED);
Invalidate();
}
}
if( event.Type == UIEVENT_MOUSEENTER)
{
m_uButtonState |= UISTATE_HOT;
Invalidate();
}
if( event.Type == UIEVENT_MOUSELEAVE)
{
m_uButtonState &= ~UISTATE_HOT;
Invalidate();
}
CControlUI::Event(event);
}
void CButtonUI::SetText(LPCTSTR pstrText)
{
CControlUI::SetText(pstrText);
// Automatic assignment of keyboard shortcut
if( _tcschr(pstrText, '&') != NULL ) m_chShortcut = *(_tcschr(pstrText, '&') + 1);
}
bool CButtonUI::Activate()
{
if( !CControlUI::Activate() ) return false;
if( m_pManager != NULL ) m_pManager->SendNotify(this, _T("click"));
return true;
}
void CButtonUI::SetWidth(int cxWidth)
{
m_cxWidth = cxWidth;
UpdateLayout();
}
void CButtonUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
if( _tcscmp(pstrName, _T("width")) == 0 ) SetWidth(_ttoi(pstrValue));
else if( _tcscmp(pstrName, _T("align")) == 0 ) {
if( _tcsstr(pstrValue, _T("center")) != NULL ) m_uTextStyle |= DT_CENTER;
if( _tcsstr(pstrValue, _T("right")) != NULL ) m_uTextStyle |= DT_RIGHT;
}
else CControlUI::SetAttribute(pstrName, pstrValue);
}
void CButtonUI::SetPadding(int cx, int cy)
{
m_szPadding.cx = cx;
m_szPadding.cy = cy;
UpdateLayout();
}
SIZE CButtonUI::EstimateSize(SIZE /*szAvailable*/)
{
SIZE sz = { m_cxWidth, 12 + m_pManager->GetThemeFontInfo(UIFONT_NORMAL).tmHeight };
if( m_cxWidth == 0 && m_pManager != NULL ) {
RECT rcText = { 0, 0, 9999, 20 };
int nLinks = 0;
CBlueRenderEngineUI::DoPaintPrettyText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, UICOLOR_STANDARD_BLACK, UICOLOR__INVALID, NULL, nLinks, DT_SINGLELINE | DT_CALCRECT);
sz.cx = rcText.right - rcText.left;
}
sz.cx += m_szPadding.cx * 2;
sz.cy += m_szPadding.cy * 2;
return sz;
}
void CButtonUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
// Draw button
UINT uState = 0;
if( IsFocused() ) uState |= UISTATE_FOCUSED;
if( !IsEnabled() ) uState |= UISTATE_DISABLED;
RECT rcPadding = { m_szPadding.cx, m_szPadding.cy, m_szPadding.cx, m_szPadding.cy };
CBlueRenderEngineUI::DoPaintButton(hDC, m_pManager, m_rcItem, m_sText, rcPadding, m_uButtonState | uState, m_uTextStyle);
}
/////////////////////////////////////////////////////////////////////////////////////
//
//
COptionUI::COptionUI() : m_cxWidth(0), m_uButtonState(0), m_uStyle(DT_LEFT), m_bSelected(false)
{
}
LPCTSTR COptionUI::GetClass() const
{
return _T("OptionUI");
}
UINT COptionUI::GetControlFlags() const
{
return UIFLAG_TABSTOP;
}
void COptionUI::Event(TEventUI& event)
{
if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK )
{
if( ::PtInRect(&m_rcItem, event.ptMouse) && IsEnabled() ) {
m_uButtonState |= UISTATE_PUSHED | UISTATE_CAPTURED;
Invalidate();
}
}
if( event.Type == UIEVENT_MOUSEMOVE )
{
if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
if( ::PtInRect(&m_rcItem, event.ptMouse) ) m_uButtonState |= UISTATE_PUSHED;
else m_uButtonState &= ~UISTATE_PUSHED;
Invalidate();
}
}
if( event.Type == UIEVENT_BUTTONUP )
{
if( (m_uButtonState & UISTATE_CAPTURED) != 0 ) {
if( ::PtInRect(&m_rcItem, event.ptMouse) ) Activate();
m_uButtonState &= ~(UISTATE_PUSHED | UISTATE_CAPTURED);
Invalidate();
}
}
CControlUI::Event(event);
}
bool COptionUI::IsChecked() const
{
return m_bSelected;
}
void COptionUI::SetCheck(bool bSelected)
{
if( m_bSelected == bSelected ) return;
m_bSelected = bSelected;
if( m_pManager != NULL ) m_pManager->SendNotify(this, _T("changed"));
Invalidate();
}
bool COptionUI::Activate()
{
if( !CControlUI::Activate() ) return false;
SetCheck(true);
return true;
}
void COptionUI::SetWidth(int cxWidth)
{
m_cxWidth = cxWidth;
UpdateLayout();
}
void COptionUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
if( _tcscmp(pstrName, _T("width")) == 0 ) SetWidth(_ttoi(pstrValue));
else if( _tcscmp(pstrName, _T("selected")) == 0 ) SetCheck(_tcscmp(pstrValue, _T("true")) == 0);
else if( _tcscmp(pstrName, _T("align")) == 0 ) {
if( _tcsstr(pstrValue, _T("right")) != NULL ) m_uStyle |= DT_RIGHT;
}
else CControlUI::SetAttribute(pstrName, pstrValue);
}
SIZE COptionUI::EstimateSize(SIZE /*szAvailable*/)
{
return CSize(m_cxWidth, 18 + m_pManager->GetThemeFontInfo(UIFONT_NORMAL).tmHeight);
}
void COptionUI::DoPaint(HDC hDC, const RECT& rcPaint)
{
// Draw button
UINT uState = 0;
if( m_bSelected ) uState |= UISTATE_CHECKED;
if( IsFocused() ) uState |= UISTATE_FOCUSED;
if( !IsEnabled() ) uState |= UISTATE_DISABLED;
CBlueRenderEngineUI::DoPaintOptionBox(hDC, m_pManager, m_rcItem, m_sText, m_uButtonState | uState, m_uStyle);
}