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/javascript/Field.h" | 7 #include "fpdfsdk/javascript/Field.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 IMPLEMENT_JS_CLASS(CJS_Field, Field) | 115 IMPLEMENT_JS_CLASS(CJS_Field, Field) |
116 | 116 |
117 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { | 117 void CJS_Field::InitInstance(IJS_Runtime* pIRuntime) { |
118 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); | 118 CJS_Runtime* pRuntime = static_cast<CJS_Runtime*>(pIRuntime); |
119 Field* pField = static_cast<Field*>(GetEmbedObject()); | 119 Field* pField = static_cast<Field*>(GetEmbedObject()); |
120 pField->SetIsolate(pRuntime->GetIsolate()); | 120 pField->SetIsolate(pRuntime->GetIsolate()); |
121 } | 121 } |
122 | 122 |
123 Field::Field(CJS_Object* pJSObject) | 123 Field::Field(CJS_Object* pJSObject) |
124 : CJS_EmbedObj(pJSObject), | 124 : CJS_EmbedObj(pJSObject), |
125 m_pJSDoc(NULL), | 125 m_pJSDoc(nullptr), |
126 m_pDocument(NULL), | 126 m_pDocument(nullptr), |
127 m_nFormControlIndex(-1), | 127 m_nFormControlIndex(-1), |
128 m_bCanSet(FALSE), | 128 m_bCanSet(FALSE), |
129 m_bDelay(FALSE), | 129 m_bDelay(FALSE), |
130 m_isolate(NULL) {} | 130 m_isolate(nullptr) {} |
131 | 131 |
132 Field::~Field() {} | 132 Field::~Field() {} |
133 | 133 |
134 // note: iControlNo = -1, means not a widget. | 134 // note: iControlNo = -1, means not a widget. |
135 void Field::ParseFieldName(const std::wstring& strFieldNameParsed, | 135 void Field::ParseFieldName(const std::wstring& strFieldNameParsed, |
136 std::wstring& strFieldName, | 136 std::wstring& strFieldName, |
137 int& iControlNo) { | 137 int& iControlNo) { |
138 int iStart = strFieldNameParsed.find_last_of(L'.'); | 138 int iStart = strFieldNameParsed.find_last_of(L'.'); |
139 if (iStart == -1) { | 139 if (iStart == -1) { |
140 strFieldName = strFieldNameParsed; | 140 strFieldName = strFieldNameParsed; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (pWidget) { | 255 if (pWidget) { |
256 if (bResetAP) { | 256 if (bResetAP) { |
257 int nFieldType = pWidget->GetFieldType(); | 257 int nFieldType = pWidget->GetFieldType(); |
258 if (nFieldType == FIELDTYPE_COMBOBOX || | 258 if (nFieldType == FIELDTYPE_COMBOBOX || |
259 nFieldType == FIELDTYPE_TEXTFIELD) { | 259 nFieldType == FIELDTYPE_TEXTFIELD) { |
260 FX_BOOL bFormated = FALSE; | 260 FX_BOOL bFormated = FALSE; |
261 CFX_WideString sValue = pWidget->OnFormat(bFormated); | 261 CFX_WideString sValue = pWidget->OnFormat(bFormated); |
262 if (bFormated) | 262 if (bFormated) |
263 pWidget->ResetAppearance(sValue.c_str(), FALSE); | 263 pWidget->ResetAppearance(sValue.c_str(), FALSE); |
264 else | 264 else |
265 pWidget->ResetAppearance(NULL, FALSE); | 265 pWidget->ResetAppearance(nullptr, FALSE); |
266 } else { | 266 } else { |
267 pWidget->ResetAppearance(NULL, FALSE); | 267 pWidget->ResetAppearance(nullptr, FALSE); |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 if (bRefresh) { | 271 if (bRefresh) { |
272 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); | 272 CPDFSDK_InterForm* pInterForm = pWidget->GetInterForm(); |
273 CPDFSDK_Document* pDoc = pInterForm->GetDocument(); | 273 CPDFSDK_Document* pDoc = pInterForm->GetDocument(); |
274 pDoc->UpdateAllViews(NULL, pWidget); | 274 pDoc->UpdateAllViews(nullptr, pWidget); |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 if (bChangeMark) | 278 if (bChangeMark) |
279 pDocument->SetChangeMark(); | 279 pDocument->SetChangeMark(); |
280 } | 280 } |
281 | 281 |
282 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, | 282 CPDFSDK_Widget* Field::GetWidget(CPDFSDK_Document* pDocument, |
283 CPDF_FormControl* pFormControl) { | 283 CPDF_FormControl* pFormControl) { |
284 CPDFSDK_InterForm* pInterForm = | 284 CPDFSDK_InterForm* pInterForm = |
285 static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm()); | 285 static_cast<CPDFSDK_InterForm*>(pDocument->GetInterForm()); |
286 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr; | 286 return pInterForm ? pInterForm->GetWidget(pFormControl) : nullptr; |
287 } | 287 } |
288 | 288 |
289 FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, | 289 FX_BOOL Field::ValueIsOccur(CPDF_FormField* pFormField, |
290 CFX_WideString csOptLabel) { | 290 CFX_WideString csOptLabel) { |
291 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { | 291 for (int i = 0, sz = pFormField->CountOptions(); i < sz; i++) { |
292 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) | 292 if (csOptLabel.Compare(pFormField->GetOptionLabel(i)) == 0) |
293 return TRUE; | 293 return TRUE; |
294 } | 294 } |
295 | 295 |
296 return FALSE; | 296 return FALSE; |
297 } | 297 } |
298 | 298 |
299 CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) { | 299 CPDF_FormControl* Field::GetSmartFieldControl(CPDF_FormField* pFormField) { |
300 if (!pFormField->CountControls() || | 300 if (!pFormField->CountControls() || |
301 m_nFormControlIndex >= pFormField->CountControls()) | 301 m_nFormControlIndex >= pFormField->CountControls()) |
302 return NULL; | 302 return nullptr; |
303 | 303 |
304 if (m_nFormControlIndex < 0) | 304 if (m_nFormControlIndex < 0) |
305 return pFormField->GetControl(0); | 305 return pFormField->GetControl(0); |
306 | 306 |
307 return pFormField->GetControl(m_nFormControlIndex); | 307 return pFormField->GetControl(m_nFormControlIndex); |
308 } | 308 } |
309 | 309 |
310 FX_BOOL Field::alignment(IJS_Context* cc, | 310 FX_BOOL Field::alignment(IJS_Context* cc, |
311 CJS_PropValue& vp, | 311 CJS_PropValue& vp, |
312 CFX_WideString& sError) { | 312 CFX_WideString& sError) { |
(...skipping 2636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2949 | 2949 |
2950 CJS_Context* pContext = (CJS_Context*)cc; | 2950 CJS_Context* pContext = (CJS_Context*)cc; |
2951 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); | 2951 CJS_Runtime* pRuntime = pContext->GetJSRuntime(); |
2952 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( | 2952 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj( |
2953 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); | 2953 pRuntime->GetIsolate(), pRuntime, CJS_Icon::g_nObjDefnID); |
2954 ASSERT(pObj.IsEmpty() == FALSE); | 2954 ASSERT(pObj.IsEmpty() == FALSE); |
2955 | 2955 |
2956 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); | 2956 CJS_Icon* pJS_Icon = (CJS_Icon*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj); |
2957 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); | 2957 Icon* pIcon = (Icon*)pJS_Icon->GetEmbedObject(); |
2958 | 2958 |
2959 CPDF_Stream* pIconStream = NULL; | 2959 CPDF_Stream* pIconStream = nullptr; |
2960 if (nface == 0) | 2960 if (nface == 0) |
2961 pIconStream = pFormControl->GetNormalIcon(); | 2961 pIconStream = pFormControl->GetNormalIcon(); |
2962 else if (nface == 1) | 2962 else if (nface == 1) |
2963 pIconStream = pFormControl->GetDownIcon(); | 2963 pIconStream = pFormControl->GetDownIcon(); |
2964 else if (nface == 2) | 2964 else if (nface == 2) |
2965 pIconStream = pFormControl->GetRolloverIcon(); | 2965 pIconStream = pFormControl->GetRolloverIcon(); |
2966 else | 2966 else |
2967 return FALSE; | 2967 return FALSE; |
2968 | 2968 |
2969 pIcon->SetStream(pIconStream); | 2969 pIcon->SetStream(pIconStream); |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3247 if (FieldArray.empty()) | 3247 if (FieldArray.empty()) |
3248 return FALSE; | 3248 return FALSE; |
3249 | 3249 |
3250 CPDF_FormField* pFormField = FieldArray[0]; | 3250 CPDF_FormField* pFormField = FieldArray[0]; |
3251 int32_t nCount = pFormField->CountControls(); | 3251 int32_t nCount = pFormField->CountControls(); |
3252 if (nCount < 1) | 3252 if (nCount < 1) |
3253 return FALSE; | 3253 return FALSE; |
3254 | 3254 |
3255 CPDFSDK_InterForm* pInterForm = | 3255 CPDFSDK_InterForm* pInterForm = |
3256 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); | 3256 (CPDFSDK_InterForm*)m_pDocument->GetInterForm(); |
3257 CPDFSDK_Widget* pWidget = NULL; | 3257 CPDFSDK_Widget* pWidget = nullptr; |
3258 if (nCount == 1) { | 3258 if (nCount == 1) { |
3259 pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); | 3259 pWidget = pInterForm->GetWidget(pFormField->GetControl(0)); |
3260 } else { | 3260 } else { |
3261 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); | 3261 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); |
3262 UnderlyingPageType* pPage = UnderlyingFromFPDFPage( | 3262 UnderlyingPageType* pPage = UnderlyingFromFPDFPage( |
3263 pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument())); | 3263 pEnv->FFI_GetCurrentPage(m_pDocument->GetUnderlyingDocument())); |
3264 if (!pPage) | 3264 if (!pPage) |
3265 return FALSE; | 3265 return FALSE; |
3266 if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) { | 3266 if (CPDFSDK_PageView* pCurPageView = m_pDocument->GetPageView(pPage)) { |
3267 for (int32_t i = 0; i < nCount; i++) { | 3267 for (int32_t i = 0; i < nCount; i++) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3336 const std::vector<CJS_Value>& params, | 3336 const std::vector<CJS_Value>& params, |
3337 CJS_Value& vRet, | 3337 CJS_Value& vRet, |
3338 CFX_WideString& sError) { | 3338 CFX_WideString& sError) { |
3339 return FALSE; | 3339 return FALSE; |
3340 } | 3340 } |
3341 | 3341 |
3342 FX_BOOL Field::source(IJS_Context* cc, | 3342 FX_BOOL Field::source(IJS_Context* cc, |
3343 CJS_PropValue& vp, | 3343 CJS_PropValue& vp, |
3344 CFX_WideString& sError) { | 3344 CFX_WideString& sError) { |
3345 if (vp.IsGetting()) { | 3345 if (vp.IsGetting()) { |
3346 vp << (CJS_Object*)NULL; | 3346 vp << (CJS_Object*)nullptr; |
3347 } | 3347 } |
3348 | 3348 |
3349 return TRUE; | 3349 return TRUE; |
3350 } | 3350 } |
3351 | 3351 |
3352 void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) { | 3352 void Field::AddDelay_Int(FIELD_PROP prop, int32_t n) { |
3353 CJS_DelayData* pNewData = | 3353 CJS_DelayData* pNewData = |
3354 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); | 3354 new CJS_DelayData(prop, m_nFormControlIndex, m_FieldName); |
3355 pNewData->num = n; | 3355 pNewData->num = n; |
3356 m_pJSDoc->AddDelayData(pNewData); | 3356 m_pJSDoc->AddDelayData(pNewData); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3547 } | 3547 } |
3548 } | 3548 } |
3549 | 3549 |
3550 void Field::AddField(CPDFSDK_Document* pDocument, | 3550 void Field::AddField(CPDFSDK_Document* pDocument, |
3551 int nPageIndex, | 3551 int nPageIndex, |
3552 int nFieldType, | 3552 int nFieldType, |
3553 const CFX_WideString& sName, | 3553 const CFX_WideString& sName, |
3554 const CFX_FloatRect& rcCoords) { | 3554 const CFX_FloatRect& rcCoords) { |
3555 // Not supported. | 3555 // Not supported. |
3556 } | 3556 } |
OLD | NEW |