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

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

Issue 1529553003: Merge to XFA: Get rid of most instance of 'foo != NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: 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
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_FormFiller.h" 8 #include "fpdfsdk/include/formfiller/FFL_FormFiller.h"
9 #include "fpdfsdk/include/formfiller/FFL_IFormFiller.h" 9 #include "fpdfsdk/include/formfiller/FFL_IFormFiller.h"
10 #include "fpdfsdk/include/formfiller/FFL_ListBox.h" 10 #include "fpdfsdk/include/formfiller/FFL_ListBox.h"
11 #include "fpdfsdk/include/formfiller/FormFiller.h" 11 #include "fpdfsdk/include/formfiller/FormFiller.h"
12 12
13 #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f 13 #define FFL_DEFAULTLISTBOXFONTSIZE 12.0f
14 14
15 /* ------------------------------- CFFL_ListBox ------------------------------- 15 /* ------------------------------- CFFL_ListBox -------------------------------
16 */ 16 */
17 17
18 CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget) 18 CFFL_ListBox::CFFL_ListBox(CPDFDoc_Environment* pApp, CPDFSDK_Annot* pWidget)
19 : CFFL_FormFiller(pApp, pWidget), m_pFontMap(NULL) {} 19 : CFFL_FormFiller(pApp, pWidget), m_pFontMap(NULL) {}
20 20
21 CFFL_ListBox::~CFFL_ListBox() { 21 CFFL_ListBox::~CFFL_ListBox() {
22 delete m_pFontMap; 22 delete m_pFontMap;
23 } 23 }
24 24
25 PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() { 25 PWL_CREATEPARAM CFFL_ListBox::GetCreateParam() {
26 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam(); 26 PWL_CREATEPARAM cp = CFFL_FormFiller::GetCreateParam();
27 27
28 ASSERT(m_pWidget != NULL);
29 FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags(); 28 FX_DWORD dwFieldFlag = m_pWidget->GetFieldFlags();
30 29
31 if (dwFieldFlag & FIELDFLAG_MULTISELECT) { 30 if (dwFieldFlag & FIELDFLAG_MULTISELECT) {
32 cp.dwFlags |= PLBS_MULTIPLESEL; 31 cp.dwFlags |= PLBS_MULTIPLESEL;
33 } 32 }
34 33
35 cp.dwFlags |= PWS_VSCROLL; 34 cp.dwFlags |= PWS_VSCROLL;
36 35
37 if (cp.dwFlags & PWS_AUTOFONTSIZE) 36 if (cp.dwFlags & PWS_AUTOFONTSIZE)
38 cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE; 37 cp.fFontSize = FFL_DEFAULTLISTBOXFONTSIZE;
39 38
40 if (!m_pFontMap) { 39 if (!m_pFontMap) {
41 m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler()); 40 m_pFontMap = new CBA_FontMap(m_pWidget, m_pApp->GetSysHandler());
42 m_pFontMap->Initial(); 41 m_pFontMap->Initial();
43 } 42 }
44 cp.pFontMap = m_pFontMap; 43 cp.pFontMap = m_pFontMap;
45 44
46 return cp; 45 return cp;
47 } 46 }
48 47
49 CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp, 48 CPWL_Wnd* CFFL_ListBox::NewPDFWindow(const PWL_CREATEPARAM& cp,
50 CPDFSDK_PageView* pPageView) { 49 CPDFSDK_PageView* pPageView) {
51 CPWL_ListBox* pWnd = new CPWL_ListBox(); 50 CPWL_ListBox* pWnd = new CPWL_ListBox();
52 pWnd->AttachFFLData(this); 51 pWnd->AttachFFLData(this);
53 pWnd->Create(cp); 52 pWnd->Create(cp);
54 53
55 ASSERT(m_pApp != NULL);
56 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller(); 54 CFFL_IFormFiller* pIFormFiller = m_pApp->GetIFormFiller();
57 pWnd->SetFillerNotify(pIFormFiller); 55 pWnd->SetFillerNotify(pIFormFiller);
58 56
59 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) 57 for (int32_t i = 0, sz = m_pWidget->CountOptions(); i < sz; i++)
60 pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str()); 58 pWnd->AddString(m_pWidget->GetOptionLabel(i).c_str());
61 59
62 if (pWnd->HasFlag(PLBS_MULTIPLESEL)) { 60 if (pWnd->HasFlag(PLBS_MULTIPLESEL)) {
63 m_OriginSelections.clear(); 61 m_OriginSelections.clear();
64 62
65 FX_BOOL bSetCaret = FALSE; 63 FX_BOOL bSetCaret = FALSE;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 ++nSelCount; 106 ++nSelCount;
109 } 107 }
110 } 108 }
111 109
112 return nSelCount != m_OriginSelections.size(); 110 return nSelCount != m_OriginSelections.size();
113 } 111 }
114 return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0); 112 return pListBox->GetCurSel() != m_pWidget->GetSelectedIndex(0);
115 } 113 }
116 114
117 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) { 115 void CFFL_ListBox::SaveData(CPDFSDK_PageView* pPageView) {
118 ASSERT(m_pWidget != NULL); 116 ASSERT(m_pWidget);
119 117
120 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { 118 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
121 CFX_IntArray aOldSelect, aNewSelect; 119 CFX_IntArray aOldSelect, aNewSelect;
122 120
123 { 121 {
124 for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) { 122 for (int i = 0, sz = m_pWidget->CountOptions(); i < sz; i++) {
125 if (m_pWidget->IsOptionSelected(i)) { 123 if (m_pWidget->IsOptionSelected(i)) {
126 aOldSelect.Add(i); 124 aOldSelect.Add(i);
127 } 125 }
128 } 126 }
(...skipping 25 matching lines...) Expand all
154 void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView, 152 void CFFL_ListBox::GetActionData(CPDFSDK_PageView* pPageView,
155 CPDF_AAction::AActionType type, 153 CPDF_AAction::AActionType type,
156 PDFSDK_FieldAction& fa) { 154 PDFSDK_FieldAction& fa) {
157 switch (type) { 155 switch (type) {
158 case CPDF_AAction::Validate: 156 case CPDF_AAction::Validate:
159 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { 157 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
160 fa.sValue = L""; 158 fa.sValue = L"";
161 } else { 159 } else {
162 if (CPWL_ListBox* pListBox = 160 if (CPWL_ListBox* pListBox =
163 (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { 161 (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
164 ASSERT(m_pWidget != NULL);
165 int32_t nCurSel = pListBox->GetCurSel(); 162 int32_t nCurSel = pListBox->GetCurSel();
166 if (nCurSel >= 0) 163 if (nCurSel >= 0)
167 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); 164 fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
168 } 165 }
169 } 166 }
170 break; 167 break;
171 case CPDF_AAction::LoseFocus: 168 case CPDF_AAction::LoseFocus:
172 case CPDF_AAction::GetFocus: 169 case CPDF_AAction::GetFocus:
173 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) { 170 if (m_pWidget->GetFieldFlags() & FIELDFLAG_MULTISELECT) {
174 fa.sValue = L""; 171 fa.sValue = L"";
175 } else { 172 } else {
176 ASSERT(m_pWidget != NULL);
177 int32_t nCurSel = m_pWidget->GetSelectedIndex(0); 173 int32_t nCurSel = m_pWidget->GetSelectedIndex(0);
178 if (nCurSel >= 0) 174 if (nCurSel >= 0)
179 fa.sValue = m_pWidget->GetOptionLabel(nCurSel); 175 fa.sValue = m_pWidget->GetOptionLabel(nCurSel);
180 } 176 }
181 break; 177 break;
182 default: 178 default:
183 break; 179 break;
184 } 180 }
185 } 181 }
186 182
187 void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView, 183 void CFFL_ListBox::SetActionData(CPDFSDK_PageView* pPageView,
188 CPDF_AAction::AActionType type, 184 CPDF_AAction::AActionType type,
189 const PDFSDK_FieldAction& fa) {} 185 const PDFSDK_FieldAction& fa) {}
190 186
191 void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) { 187 void CFFL_ListBox::SaveState(CPDFSDK_PageView* pPageView) {
192 ASSERT(pPageView != NULL); 188 ASSERT(pPageView);
193 189
194 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) { 190 if (CPWL_ListBox* pListBox = (CPWL_ListBox*)GetPDFWindow(pPageView, FALSE)) {
195 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) { 191 for (int32_t i = 0, sz = pListBox->GetCount(); i < sz; i++) {
196 if (pListBox->IsItemSelected(i)) { 192 if (pListBox->IsItemSelected(i)) {
197 m_State.Add(i); 193 m_State.Add(i);
198 } 194 }
199 } 195 }
200 } 196 }
201 } 197 }
202 198
(...skipping 16 matching lines...) Expand all
219 if (bRestoreValue) { 215 if (bRestoreValue) {
220 RestoreState(pPageView); 216 RestoreState(pPageView);
221 pRet = GetPDFWindow(pPageView, FALSE); 217 pRet = GetPDFWindow(pPageView, FALSE);
222 } else 218 } else
223 pRet = GetPDFWindow(pPageView, TRUE); 219 pRet = GetPDFWindow(pPageView, TRUE);
224 220
225 m_pWidget->UpdateField(); 221 m_pWidget->UpdateField();
226 222
227 return pRet; 223 return pRet;
228 } 224 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698