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_ffnumericedit.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_ffnumericedit.h"
8
9#include "third_party/base/check.h"
10#include "xfa/fwl/cfwl_edit.h"
11#include "xfa/fwl/cfwl_eventvalidate.h"
12#include "xfa/fwl/cfwl_notedriver.h"
13#include "xfa/fxfa/cxfa_ffdoc.h"
14#include "xfa/fxfa/parser/cxfa_localevalue.h"
15#include "xfa/fxfa/parser/cxfa_node.h"
16#include "xfa/fxfa/parser/xfa_utils.h"
17
18CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_Node* pNode)
19 : CXFA_FFTextEdit(pNode) {}
20
21CXFA_FFNumericEdit::~CXFA_FFNumericEdit() = default;
22
23bool CXFA_FFNumericEdit::LoadWidget() {
24 DCHECK(!IsLoaded());
25
26 CFWL_Edit* pWidget = cppgc::MakeGarbageCollected<CFWL_Edit>(
27 GetFWLApp()->GetHeap()->GetAllocationHandle(), GetFWLApp(),
28 CFWL_Widget::Properties(), nullptr);
29 SetNormalWidget(pWidget);
30 pWidget->SetAdapterIface(this);
31
32 CFWL_NoteDriver* pNoteDriver = pWidget->GetFWLApp()->GetNoteDriver();
33 pNoteDriver->RegisterEventTarget(pWidget, pWidget);
34 m_pOldDelegate = pWidget->GetDelegate();
35 pWidget->SetDelegate(this);
36
37 {
38 CFWL_Widget::ScopedUpdateLock update_lock(pWidget);
39 pWidget->SetText(m_pNode->GetValue(XFA_ValuePicture::kDisplay));
41 }
42
44}
45
46void CXFA_FFNumericEdit::UpdateWidgetProperty() {
47 CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(GetNormalWidget());
48 if (!pWidget)
49 return;
50
51 uint32_t dwExtendedStyle =
54 dwExtendedStyle |= UpdateUIProperty();
55 if (!m_pNode->IsHorizontalScrollPolicyOff())
56 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
57
58 absl::optional<int32_t> numCells = m_pNode->GetNumberOfCells();
59 if (numCells.has_value() && numCells.value() > 0) {
60 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
61 pWidget->SetLimit(numCells.value());
62 }
63 dwExtendedStyle |= GetAlignment();
64 if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive())
65 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
66
67 GetNormalWidget()->ModifyStyleExts(dwExtendedStyle, 0xFFFFFFFF);
68}
69
70void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) {
72 CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent);
73 event->SetValidate(OnValidate(GetNormalWidget(), event->GetInsert()));
74 return;
75 }
77}
78
79bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget,
80 const WideString& wsText) {
81 WideString wsPattern = m_pNode->GetPictureContent(XFA_ValuePicture::kEdit);
82 if (!wsPattern.IsEmpty())
83 return true;
84
85 WideString wsFormat;
86 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pNode.Get());
87 widgetValue.GetNumericFormat(wsFormat, m_pNode->GetLeadDigits(),
88 m_pNode->GetFracDigits());
89 return widgetValue.ValidateNumericTemp(wsText, wsFormat,
90 m_pNode->GetLocale());
91}
#define FWL_STYLEEXT_EDT_ShowScrollbarFocus
Definition cfwl_edit.h:38
#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_Validate
Definition cfwl_edit.h:24
#define FWL_STYLEEXT_EDT_Number
Definition cfwl_edit.h:26
#define FWL_STYLEEXT_EDT_CombText
Definition cfwl_edit.h:27
void SetValidate(bool bValidate)
WideString GetInsert() const
Type GetType() const
Definition cfwl_event.h:39
void RegisterEventTarget(CFWL_Widget *pListener, CFWL_Widget *pEventSource)
void SetDelegate(IFWL_WidgetDelegate *delegate)
void SetAdapterIface(AdapterIface *pItem)
CFWL_App * GetFWLApp() const
bool LoadWidget() override
void SetNormalWidget(CFWL_Widget *widget)
uint32_t UpdateUIProperty()
CXFA_FFNumericEdit(CXFA_Node *pNode)
void OnProcessEvent(CFWL_Event *pEvent) override
bool LoadWidget() override
~CXFA_FFNumericEdit() override
void UpdateWidgetProperty() override
void OnProcessEvent(CFWL_Event *pEvent) override
CXFA_FFTextEdit(CXFA_Node *pNode)
bool IsEmpty() const
Definition widestring.h:118