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