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