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 "../../include/formfiller/FormFiller.h" | 7 #include "../../include/formfiller/FormFiller.h" |
8 #include "../../include/formfiller/FFL_FormFiller.h" | 8 #include "../../include/formfiller/FFL_FormFiller.h" |
9 #include "../../include/formfiller/FFL_CheckBox.h" | 9 #include "../../include/formfiller/FFL_CheckBox.h" |
10 | 10 |
| 11 /* ------------------------------- CFFL_CheckBox ------------------------------- |
| 12 */ |
11 | 13 |
12 /* ------------------------------- CFFL_CheckBox -------------------------------
*/ | 14 CFFL_CheckBox::CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget) |
| 15 : CFFL_Button(pApp, pWidget) {} |
13 | 16 |
14 CFFL_CheckBox::CFFL_CheckBox(CPDFDoc_Environment* pApp, CPDFSDK_Widget* pWidget)
: | 17 CFFL_CheckBox::~CFFL_CheckBox() {} |
15 » CFFL_Button(pApp, pWidget) | 18 |
16 { | 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); |
| 23 |
| 24 ASSERT(m_pWidget != NULL); |
| 25 pWnd->SetCheck(m_pWidget->IsChecked()); |
| 26 |
| 27 return pWnd; |
17 } | 28 } |
18 | 29 |
19 CFFL_CheckBox::~CFFL_CheckBox() | 30 FX_BOOL CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, |
20 { | 31 FX_UINT nKeyCode, |
| 32 FX_UINT nFlags) { |
| 33 switch (nKeyCode) { |
| 34 case FWL_VKEY_Return: |
| 35 case FWL_VKEY_Space: |
| 36 return TRUE; |
| 37 default: |
| 38 return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); |
| 39 } |
| 40 } |
| 41 FX_BOOL CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, |
| 42 FX_UINT nChar, |
| 43 FX_UINT nFlags) { |
| 44 switch (nChar) { |
| 45 case FWL_VKEY_Return: |
| 46 case FWL_VKEY_Space: { |
| 47 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); |
| 48 ASSERT(pIFormFiller != NULL); |
| 49 |
| 50 CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); |
| 51 ASSERT(pPageView != NULL); |
| 52 |
| 53 FX_BOOL bReset = FALSE; |
| 54 FX_BOOL bExit = FALSE; |
| 55 |
| 56 pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, bExit, nFlags); |
| 57 |
| 58 if (bReset) |
| 59 return TRUE; |
| 60 if (bExit) |
| 61 return TRUE; |
| 62 |
| 63 CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
| 64 |
| 65 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) |
| 66 pWnd->SetCheck(!pWnd->IsChecked()); |
| 67 |
| 68 CommitData(pPageView, nFlags); |
| 69 return TRUE; |
| 70 } |
| 71 default: |
| 72 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
| 73 } |
21 } | 74 } |
22 | 75 |
23 CPWL_Wnd* CFFL_CheckBox::NewPDFWindow(const PWL_CREATEPARAM& cp, CPDFSDK_PageVie
w* pPageView) | 76 FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView* pPageView, |
24 { | 77 CPDFSDK_Annot* pAnnot, |
25 » CPWL_CheckBox* pWnd = new CPWL_CheckBox(); | 78 FX_UINT nFlags, |
26 » pWnd->Create(cp); | 79 const CPDF_Point& point) { |
| 80 CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); |
27 | 81 |
28 » ASSERT(m_pWidget != NULL); | 82 if (IsValid()) { |
29 » pWnd->SetCheck(m_pWidget->IsChecked()); | 83 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, TRUE)) { |
| 84 CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; |
| 85 pWnd->SetCheck(!pWidget->IsChecked()); |
| 86 //» pWnd->SetCheck(!pWnd->IsChecked()); |
| 87 } |
30 | 88 |
31 » return pWnd; | 89 if (!CommitData(pPageView, nFlags)) |
| 90 return FALSE; |
| 91 } |
| 92 |
| 93 return TRUE; |
32 } | 94 } |
33 | 95 |
34 FX_BOOL»CFFL_CheckBox::OnKeyDown(CPDFSDK_Annot* pAnnot, FX_UINT nKeyCode, FX_UIN
T nFlags) | 96 FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) { |
35 { | 97 ASSERT(m_pWidget != NULL); |
36 » switch (nKeyCode) | |
37 » { | |
38 » case FWL_VKEY_Return: | |
39 » case FWL_VKEY_Space: | |
40 » » return TRUE; | |
41 » default: | |
42 » » return CFFL_FormFiller::OnKeyDown(pAnnot, nKeyCode, nFlags); | |
43 » } | |
44 } | |
45 FX_BOOL»CFFL_CheckBox::OnChar(CPDFSDK_Annot* pAnnot, FX_UINT nChar, FX_UINT nFla
gs) | |
46 { | |
47 » switch (nChar) | |
48 » { | |
49 » case FWL_VKEY_Return: | |
50 » case FWL_VKEY_Space: | |
51 » » { | |
52 » » » CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(
); | |
53 » » » ASSERT(pIFormFiller != NULL); | |
54 | 98 |
55 » » » CPDFSDK_PageView* pPageView = pAnnot->GetPageView(); | 99 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)) { |
56 » » » ASSERT(pPageView != NULL); | 100 return pWnd->IsChecked() != m_pWidget->IsChecked(); |
| 101 } |
57 | 102 |
58 » » » FX_BOOL bReset = FALSE; | 103 return FALSE; |
59 » » » FX_BOOL bExit = FALSE; | |
60 | |
61 » » » pIFormFiller->OnButtonUp(m_pWidget, pPageView, bReset, b
Exit,nFlags); | |
62 | |
63 » » » if (bReset) return TRUE; | |
64 » » » if (bExit) return TRUE; | |
65 | |
66 » » » CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | |
67 | |
68 » » » if (CPWL_CheckBox * pWnd = (CPWL_CheckBox*)GetPDFWindow(
pPageView, TRUE)) | |
69 » » » » pWnd->SetCheck(!pWnd->IsChecked()); | |
70 | |
71 » » » CommitData(pPageView,nFlags); | |
72 » » » return TRUE; | |
73 » » } | |
74 » default: | |
75 » » return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | |
76 » } | |
77 } | 104 } |
78 | 105 |
79 FX_BOOL CFFL_CheckBox::OnLButtonUp(CPDFSDK_PageView *pPageView, CPDFSDK_Annot* p
Annot, FX_UINT nFlags, const CPDF_Point& point) | 106 void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) { |
80 { | 107 ASSERT(m_pWidget != NULL); |
81 » CFFL_Button::OnLButtonUp(pPageView, pAnnot, nFlags, point); | |
82 | 108 |
83 » if (IsValid()) | 109 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)) { |
84 » { | 110 FX_BOOL bNewChecked = pWnd->IsChecked(); |
85 » » if (CPWL_CheckBox * pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageVie
w, TRUE)) | |
86 » » { | |
87 » » » CPDFSDK_Widget* pWidget = (CPDFSDK_Widget*)pAnnot; | |
88 » » » pWnd->SetCheck(!pWidget->IsChecked()); | |
89 » » //» pWnd->SetCheck(!pWnd->IsChecked()); | |
90 » » } | |
91 | 111 |
92 » » if (!CommitData(pPageView, nFlags)) return FALSE; | 112 if (bNewChecked) { |
93 » } | 113 CPDF_FormField* pField = m_pWidget->GetFormField(); |
| 114 ASSERT(pField != NULL); |
94 | 115 |
95 » return TRUE; | 116 for (int32_t i = 0, sz = pField->CountControls(); i < sz; i++) { |
| 117 if (CPDF_FormControl* pCtrl = pField->GetControl(i)) { |
| 118 if (pCtrl->IsChecked()) { |
| 119 break; |
| 120 } |
| 121 } |
| 122 } |
| 123 } |
| 124 |
| 125 m_pWidget->SetCheck(bNewChecked, FALSE); |
| 126 m_pWidget->UpdateField(); |
| 127 SetChangeMark(); |
| 128 } |
96 } | 129 } |
97 | |
98 FX_BOOL CFFL_CheckBox::IsDataChanged(CPDFSDK_PageView* pPageView) | |
99 { | |
100 | |
101 ASSERT(m_pWidget != NULL); | |
102 | |
103 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)
) | |
104 { | |
105 return pWnd->IsChecked() != m_pWidget->IsChecked(); | |
106 } | |
107 | |
108 return FALSE; | |
109 } | |
110 | |
111 void CFFL_CheckBox::SaveData(CPDFSDK_PageView* pPageView) | |
112 { | |
113 | |
114 ASSERT(m_pWidget != NULL); | |
115 | |
116 if (CPWL_CheckBox* pWnd = (CPWL_CheckBox*)GetPDFWindow(pPageView, FALSE)
) | |
117 { | |
118 | |
119 FX_BOOL bNewChecked = pWnd->IsChecked(); | |
120 | |
121 | |
122 if (bNewChecked) | |
123 { | |
124 CPDF_FormField* pField = m_pWidget->GetFormField(); | |
125 ASSERT(pField != NULL); | |
126 | |
127 for (int32_t i=0,sz=pField->CountControls(); i<sz; i++) | |
128 { | |
129 if (CPDF_FormControl* pCtrl = pField->GetControl
(i)) | |
130 { | |
131 if (pCtrl->IsChecked()) | |
132 { | |
133 break; | |
134 } | |
135 } | |
136 } | |
137 } | |
138 | |
139 m_pWidget->SetCheck(bNewChecked, FALSE); | |
140 m_pWidget->UpdateField(); | |
141 SetChangeMark(); | |
142 } | |
143 | |
144 } | |
OLD | NEW |