Revert build of pdfium_unittests.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_Edit.cpp
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 "../../include/pdfwindow/PDFWindow.h"
8 #include "../../include/pdfwindow/PWL_Wnd.h"
9 #include "../../include/pdfwindow/PWL_EditCtrl.h"
10 #include "../../include/pdfwindow/PWL_Edit.h"
11 #include "../../include/pdfwindow/PWL_ScrollBar.h"
12 #include "../../include/pdfwindow/PWL_Utils.h"
13 #include "../../include/pdfwindow/PWL_Caret.h"
14 #include "../../include/pdfwindow/PWL_FontMap.h"
15
16 /* ---------------------------- CPWL_Edit ------------------------------ */
17
18 CPWL_Edit::CPWL_Edit() : m_pFillerNotify(NULL), 
19         m_pSpellCheck(NULL),
20         m_bFocus(FALSE)
21 {
22         m_pFormFiller = NULL;
23 }
24
25 CPWL_Edit::~CPWL_Edit()
26 {
27         ASSERT(m_bFocus == FALSE);
28 }
29
30 CFX_ByteString CPWL_Edit::GetClassName() const
31 {
32         return PWL_CLASSNAME_EDIT;
33 }
34
35 void CPWL_Edit::OnDestroy()
36 {
37 }
38
39 void CPWL_Edit::SetText(FX_LPCWSTR csText)
40 {
41         CFX_WideString swText = csText;
42
43         if (HasFlag(PES_RICH))
44         {               
45                 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText);
46                 
47                 if (CXML_Element * pXML = CXML_Element::Parse((FX_LPCSTR)sValue,sValue.GetLength()))
48                 {
49                         FX_INT32 nCount = pXML->CountChildren();
50                         FX_BOOL bFirst = TRUE;
51
52                         swText.Empty();
53
54                         for (FX_INT32 i=0; i<nCount; i++)
55                         {
56                                 if (CXML_Element * pSubElement = pXML->GetElement(i))
57                                 {
58                                         CFX_ByteString tag=pSubElement->GetTagName();
59                                         if (tag.EqualNoCase("p"))
60                                         {
61                                                 int nChild = pSubElement->CountChildren();
62                                                 CFX_WideString swSection;
63                                                 for(FX_INT32 j=0; j<nChild; j++)
64                                                 {
65                                                         swSection += pSubElement->GetContent(j);
66                                                 }
67                                                 
68                                                 if (bFirst)bFirst = FALSE;
69                                                 else
70                                                         swText += FWL_VKEY_Return;
71                                                 swText += swSection;
72                                         }
73                                 }
74                         }
75
76                         delete pXML;
77                 }
78         }       
79
80         m_pEdit->SetText(swText);
81 }
82
83 void CPWL_Edit::RePosChildWnd()
84 {
85         if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
86         {
87                 //if (pVSB->IsVisible())
88                 {
89                         CPDF_Rect rcWindow = m_rcOldWindow;             
90                         CPDF_Rect rcVScroll = CPDF_Rect(rcWindow.right,
91                                                                 rcWindow.bottom,
92                                                                 rcWindow.right + PWL_SCROLLBAR_WIDTH,
93                                                                 rcWindow.top);
94                         pVSB->Move(rcVScroll, TRUE, FALSE);
95                 }
96         }
97
98         if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW))
99                 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(),1.0f)); //+1 for caret beside border
100
101         CPWL_EditCtrl::RePosChildWnd();
102 }
103
104 CPDF_Rect CPWL_Edit::GetClientRect() const
105 {
106         CPDF_Rect rcClient = CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(GetBorderWidth()+GetInnerBorderWidth()));
107         
108         if (CPWL_ScrollBar * pVSB = this->GetVScrollBar())
109         {
110                 if (pVSB->IsVisible())
111                 {
112                         rcClient.right -= PWL_SCROLLBAR_WIDTH;
113                 }
114         }
115
116         return rcClient;
117 }
118
119 void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, FX_BOOL bPaint/* = TRUE*/)
120 {
121         m_pEdit->SetAlignmentH((FX_INT32)nFormat, bPaint);
122 }
123
124 void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, FX_BOOL bPaint/* = TRUE*/)
125 {
126         m_pEdit->SetAlignmentV((FX_INT32)nFormat, bPaint);
127 }
128
129 FX_BOOL CPWL_Edit::CanSelectAll() const
130 {
131         return  GetSelectWordRange() != m_pEdit->GetWholeWordRange();
132 }
133
134 FX_BOOL CPWL_Edit::CanClear() const
135 {
136         return !IsReadOnly() && m_pEdit->IsSelected();
137 }
138
139 FX_BOOL CPWL_Edit::CanCopy() const
140 {
141         return  !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && m_pEdit->IsSelected();
142 }
143
144 FX_BOOL CPWL_Edit::CanCut() const
145 {
146         return  CanCopy() && !IsReadOnly();
147 }
148
149 FX_BOOL CPWL_Edit::CanPaste() const
150 {
151         if (IsReadOnly()) return FALSE;
152
153         CFX_WideString swClipboard;
154         if (IFX_SystemHandler* pSH = GetSystemHandler())
155                 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
156
157         return !swClipboard.IsEmpty();
158 }
159
160 void CPWL_Edit::CopyText()
161 {
162         if (!CanCopy()) return;
163
164         CFX_WideString str = m_pEdit->GetSelText();
165
166         if (IFX_SystemHandler* pSH = GetSystemHandler())
167                 pSH->SetClipboardText(GetAttachedHWnd(), str);
168 }
169
170 void CPWL_Edit::PasteText()
171 {
172         if (!CanPaste()) return;
173
174         CFX_WideString swClipboard;
175         if (IFX_SystemHandler* pSH = GetSystemHandler())
176                 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
177
178         if (m_pFillerNotify)
179         {
180                 FX_BOOL bRC = TRUE;
181                 FX_BOOL bExit = FALSE;
182                 CFX_WideString strChangeEx;
183                 int nSelStart = 0;
184                 int nSelEnd = 0;
185                 GetSel(nSelStart, nSelEnd);
186                 m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), 0 , swClipboard, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, 0);
187                 if (!bRC) return;
188                 if (bExit) return;
189         }
190
191         if (swClipboard.GetLength() > 0)
192         {
193                 Clear();
194                 InsertText(swClipboard);
195         }
196
197         if (m_pFillerNotify)
198         {
199                 FX_BOOL bExit = FALSE;
200                 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,0);
201                 if (bExit) return;
202         }
203 }
204
205 void CPWL_Edit::CutText()
206 {
207         if (!CanCut()) return;
208
209         CFX_WideString str = m_pEdit->GetSelText();
210
211         if (IFX_SystemHandler* pSH = GetSystemHandler())
212                 pSH->SetClipboardText(GetAttachedHWnd(), str);
213
214         m_pEdit->Clear();
215 }
216
217 void CPWL_Edit::OnCreated()
218 {
219         CPWL_EditCtrl::OnCreated();
220
221         if (CPWL_ScrollBar * pScroll = GetVScrollBar())
222         {
223                 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
224                 pScroll->SetTransparency(255);
225         }
226
227         SetParamByFlag();
228
229         m_rcOldWindow = GetWindowRect();
230
231         m_pEdit->SetOprNotify(this);
232         m_pEdit->EnableOprNotify(TRUE);
233 }
234
235 void CPWL_Edit::SetParamByFlag()
236 {       
237         if (HasFlag(PES_RIGHT))
238         {
239                 m_pEdit->SetAlignmentH(2, FALSE);
240         }
241         else if (HasFlag(PES_MIDDLE))
242         {
243                 m_pEdit->SetAlignmentH(1, FALSE);
244         }
245         else
246         {
247                 m_pEdit->SetAlignmentH(0, FALSE);
248         }
249
250         if (HasFlag(PES_BOTTOM))
251         {
252                 m_pEdit->SetAlignmentV(2, FALSE);
253         }
254         else if (HasFlag(PES_CENTER))
255         {
256                 m_pEdit->SetAlignmentV(1, FALSE);
257         }
258         else
259         {
260                 m_pEdit->SetAlignmentV(0, FALSE);
261         }
262
263         if (HasFlag(PES_PASSWORD))
264         {
265                 m_pEdit->SetPasswordChar('*', FALSE);
266         }
267
268         m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE);
269         m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE);
270         m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE);
271         m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE);
272         m_pEdit->EnableUndo(HasFlag(PES_UNDO));
273
274         if (HasFlag(PES_TEXTOVERFLOW))
275         {
276                 SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f));
277                 m_pEdit->SetTextOverflow(TRUE, FALSE);
278         }
279         else
280         {
281                 if (m_pEditCaret)
282                 {
283                         m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(),1.0f)); //+1 for caret beside border
284                 }
285         }
286
287         if (HasFlag(PES_SPELLCHECK))
288         {
289                 m_pSpellCheck = GetCreationParam().pSpellCheck;
290         }
291 }
292
293 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream)
294 {
295         CPWL_Wnd::GetThisAppearanceStream(sAppStream);
296
297         CPDF_Rect rcClient = GetClientRect();
298         CFX_ByteTextBuf sLine;
299
300         FX_INT32 nCharArray = m_pEdit->GetCharArray();
301
302         if (nCharArray > 0)
303         {
304                 switch (GetBorderStyle())
305                 {
306                 case PBS_SOLID:
307                         {
308                                 sLine << "q\n" << GetBorderWidth() << " w\n" 
309                                         << CPWL_Utils::GetColorAppStream(GetBorderColor(),FALSE) << " 2 J 0 j\n";                                       
310
311                                 for (FX_INT32 i=1;i<nCharArray;i++)
312                                 {
313                                         sLine << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
314                                                 << rcClient.bottom << " m\n"
315                                                 << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
316                                                 << rcClient.top << " l S\n";                                            
317                                 }
318
319                                 sLine << "Q\n";                                 
320                         }
321                         break; 
322                 case PBS_DASH:
323                         {
324                                 sLine << "q\n" << GetBorderWidth() << " w\n" 
325                                         << CPWL_Utils::GetColorAppStream(GetBorderColor(),FALSE) << " 2 J 0 j\n"
326                                         << "[" << GetBorderDash().nDash << " " 
327                                         << GetBorderDash().nGap << "] " 
328                                         << GetBorderDash().nPhase << " d\n";
329
330                                 for (FX_INT32 i=1;i<nCharArray;i++)                                     
331                                 {
332                                         sLine << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
333                                                 << rcClient.bottom << " m\n"
334                                                 << rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*i << " "
335                                                 << rcClient.top << " l S\n";    
336                                 }
337
338                                 sLine << "Q\n";
339                         }
340                         break;
341                 }               
342         }
343
344         sAppStream << sLine;
345
346         CFX_ByteTextBuf sText;
347
348         CPDF_Point ptOffset = CPDF_Point(0.0f,0.0f);
349
350         CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange();
351         CPVT_WordRange wrSelect = GetSelectWordRange();
352         CPVT_WordRange wrVisible = (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange());
353         CPVT_WordRange wrSelBefore(wrWhole.BeginPos,wrSelect.BeginPos);
354         CPVT_WordRange wrSelAfter(wrSelect.EndPos,wrWhole.EndPos);
355
356         CPVT_WordRange wrTemp = CPWL_Utils::OverlapWordRange(GetSelectWordRange(),wrVisible);
357         CFX_ByteString sEditSel = CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset,
358                         &wrTemp);
359
360         if (sEditSel.GetLength() > 0)
361                 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR) << sEditSel ;
362
363         wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelBefore);
364         CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset,  
365                         &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());                  
366
367         if (sEditBefore.GetLength() > 0)
368                 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditBefore << "ET\n";
369
370         wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelect);
371         CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset, 
372                         &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());                  
373
374         if (sEditMid.GetLength() > 0)
375                 sText << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY,1)) << sEditMid << "ET\n";
376
377         wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelAfter);
378         CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset, 
379                         &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordChar());                  
380
381         if (sEditAfter.GetLength() > 0)
382                 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEditAfter<< "ET\n";
383
384         if (HasFlag(PES_SPELLCHECK))
385         {
386                 CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream(m_pEdit, m_pSpellCheck, ptOffset, &wrVisible);
387                 if (sSpellCheck.GetLength() > 0)
388                         sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB,1,0,0),FALSE) << sSpellCheck;
389         }
390
391         if (sText.GetLength() > 0)
392         {
393                 CPDF_Rect rcClient = this->GetClientRect();
394                 sAppStream << "q\n/Tx BMC\n";
395                 
396                 if (!HasFlag(PES_TEXTOVERFLOW))
397                         sAppStream << rcClient.left << " " << rcClient.bottom << " "
398                                 << rcClient.right - rcClient.left << " " << rcClient.top - rcClient.bottom << " re W n\n";
399
400                 sAppStream << sText;
401
402                 sAppStream << "EMC\nQ\n";
403         }
404 }
405
406 void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device)
407 {
408         CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device);
409
410         CPDF_Rect rcClient = GetClientRect();
411         CFX_ByteTextBuf sLine;
412
413         FX_INT32 nCharArray = m_pEdit->GetCharArray();
414         FX_SAFE_INT32 nCharArraySafe = nCharArray;
415         nCharArraySafe -= 1;
416         nCharArraySafe *= 2;
417
418         if (nCharArray > 0 && nCharArraySafe.IsValid())
419         {
420                 switch (GetBorderStyle())
421                 {
422                 case PBS_SOLID:
423                         {
424                                 CFX_GraphStateData gsd;
425                                 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
426
427                                 CFX_PathData path;
428                                 if (!path.SetPointCount(nCharArraySafe.ValueOrDie())) {
429                                         return;
430                                 }
431                                 
432                                 for (FX_INT32 i=0; i<nCharArray-1; i++)
433                                 {                                       
434                                         path.SetPoint(i*2, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1), 
435                                                 rcClient.bottom, FXPT_MOVETO);
436                                         path.SetPoint(i*2+1, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
437                                                 rcClient.top, FXPT_LINETO);                                                                                     
438                                 }                       
439                                 if (path.GetPointCount() > 0)
440                                         pDevice->DrawPath(&path, pUser2Device, &gsd,0,  
441                                                 CPWL_Utils::PWLColorToFXColor(GetBorderColor(),255), FXFILL_ALTERNATE);
442                         }
443                         break; 
444                 case PBS_DASH:
445                         {
446                                 CFX_GraphStateData gsd;
447                                 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth();
448
449                                 gsd.SetDashCount(2);
450                                 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash;
451                                 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap;
452                                 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase;
453
454                                 CFX_PathData path;
455                                 if (!path.SetPointCount(nCharArraySafe.ValueOrDie())) {
456                                         return;
457                                 }
458                                 
459                                 for (FX_INT32 i=0; i<nCharArray-1; i++)
460                                 {                                       
461                                         path.SetPoint(i*2, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1), 
462                                                 rcClient.bottom, FXPT_MOVETO);
463                                         path.SetPoint(i*2+1, rcClient.left + ((rcClient.right - rcClient.left)/nCharArray)*(i+1),
464                                                 rcClient.top, FXPT_LINETO);                                                                                     
465                                 }               
466                                 if (path.GetPointCount() > 0)
467                                         pDevice->DrawPath(&path, pUser2Device, &gsd,0,  
468                                                 CPWL_Utils::PWLColorToFXColor(GetBorderColor(),255), FXFILL_ALTERNATE);
469                         }
470                         break;
471                 }               
472         }
473
474         CPDF_Rect rcClip;
475         CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
476         CPVT_WordRange* pRange = NULL;
477
478         if (!HasFlag(PES_TEXTOVERFLOW))
479         {
480                 rcClip = GetClientRect();
481                 pRange = &wrRange;
482         }
483 IFX_SystemHandler* pSysHandler = GetSystemHandler();
484         IFX_Edit::DrawEdit(pDevice,pUser2Device,m_pEdit,
485                 CPWL_Utils::PWLColorToFXColor(GetTextColor(),this->GetTransparency()),
486                 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(),this->GetTransparency()),
487                 rcClip,CPDF_Point(0.0f,0.0f),pRange, pSysHandler, m_pFormFiller);
488
489         if (HasFlag(PES_SPELLCHECK))
490         {
491                 CPWL_Utils::DrawEditSpellCheck(pDevice,pUser2Device,m_pEdit,rcClip,
492                         CPDF_Point(0.0f,0.0f),pRange, this->GetCreationParam().pSpellCheck);
493         }
494 }
495
496 FX_BOOL CPWL_Edit::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
497 {
498         CPWL_Wnd::OnLButtonDown(point,nFlag);
499
500         if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
501         {
502                 if (m_bMouseDown)
503                         this->InvalidateRect();
504
505                 m_bMouseDown = TRUE;            
506                 SetCapture();
507
508                 m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
509         }
510
511         return TRUE;
512 }
513
514 FX_BOOL CPWL_Edit::OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag)
515 {
516         CPWL_Wnd::OnLButtonDblClk(point, nFlag);
517
518         if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
519         {
520                 m_pEdit->SelectAll();
521         }
522
523         return TRUE;
524 }
525
526 #define WM_PWLEDIT_UNDO                                 0x01
527 #define WM_PWLEDIT_REDO                                 0x02
528 #define WM_PWLEDIT_CUT                                  0x03
529 #define WM_PWLEDIT_COPY                                 0x04
530 #define WM_PWLEDIT_PASTE                                0x05
531 #define WM_PWLEDIT_DELETE                               0x06
532 #define WM_PWLEDIT_SELECTALL                    0x07
533 #define WM_PWLEDIT_SUGGEST                              0x08
534
535 FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
536 {
537         if (m_bMouseDown) return FALSE;
538
539         CPWL_Wnd::OnRButtonUp(point, nFlag);
540         
541         if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) return TRUE;
542
543         IFX_SystemHandler* pSH = GetSystemHandler();
544         if (!pSH) return FALSE;
545
546         this->SetFocus();
547
548         CPVT_WordRange wrLatin = GetLatinWordsRange(point);
549         CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin);
550
551         FX_HMENU hPopup = pSH->CreatePopupMenu();
552         if (!hPopup) return FALSE;
553
554         CFX_ByteStringArray sSuggestWords;
555         CPDF_Point ptPopup = point;
556
557         if (!IsReadOnly())
558         {
559                 if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty())
560                 {
561                         if (m_pSpellCheck)
562                         {
563                                 CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin);
564
565                                 if (!m_pSpellCheck->CheckWord(sLatin))
566                                 {                                               
567                                         m_pSpellCheck->SuggestWords(sLatin,sSuggestWords);
568
569                                         FX_INT32 nSuggest = sSuggestWords.GetSize();
570
571                                         for (FX_INT32 nWord=0; nWord<nSuggest; nWord++)
572                                         {       
573                                                 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST+nWord, sSuggestWords[nWord].UTF8Decode());
574                                         }
575
576                                         if (nSuggest > 0)
577                                                 pSH->AppendMenuItem(hPopup, 0, L"");
578
579                                         ptPopup = GetWordRightBottomPoint(wrLatin.EndPos);
580                                 }
581                         }
582                 }
583         }
584
585         IPWL_Provider* pProvider = this->GetProvider();
586
587         if (HasFlag(PES_UNDO))
588         {
589                 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_UNDO, 
590                         pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo");
591                 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_REDO,
592                         pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo");
593                 pSH->AppendMenuItem(hPopup, 0, L"");
594
595                 if (!m_pEdit->CanUndo())
596                         pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE);
597                 if (!m_pEdit->CanRedo())
598                         pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE);
599         }
600
601         pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT, 
602                 pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t");
603         pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY, 
604                 pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy");
605         pSH->AppendMenuItem(hPopup, WM_PWLEDIT_PASTE, 
606                 pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste");
607         pSH->AppendMenuItem(hPopup, WM_PWLEDIT_DELETE, 
608                 pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete");
609
610         CFX_WideString swText = pSH->GetClipboardText(this->GetAttachedHWnd());
611         if (swText.IsEmpty())
612                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
613
614         if (!m_pEdit->IsSelected())
615         {
616                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
617                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
618                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
619         }
620
621         if (IsReadOnly())
622         {
623                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
624                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
625                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);                   
626         }
627
628         if (HasFlag(PES_PASSWORD))
629         {
630                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
631                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
632         }
633
634         if (HasFlag(PES_NOREAD))
635         {
636                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
637                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
638         }
639
640         pSH->AppendMenuItem(hPopup, 0, L"");
641         pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SELECTALL,
642                 pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All");
643
644         if (m_pEdit->GetTotalWords() == 0)
645         {
646                 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE);
647         }
648
649         FX_INT32 x, y;
650         PWLtoWnd(ptPopup, x, y);
651         pSH->ClientToScreen(GetAttachedHWnd(), x, y);
652         pSH->SetCursor(FXCT_ARROW);
653         FX_INT32 nCmd = pSH->TrackPopupMenu(hPopup,
654                                          x,
655                                          y,
656                                          GetAttachedHWnd());
657
658
659         switch (nCmd)
660         {
661         case WM_PWLEDIT_UNDO:
662                 Undo();
663                 break;
664         case WM_PWLEDIT_REDO:
665                 Redo();
666                 break;
667         case WM_PWLEDIT_CUT:
668                 this->CutText();
669                 break;
670         case WM_PWLEDIT_COPY:
671                 this->CopyText();
672                 break;
673         case WM_PWLEDIT_PASTE:
674                 this->PasteText();
675                 break;
676         case WM_PWLEDIT_DELETE:
677                 this->Clear();
678                 break;
679         case WM_PWLEDIT_SELECTALL:
680                 this->SelectAll();
681                 break;
682         case WM_PWLEDIT_SUGGEST + 0:
683                 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
684                 ReplaceSel(sSuggestWords[0].UTF8Decode());
685                 break;
686         case WM_PWLEDIT_SUGGEST + 1:
687                 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
688                 ReplaceSel(sSuggestWords[1].UTF8Decode());
689                 break;
690         case WM_PWLEDIT_SUGGEST + 2:
691                 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
692                 ReplaceSel(sSuggestWords[2].UTF8Decode());
693                 break;
694         case WM_PWLEDIT_SUGGEST + 3:
695                 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
696                 ReplaceSel(sSuggestWords[3].UTF8Decode());
697                 break;
698         case WM_PWLEDIT_SUGGEST + 4:            
699                 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
700                 ReplaceSel(sSuggestWords[4].UTF8Decode());
701                 break;
702         default:
703                 break;
704         }
705
706         pSH->DestroyMenu(hPopup);
707
708         return TRUE;
709 }
710
711 void CPWL_Edit::OnSetFocus()
712 {
713         SetEditCaret(TRUE);
714
715         if (!IsReadOnly())
716         {
717                 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
718                         pFocusHandler->OnSetFocus(this);
719         }
720
721         m_bFocus = TRUE;
722 }
723
724 void CPWL_Edit::OnKillFocus()
725 {
726         ShowVScrollBar(FALSE);
727         
728         m_pEdit->SelectNone();
729         SetCaret(FALSE, CPDF_Point(0.0f,0.0f), CPDF_Point(0.0f,0.0f));
730         
731         SetCharSet(0);
732
733         if (!IsReadOnly())
734         {
735                 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
736                         pFocusHandler->OnKillFocus(this);
737         }
738
739         m_bFocus = FALSE;
740 }
741
742 void CPWL_Edit::SetHorzScale(FX_INT32 nHorzScale, FX_BOOL bPaint/* = TRUE*/)
743 {
744         m_pEdit->SetHorzScale(nHorzScale, bPaint);
745 }
746
747 void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint/* = TRUE*/)
748 {
749         m_pEdit->SetCharSpace(fCharSpace, bPaint);
750 }
751
752 void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint/* = TRUE*/)
753 {
754         m_pEdit->SetLineLeading(fLineLeading, bPaint);
755 }
756
757 CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(const CPDF_Point & ptOffset) const
758 {
759         CPVT_WordRange wr = GetSelectWordRange();
760         return CPWL_Utils::GetEditSelAppStream(m_pEdit,ptOffset,&wr);
761 }
762
763 CPVT_WordRange CPWL_Edit::GetSelectWordRange() const
764 {
765         if (m_pEdit->IsSelected())
766         {
767                 FX_INT32 nStart = -1;
768                 FX_INT32 nEnd = -1;
769
770                 m_pEdit->GetSel(nStart, nEnd);
771
772                 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart);
773                 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd);
774
775                 return CPVT_WordRange(wpStart,wpEnd);
776         }
777
778         return CPVT_WordRange();
779 }
780
781 CFX_ByteString CPWL_Edit::GetTextAppearanceStream(const CPDF_Point & ptOffset) const
782 {
783         CFX_ByteTextBuf sRet;
784         CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset);
785         
786         if (sEdit.GetLength() > 0)
787         {
788                 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit << "ET\n";
789         }
790
791         return sRet.GetByteString();
792 }
793
794 CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(const CPDF_Point & ptOffset) const
795 {
796         if (m_pEditCaret)
797                 return m_pEditCaret->GetCaretAppearanceStream(ptOffset);
798
799         return CFX_ByteString();
800 }
801
802 CPDF_Point CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord)
803 {
804         CPDF_Point pt(0.0f, 0.0f);
805
806         if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
807         {
808                 CPVT_WordPlace wpOld = pIterator->GetAt();
809                 pIterator->SetAt(wpWord);
810                 CPVT_Word word;
811                 if (pIterator->GetWord(word))
812                 {
813                         pt = CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord.y + word.fDescent);
814                 }
815
816                 pIterator->SetAt(wpOld);
817         }
818
819         return pt;
820 }
821
822 FX_BOOL CPWL_Edit::IsTextFull() const
823 {
824         return m_pEdit->IsTextFull();
825 }
826
827 FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, const CPDF_Rect& rcPlate, FX_INT32 nCharArray)
828 {
829         if (pFont && !pFont->IsStandardFont())
830         {
831                 FX_RECT rcBBox;
832                 pFont->GetFontBBox(rcBBox);
833
834                 CPDF_Rect rcCell = rcPlate;
835                 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width();
836                 FX_FLOAT ydiv = - rcCell.Height() * 1000.0f / rcBBox.Height();
837
838                 return xdiv < ydiv ? xdiv : ydiv;
839         }
840
841         return 0.0f;
842 }
843
844 void CPWL_Edit::SetCharArray(FX_INT32 nCharArray)
845 {
846         if (HasFlag(PES_CHARARRAY) && nCharArray > 0)
847         {
848                 m_pEdit->SetCharArray(nCharArray);      
849                 m_pEdit->SetTextOverflow(TRUE);
850
851                 if (HasFlag(PWS_AUTOFONTSIZE))
852                 {
853                         if (IFX_Edit_FontMap* pFontMap = this->GetFontMap())
854                         {
855                                 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(pFontMap->GetPDFFont(0), GetClientRect(), nCharArray);
856                                 if (fFontSize > 0.0f)
857                                 {
858                                         m_pEdit->SetAutoFontSize(FALSE);
859                                         m_pEdit->SetFontSize(fFontSize);
860                                 }
861                         }
862                 }
863         }
864 }
865
866 void CPWL_Edit::SetLimitChar(FX_INT32 nLimitChar)
867 {
868         m_pEdit->SetLimitChar(nLimitChar);
869 }
870
871 void CPWL_Edit::ReplaceSel(FX_LPCWSTR csText)
872 {
873         m_pEdit->Clear();
874         m_pEdit->InsertText(csText);
875 }
876
877 CPDF_Rect CPWL_Edit::GetFocusRect() const
878 {
879         return CPDF_Rect();
880 }
881
882 void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow)
883 {
884         if (CPWL_ScrollBar * pScroll = GetVScrollBar())
885         {
886                 if (bShow)
887                 {
888                         if (!pScroll->IsVisible())
889                         {
890                                 pScroll->SetVisible(TRUE);
891                                 CPDF_Rect rcWindow = GetWindowRect();
892                                 m_rcOldWindow = rcWindow;
893                                 rcWindow.right += PWL_SCROLLBAR_WIDTH;                  
894                                 Move(rcWindow, TRUE, TRUE);
895                         }
896                 }
897                 else
898                 {
899                         if (pScroll->IsVisible())
900                         {
901                                 pScroll->SetVisible(FALSE);
902                                 Move(m_rcOldWindow, TRUE, TRUE);
903                         }       
904                 }
905         }
906 }
907
908 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const
909 {
910         if (CPWL_ScrollBar * pScroll = GetVScrollBar())
911         {
912                 return pScroll->IsVisible();
913         }
914
915         return FALSE;
916 }
917
918 void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled)
919 {
920         if (bEnabled)
921                 AddFlag(PES_SPELLCHECK);
922         else
923                 RemoveFlag(PES_SPELLCHECK);
924 }
925
926 FX_BOOL CPWL_Edit::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
927 {
928         if (m_bMouseDown) return TRUE;
929
930         if (nChar == FWL_VKEY_Delete)
931         {
932                 if (m_pFillerNotify)
933                 {
934                         FX_BOOL bRC = TRUE;
935                         FX_BOOL bExit = FALSE;
936                         CFX_WideString strChange;
937                         CFX_WideString strChangeEx;
938
939                         int nSelStart = 0;
940                         int nSelEnd = 0;
941                         GetSel(nSelStart, nSelEnd);
942
943                         if (nSelStart == nSelEnd)
944                                 nSelEnd = nSelStart + 1;
945                         m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), FWL_VKEY_Delete, strChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag);
946                         if (!bRC) return FALSE;                         
947                         if (bExit) return FALSE;
948                 }
949         }
950
951         FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar,  nFlag);
952
953         if (nChar == FWL_VKEY_Delete)
954         {
955                 if (m_pFillerNotify)
956                 {
957                         FX_BOOL bExit = FALSE;
958                         m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,nFlag);
959                         if (bExit) return FALSE;
960                 }
961         }
962
963         //In case of implementation swallow the OnKeyDown event.
964         if(IsProceedtoOnChar(nChar, nFlag))
965                         return TRUE;
966
967         return bRet;
968 }
969
970 /**
971 *In case of implementation swallow the OnKeyDown event. 
972 *If the event is swallowed, implementation may do other unexpected things, which is not the control means to do.
973 */
974 FX_BOOL CPWL_Edit::IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag)
975 {
976
977         FX_BOOL bCtrl = IsCTRLpressed(nFlag);
978         FX_BOOL bAlt = IsALTpressed(nFlag);
979         if(bCtrl && !bAlt)
980         {
981         //hot keys for edit control.    
982                 switch(nKeyCode)
983                 {
984                 case 'C':
985                 case 'V':
986                 case 'X':
987                 case 'A':
988                 case 'Z':
989                         return TRUE;
990                 default:
991                         break;
992                 }
993         }
994         //control characters.
995         switch(nKeyCode)
996         {
997         case FWL_VKEY_Escape:
998         case FWL_VKEY_Back:
999         case FWL_VKEY_Return:
1000         case FWL_VKEY_Space:
1001                 return TRUE;
1002         default:
1003                 break;
1004         }
1005         return FALSE;
1006
1007 }
1008
1009 FX_BOOL CPWL_Edit::OnChar(FX_WORD nChar, FX_DWORD nFlag)
1010 {
1011         if (m_bMouseDown) return TRUE;
1012
1013         FX_BOOL bRC = TRUE;
1014         FX_BOOL bExit = FALSE;
1015
1016         FX_BOOL bCtrl = IsCTRLpressed(nFlag);
1017         if (!bCtrl)
1018         {
1019                 if (m_pFillerNotify)
1020                 {
1021                         CFX_WideString swChange;
1022                         FX_INT32 nKeyCode;
1023
1024                         int nSelStart = 0;
1025                         int nSelEnd = 0;
1026                         GetSel(nSelStart, nSelEnd);
1027
1028                         switch (nChar)
1029                         {
1030                         case FWL_VKEY_Back:
1031                                 nKeyCode = nChar;
1032                                 if (nSelStart == nSelEnd)
1033                                         nSelStart = nSelEnd - 1;
1034                                 break;
1035                         case FWL_VKEY_Return:
1036                                 nKeyCode = nChar;
1037                                 break;
1038                         default:
1039                                 nKeyCode = 0;
1040                                 swChange += nChar;
1041                                 break;
1042                         }
1043                 
1044                         CFX_WideString strChangeEx;
1045                         m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), nKeyCode, swChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag);
1046                 }
1047         }
1048
1049         if (!bRC) return TRUE;
1050         if (bExit) return FALSE;
1051
1052         if (IFX_Edit_FontMap * pFontMap = GetFontMap())
1053         {
1054                 FX_INT32 nOldCharSet = GetCharSet();
1055                 FX_INT32 nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET);
1056                 if(nOldCharSet != nNewCharSet)
1057                 {
1058                         SetCharSet(nNewCharSet);
1059                 }
1060         }
1061         FX_BOOL bRet = CPWL_EditCtrl::OnChar(nChar,nFlag);
1062
1063         if (!bCtrl)
1064         {
1065                 if (m_pFillerNotify)
1066                 {
1067                         m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit,nFlag);
1068                         if (bExit) return FALSE;
1069                 }
1070         }
1071
1072         return bRet;
1073 }
1074
1075 FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag)
1076 {
1077         if (HasFlag(PES_MULTILINE))
1078         {
1079                 CPDF_Point ptScroll = GetScrollPos();
1080
1081                 if (zDelta > 0)
1082                 {
1083                         ptScroll.y += this->GetFontSize();
1084                 }
1085                 else
1086                 {
1087                         ptScroll.y -= this->GetFontSize();
1088                 }
1089                 this->SetScrollPos(ptScroll);
1090
1091                 return TRUE;
1092         }
1093
1094         return FALSE;
1095 }
1096
1097 void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1098 {
1099         if (HasFlag(PES_SPELLCHECK))
1100         {
1101                 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
1102         }
1103
1104         if (m_pEditNotify)
1105         {
1106                 m_pEditNotify->OnInsertReturn(place, oldplace);
1107         }
1108 }
1109
1110 void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1111 {
1112         if (HasFlag(PES_SPELLCHECK))
1113         {
1114                 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
1115         }
1116
1117         if (m_pEditNotify)
1118         {
1119                 m_pEditNotify->OnBackSpace(place, oldplace);
1120         }
1121 }
1122
1123 void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1124 {
1125         if (HasFlag(PES_SPELLCHECK))
1126         {
1127                 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
1128         }
1129
1130         if (m_pEditNotify)
1131         {
1132                 m_pEditNotify->OnDelete(place, oldplace);
1133         }
1134 }
1135
1136 void CPWL_Edit::OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1137 {
1138         if (HasFlag(PES_SPELLCHECK))
1139         {
1140                 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
1141         }
1142
1143         if (m_pEditNotify)
1144         {
1145                 m_pEditNotify->OnClear(place, oldplace);
1146         }
1147 }
1148
1149 void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1150 {
1151         if (HasFlag(PES_SPELLCHECK))
1152         {
1153                 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
1154         }
1155
1156         if (m_pEditNotify)
1157         {
1158                 m_pEditNotify->OnInsertWord(place, oldplace);
1159         }
1160 }
1161
1162 void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1163 {
1164 }
1165
1166 void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace)
1167 {
1168         if (HasFlag(PES_SPELLCHECK))
1169         {
1170                 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace),GetLatinWordsRange(place)));
1171         }
1172
1173         if (m_pEditNotify)
1174         {
1175                 m_pEditNotify->OnInsertText(place, oldplace);
1176         }
1177 }
1178
1179 void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem)
1180 {
1181         if (m_pEditNotify)
1182         {
1183                 m_pEditNotify->OnAddUndo(this);
1184         }
1185 }
1186
1187 CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, const CPVT_WordRange& wr2)
1188 {
1189         CPVT_WordRange wrRet;
1190
1191         if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0)
1192         {
1193                 wrRet.BeginPos = wr1.BeginPos;
1194         }
1195         else
1196         {
1197                 wrRet.BeginPos = wr2.BeginPos;
1198         }
1199
1200         if (wr1.EndPos.WordCmp(wr2.EndPos) < 0)
1201         {
1202                 wrRet.EndPos = wr2.EndPos;
1203         }
1204         else
1205         {
1206                 wrRet.EndPos = wr1.EndPos;
1207         }
1208
1209         return wrRet;
1210 }
1211
1212 CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPDF_Point& point) const
1213 {
1214         return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE);
1215 }
1216
1217 CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPVT_WordPlace & place) const
1218 {
1219         return GetSameWordsRange(place, TRUE, FALSE);
1220 }
1221
1222 CPVT_WordRange CPWL_Edit::GetArabicWordsRange(const CPVT_WordPlace & place) const
1223 {
1224         return GetSameWordsRange(place, FALSE, TRUE);
1225 }
1226
1227 #define PWL_ISARABICWORD(word) ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC))
1228
1229 CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace & place, FX_BOOL bLatin, FX_BOOL bArabic) const
1230 {
1231         CPVT_WordRange range;
1232
1233         if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator())
1234         {
1235                 CPVT_Word wordinfo;     
1236                 CPVT_WordPlace wpStart(place),wpEnd(place);                     
1237                 pIterator->SetAt(place);                        
1238                 
1239                 if (bLatin)
1240                 {
1241                         while (pIterator->NextWord())
1242                         {
1243                                 if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLATINWORD(wordinfo.Word))
1244                                 {
1245                                         wpEnd = pIterator->GetAt();
1246                                         continue;
1247                                 }
1248                                 else 
1249                                         break;
1250                         };
1251                 }
1252                 else if (bArabic)
1253                 {
1254                         while (pIterator->NextWord())
1255                         {
1256                                 if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word))
1257                                 {
1258                                         wpEnd = pIterator->GetAt();
1259                                         continue;
1260                                 }
1261                                 else 
1262                                         break;
1263                         };
1264                 }
1265
1266                 pIterator->SetAt(place);
1267
1268                 if (bLatin)
1269                 {
1270                         do
1271                         {
1272                                 if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLATINWORD(wordinfo.Word))
1273                                 {                                       
1274                                         continue;
1275                                 }
1276                                 else
1277                                 {
1278                                         wpStart = pIterator->GetAt();
1279                                         break;
1280                                 }
1281                         }
1282                         while (pIterator->PrevWord());
1283                 }
1284                 else if (bArabic)
1285                 {
1286                         do
1287                         {
1288                                 if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word))
1289                                 {                                       
1290                                         continue;
1291                                 }
1292                                 else
1293                                 {
1294                                         wpStart = pIterator->GetAt();
1295                                         break;
1296                                 }
1297                         }
1298                         while (pIterator->PrevWord());
1299                 }
1300
1301                 range.Set(wpStart,wpEnd);
1302         }       
1303
1304         return range;
1305 }
1306
1307 void CPWL_Edit::AjustArabicWords(const CPVT_WordRange& wr)
1308 {
1309 }
1310
1311 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, 
1312                                                                                 const CPDF_Point& ptOffset, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray)
1313 {
1314         IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray);
1315 }
1316
1317 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, 
1318                                                                         const CPDF_Point& ptOffset)
1319 {
1320         CFX_ArrayTemplate<CPDF_TextObject*> ObjArray;
1321         IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPWL_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray);
1322 }
1323