Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 1 | // Copyright 2017 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "fpdfsdk/formfiller/cffl_button.h" |
| 8 | |
| 9 | CFFL_Button::CFFL_Button(CPDFSDK_FormFillEnvironment* pApp, |
| 10 | CPDFSDK_Widget* pWidget) |
| 11 | : CFFL_FormFiller(pApp, pWidget), m_bMouseIn(false), m_bMouseDown(false) {} |
| 12 | |
| 13 | CFFL_Button::~CFFL_Button() {} |
| 14 | |
| 15 | void CFFL_Button::OnMouseEnter(CPDFSDK_PageView* pPageView, |
| 16 | CPDFSDK_Annot* pAnnot) { |
| 17 | m_bMouseIn = true; |
| 18 | InvalidateRect(GetViewBBox(pPageView, pAnnot)); |
| 19 | } |
| 20 | |
| 21 | void CFFL_Button::OnMouseExit(CPDFSDK_PageView* pPageView, |
| 22 | CPDFSDK_Annot* pAnnot) { |
| 23 | m_bMouseIn = false; |
| 24 | InvalidateRect(GetViewBBox(pPageView, pAnnot)); |
| 25 | EndTimer(); |
| 26 | ASSERT(m_pWidget); |
| 27 | } |
| 28 | |
| 29 | bool CFFL_Button::OnLButtonDown(CPDFSDK_PageView* pPageView, |
| 30 | CPDFSDK_Annot* pAnnot, |
| 31 | uint32_t nFlags, |
| 32 | const CFX_PointF& point) { |
| 33 | if (!pAnnot->GetRect().Contains(point)) |
| 34 | return false; |
| 35 | |
| 36 | m_bMouseDown = true; |
| 37 | m_bValid = true; |
| 38 | InvalidateRect(GetViewBBox(pPageView, pAnnot)); |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | bool CFFL_Button::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 43 | CPDFSDK_Annot* pAnnot, |
| 44 | uint32_t nFlags, |
| 45 | const CFX_PointF& point) { |
| 46 | if (!pAnnot->GetRect().Contains(point)) |
| 47 | return false; |
| 48 | |
| 49 | m_bMouseDown = false; |
| 50 | m_pWidget->GetPDFPage(); |
| 51 | InvalidateRect(GetViewBBox(pPageView, pAnnot)); |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | bool CFFL_Button::OnMouseMove(CPDFSDK_PageView* pPageView, |
| 56 | CPDFSDK_Annot* pAnnot, |
| 57 | uint32_t nFlags, |
| 58 | const CFX_PointF& point) { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | void CFFL_Button::OnDraw(CPDFSDK_PageView* pPageView, |
| 63 | CPDFSDK_Annot* pAnnot, |
| 64 | CFX_RenderDevice* pDevice, |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 65 | const CFX_Matrix& mtUser2Device) { |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 66 | ASSERT(pPageView); |
| 67 | CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot); |
| 68 | CPDF_FormControl* pCtrl = pWidget->GetFormControl(); |
| 69 | if (pCtrl->GetHighlightingMode() != CPDF_FormControl::Push) { |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 70 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 71 | nullptr); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 72 | return; |
| 73 | } |
| 74 | if (m_bMouseDown) { |
| 75 | if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Down)) { |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 76 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Down, |
Lei Zhang | 8a44940 | 2017-08-17 15:07:47 -0700 | [diff] [blame] | 77 | nullptr); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 78 | } else { |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 79 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 80 | nullptr); |
| 81 | } |
| 82 | return; |
| 83 | } |
| 84 | if (m_bMouseIn) { |
| 85 | if (pWidget->IsWidgetAppearanceValid(CPDF_Annot::Rollover)) { |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 86 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Rollover, |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 87 | nullptr); |
| 88 | } else { |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 89 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 90 | nullptr); |
| 91 | } |
| 92 | return; |
| 93 | } |
| 94 | |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 95 | pWidget->DrawAppearance(pDevice, mtUser2Device, CPDF_Annot::Normal, nullptr); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void CFFL_Button::OnDrawDeactive(CPDFSDK_PageView* pPageView, |
| 99 | CPDFSDK_Annot* pAnnot, |
| 100 | CFX_RenderDevice* pDevice, |
Lei Zhang | 2b6e2a7 | 2017-08-28 11:34:16 -0700 | [diff] [blame] | 101 | const CFX_Matrix& mtUser2Device) { |
| 102 | OnDraw(pPageView, pAnnot, pDevice, mtUser2Device); |
Dan Sinclair | b9eed2f | 2017-07-10 11:35:18 -0400 | [diff] [blame] | 103 | } |