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/ifwl_spinbutton.h" | 7 #include "xfa/fwl/core/ifwl_spinbutton.h" |
8 | 8 |
9 #include "xfa/fwl/core/cfwl_message.h" | 9 #include "xfa/fwl/core/cfwl_message.h" |
10 #include "xfa/fwl/core/cfwl_themebackground.h" | 10 #include "xfa/fwl/core/cfwl_themebackground.h" |
11 #include "xfa/fwl/core/cfwl_widgetimpproperties.h" | 11 #include "xfa/fwl/core/cfwl_widgetimpproperties.h" |
12 #include "xfa/fwl/core/fwl_noteimp.h" | 12 #include "xfa/fwl/core/fwl_noteimp.h" |
13 #include "xfa/fwl/core/ifwl_spinbutton.h" | 13 #include "xfa/fwl/core/ifwl_spinbutton.h" |
14 #include "xfa/fwl/core/ifwl_themeprovider.h" | 14 #include "xfa/fwl/core/ifwl_themeprovider.h" |
15 #include "xfa/fwl/core/ifwl_themeprovider.h" | 15 #include "xfa/fwl/core/ifwl_themeprovider.h" |
16 #include "xfa/fwl/core/ifwl_timer.h" | 16 #include "xfa/fwl/core/ifwl_timer.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 const int kMinWidth = 18; | 20 const int kMinWidth = 18; |
21 const int kMinHeight = 32; | 21 const int kMinHeight = 32; |
22 const int kElapseTime = 200; | 22 const int kElapseTime = 200; |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 IFWL_SpinButton::IFWL_SpinButton(const CFWL_WidgetImpProperties& properties) | 26 IFWL_SpinButton::IFWL_SpinButton(const IFWL_App* app, |
27 : IFWL_Widget(properties, nullptr), | 27 const CFWL_WidgetImpProperties& properties) |
| 28 : IFWL_Widget(app, properties, nullptr), |
28 m_dwUpState(CFWL_PartState_Normal), | 29 m_dwUpState(CFWL_PartState_Normal), |
29 m_dwDnState(CFWL_PartState_Normal), | 30 m_dwDnState(CFWL_PartState_Normal), |
30 m_iButtonIndex(0), | 31 m_iButtonIndex(0), |
31 m_bLButtonDwn(FALSE), | 32 m_bLButtonDwn(FALSE), |
32 m_pTimerInfo(nullptr) { | 33 m_pTimerInfo(nullptr), |
| 34 m_Timer(this) { |
33 m_rtClient.Reset(); | 35 m_rtClient.Reset(); |
34 m_rtUpButton.Reset(); | 36 m_rtUpButton.Reset(); |
35 m_rtDnButton.Reset(); | 37 m_rtDnButton.Reset(); |
36 m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; | 38 m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; |
37 } | 39 } |
38 | 40 |
39 IFWL_SpinButton::~IFWL_SpinButton() {} | 41 IFWL_SpinButton::~IFWL_SpinButton() {} |
40 | 42 |
41 FWL_Type IFWL_SpinButton::GetClassID() const { | 43 void IFWL_SpinButton::Initialize() { |
42 return FWL_Type::SpinButton; | 44 IFWL_Widget::Initialize(); |
43 } | |
44 | |
45 FWL_Error IFWL_SpinButton::Initialize() { | |
46 if (IFWL_Widget::Initialize() != FWL_Error::Succeeded) | |
47 return FWL_Error::Indefinite; | |
48 | |
49 m_pDelegate = new CFWL_SpinButtonImpDelegate(this); | 45 m_pDelegate = new CFWL_SpinButtonImpDelegate(this); |
50 return FWL_Error::Succeeded; | |
51 } | 46 } |
52 | 47 |
53 void IFWL_SpinButton::Finalize() { | 48 void IFWL_SpinButton::Finalize() { |
54 delete m_pDelegate; | 49 delete m_pDelegate; |
55 m_pDelegate = nullptr; | 50 m_pDelegate = nullptr; |
56 IFWL_Widget::Finalize(); | 51 IFWL_Widget::Finalize(); |
57 } | 52 } |
58 | 53 |
| 54 FWL_Type IFWL_SpinButton::GetClassID() const { |
| 55 return FWL_Type::SpinButton; |
| 56 } |
| 57 |
59 FWL_Error IFWL_SpinButton::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 58 FWL_Error IFWL_SpinButton::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { |
60 if (bAutoSize) { | 59 if (bAutoSize) { |
61 rect.Set(0, 0, kMinWidth, kMinHeight); | 60 rect.Set(0, 0, kMinWidth, kMinHeight); |
62 IFWL_Widget::GetWidgetRect(rect, TRUE); | 61 IFWL_Widget::GetWidgetRect(rect, TRUE); |
63 } else { | 62 } else { |
64 rect = m_pProperties->m_rtWidget; | 63 rect = m_pProperties->m_rtWidget; |
65 } | 64 } |
66 return FWL_Error::Succeeded; | 65 return FWL_Error::Succeeded; |
67 } | 66 } |
68 | 67 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 115 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
117 } | 116 } |
118 if (HasEdge()) { | 117 if (HasEdge()) { |
119 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 118 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
120 } | 119 } |
121 DrawUpButton(pGraphics, pTheme, pMatrix); | 120 DrawUpButton(pGraphics, pTheme, pMatrix); |
122 DrawDownButton(pGraphics, pTheme, pMatrix); | 121 DrawDownButton(pGraphics, pTheme, pMatrix); |
123 return FWL_Error::Succeeded; | 122 return FWL_Error::Succeeded; |
124 } | 123 } |
125 | 124 |
126 void IFWL_SpinButton::Run(IFWL_TimerInfo* pTimerInfo) { | |
127 if (!m_pTimerInfo) | |
128 return; | |
129 | |
130 CFWL_EvtSpbClick wmPosChanged; | |
131 wmPosChanged.m_pSrcTarget = this; | |
132 wmPosChanged.m_bUp = m_iButtonIndex == 0; | |
133 DispatchEvent(&wmPosChanged); | |
134 } | |
135 | |
136 FWL_Error IFWL_SpinButton::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { | 125 FWL_Error IFWL_SpinButton::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { |
137 if (bUp) { | 126 if (bUp) { |
138 if (bEnable) { | 127 if (bEnable) { |
139 m_dwUpState = CFWL_PartState_Normal; | 128 m_dwUpState = CFWL_PartState_Normal; |
140 } else { | 129 } else { |
141 m_dwUpState = CFWL_PartState_Disabled; | 130 m_dwUpState = CFWL_PartState_Disabled; |
142 } | 131 } |
143 } else { | 132 } else { |
144 if (bEnable) { | 133 if (bEnable) { |
145 m_dwDnState = CFWL_PartState_Normal; | 134 m_dwDnState = CFWL_PartState_Normal; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 if (bDnPress) { | 265 if (bDnPress) { |
277 m_pOwner->m_iButtonIndex = 1; | 266 m_pOwner->m_iButtonIndex = 1; |
278 m_pOwner->m_dwDnState = CFWL_PartState_Pressed; | 267 m_pOwner->m_dwDnState = CFWL_PartState_Pressed; |
279 } | 268 } |
280 CFWL_EvtSpbClick wmPosChanged; | 269 CFWL_EvtSpbClick wmPosChanged; |
281 wmPosChanged.m_pSrcTarget = m_pOwner; | 270 wmPosChanged.m_pSrcTarget = m_pOwner; |
282 wmPosChanged.m_bUp = bUpPress; | 271 wmPosChanged.m_bUp = bUpPress; |
283 m_pOwner->DispatchEvent(&wmPosChanged); | 272 m_pOwner->DispatchEvent(&wmPosChanged); |
284 m_pOwner->Repaint(bUpPress ? &m_pOwner->m_rtUpButton | 273 m_pOwner->Repaint(bUpPress ? &m_pOwner->m_rtUpButton |
285 : &m_pOwner->m_rtDnButton); | 274 : &m_pOwner->m_rtDnButton); |
286 m_pOwner->m_pTimerInfo = m_pOwner->StartTimer(kElapseTime, true); | 275 m_pOwner->m_pTimerInfo = m_pOwner->m_Timer.StartTimer(kElapseTime, true); |
287 } | 276 } |
288 | 277 |
289 void CFWL_SpinButtonImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 278 void CFWL_SpinButtonImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
290 if (m_pOwner->m_pProperties->m_dwStates & CFWL_PartState_Disabled) { | 279 if (m_pOwner->m_pProperties->m_dwStates & CFWL_PartState_Disabled) { |
291 return; | 280 return; |
292 } | 281 } |
293 m_pOwner->m_bLButtonDwn = FALSE; | 282 m_pOwner->m_bLButtonDwn = FALSE; |
294 m_pOwner->SetGrab(FALSE); | 283 m_pOwner->SetGrab(FALSE); |
295 m_pOwner->SetFocus(FALSE); | 284 m_pOwner->SetFocus(FALSE); |
296 if (m_pOwner->m_pTimerInfo) { | 285 if (m_pOwner->m_pTimerInfo) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 if (!bUpEnable && !bDownEnable) { | 403 if (!bUpEnable && !bDownEnable) { |
415 return; | 404 return; |
416 } | 405 } |
417 CFWL_EvtSpbClick wmPosChanged; | 406 CFWL_EvtSpbClick wmPosChanged; |
418 wmPosChanged.m_pSrcTarget = m_pOwner; | 407 wmPosChanged.m_pSrcTarget = m_pOwner; |
419 wmPosChanged.m_bUp = bUpEnable; | 408 wmPosChanged.m_bUp = bUpEnable; |
420 m_pOwner->DispatchEvent(&wmPosChanged); | 409 m_pOwner->DispatchEvent(&wmPosChanged); |
421 m_pOwner->Repaint(bUpEnable ? &m_pOwner->m_rtUpButton | 410 m_pOwner->Repaint(bUpEnable ? &m_pOwner->m_rtUpButton |
422 : &m_pOwner->m_rtDnButton); | 411 : &m_pOwner->m_rtDnButton); |
423 } | 412 } |
| 413 |
| 414 IFWL_SpinButton::Timer::Timer(IFWL_SpinButton* pToolTip) |
| 415 : IFWL_Timer(pToolTip) {} |
| 416 |
| 417 void IFWL_SpinButton::Timer::Run(IFWL_TimerInfo* pTimerInfo) { |
| 418 IFWL_SpinButton* pButton = static_cast<IFWL_SpinButton*>(m_pWidget); |
| 419 |
| 420 if (!pButton->m_pTimerInfo) |
| 421 return; |
| 422 |
| 423 CFWL_EvtSpbClick wmPosChanged; |
| 424 wmPosChanged.m_pSrcTarget = pButton; |
| 425 wmPosChanged.m_bUp = pButton->m_iButtonIndex == 0; |
| 426 pButton->DispatchEvent(&wmPosChanged); |
| 427 } |
OLD | NEW |