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/core/cfwl_spinbutton.h" | 7 #include "xfa/fwl/core/cfwl_spinbutton.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | 107 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); |
108 if (HasBorder()) | 108 if (HasBorder()) |
109 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 109 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
110 if (HasEdge()) | 110 if (HasEdge()) |
111 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 111 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
112 | 112 |
113 DrawUpButton(pGraphics, pTheme, pMatrix); | 113 DrawUpButton(pGraphics, pTheme, pMatrix); |
114 DrawDownButton(pGraphics, pTheme, pMatrix); | 114 DrawDownButton(pGraphics, pTheme, pMatrix); |
115 } | 115 } |
116 | 116 |
117 void CFWL_SpinButton::EnableButton(bool bEnable, bool bUp) { | 117 void CFWL_SpinButton::DisableButton() { |
118 if (bUp) | 118 m_dwDnState = CFWL_PartState_Disabled; |
119 m_dwUpState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; | |
120 else | |
121 m_dwDnState = bEnable ? CFWL_PartState_Normal : CFWL_PartState_Disabled; | |
122 } | 119 } |
123 | 120 |
124 bool CFWL_SpinButton::IsButtonEnabled(bool bUp) { | 121 bool CFWL_SpinButton::IsUpButtonEnabled() { |
125 if (bUp) | 122 return m_dwUpState != CFWL_PartState_Disabled; |
126 return (m_dwUpState != CFWL_PartState_Disabled); | 123 } |
127 return (m_dwDnState != CFWL_PartState_Disabled); | 124 |
| 125 bool CFWL_SpinButton::IsDownButtonEnabled() { |
| 126 return m_dwDnState != CFWL_PartState_Disabled; |
128 } | 127 } |
129 | 128 |
130 void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, | 129 void CFWL_SpinButton::DrawUpButton(CFX_Graphics* pGraphics, |
131 IFWL_ThemeProvider* pTheme, | 130 IFWL_ThemeProvider* pTheme, |
132 const CFX_Matrix* pMatrix) { | 131 const CFX_Matrix* pMatrix) { |
133 CFWL_ThemeBackground params; | 132 CFWL_ThemeBackground params; |
134 params.m_pWidget = this; | 133 params.m_pWidget = this; |
135 params.m_iPart = CFWL_Part::UpButton; | 134 params.m_iPart = CFWL_Part::UpButton; |
136 params.m_pGraphics = pGraphics; | 135 params.m_pGraphics = pGraphics; |
137 params.m_dwStates = m_dwUpState + 1; | 136 params.m_dwStates = m_dwUpState + 1; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 | 214 |
216 Repaint(&m_rtClient); | 215 Repaint(&m_rtClient); |
217 } | 216 } |
218 | 217 |
219 void CFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 218 void CFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
220 m_bLButtonDwn = true; | 219 m_bLButtonDwn = true; |
221 SetGrab(true); | 220 SetGrab(true); |
222 SetFocus(true); | 221 SetFocus(true); |
223 | 222 |
224 bool bUpPress = | 223 bool bUpPress = |
225 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(true)); | 224 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); |
226 bool bDnPress = | 225 bool bDnPress = |
227 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsButtonEnabled(false)); | 226 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); |
228 if (!bUpPress && !bDnPress) | 227 if (!bUpPress && !bDnPress) |
229 return; | 228 return; |
230 if (bUpPress) { | 229 if (bUpPress) { |
231 m_iButtonIndex = 0; | 230 m_iButtonIndex = 0; |
232 m_dwUpState = CFWL_PartState_Pressed; | 231 m_dwUpState = CFWL_PartState_Pressed; |
233 } | 232 } |
234 if (bDnPress) { | 233 if (bDnPress) { |
235 m_iButtonIndex = 1; | 234 m_iButtonIndex = 1; |
236 m_dwDnState = CFWL_PartState_Pressed; | 235 m_dwDnState = CFWL_PartState_Pressed; |
237 } | 236 } |
(...skipping 11 matching lines...) Expand all Loading... |
249 | 248 |
250 m_bLButtonDwn = false; | 249 m_bLButtonDwn = false; |
251 SetGrab(false); | 250 SetGrab(false); |
252 SetFocus(false); | 251 SetFocus(false); |
253 if (m_pTimerInfo) { | 252 if (m_pTimerInfo) { |
254 m_pTimerInfo->StopTimer(); | 253 m_pTimerInfo->StopTimer(); |
255 m_pTimerInfo = nullptr; | 254 m_pTimerInfo = nullptr; |
256 } | 255 } |
257 bool bRepaint = false; | 256 bool bRepaint = false; |
258 CFX_RectF rtInvalidate; | 257 CFX_RectF rtInvalidate; |
259 if (m_dwUpState == CFWL_PartState_Pressed && IsButtonEnabled(true)) { | 258 if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { |
260 m_dwUpState = CFWL_PartState_Normal; | 259 m_dwUpState = CFWL_PartState_Normal; |
261 bRepaint = true; | 260 bRepaint = true; |
262 rtInvalidate = m_rtUpButton; | 261 rtInvalidate = m_rtUpButton; |
263 } else if (m_dwDnState == CFWL_PartState_Pressed && IsButtonEnabled(false)) { | 262 } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { |
264 m_dwDnState = CFWL_PartState_Normal; | 263 m_dwDnState = CFWL_PartState_Normal; |
265 bRepaint = true; | 264 bRepaint = true; |
266 rtInvalidate = m_rtDnButton; | 265 rtInvalidate = m_rtDnButton; |
267 } | 266 } |
268 if (bRepaint) | 267 if (bRepaint) |
269 Repaint(&rtInvalidate); | 268 Repaint(&rtInvalidate); |
270 } | 269 } |
271 | 270 |
272 void CFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { | 271 void CFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { |
273 if (m_bLButtonDwn) | 272 if (m_bLButtonDwn) |
274 return; | 273 return; |
275 | 274 |
276 bool bRepaint = false; | 275 bool bRepaint = false; |
277 CFX_RectF rtInvlidate; | 276 CFX_RectF rtInvlidate; |
278 rtInvlidate.Reset(); | 277 rtInvlidate.Reset(); |
279 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { | 278 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { |
280 if (IsButtonEnabled(true)) { | 279 if (IsUpButtonEnabled()) { |
281 if (m_dwUpState == CFWL_PartState_Hovered) { | 280 if (m_dwUpState == CFWL_PartState_Hovered) { |
282 m_dwUpState = CFWL_PartState_Hovered; | 281 m_dwUpState = CFWL_PartState_Hovered; |
283 bRepaint = true; | 282 bRepaint = true; |
284 rtInvlidate = m_rtUpButton; | 283 rtInvlidate = m_rtUpButton; |
285 } | 284 } |
286 if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) { | 285 if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) { |
287 m_dwDnState = CFWL_PartState_Normal; | 286 m_dwDnState = CFWL_PartState_Normal; |
288 if (bRepaint) | 287 if (bRepaint) |
289 rtInvlidate.Union(m_rtDnButton); | 288 rtInvlidate.Union(m_rtDnButton); |
290 else | 289 else |
291 rtInvlidate = m_rtDnButton; | 290 rtInvlidate = m_rtDnButton; |
292 | 291 |
293 bRepaint = true; | 292 bRepaint = true; |
294 } | 293 } |
295 } | 294 } |
296 if (!IsButtonEnabled(false)) | 295 if (!IsDownButtonEnabled()) |
297 EnableButton(false, false); | 296 DisableButton(); |
298 | 297 |
299 } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { | 298 } else if (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy)) { |
300 if (IsButtonEnabled(false)) { | 299 if (IsDownButtonEnabled()) { |
301 if (m_dwDnState != CFWL_PartState_Hovered) { | 300 if (m_dwDnState != CFWL_PartState_Hovered) { |
302 m_dwDnState = CFWL_PartState_Hovered; | 301 m_dwDnState = CFWL_PartState_Hovered; |
303 bRepaint = true; | 302 bRepaint = true; |
304 rtInvlidate = m_rtDnButton; | 303 rtInvlidate = m_rtDnButton; |
305 } | 304 } |
306 if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) { | 305 if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) { |
307 m_dwUpState = CFWL_PartState_Normal; | 306 m_dwUpState = CFWL_PartState_Normal; |
308 if (bRepaint) | 307 if (bRepaint) |
309 rtInvlidate.Union(m_rtUpButton); | 308 rtInvlidate.Union(m_rtUpButton); |
310 else | 309 else |
311 rtInvlidate = m_rtUpButton; | 310 rtInvlidate = m_rtUpButton; |
312 bRepaint = true; | 311 bRepaint = true; |
313 } | 312 } |
314 } | 313 } |
315 } else if (m_dwUpState != CFWL_PartState_Normal || | 314 } else if (m_dwUpState != CFWL_PartState_Normal || |
316 m_dwDnState != CFWL_PartState_Normal) { | 315 m_dwDnState != CFWL_PartState_Normal) { |
(...skipping 12 matching lines...) Expand all Loading... |
329 bRepaint = true; | 328 bRepaint = true; |
330 } | 329 } |
331 } | 330 } |
332 if (bRepaint) | 331 if (bRepaint) |
333 Repaint(&rtInvlidate); | 332 Repaint(&rtInvlidate); |
334 } | 333 } |
335 | 334 |
336 void CFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { | 335 void CFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { |
337 if (!pMsg) | 336 if (!pMsg) |
338 return; | 337 return; |
339 if (m_dwUpState != CFWL_PartState_Normal && IsButtonEnabled(true)) | 338 if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) |
340 m_dwUpState = CFWL_PartState_Normal; | 339 m_dwUpState = CFWL_PartState_Normal; |
341 if (m_dwDnState != CFWL_PartState_Normal && IsButtonEnabled(false)) | 340 if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) |
342 m_dwDnState = CFWL_PartState_Normal; | 341 m_dwDnState = CFWL_PartState_Normal; |
343 | 342 |
344 Repaint(&m_rtClient); | 343 Repaint(&m_rtClient); |
345 } | 344 } |
346 | 345 |
347 void CFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { | 346 void CFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { |
348 bool bUp = | 347 bool bUp = |
349 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; | 348 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; |
350 bool bDown = | 349 bool bDown = |
351 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; | 350 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; |
352 if (!bUp && !bDown) | 351 if (!bUp && !bDown) |
353 return; | 352 return; |
354 | 353 |
355 bool bUpEnable = IsButtonEnabled(true); | 354 bool bUpEnable = IsUpButtonEnabled(); |
356 bool bDownEnable = IsButtonEnabled(false); | 355 bool bDownEnable = IsDownButtonEnabled(); |
357 if (!bUpEnable && !bDownEnable) | 356 if (!bUpEnable && !bDownEnable) |
358 return; | 357 return; |
359 | 358 |
360 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); | 359 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); |
361 DispatchEvent(&wmPosChanged); | 360 DispatchEvent(&wmPosChanged); |
362 | 361 |
363 Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); | 362 Repaint(bUpEnable ? &m_rtUpButton : &m_rtDnButton); |
364 } | 363 } |
365 | 364 |
366 CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) | 365 CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip) |
367 : CFWL_Timer(pToolTip) {} | 366 : CFWL_Timer(pToolTip) {} |
368 | 367 |
369 void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { | 368 void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { |
370 CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget); | 369 CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget); |
371 | 370 |
372 if (!pButton->m_pTimerInfo) | 371 if (!pButton->m_pTimerInfo) |
373 return; | 372 return; |
374 | 373 |
375 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); | 374 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); |
376 pButton->DispatchEvent(&wmPosChanged); | 375 pButton->DispatchEvent(&wmPosChanged); |
377 } | 376 } |
OLD | NEW |