blob: 094839f48626a57e9491005d0e329e7536758e26 [file] [log] [blame]
Dan Sinclair1770c022016-03-14 14:14:16 -04001// Copyright 2014 PDFium Authors. All rights reserved.
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/app/xfa_fftextedit.h"
8
9#include <vector>
10
dsinclair447b1f32016-12-08 10:06:32 -080011#include "xfa/fwl/cfwl_datetimepicker.h"
12#include "xfa/fwl/cfwl_edit.h"
13#include "xfa/fwl/cfwl_eventcheckword.h"
14#include "xfa/fwl/cfwl_eventselectchanged.h"
15#include "xfa/fwl/cfwl_eventtextchanged.h"
16#include "xfa/fwl/cfwl_eventvalidate.h"
17#include "xfa/fwl/cfwl_messagekillfocus.h"
18#include "xfa/fwl/cfwl_messagemouse.h"
19#include "xfa/fwl/cfwl_messagesetfocus.h"
20#include "xfa/fwl/cfwl_notedriver.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040021#include "xfa/fxfa/app/xfa_fffield.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040022#include "xfa/fxfa/app/xfa_fwladapter.h"
dsinclair5b493092016-09-29 20:20:24 -070023#include "xfa/fxfa/cxfa_eventparam.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040024#include "xfa/fxfa/parser/xfa_localevalue.h"
dsinclair5b493092016-09-29 20:20:24 -070025#include "xfa/fxfa/xfa_ffapp.h"
26#include "xfa/fxfa/xfa_ffdoc.h"
27#include "xfa/fxfa/xfa_ffdocview.h"
28#include "xfa/fxfa/xfa_ffpageview.h"
29#include "xfa/fxfa/xfa_ffwidget.h"
Dan Sinclair1770c022016-03-14 14:14:16 -040030
dan sinclairaaf0bdc2017-02-04 10:16:21 -050031CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_WidgetAcc* pDataAcc)
32 : CXFA_FFField(pDataAcc), m_pOldDelegate(nullptr) {}
dsinclair20855382016-10-31 07:29:34 -070033
Dan Sinclair1770c022016-03-14 14:14:16 -040034CXFA_FFTextEdit::~CXFA_FFTextEdit() {
35 if (m_pNormalWidget) {
dsinclair2c489cc2016-11-23 16:17:20 -080036 CFWL_NoteDriver* pNoteDriver =
37 m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
38 pNoteDriver->UnregisterEventTarget(m_pNormalWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -040039 }
40}
dsinclair20855382016-10-31 07:29:34 -070041
tsepezd19e9122016-11-02 15:43:18 -070042bool CXFA_FFTextEdit::LoadWidget() {
dsinclair2c489cc2016-11-23 16:17:20 -080043 CFWL_Edit* pFWLEdit = new CFWL_Edit(
44 GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -040045 m_pNormalWidget = pFWLEdit;
tsepez54ab2342016-05-26 17:35:54 -070046 m_pNormalWidget->SetLayoutItem(this);
dsinclair20855382016-10-31 07:29:34 -070047
dsinclair2c489cc2016-11-23 16:17:20 -080048 CFWL_NoteDriver* pNoteDriver =
49 m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
50 pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
dsinclair9ec22172016-11-01 08:33:02 -070051
dsinclair3b3ce1a2016-11-02 14:51:25 -070052 m_pOldDelegate = m_pNormalWidget->GetDelegate();
53 m_pNormalWidget->SetDelegate(this);
Dan Sinclair1770c022016-03-14 14:14:16 -040054 m_pNormalWidget->LockUpdate();
dsinclair9ec22172016-11-01 08:33:02 -070055
Dan Sinclair1770c022016-03-14 14:14:16 -040056 UpdateWidgetProperty();
57 CFX_WideString wsText;
58 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
59 pFWLEdit->SetText(wsText);
60 m_pNormalWidget->UnlockUpdate();
61 return CXFA_FFField::LoadWidget();
62}
63void CXFA_FFTextEdit::UpdateWidgetProperty() {
64 CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;
65 if (!pWidget) {
66 return;
67 }
tsepez736f28a2016-03-25 14:19:51 -070068 uint32_t dwStyle = 0;
69 uint32_t dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus |
Dan Sinclair1770c022016-03-14 14:14:16 -040070 FWL_STYLEEXT_EDT_OuterScrollbar |
71 FWL_STYLEEXT_EDT_LastLineHeight;
72 dwExtendedStyle |= UpdateUIProperty();
73 if (m_pDataAcc->IsMultiLine()) {
74 dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn;
75 if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
76 dwStyle |= FWL_WGTSTYLE_VScroll;
77 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll;
78 }
79 } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
80 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
81 }
82 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
83 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
84 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
85 dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine;
86 }
dsinclair56a8b192016-06-21 14:15:25 -070087 XFA_Element eType = XFA_Element::Unknown;
Dan Sinclair1770c022016-03-14 14:14:16 -040088 int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType);
dsinclair56a8b192016-06-21 14:15:25 -070089 if (eType == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -040090 iMaxChars = 0;
91 }
92 int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
93 if (iNumCells == 0) {
94 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
95 pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1);
96 } else if (iNumCells > 0) {
97 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
98 pWidget->SetLimit(iNumCells);
99 } else {
100 pWidget->SetLimit(iMaxChars);
101 }
102 dwExtendedStyle |= GetAlignment();
103 m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF);
104 m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
105}
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500106
107bool CXFA_FFTextEdit::OnLButtonDown(uint32_t dwFlags, const CFX_PointF& point) {
108 if (!PtInActiveRect(point))
tsepezd19e9122016-11-02 15:43:18 -0700109 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400110 if (!IsFocused()) {
dsinclair935d8d52016-05-17 10:32:18 -0700111 m_dwStatus |= XFA_WidgetStatus_Focused;
Dan Sinclair1770c022016-03-14 14:14:16 -0400112 UpdateFWLData();
113 AddInvalidateRect();
114 }
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500115
tsepezd19e9122016-11-02 15:43:18 -0700116 SetButtonDown(true);
dsinclair447b1f32016-12-08 10:06:32 -0800117 CFWL_MessageMouse ms(nullptr, m_pNormalWidget);
dsinclair8f4bf9a2016-05-04 13:51:51 -0700118 ms.m_dwCmd = FWL_MouseCommand::LeftButtonDown;
Dan Sinclair1770c022016-03-14 14:14:16 -0400119 ms.m_dwFlags = dwFlags;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500120 ms.m_pos = FWLToClient(point);
Dan Sinclair1770c022016-03-14 14:14:16 -0400121 TranslateFWLMessage(&ms);
tsepezd19e9122016-11-02 15:43:18 -0700122 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400123}
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500124
125bool CXFA_FFTextEdit::OnRButtonDown(uint32_t dwFlags, const CFX_PointF& point) {
126 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open)
tsepezd19e9122016-11-02 15:43:18 -0700127 return false;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500128 if (!PtInActiveRect(point))
tsepezd19e9122016-11-02 15:43:18 -0700129 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400130 if (!IsFocused()) {
dsinclair935d8d52016-05-17 10:32:18 -0700131 m_dwStatus |= XFA_WidgetStatus_Focused;
Dan Sinclair1770c022016-03-14 14:14:16 -0400132 UpdateFWLData();
133 AddInvalidateRect();
134 }
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500135
tsepezd19e9122016-11-02 15:43:18 -0700136 SetButtonDown(true);
dsinclair447b1f32016-12-08 10:06:32 -0800137 CFWL_MessageMouse ms(nullptr, nullptr);
dsinclair8f4bf9a2016-05-04 13:51:51 -0700138 ms.m_dwCmd = FWL_MouseCommand::RightButtonDown;
Dan Sinclair1770c022016-03-14 14:14:16 -0400139 ms.m_dwFlags = dwFlags;
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500140 ms.m_pos = FWLToClient(point);
Dan Sinclair1770c022016-03-14 14:14:16 -0400141 TranslateFWLMessage(&ms);
tsepezd19e9122016-11-02 15:43:18 -0700142 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400143}
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500144
145bool CXFA_FFTextEdit::OnRButtonUp(uint32_t dwFlags, const CFX_PointF& point) {
146 if (!CXFA_FFField::OnRButtonUp(dwFlags, point))
tsepezd19e9122016-11-02 15:43:18 -0700147 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400148
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500149 GetDoc()->GetDocEnvironment()->PopupMenu(this, point);
tsepezd19e9122016-11-02 15:43:18 -0700150 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400151}
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500152
tsepezd19e9122016-11-02 15:43:18 -0700153bool CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) {
dsinclair935d8d52016-05-17 10:32:18 -0700154 m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged;
Dan Sinclair1770c022016-03-14 14:14:16 -0400155 if (!IsFocused()) {
dsinclair935d8d52016-05-17 10:32:18 -0700156 m_dwStatus |= XFA_WidgetStatus_Focused;
Dan Sinclair1770c022016-03-14 14:14:16 -0400157 UpdateFWLData();
158 AddInvalidateRect();
159 }
160 CXFA_FFWidget::OnSetFocus(pOldWidget);
dsinclair447b1f32016-12-08 10:06:32 -0800161 CFWL_MessageSetFocus ms(nullptr, m_pNormalWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -0400162 TranslateFWLMessage(&ms);
tsepezd19e9122016-11-02 15:43:18 -0700163 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400164}
tsepezd19e9122016-11-02 15:43:18 -0700165bool CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) {
dsinclair447b1f32016-12-08 10:06:32 -0800166 CFWL_MessageKillFocus ms(nullptr, m_pNormalWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -0400167 TranslateFWLMessage(&ms);
dsinclair935d8d52016-05-17 10:32:18 -0700168 m_dwStatus &= ~XFA_WidgetStatus_Focused;
Dan Sinclair1770c022016-03-14 14:14:16 -0400169 SetEditScrollOffset();
170 ProcessCommittedData();
171 UpdateFWLData();
172 AddInvalidateRect();
173 CXFA_FFWidget::OnKillFocus(pNewWidget);
dsinclair935d8d52016-05-17 10:32:18 -0700174 m_dwStatus &= ~XFA_WidgetStatus_TextEditValueChanged;
tsepezd19e9122016-11-02 15:43:18 -0700175 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400176}
tsepezd19e9122016-11-02 15:43:18 -0700177bool CXFA_FFTextEdit::CommitData() {
dan sinclair0354ccf2016-11-24 10:45:29 -0500178 CFX_WideString wsText = static_cast<CFWL_Edit*>(m_pNormalWidget)->GetText();
Dan Sinclair1770c022016-03-14 14:14:16 -0400179 if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) {
180 m_pDataAcc->UpdateUIDisplay(this);
tsepezd19e9122016-11-02 15:43:18 -0700181 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400182 }
183 ValidateNumberField(wsText);
tsepezd19e9122016-11-02 15:43:18 -0700184 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400185}
186void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) {
187 CXFA_WidgetAcc* pAcc = GetDataAcc();
dsinclair56a8b192016-06-21 14:15:25 -0700188 if (pAcc && pAcc->GetUIType() == XFA_Element::NumericEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400189 IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider();
190 if (pAppProvider) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400191 CFX_WideString wsSomField;
192 pAcc->GetNode()->GetSOMExpression(wsSomField);
Dan Sinclairc8fd3312017-01-02 17:17:02 -0500193
tsepez3f80c862016-05-16 12:03:24 -0700194 CFX_WideString wsMessage;
Dan Sinclairc8fd3312017-01-02 17:17:02 -0500195 wsMessage.Format(L"%s can not contain %s", wsText.c_str(),
196 wsSomField.c_str());
197 pAppProvider->MsgBox(wsMessage, pAppProvider->GetAppTitle(),
198 XFA_MBICON_Error, XFA_MB_OK);
Dan Sinclair1770c022016-03-14 14:14:16 -0400199 }
200 }
201}
tsepezd19e9122016-11-02 15:43:18 -0700202bool CXFA_FFTextEdit::IsDataChanged() {
dsinclair935d8d52016-05-17 10:32:18 -0700203 return (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) != 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400204}
tsepez736f28a2016-03-25 14:19:51 -0700205uint32_t CXFA_FFTextEdit::GetAlignment() {
206 uint32_t dwExtendedStyle = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400207 if (CXFA_Para para = m_pDataAcc->GetPara()) {
208 int32_t iHorz = para.GetHorizontalAlign();
209 switch (iHorz) {
210 case XFA_ATTRIBUTEENUM_Center:
211 dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter;
212 break;
213 case XFA_ATTRIBUTEENUM_Justify:
214 dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified;
215 break;
216 case XFA_ATTRIBUTEENUM_JustifyAll:
217 break;
218 case XFA_ATTRIBUTEENUM_Radix:
219 break;
220 case XFA_ATTRIBUTEENUM_Right:
221 dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar;
222 break;
223 default:
224 dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear;
225 break;
226 }
227 int32_t iVert = para.GetVerticalAlign();
228 switch (iVert) {
229 case XFA_ATTRIBUTEENUM_Middle:
230 dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter;
231 break;
232 case XFA_ATTRIBUTEENUM_Bottom:
233 dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar;
234 break;
235 default:
236 dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear;
237 break;
238 }
239 }
240 return dwExtendedStyle;
241}
tsepezd19e9122016-11-02 15:43:18 -0700242bool CXFA_FFTextEdit::UpdateFWLData() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400243 if (!m_pNormalWidget) {
tsepezd19e9122016-11-02 15:43:18 -0700244 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400245 }
246 XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;
247 if (IsFocused()) {
248 eType = XFA_VALUEPICTURE_Edit;
249 }
tsepezd19e9122016-11-02 15:43:18 -0700250 bool bUpdate = false;
dsinclair56a8b192016-06-21 14:15:25 -0700251 if (m_pDataAcc->GetUIType() == XFA_Element::TextEdit &&
Dan Sinclair1770c022016-03-14 14:14:16 -0400252 m_pDataAcc->GetNumberOfCells() < 0) {
dsinclair56a8b192016-06-21 14:15:25 -0700253 XFA_Element elementType = XFA_Element::Unknown;
Dan Sinclair1770c022016-03-14 14:14:16 -0400254 int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType);
dsinclair56a8b192016-06-21 14:15:25 -0700255 if (elementType == XFA_Element::ExData) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400256 iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0;
257 }
258 if (((CFWL_Edit*)m_pNormalWidget)->GetLimit() != iMaxChars) {
259 ((CFWL_Edit*)m_pNormalWidget)->SetLimit(iMaxChars);
tsepezd19e9122016-11-02 15:43:18 -0700260 bUpdate = true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400261 }
262 }
dsinclair56a8b192016-06-21 14:15:25 -0700263 if (m_pDataAcc->GetUIType() == XFA_Element::Barcode) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400264 int32_t nDataLen = 0;
265 if (eType == XFA_VALUEPICTURE_Edit)
266 m_pDataAcc->GetBarcodeAttribute_DataLength(nDataLen);
267 static_cast<CFWL_Edit*>(m_pNormalWidget)->SetLimit(nDataLen);
tsepezd19e9122016-11-02 15:43:18 -0700268 bUpdate = true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400269 }
270 CFX_WideString wsText;
271 m_pDataAcc->GetValue(wsText, eType);
dan sinclair0354ccf2016-11-24 10:45:29 -0500272 CFX_WideString wsOldText =
273 static_cast<CFWL_Edit*>(m_pNormalWidget)->GetText();
Dan Sinclair1770c022016-03-14 14:14:16 -0400274 if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) {
275 ((CFWL_Edit*)m_pNormalWidget)->SetText(wsText);
tsepezd19e9122016-11-02 15:43:18 -0700276 bUpdate = true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400277 }
278 if (bUpdate) {
279 m_pNormalWidget->Update();
280 }
tsepezd19e9122016-11-02 15:43:18 -0700281 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400282}
dsinclair2c489cc2016-11-23 16:17:20 -0800283void CXFA_FFTextEdit::OnTextChanged(CFWL_Widget* pWidget,
Dan Sinclair1770c022016-03-14 14:14:16 -0400284 const CFX_WideString& wsChanged,
285 const CFX_WideString& wsPrevText) {
dsinclair935d8d52016-05-17 10:32:18 -0700286 m_dwStatus |= XFA_WidgetStatus_TextEditValueChanged;
Dan Sinclair1770c022016-03-14 14:14:16 -0400287 CXFA_EventParam eParam;
288 eParam.m_eType = XFA_EVENT_Change;
289 eParam.m_wsChange = wsChanged;
290 eParam.m_pTarget = m_pDataAcc;
291 eParam.m_wsPrevText = wsPrevText;
292 CFWL_Edit* pEdit = ((CFWL_Edit*)m_pNormalWidget);
dsinclair56a8b192016-06-21 14:15:25 -0700293 if (m_pDataAcc->GetUIType() == XFA_Element::DateTimeEdit) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400294 CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit;
dan sinclair0354ccf2016-11-24 10:45:29 -0500295 eParam.m_wsNewText = pDateTime->GetEditText();
Dan Sinclair1770c022016-03-14 14:14:16 -0400296 int32_t iSels = pDateTime->CountSelRanges();
297 if (iSels) {
dsinclair442997c2016-12-07 17:58:41 -0800298 eParam.m_iSelEnd = pDateTime->GetSelRange(0, &eParam.m_iSelStart);
Dan Sinclair1770c022016-03-14 14:14:16 -0400299 }
300 } else {
dan sinclair0354ccf2016-11-24 10:45:29 -0500301 eParam.m_wsNewText = pEdit->GetText();
Dan Sinclair1770c022016-03-14 14:14:16 -0400302 int32_t iSels = pEdit->CountSelRanges();
303 if (iSels) {
dsinclair442997c2016-12-07 17:58:41 -0800304 eParam.m_iSelEnd = pEdit->GetSelRange(0, &eParam.m_iSelStart);
Dan Sinclair1770c022016-03-14 14:14:16 -0400305 }
306 }
307 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);
308}
dsinclair2c489cc2016-11-23 16:17:20 -0800309void CXFA_FFTextEdit::OnTextFull(CFWL_Widget* pWidget) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400310 CXFA_EventParam eParam;
311 eParam.m_eType = XFA_EVENT_Full;
312 eParam.m_pTarget = m_pDataAcc;
313 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam);
314}
315
tsepezd19e9122016-11-02 15:43:18 -0700316bool CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) {
dsinclair89f8fa82016-09-14 06:11:08 -0700317 if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_Element::TextEdit)
tsepezd19e9122016-11-02 15:43:18 -0700318 return true;
319 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400320}
dsinclairc777f482016-05-04 17:57:03 -0700321
322void CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) {
323 m_pOldDelegate->OnProcessMessage(pMessage);
Dan Sinclair1770c022016-03-14 14:14:16 -0400324}
dsinclair5d9da0c2016-04-21 13:12:06 -0700325
dsinclairc777f482016-05-04 17:57:03 -0700326void CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400327 CXFA_FFField::OnProcessEvent(pEvent);
dsinclair4614b452016-12-07 17:01:58 -0800328 switch (pEvent->GetType()) {
329 case CFWL_Event::Type::TextChanged: {
dsinclair447b1f32016-12-08 10:06:32 -0800330 CFWL_EventTextChanged* event =
331 static_cast<CFWL_EventTextChanged*>(pEvent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400332 CFX_WideString wsChange;
dsinclair2c489cc2016-11-23 16:17:20 -0800333 OnTextChanged(m_pNormalWidget, wsChange, event->wsPrevText);
Dan Sinclair1770c022016-03-14 14:14:16 -0400334 break;
335 }
dsinclair4614b452016-12-07 17:01:58 -0800336 case CFWL_Event::Type::TextFull: {
dsinclair2c489cc2016-11-23 16:17:20 -0800337 OnTextFull(m_pNormalWidget);
Dan Sinclair1770c022016-03-14 14:14:16 -0400338 break;
339 }
dsinclair4614b452016-12-07 17:01:58 -0800340 case CFWL_Event::Type::CheckWord: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400341 CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged");
dsinclair447b1f32016-12-08 10:06:32 -0800342 CFWL_EventCheckWord* event = static_cast<CFWL_EventCheckWord*>(pEvent);
tsepez4c3debb2016-04-08 12:20:38 -0700343 event->bCheckWord = CheckWord(event->bsWord.AsStringC());
Dan Sinclair1770c022016-03-14 14:14:16 -0400344 break;
345 }
dsinclair5d9da0c2016-04-21 13:12:06 -0700346 default:
347 break;
Dan Sinclair1770c022016-03-14 14:14:16 -0400348 }
dsinclairc777f482016-05-04 17:57:03 -0700349 m_pOldDelegate->OnProcessEvent(pEvent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400350}
dsinclair5d9da0c2016-04-21 13:12:06 -0700351
dsinclairc777f482016-05-04 17:57:03 -0700352void CXFA_FFTextEdit::OnDrawWidget(CFX_Graphics* pGraphics,
353 const CFX_Matrix* pMatrix) {
354 m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix);
Dan Sinclair1770c022016-03-14 14:14:16 -0400355}
dsinclairc777f482016-05-04 17:57:03 -0700356
dan sinclairaaf0bdc2017-02-04 10:16:21 -0500357CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_WidgetAcc* pDataAcc)
358 : CXFA_FFTextEdit(pDataAcc) {}
359
Dan Sinclair1770c022016-03-14 14:14:16 -0400360CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {}
dan sinclairaaf0bdc2017-02-04 10:16:21 -0500361
tsepezd19e9122016-11-02 15:43:18 -0700362bool CXFA_FFNumericEdit::LoadWidget() {
dsinclair2c489cc2016-11-23 16:17:20 -0800363 CFWL_Edit* pWidget = new CFWL_Edit(
364 GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);
tsepez20d6b762016-06-09 11:46:16 -0700365 m_pNormalWidget = pWidget;
dsinclair20855382016-10-31 07:29:34 -0700366
tsepez54ab2342016-05-26 17:35:54 -0700367 m_pNormalWidget->SetLayoutItem(this);
dsinclair2c489cc2016-11-23 16:17:20 -0800368 CFWL_NoteDriver* pNoteDriver =
369 m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
370 pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
dsinclair9ec22172016-11-01 08:33:02 -0700371
dsinclair3b3ce1a2016-11-02 14:51:25 -0700372 m_pOldDelegate = m_pNormalWidget->GetDelegate();
373 m_pNormalWidget->SetDelegate(this);
Dan Sinclair1770c022016-03-14 14:14:16 -0400374 m_pNormalWidget->LockUpdate();
dsinclair9ec22172016-11-01 08:33:02 -0700375
Dan Sinclair1770c022016-03-14 14:14:16 -0400376 CFX_WideString wsText;
377 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
378 pWidget->SetText(wsText);
379 UpdateWidgetProperty();
380 m_pNormalWidget->UnlockUpdate();
381 return CXFA_FFField::LoadWidget();
382}
383void CXFA_FFNumericEdit::UpdateWidgetProperty() {
384 CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;
385 if (!pWidget) {
386 return;
387 }
tsepez736f28a2016-03-25 14:19:51 -0700388 uint32_t dwExtendedStyle =
Dan Sinclair1770c022016-03-14 14:14:16 -0400389 FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar |
390 FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number |
391 FWL_STYLEEXT_EDT_LastLineHeight;
392 dwExtendedStyle |= UpdateUIProperty();
393 if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
394 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
395 }
396 int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
397 if (iNumCells > 0) {
398 dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
399 pWidget->SetLimit(iNumCells);
400 }
401 dwExtendedStyle |= GetAlignment();
402 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
403 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
404 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
405 }
406 m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
407}
dsinclair5d9da0c2016-04-21 13:12:06 -0700408
dsinclairc777f482016-05-04 17:57:03 -0700409void CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) {
dsinclair4614b452016-12-07 17:01:58 -0800410 if (pEvent->GetType() == CFWL_Event::Type::Validate) {
dsinclair447b1f32016-12-08 10:06:32 -0800411 CFWL_EventValidate* event = static_cast<CFWL_EventValidate*>(pEvent);
dsinclair2c489cc2016-11-23 16:17:20 -0800412 event->bValidate = OnValidate(m_pNormalWidget, event->wsInsert);
dsinclairc777f482016-05-04 17:57:03 -0700413 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400414 }
dsinclairc777f482016-05-04 17:57:03 -0700415 CXFA_FFTextEdit::OnProcessEvent(pEvent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400416}
dsinclair5d9da0c2016-04-21 13:12:06 -0700417
dsinclair2c489cc2016-11-23 16:17:20 -0800418bool CXFA_FFNumericEdit::OnValidate(CFWL_Widget* pWidget,
tsepezd19e9122016-11-02 15:43:18 -0700419 CFX_WideString& wsText) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400420 CFX_WideString wsPattern;
421 m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit);
422 if (!wsPattern.IsEmpty()) {
tsepezd19e9122016-11-02 15:43:18 -0700423 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400424 }
425 int32_t iLeads = 0;
426 m_pDataAcc->GetLeadDigits(iLeads);
427 int32_t iFracs = 0;
428 m_pDataAcc->GetFracDigits(iFracs);
429 CFX_WideString wsFormat;
430 CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc);
431 widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs);
432 return widgetValue.ValidateNumericTemp(wsText, wsFormat,
433 m_pDataAcc->GetLocal());
434}
dan sinclairaaf0bdc2017-02-04 10:16:21 -0500435
436CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_WidgetAcc* pDataAcc)
437 : CXFA_FFTextEdit(pDataAcc) {}
dsinclair20855382016-10-31 07:29:34 -0700438
Dan Sinclair1770c022016-03-14 14:14:16 -0400439CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {}
dsinclair20855382016-10-31 07:29:34 -0700440
tsepezd19e9122016-11-02 15:43:18 -0700441bool CXFA_FFPasswordEdit::LoadWidget() {
dsinclair2c489cc2016-11-23 16:17:20 -0800442 CFWL_Edit* pWidget = new CFWL_Edit(
443 GetFWLApp(), pdfium::MakeUnique<CFWL_WidgetProperties>(), nullptr);
tsepez20d6b762016-06-09 11:46:16 -0700444 m_pNormalWidget = pWidget;
tsepez54ab2342016-05-26 17:35:54 -0700445 m_pNormalWidget->SetLayoutItem(this);
dsinclair20855382016-10-31 07:29:34 -0700446
dsinclair2c489cc2016-11-23 16:17:20 -0800447 CFWL_NoteDriver* pNoteDriver =
448 m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
449 pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
dsinclair9ec22172016-11-01 08:33:02 -0700450
dsinclair3b3ce1a2016-11-02 14:51:25 -0700451 m_pOldDelegate = m_pNormalWidget->GetDelegate();
452 m_pNormalWidget->SetDelegate(this);
Dan Sinclair1770c022016-03-14 14:14:16 -0400453 m_pNormalWidget->LockUpdate();
dsinclair9ec22172016-11-01 08:33:02 -0700454
Dan Sinclair1770c022016-03-14 14:14:16 -0400455 CFX_WideString wsText;
456 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
457 pWidget->SetText(wsText);
458 UpdateWidgetProperty();
459 m_pNormalWidget->UnlockUpdate();
460 return CXFA_FFField::LoadWidget();
461}
462void CXFA_FFPasswordEdit::UpdateWidgetProperty() {
463 CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;
464 if (!pWidget) {
465 return;
466 }
tsepez736f28a2016-03-25 14:19:51 -0700467 uint32_t dwExtendedStyle =
Dan Sinclair1770c022016-03-14 14:14:16 -0400468 FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar |
469 FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight;
470 dwExtendedStyle |= UpdateUIProperty();
471 CFX_WideString wsPassWord;
472 m_pDataAcc->GetPasswordChar(wsPassWord);
473 if (!wsPassWord.IsEmpty()) {
474 pWidget->SetAliasChar(wsPassWord.GetAt(0));
475 }
476 if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
477 dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
478 }
479 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
480 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
481 dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
482 }
483 dwExtendedStyle |= GetAlignment();
484 m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
485}
dan sinclairaaf0bdc2017-02-04 10:16:21 -0500486CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_WidgetAcc* pDataAcc)
487 : CXFA_FFTextEdit(pDataAcc) {}
Dan Sinclair1770c022016-03-14 14:14:16 -0400488
489CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {}
490
Dan Sinclair1b08df12017-02-09 09:17:20 -0500491CFX_RectF CXFA_FFDateTimeEdit::GetBBox(uint32_t dwStatus, bool bDrawFocus) {
Dan Sinclair1770c022016-03-14 14:14:16 -0400492 if (bDrawFocus)
Dan Sinclair1b08df12017-02-09 09:17:20 -0500493 return CFX_RectF();
494 return CXFA_FFWidget::GetBBox(dwStatus);
Dan Sinclair1770c022016-03-14 14:14:16 -0400495}
496
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500497bool CXFA_FFDateTimeEdit::PtInActiveRect(const CFX_PointF& point) {
dsinclair603f57b2016-12-14 06:25:02 -0800498 return m_pNormalWidget &&
499 static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)
500 ->GetBBox()
Dan Sinclairb45ea1f2017-02-21 14:27:59 -0500501 .Contains(point);
Dan Sinclair1770c022016-03-14 14:14:16 -0400502}
dsinclair603f57b2016-12-14 06:25:02 -0800503
tsepezd19e9122016-11-02 15:43:18 -0700504bool CXFA_FFDateTimeEdit::LoadWidget() {
dsinclair20855382016-10-31 07:29:34 -0700505 CFWL_DateTimePicker* pWidget = new CFWL_DateTimePicker(GetFWLApp());
tsepez20d6b762016-06-09 11:46:16 -0700506 m_pNormalWidget = pWidget;
tsepez54ab2342016-05-26 17:35:54 -0700507 m_pNormalWidget->SetLayoutItem(this);
dsinclair2c489cc2016-11-23 16:17:20 -0800508 CFWL_NoteDriver* pNoteDriver =
509 m_pNormalWidget->GetOwnerApp()->GetNoteDriver();
510 pNoteDriver->RegisterEventTarget(m_pNormalWidget, m_pNormalWidget);
dsinclair9ec22172016-11-01 08:33:02 -0700511
dsinclair3b3ce1a2016-11-02 14:51:25 -0700512 m_pOldDelegate = m_pNormalWidget->GetDelegate();
513 m_pNormalWidget->SetDelegate(this);
Dan Sinclair1770c022016-03-14 14:14:16 -0400514 m_pNormalWidget->LockUpdate();
dsinclair9ec22172016-11-01 08:33:02 -0700515
Dan Sinclair1770c022016-03-14 14:14:16 -0400516 CFX_WideString wsText;
517 m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
tsepez31e44632016-04-15 16:04:24 -0700518 pWidget->SetEditText(wsText);
Dan Sinclair1770c022016-03-14 14:14:16 -0400519 if (CXFA_Value value = m_pDataAcc->GetFormValue()) {
520 switch (value.GetChildValueClassID()) {
dsinclair56a8b192016-06-21 14:15:25 -0700521 case XFA_Element::Date: {
Dan Sinclair1770c022016-03-14 14:14:16 -0400522 if (!wsText.IsEmpty()) {
523 CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);
524 CFX_Unitime date = lcValue.GetDate();
525 if ((FX_UNITIME)date != 0) {
526 pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
527 }
528 }
529 } break;
530 default:
531 break;
532 }
533 }
534 UpdateWidgetProperty();
535 m_pNormalWidget->UnlockUpdate();
536 return CXFA_FFField::LoadWidget();
537}
538void CXFA_FFDateTimeEdit::UpdateWidgetProperty() {
539 CFWL_DateTimePicker* pWidget = (CFWL_DateTimePicker*)m_pNormalWidget;
540 if (!pWidget) {
541 return;
542 }
tsepez736f28a2016-03-25 14:19:51 -0700543 uint32_t dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat;
Dan Sinclair1770c022016-03-14 14:14:16 -0400544 dwExtendedStyle |= UpdateUIProperty();
545 dwExtendedStyle |= GetAlignment();
546 m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
tsepez736f28a2016-03-25 14:19:51 -0700547 uint32_t dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight;
Dan Sinclair1770c022016-03-14 14:14:16 -0400548 int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
549 if (iNumCells > 0) {
550 dwEditStyles |= FWL_STYLEEXT_EDT_CombText;
551 pWidget->SetEditLimit(iNumCells);
552 }
553 if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
554 !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
555 dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly;
556 }
557 if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
558 dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll;
559 }
560 pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF);
561}
tsepez736f28a2016-03-25 14:19:51 -0700562uint32_t CXFA_FFDateTimeEdit::GetAlignment() {
563 uint32_t dwExtendedStyle = 0;
Dan Sinclair1770c022016-03-14 14:14:16 -0400564 if (CXFA_Para para = m_pDataAcc->GetPara()) {
565 int32_t iHorz = para.GetHorizontalAlign();
566 switch (iHorz) {
567 case XFA_ATTRIBUTEENUM_Center:
568 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter;
569 break;
570 case XFA_ATTRIBUTEENUM_Justify:
571 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified;
572 break;
573 case XFA_ATTRIBUTEENUM_JustifyAll:
574 break;
575 case XFA_ATTRIBUTEENUM_Radix:
576 break;
577 case XFA_ATTRIBUTEENUM_Right:
578 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar;
579 break;
580 default:
581 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear;
582 break;
583 }
584 int32_t iVert = para.GetVerticalAlign();
585 switch (iVert) {
586 case XFA_ATTRIBUTEENUM_Middle:
587 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter;
588 break;
589 case XFA_ATTRIBUTEENUM_Bottom:
590 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar;
591 break;
592 default:
593 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear;
594 break;
595 }
596 }
597 return dwExtendedStyle;
598}
tsepezd19e9122016-11-02 15:43:18 -0700599bool CXFA_FFDateTimeEdit::CommitData() {
dan sinclair0354ccf2016-11-24 10:45:29 -0500600 CFX_WideString wsText =
601 static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)->GetEditText();
Dan Sinclair1770c022016-03-14 14:14:16 -0400602 if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) {
603 m_pDataAcc->UpdateUIDisplay(this);
tsepezd19e9122016-11-02 15:43:18 -0700604 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400605 }
tsepezd19e9122016-11-02 15:43:18 -0700606 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400607}
tsepezd19e9122016-11-02 15:43:18 -0700608bool CXFA_FFDateTimeEdit::UpdateFWLData() {
Dan Sinclair1770c022016-03-14 14:14:16 -0400609 if (!m_pNormalWidget) {
tsepezd19e9122016-11-02 15:43:18 -0700610 return false;
Dan Sinclair1770c022016-03-14 14:14:16 -0400611 }
612 XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;
613 if (IsFocused()) {
614 eType = XFA_VALUEPICTURE_Edit;
615 }
616 CFX_WideString wsText;
617 m_pDataAcc->GetValue(wsText, eType);
tsepez31e44632016-04-15 16:04:24 -0700618 ((CFWL_DateTimePicker*)m_pNormalWidget)->SetEditText(wsText);
Dan Sinclair1770c022016-03-14 14:14:16 -0400619 if (IsFocused() && !wsText.IsEmpty()) {
620 CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);
621 CFX_Unitime date = lcValue.GetDate();
622 if (lcValue.IsValid()) {
623 if ((FX_UNITIME)date != 0) {
624 ((CFWL_DateTimePicker*)m_pNormalWidget)
625 ->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
626 }
627 }
628 }
629 m_pNormalWidget->Update();
tsepezd19e9122016-11-02 15:43:18 -0700630 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400631}
tsepezd19e9122016-11-02 15:43:18 -0700632bool CXFA_FFDateTimeEdit::IsDataChanged() {
dsinclair935d8d52016-05-17 10:32:18 -0700633 if (m_dwStatus & XFA_WidgetStatus_TextEditValueChanged) {
tsepezd19e9122016-11-02 15:43:18 -0700634 return true;
Dan Sinclair1770c022016-03-14 14:14:16 -0400635 }
dan sinclair0354ccf2016-11-24 10:45:29 -0500636 CFX_WideString wsText =
637 static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)->GetEditText();
Dan Sinclair1770c022016-03-14 14:14:16 -0400638 CFX_WideString wsOldValue;
639 m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit);
640 return wsOldValue != wsText;
641}
dsinclair522c3d42016-11-10 14:01:19 -0800642
dsinclair2c489cc2016-11-23 16:17:20 -0800643void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget,
Dan Sinclair1770c022016-03-14 14:14:16 -0400644 int32_t iYear,
645 int32_t iMonth,
646 int32_t iDay) {
647 CFX_WideString wsPicture;
648 m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit);
649 CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr());
650 CFX_Unitime dt;
651 dt.Set(iYear, iMonth, iDay);
652 date.SetDate(dt);
653 CFX_WideString wsDate;
654 date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(),
655 XFA_VALUEPICTURE_Edit);
656 CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget;
tsepez31e44632016-04-15 16:04:24 -0700657 pDateTime->SetEditText(wsDate);
Dan Sinclair1770c022016-03-14 14:14:16 -0400658 pDateTime->Update();
dsinclaira440bb32016-09-14 07:01:54 -0700659 GetDoc()->GetDocEnvironment()->SetFocusWidget(GetDoc(), nullptr);
Dan Sinclair1770c022016-03-14 14:14:16 -0400660 CXFA_EventParam eParam;
661 eParam.m_eType = XFA_EVENT_Change;
662 eParam.m_pTarget = m_pDataAcc;
663 m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw);
664 m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);
665}
dsinclair5d9da0c2016-04-21 13:12:06 -0700666
dsinclairc777f482016-05-04 17:57:03 -0700667void CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) {
dsinclair4614b452016-12-07 17:01:58 -0800668 if (pEvent->GetType() == CFWL_Event::Type::SelectChanged) {
dsinclair447b1f32016-12-08 10:06:32 -0800669 CFWL_EventSelectChanged* event =
670 static_cast<CFWL_EventSelectChanged*>(pEvent);
dsinclair2c489cc2016-11-23 16:17:20 -0800671 OnSelectChanged(m_pNormalWidget, event->iYear, event->iMonth, event->iDay);
dsinclairc777f482016-05-04 17:57:03 -0700672 return;
Dan Sinclair1770c022016-03-14 14:14:16 -0400673 }
dsinclairc777f482016-05-04 17:57:03 -0700674 CXFA_FFTextEdit::OnProcessEvent(pEvent);
Dan Sinclair1770c022016-03-14 14:14:16 -0400675}