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/cfwl_spinbutton.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "third_party/base/ptr_util.h" | 12 #include "third_party/base/ptr_util.h" |
13 #include "xfa/fwl/core/cfwl_event.h" | 13 #include "xfa/fwl/cfwl_event.h" |
14 #include "xfa/fwl/core/cfwl_msgkey.h" | 14 #include "xfa/fwl/cfwl_messagekey.h" |
15 #include "xfa/fwl/core/cfwl_msgmouse.h" | 15 #include "xfa/fwl/cfwl_messagemouse.h" |
16 #include "xfa/fwl/core/cfwl_notedriver.h" | 16 #include "xfa/fwl/cfwl_notedriver.h" |
17 #include "xfa/fwl/core/cfwl_themebackground.h" | 17 #include "xfa/fwl/cfwl_themebackground.h" |
18 #include "xfa/fwl/core/cfwl_timerinfo.h" | 18 #include "xfa/fwl/cfwl_timerinfo.h" |
19 #include "xfa/fwl/core/cfwl_widgetproperties.h" | 19 #include "xfa/fwl/cfwl_widgetproperties.h" |
20 #include "xfa/fwl/core/ifwl_themeprovider.h" | 20 #include "xfa/fwl/ifwl_themeprovider.h" |
21 | 21 |
22 namespace { | 22 namespace { |
23 const int kElapseTime = 200; | 23 const int kElapseTime = 200; |
24 | 24 |
25 } // namespace | 25 } // namespace |
26 | 26 |
27 CFWL_SpinButton::CFWL_SpinButton( | 27 CFWL_SpinButton::CFWL_SpinButton( |
28 const CFWL_App* app, | 28 const CFWL_App* app, |
29 std::unique_ptr<CFWL_WidgetProperties> properties) | 29 std::unique_ptr<CFWL_WidgetProperties> properties) |
30 : CFWL_Widget(app, std::move(properties), nullptr), | 30 : CFWL_Widget(app, std::move(properties), nullptr), |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 switch (pMessage->GetType()) { | 150 switch (pMessage->GetType()) { |
151 case CFWL_Message::Type::SetFocus: { | 151 case CFWL_Message::Type::SetFocus: { |
152 OnFocusChanged(pMessage, true); | 152 OnFocusChanged(pMessage, true); |
153 break; | 153 break; |
154 } | 154 } |
155 case CFWL_Message::Type::KillFocus: { | 155 case CFWL_Message::Type::KillFocus: { |
156 OnFocusChanged(pMessage, false); | 156 OnFocusChanged(pMessage, false); |
157 break; | 157 break; |
158 } | 158 } |
159 case CFWL_Message::Type::Mouse: { | 159 case CFWL_Message::Type::Mouse: { |
160 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 160 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
161 switch (pMsg->m_dwCmd) { | 161 switch (pMsg->m_dwCmd) { |
162 case FWL_MouseCommand::LeftButtonDown: | 162 case FWL_MouseCommand::LeftButtonDown: |
163 OnLButtonDown(pMsg); | 163 OnLButtonDown(pMsg); |
164 break; | 164 break; |
165 case FWL_MouseCommand::LeftButtonUp: | 165 case FWL_MouseCommand::LeftButtonUp: |
166 OnLButtonUp(pMsg); | 166 OnLButtonUp(pMsg); |
167 break; | 167 break; |
168 case FWL_MouseCommand::Move: | 168 case FWL_MouseCommand::Move: |
169 OnMouseMove(pMsg); | 169 OnMouseMove(pMsg); |
170 break; | 170 break; |
171 case FWL_MouseCommand::Leave: | 171 case FWL_MouseCommand::Leave: |
172 OnMouseLeave(pMsg); | 172 OnMouseLeave(pMsg); |
173 break; | 173 break; |
174 default: | 174 default: |
175 break; | 175 break; |
176 } | 176 } |
177 break; | 177 break; |
178 } | 178 } |
179 case CFWL_Message::Type::Key: { | 179 case CFWL_Message::Type::Key: { |
180 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 180 CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage); |
181 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 181 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
182 OnKeyDown(pKey); | 182 OnKeyDown(pKey); |
183 break; | 183 break; |
184 } | 184 } |
185 default: | 185 default: |
186 break; | 186 break; |
187 } | 187 } |
188 CFWL_Widget::OnProcessMessage(pMessage); | 188 CFWL_Widget::OnProcessMessage(pMessage); |
189 } | 189 } |
190 | 190 |
191 void CFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, | 191 void CFWL_SpinButton::OnDrawWidget(CFX_Graphics* pGraphics, |
192 const CFX_Matrix* pMatrix) { | 192 const CFX_Matrix* pMatrix) { |
193 DrawWidget(pGraphics, pMatrix); | 193 DrawWidget(pGraphics, pMatrix); |
194 } | 194 } |
195 | 195 |
196 void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { | 196 void CFWL_SpinButton::OnFocusChanged(CFWL_Message* pMsg, bool bSet) { |
197 if (bSet) | 197 if (bSet) |
198 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); | 198 m_pProperties->m_dwStates |= (FWL_WGTSTATE_Focused); |
199 else | 199 else |
200 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); | 200 m_pProperties->m_dwStates &= ~(FWL_WGTSTATE_Focused); |
201 | 201 |
202 Repaint(&m_rtClient); | 202 Repaint(&m_rtClient); |
203 } | 203 } |
204 | 204 |
205 void CFWL_SpinButton::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 205 void CFWL_SpinButton::OnLButtonDown(CFWL_MessageMouse* pMsg) { |
206 m_bLButtonDwn = true; | 206 m_bLButtonDwn = true; |
207 SetGrab(true); | 207 SetGrab(true); |
208 SetFocus(true); | 208 SetFocus(true); |
209 | 209 |
210 bool bUpPress = | 210 bool bUpPress = |
211 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); | 211 (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsUpButtonEnabled()); |
212 bool bDnPress = | 212 bool bDnPress = |
213 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); | 213 (m_rtDnButton.Contains(pMsg->m_fx, pMsg->m_fy) && IsDownButtonEnabled()); |
214 if (!bUpPress && !bDnPress) | 214 if (!bUpPress && !bDnPress) |
215 return; | 215 return; |
216 if (bUpPress) { | 216 if (bUpPress) { |
217 m_iButtonIndex = 0; | 217 m_iButtonIndex = 0; |
218 m_dwUpState = CFWL_PartState_Pressed; | 218 m_dwUpState = CFWL_PartState_Pressed; |
219 } | 219 } |
220 if (bDnPress) { | 220 if (bDnPress) { |
221 m_iButtonIndex = 1; | 221 m_iButtonIndex = 1; |
222 m_dwDnState = CFWL_PartState_Pressed; | 222 m_dwDnState = CFWL_PartState_Pressed; |
223 } | 223 } |
224 | 224 |
225 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); | 225 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this); |
226 DispatchEvent(&wmPosChanged); | 226 DispatchEvent(&wmPosChanged); |
227 | 227 |
228 Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); | 228 Repaint(bUpPress ? &m_rtUpButton : &m_rtDnButton); |
229 m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); | 229 m_pTimerInfo = m_Timer.StartTimer(kElapseTime, true); |
230 } | 230 } |
231 | 231 |
232 void CFWL_SpinButton::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 232 void CFWL_SpinButton::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
233 if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) | 233 if (m_pProperties->m_dwStates & CFWL_PartState_Disabled) |
234 return; | 234 return; |
235 | 235 |
236 m_bLButtonDwn = false; | 236 m_bLButtonDwn = false; |
237 SetGrab(false); | 237 SetGrab(false); |
238 SetFocus(false); | 238 SetFocus(false); |
239 if (m_pTimerInfo) { | 239 if (m_pTimerInfo) { |
240 m_pTimerInfo->StopTimer(); | 240 m_pTimerInfo->StopTimer(); |
241 m_pTimerInfo = nullptr; | 241 m_pTimerInfo = nullptr; |
242 } | 242 } |
243 bool bRepaint = false; | 243 bool bRepaint = false; |
244 CFX_RectF rtInvalidate; | 244 CFX_RectF rtInvalidate; |
245 if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { | 245 if (m_dwUpState == CFWL_PartState_Pressed && IsUpButtonEnabled()) { |
246 m_dwUpState = CFWL_PartState_Normal; | 246 m_dwUpState = CFWL_PartState_Normal; |
247 bRepaint = true; | 247 bRepaint = true; |
248 rtInvalidate = m_rtUpButton; | 248 rtInvalidate = m_rtUpButton; |
249 } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { | 249 } else if (m_dwDnState == CFWL_PartState_Pressed && IsDownButtonEnabled()) { |
250 m_dwDnState = CFWL_PartState_Normal; | 250 m_dwDnState = CFWL_PartState_Normal; |
251 bRepaint = true; | 251 bRepaint = true; |
252 rtInvalidate = m_rtDnButton; | 252 rtInvalidate = m_rtDnButton; |
253 } | 253 } |
254 if (bRepaint) | 254 if (bRepaint) |
255 Repaint(&rtInvalidate); | 255 Repaint(&rtInvalidate); |
256 } | 256 } |
257 | 257 |
258 void CFWL_SpinButton::OnMouseMove(CFWL_MsgMouse* pMsg) { | 258 void CFWL_SpinButton::OnMouseMove(CFWL_MessageMouse* pMsg) { |
259 if (m_bLButtonDwn) | 259 if (m_bLButtonDwn) |
260 return; | 260 return; |
261 | 261 |
262 bool bRepaint = false; | 262 bool bRepaint = false; |
263 CFX_RectF rtInvlidate; | 263 CFX_RectF rtInvlidate; |
264 rtInvlidate.Reset(); | 264 rtInvlidate.Reset(); |
265 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { | 265 if (m_rtUpButton.Contains(pMsg->m_fx, pMsg->m_fy)) { |
266 if (IsUpButtonEnabled()) { | 266 if (IsUpButtonEnabled()) { |
267 if (m_dwUpState == CFWL_PartState_Hovered) { | 267 if (m_dwUpState == CFWL_PartState_Hovered) { |
268 m_dwUpState = CFWL_PartState_Hovered; | 268 m_dwUpState = CFWL_PartState_Hovered; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 else | 312 else |
313 rtInvlidate = m_rtDnButton; | 313 rtInvlidate = m_rtDnButton; |
314 | 314 |
315 bRepaint = true; | 315 bRepaint = true; |
316 } | 316 } |
317 } | 317 } |
318 if (bRepaint) | 318 if (bRepaint) |
319 Repaint(&rtInvlidate); | 319 Repaint(&rtInvlidate); |
320 } | 320 } |
321 | 321 |
322 void CFWL_SpinButton::OnMouseLeave(CFWL_MsgMouse* pMsg) { | 322 void CFWL_SpinButton::OnMouseLeave(CFWL_MessageMouse* pMsg) { |
323 if (!pMsg) | 323 if (!pMsg) |
324 return; | 324 return; |
325 if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) | 325 if (m_dwUpState != CFWL_PartState_Normal && IsUpButtonEnabled()) |
326 m_dwUpState = CFWL_PartState_Normal; | 326 m_dwUpState = CFWL_PartState_Normal; |
327 if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) | 327 if (m_dwDnState != CFWL_PartState_Normal && IsDownButtonEnabled()) |
328 m_dwDnState = CFWL_PartState_Normal; | 328 m_dwDnState = CFWL_PartState_Normal; |
329 | 329 |
330 Repaint(&m_rtClient); | 330 Repaint(&m_rtClient); |
331 } | 331 } |
332 | 332 |
333 void CFWL_SpinButton::OnKeyDown(CFWL_MsgKey* pMsg) { | 333 void CFWL_SpinButton::OnKeyDown(CFWL_MessageKey* pMsg) { |
334 bool bUp = | 334 bool bUp = |
335 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; | 335 pMsg->m_dwKeyCode == FWL_VKEY_Up || pMsg->m_dwKeyCode == FWL_VKEY_Left; |
336 bool bDown = | 336 bool bDown = |
337 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; | 337 pMsg->m_dwKeyCode == FWL_VKEY_Down || pMsg->m_dwKeyCode == FWL_VKEY_Right; |
338 if (!bUp && !bDown) | 338 if (!bUp && !bDown) |
339 return; | 339 return; |
340 | 340 |
341 bool bUpEnable = IsUpButtonEnabled(); | 341 bool bUpEnable = IsUpButtonEnabled(); |
342 bool bDownEnable = IsDownButtonEnabled(); | 342 bool bDownEnable = IsDownButtonEnabled(); |
343 if (!bUpEnable && !bDownEnable) | 343 if (!bUpEnable && !bDownEnable) |
(...skipping 10 matching lines...) Expand all Loading... |
354 | 354 |
355 void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { | 355 void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) { |
356 CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget); | 356 CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget); |
357 | 357 |
358 if (!pButton->m_pTimerInfo) | 358 if (!pButton->m_pTimerInfo) |
359 return; | 359 return; |
360 | 360 |
361 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); | 361 CFWL_Event wmPosChanged(CFWL_Event::Type::Click, pButton); |
362 pButton->DispatchEvent(&wmPosChanged); | 362 pButton->DispatchEvent(&wmPosChanged); |
363 } | 363 } |
OLD | NEW |