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