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