Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cxfa_fftextedit.cpp
Go to the documentation of this file.
1// Copyright 2017 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "xfa/fxfa/cxfa_fftextedit.h"
8
9#include <utility>
10
11#include "core/fxcrt/check.h"
12#include "xfa/fwl/cfwl_datetimepicker.h"
13#include "xfa/fwl/cfwl_edit.h"
14#include "xfa/fwl/cfwl_eventtextwillchange.h"
15#include "xfa/fwl/cfwl_messagekillfocus.h"
16#include "xfa/fwl/cfwl_messagesetfocus.h"
17#include "xfa/fwl/cfwl_notedriver.h"
18#include "xfa/fxfa/cxfa_eventparam.h"
19#include "xfa/fxfa/cxfa_ffapp.h"
20#include "xfa/fxfa/cxfa_ffdoc.h"
21#include "xfa/fxfa/cxfa_ffdocview.h"
22#include "xfa/fxfa/parser/cxfa_barcode.h"
23#include "xfa/fxfa/parser/cxfa_node.h"
24#include "xfa/fxfa/parser/cxfa_para.h"
25
26namespace {
27
28CFWL_Edit* ToEdit(CFWL_Widget* widget) {
29 return static_cast<CFWL_Edit*>(widget);
30}
31
32} // namespace
33
35
37
39 if (GetNormalWidget()) {
40 CFWL_NoteDriver* pNoteDriver =
41 GetNormalWidget()->GetFWLApp()->GetNoteDriver();
42 pNoteDriver->UnregisterEventTarget(GetNormalWidget());
43 }
44}
45
46void CXFA_FFTextEdit::Trace(cppgc::Visitor* visitor) const {
47 CXFA_FFField::Trace(visitor);
48 visitor->Trace(m_pOldDelegate);
49}
50
52 DCHECK(!IsLoaded());
53
54 CFWL_Edit* pFWLEdit = cppgc::MakeGarbageCollected<CFWL_Edit>(
55 GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp(),
56 CFWL_Widget::Properties(), nullptr);
57 SetNormalWidget(pFWLEdit);
58 pFWLEdit->SetAdapterIface(this);
59
60 CFWL_NoteDriver* pNoteDriver = pFWLEdit->GetFWLApp()->GetNoteDriver();
61 pNoteDriver->RegisterEventTarget(pFWLEdit, pFWLEdit);
62 m_pOldDelegate = pFWLEdit->GetDelegate();
63 pFWLEdit->SetDelegate(this);
64
65 {
66 CFWL_Widget::ScopedUpdateLock update_lock(pFWLEdit);
68 pFWLEdit->SetText(m_pNode->GetValue(XFA_ValuePicture::kDisplay));
69 }
70
72}
73
75 CFWL_Edit* pWidget = ToEdit(GetNormalWidget());
76 if (!pWidget)
77 return;
78
79 uint32_t dwStyle = 0;
80 uint32_t dwExtendedStyle =
82 dwExtendedStyle |= UpdateUIProperty();
83 if (m_pNode->IsMultiLine()) {
85 if (!m_pNode->IsVerticalScrollPolicyOff()) {
86 dwStyle |= FWL_STYLE_WGT_VScroll;
87 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll;
88 }
89 } else if (!m_pNode->IsHorizontalScrollPolicyOff()) {
90 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
91 }
92 if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive()) {
93 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
94 dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine;
95 }
96
97 auto [eType, iMaxChars] = m_pNode->GetMaxChars();
98 if (eType == XFA_Element::ExData)
99 iMaxChars = 0;
100
101 std::optional<int32_t> numCells = m_pNode->GetNumberOfCells();
102 if (!numCells.has_value()) {
103 pWidget->SetLimit(iMaxChars);
104 } else if (numCells == 0) {
105 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
106 pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1);
107 } else {
108 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
109 pWidget->SetLimit(numCells.value());
110 }
111
112 dwExtendedStyle |= GetAlignment();
113 GetNormalWidget()->ModifyStyles(dwStyle, 0xFFFFFFFF);
114 GetNormalWidget()->ModifyStyleExts(dwExtendedStyle, 0xFFFFFFFF);
115}
116
118 Mask<XFA_FWL_KeyFlag> dwFlags,
119 const CFX_PointF& point,
120 CFWL_MessageMouse::MouseCommand command) {
121 if (command == CFWL_MessageMouse::MouseCommand::kRightButtonDown &&
122 !m_pNode->IsOpenAccess()) {
123 return false;
124 }
125 if (!PtInActiveRect(point))
126 return false;
127
128 return true;
129}
130
132 const CFX_PointF& point) {
133 if (!IsFocused()) {
137 }
138 SetButtonDown(true);
139 CFWL_MessageMouse msg(GetNormalWidget(),
140 CFWL_MessageMouse::MouseCommand::kLeftButtonDown,
141 dwFlags, FWLToClient(point));
143 return true;
144}
145
147 const CFX_PointF& point) {
148 if (!IsFocused()) {
152 }
153 SetButtonDown(true);
154 CFWL_MessageMouse msg(nullptr,
155 CFWL_MessageMouse::MouseCommand::kRightButtonDown,
156 dwFlags, FWLToClient(point));
158 return true;
159}
160
162 const CFX_PointF& point) {
163 if (!CXFA_FFField::OnRButtonUp(dwFlags, point))
164 return false;
165
166 GetDoc()->PopupMenu(this, point);
167 return true;
168}
169
172 if (!IsFocused()) {
176 }
177 if (!CXFA_FFWidget::OnSetFocus(pOldWidget))
178 return false;
179
180 CFWL_MessageSetFocus msg(GetNormalWidget());
182 return true;
183}
184
186 CFWL_MessageKillFocus msg(GetNormalWidget());
188
189 GetLayoutItem()->ClearStatusBits(XFA_WidgetStatus::kFocused);
194
195 if (!CXFA_FFWidget::OnKillFocus(pNewWidget))
196 return false;
197
199 return true;
200}
201
203 WideString wsText = ToEdit(GetNormalWidget())->GetText();
204 if (m_pNode->SetValue(XFA_ValuePicture::kEdit, wsText)) {
205 GetDoc()->GetDocView()->UpdateUIDisplay(m_pNode.Get(), this);
206 return true;
207 }
208 ValidateNumberField(wsText);
209 return false;
210}
211
212void CXFA_FFTextEdit::ValidateNumberField(const WideString& wsText) {
213 if (GetNode()->GetFFWidgetType() != XFA_FFWidgetType::kNumericEdit)
214 return;
215
216 CXFA_FFApp::CallbackIface* pAppProvider = GetAppProvider();
217 if (!pAppProvider)
218 return;
219
220 WideString wsSomField = GetNode()->GetSOMExpression();
221 pAppProvider->MsgBox(
222 wsText + WideString::FromASCII(" can not contain ") + wsSomField,
223 pAppProvider->GetAppTitle(), static_cast<uint32_t>(AlertIcon::kError),
224 static_cast<uint32_t>(AlertButton::kOK));
225}
226
231
233 CXFA_Para* para = m_pNode->GetParaIfExists();
234 if (!para)
235 return 0;
236
237 uint32_t dwExtendedStyle = 0;
238 switch (para->GetHorizontalAlign()) {
239 case XFA_AttributeValue::Center:
240 dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter;
241 break;
242 case XFA_AttributeValue::Justify:
243 dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified;
244 break;
245 case XFA_AttributeValue::JustifyAll:
246 case XFA_AttributeValue::Radix:
247 break;
248 case XFA_AttributeValue::Right:
249 dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar;
250 break;
251 default:
252 dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear;
253 break;
254 }
255
256 switch (para->GetVerticalAlign()) {
257 case XFA_AttributeValue::Middle:
258 dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter;
259 break;
260 case XFA_AttributeValue::Bottom:
261 dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar;
262 break;
263 default:
264 dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear;
265 break;
266 }
267 return dwExtendedStyle;
268}
269
271 CFWL_Edit* pEdit = ToEdit(GetNormalWidget());
272 if (!pEdit)
273 return false;
274
276 if (IsFocused())
278
279 bool bUpdate = false;
280 if (m_pNode->GetFFWidgetType() == XFA_FFWidgetType::kTextEdit &&
281 !m_pNode->GetNumberOfCells().has_value()) {
282 auto [elementType, iMaxChars] = m_pNode->GetMaxChars();
283 if (elementType == XFA_Element::ExData)
284 iMaxChars = eType == XFA_ValuePicture::kEdit ? iMaxChars : 0;
285 if (pEdit->GetLimit() != iMaxChars) {
286 pEdit->SetLimit(iMaxChars);
287 bUpdate = true;
288 }
289 } else if (m_pNode->GetFFWidgetType() == XFA_FFWidgetType::kBarcode) {
290 int32_t nDataLen = 0;
291 if (eType == XFA_ValuePicture::kEdit) {
292 nDataLen = static_cast<CXFA_Barcode*>(m_pNode->GetUIChildNode())
293 ->GetDataLength()
294 .value_or(0);
295 }
296
297 pEdit->SetLimit(nDataLen);
298 bUpdate = true;
299 }
300 WideString wsText = m_pNode->GetValue(eType);
301 WideString wsOldText = pEdit->GetText();
302 if (wsText != wsOldText || (eType == XFA_ValuePicture::kEdit && bUpdate)) {
303 pEdit->SetTextSkipNotify(wsText);
304 bUpdate = true;
305 }
306 if (bUpdate)
307 GetNormalWidget()->Update();
308
309 return true;
310}
311
313 CFWL_EventTextWillChange* event) {
315
317 eParam.m_wsChange = event->GetChangeText();
318 eParam.m_wsPrevText = event->GetPreviousText();
319 eParam.m_iSelStart = static_cast<int32_t>(event->GetSelectionStart());
320 eParam.m_iSelEnd = static_cast<int32_t>(event->GetSelectionEnd());
321 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Change, &eParam);
322
323 // Copy the data back out of the EventParam and into the TextChanged event so
324 // it can propagate back to the calling widget.
326 event->SetChangeText(eParam.m_wsChange);
327 event->SetSelectionStart(static_cast<size_t>(eParam.m_iSelStart));
328 event->SetSelectionEnd(static_cast<size_t>(eParam.m_iSelEnd));
329}
330
333 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Full, &eParam);
334}
335
337 m_pOldDelegate->OnProcessMessage(pMessage);
338}
339
342 switch (pEvent->GetType()) {
344 OnTextWillChange(GetNormalWidget(),
345 static_cast<CFWL_EventTextWillChange*>(pEvent));
346 break;
348 OnTextFull(GetNormalWidget());
349 break;
350 default:
351 break;
352 }
353 m_pOldDelegate->OnProcessEvent(pEvent);
354}
355
357 const CFX_Matrix& matrix) {
358 m_pOldDelegate->OnDrawWidget(pGraphics, matrix);
359}
360
362 return ToEdit(GetNormalWidget())->CanUndo();
363}
364
366 return ToEdit(GetNormalWidget())->CanRedo();
367}
368
370 return ToEdit(GetNormalWidget())->HasSelection();
371}
372
374 if (ToEdit(GetNormalWidget())->GetStyleExts() & FWL_STYLEEXT_EDT_ReadOnly)
375 return false;
376 return ToEdit(GetNormalWidget())->HasSelection();
377}
378
380 return !(ToEdit(GetNormalWidget())->GetStyleExts() &
382}
383
385 return ToEdit(GetNormalWidget())->GetTextLength() > 0;
386}
387
389 return ToEdit(GetNormalWidget())->Undo();
390}
391
393 return ToEdit(GetNormalWidget())->Redo();
394}
395
397 return ToEdit(GetNormalWidget())->Copy();
398}
399
401 return ToEdit(GetNormalWidget())->Cut();
402}
403
404bool CXFA_FFTextEdit::Paste(const WideString& wsPaste) {
405 return ToEdit(GetNormalWidget())->Paste(wsPaste);
406}
407
409 ToEdit(GetNormalWidget())->SelectAll();
410}
411
413 ToEdit(GetNormalWidget())->ClearText();
414}
415
417 ToEdit(GetNormalWidget())->ClearSelection();
418}
419
421 return ToEdit(GetNormalWidget())->GetText();
422}
423
425 return FormFieldType::kXFA_TextField;
426}
#define FWL_STYLEEXT_EDT_MultiLine
Definition cfwl_edit.h:24
#define FWL_STYLEEXT_EDT_HFar
Definition cfwl_edit.h:34
#define FWL_STYLEEXT_EDT_ShowScrollbarFocus
Definition cfwl_edit.h:42
#define FWL_STYLEEXT_EDT_WantReturn
Definition cfwl_edit.h:25
#define FWL_STYLEEXT_EDT_VNear
Definition cfwl_edit.h:35
#define FWL_STYLEEXT_EDT_VCenter
Definition cfwl_edit.h:36
#define FWL_STYLEEXT_EDT_OuterScrollbar
Definition cfwl_edit.h:43
#define FWL_STYLEEXT_EDT_AutoHScroll
Definition cfwl_edit.h:26
#define FWL_STYLEEXT_EDT_ReadOnly
Definition cfwl_edit.h:23
#define FWL_STYLEEXT_EDT_VFar
Definition cfwl_edit.h:37
#define FWL_STYLEEXT_EDT_AutoVScroll
Definition cfwl_edit.h:27
#define FWL_STYLEEXT_EDT_HNear
Definition cfwl_edit.h:32
#define FWL_STYLEEXT_EDT_Justified
Definition cfwl_edit.h:38
#define FWL_STYLEEXT_EDT_CombText
Definition cfwl_edit.h:31
#define FWL_STYLEEXT_EDT_HCenter
Definition cfwl_edit.h:33
#define FWL_STYLE_WGT_VScroll
Definition cfwl_widget.h:39
#define DCHECK
Definition check.h:33
CXFA_EventParam(XFA_EVENTTYPE type)
virtual WideString GetAppTitle() const =0
virtual int32_t MsgBox(const WideString &wsMessage, const WideString &wsTitle, uint32_t dwIconType, uint32_t dwButtonType)=0
CXFA_FFField(CXFA_Node *pNode)
void OnProcessEvent(pdfium::CFWL_Event *pEvent) override
CFX_PointF FWLToClient(const CFX_PointF &point)
bool ProcessCommittedData()
bool LoadWidget() override
void SetEditScrollOffset()
bool OnRButtonUp(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
void SetNormalWidget(CFWL_Widget *widget)
bool PtInActiveRect(const CFX_PointF &point) override
uint32_t UpdateUIProperty()
void SendMessageToFWLWidget(CFWL_Message *pMessage)
std::optional< WideString > Copy() override
bool OnKillFocus(CXFA_FFWidget *pNewWidget) override
void SelectAll() override
bool CanUndo() override
bool OnLButtonDown(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void OnProcessMessage(CFWL_Message *pMessage) override
void OnProcessEvent(pdfium::CFWL_Event *pEvent) override
bool CanSelectAll() override
bool Redo() override
bool OnRButtonUp(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
~CXFA_FFTextEdit() override
void OnTextWillChange(pdfium::CFWL_Widget *pWidget, pdfium::CFWL_EventTextWillChange *change)
bool Undo() override
bool CommitData() override
std::optional< WideString > Cut() override
bool OnSetFocus(CXFA_FFWidget *pOldWidget) override
bool AcceptsFocusOnButtonDown(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point, CFWL_MessageMouse::MouseCommand command) override
bool UpdateFWLData() override
bool LoadWidget() override
bool Paste(const WideString &wsPaste) override
CXFA_FFTextEdit(CXFA_Node *pNode)
void Delete() override
void UpdateWidgetProperty() override
void DeSelect() override
bool CanCopy() override
void OnTextFull(CFWL_Widget *pWidget)
bool CanCut() override
bool CanPaste() override
FormFieldType GetFormFieldType() override
bool OnRButtonDown(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
bool CanRedo() override
bool IsDataChanged() override
WideString GetText() override
virtual bool OnSetFocus(CXFA_FFWidget *pOldWidget)
bool IsFocused() const
CXFA_FFApp::CallbackIface * GetAppProvider()
CXFA_Node * GetNode() const
void SetButtonDown(bool bSet)
CXFA_FFDoc * GetDoc()
CXFA_ContentLayoutItem * GetLayoutItem() const
virtual bool OnKillFocus(CXFA_FFWidget *pNewWidget)
XFA_AttributeValue GetHorizontalAlign()
Definition cxfa_para.cpp:57
XFA_AttributeValue GetVerticalAlign()
Definition cxfa_para.cpp:63
bool operator!=(const WideString &other) const
Definition widestring.h:85
static WideString FromASCII(ByteStringView str)
WideString GetText() const
virtual void SetTextSkipNotify(const WideString &wsText)
int32_t GetLimit() const
void SetLimit(int32_t nLimit)
void SetChangeText(const WideString &change_text)
Type GetType() const
Definition cfwl_event.h:41
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
void UnregisterEventTarget(CFWL_Widget *pListener)
void SetDelegate(IFWL_WidgetDelegate *delegate)
void SetAdapterIface(AdapterIface *pItem)
CFWL_App * GetFWLApp() const
FormFieldType
@ XFA_EVENT_Change
@ XFA_EVENT_Full
XFA_FFWidgetType
XFA_ValuePicture
Definition cxfa_node.h:71
CFX_PTemplate< float > CFX_PointF
AlertIcon
Definition fxfa.h:20
@ kError
Definition fxfa.h:22
AlertButton
Definition fxfa.h:11
XFA_WidgetStatus
Definition fxfa.h:61
@ kTextEditValueChanged
Definition fxfa.h:69
XFA_AttributeValue
Definition fxfa_basic.h:60
Definition heap.h:12
fxcrt::WideString WideString
Definition widestring.h:207