OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/cfwl_spinbutton.h" | 7 #include "xfa/fwl/cfwl_spinbutton.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 CFWL_SpinButton::~CFWL_SpinButton() {} | 43 CFWL_SpinButton::~CFWL_SpinButton() {} |
44 | 44 |
45 FWL_Type CFWL_SpinButton::GetClassID() const { | 45 FWL_Type CFWL_SpinButton::GetClassID() const { |
46 return FWL_Type::SpinButton; | 46 return FWL_Type::SpinButton; |
47 } | 47 } |
48 | 48 |
49 void CFWL_SpinButton::Update() { | 49 void CFWL_SpinButton::Update() { |
50 if (IsLocked()) | 50 if (IsLocked()) |
51 return; | 51 return; |
52 | 52 |
53 GetClientRect(m_rtClient); | 53 m_rtClient = GetClientRect(); |
54 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { | 54 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { |
55 m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, | 55 m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, |
56 m_rtClient.height / 2); | 56 m_rtClient.height / 2); |
57 m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, | 57 m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, |
58 m_rtClient.width, m_rtClient.height / 2); | 58 m_rtClient.width, m_rtClient.height / 2); |
59 } else { | 59 } else { |
60 m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, | 60 m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, |
61 m_rtClient.height); | 61 m_rtClient.height); |
62 m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, | 62 m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, |
63 m_rtClient.width / 2, m_rtClient.height); | 63 m_rtClient.width / 2, m_rtClient.height); |
64 } | 64 } |
65 } | 65 } |
66 | 66 |
67 FWL_WidgetHit CFWL_SpinButton::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 67 FWL_WidgetHit CFWL_SpinButton::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
68 if (m_rtClient.Contains(fx, fy)) | 68 if (m_rtClient.Contains(fx, fy)) |
69 return FWL_WidgetHit::Client; | 69 return FWL_WidgetHit::Client; |
70 if (HasBorder() && (m_rtClient.Contains(fx, fy))) | 70 if (HasBorder() && (m_rtClient.Contains(fx, fy))) |
71 return FWL_WidgetHit::Border; | 71 return FWL_WidgetHit::Border; |
72 if (HasEdge()) { | 72 if (HasEdge() && GetEdgeRect().Contains(fx, fy)) |
73 CFX_RectF rtEdge; | 73 return FWL_WidgetHit::Left; |
74 GetEdgeRect(rtEdge); | |
75 if (rtEdge.Contains(fx, fy)) | |
76 return FWL_WidgetHit::Left; | |
77 } | |
78 if (m_rtUpButton.Contains(fx, fy)) | 74 if (m_rtUpButton.Contains(fx, fy)) |
79 return FWL_WidgetHit::UpButton; | 75 return FWL_WidgetHit::UpButton; |
80 if (m_rtDnButton.Contains(fx, fy)) | 76 if (m_rtDnButton.Contains(fx, fy)) |
81 return FWL_WidgetHit::DownButton; | 77 return FWL_WidgetHit::DownButton; |
82 return FWL_WidgetHit::Unknown; | 78 return FWL_WidgetHit::Unknown; |
83 } | 79 } |
84 | 80 |
85 void CFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, | 81 void CFWL_SpinButton::DrawWidget(CFX_Graphics* pGraphics, |
86 const CFX_Matrix* pMatrix) { | 82 const CFX_Matrix* pMatrix) { |
87 if (!pGraphics) | 83 if (!pGraphics) |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 const CFX_Matrix* pMatrix) { | 188 const CFX_Matrix* pMatrix) { |
193 DrawWidget(pGraphics, pMatrix); | 189 DrawWidget(pGraphics, pMatrix); |
194 } | 190 } |
195 | 191 |
196 void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { | 192 void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
197 if (bSet) | 193 if (bSet) |
198 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 194 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
199 else | 195 else |
200 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 196 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
201 | 197 |
202 Repaint(&m_rtClient); | 198 RepaintRect(m_rtClient); |
203 } | 199 } |
204 | 200 |
205 void CFWL_SpinButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { | 201 void CFWL_SpinButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
206 m_bLButtonDwn = true; | 202 m_bLButtonDwn = true; |
207 SetGrab(true); | 203 SetGrab(true); |
208 SetFocus(true); | 204 SetFocus(true); |
209 | 205 |
210 bool bUpPress = | 206 bool bUpPress = |
211 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); | 207 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); |
212 bool bDnPress = | 208 bool bDnPress = |
213 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); | 209 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); |
214 if (!bUpPress && !bDnPress) | 210 if (!bUpPress && !bDnPress) |
215 return; | 211 return; |
216 if (bUpPress) { | 212 if (bUpPress) { |
217 m_iButtonIndex = 0; | 213 m_iButtonIndex = 0; |
218 m_dwUpState = CFWL_PartState_Pressed; | 214 m_dwUpState = CFWL_PartState_Pressed; |
219 } | 215 } |
220 if (bDnPress) { | 216 if (bDnPress) { |
221 m_iButtonIndex = 1; | 217 m_iButtonIndex = 1; |
222 m_dwDnState = CFWL_PartState_Pressed; | 218 m_dwDnState = CFWL_PartState_Pressed; |
223 } | 219 } |
224 | 220 |
225 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); | 221 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); |
226 DispatchEvent(&wmPosChanged); | 222 DispatchEvent(&wmPosChanged); |
227 | 223 |
228 Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); | 224 RepaintRect(bUpPress ? m_rtUpButton : m_rtDnButton); |
229 m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); | 225 m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); |
230 } | 226 } |
231 | 227 |
232 void CFWL_SpinButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { | 228 void CFWL_SpinButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
233 if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) | 229 if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) |
234 return; | 230 return; |
235 | 231 |
236 m_bLButtonDwn = false; | 232 m_bLButtonDwn = false; |
237 SetGrab(false); | 233 SetGrab(false); |
238 SetFocus(false); | 234 SetFocus(false); |
239 if (m_pTimerInfo) { | 235 if (m_pTimerInfo) { |
240 m_pTimerInfo->StopTimer(); | 236 m_pTimerInfo->StopTimer(); |
241 m_pTimerInfo = nullptr; | 237 m_pTimerInfo = nullptr; |
242 } | 238 } |
243 bool bRepaint = false; | 239 bool bRepaint = false; |
244 CFX_RectF rtInvalidate; | 240 CFX_RectF rtInvalidate; |
245 if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { | 241 if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { |
246 m_dwUpState = CFWL_PartState_Normal; | 242 m_dwUpState = CFWL_PartState_Normal; |
247 bRepaint = true; | 243 bRepaint = true; |
248 rtInvalidate = m_rtUpButton; | 244 rtInvalidate = m_rtUpButton; |
249 } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { | 245 } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { |
250 m_dwDnState = CFWL_PartState_Normal; | 246 m_dwDnState = CFWL_PartState_Normal; |
251 bRepaint = true; | 247 bRepaint = true; |
252 rtInvalidate = m_rtDnButton; | 248 rtInvalidate = m_rtDnButton; |
253 } | 249 } |
254 if (bRepaint) | 250 if (bRepaint) |
255 Repaint(&rtInvalidate); | 251 RepaintRect(rtInvalidate); |
256 } | 252 } |
257 | 253 |
258 void CFWL_SpinButton::OnMouseMove(CFWL_MessageMouse* pMsg) { | 254 void CFWL_SpinButton::OnMouseMove(CFWL_MessageMouse* pMsg) { |
259 if (m_bLButtonDwn) | 255 if (m_bLButtonDwn) |
260 return; | 256 return; |
261 | 257 |
262 bool bRepaint = false; | 258 bool bRepaint = false; |
263 CFX_RectF rtInvlidate; | 259 CFX_RectF rtInvlidate; |
264 rtInvlidate.Reset(); | 260 rtInvlidate.Reset(); |
265 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { | 261 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 m_dwDnState = CFWL_PartState_Normal; | 305 m_dwDnState = CFWL_PartState_Normal; |
310 if (bRepaint) | 306 if (bRepaint) |
311 rtInvlidate.Union(m_rtDnButton); | 307 rtInvlidate.Union(m_rtDnButton); |
312 else | 308 else |
313 rtInvlidate = m_rtDnButton; | 309 rtInvlidate = m_rtDnButton; |
314 | 310 |
315 bRepaint = true; | 311 bRepaint = true; |
316 } | 312 } |
317 } | 313 } |
318 if (bRepaint) | 314 if (bRepaint) |
319 Repaint(&rtInvlidate); | 315 RepaintRect(rtInvlidate); |
320 } | 316 } |
321 | 317 |
322 void CFWL_SpinButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { | 318 void CFWL_SpinButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { |
323 if (!pMsg) | 319 if (!pMsg) |
324 return; | 320 return; |
325 if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) | 321 if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) |
326 m_dwUpState = CFWL_PartState_Normal; | 322 m_dwUpState = CFWL_PartState_Normal; |
327 if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) | 323 if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) |
328 m_dwDnState = CFWL_PartState_Normal; | 324 m_dwDnState = CFWL_PartState_Normal; |
329 | 325 |
330 Repaint(&m_rtClient); | 326 RepaintRect(m_rtClient); |
331 } | 327 } |
332 | 328 |
333 void CFWL_SpinButton::OnKeyDown(CFWL_MessageKey* pMsg) { | 329 void CFWL_SpinButton::OnKeyDown(CFWL_MessageKey* pMsg) { |
334 bool bUp = | 330 bool bUp = |
335 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; | 331 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; |
336 bool bDown = | 332 bool bDown = |
337 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; | 333 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; |
338 if (!bUp && !bDown) | 334 if (!bUp && !bDown) |
339 return; | 335 return; |
340 | 336 |
341 bool bUpEnable = IsUpButtonEnabled(); | 337 bool bUpEnable = IsUpButtonEnabled(); |
342 bool bDownEnable = IsDownButtonEnabled(); | 338 bool bDownEnable = IsDownButtonEnabled(); |
343 if (!bUpEnable && !bDownEnable) | 339 if (!bUpEnable && !bDownEnable) |
344 return; | 340 return; |
345 | 341 |
346 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); | 342 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); |
347 DispatchEvent(&wmPosChanged); | 343 DispatchEvent(&wmPosChanged); |
348 | 344 |
349 Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); | 345 RepaintRect(bUpEnable ? m_rtUpButton : m_rtDnButton); |
350 } | 346 } |
351 | 347 |
352 CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) | 348 CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) |
353 : CFWL_Timer(pToolTip) {} | 349 : CFWL_Timer(pToolTip) {} |
354 | 350 |
355 void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { | 351 void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { |
356 CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget); | 352 CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget); |
357 | 353 |
358 if (!pButton->m_pTimerInfo) | 354 if (!pButton->m_pTimerInfo) |
359 return; | 355 return; |
360 | 356 |
361 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); | 357 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); |
362 pButton->DispatchEvent(&wmPosChanged); | 358 pButton->DispatchEvent(&wmPosChanged); |
363 } | 359 } |
OLD | NEW |