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_checkbox.h" | 7 #include "xfa/fwl/cfwl_checkbox.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "third_party/base/ptr_util.h" | 13 #include "third_party/base/ptr_util.h" |
14 #include "xfa/fde/tto/fde_textout.h" | 14 #include "xfa/fde/tto/fde_textout.h" |
15 #include "xfa/fwl/core/cfwl_app.h" | 15 #include "xfa/fwl/cfwl_app.h" |
16 #include "xfa/fwl/core/cfwl_event.h" | 16 #include "xfa/fwl/cfwl_event.h" |
17 #include "xfa/fwl/core/cfwl_msgkey.h" | 17 #include "xfa/fwl/cfwl_messagekey.h" |
18 #include "xfa/fwl/core/cfwl_msgmouse.h" | 18 #include "xfa/fwl/cfwl_messagemouse.h" |
19 #include "xfa/fwl/core/cfwl_notedriver.h" | 19 #include "xfa/fwl/cfwl_notedriver.h" |
20 #include "xfa/fwl/core/cfwl_themebackground.h" | 20 #include "xfa/fwl/cfwl_themebackground.h" |
21 #include "xfa/fwl/core/cfwl_themetext.h" | 21 #include "xfa/fwl/cfwl_themetext.h" |
22 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 22 #include "xfa/fwl/cfwl_widgetmgr.h" |
23 #include "xfa/fwl/core/ifwl_themeprovider.h" | 23 #include "xfa/fwl/ifwl_themeprovider.h" |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 const int kCaptionMargin = 5; | 27 const int kCaptionMargin = 5; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 CFWL_CheckBox::CFWL_CheckBox(const CFWL_App* app) | 31 CFWL_CheckBox::CFWL_CheckBox(const CFWL_App* app) |
32 : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr), | 32 : CFWL_Widget(app, pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr), |
33 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), | 33 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine), |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 return; | 324 return; |
325 | 325 |
326 switch (pMessage->GetType()) { | 326 switch (pMessage->GetType()) { |
327 case CFWL_Message::Type::SetFocus: | 327 case CFWL_Message::Type::SetFocus: |
328 OnFocusChanged(true); | 328 OnFocusChanged(true); |
329 break; | 329 break; |
330 case CFWL_Message::Type::KillFocus: | 330 case CFWL_Message::Type::KillFocus: |
331 OnFocusChanged(false); | 331 OnFocusChanged(false); |
332 break; | 332 break; |
333 case CFWL_Message::Type::Mouse: { | 333 case CFWL_Message::Type::Mouse: { |
334 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 334 CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage); |
335 switch (pMsg->m_dwCmd) { | 335 switch (pMsg->m_dwCmd) { |
336 case FWL_MouseCommand::LeftButtonDown: | 336 case FWL_MouseCommand::LeftButtonDown: |
337 OnLButtonDown(); | 337 OnLButtonDown(); |
338 break; | 338 break; |
339 case FWL_MouseCommand::LeftButtonUp: | 339 case FWL_MouseCommand::LeftButtonUp: |
340 OnLButtonUp(pMsg); | 340 OnLButtonUp(pMsg); |
341 break; | 341 break; |
342 case FWL_MouseCommand::Move: | 342 case FWL_MouseCommand::Move: |
343 OnMouseMove(pMsg); | 343 OnMouseMove(pMsg); |
344 break; | 344 break; |
345 case FWL_MouseCommand::Leave: | 345 case FWL_MouseCommand::Leave: |
346 OnMouseLeave(); | 346 OnMouseLeave(); |
347 break; | 347 break; |
348 default: | 348 default: |
349 break; | 349 break; |
350 } | 350 } |
351 break; | 351 break; |
352 } | 352 } |
353 case CFWL_Message::Type::Key: { | 353 case CFWL_Message::Type::Key: { |
354 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 354 CFWL_MessageKey* pKey = static_cast<CFWL_MessageKey*>(pMessage); |
355 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) | 355 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) |
356 OnKeyDown(pKey); | 356 OnKeyDown(pKey); |
357 break; | 357 break; |
358 } | 358 } |
359 default: | 359 default: |
360 break; | 360 break; |
361 } | 361 } |
362 | 362 |
363 CFWL_Widget::OnProcessMessage(pMessage); | 363 CFWL_Widget::OnProcessMessage(pMessage); |
364 } | 364 } |
(...skipping 17 matching lines...) Expand all Loading... |
382 return; | 382 return; |
383 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 383 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
384 SetFocus(true); | 384 SetFocus(true); |
385 | 385 |
386 m_bBtnDown = true; | 386 m_bBtnDown = true; |
387 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 387 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
388 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | 388 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; |
389 Repaint(&m_rtClient); | 389 Repaint(&m_rtClient); |
390 } | 390 } |
391 | 391 |
392 void CFWL_CheckBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 392 void CFWL_CheckBox::OnLButtonUp(CFWL_MessageMouse* pMsg) { |
393 if (!m_bBtnDown) | 393 if (!m_bBtnDown) |
394 return; | 394 return; |
395 | 395 |
396 m_bBtnDown = false; | 396 m_bBtnDown = false; |
397 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) | 397 if (!m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) |
398 return; | 398 return; |
399 | 399 |
400 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 400 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
401 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; | 401 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Pressed; |
402 NextStates(); | 402 NextStates(); |
403 } | 403 } |
404 | 404 |
405 void CFWL_CheckBox::OnMouseMove(CFWL_MsgMouse* pMsg) { | 405 void CFWL_CheckBox::OnMouseMove(CFWL_MessageMouse* pMsg) { |
406 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 406 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
407 return; | 407 return; |
408 | 408 |
409 bool bRepaint = false; | 409 bool bRepaint = false; |
410 if (m_bBtnDown) { | 410 if (m_bBtnDown) { |
411 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | 411 if (m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { |
412 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { | 412 if ((m_pProperties->m_dwStates & FWL_STATE_CKB_Pressed) == 0) { |
413 bRepaint = true; | 413 bRepaint = true; |
414 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; | 414 m_pProperties->m_dwStates |= FWL_STATE_CKB_Pressed; |
415 } | 415 } |
(...skipping 25 matching lines...) Expand all Loading... |
441 | 441 |
442 void CFWL_CheckBox::OnMouseLeave() { | 442 void CFWL_CheckBox::OnMouseLeave() { |
443 if (m_bBtnDown) | 443 if (m_bBtnDown) |
444 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; | 444 m_pProperties->m_dwStates |= FWL_STATE_CKB_Hovered; |
445 else | 445 else |
446 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; | 446 m_pProperties->m_dwStates &= ~FWL_STATE_CKB_Hovered; |
447 | 447 |
448 Repaint(&m_rtBox); | 448 Repaint(&m_rtBox); |
449 } | 449 } |
450 | 450 |
451 void CFWL_CheckBox::OnKeyDown(CFWL_MsgKey* pMsg) { | 451 void CFWL_CheckBox::OnKeyDown(CFWL_MessageKey* pMsg) { |
452 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) | 452 if (pMsg->m_dwKeyCode == FWL_VKEY_Tab) |
453 return; | 453 return; |
454 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || | 454 if (pMsg->m_dwKeyCode == FWL_VKEY_Return || |
455 pMsg->m_dwKeyCode == FWL_VKEY_Space) { | 455 pMsg->m_dwKeyCode == FWL_VKEY_Space) { |
456 NextStates(); | 456 NextStates(); |
457 } | 457 } |
458 } | 458 } |
OLD | NEW |