summaryrefslogtreecommitdiff
path: root/fpdfsdk/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk/javascript')
-rw-r--r--fpdfsdk/javascript/Annot.cpp35
-rw-r--r--fpdfsdk/javascript/Annot.h5
-rw-r--r--fpdfsdk/javascript/Field.cpp7
3 files changed, 36 insertions, 11 deletions
diff --git a/fpdfsdk/javascript/Annot.cpp b/fpdfsdk/javascript/Annot.cpp
index a23d42f72a..ab84247baa 100644
--- a/fpdfsdk/javascript/Annot.cpp
+++ b/fpdfsdk/javascript/Annot.cpp
@@ -11,6 +11,14 @@
#include "fpdfsdk/javascript/JS_Value.h"
#include "fpdfsdk/javascript/cjs_context.h"
+namespace {
+
+CPDFSDK_BAAnnot* ToBAAnnot(CPDFSDK_Annot* annot) {
+ return static_cast<CPDFSDK_BAAnnot*>(annot);
+}
+
+} // namespace
+
BEGIN_JS_STATIC_CONST(CJS_Annot)
END_JS_STATIC_CONST()
@@ -32,8 +40,12 @@ Annot::~Annot() {}
FX_BOOL Annot::hidden(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
+ CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot);
+ if (!baAnnot)
+ return FALSE;
+
if (vp.IsGetting()) {
- CPDF_Annot* pPDFAnnot = m_BAAnnot->GetPDFAnnot();
+ CPDF_Annot* pPDFAnnot = baAnnot->GetPDFAnnot();
vp << CPDF_Annot::IsAnnotationHidden(pPDFAnnot->GetAnnotDict());
return TRUE;
}
@@ -41,7 +53,7 @@ FX_BOOL Annot::hidden(IJS_Context* cc,
bool bHidden;
vp >> bHidden;
- uint32_t flags = m_BAAnnot->GetFlags();
+ uint32_t flags = baAnnot->GetFlags();
if (bHidden) {
flags |= ANNOTFLAG_HIDDEN;
flags |= ANNOTFLAG_INVISIBLE;
@@ -53,21 +65,25 @@ FX_BOOL Annot::hidden(IJS_Context* cc,
flags &= ~ANNOTFLAG_NOVIEW;
flags |= ANNOTFLAG_PRINT;
}
- m_BAAnnot->SetFlags(flags);
+ baAnnot->SetFlags(flags);
return TRUE;
}
FX_BOOL Annot::name(IJS_Context* cc,
CJS_PropValue& vp,
CFX_WideString& sError) {
+ CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot);
+ if (!baAnnot)
+ return FALSE;
+
if (vp.IsGetting()) {
- vp << m_BAAnnot->GetAnnotName();
+ vp << baAnnot->GetAnnotName();
return TRUE;
}
CFX_WideString annotName;
vp >> annotName;
- m_BAAnnot->SetAnnotName(annotName);
+ baAnnot->SetAnnotName(annotName);
return TRUE;
}
@@ -80,10 +96,15 @@ FX_BOOL Annot::type(IJS_Context* cc,
return FALSE;
}
- vp << CPDF_Annot::AnnotSubtypeToString(m_BAAnnot->GetAnnotSubtype());
+ CPDFSDK_BAAnnot* baAnnot = ToBAAnnot(m_pAnnot);
+ if (!baAnnot)
+ return FALSE;
+
+ vp << CPDF_Annot::AnnotSubtypeToString(baAnnot->GetAnnotSubtype());
return TRUE;
}
void Annot::SetSDKAnnot(CPDFSDK_BAAnnot* annot) {
- m_BAAnnot = annot;
+ m_pAnnot = annot;
+ m_pObserver.reset(new CPDFSDK_Annot::Observer(&m_pAnnot));
}
diff --git a/fpdfsdk/javascript/Annot.h b/fpdfsdk/javascript/Annot.h
index b3ea292aed..be850350ae 100644
--- a/fpdfsdk/javascript/Annot.h
+++ b/fpdfsdk/javascript/Annot.h
@@ -7,6 +7,8 @@
#ifndef FPDFSDK_JAVASCRIPT_ANNOT_H_
#define FPDFSDK_JAVASCRIPT_ANNOT_H_
+#include <memory>
+
#include "fpdfsdk/include/cpdfsdk_baannot.h"
#include "fpdfsdk/javascript/JS_Define.h"
@@ -22,7 +24,8 @@ class Annot : public CJS_EmbedObj {
void SetSDKAnnot(CPDFSDK_BAAnnot* annot);
private:
- CPDFSDK_BAAnnot* m_BAAnnot = nullptr;
+ CPDFSDK_Annot* m_pAnnot = nullptr;
+ std::unique_ptr<CPDFSDK_Annot::Observer> m_pObserver;
};
class CJS_Annot : public CJS_Object {
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index 5c279d6b53..3f5e5e1b0f 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -267,11 +267,12 @@ void Field::UpdateFormField(CPDFSDK_Document* pDocument,
if (bResetAP) {
int nFieldType = pFormField->GetFieldType();
if (nFieldType == FIELDTYPE_COMBOBOX || nFieldType == FIELDTYPE_TEXTFIELD) {
- for (CPDFSDK_Widget* pWidget : widgets) {
+ for (CPDFSDK_Annot* pAnnot : widgets) {
FX_BOOL bFormatted = FALSE;
- CPDFSDK_Widget::Observer observer(&pWidget);
+ CPDFSDK_Widget* pWidget = static_cast<CPDFSDK_Widget*>(pAnnot);
+ CPDFSDK_Widget::Observer observer(&pAnnot);
CFX_WideString sValue = pWidget->OnFormat(bFormatted);
- if (pWidget) {
+ if (pAnnot) {
pWidget->ResetAppearance(bFormatted ? sValue.c_str() : nullptr,
FALSE);
}