Merge XFA to PDFium master at 4dc95e7 on 10/28/2014
[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     return FALSE;\r
183 }\r
184 FX_BOOL CXFA_FFTextEdit::IsDataChanged()\r
185 {\r
186     return (m_dwStatus & XFA_WIDGETSTATUS_TextEditValueChanged) != 0;\r
187 }\r
188 FX_DWORD CXFA_FFTextEdit::GetAlignment()\r
189 {\r
190     FX_DWORD dwExtendedStyle = 0;\r
191     if (CXFA_Para para = m_pDataAcc->GetPara()) {\r
192         FX_INT32 iHorz = para.GetHorizontalAlign();\r
193         switch(iHorz) {\r
194             case XFA_ATTRIBUTEENUM_Center:\r
195                 dwExtendedStyle |= FWL_STYLEEXT_EDT_HCenter;\r
196                 break;\r
197             case XFA_ATTRIBUTEENUM_Justify:\r
198                 dwExtendedStyle |= FWL_STYLEEXT_EDT_Justified;\r
199                 break;\r
200             case XFA_ATTRIBUTEENUM_JustifyAll:\r
201                 break;\r
202             case XFA_ATTRIBUTEENUM_Radix:\r
203                 break;\r
204             case XFA_ATTRIBUTEENUM_Right:\r
205                 dwExtendedStyle |= FWL_STYLEEXT_EDT_HFar;\r
206                 break;\r
207             default:\r
208                 dwExtendedStyle |= FWL_STYLEEXT_EDT_HNear;\r
209                 break;\r
210         }\r
211         FX_INT32 iVert = para.GetVerticalAlign();\r
212         switch(iVert) {\r
213             case XFA_ATTRIBUTEENUM_Middle:\r
214                 dwExtendedStyle |= FWL_STYLEEXT_EDT_VCenter;\r
215                 break;\r
216             case XFA_ATTRIBUTEENUM_Bottom:\r
217                 dwExtendedStyle |= FWL_STYLEEXT_EDT_VFar;\r
218                 break;\r
219             default:\r
220                 dwExtendedStyle |= FWL_STYLEEXT_EDT_VNear;\r
221                 break;\r
222         }\r
223     }\r
224     return dwExtendedStyle;\r
225 }\r
226 FX_BOOL CXFA_FFTextEdit::UpdateFWLData()\r
227 {\r
228     if (!m_pNormalWidget) {\r
229         return FALSE;\r
230     }\r
231     XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;\r
232     if (IsFocused()) {\r
233         eType = XFA_VALUEPICTURE_Edit;\r
234     }\r
235     FX_BOOL bUpdate = FALSE;\r
236     if (m_pDataAcc->GetUIType() == XFA_ELEMENT_TextEdit && m_pDataAcc->GetNumberOfCells() < 0) {\r
237         XFA_ELEMENT elementType = XFA_ELEMENT_UNKNOWN;\r
238         FX_INT32 iMaxChars = m_pDataAcc->GetMaxChars(elementType);\r
239         if (elementType == XFA_ELEMENT_ExData) {\r
240             iMaxChars = eType == XFA_VALUEPICTURE_Edit ? iMaxChars : 0;\r
241         }\r
242         if (((CFWL_Edit*)m_pNormalWidget)->GetLimit() != iMaxChars) {\r
243             ((CFWL_Edit*)m_pNormalWidget)->SetLimit(iMaxChars);\r
244             bUpdate = TRUE;\r
245         }\r
246     }\r
247     CFX_WideString wsText;\r
248     m_pDataAcc->GetValue(wsText, eType);\r
249     CFX_WideString wsOldText;\r
250     ((CFWL_Edit*)m_pNormalWidget)->GetText(wsOldText);\r
251     if (wsText != wsOldText || (eType == XFA_VALUEPICTURE_Edit && bUpdate)) {\r
252         ((CFWL_Edit*)m_pNormalWidget)->SetText(wsText);\r
253         bUpdate = TRUE;\r
254     }\r
255     if (bUpdate) {\r
256         m_pNormalWidget->Update();\r
257     }\r
258     return TRUE;\r
259 }\r
260 FX_BOOL CXFA_FFTextEdit::CanUndo()\r
261 {\r
262     return ((CFWL_Edit*)m_pNormalWidget)->CanUndo();\r
263 }\r
264 FX_BOOL CXFA_FFTextEdit::CanRedo()\r
265 {\r
266     return ((CFWL_Edit*)m_pNormalWidget)->CanRedo();\r
267 }\r
268 FX_BOOL CXFA_FFTextEdit::Undo()\r
269 {\r
270     return ((CFWL_Edit*)m_pNormalWidget)->Undo();\r
271 }\r
272 FX_BOOL CXFA_FFTextEdit::Redo()\r
273 {\r
274     return ((CFWL_Edit*)m_pNormalWidget)->Redo();\r
275 }\r
276 FX_BOOL CXFA_FFTextEdit::CanCopy()\r
277 {\r
278     FX_INT32 nCount = ((CFWL_Edit*)m_pNormalWidget)->CountSelRanges();\r
279     return nCount > 0;\r
280 }\r
281 FX_BOOL CXFA_FFTextEdit::CanCut()\r
282 {\r
283     if (m_pNormalWidget->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) {\r
284         return FALSE;\r
285     }\r
286     FX_INT32 nCount = ((CFWL_Edit*)m_pNormalWidget)->CountSelRanges();\r
287     return nCount > 0;\r
288 }\r
289 FX_BOOL CXFA_FFTextEdit::CanPaste()\r
290 {\r
291     return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open;\r
292 }\r
293 FX_BOOL CXFA_FFTextEdit::CanSelectAll()\r
294 {\r
295     return ((CFWL_Edit*)m_pNormalWidget)->GetTextLength() > 0;\r
296 }\r
297 FX_BOOL CXFA_FFTextEdit::Copy(CFX_WideString &wsCopy)\r
298 {\r
299     return ((CFWL_Edit*)m_pNormalWidget)->Copy(wsCopy);\r
300 }\r
301 FX_BOOL CXFA_FFTextEdit::Cut(CFX_WideString &wsCut)\r
302 {\r
303     return ((CFWL_Edit*)m_pNormalWidget)->Cut(wsCut);\r
304 }\r
305 FX_BOOL CXFA_FFTextEdit::Paste(const CFX_WideString &wsPaste)\r
306 {\r
307     return ((CFWL_Edit*)m_pNormalWidget)->Paste(wsPaste);\r
308 }\r
309 FX_BOOL CXFA_FFTextEdit::SelectAll()\r
310 {\r
311     FX_INT32 nCount = ((CFWL_Edit*)m_pNormalWidget)->GetTextLength();\r
312     return ((CFWL_Edit*)m_pNormalWidget)->AddSelRange(0, nCount);\r
313 }\r
314 FX_BOOL CXFA_FFTextEdit::Delete()\r
315 {\r
316     return ((CFWL_Edit*)m_pNormalWidget)->Delete();\r
317 }\r
318 FX_BOOL CXFA_FFTextEdit::DeSelect()\r
319 {\r
320     return ((CFWL_Edit*)m_pNormalWidget)->ClearSelections();\r
321 }\r
322 FX_BOOL CXFA_FFTextEdit::GetSuggestWords(CFX_PointF pointf, CFX_ByteStringArray &sSuggest)\r
323 {\r
324     if (m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {\r
325         return FALSE;\r
326     }\r
327     FWLToClient(pointf.x, pointf.y);\r
328     return ((CFWL_Edit*)m_pNormalWidget)->GetSuggestWords(pointf, sSuggest);\r
329 }\r
330 FX_BOOL CXFA_FFTextEdit::ReplaceSpellCheckWord(CFX_PointF pointf, FX_BSTR bsReplace)\r
331 {\r
332     if (m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {\r
333         return FALSE;\r
334     }\r
335     FWLToClient(pointf.x, pointf.y);\r
336     return ((CFWL_Edit*)m_pNormalWidget)->ReplaceSpellCheckWord(pointf, bsReplace);\r
337 }\r
338 void CXFA_FFTextEdit::OnTextChanged(IFWL_Widget *pWidget, const CFX_WideString &wsChanged, const CFX_WideString &wsPrevText)\r
339 {\r
340     m_dwStatus |= XFA_WIDGETSTATUS_TextEditValueChanged;\r
341     CXFA_EventParam eParam;\r
342     eParam.m_eType = XFA_EVENT_Change;\r
343     eParam.m_wsChange = wsChanged;\r
344     eParam.m_pTarget = m_pDataAcc;\r
345     eParam.m_wsPrevText = wsPrevText;\r
346     CFWL_Edit* pEdit = ((CFWL_Edit*)m_pNormalWidget);\r
347     if (m_pDataAcc->GetUIType() == XFA_ELEMENT_DateTimeEdit) {\r
348         CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)pEdit;\r
349         pDateTime->GetEditText(eParam.m_wsNewText);\r
350         FX_INT32 iSels = pDateTime->CountSelRanges();\r
351         if (iSels ) {\r
352             eParam.m_iSelEnd = pDateTime->GetSelRange(0, eParam.m_iSelStart);\r
353         }\r
354     } else {\r
355         pEdit->GetText(eParam.m_wsNewText);\r
356         FX_INT32 iSels = pEdit->CountSelRanges();\r
357         if (iSels ) {\r
358             eParam.m_iSelEnd = pEdit->GetSelRange(0, eParam.m_iSelStart);\r
359         }\r
360     }\r
361     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);\r
362 }\r
363 void CXFA_FFTextEdit::OnTextFull(IFWL_Widget *pWidget)\r
364 {\r
365     CXFA_EventParam eParam;\r
366     eParam.m_eType = XFA_EVENT_Full;\r
367     eParam.m_pTarget = m_pDataAcc;\r
368     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Full, &eParam);\r
369 }\r
370 void CXFA_FFTextEdit::OnAddDoRecord(IFWL_Widget *pWidget)\r
371 {\r
372     GetDoc()->GetDocProvider()->AddDoRecord((XFA_HWIDGET)this);\r
373 }\r
374 FX_BOOL CXFA_FFTextEdit::CheckWord(FX_BSTR sWord)\r
375 {\r
376     if (sWord.IsEmpty() || m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {\r
377         return TRUE;\r
378     }\r
379     return GetDoc()->GetDocProvider()->CheckWord((XFA_HDOC)GetDoc(), sWord);\r
380 }\r
381 FX_BOOL CXFA_FFTextEdit::GetSuggestWords(FX_BSTR sWord, CFX_ByteStringArray &sSuggest)\r
382 {\r
383     if (m_pDataAcc->GetUIType() != XFA_ELEMENT_TextEdit) {\r
384         return FALSE;\r
385     }\r
386     return GetDoc()->GetDocProvider()->GetSuggestWords((XFA_HDOC)GetDoc(), sWord, sSuggest);\r
387 }\r
388 FX_INT32 CXFA_FFTextEdit::OnProcessMessage(CFWL_Message *pMessage)\r
389 {\r
390     return m_pOldDelegate->OnProcessMessage(pMessage);\r
391 }\r
392 FWL_ERR CXFA_FFTextEdit::OnProcessEvent(CFWL_Event *pEvent)\r
393 {\r
394     CXFA_FFField::OnProcessEvent(pEvent);\r
395     FX_DWORD dwEventID = pEvent->GetClassID();\r
396     switch (dwEventID) {\r
397         case FWL_EVTHASH_EDT_TextChanged: {\r
398                 CFWL_EvtEdtTextChanged *event = (CFWL_EvtEdtTextChanged*)pEvent;\r
399                 CFX_WideString wsChange;\r
400                 OnTextChanged(m_pNormalWidget->GetWidget(), wsChange, event->wsPrevText);\r
401                 break;\r
402             }\r
403         case FWL_EVTHASH_EDT_AddDoRecord: {\r
404                 OnAddDoRecord(m_pNormalWidget->GetWidget());\r
405                 break;\r
406             }\r
407         case FWL_EVTHASH_EDT_TextFull: {\r
408                 OnTextFull(m_pNormalWidget->GetWidget());\r
409                 break;\r
410             }\r
411         case FWL_EVTHASH_EDT_CheckWord: {\r
412                 CFX_WideString wstr(L"FWL_EVENT_DTP_SelectChanged");\r
413                 FX_DWORD hashcode = FX_HashCode_String_GetW(wstr, wstr.GetLength());\r
414                 CFWL_EvtEdtCheckWord *event = (CFWL_EvtEdtCheckWord*)pEvent;\r
415                 event->bCheckWord = CheckWord(event->bsWord);\r
416                 break;\r
417             }\r
418         case FWL_EVTHASH_EDT_GetSuggestWords: {\r
419                 CFWL_EvtEdtGetSuggestWords *event = (CFWL_EvtEdtGetSuggestWords*)pEvent;\r
420                 event->bSuggestWords = GetSuggestWords(event->bsWord, event->bsArraySuggestWords);\r
421                 break;\r
422             }\r
423         default: {\r
424             }\r
425     }\r
426     return m_pOldDelegate->OnProcessEvent(pEvent);\r
427 }\r
428 FWL_ERR CXFA_FFTextEdit::OnDrawWidget(CFX_Graphics *pGraphics, const CFX_Matrix *pMatrix )\r
429 {\r
430     return m_pOldDelegate->OnDrawWidget(pGraphics, pMatrix);\r
431 }\r
432 CXFA_FFNumericEdit::CXFA_FFNumericEdit(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)\r
433     : CXFA_FFTextEdit(pPageView, pDataAcc)\r
434 {\r
435 }\r
436 CXFA_FFNumericEdit::~CXFA_FFNumericEdit()\r
437 {\r
438 }\r
439 FX_BOOL CXFA_FFNumericEdit::LoadWidget()\r
440 {\r
441     CFWL_Edit* pWidget = CFWL_Edit::Create();\r
442     pWidget->Initialize();\r
443     m_pNormalWidget = (CFWL_Widget*)pWidget;\r
444     IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget();\r
445     m_pNormalWidget->SetPrivateData(pIWidget, this, NULL);\r
446     IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
447     pNoteDriver->RegisterEventTarget(pIWidget, pIWidget);\r
448     m_pOldDelegate = m_pNormalWidget->SetDelegate(this);\r
449     m_pNormalWidget->LockUpdate();\r
450     CFX_WideString wsText;\r
451     m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);\r
452     pWidget->SetText(wsText);\r
453     UpdateWidgetProperty();\r
454     m_pNormalWidget->UnlockUpdate();\r
455     return CXFA_FFField::LoadWidget();\r
456 }\r
457 void CXFA_FFNumericEdit::UpdateWidgetProperty()\r
458 {\r
459     CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;\r
460     if (!pWidget) {\r
461         return;\r
462     }\r
463     FX_DWORD dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus |\r
464                                FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Validate | FWL_STYLEEXT_EDT_Number | FWL_STYLEEXT_EDT_LastLineHeight;\r
465     dwExtendedStyle |= UpdateUIProperty();\r
466     if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {\r
467         dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;\r
468     }\r
469     FX_INT32 iNumCells = m_pDataAcc->GetNumberOfCells();\r
470     if (iNumCells > 0) {\r
471         dwExtendedStyle |= FWL_STYLEEXT_EDT_CombText;\r
472         pWidget->SetLimit(iNumCells);\r
473     }\r
474     dwExtendedStyle |= GetAlignment();\r
475     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {\r
476         dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;\r
477     }\r
478     m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);\r
479 }\r
480 FWL_ERR CXFA_FFNumericEdit::OnProcessEvent(CFWL_Event *pEvent)\r
481 {\r
482     FX_DWORD dwEventID = pEvent->GetClassID();\r
483     if (dwEventID == FWL_EVTHASH_EDT_Validate) {\r
484         CFWL_EvtEdtValidate *event = (CFWL_EvtEdtValidate*)pEvent;\r
485         CFX_WideString wsChange = event->wsInsert;\r
486         event->bValidate = OnValidate(m_pNormalWidget->GetWidget(), wsChange);\r
487         return event->bValidate;\r
488     } else {\r
489         return CXFA_FFTextEdit::OnProcessEvent(pEvent);\r
490     }\r
491 }\r
492 FX_BOOL CXFA_FFNumericEdit::OnValidate(IFWL_Widget *pWidget, CFX_WideString &wsText)\r
493 {\r
494     CFX_WideString wsPattern;\r
495     m_pDataAcc->GetPictureContent(wsPattern, XFA_VALUEPICTURE_Edit);\r
496     if (!wsPattern.IsEmpty()) {\r
497         return TRUE;\r
498     }\r
499     FX_INT32 iLeads = 0;\r
500     m_pDataAcc->GetLeadDigits(iLeads);\r
501     FX_INT32 iFracs = 0;\r
502     m_pDataAcc->GetFracDigits(iFracs);\r
503     CFX_WideString wsFormat;\r
504     CXFA_LocaleValue widgetValue = XFA_GetLocaleValue(m_pDataAcc);\r
505     widgetValue.GetNumbericFormat(wsFormat, iLeads, iFracs);\r
506     return widgetValue.ValidateNumericTemp(wsText, wsFormat, m_pDataAcc->GetLocal());\r
507 }\r
508 CXFA_FFPasswordEdit::CXFA_FFPasswordEdit(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)\r
509     : CXFA_FFTextEdit(pPageView, pDataAcc)\r
510 {\r
511 }\r
512 CXFA_FFPasswordEdit::~CXFA_FFPasswordEdit()\r
513 {\r
514 }\r
515 FX_BOOL CXFA_FFPasswordEdit::LoadWidget()\r
516 {\r
517     CFWL_Edit* pWidget = CFWL_Edit::Create();\r
518     pWidget->Initialize();\r
519     m_pNormalWidget = (CFWL_Widget*)pWidget;\r
520     IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget();\r
521     m_pNormalWidget->SetPrivateData(pIWidget, this, NULL);\r
522     IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
523     pNoteDriver->RegisterEventTarget(pIWidget, pIWidget);\r
524     m_pOldDelegate = m_pNormalWidget->SetDelegate(this);\r
525     m_pNormalWidget->LockUpdate();\r
526     CFX_WideString wsText;\r
527     m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);\r
528     pWidget->SetText(wsText);\r
529     UpdateWidgetProperty();\r
530     m_pNormalWidget->UnlockUpdate();\r
531     return CXFA_FFField::LoadWidget();\r
532 }\r
533 void CXFA_FFPasswordEdit::UpdateWidgetProperty()\r
534 {\r
535     CFWL_Edit* pWidget = (CFWL_Edit*)m_pNormalWidget;\r
536     if (!pWidget) {\r
537         return;\r
538     }\r
539     FX_DWORD dwExtendedStyle = FWL_STYLEEXT_EDT_ShowScrollbarFocus |\r
540                                FWL_STYLEEXT_EDT_OuterScrollbar | FWL_STYLEEXT_EDT_Password | FWL_STYLEEXT_EDT_LastLineHeight;\r
541     dwExtendedStyle |= UpdateUIProperty();\r
542     CFX_WideString wsPassWord;\r
543     m_pDataAcc->GetPasswordChar(wsPassWord);\r
544     if (!wsPassWord.IsEmpty()) {\r
545         pWidget->SetAliasChar(wsPassWord.GetAt(0));\r
546     }\r
547     if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {\r
548         dwExtendedStyle |= FWL_STYLEEXT_EDT_AutoHScroll;\r
549     }\r
550     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {\r
551         dwExtendedStyle |= FWL_STYLEEXT_EDT_ReadOnly;\r
552     }\r
553     dwExtendedStyle |= GetAlignment();\r
554     m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);\r
555 }\r
556 CXFA_FFDateTimeEdit::CXFA_FFDateTimeEdit(CXFA_FFPageView* pPageView, CXFA_WidgetAcc* pDataAcc)\r
557     : CXFA_FFTextEdit(pPageView, pDataAcc)\r
558 {\r
559 }\r
560 CXFA_FFDateTimeEdit::~CXFA_FFDateTimeEdit()\r
561 {\r
562 }\r
563 FX_BOOL CXFA_FFDateTimeEdit::GetBBox(CFX_RectF &rtBox, FX_DWORD dwStatus, FX_BOOL bDrawFocus)\r
564 {\r
565     if (bDrawFocus) {\r
566         return FALSE;\r
567     }\r
568 #ifndef _XFA_EMB\r
569     return CXFA_FFWidget::GetBBox(rtBox, dwStatus);\r
570 #endif\r
571     GetRectWithoutRotate(rtBox);\r
572     if (m_pNormalWidget) {\r
573         CFX_RectF rtWidget;\r
574         ((CFWL_DateTimePicker*)m_pNormalWidget)->GetBBox(rtWidget);\r
575         rtBox.Union(rtWidget);\r
576     }\r
577     CFX_Matrix mt;\r
578     GetRotateMatrix(mt);\r
579     mt.TransformRect(rtBox);\r
580     return TRUE;\r
581 }\r
582 FX_BOOL CXFA_FFDateTimeEdit::PtInActiveRect(FX_FLOAT fx, FX_FLOAT fy)\r
583 {\r
584     if (!m_pNormalWidget) {\r
585         return FALSE;\r
586     }\r
587     CFX_RectF rtWidget;\r
588     ((CFWL_DateTimePicker*)m_pNormalWidget)->GetBBox(rtWidget);\r
589     if (rtWidget.Contains(fx, fy)) {\r
590         return TRUE;\r
591     }\r
592     return FALSE;\r
593 }\r
594 FX_BOOL CXFA_FFDateTimeEdit::LoadWidget()\r
595 {\r
596     CFWL_DateTimePicker *pWidget = CFWL_DateTimePicker::Create();\r
597     pWidget->Initialize();\r
598     m_pNormalWidget = (CFWL_Widget*)pWidget;\r
599     IFWL_Widget* pIWidget = m_pNormalWidget->GetWidget();\r
600     m_pNormalWidget->SetPrivateData(pIWidget, this, NULL);\r
601     IFWL_NoteDriver *pNoteDriver = FWL_GetApp()->GetNoteDriver();\r
602     pNoteDriver->RegisterEventTarget(pIWidget, pIWidget);\r
603     m_pOldDelegate = m_pNormalWidget->SetDelegate(this);\r
604     m_pNormalWidget->LockUpdate();\r
605     CFX_WideString wsText;\r
606     m_pDataAcc->GetValue(wsText, XFA_VALUEPICTURE_Display);\r
607     pWidget->SetEditText(wsText);\r
608     XFA_DATETIMETYPE eType = XFA_DATETIMETYPE_DateAndTime;\r
609     if (CXFA_Value value = m_pDataAcc->GetFormValue()) {\r
610         switch(value.GetChildValueClassID()) {\r
611             case XFA_ELEMENT_Date: {\r
612                     eType = XFA_DATETIMETYPE_Date;\r
613                     if (!wsText.IsEmpty()) {\r
614                         CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);\r
615                         CFX_Unitime date = lcValue.GetDate();\r
616                         if ((FX_UNITIME)date != 0) {\r
617                             pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());\r
618                         }\r
619                     }\r
620                 }\r
621                 break;\r
622             case XFA_ELEMENT_Time:\r
623                 eType = XFA_DATETIMETYPE_Time;\r
624                 break;\r
625             default:\r
626                 eType = XFA_DATETIMETYPE_DateAndTime;\r
627                 break;\r
628         }\r
629     }\r
630     UpdateWidgetProperty();\r
631     m_pNormalWidget->UnlockUpdate();\r
632     return CXFA_FFField::LoadWidget();\r
633 }\r
634 void CXFA_FFDateTimeEdit::UpdateWidgetProperty()\r
635 {\r
636     CFWL_DateTimePicker* pWidget = (CFWL_DateTimePicker*)m_pNormalWidget;\r
637     if (!pWidget) {\r
638         return;\r
639     }\r
640     FX_DWORD dwExtendedStyle = FWL_STYLEEXT_DTP_ShortDateFormat;\r
641     dwExtendedStyle |= UpdateUIProperty();\r
642     dwExtendedStyle |= GetAlignment();\r
643     m_pNormalWidget->ModifyStylesEx(dwExtendedStyle, 0xFFFFFFFF);\r
644     FX_DWORD dwEditStyles = FWL_STYLEEXT_EDT_LastLineHeight;\r
645     FX_INT32 iNumCells = m_pDataAcc->GetNumberOfCells();\r
646     if (iNumCells > 0) {\r
647         dwEditStyles |= FWL_STYLEEXT_EDT_CombText;\r
648         pWidget->SetEditLimit(iNumCells);\r
649     }\r
650     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open || !m_pDataAcc->GetDoc()->GetXFADoc()->IsInteractive()) {\r
651         dwEditStyles |= FWL_STYLEEXT_EDT_ReadOnly;\r
652     }\r
653     if (m_pDataAcc->GetHorizontalScrollPolicy() != XFA_ATTRIBUTEENUM_Off) {\r
654         dwEditStyles |= FWL_STYLEEXT_EDT_AutoHScroll;\r
655     }\r
656     pWidget->ModifyEditStylesEx(dwEditStyles, 0xFFFFFFFF);\r
657 }\r
658 FX_DWORD CXFA_FFDateTimeEdit::GetAlignment()\r
659 {\r
660     FX_DWORD dwExtendedStyle = 0;\r
661     if (CXFA_Para para = m_pDataAcc->GetPara()) {\r
662         FX_INT32 iHorz = para.GetHorizontalAlign();\r
663         switch(iHorz) {\r
664             case XFA_ATTRIBUTEENUM_Center:\r
665                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHCenter;\r
666                 break;\r
667             case XFA_ATTRIBUTEENUM_Justify:\r
668                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditJustified;\r
669                 break;\r
670             case XFA_ATTRIBUTEENUM_JustifyAll:\r
671                 break;\r
672             case XFA_ATTRIBUTEENUM_Radix:\r
673                 break;\r
674             case XFA_ATTRIBUTEENUM_Right:\r
675                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHFar;\r
676                 break;\r
677             default:\r
678                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditHNear;\r
679                 break;\r
680         }\r
681         FX_INT32 iVert = para.GetVerticalAlign();\r
682         switch(iVert) {\r
683             case XFA_ATTRIBUTEENUM_Middle:\r
684                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVCenter;\r
685                 break;\r
686             case XFA_ATTRIBUTEENUM_Bottom:\r
687                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVFar;\r
688                 break;\r
689             default:\r
690                 dwExtendedStyle |= FWL_STYLEEXT_DTP_EditVNear;\r
691                 break;\r
692         }\r
693     }\r
694     return dwExtendedStyle;\r
695 }\r
696 FX_BOOL CXFA_FFDateTimeEdit::CommitData()\r
697 {\r
698     CFX_WideString wsText;\r
699     ((CFWL_DateTimePicker*)m_pNormalWidget)->GetEditText(wsText);\r
700     if (m_pDataAcc->SetValue(wsText, XFA_VALUEPICTURE_Edit)) {\r
701         m_pDataAcc->UpdateUIDisplay(this);\r
702         return TRUE;\r
703     }\r
704     return FALSE;\r
705 }\r
706 FX_BOOL CXFA_FFDateTimeEdit::UpdateFWLData()\r
707 {\r
708     if (!m_pNormalWidget) {\r
709         return FALSE;\r
710     }\r
711     XFA_VALUEPICTURE eType = XFA_VALUEPICTURE_Display;\r
712     if (IsFocused()) {\r
713         eType = XFA_VALUEPICTURE_Edit;\r
714     }\r
715     CFX_WideString wsText;\r
716     m_pDataAcc->GetValue(wsText, eType);\r
717     ((CFWL_DateTimePicker*)m_pNormalWidget)->SetEditText(wsText);\r
718     if (IsFocused() && !wsText.IsEmpty()) {\r
719         CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);\r
720         CFX_Unitime date = lcValue.GetDate();\r
721         if (lcValue.IsValid()) {\r
722             if ((FX_UNITIME)date != 0) {\r
723                 ((CFWL_DateTimePicker*)m_pNormalWidget)->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());\r
724             }\r
725         }\r
726     }\r
727     m_pNormalWidget->Update();\r
728     return TRUE;\r
729 }\r
730 FX_BOOL CXFA_FFDateTimeEdit::IsDataChanged()\r
731 {\r
732     if (m_dwStatus & XFA_WIDGETSTATUS_TextEditValueChanged) {\r
733         return TRUE;\r
734     }\r
735     CFX_WideString wsText;\r
736     ((CFWL_DateTimePicker*)m_pNormalWidget)->GetEditText(wsText);\r
737     CFX_WideString wsOldValue;\r
738     m_pDataAcc->GetValue(wsOldValue, XFA_VALUEPICTURE_Edit);\r
739     return wsOldValue != wsText;\r
740 }\r
741 FX_BOOL CXFA_FFDateTimeEdit::CanUndo()\r
742 {\r
743     return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanUndo();\r
744 }\r
745 FX_BOOL CXFA_FFDateTimeEdit::CanRedo()\r
746 {\r
747     return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanRedo();\r
748 }\r
749 FX_BOOL CXFA_FFDateTimeEdit::Undo()\r
750 {\r
751     return ((CFWL_DateTimePicker*)m_pNormalWidget)->Undo();\r
752 }\r
753 FX_BOOL CXFA_FFDateTimeEdit::Redo()\r
754 {\r
755     return ((CFWL_DateTimePicker*)m_pNormalWidget)->Redo();\r
756 }\r
757 FX_BOOL CXFA_FFDateTimeEdit::CanCopy()\r
758 {\r
759     return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanCopy();\r
760 }\r
761 FX_BOOL CXFA_FFDateTimeEdit::CanCut()\r
762 {\r
763     if (m_pDataAcc->GetAccess() != XFA_ATTRIBUTEENUM_Open) {\r
764         return FALSE;\r
765     }\r
766     return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanCut();\r
767 }\r
768 FX_BOOL CXFA_FFDateTimeEdit::CanPaste()\r
769 {\r
770     return m_pDataAcc->GetAccess() == XFA_ATTRIBUTEENUM_Open;\r
771 }\r
772 FX_BOOL CXFA_FFDateTimeEdit::CanSelectAll()\r
773 {\r
774     return ((CFWL_DateTimePicker*)m_pNormalWidget)->CanSelectAll();\r
775 }\r
776 FX_BOOL CXFA_FFDateTimeEdit::Copy(CFX_WideString &wsCopy)\r
777 {\r
778     return ((CFWL_DateTimePicker*)m_pNormalWidget)->Copy(wsCopy);\r
779 }\r
780 FX_BOOL CXFA_FFDateTimeEdit::Cut(CFX_WideString &wsCut)\r
781 {\r
782     return ((CFWL_DateTimePicker*)m_pNormalWidget)->Cut(wsCut);\r
783 }\r
784 FX_BOOL CXFA_FFDateTimeEdit::Paste(const CFX_WideString &wsPaste)\r
785 {\r
786     return ((CFWL_DateTimePicker*)m_pNormalWidget)->Paste(wsPaste);\r
787 }\r
788 FX_BOOL CXFA_FFDateTimeEdit::SelectAll()\r
789 {\r
790     return ((CFWL_DateTimePicker*)m_pNormalWidget)->SelectAll();\r
791 }\r
792 FX_BOOL CXFA_FFDateTimeEdit::Delete()\r
793 {\r
794     return ((CFWL_DateTimePicker*)m_pNormalWidget)->Delete();\r
795 }\r
796 FX_BOOL CXFA_FFDateTimeEdit::DeSelect()\r
797 {\r
798     return ((CFWL_DateTimePicker*)m_pNormalWidget)->DeSelect();\r
799 }\r
800 void CXFA_FFDateTimeEdit::OnSelectChanged(IFWL_Widget *pWidget, FX_INT32 iYear, FX_INT32 iMonth, FX_INT32 iDay)\r
801 {\r
802     CFX_WideString wsPicture;\r
803     m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit);\r
804     CXFA_LocaleValue date(XFA_VT_DATE, this->GetDoc()->GetXFADoc()->GetLocalMgr());\r
805     CFX_Unitime dt;\r
806     dt.Set(iYear, iMonth, iDay);\r
807     date.SetDate(dt);\r
808     CFX_WideString wsDate;\r
809     date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(), XFA_VALUEPICTURE_Edit);\r
810     CFWL_DateTimePicker* pDateTime = (CFWL_DateTimePicker*)m_pNormalWidget;\r
811     pDateTime->SetEditText(wsDate);\r
812     pDateTime->Update();\r
813     GetDoc()->GetDocProvider()->SetFocusWidget((XFA_HDOC)GetDoc(), NULL);\r
814     CXFA_EventParam eParam;\r
815     eParam.m_eType = XFA_EVENT_Change;\r
816     eParam.m_pTarget = m_pDataAcc;\r
817     m_pDataAcc->GetValue(eParam.m_wsNewText, XFA_VALUEPICTURE_Raw);\r
818     m_pDataAcc->ProcessEvent(XFA_ATTRIBUTEENUM_Change, &eParam);\r
819 }\r
820 FWL_ERR CXFA_FFDateTimeEdit::OnProcessEvent(CFWL_Event *pEvent)\r
821 {\r
822     FX_DWORD dwEventID = pEvent->GetClassID();\r
823     if (dwEventID == FWL_EVTHASH_DTP_SelectChanged) {\r
824         CFWL_Event_DtpSelectChanged *event = (CFWL_Event_DtpSelectChanged*)pEvent;\r
825         OnSelectChanged(m_pNormalWidget->GetWidget(), event->iYear, event->iMonth, event->iDay);\r
826         return TRUE;\r
827     } else {\r
828         return CXFA_FFTextEdit::OnProcessEvent(pEvent);\r
829     }\r
830 }\r