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/basewidget/fwl_spinbuttonimp.h" | 7 #include "xfa/fwl/basewidget/fwl_spinbuttonimp.h" |
8 | 8 |
9 #include "xfa/fwl/basewidget/ifwl_spinbutton.h" | 9 #include "xfa/fwl/basewidget/ifwl_spinbutton.h" |
10 #include "xfa/fwl/core/cfwl_message.h" | 10 #include "xfa/fwl/core/cfwl_message.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const CFWL_WidgetImpProperties& properties, | 29 const CFWL_WidgetImpProperties& properties, |
30 IFWL_Widget* pOuter) { | 30 IFWL_Widget* pOuter) { |
31 IFWL_SpinButton* pSpinButton = new IFWL_SpinButton; | 31 IFWL_SpinButton* pSpinButton = new IFWL_SpinButton; |
32 CFWL_SpinButtonImp* pSpinButtonImpl = | 32 CFWL_SpinButtonImp* pSpinButtonImpl = |
33 new CFWL_SpinButtonImp(properties, nullptr); | 33 new CFWL_SpinButtonImp(properties, nullptr); |
34 pSpinButton->SetImpl(pSpinButtonImpl); | 34 pSpinButton->SetImpl(pSpinButtonImpl); |
35 pSpinButtonImpl->SetInterface(pSpinButton); | 35 pSpinButtonImpl->SetInterface(pSpinButton); |
36 return pSpinButton; | 36 return pSpinButton; |
37 } | 37 } |
38 IFWL_SpinButton::IFWL_SpinButton() {} | 38 IFWL_SpinButton::IFWL_SpinButton() {} |
39 FWL_ERR IFWL_SpinButton::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { | 39 FWL_Error IFWL_SpinButton::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { |
40 return static_cast<CFWL_SpinButtonImp*>(GetImpl()) | 40 return static_cast<CFWL_SpinButtonImp*>(GetImpl()) |
41 ->EnableButton(bEnable, bUp); | 41 ->EnableButton(bEnable, bUp); |
42 } | 42 } |
43 FX_BOOL IFWL_SpinButton::IsButtonEnable(FX_BOOL bUp) { | 43 FX_BOOL IFWL_SpinButton::IsButtonEnable(FX_BOOL bUp) { |
44 return static_cast<CFWL_SpinButtonImp*>(GetImpl())->IsButtonEnable(bUp); | 44 return static_cast<CFWL_SpinButtonImp*>(GetImpl())->IsButtonEnable(bUp); |
45 } | 45 } |
46 | 46 |
47 CFWL_SpinButtonImp::CFWL_SpinButtonImp( | 47 CFWL_SpinButtonImp::CFWL_SpinButtonImp( |
48 const CFWL_WidgetImpProperties& properties, | 48 const CFWL_WidgetImpProperties& properties, |
49 IFWL_Widget* pOuter) | 49 IFWL_Widget* pOuter) |
50 : CFWL_WidgetImp(properties, pOuter), | 50 : CFWL_WidgetImp(properties, pOuter), |
51 m_dwUpState(CFWL_PartState_Normal), | 51 m_dwUpState(CFWL_PartState_Normal), |
52 m_dwDnState(CFWL_PartState_Normal), | 52 m_dwDnState(CFWL_PartState_Normal), |
53 m_iButtonIndex(0), | 53 m_iButtonIndex(0), |
54 m_bLButtonDwn(FALSE), | 54 m_bLButtonDwn(FALSE), |
55 m_hTimer(NULL) { | 55 m_hTimer(NULL) { |
56 m_rtClient.Reset(); | 56 m_rtClient.Reset(); |
57 m_rtUpButton.Reset(); | 57 m_rtUpButton.Reset(); |
58 m_rtDnButton.Reset(); | 58 m_rtDnButton.Reset(); |
59 m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; | 59 m_pProperties->m_dwStyleExes |= FWL_STYLEEXE_SPB_Vert; |
60 } | 60 } |
61 CFWL_SpinButtonImp::~CFWL_SpinButtonImp() {} | 61 CFWL_SpinButtonImp::~CFWL_SpinButtonImp() {} |
62 FWL_ERR CFWL_SpinButtonImp::GetClassName(CFX_WideString& wsClass) const { | 62 FWL_Error CFWL_SpinButtonImp::GetClassName(CFX_WideString& wsClass) const { |
63 wsClass = FWL_CLASS_SpinButton; | 63 wsClass = FWL_CLASS_SpinButton; |
64 return FWL_ERR_Succeeded; | 64 return FWL_Error::Succeeded; |
65 } | 65 } |
66 uint32_t CFWL_SpinButtonImp::GetClassID() const { | 66 uint32_t CFWL_SpinButtonImp::GetClassID() const { |
67 return FWL_CLASSHASH_SpinButton; | 67 return FWL_CLASSHASH_SpinButton; |
68 } | 68 } |
69 FWL_ERR CFWL_SpinButtonImp::Initialize() { | 69 FWL_Error CFWL_SpinButtonImp::Initialize() { |
70 if (CFWL_WidgetImp::Initialize() != FWL_ERR_Succeeded) | 70 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) |
71 return FWL_ERR_Indefinite; | 71 return FWL_Error::Indefinite; |
72 m_pDelegate = new CFWL_SpinButtonImpDelegate(this); | 72 m_pDelegate = new CFWL_SpinButtonImpDelegate(this); |
73 return FWL_ERR_Succeeded; | 73 return FWL_Error::Succeeded; |
74 } | 74 } |
75 FWL_ERR CFWL_SpinButtonImp::Finalize() { | 75 FWL_Error CFWL_SpinButtonImp::Finalize() { |
76 delete m_pDelegate; | 76 delete m_pDelegate; |
77 m_pDelegate = nullptr; | 77 m_pDelegate = nullptr; |
78 return CFWL_WidgetImp::Finalize(); | 78 return CFWL_WidgetImp::Finalize(); |
79 } | 79 } |
80 FWL_ERR CFWL_SpinButtonImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | 80 FWL_Error CFWL_SpinButtonImp::GetWidgetRect(CFX_RectF& rect, |
| 81 FX_BOOL bAutoSize) { |
81 if (bAutoSize) { | 82 if (bAutoSize) { |
82 rect.Set(0, 0, kMinWidth, kMinHeight); | 83 rect.Set(0, 0, kMinWidth, kMinHeight); |
83 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | 84 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); |
84 } else { | 85 } else { |
85 rect = m_pProperties->m_rtWidget; | 86 rect = m_pProperties->m_rtWidget; |
86 } | 87 } |
87 return FWL_ERR_Succeeded; | 88 return FWL_Error::Succeeded; |
88 } | 89 } |
89 FWL_ERR CFWL_SpinButtonImp::Update() { | 90 FWL_Error CFWL_SpinButtonImp::Update() { |
90 if (IsLocked()) { | 91 if (IsLocked()) { |
91 return FWL_ERR_Indefinite; | 92 return FWL_Error::Indefinite; |
92 } | 93 } |
93 GetClientRect(m_rtClient); | 94 GetClientRect(m_rtClient); |
94 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { | 95 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXE_SPB_Vert) { |
95 m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, | 96 m_rtUpButton.Set(m_rtClient.top, m_rtClient.left, m_rtClient.width, |
96 m_rtClient.height / 2); | 97 m_rtClient.height / 2); |
97 m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, | 98 m_rtDnButton.Set(m_rtClient.left, m_rtClient.top + m_rtClient.height / 2, |
98 m_rtClient.width, m_rtClient.height / 2); | 99 m_rtClient.width, m_rtClient.height / 2); |
99 } else { | 100 } else { |
100 m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, | 101 m_rtUpButton.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width / 2, |
101 m_rtClient.height); | 102 m_rtClient.height); |
102 m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, | 103 m_rtDnButton.Set(m_rtClient.left + m_rtClient.width / 2, m_rtClient.top, |
103 m_rtClient.width / 2, m_rtClient.height); | 104 m_rtClient.width / 2, m_rtClient.height); |
104 } | 105 } |
105 return FWL_ERR_Succeeded; | 106 return FWL_Error::Succeeded; |
106 } | 107 } |
107 uint32_t CFWL_SpinButtonImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 108 uint32_t CFWL_SpinButtonImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
108 if (m_rtClient.Contains(fx, fy)) { | 109 if (m_rtClient.Contains(fx, fy)) { |
109 return FWL_WGTHITTEST_Client; | 110 return FWL_WGTHITTEST_Client; |
110 } | 111 } |
111 if (HasBorder() && (m_rtClient.Contains(fx, fy))) { | 112 if (HasBorder() && (m_rtClient.Contains(fx, fy))) { |
112 return FWL_WGTHITTEST_Border; | 113 return FWL_WGTHITTEST_Border; |
113 } | 114 } |
114 if (HasEdge()) { | 115 if (HasEdge()) { |
115 CFX_RectF rtEdge; | 116 CFX_RectF rtEdge; |
116 GetEdgeRect(rtEdge); | 117 GetEdgeRect(rtEdge); |
117 if (rtEdge.Contains(fx, fy)) { | 118 if (rtEdge.Contains(fx, fy)) { |
118 return FWL_WGTHITTEST_Left; | 119 return FWL_WGTHITTEST_Left; |
119 } | 120 } |
120 } | 121 } |
121 if (m_rtUpButton.Contains(fx, fy)) { | 122 if (m_rtUpButton.Contains(fx, fy)) { |
122 return FWL_WGTHITTEST_SPB_UpButton; | 123 return FWL_WGTHITTEST_SPB_UpButton; |
123 } | 124 } |
124 if (m_rtDnButton.Contains(fx, fy)) { | 125 if (m_rtDnButton.Contains(fx, fy)) { |
125 return FWL_WGTHITTEST_SPB_DownButton; | 126 return FWL_WGTHITTEST_SPB_DownButton; |
126 } | 127 } |
127 return FWL_WGTHITTEST_Unknown; | 128 return FWL_WGTHITTEST_Unknown; |
128 } | 129 } |
129 FWL_ERR CFWL_SpinButtonImp::DrawWidget(CFX_Graphics* pGraphics, | 130 FWL_Error CFWL_SpinButtonImp::DrawWidget(CFX_Graphics* pGraphics, |
130 const CFX_Matrix* pMatrix) { | 131 const CFX_Matrix* pMatrix) { |
131 if (!pGraphics) | 132 if (!pGraphics) |
132 return FWL_ERR_Indefinite; | 133 return FWL_Error::Indefinite; |
133 CFX_RectF rtClip(m_rtClient); | 134 CFX_RectF rtClip(m_rtClient); |
134 if (pMatrix != NULL) { | 135 if (pMatrix != NULL) { |
135 pMatrix->TransformRect(rtClip); | 136 pMatrix->TransformRect(rtClip); |
136 } | 137 } |
137 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); | 138 IFWL_ThemeProvider* pTheme = GetAvailableTheme(); |
138 if (HasBorder()) { | 139 if (HasBorder()) { |
139 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 140 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
140 } | 141 } |
141 if (HasEdge()) { | 142 if (HasEdge()) { |
142 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 143 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
143 } | 144 } |
144 DrawUpButton(pGraphics, pTheme, pMatrix); | 145 DrawUpButton(pGraphics, pTheme, pMatrix); |
145 DrawDownButton(pGraphics, pTheme, pMatrix); | 146 DrawDownButton(pGraphics, pTheme, pMatrix); |
146 return FWL_ERR_Succeeded; | 147 return FWL_Error::Succeeded; |
147 } | 148 } |
148 int32_t CFWL_SpinButtonImp::Run(FWL_HTIMER hTimer) { | 149 int32_t CFWL_SpinButtonImp::Run(FWL_HTIMER hTimer) { |
149 if (m_hTimer) { | 150 if (m_hTimer) { |
150 CFWL_EvtSpbClick wmPosChanged; | 151 CFWL_EvtSpbClick wmPosChanged; |
151 wmPosChanged.m_pSrcTarget = m_pInterface; | 152 wmPosChanged.m_pSrcTarget = m_pInterface; |
152 wmPosChanged.m_bUp = m_iButtonIndex == 0; | 153 wmPosChanged.m_bUp = m_iButtonIndex == 0; |
153 DispatchEvent(&wmPosChanged); | 154 DispatchEvent(&wmPosChanged); |
154 } | 155 } |
155 return 1; | 156 return 1; |
156 } | 157 } |
157 FWL_ERR CFWL_SpinButtonImp::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { | 158 FWL_Error CFWL_SpinButtonImp::EnableButton(FX_BOOL bEnable, FX_BOOL bUp) { |
158 if (bUp) { | 159 if (bUp) { |
159 if (bEnable) { | 160 if (bEnable) { |
160 m_dwUpState = CFWL_PartState_Normal; | 161 m_dwUpState = CFWL_PartState_Normal; |
161 } else { | 162 } else { |
162 m_dwUpState = CFWL_PartState_Disabled; | 163 m_dwUpState = CFWL_PartState_Disabled; |
163 } | 164 } |
164 } else { | 165 } else { |
165 if (bEnable) { | 166 if (bEnable) { |
166 m_dwDnState = CFWL_PartState_Normal; | 167 m_dwDnState = CFWL_PartState_Normal; |
167 } else { | 168 } else { |
168 m_dwDnState = CFWL_PartState_Disabled; | 169 m_dwDnState = CFWL_PartState_Disabled; |
169 } | 170 } |
170 } | 171 } |
171 return FWL_ERR_Succeeded; | 172 return FWL_Error::Succeeded; |
172 } | 173 } |
173 FX_BOOL CFWL_SpinButtonImp::IsButtonEnable(FX_BOOL bUp) { | 174 FX_BOOL CFWL_SpinButtonImp::IsButtonEnable(FX_BOOL bUp) { |
174 if (bUp) { | 175 if (bUp) { |
175 return (m_dwUpState != CFWL_PartState_Disabled); | 176 return (m_dwUpState != CFWL_PartState_Disabled); |
176 } | 177 } |
177 return (m_dwDnState != CFWL_PartState_Disabled); | 178 return (m_dwDnState != CFWL_PartState_Disabled); |
178 } | 179 } |
179 void CFWL_SpinButtonImp::DrawUpButton(CFX_Graphics* pGraphics, | 180 void CFWL_SpinButtonImp::DrawUpButton(CFX_Graphics* pGraphics, |
180 IFWL_ThemeProvider* pTheme, | 181 IFWL_ThemeProvider* pTheme, |
181 const CFX_Matrix* pMatrix) { | 182 const CFX_Matrix* pMatrix) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } | 257 } |
257 default: { | 258 default: { |
258 iRet = 0; | 259 iRet = 0; |
259 break; | 260 break; |
260 } | 261 } |
261 } | 262 } |
262 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 263 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); |
263 return iRet; | 264 return iRet; |
264 } | 265 } |
265 | 266 |
266 FWL_ERR CFWL_SpinButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 267 FWL_Error CFWL_SpinButtonImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { |
267 return FWL_ERR_Succeeded; | 268 return FWL_Error::Succeeded; |
268 } | 269 } |
269 FWL_ERR CFWL_SpinButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 270 FWL_Error CFWL_SpinButtonImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, |
270 const CFX_Matrix* pMatrix) { | 271 const CFX_Matrix* pMatrix) { |
271 return m_pOwner->DrawWidget(pGraphics, pMatrix); | 272 return m_pOwner->DrawWidget(pGraphics, pMatrix); |
272 } | 273 } |
273 void CFWL_SpinButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 274 void CFWL_SpinButtonImpDelegate::OnFocusChanged(CFWL_Message* pMsg, |
274 FX_BOOL bSet) { | 275 FX_BOOL bSet) { |
275 if (bSet) { | 276 if (bSet) { |
276 m_pOwner->m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 277 m_pOwner->m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
277 } else { | 278 } else { |
278 m_pOwner->m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 279 m_pOwner->m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
279 } | 280 } |
280 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 281 m_pOwner->Repaint(&m_pOwner->m_rtClient); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 if (!bUpEnable && !bDownEnable) { | 434 if (!bUpEnable && !bDownEnable) { |
434 return; | 435 return; |
435 } | 436 } |
436 CFWL_EvtSpbClick wmPosChanged; | 437 CFWL_EvtSpbClick wmPosChanged; |
437 wmPosChanged.m_pSrcTarget = m_pOwner->m_pInterface; | 438 wmPosChanged.m_pSrcTarget = m_pOwner->m_pInterface; |
438 wmPosChanged.m_bUp = bUpEnable; | 439 wmPosChanged.m_bUp = bUpEnable; |
439 m_pOwner->DispatchEvent(&wmPosChanged); | 440 m_pOwner->DispatchEvent(&wmPosChanged); |
440 m_pOwner->Repaint(bUpEnable ? &m_pOwner->m_rtUpButton | 441 m_pOwner->Repaint(bUpEnable ? &m_pOwner->m_rtUpButton |
441 : &m_pOwner->m_rtDnButton); | 442 : &m_pOwner->m_rtDnButton); |
442 } | 443 } |
OLD | NEW |