• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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/src/foxitlib.h"
8 #include "xfa/src/fxfa/src/common/xfa_common.h"
9 #include "xfa_fwladapter.h"
10 #include "xfa_ffwidget.h"
11 #include "xfa_fffield.h"
12 #include "xfa_ffpageview.h"
13 #include "xfa_fftextedit.h"
14 #include "xfa_textlayout.h"
15 #include "xfa_ffapp.h"
16 #include "xfa_ffdocview.h"
17 #include "xfa_ffdoc.h"
CXFA_FFTextEdit(CXFA_FFPageView * pPageView,CXFA_WidgetAcc * pDataAcc)18 CXFA_FFTextEdit::CXFA_FFTextEdit(CXFA_FFPageView* pPageView,
19                                  CXFA_WidgetAcc* pDataAcc)
20     : CXFA_FFField(pPageView, pDataAcc), m_pOldDelegate(NULL) {}
~CXFA_FFTextEdit()21 CXFA_FFTextEdit::~CXFA_FFTextEdit() {
22   if (m_pNormalWidget) {
23     IFWL_Widget* pWidget = m_pNormalWidget->GetWidget();
24     IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver();
25     pNoteDriver->UnregisterEventTarget(pWidget);
26   }
27 }
LoadWidget()28 FX_BOOL CXFA_FFTextEdit::LoadWidget() {
29   CFWL_Edit* pFWLEdit = CFWL_Edit::Create();
30   pFWLEdit->Initialize();
31   m_pNormalWidget = pFWLEdit;
32   IFWL_Widget* pWidget = m_pNormalWidget->GetWidget();
33   m_pNormalWidget->SetPrivateData(pWidget, this, NULL);
34   IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver();
35   pNoteDriver->RegisterEventTarget(pWidget, pWidget);
36   m_pOldDelegate = m_pNormalWidget->SetDelegate(this);
37   m_pNormalWidget->LockUpdate();
38   UpdateWidgetProperty();
39   CFX_WideString wsText;
40   m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
41   pFWLEdit->SetText(wsText);
42   m_pNormalWidget->UnlockUpdate();
43   return CXFA_FFField::LoadWidget();
44 }
UpdateWidgetProperty()45 void CXFA_FFTextEdit::UpdateWidgetProperty() {
46   CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;
47   if (!pWidget) {
48     return;
49   }
50   FX_DWORD dwStyle = 0;
51   FX_DWORD dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus |
52                              FWL_STYLEEXT_EDT_OuterScrollbar |
53                              FWL_STYLEEXT_EDT_LastLineHeight;
54   dwExtendedStyle |= UpdateUIProperty();
55   if (m_pDataAcc->IsMultiLine()) {
56     dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine | FWL_STYLEEXT_EDT_WantReturn;
57     if (m_pDataAcc->GetVerticalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
58       dwStyle |= FWL_WGTSTYLE_VScroll;
59       dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoVScroll;
60     }
61   } else if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
62     dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
63   }
64   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
65       !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
66     dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
67     dwExtendedStyle |= FWL_STYLEEXT_EDT_MultiLine;
68   }
69   XFA_ELEMENT eType = XFA_ELEMENT_UNKNOWN;
70   int32_t iMaxChars = m_pDataAcc->GetMaxChars(eType);
71   if (eType == XFA_ELEMENT_ExData) {
72     iMaxChars = 0;
73   }
74   int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
75   if (iNumCells == 0) {
76     dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
77     pWidget->SetLimit(iMaxChars > 0 ? iMaxChars : 1);
78   } else if (iNumCells > 0) {
79     dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
80     pWidget->SetLimit(iNumCells);
81   } else {
82     pWidget->SetLimit(iMaxChars);
83   }
84   dwExtendedStyle |= GetAlignment();
85   m_pNormalWidget->ModifyStyles(dwStyle, 0xFFFFFFFF);
86   m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
87 }
OnLButtonDown(FX_DWORD dwFlags,FX_FLOAT fx,FX_FLOAT fy)88 FX_BOOL CXFA_FFTextEdit::OnLButtonDown(FX_DWORD dwFlags,
89                                        FX_FLOAT fx,
90                                        FX_FLOAT fy) {
91   if (!PtInActiveRect(fx, fy)) {
92     return FALSE;
93   }
94   if (!IsFocused()) {
95     m_dwStatus |= XFA_WIDGETSTATUS_Focused;
96     UpdateFWLData();
97     AddInvalidateRect();
98   }
99   SetButtonDown(TRUE);
100   CFWL_MsgMouse ms;
101   ms.m_dwCmd = FWL_MSGMOUSECMD_LButtonDown;
102   ms.m_dwFlags = dwFlags;
103   ms.m_fx = fx;
104   ms.m_fy = fy;
105   ms.m_pDstTarget = m_pNormalWidget->m_pIface;
106   FWLToClient(ms.m_fx, ms.m_fy);
107   TranslateFWLMessage(&ms);
108   return TRUE;
109 }
OnRButtonDown(FX_DWORD dwFlags,FX_FLOAT fx,FX_FLOAT fy)110 FX_BOOL CXFA_FFTextEdit::OnRButtonDown(FX_DWORD dwFlags,
111                                        FX_FLOAT fx,
112                                        FX_FLOAT fy) {
113   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) {
114     return FALSE;
115   }
116   if (!PtInActiveRect(fx, fy)) {
117     return FALSE;
118   }
119   if (!IsFocused()) {
120     m_dwStatus |= XFA_WIDGETSTATUS_Focused;
121     UpdateFWLData();
122     AddInvalidateRect();
123   }
124   SetButtonDown(TRUE);
125   CFWL_MsgMouse ms;
126   ms.m_dwCmd = FWL_MSGMOUSECMD_RButtonDown;
127   ms.m_dwFlags = dwFlags;
128   ms.m_fx = fx;
129   ms.m_fy = fy;
130   FWLToClient(ms.m_fx, ms.m_fy);
131   TranslateFWLMessage(&ms);
132   return TRUE;
133 }
OnRButtonUp(FX_DWORD dwFlags,FX_FLOAT fx,FX_FLOAT fy)134 FX_BOOL CXFA_FFTextEdit::OnRButtonUp(FX_DWORD dwFlags,
135                                      FX_FLOAT fx,
136                                      FX_FLOAT fy) {
137   if (!CXFA_FFField::OnRButtonUp(dwFlags, fx, fy)) {
138     return FALSE;
139   }
140   CFX_PointF pt;
141   pt.Set(fx, fy);
142   GetDoc()->GetDocProvider()->PopupMenu(this, pt, NULL);
143   return TRUE;
144 }
OnSetFocus(CXFA_FFWidget * pOldWidget)145 FX_BOOL CXFA_FFTextEdit::OnSetFocus(CXFA_FFWidget* pOldWidget) {
146   m_dwStatus &= ~XFA_WIDGETSTATUS_TextEditValueChanged;
147   if (!IsFocused()) {
148     m_dwStatus |= XFA_WIDGETSTATUS_Focused;
149     UpdateFWLData();
150     AddInvalidateRect();
151   }
152   CXFA_FFWidget::OnSetFocus(pOldWidget);
153   CFWL_MsgSetFocus ms;
154   ms.m_pDstTarget = m_pNormalWidget->m_pIface;
155   ms.m_pSrcTarget = NULL;
156   TranslateFWLMessage(&ms);
157   return TRUE;
158 }
OnKillFocus(CXFA_FFWidget * pNewWidget)159 FX_BOOL CXFA_FFTextEdit::OnKillFocus(CXFA_FFWidget* pNewWidget) {
160   CFWL_MsgKillFocus ms;
161   ms.m_pDstTarget = m_pNormalWidget->m_pIface;
162   ms.m_pSrcTarget = NULL;
163   TranslateFWLMessage(&ms);
164   m_dwStatus &= ~XFA_WIDGETSTATUS_Focused;
165   SetEditScrollOffset();
166   ProcessCommittedData();
167   UpdateFWLData();
168   AddInvalidateRect();
169   CXFA_FFWidget::OnKillFocus(pNewWidget);
170   m_dwStatus &= ~XFA_WIDGETSTATUS_TextEditValueChanged;
171   return TRUE;
172 }
CommitData()173 FX_BOOL CXFA_FFTextEdit::CommitData() {
174   CFX_WideString wsText;
175   ((CFWL_Edit*)m_pNormalWidget)->GetText(wsText);
176   if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) {
177     m_pDataAcc->UpdateUIDisplay(this);
178     return TRUE;
179   }
180   ValidateNumberField(wsText);
181   return FALSE;
182 }
ValidateNumberField(const CFX_WideString & wsText)183 void CXFA_FFTextEdit::ValidateNumberField(const CFX_WideString& wsText) {
184   CXFA_WidgetAcc* pAcc = this->GetDataAcc();
185   if (pAcc && pAcc->GetUIType() == XFA_ELEMENT_NumericEdit) {
186     IXFA_AppProvider* pAppProvider = GetApp()->GetAppProvider();
187     if (pAppProvider) {
188       CFX_WideString wsTitle;
189       pAppProvider->LoadString(XFA_IDS_AppName, wsTitle);
190       CFX_WideString wsMessage;
191       CFX_WideString wsError;
192       pAppProvider->LoadString(XFA_IDS_ValidateNumberError, wsError);
193       CFX_WideString wsSomField;
194       pAcc->GetNode()->GetSOMExpression(wsSomField);
195       wsMessage.Format(wsError, (const FX_WCHAR*)wsText,
196                        (const FX_WCHAR*)wsSomField);
197       pAppProvider->MsgBox(wsMessage, wsTitle, XFA_MBICON_Error, XFA_MB_OK);
198     }
199   }
200 }
IsDataChanged()201 FX_BOOL CXFA_FFTextEdit::IsDataChanged() {
202   return (m_dwStatus & XFA_WIDGETSTATUS_TextEditValueChanged) != 0;
203 }
GetAlignment()204 FX_DWORD CXFA_FFTextEdit::GetAlignment() {
205   FX_DWORD dwExtendedStyle = 0;
206   if (CXFA_Para para = m_pDataAcc->GetPara()) {
207     int32_t iHorz = para.GetHorizontalAlign();
208     switch (iHorz) {
209       case XFA_ATTRIBUTEENUM_Center:
210         dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter;
211         break;
212       case XFA_ATTRIBUTEENUM_Justify:
213         dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified;
214         break;
215       case XFA_ATTRIBUTEENUM_JustifyAll:
216         break;
217       case XFA_ATTRIBUTEENUM_Radix:
218         break;
219       case XFA_ATTRIBUTEENUM_Right:
220         dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar;
221         break;
222       default:
223         dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear;
224         break;
225     }
226     int32_t iVert = para.GetVerticalAlign();
227     switch (iVert) {
228       case XFA_ATTRIBUTEENUM_Middle:
229         dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter;
230         break;
231       case XFA_ATTRIBUTEENUM_Bottom:
232         dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar;
233         break;
234       default:
235         dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear;
236         break;
237     }
238   }
239   return dwExtendedStyle;
240 }
UpdateFWLData()241 FX_BOOL CXFA_FFTextEdit::UpdateFWLData() {
242   if (!m_pNormalWidget) {
243     return FALSE;
244   }
245   XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;
246   if (IsFocused()) {
247     eType = XFA_VALUEPICTURE_Edit;
248   }
249   FX_BOOL bUpdate = FALSE;
250   if (m_pDataAcc->GetUIType() == XFA_ELEMENT_TextEdit &&
251       m_pDataAcc->GetNumberOfCells() < 0) {
252     XFA_ELEMENT elementType = XFA_ELEMENT_UNKNOWN;
253     int32_t iMaxChars = m_pDataAcc->GetMaxChars(elementType);
254     if (elementType == XFA_ELEMENT_ExData) {
255       iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0;
256     }
257     if (((CFWL_Edit*)m_pNormalWidget)->GetLimit() != iMaxChars) {
258       ((CFWL_Edit*)m_pNormalWidget)->SetLimit(iMaxChars);
259       bUpdate = TRUE;
260     }
261   }
262   CFX_WideString wsText;
263   m_pDataAcc->GetValue(wsText, eType);
264   CFX_WideString wsOldText;
265   ((CFWL_Edit*)m_pNormalWidget)->GetText(wsOldText);
266   if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) {
267     ((CFWL_Edit*)m_pNormalWidget)->SetText(wsText);
268     bUpdate = TRUE;
269   }
270   if (bUpdate) {
271     m_pNormalWidget->Update();
272   }
273   return TRUE;
274 }
CanUndo()275 FX_BOOL CXFA_FFTextEdit::CanUndo() {
276   return ((CFWL_Edit*)m_pNormalWidget)->CanUndo();
277 }
CanRedo()278 FX_BOOL CXFA_FFTextEdit::CanRedo() {
279   return ((CFWL_Edit*)m_pNormalWidget)->CanRedo();
280 }
Undo()281 FX_BOOL CXFA_FFTextEdit::Undo() {
282   return ((CFWL_Edit*)m_pNormalWidget)->Undo();
283 }
Redo()284 FX_BOOL CXFA_FFTextEdit::Redo() {
285   return ((CFWL_Edit*)m_pNormalWidget)->Redo();
286 }
CanCopy()287 FX_BOOL CXFA_FFTextEdit::CanCopy() {
288   int32_t nCount = ((CFWL_Edit*)m_pNormalWidget)->CountSelRanges();
289   return nCount > 0;
290 }
CanCut()291 FX_BOOL CXFA_FFTextEdit::CanCut() {
292   if (m_pNormalWidget->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) {
293     return FALSE;
294   }
295   int32_t nCount = ((CFWL_Edit*)m_pNormalWidget)->CountSelRanges();
296   return nCount > 0;
297 }
CanPaste()298 FX_BOOL CXFA_FFTextEdit::CanPaste() {
299   return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open;
300 }
CanSelectAll()301 FX_BOOL CXFA_FFTextEdit::CanSelectAll() {
302   return ((CFWL_Edit*)m_pNormalWidget)->GetTextLength() > 0;
303 }
Copy(CFX_WideString & wsCopy)304 FX_BOOL CXFA_FFTextEdit::Copy(CFX_WideString& wsCopy) {
305   return ((CFWL_Edit*)m_pNormalWidget)->Copy(wsCopy);
306 }
Cut(CFX_WideString & wsCut)307 FX_BOOL CXFA_FFTextEdit::Cut(CFX_WideString& wsCut) {
308   return ((CFWL_Edit*)m_pNormalWidget)->Cut(wsCut);
309 }
Paste(const CFX_WideString & wsPaste)310 FX_BOOL CXFA_FFTextEdit::Paste(const CFX_WideString& wsPaste) {
311   return ((CFWL_Edit*)m_pNormalWidget)->Paste(wsPaste);
312 }
SelectAll()313 FX_BOOL CXFA_FFTextEdit::SelectAll() {
314   int32_t nCount = ((CFWL_Edit*)m_pNormalWidget)->GetTextLength();
315   return ((CFWL_Edit*)m_pNormalWidget)->AddSelRange(0, nCount);
316 }
Delete()317 FX_BOOL CXFA_FFTextEdit::Delete() {
318   return ((CFWL_Edit*)m_pNormalWidget)->Delete();
319 }
DeSelect()320 FX_BOOL CXFA_FFTextEdit::DeSelect() {
321   return ((CFWL_Edit*)m_pNormalWidget)->ClearSelections();
322 }
GetSuggestWords(CFX_PointF pointf,CFX_ByteStringArray & sSuggest)323 FX_BOOL CXFA_FFTextEdit::GetSuggestWords(CFX_PointF pointf,
324                                          CFX_ByteStringArray& sSuggest) {
325   if (m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {
326     return FALSE;
327   }
328   FWLToClient(pointf.x, pointf.y);
329   return ((CFWL_Edit*)m_pNormalWidget)->GetSuggestWords(pointf, sSuggest);
330 }
ReplaceSpellCheckWord(CFX_PointF pointf,const CFX_ByteStringC & bsReplace)331 FX_BOOL CXFA_FFTextEdit::ReplaceSpellCheckWord(
332     CFX_PointF pointf,
333     const CFX_ByteStringC& bsReplace) {
334   if (m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {
335     return FALSE;
336   }
337   FWLToClient(pointf.x, pointf.y);
338   return ((CFWL_Edit*)m_pNormalWidget)
339       ->ReplaceSpellCheckWord(pointf, bsReplace);
340 }
OnTextChanged(IFWL_Widget * pWidget,const CFX_WideString & wsChanged,const CFX_WideString & wsPrevText)341 void CXFA_FFTextEdit::OnTextChanged(IFWL_Widget* pWidget,
342                                     const CFX_WideString& wsChanged,
343                                     const CFX_WideString& wsPrevText) {
344   m_dwStatus |= XFA_WIDGETSTATUS_TextEditValueChanged;
345   CXFA_EventParam eParam;
346   eParam.m_eType = XFA_EVENT_Change;
347   eParam.m_wsChange = wsChanged;
348   eParam.m_pTarget = m_pDataAcc;
349   eParam.m_wsPrevText = wsPrevText;
350   CFWL_Edit* pEdit = ((CFWL_Edit*)m_pNormalWidget);
351   if (m_pDataAcc->GetUIType() == XFA_ELEMENT_DateTimeEdit) {
352     CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit;
353     pDateTime->GetEditText(eParam.m_wsNewText);
354     int32_t iSels = pDateTime->CountSelRanges();
355     if (iSels) {
356       eParam.m_iSelEnd = pDateTime->GetSelRange(0, eParam.m_iSelStart);
357     }
358   } else {
359     pEdit->GetText(eParam.m_wsNewText);
360     int32_t iSels = pEdit->CountSelRanges();
361     if (iSels) {
362       eParam.m_iSelEnd = pEdit->GetSelRange(0, eParam.m_iSelStart);
363     }
364   }
365   m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);
366 }
OnTextFull(IFWL_Widget * pWidget)367 void CXFA_FFTextEdit::OnTextFull(IFWL_Widget* pWidget) {
368   CXFA_EventParam eParam;
369   eParam.m_eType = XFA_EVENT_Full;
370   eParam.m_pTarget = m_pDataAcc;
371   m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam);
372 }
OnAddDoRecord(IFWL_Widget * pWidget)373 void CXFA_FFTextEdit::OnAddDoRecord(IFWL_Widget* pWidget) {
374   GetDoc()->GetDocProvider()->AddDoRecord(this);
375 }
CheckWord(const CFX_ByteStringC & sWord)376 FX_BOOL CXFA_FFTextEdit::CheckWord(const CFX_ByteStringC& sWord) {
377   if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {
378     return TRUE;
379   }
380   return GetDoc()->GetDocProvider()->CheckWord(GetDoc(), sWord);
381 }
GetSuggestWords(const CFX_ByteStringC & sWord,CFX_ByteStringArray & sSuggest)382 FX_BOOL CXFA_FFTextEdit::GetSuggestWords(const CFX_ByteStringC& sWord,
383                                          CFX_ByteStringArray& sSuggest) {
384   if (m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {
385     return FALSE;
386   }
387   return GetDoc()->GetDocProvider()->GetSuggestWords(GetDoc(), sWord, sSuggest);
388 }
OnProcessMessage(CFWL_Message * pMessage)389 int32_t CXFA_FFTextEdit::OnProcessMessage(CFWL_Message* pMessage) {
390   return m_pOldDelegate->OnProcessMessage(pMessage);
391 }
OnProcessEvent(CFWL_Event * pEvent)392 FWL_ERR CXFA_FFTextEdit::OnProcessEvent(CFWL_Event* pEvent) {
393   CXFA_FFField::OnProcessEvent(pEvent);
394   FX_DWORD dwEventID = pEvent->GetClassID();
395   switch (dwEventID) {
396     case FWL_EVTHASH_EDT_TextChanged: {
397       CFWL_EvtEdtTextChanged* event = (CFWL_EvtEdtTextChanged*)pEvent;
398       CFX_WideString wsChange;
399       OnTextChanged(m_pNormalWidget->GetWidget(), wsChange, event->wsPrevText);
400       break;
401     }
402     case FWL_EVTHASH_EDT_AddDoRecord: {
403       OnAddDoRecord(m_pNormalWidget->GetWidget());
404       break;
405     }
406     case FWL_EVTHASH_EDT_TextFull: {
407       OnTextFull(m_pNormalWidget->GetWidget());
408       break;
409     }
410     case FWL_EVTHASH_EDT_CheckWord: {
411       CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged");
412       CFWL_EvtEdtCheckWord* event = (CFWL_EvtEdtCheckWord*)pEvent;
413       event->bCheckWord = CheckWord(event->bsWord);
414       break;
415     }
416     case FWL_EVTHASH_EDT_GetSuggestWords: {
417       CFWL_EvtEdtGetSuggestWords* event = (CFWL_EvtEdtGetSuggestWords*)pEvent;
418       event->bSuggestWords =
419           GetSuggestWords(event->bsWord, event->bsArraySuggestWords);
420       break;
421     }
422     default: {}
423   }
424   return m_pOldDelegate->OnProcessEvent(pEvent);
425 }
OnDrawWidget(CFX_Graphics * pGraphics,const CFX_Matrix * pMatrix)426 FWL_ERR CXFA_FFTextEdit::OnDrawWidget(CFX_Graphics* pGraphics,
427                                       const CFX_Matrix* pMatrix) {
428   return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix);
429 }
CXFA_FFNumericEdit(CXFA_FFPageView * pPageView,CXFA_WidgetAcc * pDataAcc)430 CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_FFPageView* pPageView,
431                                        CXFA_WidgetAcc* pDataAcc)
432     : CXFA_FFTextEdit(pPageView, pDataAcc) {}
~CXFA_FFNumericEdit()433 CXFA_FFNumericEdit::~CXFA_FFNumericEdit() {}
LoadWidget()434 FX_BOOL CXFA_FFNumericEdit::LoadWidget() {
435   CFWL_Edit* pWidget = CFWL_Edit::Create();
436   pWidget->Initialize();
437   m_pNormalWidget = (CFWL_Widget*)pWidget;
438   IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget();
439   m_pNormalWidget->SetPrivateData(pIWidget, this, NULL);
440   IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver();
441   pNoteDriver->RegisterEventTarget(pIWidget, pIWidget);
442   m_pOldDelegate = m_pNormalWidget->SetDelegate(this);
443   m_pNormalWidget->LockUpdate();
444   CFX_WideString wsText;
445   m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
446   pWidget->SetText(wsText);
447   UpdateWidgetProperty();
448   m_pNormalWidget->UnlockUpdate();
449   return CXFA_FFField::LoadWidget();
450 }
UpdateWidgetProperty()451 void CXFA_FFNumericEdit::UpdateWidgetProperty() {
452   CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;
453   if (!pWidget) {
454     return;
455   }
456   FX_DWORD dwExtendedStyle =
457       FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar |
458       FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number |
459       FWL_STYLEEXT_EDT_LastLineHeight;
460   dwExtendedStyle |= UpdateUIProperty();
461   if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
462     dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
463   }
464   int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
465   if (iNumCells > 0) {
466     dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;
467     pWidget->SetLimit(iNumCells);
468   }
469   dwExtendedStyle |= GetAlignment();
470   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
471       !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
472     dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
473   }
474   m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
475 }
OnProcessEvent(CFWL_Event * pEvent)476 FWL_ERR CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event* pEvent) {
477   FX_DWORD dwEventID = pEvent->GetClassID();
478   if (dwEventID == FWL_EVTHASH_EDT_Validate) {
479     CFWL_EvtEdtValidate* event = (CFWL_EvtEdtValidate*)pEvent;
480     CFX_WideString wsChange = event->wsInsert;
481     event->bValidate = OnValidate(m_pNormalWidget->GetWidget(), wsChange);
482     return event->bValidate;
483   } else {
484     return CXFA_FFTextEdit::OnProcessEvent(pEvent);
485   }
486 }
OnValidate(IFWL_Widget * pWidget,CFX_WideString & wsText)487 FX_BOOL CXFA_FFNumericEdit::OnValidate(IFWL_Widget* pWidget,
488                                        CFX_WideString& wsText) {
489   CFX_WideString wsPattern;
490   m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit);
491   if (!wsPattern.IsEmpty()) {
492     return TRUE;
493   }
494   int32_t iLeads = 0;
495   m_pDataAcc->GetLeadDigits(iLeads);
496   int32_t iFracs = 0;
497   m_pDataAcc->GetFracDigits(iFracs);
498   CFX_WideString wsFormat;
499   CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc);
500   widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs);
501   return widgetValue.ValidateNumericTemp(wsText, wsFormat,
502                                          m_pDataAcc->GetLocal());
503 }
CXFA_FFPasswordEdit(CXFA_FFPageView * pPageView,CXFA_WidgetAcc * pDataAcc)504 CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_FFPageView* pPageView,
505                                          CXFA_WidgetAcc* pDataAcc)
506     : CXFA_FFTextEdit(pPageView, pDataAcc) {}
~CXFA_FFPasswordEdit()507 CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit() {}
LoadWidget()508 FX_BOOL CXFA_FFPasswordEdit::LoadWidget() {
509   CFWL_Edit* pWidget = CFWL_Edit::Create();
510   pWidget->Initialize();
511   m_pNormalWidget = (CFWL_Widget*)pWidget;
512   IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget();
513   m_pNormalWidget->SetPrivateData(pIWidget, this, NULL);
514   IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver();
515   pNoteDriver->RegisterEventTarget(pIWidget, pIWidget);
516   m_pOldDelegate = m_pNormalWidget->SetDelegate(this);
517   m_pNormalWidget->LockUpdate();
518   CFX_WideString wsText;
519   m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
520   pWidget->SetText(wsText);
521   UpdateWidgetProperty();
522   m_pNormalWidget->UnlockUpdate();
523   return CXFA_FFField::LoadWidget();
524 }
UpdateWidgetProperty()525 void CXFA_FFPasswordEdit::UpdateWidgetProperty() {
526   CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;
527   if (!pWidget) {
528     return;
529   }
530   FX_DWORD dwExtendedStyle =
531       FWL_STYLEEXT_EDT_ShowScrollbarFocus | FWL_STYLEEXT_EDT_OuterScrollbar |
532       FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight;
533   dwExtendedStyle |= UpdateUIProperty();
534   CFX_WideString wsPassWord;
535   m_pDataAcc->GetPasswordChar(wsPassWord);
536   if (!wsPassWord.IsEmpty()) {
537     pWidget->SetAliasChar(wsPassWord.GetAt(0));
538   }
539   if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
540     dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;
541   }
542   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
543       !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
544     dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;
545   }
546   dwExtendedStyle |= GetAlignment();
547   m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
548 }
CXFA_FFDateTimeEdit(CXFA_FFPageView * pPageView,CXFA_WidgetAcc * pDataAcc)549 CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_FFPageView* pPageView,
550                                          CXFA_WidgetAcc* pDataAcc)
551     : CXFA_FFTextEdit(pPageView, pDataAcc) {}
~CXFA_FFDateTimeEdit()552 CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit() {}
GetBBox(CFX_RectF & rtBox,FX_DWORD dwStatus,FX_BOOL bDrawFocus)553 FX_BOOL CXFA_FFDateTimeEdit::GetBBox(CFX_RectF& rtBox,
554                                      FX_DWORD dwStatus,
555                                      FX_BOOL bDrawFocus) {
556   if (bDrawFocus) {
557     return FALSE;
558   }
559 #ifndef _XFA_EMB
560   return CXFA_FFWidget::GetBBox(rtBox, dwStatus);
561 #endif
562   GetRectWithoutRotate(rtBox);
563   if (m_pNormalWidget) {
564     CFX_RectF rtWidget;
565     ((CFWL_DateTimePicker*)m_pNormalWidget)->GetBBox(rtWidget);
566     rtBox.Union(rtWidget);
567   }
568   CFX_Matrix mt;
569   GetRotateMatrix(mt);
570   mt.TransformRect(rtBox);
571   return TRUE;
572 }
PtInActiveRect(FX_FLOAT fx,FX_FLOAT fy)573 FX_BOOL CXFA_FFDateTimeEdit::PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy) {
574   if (!m_pNormalWidget) {
575     return FALSE;
576   }
577   CFX_RectF rtWidget;
578   ((CFWL_DateTimePicker*)m_pNormalWidget)->GetBBox(rtWidget);
579   if (rtWidget.Contains(fx, fy)) {
580     return TRUE;
581   }
582   return FALSE;
583 }
LoadWidget()584 FX_BOOL CXFA_FFDateTimeEdit::LoadWidget() {
585   CFWL_DateTimePicker* pWidget = CFWL_DateTimePicker::Create();
586   pWidget->Initialize();
587   m_pNormalWidget = (CFWL_Widget*)pWidget;
588   IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget();
589   m_pNormalWidget->SetPrivateData(pIWidget, this, NULL);
590   IFWL_NoteDriver* pNoteDriver = FWL_GetApp()->GetNoteDriver();
591   pNoteDriver->RegisterEventTarget(pIWidget, pIWidget);
592   m_pOldDelegate = m_pNormalWidget->SetDelegate(this);
593   m_pNormalWidget->LockUpdate();
594   CFX_WideString wsText;
595   m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);
596   pWidget->SetEditText(wsText);
597   XFA_DATETIMETYPE eType = XFA_DATETIMETYPE_DateAndTime;
598   if (CXFA_Value value = m_pDataAcc->GetFormValue()) {
599     switch (value.GetChildValueClassID()) {
600       case XFA_ELEMENT_Date: {
601         eType = XFA_DATETIMETYPE_Date;
602         if (!wsText.IsEmpty()) {
603           CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);
604           CFX_Unitime date = lcValue.GetDate();
605           if ((FX_UNITIME)date != 0) {
606             pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
607           }
608         }
609       } break;
610       case XFA_ELEMENT_Time:
611         eType = XFA_DATETIMETYPE_Time;
612         break;
613       default:
614         eType = XFA_DATETIMETYPE_DateAndTime;
615         break;
616     }
617   }
618   UpdateWidgetProperty();
619   m_pNormalWidget->UnlockUpdate();
620   return CXFA_FFField::LoadWidget();
621 }
UpdateWidgetProperty()622 void CXFA_FFDateTimeEdit::UpdateWidgetProperty() {
623   CFWL_DateTimePicker* pWidget = (CFWL_DateTimePicker*)m_pNormalWidget;
624   if (!pWidget) {
625     return;
626   }
627   FX_DWORD dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat;
628   dwExtendedStyle |= UpdateUIProperty();
629   dwExtendedStyle |= GetAlignment();
630   m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);
631   FX_DWORD dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight;
632   int32_t iNumCells = m_pDataAcc->GetNumberOfCells();
633   if (iNumCells > 0) {
634     dwEditStyles |= FWL_STYLEEXT_EDT_CombText;
635     pWidget->SetEditLimit(iNumCells);
636   }
637   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open ||
638       !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {
639     dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly;
640   }
641   if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {
642     dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll;
643   }
644   pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF);
645 }
GetAlignment()646 FX_DWORD CXFA_FFDateTimeEdit::GetAlignment() {
647   FX_DWORD dwExtendedStyle = 0;
648   if (CXFA_Para para = m_pDataAcc->GetPara()) {
649     int32_t iHorz = para.GetHorizontalAlign();
650     switch (iHorz) {
651       case XFA_ATTRIBUTEENUM_Center:
652         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter;
653         break;
654       case XFA_ATTRIBUTEENUM_Justify:
655         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified;
656         break;
657       case XFA_ATTRIBUTEENUM_JustifyAll:
658         break;
659       case XFA_ATTRIBUTEENUM_Radix:
660         break;
661       case XFA_ATTRIBUTEENUM_Right:
662         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar;
663         break;
664       default:
665         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear;
666         break;
667     }
668     int32_t iVert = para.GetVerticalAlign();
669     switch (iVert) {
670       case XFA_ATTRIBUTEENUM_Middle:
671         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter;
672         break;
673       case XFA_ATTRIBUTEENUM_Bottom:
674         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar;
675         break;
676       default:
677         dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear;
678         break;
679     }
680   }
681   return dwExtendedStyle;
682 }
CommitData()683 FX_BOOL CXFA_FFDateTimeEdit::CommitData() {
684   CFX_WideString wsText;
685   ((CFWL_DateTimePicker*)m_pNormalWidget)->GetEditText(wsText);
686   if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) {
687     m_pDataAcc->UpdateUIDisplay(this);
688     return TRUE;
689   }
690   return FALSE;
691 }
UpdateFWLData()692 FX_BOOL CXFA_FFDateTimeEdit::UpdateFWLData() {
693   if (!m_pNormalWidget) {
694     return FALSE;
695   }
696   XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;
697   if (IsFocused()) {
698     eType = XFA_VALUEPICTURE_Edit;
699   }
700   CFX_WideString wsText;
701   m_pDataAcc->GetValue(wsText, eType);
702   ((CFWL_DateTimePicker*)m_pNormalWidget)->SetEditText(wsText);
703   if (IsFocused() && !wsText.IsEmpty()) {
704     CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);
705     CFX_Unitime date = lcValue.GetDate();
706     if (lcValue.IsValid()) {
707       if ((FX_UNITIME)date != 0) {
708         ((CFWL_DateTimePicker*)m_pNormalWidget)
709             ->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
710       }
711     }
712   }
713   m_pNormalWidget->Update();
714   return TRUE;
715 }
IsDataChanged()716 FX_BOOL CXFA_FFDateTimeEdit::IsDataChanged() {
717   if (m_dwStatus & XFA_WIDGETSTATUS_TextEditValueChanged) {
718     return TRUE;
719   }
720   CFX_WideString wsText;
721   ((CFWL_DateTimePicker*)m_pNormalWidget)->GetEditText(wsText);
722   CFX_WideString wsOldValue;
723   m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit);
724   return wsOldValue != wsText;
725 }
CanUndo()726 FX_BOOL CXFA_FFDateTimeEdit::CanUndo() {
727   return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanUndo();
728 }
CanRedo()729 FX_BOOL CXFA_FFDateTimeEdit::CanRedo() {
730   return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanRedo();
731 }
Undo()732 FX_BOOL CXFA_FFDateTimeEdit::Undo() {
733   return ((CFWL_DateTimePicker*)m_pNormalWidget)->Undo();
734 }
Redo()735 FX_BOOL CXFA_FFDateTimeEdit::Redo() {
736   return ((CFWL_DateTimePicker*)m_pNormalWidget)->Redo();
737 }
CanCopy()738 FX_BOOL CXFA_FFDateTimeEdit::CanCopy() {
739   return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanCopy();
740 }
CanCut()741 FX_BOOL CXFA_FFDateTimeEdit::CanCut() {
742   if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) {
743     return FALSE;
744   }
745   return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanCut();
746 }
CanPaste()747 FX_BOOL CXFA_FFDateTimeEdit::CanPaste() {
748   return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open;
749 }
CanSelectAll()750 FX_BOOL CXFA_FFDateTimeEdit::CanSelectAll() {
751   return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanSelectAll();
752 }
Copy(CFX_WideString & wsCopy)753 FX_BOOL CXFA_FFDateTimeEdit::Copy(CFX_WideString& wsCopy) {
754   return ((CFWL_DateTimePicker*)m_pNormalWidget)->Copy(wsCopy);
755 }
Cut(CFX_WideString & wsCut)756 FX_BOOL CXFA_FFDateTimeEdit::Cut(CFX_WideString& wsCut) {
757   return ((CFWL_DateTimePicker*)m_pNormalWidget)->Cut(wsCut);
758 }
Paste(const CFX_WideString & wsPaste)759 FX_BOOL CXFA_FFDateTimeEdit::Paste(const CFX_WideString& wsPaste) {
760   return ((CFWL_DateTimePicker*)m_pNormalWidget)->Paste(wsPaste);
761 }
SelectAll()762 FX_BOOL CXFA_FFDateTimeEdit::SelectAll() {
763   return ((CFWL_DateTimePicker*)m_pNormalWidget)->SelectAll();
764 }
Delete()765 FX_BOOL CXFA_FFDateTimeEdit::Delete() {
766   return ((CFWL_DateTimePicker*)m_pNormalWidget)->Delete();
767 }
DeSelect()768 FX_BOOL CXFA_FFDateTimeEdit::DeSelect() {
769   return ((CFWL_DateTimePicker*)m_pNormalWidget)->DeSelect();
770 }
OnSelectChanged(IFWL_Widget * pWidget,int32_t iYear,int32_t iMonth,int32_t iDay)771 void CXFA_FFDateTimeEdit::OnSelectChanged(IFWL_Widget* pWidget,
772                                           int32_t iYear,
773                                           int32_t iMonth,
774                                           int32_t iDay) {
775   CFX_WideString wsPicture;
776   m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit);
777   CXFA_LocaleValue date(XFA_VT_DATE,
778                         this->GetDoc()->GetXFADoc()->GetLocalMgr());
779   CFX_Unitime dt;
780   dt.Set(iYear, iMonth, iDay);
781   date.SetDate(dt);
782   CFX_WideString wsDate;
783   date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(),
784                       XFA_VALUEPICTURE_Edit);
785   CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget;
786   pDateTime->SetEditText(wsDate);
787   pDateTime->Update();
788   GetDoc()->GetDocProvider()->SetFocusWidget(GetDoc(), NULL);
789   CXFA_EventParam eParam;
790   eParam.m_eType = XFA_EVENT_Change;
791   eParam.m_pTarget = m_pDataAcc;
792   m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw);
793   m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);
794 }
OnProcessEvent(CFWL_Event * pEvent)795 FWL_ERR CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event* pEvent) {
796   FX_DWORD dwEventID = pEvent->GetClassID();
797   if (dwEventID == FWL_EVTHASH_DTP_SelectChanged) {
798     CFWL_Event_DtpSelectChanged* event = (CFWL_Event_DtpSelectChanged*)pEvent;
799     OnSelectChanged(m_pNormalWidget->GetWidget(), event->iYear, event->iMonth,
800                     event->iDay);
801     return TRUE;
802   } else {
803     return CXFA_FFTextEdit::OnProcessEvent(pEvent);
804   }
805 }
806