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 "third_party/base/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 XFA_Element eType;
98 int32_t iMaxChars;
99 std::tie(eType, iMaxChars) = m_pNode->GetMaxChars();
100 if (eType == XFA_Element::ExData)
101 iMaxChars = 0;
102
103 absl::optional<int32_t> numCells = m_pNode->GetNumberOfCells();
104 if (!numCells.has_value()) {
105 pWidget->SetLimit(iMaxChars);
106 } else if (numCells == 0) {
107 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
108 pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1);
109 } else {
110 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
111 pWidget->SetLimit(numCells.value());
112 }
113
114 dwExtendedStyle |= GetAlignment();
115 GetNormalWidget()->ModifyStyles(dwStyle, 0xFFFFFFFF);
116 GetNormalWidget()->ModifyStyleExts(dwExtendedStyle, 0xFFFFFFFF);
117}
118
120 Mask<XFA_FWL_KeyFlag> dwFlags,
121 const CFX_PointF& point,
122 CFWL_MessageMouse::MouseCommand command) {
123 if (command == CFWL_MessageMouse::MouseCommand::kRightButtonDown &&
124 !m_pNode->IsOpenAccess()) {
125 return false;
126 }
127 if (!PtInActiveRect(point))
128 return false;
129
130 return true;
131}
132
134 const CFX_PointF& point) {
135 if (!IsFocused()) {
139 }
140 SetButtonDown(true);
141 CFWL_MessageMouse msg(GetNormalWidget(),
142 CFWL_MessageMouse::MouseCommand::kLeftButtonDown,
143 dwFlags, FWLToClient(point));
145 return true;
146}
147
149 const CFX_PointF& point) {
150 if (!IsFocused()) {
154 }
155 SetButtonDown(true);
156 CFWL_MessageMouse msg(nullptr,
157 CFWL_MessageMouse::MouseCommand::kRightButtonDown,
158 dwFlags, FWLToClient(point));
160 return true;
161}
162
164 const CFX_PointF& point) {
165 if (!CXFA_FFField::OnRButtonUp(dwFlags, point))
166 return false;
167
168 GetDoc()->PopupMenu(this, point);
169 return true;
170}
171
174 if (!IsFocused()) {
178 }
179 if (!CXFA_FFWidget::OnSetFocus(pOldWidget))
180 return false;
181
182 CFWL_MessageSetFocus msg(GetNormalWidget());
184 return true;
185}
186
188 CFWL_MessageKillFocus msg(GetNormalWidget());
190
191 GetLayoutItem()->ClearStatusBits(XFA_WidgetStatus::kFocused);
196
197 if (!CXFA_FFWidget::OnKillFocus(pNewWidget))
198 return false;
199
201 return true;
202}
203
205 WideString wsText = ToEdit(GetNormalWidget())->GetText();
206 if (m_pNode->SetValue(XFA_ValuePicture::kEdit, wsText)) {
207 GetDoc()->GetDocView()->UpdateUIDisplay(m_pNode.Get(), this);
208 return true;
209 }
210 ValidateNumberField(wsText);
211 return false;
212}
213
214void CXFA_FFTextEdit::ValidateNumberField(const WideString& wsText) {
215 if (GetNode()->GetFFWidgetType() != XFA_FFWidgetType::kNumericEdit)
216 return;
217
218 CXFA_FFApp::CallbackIface* pAppProvider = GetAppProvider();
219 if (!pAppProvider)
220 return;
221
222 WideString wsSomField = GetNode()->GetSOMExpression();
223 pAppProvider->MsgBox(
224 wsText + WideString::FromASCII(" can not contain ") + wsSomField,
225 pAppProvider->GetAppTitle(), static_cast<uint32_t>(AlertIcon::kError),
226 static_cast<uint32_t>(AlertButton::kOK));
227}
228
233
235 CXFA_Para* para = m_pNode->GetParaIfExists();
236 if (!para)
237 return 0;
238
239 uint32_t dwExtendedStyle = 0;
240 switch (para->GetHorizontalAlign()) {
241 case XFA_AttributeValue::Center:
242 dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter;
243 break;
244 case XFA_AttributeValue::Justify:
245 dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified;
246 break;
247 case XFA_AttributeValue::JustifyAll:
248 case XFA_AttributeValue::Radix:
249 break;
250 case XFA_AttributeValue::Right:
251 dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar;
252 break;
253 default:
254 dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear;
255 break;
256 }
257
258 switch (para->GetVerticalAlign()) {
259 case XFA_AttributeValue::Middle:
260 dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter;
261 break;
262 case XFA_AttributeValue::Bottom:
263 dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar;
264 break;
265 default:
266 dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear;
267 break;
268 }
269 return dwExtendedStyle;
270}
271
273 CFWL_Edit* pEdit = ToEdit(GetNormalWidget());
274 if (!pEdit)
275 return false;
276
278 if (IsFocused())
280
281 bool bUpdate = false;
282 if (m_pNode->GetFFWidgetType() == XFA_FFWidgetType::kTextEdit &&
283 !m_pNode->GetNumberOfCells().has_value()) {
284 XFA_Element elementType;
285 int32_t iMaxChars;
286 std::tie(elementType, iMaxChars) = m_pNode->GetMaxChars();
287 if (elementType == XFA_Element::ExData)
288 iMaxChars = eType == XFA_ValuePicture::kEdit ? iMaxChars : 0;
289 if (pEdit->GetLimit() != iMaxChars) {
290 pEdit->SetLimit(iMaxChars);
291 bUpdate = true;
292 }
293 } else if (m_pNode->GetFFWidgetType() == XFA_FFWidgetType::kBarcode) {
294 int32_t nDataLen = 0;
295 if (eType == XFA_ValuePicture::kEdit) {
296 nDataLen = static_cast<CXFA_Barcode*>(m_pNode->GetUIChildNode())
297 ->GetDataLength()
298 .value_or(0);
299 }
300
301 pEdit->SetLimit(nDataLen);
302 bUpdate = true;
303 }
304 WideString wsText = m_pNode->GetValue(eType);
305 WideString wsOldText = pEdit->GetText();
306 if (wsText != wsOldText || (eType == XFA_ValuePicture::kEdit && bUpdate)) {
307 pEdit->SetTextSkipNotify(wsText);
308 bUpdate = true;
309 }
310 if (bUpdate)
311 GetNormalWidget()->Update();
312
313 return true;
314}
315
317 CFWL_EventTextWillChange* event) {
319
321 eParam.m_wsChange = event->GetChangeText();
322 eParam.m_wsPrevText = event->GetPreviousText();
323 eParam.m_iSelStart = static_cast<int32_t>(event->GetSelectionStart());
324 eParam.m_iSelEnd = static_cast<int32_t>(event->GetSelectionEnd());
325 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Change, &eParam);
326
327 // Copy the data back out of the EventParam and into the TextChanged event so
328 // it can propagate back to the calling widget.
330 event->SetChangeText(eParam.m_wsChange);
331 event->SetSelectionStart(static_cast<size_t>(eParam.m_iSelStart));
332 event->SetSelectionEnd(static_cast<size_t>(eParam.m_iSelEnd));
333}
334
337 m_pNode->ProcessEvent(GetDocView(), XFA_AttributeValue::Full, &eParam);
338}
339
341 m_pOldDelegate->OnProcessMessage(pMessage);
342}
343
346 switch (pEvent->GetType()) {
348 OnTextWillChange(GetNormalWidget(),
349 static_cast<CFWL_EventTextWillChange*>(pEvent));
350 break;
352 OnTextFull(GetNormalWidget());
353 break;
354 default:
355 break;
356 }
357 m_pOldDelegate->OnProcessEvent(pEvent);
358}
359
361 const CFX_Matrix& matrix) {
362 m_pOldDelegate->OnDrawWidget(pGraphics, matrix);
363}
364
366 return ToEdit(GetNormalWidget())->CanUndo();
367}
368
370 return ToEdit(GetNormalWidget())->CanRedo();
371}
372
374 return ToEdit(GetNormalWidget())->HasSelection();
375}
376
378 if (ToEdit(GetNormalWidget())->GetStyleExts() & FWL_STYLEEXT_EDT_ReadOnly)
379 return false;
380 return ToEdit(GetNormalWidget())->HasSelection();
381}
382
384 return !(ToEdit(GetNormalWidget())->GetStyleExts() &
386}
387
389 return ToEdit(GetNormalWidget())->GetTextLength() > 0;
390}
391
393 return ToEdit(GetNormalWidget())->Undo();
394}
395
397 return ToEdit(GetNormalWidget())->Redo();
398}
399
401 return ToEdit(GetNormalWidget())->Copy();
402}
403
405 return ToEdit(GetNormalWidget())->Cut();
406}
407
408bool CXFA_FFTextEdit::Paste(const WideString& wsPaste) {
409 return ToEdit(GetNormalWidget())->Paste(wsPaste);
410}
411
413 ToEdit(GetNormalWidget())->SelectAll();
414}
415
417 ToEdit(GetNormalWidget())->ClearText();
418}
419
421 ToEdit(GetNormalWidget())->ClearSelection();
422}
423
425 return ToEdit(GetNormalWidget())->GetText();
426}
427
429 return FormFieldType::kXFA_TextField;
430}
#define FWL_STYLEEXT_EDT_MultiLine
Definition cfwl_edit.h:20
#define FWL_STYLEEXT_EDT_HFar
Definition cfwl_edit.h:30
#define FWL_STYLEEXT_EDT_ShowScrollbarFocus
Definition cfwl_edit.h:38
#define FWL_STYLEEXT_EDT_WantReturn
Definition cfwl_edit.h:21
#define FWL_STYLEEXT_EDT_VNear
Definition cfwl_edit.h:31
#define FWL_STYLEEXT_EDT_VCenter
Definition cfwl_edit.h:32
#define FWL_STYLEEXT_EDT_OuterScrollbar
Definition cfwl_edit.h:39
#define FWL_STYLEEXT_EDT_AutoHScroll
Definition cfwl_edit.h:22
#define FWL_STYLEEXT_EDT_ReadOnly
Definition cfwl_edit.h:19
#define FWL_STYLEEXT_EDT_VFar
Definition cfwl_edit.h:33
#define FWL_STYLEEXT_EDT_AutoVScroll
Definition cfwl_edit.h:23
#define FWL_STYLEEXT_EDT_HNear
Definition cfwl_edit.h:28
#define FWL_STYLEEXT_EDT_Justified
Definition cfwl_edit.h:34
#define FWL_STYLEEXT_EDT_CombText
Definition cfwl_edit.h:27
#define FWL_STYLEEXT_EDT_HCenter
Definition cfwl_edit.h:29
#define FWL_STYLE_WGT_VScroll
Definition cfwl_widget.h:37
void SetLimit(int32_t nLimit)
int32_t GetLimit() const
WideString GetText() const
virtual void SetTextSkipNotify(const WideString &wsText)
void SetChangeText(const WideString &change_text)
Type GetType() const
Definition cfwl_event.h:39
void UnregisterEventTarget(CFWL_Widget *pListener)
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
void SetDelegate(IFWL_WidgetDelegate *delegate)
void SetAdapterIface(AdapterIface *pItem)
CFWL_App * GetFWLApp() const
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)
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
void OnProcessEvent(CFWL_Event *pEvent) override
uint32_t UpdateUIProperty()
void SendMessageToFWLWidget(CFWL_Message *pMessage)
bool OnKillFocus(CXFA_FFWidget *pNewWidget) override
void OnProcessEvent(CFWL_Event *pEvent) override
void OnTextWillChange(CFWL_Widget *pWidget, CFWL_EventTextWillChange *change)
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
bool CanSelectAll() override
bool Redo() override
bool OnRButtonUp(Mask< XFA_FWL_KeyFlag > dwFlags, const CFX_PointF &point) override
~CXFA_FFTextEdit() override
bool Undo() override
absl::optional< WideString > Cut() override
bool CommitData() 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
absl::optional< WideString > Copy() 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:140
static WideString FromASCII(ByteStringView str)
FormFieldType
@ XFA_EVENT_Change
@ XFA_EVENT_Full
XFA_FFWidgetType
XFA_ValuePicture
Definition cxfa_node.h:70
XFA_FWL_KeyFlag
AlertIcon
Definition fxfa.h:20
AlertButton
Definition fxfa.h:11
XFA_WidgetStatus
Definition fxfa.h:61
XFA_Element
Definition fxfa_basic.h:75
XFA_AttributeValue
Definition fxfa_basic.h:60
Definition heap.h:12