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 "fpdfsdk/formfiller/cffl_checkbox.h" | 7 #include "fpdfsdk/formfiller/cffl_checkbox.h" |
8 | 8 |
9 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" | 9 #include "fpdfsdk/cpdfsdk_formfillenvironment.h" |
10 #include "fpdfsdk/cpdfsdk_widget.h" | 10 #include "fpdfsdk/cpdfsdk_widget.h" |
11 #include "fpdfsdk/formfiller/cffl_formfiller.h" | 11 #include "fpdfsdk/formfiller/cffl_formfiller.h" |
12 #include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" | 12 #include "fpdfsdk/pdfwindow/PWL_SpecialButton.h" |
13 #include "public/fpdf_fwlevent.h" | 13 #include "public/fpdf_fwlevent.h" |
14 | 14 |
15 CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_FormFillEnvironment* pApp, | 15 CFFL_CheckBox::CFFL_CheckBox(CPDFSDK_FormFillEnvironment* pApp, |
16 CPDFSDK_Widget* pWidget) | 16 CPDFSDK_Widget* pWidget) |
17 : CFFL_Button(pApp, pWidget) {} | 17 : CFFL_Button(pApp, pWidget) {} |
18 | 18 |
19 CFFL_CheckBox::~CFFL_CheckBox() {} | 19 CFFL_CheckBox::~CFFL_CheckBox() {} |
20 | 20 |
21 CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, | 21 CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, |
22 CPDFSDK_PageView* pPageView) { | 22 CPDFSDK_PageView* pPageView) { |
23 CPWL_CheckBox* pWnd = new CPWL_CheckBox(); | 23 CPWL_CheckBox* pWnd = new CPWL_CheckBox(); |
24 pWnd->Create(cp); | 24 pWnd->Create(cp); |
25 pWnd->SetCheck(m_pWidget->IsChecked()); | 25 pWnd->SetCheck(m_pWidget->IsChecked()); |
26 return pWnd; | 26 return pWnd; |
27 } | 27 } |
28 | 28 |
29 FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, | 29 bool CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, |
30 uint32_t nKeyCode, | 30 uint32_t nKeyCode, |
31 uint32_t nFlags) { | 31 uint32_t nFlags) { |
32 switch (nKeyCode) { | 32 switch (nKeyCode) { |
33 case FWL_VKEY_Return: | 33 case FWL_VKEY_Return: |
34 case FWL_VKEY_Space: | 34 case FWL_VKEY_Space: |
35 return TRUE; | 35 return true; |
36 default: | 36 default: |
37 return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); | 37 return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); |
38 } | 38 } |
39 } | 39 } |
40 FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, | 40 bool CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, |
41 uint32_t nChar, | 41 uint32_t nChar, |
42 uint32_t nFlags) { | 42 uint32_t nFlags) { |
43 switch (nChar) { | 43 switch (nChar) { |
44 case FWL_VKEY_Return: | 44 case FWL_VKEY_Return: |
45 case FWL_VKEY_Space: { | 45 case FWL_VKEY_Space: { |
46 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | 46 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
47 ASSERT(pPageView); | 47 ASSERT(pPageView); |
48 | 48 |
49 FX_BOOL bReset = FALSE; | 49 bool bReset = false; |
50 FX_BOOL bExit = FALSE; | 50 bool bExit = false; |
51 CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); | 51 CPDFSDK_Annot::ObservedPtr pObserved(m_pWidget); |
52 m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( | 52 m_pFormFillEnv->GetInteractiveFormFiller()->OnButtonUp( |
53 &pObserved, pPageView, bReset, bExit, nFlags); | 53 &pObserved, pPageView, bReset, bExit, nFlags); |
54 if (!pObserved) { | 54 if (!pObserved) { |
55 m_pWidget = nullptr; | 55 m_pWidget = nullptr; |
56 return TRUE; | 56 return true; |
57 } | 57 } |
58 if (bReset || bExit) | 58 if (bReset || bExit) |
59 return TRUE; | 59 return true; |
60 | 60 |
61 CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | 61 CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
62 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) | 62 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, true)) |
63 pWnd->SetCheck(!pWnd->IsChecked()); | 63 pWnd->SetCheck(!pWnd->IsChecked()); |
64 | 64 |
65 CommitData(pPageView, nFlags); | 65 CommitData(pPageView, nFlags); |
66 return TRUE; | 66 return true; |
67 } | 67 } |
68 default: | 68 default: |
69 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | 69 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
70 } | 70 } |
71 } | 71 } |
72 | 72 |
73 FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, | 73 bool CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, |
74 CPDFSDK_Annot* pAnnot, | 74 CPDFSDK_Annot* pAnnot, |
75 uint32_t nFlags, | 75 uint32_t nFlags, |
76 const CFX_FloatPoint& point) { | 76 const CFX_FloatPoint& point) { |
77 CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); | 77 CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); |
78 | 78 |
79 if (IsValid()) { | 79 if (IsValid()) { |
80 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) { | 80 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, true)) { |
81 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | 81 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
82 pWnd->SetCheck(!pWidget->IsChecked()); | 82 pWnd->SetCheck(!pWidget->IsChecked()); |
83 } | 83 } |
84 | 84 |
85 if (!CommitData(pPageView, nFlags)) | 85 if (!CommitData(pPageView, nFlags)) |
86 return FALSE; | 86 return false; |
87 } | 87 } |
88 | 88 |
89 return TRUE; | 89 return true; |
90 } | 90 } |
91 | 91 |
92 FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { | 92 bool CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { |
93 CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE); | 93 CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, false); |
94 return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); | 94 return pWnd && pWnd->IsChecked() != m_pWidget->IsChecked(); |
95 } | 95 } |
96 | 96 |
97 void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { | 97 void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { |
98 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)) { | 98 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, false)) { |
99 bool bNewChecked = pWnd->IsChecked(); | 99 bool bNewChecked = pWnd->IsChecked(); |
100 | 100 |
101 if (bNewChecked) { | 101 if (bNewChecked) { |
102 CPDF_FormField* pField = m_pWidget->GetFormField(); | 102 CPDF_FormField* pField = m_pWidget->GetFormField(); |
103 for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { | 103 for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { |
104 if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { | 104 if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { |
105 if (pCtrl->IsChecked()) { | 105 if (pCtrl->IsChecked()) { |
106 break; | 106 break; |
107 } | 107 } |
108 } | 108 } |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 m_pWidget->SetCheck(bNewChecked, false); | 112 m_pWidget->SetCheck(bNewChecked, false); |
113 m_pWidget->UpdateField(); | 113 m_pWidget->UpdateField(); |
114 SetChangeMark(); | 114 SetChangeMark(); |
115 } | 115 } |
116 } | 116 } |
OLD | NEW |