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_listbox.h" | 7 #include "fpdfsdk/formfiller/cffl_listbox.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" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 pWnd->AttachFFLData(this); | 52 pWnd->AttachFFLData(this); |
53 pWnd->Create(cp); | 53 pWnd->Create(cp); |
54 pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); | 54 pWnd->SetFillerNotify(m_pFormFillEnv->GetInteractiveFormFiller()); |
55 | 55 |
56 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) | 56 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) |
57 pWnd->AddString(m_pWidget->GetOptionLabel(i)); | 57 pWnd->AddString(m_pWidget->GetOptionLabel(i)); |
58 | 58 |
59 if (pWnd->HasFlag(PLBS_MULTIPLESEL)) { | 59 if (pWnd->HasFlag(PLBS_MULTIPLESEL)) { |
60 m_OriginSelections.clear(); | 60 m_OriginSelections.clear(); |
61 | 61 |
62 FX_BOOL bSetCaret = FALSE; | 62 bool bSetCaret = false; |
63 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { | 63 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { |
64 if (m_pWidget->IsOptionSelected(i)) { | 64 if (m_pWidget->IsOptionSelected(i)) { |
65 if (!bSetCaret) { | 65 if (!bSetCaret) { |
66 pWnd->SetCaret(i); | 66 pWnd->SetCaret(i); |
67 bSetCaret = TRUE; | 67 bSetCaret = true; |
68 } | 68 } |
69 pWnd->Select(i); | 69 pWnd->Select(i); |
70 m_OriginSelections.insert(i); | 70 m_OriginSelections.insert(i); |
71 } | 71 } |
72 } | 72 } |
73 } else { | 73 } else { |
74 for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { | 74 for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { |
75 if (m_pWidget->IsOptionSelected(i)) { | 75 if (m_pWidget->IsOptionSelected(i)) { |
76 pWnd->Select(i); | 76 pWnd->Select(i); |
77 break; | 77 break; |
78 } | 78 } |
79 } | 79 } |
80 } | 80 } |
81 | 81 |
82 pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex()); | 82 pWnd->SetTopVisibleIndex(m_pWidget->GetTopVisibleIndex()); |
83 | 83 |
84 return pWnd; | 84 return pWnd; |
85 } | 85 } |
86 | 86 |
87 FX_BOOL CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, | 87 bool CFFL_ListBox::OnChar(CPDFSDK_Annot* pAnnot, |
88 uint32_t nChar, | 88 uint32_t nChar, |
89 uint32_t nFlags) { | 89 uint32_t nFlags) { |
90 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); | 90 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); |
91 } | 91 } |
92 | 92 |
93 FX_BOOL CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) { | 93 bool CFFL_ListBox::IsDataChanged(CPDFSDK_PageView* pPageView) { |
94 CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE); | 94 CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, false); |
95 if (!pListBox) | 95 if (!pListBox) |
96 return FALSE; | 96 return false; |
97 | 97 |
98 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { | 98 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { |
99 size_t nSelCount = 0; | 99 size_t nSelCount = 0; |
100 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; ++i) { | 100 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; ++i) { |
101 if (pListBox->IsItemSelected(i)) { | 101 if (pListBox->IsItemSelected(i)) { |
102 if (m_OriginSelections.count(i) == 0) | 102 if (m_OriginSelections.count(i) == 0) |
103 return TRUE; | 103 return true; |
104 | 104 |
105 ++nSelCount; | 105 ++nSelCount; |
106 } | 106 } |
107 } | 107 } |
108 | 108 |
109 return nSelCount != m_OriginSelections.size(); | 109 return nSelCount != m_OriginSelections.size(); |
110 } | 110 } |
111 return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); | 111 return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); |
112 } | 112 } |
113 | 113 |
114 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) { | 114 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) { |
115 CPWL_ListBox* pListBox = | 115 CPWL_ListBox* pListBox = |
116 static_cast<CPWL_ListBox*>(GetPDFWindow(pPageView, FALSE)); | 116 static_cast<CPWL_ListBox*>(GetPDFWindow(pPageView, false)); |
117 if (!pListBox) | 117 if (!pListBox) |
118 return; | 118 return; |
119 | 119 |
120 int32_t nNewTopIndex = pListBox->GetTopVisibleIndex(); | 120 int32_t nNewTopIndex = pListBox->GetTopVisibleIndex(); |
121 m_pWidget->ClearSelection(FALSE); | 121 m_pWidget->ClearSelection(false); |
122 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { | 122 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { |
123 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { | 123 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { |
124 if (pListBox->IsItemSelected(i)) | 124 if (pListBox->IsItemSelected(i)) |
125 m_pWidget->SetOptionSelection(i, TRUE, FALSE); | 125 m_pWidget->SetOptionSelection(i, true, false); |
126 } | 126 } |
127 } else { | 127 } else { |
128 m_pWidget->SetOptionSelection(pListBox->GetCurSel(), TRUE, FALSE); | 128 m_pWidget->SetOptionSelection(pListBox->GetCurSel(), true, false); |
129 } | 129 } |
130 m_pWidget->SetTopVisibleIndex(nNewTopIndex); | 130 m_pWidget->SetTopVisibleIndex(nNewTopIndex); |
131 m_pWidget->ResetFieldAppearance(TRUE); | 131 m_pWidget->ResetFieldAppearance(true); |
132 m_pWidget->UpdateField(); | 132 m_pWidget->UpdateField(); |
133 SetChangeMark(); | 133 SetChangeMark(); |
134 } | 134 } |
135 | 135 |
136 void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, | 136 void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, |
137 CPDF_AAction::AActionType type, | 137 CPDF_AAction::AActionType type, |
138 PDFSDK_FieldAction& fa) { | 138 PDFSDK_FieldAction& fa) { |
139 switch (type) { | 139 switch (type) { |
140 case CPDF_AAction::Validate: | 140 case CPDF_AAction::Validate: |
141 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { | 141 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { |
142 fa.sValue = L""; | 142 fa.sValue = L""; |
143 } else { | 143 } else { |
144 if (CPWL_ListBox* pListBox = | 144 if (CPWL_ListBox* pListBox = |
145 (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { | 145 (CPWL_ListBox*)GetPDFWindow(pPageView, false)) { |
146 int32_t nCurSel = pListBox->GetCurSel(); | 146 int32_t nCurSel = pListBox->GetCurSel(); |
147 if (nCurSel >= 0) | 147 if (nCurSel >= 0) |
148 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); | 148 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); |
149 } | 149 } |
150 } | 150 } |
151 break; | 151 break; |
152 case CPDF_AAction::LoseFocus: | 152 case CPDF_AAction::LoseFocus: |
153 case CPDF_AAction::GetFocus: | 153 case CPDF_AAction::GetFocus: |
154 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { | 154 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { |
155 fa.sValue = L""; | 155 fa.sValue = L""; |
156 } else { | 156 } else { |
157 int32_t nCurSel = m_pWidget->GetSelectedIndex(0); | 157 int32_t nCurSel = m_pWidget->GetSelectedIndex(0); |
158 if (nCurSel >= 0) | 158 if (nCurSel >= 0) |
159 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); | 159 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); |
160 } | 160 } |
161 break; | 161 break; |
162 default: | 162 default: |
163 break; | 163 break; |
164 } | 164 } |
165 } | 165 } |
166 | 166 |
167 void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) { | 167 void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) { |
168 ASSERT(pPageView); | 168 ASSERT(pPageView); |
169 | 169 |
170 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { | 170 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, false)) { |
171 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { | 171 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { |
172 if (pListBox->IsItemSelected(i)) { | 172 if (pListBox->IsItemSelected(i)) { |
173 m_State.Add(i); | 173 m_State.Add(i); |
174 } | 174 } |
175 } | 175 } |
176 } | 176 } |
177 } | 177 } |
178 | 178 |
179 void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView) { | 179 void CFFL_ListBox::RestoreState(CPDFSDK_PageView* pPageView) { |
180 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { | 180 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, false)) { |
181 for (int i = 0, sz = m_State.GetSize(); i < sz; i++) | 181 for (int i = 0, sz = m_State.GetSize(); i < sz; i++) |
182 pListBox->Select(m_State[i]); | 182 pListBox->Select(m_State[i]); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, | 186 CPWL_Wnd* CFFL_ListBox::ResetPDFWindow(CPDFSDK_PageView* pPageView, |
187 FX_BOOL bRestoreValue) { | 187 bool bRestoreValue) { |
188 if (bRestoreValue) | 188 if (bRestoreValue) |
189 SaveState(pPageView); | 189 SaveState(pPageView); |
190 | 190 |
191 DestroyPDFWindow(pPageView); | 191 DestroyPDFWindow(pPageView); |
192 | 192 |
193 CPWL_Wnd* pRet = nullptr; | 193 CPWL_Wnd* pRet = nullptr; |
194 | 194 |
195 if (bRestoreValue) { | 195 if (bRestoreValue) { |
196 RestoreState(pPageView); | 196 RestoreState(pPageView); |
197 pRet = GetPDFWindow(pPageView, FALSE); | 197 pRet = GetPDFWindow(pPageView, false); |
198 } else { | 198 } else { |
199 pRet = GetPDFWindow(pPageView, TRUE); | 199 pRet = GetPDFWindow(pPageView, true); |
200 } | 200 } |
201 | 201 |
202 m_pWidget->UpdateField(); | 202 m_pWidget->UpdateField(); |
203 | 203 |
204 return pRet; | 204 return pRet; |
205 } | 205 } |
OLD | NEW |