summaryrefslogtreecommitdiff
path: root/fpdfsdk
diff options
context:
space:
mode:
Diffstat (limited to 'fpdfsdk')
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp4
-rw-r--r--fpdfsdk/cpdfsdk_widget.cpp17
-rw-r--r--fpdfsdk/cpdfsdk_widgethandler.cpp2
-rw-r--r--fpdfsdk/formfiller/cffl_iformfiller.cpp3
-rw-r--r--fpdfsdk/fxedit/fxet_edit.cpp43
-rw-r--r--fpdfsdk/fxedit/include/fxet_edit.h8
-rw-r--r--fpdfsdk/include/cpdfsdk_interform.h2
-rw-r--r--fpdfsdk/include/cpdfsdk_widget.h6
-rw-r--r--fpdfsdk/javascript/Field.cpp7
9 files changed, 42 insertions, 50 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index a8e2663a9b..1f182d4a0c 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -323,7 +323,7 @@ CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
}
void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField,
- const FX_WCHAR* sValue,
+ const CFX_WideString* sValue,
FX_BOOL bValueChanged) {
for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
@@ -634,7 +634,7 @@ void CPDFSDK_InterForm::AfterValueChange(CPDF_FormField* pField) {
OnCalculate(pField);
FX_BOOL bFormatted = FALSE;
CFX_WideString sValue = OnFormat(pField, bFormatted);
- ResetFieldAppearance(pField, bFormatted ? sValue.c_str() : nullptr, TRUE);
+ ResetFieldAppearance(pField, bFormatted ? &sValue : nullptr, TRUE);
UpdateField(pField);
}
}
diff --git a/fpdfsdk/cpdfsdk_widget.cpp b/fpdfsdk/cpdfsdk_widget.cpp
index d518a56109..a8ebef6e99 100644
--- a/fpdfsdk/cpdfsdk_widget.cpp
+++ b/fpdfsdk/cpdfsdk_widget.cpp
@@ -739,7 +739,7 @@ void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
case FIELDTYPE_COMBOBOX: {
FX_BOOL bFormatted = FALSE;
CFX_WideString sValue = OnFormat(bFormatted);
- ResetAppearance(bFormatted ? sValue.c_str() : nullptr, TRUE);
+ ResetAppearance(bFormatted ? &sValue : nullptr, TRUE);
break;
}
default:
@@ -749,7 +749,7 @@ void CPDFSDK_Widget::ResetAppearance(FX_BOOL bValueChanged) {
}
#endif // PDF_ENABLE_XFA
-void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
+void CPDFSDK_Widget::ResetAppearance(const CFX_WideString* sValue,
FX_BOOL bValueChanged) {
SetAppModified();
@@ -1353,7 +1353,7 @@ void CPDFSDK_Widget::ResetAppearance_RadioButton() {
SetAppState("Off");
}
-void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) {
+void CPDFSDK_Widget::ResetAppearance_ComboBox(const CFX_WideString* sValue) {
CPDF_FormControl* pControl = GetFormControl();
CPDF_FormField* pField = pControl->GetField();
CFX_ByteTextBuf sBody, sLines;
@@ -1387,10 +1387,9 @@ void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) {
pEdit->Initialize();
if (sValue) {
- pEdit->SetText(sValue);
+ pEdit->SetText(*sValue);
} else {
int32_t nCurSel = pField->GetSelectedIndex(0);
-
if (nCurSel < 0)
pEdit->SetText(pField->GetValue().c_str());
else
@@ -1512,7 +1511,7 @@ void CPDFSDK_Widget::ResetAppearance_ListBox() {
WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
}
-void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
+void CPDFSDK_Widget::ResetAppearance_TextField(const CFX_WideString* sValue) {
CPDF_FormControl* pControl = GetFormControl();
CPDF_FormField* pField = pControl->GetField();
CFX_ByteTextBuf sBody, sLines;
@@ -1554,7 +1553,7 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
CFX_WideString sValueTmp;
if (!sValue && GetMixXFAWidget()) {
sValueTmp = GetValue(TRUE);
- sValue = sValueTmp.c_str();
+ sValue = &sValueTmp;
}
#endif // PDF_ENABLE_XFA
@@ -1568,7 +1567,7 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
}
} else {
if (sValue)
- nMaxLen = wcslen((const wchar_t*)sValue);
+ nMaxLen = sValue->GetLength();
pEdit->SetLimitChar(nMaxLen);
}
}
@@ -1581,7 +1580,7 @@ void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
pEdit->Initialize();
if (sValue)
- pEdit->SetText(sValue);
+ pEdit->SetText(*sValue);
else
pEdit->SetText(pField->GetValue().c_str());
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index 1a9bdacf24..b490daa8ba 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -241,7 +241,7 @@ void CPDFSDK_WidgetHandler::OnLoad(CPDFSDK_Annot* pAnnot) {
FX_BOOL bFormatted = FALSE;
CFX_WideString sValue = pWidget->OnFormat(bFormatted);
if (bFormatted && nFieldType == FIELDTYPE_COMBOBOX)
- pWidget->ResetAppearance(sValue.c_str(), FALSE);
+ pWidget->ResetAppearance(&sValue, FALSE);
}
#ifdef PDF_ENABLE_XFA
diff --git a/fpdfsdk/formfiller/cffl_iformfiller.cpp b/fpdfsdk/formfiller/cffl_iformfiller.cpp
index db1f538e9d..24a6122f62 100644
--- a/fpdfsdk/formfiller/cffl_iformfiller.cpp
+++ b/fpdfsdk/formfiller/cffl_iformfiller.cpp
@@ -724,8 +724,7 @@ void CFFL_IFormFiller::OnFormat(CPDFSDK_Widget* pWidget,
return;
if (bFormatted) {
- pInterForm->ResetFieldAppearance(pWidget->GetFormField(), sValue.c_str(),
- TRUE);
+ pInterForm->ResetFieldAppearance(pWidget->GetFormField(), &sValue, TRUE);
pInterForm->UpdateField(pWidget->GetFormField());
}
diff --git a/fpdfsdk/fxedit/fxet_edit.cpp b/fpdfsdk/fxedit/fxet_edit.cpp
index 7d207a83ca..7aa8534a0a 100644
--- a/fpdfsdk/fxedit/fxet_edit.cpp
+++ b/fpdfsdk/fxedit/fxet_edit.cpp
@@ -706,7 +706,7 @@ void CFXEU_Clear::Undo() {
if (m_pEdit) {
m_pEdit->SelectNone();
m_pEdit->SetCaret(m_wrSel.BeginPos);
- m_pEdit->InsertText(m_swText.c_str(), DEFAULT_CHARSET, FALSE, TRUE);
+ m_pEdit->InsertText(m_swText, DEFAULT_CHARSET, FALSE, TRUE);
m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos);
}
}
@@ -728,7 +728,7 @@ void CFXEU_InsertText::Redo() {
if (m_pEdit && IsLast()) {
m_pEdit->SelectNone();
m_pEdit->SetCaret(m_wpOld);
- m_pEdit->InsertText(m_swText.c_str(), m_nCharset, FALSE, TRUE);
+ m_pEdit->InsertText(m_swText, m_nCharset, FALSE, TRUE);
}
}
@@ -1670,9 +1670,9 @@ CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange& wr1,
return wrRet;
}
-void CFX_Edit::SetText(const FX_WCHAR* text) {
+void CFX_Edit::SetText(const CFX_WideString& sText) {
Empty();
- DoInsertText(CPVT_WordPlace(0, 0, -1), text, DEFAULT_CHARSET);
+ DoInsertText(CPVT_WordPlace(0, 0, -1), sText, DEFAULT_CHARSET);
Paint();
}
@@ -1696,8 +1696,8 @@ FX_BOOL CFX_Edit::Clear() {
return Clear(TRUE, TRUE);
}
-FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, int32_t charset) {
- return InsertText(text, charset, TRUE, TRUE);
+FX_BOOL CFX_Edit::InsertText(const CFX_WideString& sText, int32_t charset) {
+ return InsertText(sText, charset, TRUE, TRUE);
}
FX_FLOAT CFX_Edit::GetFontSize() const {
@@ -2685,7 +2685,7 @@ FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) {
return TRUE;
}
-FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text,
+FX_BOOL CFX_Edit::InsertText(const CFX_WideString& sText,
int32_t charset,
FX_BOOL bAddUndo,
FX_BOOL bPaint) {
@@ -2693,24 +2693,23 @@ FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text,
return FALSE;
m_pVT->UpdateWordPlace(m_wpCaret);
- SetCaret(DoInsertText(m_wpCaret, text, charset));
+ SetCaret(DoInsertText(m_wpCaret, sText, charset));
m_SelState.Set(m_wpCaret, m_wpCaret);
+ if (m_wpCaret == m_wpOldCaret)
+ return FALSE;
- if (m_wpCaret != m_wpOldCaret) {
- if (bAddUndo && m_bEnableUndo) {
- AddEditUndoItem(
- new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, text, charset));
- }
+ if (bAddUndo && m_bEnableUndo) {
+ AddEditUndoItem(
+ new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, sText, charset));
+ }
- if (bPaint)
- PaintInsertText(m_wpOldCaret, m_wpCaret);
+ if (bPaint)
+ PaintInsertText(m_wpOldCaret, m_wpCaret);
- if (m_bOprNotify && m_pOprNotify)
- m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret);
+ if (m_bOprNotify && m_pOprNotify)
+ m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret);
- return TRUE;
- }
- return FALSE;
+ return TRUE;
}
void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld,
@@ -2883,13 +2882,11 @@ FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const {
}
CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place,
- const FX_WCHAR* text,
+ const CFX_WideString& sText,
int32_t charset) {
CPVT_WordPlace wp = place;
if (m_pVT->IsValid()) {
- CFX_WideString sText = text;
-
for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) {
uint16_t word = sText[i];
switch (word) {
diff --git a/fpdfsdk/fxedit/include/fxet_edit.h b/fpdfsdk/fxedit/include/fxet_edit.h
index 9adf17271b..e0fca92dd2 100644
--- a/fpdfsdk/fxedit/include/fxet_edit.h
+++ b/fpdfsdk/fxedit/include/fxet_edit.h
@@ -470,13 +470,13 @@ class CFX_Edit {
void OnVK_RIGHT(FX_BOOL bShift, FX_BOOL bCtrl);
void OnVK_HOME(FX_BOOL bShift, FX_BOOL bCtrl);
void OnVK_END(FX_BOOL bShift, FX_BOOL bCtrl);
- void SetText(const FX_WCHAR* text);
+ void SetText(const CFX_WideString& sText);
FX_BOOL InsertWord(uint16_t word, int32_t charset);
FX_BOOL InsertReturn();
FX_BOOL Backspace();
FX_BOOL Delete();
FX_BOOL Clear();
- FX_BOOL InsertText(const FX_WCHAR* text, int32_t charset);
+ FX_BOOL InsertText(const CFX_WideString& sText, int32_t charset);
FX_BOOL Redo();
FX_BOOL Undo();
int32_t WordPlaceToWordIndex(const CPVT_WordPlace& place) const;
@@ -525,7 +525,7 @@ class CFX_Edit {
FX_BOOL Empty();
CPVT_WordPlace DoInsertText(const CPVT_WordPlace& place,
- const FX_WCHAR* text,
+ const CFX_WideString& sText,
int32_t charset);
int32_t GetCharSetFromUnicode(uint16_t word, int32_t nOldCharset);
@@ -563,7 +563,7 @@ class CFX_Edit {
FX_BOOL Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint);
FX_BOOL Delete(FX_BOOL bAddUndo, FX_BOOL bPaint);
FX_BOOL Clear(FX_BOOL bAddUndo, FX_BOOL bPaint);
- FX_BOOL InsertText(const FX_WCHAR* text,
+ FX_BOOL InsertText(const CFX_WideString& sText,
int32_t charset,
FX_BOOL bAddUndo,
FX_BOOL bPaint);
diff --git a/fpdfsdk/include/cpdfsdk_interform.h b/fpdfsdk/include/cpdfsdk_interform.h
index d900fe2ae8..b4b5db3fca 100644
--- a/fpdfsdk/include/cpdfsdk_interform.h
+++ b/fpdfsdk/include/cpdfsdk_interform.h
@@ -70,7 +70,7 @@ class CPDFSDK_InterForm : public IPDF_FormNotify {
CFX_WideString OnFormat(CPDF_FormField* pFormField, FX_BOOL& bFormatted);
void ResetFieldAppearance(CPDF_FormField* pFormField,
- const FX_WCHAR* sValue,
+ const CFX_WideString* sValue,
FX_BOOL bValueChanged);
void UpdateField(CPDF_FormField* pFormField);
diff --git a/fpdfsdk/include/cpdfsdk_widget.h b/fpdfsdk/include/cpdfsdk_widget.h
index bf033ccc3a..09f9d94693 100644
--- a/fpdfsdk/include/cpdfsdk_widget.h
+++ b/fpdfsdk/include/cpdfsdk_widget.h
@@ -108,7 +108,7 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
#ifdef PDF_ENABLE_XFA
void ResetAppearance(FX_BOOL bValueChanged);
#endif // PDF_ENABLE_XFA
- void ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChanged);
+ void ResetAppearance(const CFX_WideString* sValue, FX_BOOL bValueChanged);
void ResetFieldAppearance(FX_BOOL bValueChanged);
void UpdateField();
CFX_WideString OnFormat(FX_BOOL& bFormatted);
@@ -144,9 +144,9 @@ class CPDFSDK_Widget : public CPDFSDK_BAAnnot {
void ResetAppearance_PushButton();
void ResetAppearance_CheckBox();
void ResetAppearance_RadioButton();
- void ResetAppearance_ComboBox(const FX_WCHAR* sValue);
+ void ResetAppearance_ComboBox(const CFX_WideString* sValue);
void ResetAppearance_ListBox();
- void ResetAppearance_TextField(const FX_WCHAR* sValue);
+ void ResetAppearance_TextField(const CFX_WideString* sValue);
CFX_FloatRect GetClientRect() const;
CFX_FloatRect GetRotatedRect() const;
diff --git a/fpdfsdk/javascript/Field.cpp b/fpdfsdk/javascript/Field.cpp
index a788fb203b..9ecdec6936 100644
--- a/fpdfsdk/javascript/Field.cpp
+++ b/fpdfsdk/javascript/Field.cpp
@@ -275,7 +275,7 @@ void Field::UpdateFormField(CPDFSDK_Document* pDocument,
static_cast<CPDFSDK_Widget*>(pAnnot)->OnFormat(bFormatted);
if (pAnnot) {
static_cast<CPDFSDK_Widget*>(pAnnot)->ResetAppearance(
- bFormatted ? sValue.c_str() : nullptr, FALSE);
+ bFormatted ? &sValue : nullptr, FALSE);
}
}
} else {
@@ -319,10 +319,7 @@ void Field::UpdateFormControl(CPDFSDK_Document* pDocument,
nFieldType == FIELDTYPE_TEXTFIELD) {
FX_BOOL bFormatted = FALSE;
CFX_WideString sValue = pWidget->OnFormat(bFormatted);
- if (bFormatted)
- pWidget->ResetAppearance(sValue.c_str(), FALSE);
- else
- pWidget->ResetAppearance(nullptr, FALSE);
+ pWidget->ResetAppearance(bFormatted ? &sValue : nullptr, FALSE);
} else {
pWidget->ResetAppearance(nullptr, FALSE);
}