blob: 8f020351c2b15c51f676d293781430e2a849b632 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#include "xfa/fxfa/cxfa_ffnumericedit.h"
#include <utility>
#include "xfa/fwl/cfwl_edit.h"
#include "xfa/fwl/cfwl_eventvalidate.h"
#include "xfa/fwl/cfwl_notedriver.h"
#include "xfa/fxfa/cxfa_ffdoc.h"
#include "xfa/fxfa/parser/cxfa_localevalue.h"
#include "xfa/fxfa/parser/xfa_utils.h"
CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc)
: CXFA_FFTextEdit(pDataAcc) {}
CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {}
bool CXFA_FFNumericEdit::LoadWidget() {
auto pNewEdit = pdfium::MakeUnique<CFWL_Edit>(
GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);
CFWL_Edit* pWidget = pNewEdit.get();
m_pNormalWidget = std::move(pNewEdit);
m_pNormalWidget->SetLayoutItem(this);
CFWL_NoteDriver* pNoteDriver =
m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
pNoteDriver->RegisterEventTarget(m_pNormalWidget.get(),
m_pNormalWidget.get());
m_pOldDelegate = m_pNormalWidget->GetDelegate();
m_pNormalWidget->SetDelegate(this);
m_pNormalWidget->LockUpdate();
WideString wsText;
m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
pWidget->SetText(wsText);
UpdateWidgetProperty();
m_pNormalWidget->UnlockUpdate();
return CXFA_FFField::LoadWidget();
}
void CXFA_FFNumericEdit::UpdateWidgetProperty() {
CFWL_Edit* pWidget = static_cast<CFWL_Edit*>(m_pNormalWidget.get());
if (!pWidget)
return;
uint32_t dwExtendedStyle =
FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar |
FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number;
dwExtendedStyle |= UpdateUIProperty();
if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off)
dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
if (iNumCells > 0) {
dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
pWidget->SetLimit(iNumCells);
}
dwExtendedStyle |= GetAlignment();
if (!m_pDataAcc->IsOpenAccess() ||
!m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
}
m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
}
void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) {
if (pEvent->GetType() == CFWL_Event::Type::Validate) {
CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent);
event->bValidate = OnValidate(m_pNormalWidget.get(), event->wsInsert);
return;
}
CXFA_FFTextEdit::OnProcessEvent(pEvent);
}
bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget, WideString& wsText) {
WideString wsPattern = m_pDataAcc->GetPictureContent(XFA_VALUEPICTURE_Edit);
if (!wsPattern.IsEmpty())
return true;
int32_t iLeads = 0;
m_pDataAcc->GetLeadDigits(iLeads);
int32_t iFracs = 0;
m_pDataAcc->GetFracDigits(iFracs);
WideString wsFormat;
CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc.Get());
widgetValue.GetNumericFormat(wsFormat, iLeads, iFracs);
return widgetValue.ValidateNumericTemp(wsText, wsFormat,
m_pDataAcc->GetLocal());
}
|