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

Side by Side Diff: fpdfsdk/src/formfiller/FFL_TextField.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_RadioButton.cpp ('k') | fpdfsdk/src/fpdfformfill.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_TextField.h" 8 #include "fpdfsdk/include/formfiller/FFL_TextField.h"
9 9
10 /* ------------------------------- CFFL_TextField 10 /* ------------------------------- CFFL_TextField
11 * ------------------------------- */ 11 * ------------------------------- */
12 12
13 CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot) 13 CFFL_TextField::CFFL_TextField(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pAnnot)
14 : CFFL_FormFiller(pApp, pAnnot), 14 : CFFL_FormFiller(pApp, pAnnot), m_pFontMap(NULL) {
15 m_pFontMap(NULL) //,
16 // m_pSpellCheck(NULL)
17 {
18 m_State.nStart = m_State.nEnd = 0; 15 m_State.nStart = m_State.nEnd = 0;
19 } 16 }
20 17
21 CFFL_TextField::~CFFL_TextField() { 18 CFFL_TextField::~CFFL_TextField() {
22 delete m_pFontMap; 19 delete m_pFontMap;
23 } 20 }
24 21
25 PWL_CREATEPARAM CFFL_TextField::GetCreateParam() { 22 PWL_CREATEPARAM CFFL_TextField::GetCreateParam() {
26 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); 23 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
27 24
28 ASSERT(m_pWidget != NULL);
29 int nFlags = m_pWidget->GetFieldFlags(); 25 int nFlags = m_pWidget->GetFieldFlags();
30 26
31 if (nFlags & FIELDFLAG_PASSWORD) { 27 if (nFlags & FIELDFLAG_PASSWORD) {
32 cp.dwFlags |= PES_PASSWORD; 28 cp.dwFlags |= PES_PASSWORD;
33 } 29 }
34 30
35 if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK)) { 31 if (!(nFlags & FIELDFLAG_DONOTSPELLCHECK)) {
36 } 32 }
37 33
38 if (nFlags & FIELDFLAG_MULTILINE) { 34 if (nFlags & FIELDFLAG_MULTILINE) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 77
82 return cp; 78 return cp;
83 } 79 }
84 80
85 CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp, 81 CPWL_Wnd* CFFL_TextField::NewPDFWindow(const PWL_CREATEPARAM& cp,
86 CPDFSDK_PageView* pPageView) { 82 CPDFSDK_PageView* pPageView) {
87 CPWL_Edit* pWnd = new CPWL_Edit(); 83 CPWL_Edit* pWnd = new CPWL_Edit();
88 pWnd->AttachFFLData(this); 84 pWnd->AttachFFLData(this);
89 pWnd->Create(cp); 85 pWnd->Create(cp);
90 86
91 ASSERT(m_pApp != NULL);
92 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); 87 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
93 pWnd->SetFillerNotify(pIFormFiller); 88 pWnd->SetFillerNotify(pIFormFiller);
94 89
95 ASSERT(m_pWidget != NULL);
96 int32_t nMaxLen = m_pWidget->GetMaxLen(); 90 int32_t nMaxLen = m_pWidget->GetMaxLen();
97 CFX_WideString swValue = m_pWidget->GetValue(); 91 CFX_WideString swValue = m_pWidget->GetValue();
98 92
99 if (nMaxLen > 0) { 93 if (nMaxLen > 0) {
100 if (pWnd->HasFlag(PES_CHARARRAY)) { 94 if (pWnd->HasFlag(PES_CHARARRAY)) {
101 pWnd->SetCharArray(nMaxLen); 95 pWnd->SetCharArray(nMaxLen);
102 pWnd->SetAlignFormatV(PEAV_CENTER); 96 pWnd->SetAlignFormatV(PEAV_CENTER);
103 } else { 97 } else {
104 pWnd->SetLimitChar(nMaxLen); 98 pWnd->SetLimitChar(nMaxLen);
105 } 99 }
106 } 100 }
107 101
108 pWnd->SetText(swValue.c_str()); 102 pWnd->SetText(swValue.c_str());
109 return pWnd; 103 return pWnd;
110 } 104 }
111 105
112 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot, 106 FX_BOOL CFFL_TextField::OnChar(CPDFSDK_Annot* pAnnot,
113 FX_UINT nChar, 107 FX_UINT nChar,
114 FX_UINT nFlags) { 108 FX_UINT nFlags) {
115 switch (nChar) { 109 switch (nChar) {
116 case FWL_VKEY_Return: 110 case FWL_VKEY_Return:
117 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) { 111 if (!(m_pWidget->GetFieldFlags() & FIELDFLAG_MULTILINE)) {
118 CPDFSDK_PageView* pPageView = GetCurPageView(); 112 CPDFSDK_PageView* pPageView = GetCurPageView();
119 ASSERT(pPageView != NULL); 113 ASSERT(pPageView);
120 m_bValid = !m_bValid; 114 m_bValid = !m_bValid;
121 CPDF_Rect rcAnnot = pAnnot->GetRect(); 115 CPDF_Rect rcAnnot = pAnnot->GetRect();
122 m_pApp->FFI_Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left, 116 m_pApp->FFI_Invalidate(pAnnot->GetUnderlyingPage(), rcAnnot.left,
123 rcAnnot.top, rcAnnot.right, rcAnnot.bottom); 117 rcAnnot.top, rcAnnot.right, rcAnnot.bottom);
124 118
125 if (m_bValid) { 119 if (m_bValid) {
126 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE)) 120 if (CPWL_Wnd* pWnd = GetPDFWindow(pPageView, TRUE))
127 pWnd->SetFocus(); 121 pWnd->SetFocus();
128 } else { 122 } else {
129 if (CommitData(pPageView, nFlags)) { 123 if (CommitData(pPageView, nFlags)) {
130 DestroyPDFWindow(pPageView); 124 DestroyPDFWindow(pPageView);
131 return TRUE; 125 return TRUE;
132 } 126 }
133 return FALSE; 127 return FALSE;
134 } 128 }
135 } 129 }
136 break; 130 break;
137 case FWL_VKEY_Escape: { 131 case FWL_VKEY_Escape: {
138 CPDFSDK_PageView* pPageView = GetCurPageView(); 132 CPDFSDK_PageView* pPageView = GetCurPageView();
139 ASSERT(pPageView != NULL); 133 ASSERT(pPageView);
140 EscapeFiller(pPageView, TRUE); 134 EscapeFiller(pPageView, TRUE);
141 return TRUE; 135 return TRUE;
142 } 136 }
143 } 137 }
144 138
145 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags); 139 return CFFL_FormFiller::OnChar(pAnnot, nChar, nFlags);
146 } 140 }
147 141
148 FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) { 142 FX_BOOL CFFL_TextField::IsDataChanged(CPDFSDK_PageView* pPageView) {
149 ASSERT(m_pWidget != NULL);
150
151 if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) 143 if (CPWL_Edit* pEdit = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE))
152 return pEdit->GetText() != m_pWidget->GetValue(); 144 return pEdit->GetText() != m_pWidget->GetValue();
153 145
154 return FALSE; 146 return FALSE;
155 } 147 }
156 148
157 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) { 149 void CFFL_TextField::SaveData(CPDFSDK_PageView* pPageView) {
158 ASSERT(m_pWidget != NULL);
159
160 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { 150 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) {
161 CFX_WideString sOldValue = m_pWidget->GetValue(); 151 CFX_WideString sOldValue = m_pWidget->GetValue();
162 CFX_WideString sNewValue = pWnd->GetText(); 152 CFX_WideString sNewValue = pWnd->GetText();
163 153
164 m_pWidget->SetValue(sNewValue, FALSE); 154 m_pWidget->SetValue(sNewValue, FALSE);
165 m_pWidget->ResetFieldAppearance(TRUE); 155 m_pWidget->ResetFieldAppearance(TRUE);
166 m_pWidget->UpdateField(); 156 m_pWidget->UpdateField();
167 SetChangeMark(); 157 SetChangeMark();
168 } 158 }
169 } 159 }
(...skipping 14 matching lines...) Expand all
184 } 174 }
185 } 175 }
186 break; 176 break;
187 case CPDF_AAction::Validate: 177 case CPDF_AAction::Validate:
188 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { 178 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) {
189 fa.sValue = pWnd->GetText(); 179 fa.sValue = pWnd->GetText();
190 } 180 }
191 break; 181 break;
192 case CPDF_AAction::LoseFocus: 182 case CPDF_AAction::LoseFocus:
193 case CPDF_AAction::GetFocus: 183 case CPDF_AAction::GetFocus:
194 ASSERT(m_pWidget != NULL);
195 fa.sValue = m_pWidget->GetValue(); 184 fa.sValue = m_pWidget->GetValue();
196 break; 185 break;
197 default: 186 default:
198 break; 187 break;
199 } 188 }
200 } 189 }
201 190
202 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView, 191 void CFFL_TextField::SetActionData(CPDFSDK_PageView* pPageView,
203 CPDF_AAction::AActionType type, 192 CPDF_AAction::AActionType type,
204 const PDFSDK_FieldAction& fa) { 193 const PDFSDK_FieldAction& fa) {
(...skipping 19 matching lines...) Expand all
224 faOld.nSelStart != faNew.nSelStart || 213 faOld.nSelStart != faNew.nSelStart ||
225 faOld.sChange != faNew.sChange; 214 faOld.sChange != faNew.sChange;
226 default: 215 default:
227 break; 216 break;
228 } 217 }
229 218
230 return FALSE; 219 return FALSE;
231 } 220 }
232 221
233 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) { 222 void CFFL_TextField::SaveState(CPDFSDK_PageView* pPageView) {
234 ASSERT(pPageView != NULL); 223 ASSERT(pPageView);
235 224
236 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) { 225 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, FALSE)) {
237 pWnd->GetSel(m_State.nStart, m_State.nEnd); 226 pWnd->GetSel(m_State.nStart, m_State.nEnd);
238 m_State.sValue = pWnd->GetText(); 227 m_State.sValue = pWnd->GetText();
239 } 228 }
240 } 229 }
241 230
242 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) { 231 void CFFL_TextField::RestoreState(CPDFSDK_PageView* pPageView) {
243 ASSERT(pPageView != NULL); 232 ASSERT(pPageView);
244 233
245 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) { 234 if (CPWL_Edit* pWnd = (CPWL_Edit*)GetPDFWindow(pPageView, TRUE)) {
246 pWnd->SetText(m_State.sValue.c_str()); 235 pWnd->SetText(m_State.sValue.c_str());
247 pWnd->SetSel(m_State.nStart, m_State.nEnd); 236 pWnd->SetSel(m_State.nStart, m_State.nEnd);
248 } 237 }
249 } 238 }
250 239
251 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView, 240 CPWL_Wnd* CFFL_TextField::ResetPDFWindow(CPDFSDK_PageView* pPageView,
252 FX_BOOL bRestoreValue) { 241 FX_BOOL bRestoreValue) {
253 if (bRestoreValue) 242 if (bRestoreValue)
254 SaveState(pPageView); 243 SaveState(pPageView);
255 244
256 DestroyPDFWindow(pPageView); 245 DestroyPDFWindow(pPageView);
257 246
258 CPWL_Wnd* pRet = NULL; 247 CPWL_Wnd* pRet = NULL;
259 248
260 if (bRestoreValue) { 249 if (bRestoreValue) {
261 RestoreState(pPageView); 250 RestoreState(pPageView);
262 pRet = GetPDFWindow(pPageView, FALSE); 251 pRet = GetPDFWindow(pPageView, FALSE);
263 } else 252 } else
264 pRet = GetPDFWindow(pPageView, TRUE); 253 pRet = GetPDFWindow(pPageView, TRUE);
265 254
266 m_pWidget->UpdateField(); 255 m_pWidget->UpdateField();
267 256
268 return pRet; 257 return pRet;
269 } 258 }
270 259
271 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) { 260 void CFFL_TextField::OnSetFocus(CPWL_Wnd* pWnd) {
272 ASSERT(m_pApp != NULL); 261 ASSERT(m_pApp);
273
274 ASSERT(pWnd != NULL);
275
276 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) { 262 if (pWnd->GetClassName() == PWL_CLASSNAME_EDIT) {
277 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd; 263 CPWL_Edit* pEdit = (CPWL_Edit*)pWnd;
278 pEdit->SetCharSet(134); 264 pEdit->SetCharSet(134);
279 pEdit->SetCodePage(936); 265 pEdit->SetCodePage(936);
280 266
281 pEdit->SetReadyToInput(); 267 pEdit->SetReadyToInput();
282 CFX_WideString wsText = pEdit->GetText(); 268 CFX_WideString wsText = pEdit->GetText();
283 int nCharacters = wsText.GetLength(); 269 int nCharacters = wsText.GetLength();
284 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode(); 270 CFX_ByteString bsUTFText = wsText.UTF16LE_Encode();
285 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str(); 271 unsigned short* pBuffer = (unsigned short*)bsUTFText.c_str();
286 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer, 272 m_pApp->FFI_OnSetFieldInputFocus(m_pWidget->GetFormField(), pBuffer,
287 nCharacters, TRUE); 273 nCharacters, TRUE);
288 274
289 pEdit->SetEditNotify(this); 275 pEdit->SetEditNotify(this);
290 } 276 }
291 } 277 }
292 278
293 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) {} 279 void CFFL_TextField::OnKillFocus(CPWL_Wnd* pWnd) {}
294 280
295 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) {} 281 void CFFL_TextField::OnAddUndo(CPWL_Edit* pEdit) {}
OLDNEW
« no previous file with comments | « fpdfsdk/src/formfiller/FFL_RadioButton.cpp ('k') | fpdfsdk/src/fpdfformfill.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698