soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SSpinButtonCtrl.cpp
1#include "include/souistd.h"
3
4SNSBEGIN
6 : m_pDownSkin(GETBUILTINSKIN(SKIN_SYS_SPIN_DOWN))
7 , m_pUpSkin(GETBUILTINSKIN(SKIN_SYS_SPIN_UP))
9 , m_nMin(0)
10 , m_nMax(100)
11 , m_nValue(0)
12 , m_uStep(1)
13 , m_bCircle(TRUE)
14{
15 GetEventSet()->addEvent(EVENTID(EventSpinValue2String));
16}
17
21
23{
24 m_nValue = nValue;
26}
27
28void SSpinButtonCtrl::SetRange(int nMin, int nMax)
29{
30 m_nMin = nMin;
31 m_nMax = nMax;
32 if (m_nValue < m_nMin)
34 if (m_nValue > nMax)
35 m_nValue = nMax;
37}
38
40{
41 m_uStep = nStep;
42}
43
45{
46 return m_nValue;
47}
48
50{
51 return GetBuddy();
52}
53
54void SSpinButtonCtrl::GetDesiredSize(SIZE *psz, int wid, int hei)
55{
56 CSize szRet;
57 if (GetLayoutParam()->IsSpecifiedSize(Horz))
58 {
59 szRet.cx = GetLayoutParam()->GetSpecifiedSize(Horz).toPixelSize(GetScale());
60 }
61 else
62 {
63 szRet.cx = m_pDownSkin->GetSkinSize().cx;
64 }
65 if (GetLayoutParam()->IsSpecifiedSize(Vert))
66 {
67 szRet.cy = GetLayoutParam()->GetSpecifiedSize(Vert).toPixelSize(GetScale());
68 }
69 else
70 {
71 szRet.cy = m_pDownSkin->GetSkinSize().cy + m_pUpSkin->GetSkinSize().cy;
72 }
73 *psz = szRet;
74}
75
76HRESULT SSpinButtonCtrl::OnAttrValue(const SStringW &strValue, BOOL bLoading)
77{
78 m_nValue = _wtoi(strValue);
79 if (!bLoading)
80 {
82 }
83 return S_OK;
84}
85
87{
88 SWindow *pBuddy = GetBuddy();
89 if (pBuddy)
90 {
91 SStringT strValue = SStringT().Format(_T("%d"), m_nValue);
92 EventSpinValue2String evt(this);
93 evt.bInit = bInit;
94 evt.nValue = m_nValue;
95 evt.strValue = &strValue;
96 FireEvent(evt);
97 pBuddy->SetWindowText(strValue);
98 }
99}
100
101void SSpinButtonCtrl::OnLButtonDown(UINT nFlags, CPoint point)
102{
103 SWindow::OnLButtonDown(nFlags, point);
104 OnClick();
105 Invalidate();
106 SetTimer(1, 200);
107}
108
109void SSpinButtonCtrl::OnLButtonUp(UINT nFlags, CPoint point)
110{
111 SWindow::OnLButtonUp(nFlags, point);
112 KillTimer(1);
113 Invalidate();
114}
115
116void SSpinButtonCtrl::OnMouseMove(UINT nFlags, CPoint point)
117{
118 CRect rcClient = GetClientRect();
119 if (rcClient.PtInRect(point))
120 {
121 if (point.y > (rcClient.top + rcClient.Height() / 2))
123 else
125 }
126 else
127 {
129 }
130}
131
133{
134 __baseCls::OnColorize(cr);
135
136 if (m_pUpSkin)
137 m_pUpSkin->OnColorize(cr);
138 if (m_pDownSkin)
139 m_pDownSkin->OnColorize(cr);
140}
141
143{
144 SWindow::OnPaint(pRT);
145 CRect rcClient = GetClientRect();
146 CRect rcUp = rcClient, rcDown = rcClient;
147 rcUp.bottom = rcDown.top = rcClient.top + rcClient.Height() / 2;
148 int iState = SState2Index::GetDefIndex(GetState(), true);
149 if (m_iActionBtn == ACTION_UP)
150 {
151 m_pUpSkin->DrawByIndex(pRT, rcUp, iState);
152 m_pDownSkin->DrawByIndex(pRT, rcDown, iState != 2 ? iState : 1);
153 }
154 else if (m_iActionBtn == ACTION_DOWN)
155 {
156 m_pUpSkin->DrawByIndex(pRT, rcUp, iState != 2 ? iState : 1);
157 m_pDownSkin->DrawByIndex(pRT, rcDown, iState);
158 }
159 else
160 {
161 iState = iState != 2 ? iState : 0;
162 m_pUpSkin->DrawByIndex(pRT, rcUp, iState);
163 m_pDownSkin->DrawByIndex(pRT, rcDown, iState);
164 }
165}
166void SSpinButtonCtrl::OnTimer(char cTimerId)
167{
169 {
170 return;
171 }
172
173 OnClick();
174}
175
177{
178 EventRENotify *pEvt2 = sobj_cast<EventRENotify>(pEvt);
179 if (pEvt2->iNotify != EN_CHANGE)
180 return false;
181 SWindow *pBuddy = GetBuddy();
182 if (pBuddy)
183 {
184 int nValue = _ttoi(pBuddy->GetWindowText());
185 if (nValue <= m_nMax && nValue >= m_nMin)
186 {
187 m_nValue = nValue;
188
189 SStringT strValue = SStringT().Format(_T("%d"), m_nValue);
190 EventSpinValue2String evt(this);
191 evt.bInit = false;
192 evt.nValue = m_nValue;
193 evt.strValue = &strValue;
194 FireEvent(evt);
195 }
196 }
197 return TRUE;
198}
199
201{
202 __baseCls::OnScaleChanged(scale);
203 GetScaleSkin(m_pUpSkin, scale);
205}
206
208{
209 int nRet = __baseCls::OnCreate(NULL);
210 if (nRet != 0)
211 return nRet;
212 OnValueChanged(true);
213
214 SWindow *pBuddy = GetBuddy();
215 if (pBuddy)
217 return 0;
218}
219
221{
222 SASSERT(m_iActionBtn != ACTION_NULL);
223
225 {
226 m_nValue -= m_uStep;
227 if (m_nValue < m_nMin)
228 {
229 if (m_bCircle)
231 else
233 }
234 }
235 else
236 {
237 m_nValue += m_uStep;
238 if (m_nValue > m_nMax)
239 {
240 if (m_bCircle)
242 else
244 }
245 }
247}
248
253
254SNSEND
@ EVT_RE_NOTIFY
丰富编辑控件通知事件
Definition SEvents.h:111
Definition of the SSpinButtonCtrl class.
BOOL subscribeEvent(DWORD dwEventID, const IEvtSlot &subscriber)
订阅事件
Definition SEventSet.h:151
BOOL addEvent(DWORD dwEventID, LPCWSTR pszEventHandlerName)
添加一个新事件到事件集
int toPixelSize(int scale) const
将大小转换为像素值
void OnLButtonUp(UINT nFlags, CPoint point)
Handles left mouse button up events.
HRESULT OnAttrValue(const SStringW &strValue, BOOL bLoading)
Maps messages to handler functions.
BOOL OnBuddyChange(IEvtArgs *pEvt)
Handles buddy change events.
void OnScaleChanged(int scale)
Handles scale change events.
void OnMouseMove(UINT nFlags, CPoint point)
Handles mouse move events.
void SetStep(UINT nStep) OVERRIDE
Sets the step size for the spin button.
SAutoRefPtr< ISkinObj > m_pDownSkin
void OnClick()
Handles click events.
int OnCreate(void *)
Handles creation events.
SAutoRefPtr< ISkinObj > m_pUpSkin
ActionButton m_iActionBtn
void OnLButtonDown(UINT nFlags, CPoint point)
Handles left mouse button down events.
int GetValue() SCONST OVERRIDE
Retrieves the current value of the spin button.
SSpinButtonCtrl(void)
Define the SObject type and name, base class is SWindow, control name is spinButton.
SWindow * GetBuddy() const
Retrieves the buddy window associated with the spin button.
~SSpinButtonCtrl(void)
Destructor for SSpinButtonCtrl.
void SetRange(int nMin, int nMax) OVERRIDE
Sets the range of values for the spin button.
void OnPaint(IRenderTarget *pRT)
Handles paint events.
virtual void OnColorize(COLORREF cr)
Handles colorization of the control.
void OnTimer(char cTimerId)
Handles timer events.
void OnValueChanged(bool bInit=false)
Handles value change events.
IWindow * GetIBuddy() SCONST OVERRIDE
Retrieves the buddy window interface associated with the spin button.
void SetValue(int nValue) OVERRIDE
Sets the current value of the spin button.
void GetDesiredSize(SIZE *psz, int nParentWid, int nParentHei) OVERRIDE
Calculates the desired size of the control.
static int GetDefIndex(DWORD dwState, bool checkAsPushdown=false)
Gets the default index for a given state.
A class representing an ASCII string.
Definition sstringw.h:96
BOOL SetTimer(char id, UINT uElapse) OVERRIDE
Sets a timer for the window.
Definition Swnd.cpp:477
BOOL FireEvent(IEvtArgs *evt) OVERRIDE
Fires an event.
Definition Swnd.cpp:1540
SWindow * GetParent() const
Retrieves the parent window.
Definition Swnd.cpp:3488
DWORD GetState() SCONST OVERRIDE
Retrieves the current state of the window.
Definition Swnd.cpp:437
int GetWindowText(TCHAR *pBuf, int nBufLen, BOOL bRawText) OVERRIDE
Retrieves the window text.
Definition Swnd.cpp:263
void OnPaint(IRenderTarget *pRT)
Handles the painting of the window.
Definition Swnd.cpp:1785
int GetScale() SCONST OVERRIDE
Retrieves the scale factor of the window.
Definition Swnd.cpp:3266
SWindow * FindChildByName(LPCWSTR strName, int nDeep=-1)
Finds a child window by its name.
Definition Swnd.cpp:795
virtual CRect GetClientRect() const
Retrieves the client rectangle of the window.
Definition Swnd.cpp:243
void OnLButtonUp(UINT nFlags, CPoint pt)
Handles the left mouse button up event.
Definition Swnd.cpp:2105
SWindow()
Constructor.
Definition Swnd.cpp:104
void OnLButtonDown(UINT nFlags, CPoint pt)
Handles the left mouse button down event.
Definition Swnd.cpp:2092
ILayoutParam * GetLayoutParam() SCONST OVERRIDE
Retrieves the layout parameter object associated with the window.
Definition SWnd.h:405
SEventSet * GetEventSet()
Retrieves the event set associated with the window.
Definition SWnd.h:1290
BOOL KillTimer(char id) OVERRIDE
Kills a timer for the window.
Definition Swnd.cpp:483
void Invalidate() OVERRIDE
Invalidates the entire window.
Definition Swnd.cpp:1437
void SetWindowText(LPCTSTR lpszText) OVERRIDE
Sets the window text.
Definition Swnd.cpp:311
void GetScaleSkin(SAutoRefPtr< ISkinObj > &pSkin, int nScale)
Retrieves a scaled skin object based on the current scale factor.
Definition Swnd.cpp:3290
Interface for rendering target objects.
Definition SRender-i.h:1440