John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 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. |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 4 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 7 | #include "fpdfsdk/formfiller/cffl_checkbox.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 8 | |
Dan Sinclair | edbb319 | 2016-03-21 09:08:24 -0400 | [diff] [blame] | 9 | #include "fpdfsdk/formfiller/cffl_formfiller.h" |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 10 | #include "fpdfsdk/include/cpdfsdk_environment.h" |
jaepark | 611adb8 | 2016-08-17 11:34:36 -0700 | [diff] [blame] | 11 | #include "fpdfsdk/include/cpdfsdk_widget.h" |
dan sinclair | 89e904b | 2016-03-23 19:29:15 -0400 | [diff] [blame] | 12 | #include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" |
Lei Zhang | c2fb35f | 2016-01-05 16:46:58 -0800 | [diff] [blame] | 13 | #include "public/fpdf_fwlevent.h" |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 14 | |
dsinclair | 79db609 | 2016-09-14 07:27:21 -0700 | [diff] [blame] | 15 | CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_Environment* pApp, CPDFSDK_Widget* pWidget) |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 16 | : CFFL_Button(pApp, pWidget) {} |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 17 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 18 | CFFL_CheckBox::~CFFL_CheckBox() {} |
| 19 | |
| 20 | CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, |
| 21 | CPDFSDK_PageView* pPageView) { |
| 22 | CPWL_CheckBox* pWnd = new CPWL_CheckBox(); |
| 23 | pWnd->Create(cp); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 24 | pWnd->SetCheck(m_pWidget->IsChecked()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 25 | return pWnd; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 28 | FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 29 | uint32_t nKeyCode, |
| 30 | uint32_t nFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 31 | switch (nKeyCode) { |
| 32 | case FWL_VKEY_Return: |
| 33 | case FWL_VKEY_Space: |
| 34 | return TRUE; |
| 35 | default: |
| 36 | return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); |
| 37 | } |
| 38 | } |
| 39 | FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 40 | uint32_t nChar, |
| 41 | uint32_t nFlags) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 42 | switch (nChar) { |
| 43 | case FWL_VKEY_Return: |
| 44 | case FWL_VKEY_Space: { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 45 | CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 46 | ASSERT(pPageView); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 47 | |
| 48 | FX_BOOL bReset = FALSE; |
| 49 | FX_BOOL bExit = FALSE; |
dsinclair | b94d7c9 | 2016-09-21 12:07:00 -0700 | [diff] [blame^] | 50 | m_pEnv->GetInteractiveFormFiller()->OnButtonUp(m_pWidget, pPageView, |
| 51 | bReset, bExit, nFlags); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 52 | if (bReset) |
| 53 | return TRUE; |
| 54 | if (bExit) |
| 55 | return TRUE; |
| 56 | |
| 57 | CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
| 58 | |
| 59 | if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) |
| 60 | pWnd->SetCheck(!pWnd->IsChecked()); |
| 61 | |
| 62 | CommitData(pPageView, nFlags); |
| 63 | return TRUE; |
| 64 | } |
| 65 | default: |
| 66 | return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
| 67 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 70 | FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, |
| 71 | CPDFSDK_Annot* pAnnot, |
dsinclair | 72177da | 2016-09-15 12:07:23 -0700 | [diff] [blame] | 72 | uint32_t nFlags, |
Tom Sepez | 281a9ea | 2016-02-26 14:24:28 -0800 | [diff] [blame] | 73 | const CFX_FloatPoint& point) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 74 | CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 75 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 76 | if (IsValid()) { |
| 77 | if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) { |
| 78 | CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
| 79 | pWnd->SetCheck(!pWidget->IsChecked()); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 80 | } |
Lei Zhang | a6d9f0e | 2015-06-13 00:48:38 -0700 | [diff] [blame] | 81 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 82 | if (!CommitData(pPageView, nFlags)) |
| 83 | return FALSE; |
| 84 | } |
| 85 | |
| 86 | return TRUE; |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 87 | } |
| 88 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 89 | FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { |
Lei Zhang | 96660d6 | 2015-12-14 18:27:25 -0800 | [diff] [blame] | 90 | CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE); |
| 91 | return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | } |
| 93 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 94 | void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 95 | if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)) { |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 96 | bool bNewChecked = pWnd->IsChecked(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 97 | |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 98 | if (bNewChecked) { |
| 99 | CPDF_FormField* pField = m_pWidget->GetFormField(); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 100 | for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { |
| 101 | if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { |
| 102 | if (pCtrl->IsChecked()) { |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 108 | |
Wei Li | 97da976 | 2016-03-11 17:00:48 -0800 | [diff] [blame] | 109 | m_pWidget->SetCheck(bNewChecked, false); |
Nico Weber | 9d8ec5a | 2015-08-04 13:00:21 -0700 | [diff] [blame] | 110 | m_pWidget->UpdateField(); |
| 111 | SetChangeMark(); |
| 112 | } |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 113 | } |