Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: fpdfsdk/src/formfiller/FFL_ComboBox.cpp

Issue 1512763013: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: nits Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_CheckBox.cpp ('k') | fpdfsdk/src/formfiller/FFL_FormFiller.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/include/formfiller/FFL_CBA_Fontmap.h" 7 #include "fpdfsdk/include/formfiller/FFL_CBA_Fontmap.h"
8 #include "fpdfsdk/include/formfiller/FFL_ComboBox.h" 8 #include "fpdfsdk/include/formfiller/FFL_ComboBox.h"
9 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h" 9 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
10 #include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" 10 #include "fpdfsdk/include/formfiller/FFL_IFormFiller.h"
11 #include "fpdfsdk/include/formfiller/FormFiller.h" 11 #include "fpdfsdk/include/formfiller/FormFiller.h"
12 12
13 /* ------------------------------- CFFL_ComboBox ------------------------------- 13 /* ------------------------------- CFFL_ComboBox -------------------------------
14 */ 14 */
15 15
16 CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) 16 CFFL_ComboBox::CFFL_ComboBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
17 : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) { 17 : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) {
18 m_State.nIndex = 0; 18 m_State.nIndex = 0;
19 m_State.nStart = 0; 19 m_State.nStart = 0;
20 m_State.nEnd = 0; 20 m_State.nEnd = 0;
21 } 21 }
22 22
23 CFFL_ComboBox::~CFFL_ComboBox() { 23 CFFL_ComboBox::~CFFL_ComboBox() {
24 delete m_pFontMap; 24 delete m_pFontMap;
25 } 25 }
26 26
27 PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() { 27 PWL_CREATEPARAM CFFL_ComboBox::GetCreateParam() {
28 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); 28 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
29 29
30 ASSERT(m_pWidget != NULL);
31
32 int nFlags = m_pWidget->GetFieldFlags(); 30 int nFlags = m_pWidget->GetFieldFlags();
33
34 if (nFlags & FIELDFLAG_EDIT) { 31 if (nFlags & FIELDFLAG_EDIT) {
35 cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT; 32 cp.dwFlags |= PCBS_ALLOWCUSTOMTEXT;
36 } 33 }
37 34
38 if (!m_pFontMap) { 35 if (!m_pFontMap) {
39 m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler()); 36 m_pFontMap = new CBA_FontMap(m_pWidget, GetSystemHandler());
40 m_pFontMap->Initial(); 37 m_pFontMap->Initial();
41 } 38 }
42 39
43 cp.pFontMap = m_pFontMap; 40 cp.pFontMap = m_pFontMap;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT)) 83 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT))
87 return nCurSel != m_pWidget->GetSelectedIndex(0); 84 return nCurSel != m_pWidget->GetSelectedIndex(0);
88 85
89 if (nCurSel >= 0) 86 if (nCurSel >= 0)
90 return nCurSel != m_pWidget->GetSelectedIndex(0); 87 return nCurSel != m_pWidget->GetSelectedIndex(0);
91 88
92 return pWnd->GetText() != m_pWidget->GetValue(); 89 return pWnd->GetText() != m_pWidget->GetValue();
93 } 90 }
94 91
95 void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) { 92 void CFFL_ComboBox::SaveData(CPDFSDK_PageView* pPageView) {
96 ASSERT(m_pWidget != NULL);
97
98 if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { 93 if (CPWL_ComboBox* pWnd = (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) {
99 CFX_WideString swText = pWnd->GetText(); 94 CFX_WideString swText = pWnd->GetText();
100 int32_t nCurSel = pWnd->GetSelect(); 95 int32_t nCurSel = pWnd->GetSelect();
101 96
102 // mantis:0004157 97 // mantis:0004157
103 FX_BOOL bSetValue = TRUE; 98 FX_BOOL bSetValue = TRUE;
104 99
105 if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) { 100 if (m_pWidget->GetFieldFlags() & FIELDFLAG_EDIT) {
106 if (nCurSel >= 0) { 101 if (nCurSel >= 0) {
107 if (swText != m_pWidget->GetOptionLabel(nCurSel)) 102 if (swText != m_pWidget->GetOptionLabel(nCurSel))
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 case CPDF_AAction::Validate: 153 case CPDF_AAction::Validate:
159 if (CPWL_ComboBox* pComboBox = 154 if (CPWL_ComboBox* pComboBox =
160 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { 155 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) {
161 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { 156 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
162 fa.sValue = pEdit->GetText(); 157 fa.sValue = pEdit->GetText();
163 } 158 }
164 } 159 }
165 break; 160 break;
166 case CPDF_AAction::LoseFocus: 161 case CPDF_AAction::LoseFocus:
167 case CPDF_AAction::GetFocus: 162 case CPDF_AAction::GetFocus:
168 ASSERT(m_pWidget != NULL);
169 fa.sValue = m_pWidget->GetValue(); 163 fa.sValue = m_pWidget->GetValue();
170 break; 164 break;
171 default: 165 default:
172 break; 166 break;
173 } 167 }
174 } 168 }
175 169
176 void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView, 170 void CFFL_ComboBox::SetActionData(CPDFSDK_PageView* pPageView,
177 CPDF_AAction::AActionType type, 171 CPDF_AAction::AActionType type,
178 const PDFSDK_FieldAction& fa) { 172 const PDFSDK_FieldAction& fa) {
(...skipping 21 matching lines...) Expand all
200 faOld.nSelStart != faNew.nSelStart || 194 faOld.nSelStart != faNew.nSelStart ||
201 faOld.sChange != faNew.sChange; 195 faOld.sChange != faNew.sChange;
202 default: 196 default:
203 break; 197 break;
204 } 198 }
205 199
206 return FALSE; 200 return FALSE;
207 } 201 }
208 202
209 void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) { 203 void CFFL_ComboBox::SaveState(CPDFSDK_PageView* pPageView) {
210 ASSERT(pPageView != NULL); 204 ASSERT(pPageView);
211 205
212 if (CPWL_ComboBox* pComboBox = 206 if (CPWL_ComboBox* pComboBox =
213 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) { 207 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, FALSE))) {
214 m_State.nIndex = pComboBox->GetSelect(); 208 m_State.nIndex = pComboBox->GetSelect();
215 209
216 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { 210 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
217 pEdit->GetSel(m_State.nStart, m_State.nEnd); 211 pEdit->GetSel(m_State.nStart, m_State.nEnd);
218 m_State.sValue = pEdit->GetText(); 212 m_State.sValue = pEdit->GetText();
219 } 213 }
220 } 214 }
221 } 215 }
222 216
223 void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) { 217 void CFFL_ComboBox::RestoreState(CPDFSDK_PageView* pPageView) {
224 ASSERT(pPageView != NULL); 218 ASSERT(pPageView);
225 219
226 if (CPWL_ComboBox* pComboBox = 220 if (CPWL_ComboBox* pComboBox =
227 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, TRUE))) { 221 static_cast<CPWL_ComboBox*>(GetPDFWindow(pPageView, TRUE))) {
228 if (m_State.nIndex >= 0) 222 if (m_State.nIndex >= 0)
229 pComboBox->SetSelect(m_State.nIndex); 223 pComboBox->SetSelect(m_State.nIndex);
230 else { 224 else {
231 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) { 225 if (CPWL_Edit* pEdit = pComboBox->GetEdit()) {
232 pEdit->SetText(m_State.sValue.c_str()); 226 pEdit->SetText(m_State.sValue.c_str());
233 pEdit->SetSel(m_State.nStart, m_State.nEnd); 227 pEdit->SetSel(m_State.nStart, m_State.nEnd);
234 } 228 }
(...skipping 15 matching lines...) Expand all
250 pRet = GetPDFWindow(pPageView, FALSE); 244 pRet = GetPDFWindow(pPageView, FALSE);
251 } else 245 } else
252 pRet = GetPDFWindow(pPageView, TRUE); 246 pRet = GetPDFWindow(pPageView, TRUE);
253 247
254 m_pWidget->UpdateField(); 248 m_pWidget->UpdateField();
255 249
256 return pRet; 250 return pRet;
257 } 251 }
258 252
259 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) { 253 void CFFL_ComboBox::OnSetFocus(CPWL_Wnd* pWnd) {
260 ASSERT(m_pApp != NULL); 254 ASSERT(m_pApp);
261
262 ASSERT(pWnd != NULL);
263 255
264 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { 256 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) {
265 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; 257 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
266 pEdit->SetCharSet(134); 258 pEdit->SetCharSet(134);
267 pEdit->SetCodePage(936); 259 pEdit->SetCodePage(936);
268 260
269 pEdit->SetReadyToInput(); 261 pEdit->SetReadyToInput();
270 CFX_WideString wsText = pEdit->GetText(); 262 CFX_WideString wsText = pEdit->GetText();
271 int nCharacters = wsText.GetLength(); 263 int nCharacters = wsText.GetLength();
272 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); 264 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
273 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); 265 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str();
274 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, 266 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer,
275 nCharacters, TRUE); 267 nCharacters, TRUE);
276 268
277 pEdit->SetEditNotify(this); 269 pEdit->SetEditNotify(this);
278 } 270 }
279 } 271 }
280 272
281 void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) { 273 void CFFL_ComboBox::OnKillFocus(CPWL_Wnd* pWnd) {
282 ASSERT(m_pApp != NULL); 274 ASSERT(m_pApp);
283 } 275 }
284 276
285 void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) { 277 void CFFL_ComboBox::OnAddUndo(CPWL_Edit* pEdit) {
286 ASSERT(pEdit != NULL); 278 ASSERT(pEdit);
287 } 279 }
288 280
289 CFX_WideString CFFL_ComboBox::GetSelectExportText() { 281 CFX_WideString CFFL_ComboBox::GetSelectExportText() {
290 CFX_WideString swRet; 282 CFX_WideString swRet;
291 283
292 int nExport = -1; 284 int nExport = -1;
293 CPDFSDK_PageView* pPageView = GetCurPageView(); 285 CPDFSDK_PageView* pPageView = GetCurPageView();
294 if (CPWL_ComboBox* pComboBox = 286 if (CPWL_ComboBox* pComboBox =
295 (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) { 287 (CPWL_ComboBox*)GetPDFWindow(pPageView, FALSE)) {
296 nExport = pComboBox->GetSelect(); 288 nExport = pComboBox->GetSelect();
297 } 289 }
298 290
299 if (nExport >= 0) { 291 if (nExport >= 0) {
300 if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) { 292 if (CPDF_FormField* pFormField = m_pWidget->GetFormField()) {
301 swRet = pFormField->GetOptionValue(nExport); 293 swRet = pFormField->GetOptionValue(nExport);
302 if (swRet.IsEmpty()) 294 if (swRet.IsEmpty())
303 swRet = pFormField->GetOptionLabel(nExport); 295 swRet = pFormField->GetOptionLabel(nExport);
304 } 296 }
305 } 297 }
306 298
307 return swRet; 299 return swRet;
308 } 300 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_CheckBox.cpp ('k') | fpdfsdk/src/formfiller/FFL_FormFiller.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698