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

Side by Side Diff: core/fpdfdoc/cpdf_interform.cpp

Issue 2510223002: Make CPDF_Dictionary use unique pointers. (Closed)
Patch Set: Plug leaks Created 4 years, 1 month 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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 <vector> 7 #include <vector>
8 8
9 #include "core/fpdfapi/font/cpdf_font.h" 9 #include "core/fpdfapi/font/cpdf_font.h"
10 #include "core/fpdfapi/font/cpdf_fontencoding.h" 10 #include "core/fpdfapi/font/cpdf_fontencoding.h"
11 #include "core/fpdfapi/page/cpdf_page.h" 11 #include "core/fpdfapi/page/cpdf_page.h"
12 #include "core/fpdfapi/parser/cfdf_document.h" 12 #include "core/fpdfapi/parser/cfdf_document.h"
13 #include "core/fpdfapi/parser/cpdf_array.h" 13 #include "core/fpdfapi/parser/cpdf_array.h"
14 #include "core/fpdfapi/parser/cpdf_document.h" 14 #include "core/fpdfapi/parser/cpdf_document.h"
15 #include "core/fpdfapi/parser/cpdf_name.h"
15 #include "core/fpdfapi/parser/cpdf_reference.h" 16 #include "core/fpdfapi/parser/cpdf_reference.h"
16 #include "core/fpdfapi/parser/cpdf_string.h" 17 #include "core/fpdfapi/parser/cpdf_string.h"
17 #include "core/fpdfdoc/cpdf_filespec.h" 18 #include "core/fpdfdoc/cpdf_filespec.h"
18 #include "core/fpdfdoc/cpdf_formcontrol.h" 19 #include "core/fpdfdoc/cpdf_formcontrol.h"
19 #include "core/fpdfdoc/cpdf_interform.h" 20 #include "core/fpdfdoc/cpdf_interform.h"
20 #include "core/fxge/cfx_substfont.h" 21 #include "core/fxge/cfx_substfont.h"
21 #include "core/fxge/fx_font.h" 22 #include "core/fxge/fx_font.h"
22 #include "third_party/base/stl_util.h" 23 #include "third_party/base/stl_util.h"
23 24
24 namespace { 25 namespace {
(...skipping 28 matching lines...) Expand all
53 CPDF_Document* pDocument, 54 CPDF_Document* pDocument,
54 const CPDF_Font* pFont, 55 const CPDF_Font* pFont,
55 CFX_ByteString& csNameTag); 56 CFX_ByteString& csNameTag);
56 57
57 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) { 58 void InitDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument) {
58 if (!pDocument) 59 if (!pDocument)
59 return; 60 return;
60 61
61 if (!pFormDict) { 62 if (!pFormDict) {
62 pFormDict = pDocument->NewIndirect<CPDF_Dictionary>(); 63 pFormDict = pDocument->NewIndirect<CPDF_Dictionary>();
63 pDocument->GetRoot()->SetReferenceFor("AcroForm", pDocument, 64 pDocument->GetRoot()->SetNewFor<CPDF_Reference>("AcroForm", pDocument,
64 pFormDict->GetObjNum()); 65 pFormDict->GetObjNum());
65 } 66 }
66 67
67 CFX_ByteString csDA; 68 CFX_ByteString csDA;
68 if (!pFormDict->KeyExist("DR")) { 69 if (!pFormDict->KeyExist("DR")) {
69 CFX_ByteString csBaseName; 70 CFX_ByteString csBaseName;
70 CFX_ByteString csDefault; 71 CFX_ByteString csDefault;
71 uint8_t charSet = CPDF_InterForm::GetNativeCharSet(); 72 uint8_t charSet = CPDF_InterForm::GetNativeCharSet();
72 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica"); 73 CPDF_Font* pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
73 if (pFont) { 74 if (pFont) {
74 AddFont(pFormDict, pDocument, pFont, csBaseName); 75 AddFont(pFormDict, pDocument, pFont, csBaseName);
(...skipping 12 matching lines...) Expand all
87 } 88 }
88 } 89 }
89 if (pFont) 90 if (pFont)
90 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf"; 91 csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf";
91 } 92 }
92 if (!csDA.IsEmpty()) 93 if (!csDA.IsEmpty())
93 csDA += " "; 94 csDA += " ";
94 95
95 csDA += "0 g"; 96 csDA += "0 g";
96 if (!pFormDict->KeyExist("DA")) 97 if (!pFormDict->KeyExist("DA"))
97 pFormDict->SetStringFor("DA", csDA); 98 pFormDict->SetNewFor<CPDF_String>("DA", csDA, false);
98 } 99 }
99 100
100 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict, 101 CPDF_Font* GetFont(CPDF_Dictionary* pFormDict,
101 CPDF_Document* pDocument, 102 CPDF_Document* pDocument,
102 CFX_ByteString csNameTag) { 103 CFX_ByteString csNameTag) {
103 CFX_ByteString csAlias = PDF_NameDecode(csNameTag); 104 CFX_ByteString csAlias = PDF_NameDecode(csNameTag);
104 if (!pFormDict || csAlias.IsEmpty()) 105 if (!pFormDict || csAlias.IsEmpty())
105 return nullptr; 106 return nullptr;
106 107
107 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); 108 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
(...skipping 23 matching lines...) Expand all
131 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); 132 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
132 if (!pDR) 133 if (!pDR)
133 return nullptr; 134 return nullptr;
134 135
135 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); 136 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
136 if (!pFonts) 137 if (!pFonts)
137 return nullptr; 138 return nullptr;
138 139
139 for (const auto& it : *pFonts) { 140 for (const auto& it : *pFonts) {
140 const CFX_ByteString& csKey = it.first; 141 const CFX_ByteString& csKey = it.first;
141 CPDF_Object* pObj = it.second; 142 if (!it.second)
142 if (!pObj)
143 continue; 143 continue;
144 144
145 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); 145 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect());
146 if (!pElement) 146 if (!pElement)
147 continue; 147 continue;
148 if (pElement->GetStringFor("Type") != "Font") 148 if (pElement->GetStringFor("Type") != "Font")
149 continue; 149 continue;
150 CPDF_Font* pFind = pDocument->LoadFont(pElement); 150 CPDF_Font* pFind = pDocument->LoadFont(pElement);
151 if (!pFind) 151 if (!pFind)
152 continue; 152 continue;
153 153
154 CFX_SubstFont* pSubst = pFind->GetSubstFont(); 154 CFX_SubstFont* pSubst = pFind->GetSubstFont();
155 if (!pSubst) 155 if (!pSubst)
(...skipping 16 matching lines...) Expand all
172 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); 172 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
173 if (!pDR) 173 if (!pDR)
174 return false; 174 return false;
175 175
176 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); 176 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
177 if (!pFonts) 177 if (!pFonts)
178 return false; 178 return false;
179 179
180 for (const auto& it : *pFonts) { 180 for (const auto& it : *pFonts) {
181 const CFX_ByteString& csKey = it.first; 181 const CFX_ByteString& csKey = it.first;
182 CPDF_Object* pObj = it.second; 182 if (!it.second)
183 if (!pObj)
184 continue; 183 continue;
185 184 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect());
186 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
187 if (!pElement) 185 if (!pElement)
188 continue; 186 continue;
189 if (pElement->GetStringFor("Type") != "Font") 187 if (pElement->GetStringFor("Type") != "Font")
190 continue; 188 continue;
191 if (pFont->GetFontDict() == pElement) { 189 if (pFont->GetFontDict() == pElement) {
192 csNameTag = csKey; 190 csNameTag = csKey;
193 return true; 191 return true;
194 } 192 }
195 } 193 }
196 return false; 194 return false;
(...skipping 12 matching lines...) Expand all
209 return false; 207 return false;
210 208
211 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); 209 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
212 if (!pFonts) 210 if (!pFonts)
213 return false; 211 return false;
214 if (csFontName.GetLength() > 0) 212 if (csFontName.GetLength() > 0)
215 csFontName.Remove(' '); 213 csFontName.Remove(' ');
216 214
217 for (const auto& it : *pFonts) { 215 for (const auto& it : *pFonts) {
218 const CFX_ByteString& csKey = it.first; 216 const CFX_ByteString& csKey = it.first;
219 CPDF_Object* pObj = it.second; 217 if (!it.second)
220 if (!pObj)
221 continue; 218 continue;
222 219
223 CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect()); 220 CPDF_Dictionary* pElement = ToDictionary(it.second->GetDirect());
224 if (!pElement) 221 if (!pElement)
225 continue; 222 continue;
226 if (pElement->GetStringFor("Type") != "Font") 223 if (pElement->GetStringFor("Type") != "Font")
227 continue; 224 continue;
228
229 pFont = pDocument->LoadFont(pElement); 225 pFont = pDocument->LoadFont(pElement);
230 if (!pFont) 226 if (!pFont)
231 continue; 227 continue;
232 228
233 CFX_ByteString csBaseFont; 229 CFX_ByteString csBaseFont;
234 csBaseFont = pFont->GetBaseFont(); 230 csBaseFont = pFont->GetBaseFont();
235 csBaseFont.Remove(' '); 231 csBaseFont.Remove(' ');
236 if (csBaseFont == csFontName) { 232 if (csBaseFont == csFontName) {
237 csNameTag = csKey; 233 csNameTag = csKey;
238 return true; 234 return true;
(...skipping 13 matching lines...) Expand all
252 248
253 CFX_ByteString csTag; 249 CFX_ByteString csTag;
254 if (FindFont(pFormDict, pFont, csTag)) { 250 if (FindFont(pFormDict, pFont, csTag)) {
255 csNameTag = csTag; 251 csNameTag = csTag;
256 return; 252 return;
257 } 253 }
258 if (!pFormDict) 254 if (!pFormDict)
259 InitDict(pFormDict, pDocument); 255 InitDict(pFormDict, pDocument);
260 256
261 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR"); 257 CPDF_Dictionary* pDR = pFormDict->GetDictFor("DR");
262 if (!pDR) { 258 if (!pDR)
263 pDR = new CPDF_Dictionary(pDocument->GetByteStringPool()); 259 pDR = pFormDict->SetNewFor<CPDF_Dictionary>("DR");
264 pFormDict->SetFor("DR", pDR); 260
265 }
266 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font"); 261 CPDF_Dictionary* pFonts = pDR->GetDictFor("Font");
267 if (!pFonts) { 262 if (!pFonts)
268 pFonts = new CPDF_Dictionary(pDocument->GetByteStringPool()); 263 pFonts = pDR->SetNewFor<CPDF_Dictionary>("Font");
269 pDR->SetFor("Font", pFonts); 264
270 }
271 if (csNameTag.IsEmpty()) 265 if (csNameTag.IsEmpty())
272 csNameTag = pFont->GetBaseFont(); 266 csNameTag = pFont->GetBaseFont();
273 267
274 csNameTag.Remove(' '); 268 csNameTag.Remove(' ');
275 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4, 269 csNameTag = CPDF_InterForm::GenerateNewResourceName(pDR, "Font", 4,
276 csNameTag.c_str()); 270 csNameTag.c_str());
277 pFonts->SetReferenceFor(csNameTag, pDocument, 271 pFonts->SetNewFor<CPDF_Reference>(csNameTag, pDocument,
278 pFont->GetFontDict()->GetObjNum()); 272 pFont->GetFontDict()->GetObjNum());
279 } 273 }
280 274
281 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict, 275 CPDF_Font* AddNativeFont(CPDF_Dictionary*& pFormDict,
282 CPDF_Document* pDocument, 276 CPDF_Document* pDocument,
283 uint8_t charSet, 277 uint8_t charSet,
284 CFX_ByteString& csNameTag) { 278 CFX_ByteString& csNameTag) {
285 if (!pFormDict) 279 if (!pFormDict)
286 InitDict(pFormDict, pDocument); 280 InitDict(pFormDict, pDocument);
287 281
288 CFX_ByteString csTemp; 282 CFX_ByteString csTemp;
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1098 pFieldDict->GetStringFor("Subtype") == "Widget") { 1092 pFieldDict->GetStringFor("Subtype") == "Widget") {
1099 pParent = pFieldDict->GetDictFor("Parent"); 1093 pParent = pFieldDict->GetDictFor("Parent");
1100 if (!pParent) 1094 if (!pParent)
1101 pParent = pFieldDict; 1095 pParent = pFieldDict;
1102 } 1096 }
1103 1097
1104 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) { 1098 if (pParent && pParent != pFieldDict && !pParent->KeyExist("FT")) {
1105 if (pFieldDict->KeyExist("FT")) { 1099 if (pFieldDict->KeyExist("FT")) {
1106 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT"); 1100 CPDF_Object* pFTValue = pFieldDict->GetDirectObjectFor("FT");
1107 if (pFTValue) 1101 if (pFTValue)
1108 pParent->SetFor("FT", pFTValue->Clone().release()); 1102 pParent->SetFor("FT", pFTValue->Clone());
1109 } 1103 }
1110 1104
1111 if (pFieldDict->KeyExist("Ff")) { 1105 if (pFieldDict->KeyExist("Ff")) {
1112 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff"); 1106 CPDF_Object* pFfValue = pFieldDict->GetDirectObjectFor("Ff");
1113 if (pFfValue) 1107 if (pFfValue)
1114 pParent->SetFor("Ff", pFfValue->Clone().release()); 1108 pParent->SetFor("Ff", pFfValue->Clone());
1115 } 1109 }
1116 } 1110 }
1117 1111
1118 pField = new CPDF_FormField(this, pParent); 1112 pField = new CPDF_FormField(this, pParent);
1119 CPDF_Object* pTObj = pDict->GetObjectFor("T"); 1113 CPDF_Object* pTObj = pDict->GetObjectFor("T");
1120 if (ToReference(pTObj)) { 1114 if (ToReference(pTObj)) {
1121 std::unique_ptr<CPDF_Object> pClone = pTObj->CloneDirectObject(); 1115 std::unique_ptr<CPDF_Object> pClone = pTObj->CloneDirectObject();
1122 if (pClone) 1116 if (pClone)
1123 pDict->SetFor("T", pClone.release()); 1117 pDict->SetFor("T", std::move(pClone));
1124 else 1118 else
1125 pDict->SetNameFor("T", ""); 1119 pDict->SetNewFor<CPDF_Name>("T", "");
1126 } 1120 }
1127 m_pFieldTree->SetField(csWName, pField); 1121 m_pFieldTree->SetField(csWName, pField);
1128 } 1122 }
1129 1123
1130 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids"); 1124 CPDF_Array* pKids = pFieldDict->GetArrayFor("Kids");
1131 if (pKids) { 1125 if (pKids) {
1132 for (size_t i = 0; i < pKids->GetCount(); i++) { 1126 for (size_t i = 0; i < pKids->GetCount(); i++) {
1133 CPDF_Dictionary* pKid = pKids->GetDictAt(i); 1127 CPDF_Dictionary* pKid = pKids->GetDictAt(i);
1134 if (!pKid) 1128 if (!pKid)
1135 continue; 1129 continue;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 bool bIncludeOrExclude, 1197 bool bIncludeOrExclude,
1204 bool bSimpleFileSpec) const { 1198 bool bSimpleFileSpec) const {
1205 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc(); 1199 CFDF_Document* pDoc = CFDF_Document::CreateNewDoc();
1206 if (!pDoc) 1200 if (!pDoc)
1207 return nullptr; 1201 return nullptr;
1208 1202
1209 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF"); 1203 CPDF_Dictionary* pMainDict = pDoc->GetRoot()->GetDictFor("FDF");
1210 if (!pdf_path.IsEmpty()) { 1204 if (!pdf_path.IsEmpty()) {
1211 if (bSimpleFileSpec) { 1205 if (bSimpleFileSpec) {
1212 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path); 1206 CFX_WideString wsFilePath = CPDF_FileSpec::EncodeFileName(pdf_path);
1213 pMainDict->SetStringFor("F", CFX_ByteString::FromUnicode(wsFilePath)); 1207 pMainDict->SetNewFor<CPDF_String>(
1214 pMainDict->SetStringFor("UF", PDF_EncodeText(wsFilePath)); 1208 "F", CFX_ByteString::FromUnicode(wsFilePath), false);
1209 pMainDict->SetNewFor<CPDF_String>("UF", PDF_EncodeText(wsFilePath),
1210 false);
1215 } else { 1211 } else {
1216 CPDF_FileSpec filespec(pDoc->GetByteStringPool()); 1212 CPDF_FileSpec filespec(pDoc->GetByteStringPool());
1217 filespec.SetFileName(pdf_path); 1213 filespec.SetFileName(pdf_path);
1218 pMainDict->SetFor("F", filespec.GetObj()); 1214 pMainDict->SetFor("F", pdfium::WrapUnique(filespec.GetObj()));
1219 } 1215 }
1220 } 1216 }
1221 1217
1222 CPDF_Array* pFields = new CPDF_Array; 1218 CPDF_Array* pFields = pMainDict->SetNewFor<CPDF_Array>("Fields");
1223 pMainDict->SetFor("Fields", pFields);
1224 size_t nCount = m_pFieldTree->m_Root.CountFields(); 1219 size_t nCount = m_pFieldTree->m_Root.CountFields();
1225 for (size_t i = 0; i < nCount; ++i) { 1220 for (size_t i = 0; i < nCount; ++i) {
1226 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i); 1221 CPDF_FormField* pField = m_pFieldTree->m_Root.GetFieldAtIndex(i);
1227 if (!pField || pField->GetType() == CPDF_FormField::PushButton) 1222 if (!pField || pField->GetType() == CPDF_FormField::PushButton)
1228 continue; 1223 continue;
1229 1224
1230 uint32_t dwFlags = pField->GetFieldFlags(); 1225 uint32_t dwFlags = pField->GetFieldFlags();
1231 if (dwFlags & 0x04) 1226 if (dwFlags & 0x04)
1232 continue; 1227 continue;
1233 1228
1234 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) { 1229 if (bIncludeOrExclude == pdfium::ContainsValue(fields, pField)) {
1235 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty()) 1230 if ((dwFlags & 0x02) != 0 && pField->m_pDict->GetStringFor("V").IsEmpty())
1236 continue; 1231 continue;
1237 1232
1238 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict()); 1233 CFX_WideString fullname = FPDF_GetFullName(pField->GetFieldDict());
1239 auto pFieldDict = 1234 auto pFieldDict =
1240 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool()); 1235 pdfium::MakeUnique<CPDF_Dictionary>(pDoc->GetByteStringPool());
1241 pFieldDict->SetFor("T", new CPDF_String(fullname)); 1236 pFieldDict->SetNewFor<CPDF_String>("T", fullname);
1242 if (pField->GetType() == CPDF_FormField::CheckBox || 1237 if (pField->GetType() == CPDF_FormField::CheckBox ||
1243 pField->GetType() == CPDF_FormField::RadioButton) { 1238 pField->GetType() == CPDF_FormField::RadioButton) {
1244 CFX_WideString csExport = pField->GetCheckValue(false); 1239 CFX_WideString csExport = pField->GetCheckValue(false);
1245 CFX_ByteString csBExport = PDF_EncodeText(csExport); 1240 CFX_ByteString csBExport = PDF_EncodeText(csExport);
1246 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt"); 1241 CPDF_Object* pOpt = FPDF_GetFieldAttr(pField->m_pDict, "Opt");
1247 if (pOpt) 1242 if (pOpt)
1248 pFieldDict->SetStringFor("V", csBExport); 1243 pFieldDict->SetNewFor<CPDF_String>("V", csBExport, false);
1249 else 1244 else
1250 pFieldDict->SetNameFor("V", csBExport); 1245 pFieldDict->SetNewFor<CPDF_Name>("V", csBExport);
1251 } else { 1246 } else {
1252 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V"); 1247 CPDF_Object* pV = FPDF_GetFieldAttr(pField->m_pDict, "V");
1253 if (pV) 1248 if (pV)
1254 pFieldDict->SetFor("V", pV->CloneDirectObject().release()); 1249 pFieldDict->SetFor("V", pV->CloneDirectObject());
1255 } 1250 }
1256 pFields->Add(std::move(pFieldDict)); 1251 pFields->Add(std::move(pFieldDict));
1257 } 1252 }
1258 } 1253 }
1259 return pDoc; 1254 return pDoc;
1260 } 1255 }
1261 1256
1262 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict, 1257 void CPDF_InterForm::FDF_ImportField(CPDF_Dictionary* pFieldDict,
1263 const CFX_WideString& parent_name, 1258 const CFX_WideString& parent_name,
1264 bool bNotify, 1259 bool bNotify,
(...skipping 17 matching lines...) Expand all
1282 if (!pFieldDict->KeyExist("V")) 1277 if (!pFieldDict->KeyExist("V"))
1283 return; 1278 return;
1284 1279
1285 CPDF_FormField* pField = m_pFieldTree->GetField(name); 1280 CPDF_FormField* pField = m_pFieldTree->GetField(name);
1286 if (!pField) 1281 if (!pField)
1287 return; 1282 return;
1288 1283
1289 CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding); 1284 CFX_WideString csWValue = GetFieldValue(*pFieldDict, m_bsEncoding);
1290 int iType = pField->GetFieldType(); 1285 int iType = pField->GetFieldType();
1291 if (bNotify && m_pFormNotify) { 1286 if (bNotify && m_pFormNotify) {
1292 int iRet = 0; 1287 if (iType == FIELDTYPE_LISTBOX) {
1293 if (iType == FIELDTYPE_LISTBOX) 1288 if (m_pFormNotify->BeforeSelectionChange(pField, csWValue) < 0)
1294 iRet = m_pFormNotify->BeforeSelectionChange(pField, csWValue); 1289 return;
1295 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) 1290 } else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) {
1296 iRet = m_pFormNotify->BeforeValueChange(pField, csWValue); 1291 if (m_pFormNotify->BeforeValueChange(pField, csWValue) < 0)
1297 1292 return;
1298 if (iRet < 0) 1293 }
1299 return;
1300 } 1294 }
1301
1302 pField->SetValue(csWValue); 1295 pField->SetValue(csWValue);
1303 CPDF_FormField::Type eType = pField->GetType(); 1296 CPDF_FormField::Type eType = pField->GetType();
1304 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) && 1297 if ((eType == CPDF_FormField::ListBox || eType == CPDF_FormField::ComboBox) &&
1305 pFieldDict->KeyExist("Opt")) { 1298 pFieldDict->KeyExist("Opt")) {
1306 pField->m_pDict->SetFor( 1299 pField->m_pDict->SetFor(
1307 "Opt", 1300 "Opt", pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject());
1308 pFieldDict->GetDirectObjectFor("Opt")->CloneDirectObject().release());
1309 } 1301 }
1310 1302
1311 if (bNotify && m_pFormNotify) { 1303 if (bNotify && m_pFormNotify) {
1312 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON) 1304 if (iType == FIELDTYPE_CHECKBOX || iType == FIELDTYPE_RADIOBUTTON)
1313 m_pFormNotify->AfterCheckedStatusChange(pField); 1305 m_pFormNotify->AfterCheckedStatusChange(pField);
1314 else if (iType == FIELDTYPE_LISTBOX) 1306 else if (iType == FIELDTYPE_LISTBOX)
1315 m_pFormNotify->AfterSelectionChange(pField); 1307 m_pFormNotify->AfterSelectionChange(pField);
1316 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD) 1308 else if (iType == FIELDTYPE_COMBOBOX || iType == FIELDTYPE_TEXTFIELD)
1317 m_pFormNotify->AfterValueChange(pField); 1309 m_pFormNotify->AfterValueChange(pField);
1318 } 1310 }
1319 } 1311 }
1320 1312
1321 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) { 1313 void CPDF_InterForm::SetFormNotify(IPDF_FormNotify* pNotify) {
1322 m_pFormNotify = pNotify; 1314 m_pFormNotify = pNotify;
1323 } 1315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698