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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
// 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_ffdatetimeedit.h"
#include <utility>
#include "xfa/fwl/cfwl_datetimepicker.h"
#include "xfa/fwl/cfwl_eventselectchanged.h"
#include "xfa/fwl/cfwl_notedriver.h"
#include "xfa/fwl/cfwl_widget.h"
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/cxfa_ffdoc.h"
#include "xfa/fxfa/parser/cxfa_localevalue.h"
#include "xfa/fxfa/parser/cxfa_para.h"
#include "xfa/fxfa/parser/cxfa_value.h"
#include "xfa/fxfa/parser/xfa_utils.h"
CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_Node* pNode)
: CXFA_FFTextEdit(pNode) {}
CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {}
CFWL_DateTimePicker* CXFA_FFDateTimeEdit::GetPickerWidget() {
return static_cast<CFWL_DateTimePicker*>(m_pNormalWidget.get());
}
CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, FocusOption focus) {
if (focus == kDrawFocus)
return CFX_RectF();
return CXFA_FFWidget::GetBBox(dwStatus, kDoNotDrawFocus);
}
bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) {
CFWL_DateTimePicker* pPicker = GetPickerWidget();
return pPicker && pPicker->GetBBox().Contains(point);
}
bool CXFA_FFDateTimeEdit::LoadWidget() {
auto pNewPicker = pdfium::MakeUnique<CFWL_DateTimePicker>(GetFWLApp());
CFWL_DateTimePicker* pWidget = pNewPicker.get();
m_pNormalWidget = std::move(pNewPicker);
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_pNode->GetValue(XFA_VALUEPICTURE_Display);
pWidget->SetEditText(wsText);
CXFA_Value* value = m_pNode->GetFormValueIfExists();
if (value) {
switch (value->GetChildValueClassID()) {
case XFA_Element::Date: {
if (!wsText.IsEmpty()) {
CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pNode.Get());
CFX_DateTime date = lcValue.GetDate();
if (date.IsSet())
pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
}
} break;
default:
break;
}
}
UpdateWidgetProperty();
m_pNormalWidget->UnlockUpdate();
return CXFA_FFField::LoadWidget();
}
void CXFA_FFDateTimeEdit::UpdateWidgetProperty() {
CFWL_DateTimePicker* pPicker = GetPickerWidget();
if (!pPicker)
return;
uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat;
dwExtendedStyle |= UpdateUIProperty();
dwExtendedStyle |= GetAlignment();
m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
uint32_t dwEditStyles = 0;
Optional<int32_t> numCells = m_pNode->GetNumberOfCells();
if (numCells && *numCells > 0) {
dwEditStyles |= FWL_STYLEEXT_EDT_CombText;
pPicker->SetEditLimit(*numCells);
}
if (!m_pNode->IsOpenAccess() || !GetDoc()->GetXFADoc()->IsInteractive())
dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly;
if (!m_pNode->IsHorizontalScrollPolicyOff())
dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll;
pPicker->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF);
}
uint32_t CXFA_FFDateTimeEdit::GetAlignment() {
CXFA_Para* para = m_pNode->GetParaIfExists();
if (!para)
return 0;
uint32_t dwExtendedStyle = 0;
switch (para->GetHorizontalAlign()) {
case XFA_AttributeEnum::Center:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter;
break;
case XFA_AttributeEnum::Justify:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified;
break;
case XFA_AttributeEnum::JustifyAll:
case XFA_AttributeEnum::Radix:
break;
case XFA_AttributeEnum::Right:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar;
break;
default:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear;
break;
}
switch (para->GetVerticalAlign()) {
case XFA_AttributeEnum::Middle:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter;
break;
case XFA_AttributeEnum::Bottom:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar;
break;
default:
dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear;
break;
}
return dwExtendedStyle;
}
bool CXFA_FFDateTimeEdit::CommitData() {
CFWL_DateTimePicker* pPicker = GetPickerWidget();
if (!m_pNode->SetValue(XFA_VALUEPICTURE_Edit, pPicker->GetEditText()))
return false;
m_pNode->UpdateUIDisplay(GetDoc()->GetDocView(), this);
return true;
}
bool CXFA_FFDateTimeEdit::UpdateFWLData() {
if (!m_pNormalWidget)
return false;
XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;
if (IsFocused())
eType = XFA_VALUEPICTURE_Edit;
WideString wsText = m_pNode->GetValue(eType);
CFWL_DateTimePicker* pPicker = GetPickerWidget();
pPicker->SetEditText(wsText);
if (IsFocused() && !wsText.IsEmpty()) {
CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pNode.Get());
CFX_DateTime date = lcValue.GetDate();
if (lcValue.IsValid()) {
if (date.IsSet())
pPicker->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
}
}
m_pNormalWidget->Update();
return true;
}
bool CXFA_FFDateTimeEdit::IsDataChanged() {
if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged)
return true;
WideString wsText = GetPickerWidget()->GetEditText();
return m_pNode->GetValue(XFA_VALUEPICTURE_Edit) != wsText;
}
void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget,
int32_t iYear,
int32_t iMonth,
int32_t iDay) {
WideString wsPicture = m_pNode->GetPictureContent(XFA_VALUEPICTURE_Edit);
CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocaleMgr());
date.SetDate(CFX_DateTime(iYear, iMonth, iDay, 0, 0, 0, 0));
WideString wsDate;
date.FormatPatterns(wsDate, wsPicture, m_pNode->GetLocale(),
XFA_VALUEPICTURE_Edit);
CFWL_DateTimePicker* pPicker = GetPickerWidget();
pPicker->SetEditText(wsDate);
pPicker->Update();
GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr);
CXFA_EventParam eParam;
eParam.m_eType = XFA_EVENT_Change;
eParam.m_pTarget = m_pNode.Get();
eParam.m_wsPrevText = m_pNode->GetValue(XFA_VALUEPICTURE_Raw);
m_pNode->ProcessEvent(GetDocView(), XFA_AttributeEnum::Change, &eParam);
}
void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) {
if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) {
auto* event = static_cast<CFWL_EventSelectChanged*>(pEvent);
OnSelectChanged(m_pNormalWidget.get(), event->iYear, event->iMonth,
event->iDay);
return;
}
CXFA_FFTextEdit::OnProcessEvent(pEvent);
}
bool CXFA_FFDateTimeEdit::CanUndo() {
return GetPickerWidget()->CanUndo();
}
bool CXFA_FFDateTimeEdit::CanRedo() {
return GetPickerWidget()->CanRedo();
}
bool CXFA_FFDateTimeEdit::Undo() {
return GetPickerWidget()->Undo();
}
bool CXFA_FFDateTimeEdit::Redo() {
return GetPickerWidget()->Redo();
}
bool CXFA_FFDateTimeEdit::CanCopy() {
return GetPickerWidget()->HasSelection();
}
bool CXFA_FFDateTimeEdit::CanCut() {
if (GetPickerWidget()->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)
return false;
return GetPickerWidget()->HasSelection();
}
bool CXFA_FFDateTimeEdit::CanPaste() {
return !(GetPickerWidget()->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly);
}
bool CXFA_FFDateTimeEdit::CanSelectAll() {
return GetPickerWidget()->GetEditTextLength() > 0;
}
Optional<WideString> CXFA_FFDateTimeEdit::Copy() {
return GetPickerWidget()->Copy();
}
Optional<WideString> CXFA_FFDateTimeEdit::Cut() {
return GetPickerWidget()->Cut();
}
bool CXFA_FFDateTimeEdit::Paste(const WideString& wsPaste) {
return GetPickerWidget()->Paste(wsPaste);
}
void CXFA_FFDateTimeEdit::SelectAll() {
GetPickerWidget()->SelectAll();
}
void CXFA_FFDateTimeEdit::Delete() {
GetPickerWidget()->ClearText();
}
void CXFA_FFDateTimeEdit::DeSelect() {
GetPickerWidget()->ClearSelection();
}
WideString CXFA_FFDateTimeEdit::GetText() {
return GetPickerWidget()->GetEditText();
}
|