Initial commit.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_EditCtrl.cpp
1 // Copyright 2014 PDFium Authors. All rights reserved.\r
2 // Use of this source code is governed by a BSD-style license that can be\r
3 // found in the LICENSE file.\r
4  \r
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
6 \r
7 #include "../../include/pdfwindow/PDFWindow.h"\r
8 #include "../../include/pdfwindow/PWL_Wnd.h"\r
9 #include "../../include/pdfwindow/PWL_EditCtrl.h"\r
10 #include "../../include/pdfwindow/PWL_ScrollBar.h"\r
11 #include "../../include/pdfwindow/PWL_Utils.h"\r
12 #include "../../include/pdfwindow/PWL_Caret.h"\r
13 #include "../../include/pdfwindow/PWL_FontMap.h"\r
14 \r
15 #define IsFloatZero(f)                                          ((f) < 0.0001 && (f) > -0.0001)\r
16 #define IsFloatBigger(fa,fb)                            ((fa) > (fb) && !IsFloatZero((fa) - (fb)))\r
17 #define IsFloatSmaller(fa,fb)                           ((fa) < (fb) && !IsFloatZero((fa) - (fb)))\r
18 #define IsFloatEqual(fa,fb)                                     IsFloatZero((fa)-(fb))\r
19 \r
20 /* ---------------------------- CPWL_EditCtrl ------------------------------ */\r
21 \r
22 CPWL_EditCtrl::CPWL_EditCtrl() :\r
23         m_pEdit(NULL),\r
24         m_pEditCaret(NULL),\r
25         m_bMouseDown(FALSE),\r
26         m_pEditNotify(NULL),\r
27         m_nCharSet(DEFAULT_CHARSET),\r
28         m_nCodePage(0)\r
29 {\r
30         m_pEdit = IFX_Edit::NewEdit();\r
31         ASSERT(m_pEdit != NULL);\r
32 }\r
33 \r
34 CPWL_EditCtrl::~CPWL_EditCtrl()\r
35 {\r
36         IFX_Edit::DelEdit(m_pEdit);\r
37 }\r
38 \r
39 void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM & cp)\r
40 {\r
41         cp.eCursorType = FXCT_VBEAM;\r
42 }\r
43 \r
44 void CPWL_EditCtrl::OnCreated()\r
45 {\r
46         SetFontSize(this->GetCreationParam().fFontSize);\r
47 \r
48         m_pEdit->SetFontMap(this->GetFontMap());\r
49         m_pEdit->SetNotify(this);\r
50         m_pEdit->Initialize();\r
51 }\r
52 \r
53 FX_BOOL CPWL_EditCtrl::IsWndHorV()\r
54 {\r
55         CPDF_Matrix mt = GetWindowMatrix();\r
56         CPDF_Point point1(0,1);\r
57         CPDF_Point point2(1,1);\r
58 \r
59         mt.Transform(point1.x, point1.y);\r
60         mt.Transform(point2.x, point2.y);\r
61 \r
62         return point2.y == point1.y;\r
63 }\r
64 \r
65 void CPWL_EditCtrl::SetCursor()\r
66 {\r
67         if (IsValid()) \r
68         {\r
69                 if (IFX_SystemHandler* pSH = GetSystemHandler())\r
70                 {\r
71                         if (IsWndHorV())\r
72                                 pSH->SetCursor(FXCT_VBEAM);\r
73                         else\r
74                                 pSH->SetCursor(FXCT_HBEAM);\r
75                 }\r
76         }\r
77 }\r
78 \r
79 void CPWL_EditCtrl::RePosChildWnd()\r
80 {\r
81         m_pEdit->SetPlateRect(GetClientRect());\r
82 }\r
83 \r
84 void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)\r
85 {\r
86         CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);\r
87 \r
88         switch (msg)\r
89         {\r
90                 case PNM_SETSCROLLINFO:\r
91                         switch (wParam)\r
92                         {\r
93                                 case SBT_VSCROLL:\r
94                                         if (CPWL_Wnd * pChild = GetVScrollBar())\r
95                                         {\r
96                                                 pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);\r
97                                         }\r
98                                         break;\r
99                         }\r
100                         break;\r
101                 case PNM_SETSCROLLPOS:                  \r
102                         switch (wParam)\r
103                         {\r
104                                 case SBT_VSCROLL:\r
105                                         if (CPWL_Wnd * pChild = GetVScrollBar())\r
106                                         {\r
107                                                 pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);\r
108                                         }\r
109                                         break;\r
110                         }\r
111                         break;\r
112                 case PNM_SCROLLWINDOW:\r
113                         {\r
114                                 FX_FLOAT fPos = *(FX_FLOAT*)lParam;\r
115                                 switch (wParam)\r
116                                 {\r
117                                         case SBT_VSCROLL:\r
118                                                 m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x,fPos));\r
119                                                 break;\r
120                                 }\r
121                         }\r
122                         break;\r
123                 case PNM_SETCARETINFO:\r
124                         {\r
125                                 if (PWL_CARET_INFO * pCaretInfo = (PWL_CARET_INFO *)wParam)\r
126                                 {\r
127                                         this->SetCaret(pCaretInfo->bVisible,\r
128                                                 pCaretInfo->ptHead,\r
129                                                 pCaretInfo->ptFoot);                                    \r
130                                 }\r
131                         }\r
132                         break;\r
133         }\r
134 }\r
135 \r
136 void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM & cp)\r
137 {\r
138         if (!IsReadOnly())\r
139                 CreateEditCaret(cp);\r
140 }\r
141 \r
142 void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM & cp)\r
143 {\r
144         if (!m_pEditCaret)\r
145         {\r
146                 m_pEditCaret = new CPWL_Caret;  \r
147                 m_pEditCaret->SetInvalidRect(GetClientRect());\r
148 \r
149                 PWL_CREATEPARAM ecp = cp;\r
150                 ecp.pParentWnd = this;\r
151                 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;\r
152                 ecp.dwBorderWidth = 0;\r
153                 ecp.nBorderStyle = PBS_SOLID;\r
154                 ecp.rcRectWnd = CPDF_Rect(0,0,0,0);\r
155 \r
156                 m_pEditCaret->Create(ecp);\r
157         }\r
158 }\r
159 \r
160 void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize)\r
161 {\r
162         m_pEdit->SetFontSize(fFontSize);\r
163 }\r
164 \r
165 FX_FLOAT CPWL_EditCtrl::GetFontSize() const\r
166 {\r
167         return m_pEdit->GetFontSize();\r
168 }\r
169 \r
170 FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)\r
171 {\r
172         if (m_bMouseDown) return TRUE;\r
173 \r
174         FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar,nFlag);\r
175 \r
176         //FILTER\r
177         switch (nChar)\r
178         {\r
179         default:\r
180                 return FALSE;\r
181         case FWL_VKEY_Delete:\r
182         case FWL_VKEY_Up:\r
183         case FWL_VKEY_Down:\r
184         case FWL_VKEY_Left:\r
185         case FWL_VKEY_Right:\r
186         case FWL_VKEY_Home:\r
187         case FWL_VKEY_End:\r
188         case FWL_VKEY_Insert:\r
189         case 'C':\r
190         case 'V':\r
191         case 'X':\r
192         case 'A':\r
193         case 'Z':\r
194         case 'c':\r
195         case 'v':\r
196         case 'x':\r
197         case 'a':\r
198         case 'z':\r
199                 break;\r
200         }\r
201 \r
202         if (nChar == FWL_VKEY_Delete)\r
203         {\r
204                 if (m_pEdit->IsSelected())\r
205                         nChar = FWL_VKEY_Unknown;\r
206         }\r
207 \r
208         switch (nChar)\r
209         {\r
210                 case FWL_VKEY_Delete:   \r
211                         Delete();\r
212                         return TRUE;\r
213                 case FWL_VKEY_Insert:\r
214                         if (IsSHIFTpressed(nFlag))\r
215                                 PasteText();\r
216                         return TRUE;\r
217                 case FWL_VKEY_Up:\r
218                         m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag),FALSE);\r
219                         return TRUE;\r
220                 case FWL_VKEY_Down:\r
221                         m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag),FALSE);\r
222                         return TRUE;\r
223                 case FWL_VKEY_Left:\r
224                         m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag),FALSE);\r
225                         return TRUE;\r
226                 case FWL_VKEY_Right:\r
227                         m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag),FALSE);\r
228                         return TRUE;\r
229                 case FWL_VKEY_Home:\r
230                         m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));\r
231                         return TRUE;\r
232                 case FWL_VKEY_End:\r
233                         m_pEdit->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));\r
234                         return TRUE;\r
235                 case FWL_VKEY_Unknown:\r
236                         if (!IsSHIFTpressed(nFlag))\r
237                                 Clear();\r
238                         else\r
239                                 CutText();\r
240                         return TRUE;\r
241                 default:\r
242                         break;\r
243         }\r
244         \r
245         return bRet;\r
246 }\r
247 \r
248 FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag)\r
249 {\r
250         if (m_bMouseDown) return TRUE;\r
251 \r
252         CPWL_Wnd::OnChar(nChar,nFlag);\r
253 \r
254         //FILTER\r
255         switch (nChar)\r
256         {\r
257                 case 0x0A:\r
258                 case 0x1B:\r
259                         return FALSE;           \r
260                 default:\r
261                         break;\r
262         }\r
263 \r
264         FX_BOOL bCtrl = IsCTRLpressed(nFlag);\r
265         FX_BOOL bAlt = IsALTpressed(nFlag);\r
266         FX_BOOL bShift = IsSHIFTpressed(nFlag);\r
267 \r
268         FX_WORD word = nChar;\r
269 \r
270         if (bCtrl && !bAlt)\r
271         {\r
272                 switch (nChar)\r
273                 {\r
274                         case 'C' - 'A' + 1:\r
275                                 this->CopyText();\r
276                                 return TRUE;\r
277                         case 'V' - 'A' + 1:\r
278                                 this->PasteText();\r
279                                 return TRUE;\r
280                         case 'X' - 'A' + 1:\r
281                                 this->CutText();\r
282                                 return TRUE;\r
283                         case 'A' - 'A' + 1:\r
284                                 this->SelectAll();\r
285                                 return TRUE;\r
286                         case 'Z' - 'A' + 1:\r
287                                 if (bShift)\r
288                                         Redo();\r
289                                 else\r
290                                         Undo();\r
291                                 return TRUE;\r
292                         default:\r
293                                 if (nChar < 32)\r
294                                         return FALSE;\r
295                 }\r
296         }\r
297 \r
298         if (IsReadOnly()) return TRUE;\r
299 \r
300         if (m_pEdit->IsSelected() && word ==  FWL_VKEY_Back)\r
301                 word = FWL_VKEY_Unknown;\r
302 \r
303         Clear();\r
304 \r
305         switch (word)\r
306         {\r
307         case FWL_VKEY_Back:\r
308                 Backspace();\r
309                 break;\r
310         case FWL_VKEY_Return:   \r
311                 InsertReturn();\r
312                 break;\r
313         case FWL_VKEY_Unknown:\r
314                 break;\r
315         default:\r
316                 if (IsINSERTpressed(nFlag))\r
317                         Delete();\r
318                 InsertWord(word, this->GetCharSet());\r
319                 break;\r
320         }\r
321 \r
322         return TRUE;\r
323 }\r
324 \r
325 FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)\r
326 {\r
327         CPWL_Wnd::OnLButtonDown(point,nFlag);\r
328 \r
329         if (ClientHitTest(point))\r
330         {               \r
331                 if (m_bMouseDown)\r
332                         this->InvalidateRect();\r
333 \r
334                 m_bMouseDown = TRUE;            \r
335                 SetCapture();\r
336 \r
337                 m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));\r
338         }\r
339 \r
340         return TRUE;\r
341 }\r
342 \r
343 FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)\r
344 {\r
345         CPWL_Wnd::OnLButtonUp(point,nFlag);\r
346 \r
347         if (m_bMouseDown)\r
348         {\r
349                 //can receive keybord message\r
350                 if (ClientHitTest(point) && !this->IsFocused())\r
351                         SetFocus();     \r
352 \r
353                 ReleaseCapture();\r
354                 m_bMouseDown = FALSE;\r
355         }\r
356 \r
357         return TRUE;\r
358 }\r
359 \r
360 FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)\r
361 {\r
362         CPWL_Wnd::OnMouseMove(point,nFlag);\r
363 \r
364         if (m_bMouseDown)\r
365                 m_pEdit->OnMouseMove(point,FALSE,FALSE);\r
366 \r
367         return TRUE;\r
368 }\r
369 \r
370 CPDF_Rect CPWL_EditCtrl::GetContentRect() const\r
371 {\r
372         return m_pEdit->GetContentRect();\r
373 }\r
374 \r
375 void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible)\r
376 {\r
377         CPDF_Point ptHead(0,0),ptFoot(0,0);\r
378 \r
379         if (bVisible)\r
380         {\r
381                 GetCaretInfo(ptHead,ptFoot);\r
382         }\r
383 \r
384         CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();\r
385         this->IOnSetCaret(bVisible,ptHead,ptFoot,wpTemp);\r
386 }\r
387 \r
388 void CPWL_EditCtrl::GetCaretInfo(CPDF_Point & ptHead, CPDF_Point & ptFoot) const\r
389 {\r
390         if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())\r
391         {\r
392                 pIterator->SetAt(m_pEdit->GetCaret());\r
393                 CPVT_Word word;\r
394                 CPVT_Line line;\r
395                 if (pIterator->GetWord(word))\r
396                 {\r
397                         ptHead.x = word.ptWord.x + word.fWidth;\r
398                         ptHead.y = word.ptWord.y + word.fAscent;\r
399                         ptFoot.x = word.ptWord.x + word.fWidth;\r
400                         ptFoot.y = word.ptWord.y + word.fDescent;\r
401                 }\r
402                 else if (pIterator->GetLine(line))\r
403                 {                               \r
404                         ptHead.x = line.ptLine.x;\r
405                         ptHead.y = line.ptLine.y + line.fLineAscent;\r
406                         ptFoot.x = line.ptLine.x;\r
407                         ptFoot.y = line.ptLine.y + line.fLineDescent;\r
408                 }\r
409         }\r
410 }\r
411 \r
412 void CPWL_EditCtrl::GetCaretPos(FX_INT32& x, FX_INT32& y) const\r
413 {\r
414         CPDF_Point ptHead(0,0), ptFoot(0,0);\r
415 \r
416         GetCaretInfo(ptHead,ptFoot);\r
417 \r
418         PWLtoWnd(ptHead, x, y);\r
419 }\r
420 \r
421 void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)\r
422 {\r
423         if (m_pEditCaret)\r
424         {\r
425                 if (!IsFocused() || m_pEdit->IsSelected())\r
426                         bVisible = FALSE;\r
427 \r
428                 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);\r
429         }\r
430 }\r
431 \r
432 FX_BOOL CPWL_EditCtrl::IsModified() const\r
433 {\r
434         return m_pEdit->IsModified();\r
435 }\r
436 \r
437 CFX_WideString CPWL_EditCtrl::GetText() const\r
438 {\r
439         return m_pEdit->GetText();\r
440 }\r
441 \r
442 void CPWL_EditCtrl::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)\r
443 {\r
444         m_pEdit->SetSel(nStartChar, nEndChar);\r
445 }\r
446 \r
447 void CPWL_EditCtrl::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar ) const\r
448 {\r
449         m_pEdit->GetSel(nStartChar, nEndChar);\r
450 }\r
451 \r
452 void CPWL_EditCtrl::Clear()\r
453 {\r
454         if (!IsReadOnly())\r
455                 m_pEdit->Clear();\r
456 }\r
457 \r
458 void CPWL_EditCtrl::SelectAll()\r
459 {\r
460         m_pEdit->SelectAll();\r
461 }\r
462 \r
463 void CPWL_EditCtrl::Paint()\r
464 {\r
465         if (m_pEdit)\r
466                 m_pEdit->Paint();\r
467 }\r
468 \r
469 void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh)\r
470 {\r
471         if (m_pEdit)\r
472                 m_pEdit->EnableRefresh(bRefresh);\r
473 }\r
474 \r
475 FX_INT32 CPWL_EditCtrl::GetCaret() const\r
476 {\r
477         if (m_pEdit)\r
478                 return m_pEdit->GetCaret();\r
479 \r
480         return -1;\r
481 }\r
482 \r
483 void CPWL_EditCtrl::SetCaret(FX_INT32 nPos)\r
484 {\r
485         if (m_pEdit)\r
486                 m_pEdit->SetCaret(nPos);\r
487 }\r
488 \r
489 FX_INT32 CPWL_EditCtrl::GetTotalWords() const\r
490 {\r
491         if (m_pEdit)\r
492                 return m_pEdit->GetTotalWords();\r
493 \r
494         return 0;\r
495 }\r
496 \r
497 void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point)\r
498 {\r
499         if (m_pEdit)\r
500                 m_pEdit->SetScrollPos(point);\r
501 }\r
502 \r
503 CPDF_Point CPWL_EditCtrl::GetScrollPos() const\r
504 {\r
505         if (m_pEdit)\r
506                 return m_pEdit->GetScrollPos();\r
507 \r
508         return CPDF_Point(0.0f, 0.0f);\r
509 }\r
510 \r
511 CPDF_Font * CPWL_EditCtrl::GetCaretFont() const\r
512 {\r
513         FX_INT32 nFontIndex = 0;\r
514 \r
515         if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())\r
516         {\r
517                 pIterator->SetAt(m_pEdit->GetCaret());\r
518                 CPVT_Word word;\r
519                 CPVT_Section section;\r
520                 if (pIterator->GetWord(word))\r
521                 {\r
522                         nFontIndex = word.nFontIndex;\r
523                 }\r
524                 else if (HasFlag(PES_RICH))\r
525                 {\r
526                         if (pIterator->GetSection(section))\r
527                         {                               \r
528                                 nFontIndex = section.WordProps.nFontIndex;\r
529                         }\r
530                 }\r
531         }\r
532 \r
533         if (IFX_Edit_FontMap * pFontMap = GetFontMap())\r
534                 return pFontMap->GetPDFFont(nFontIndex);\r
535         else\r
536                 return NULL;\r
537 }\r
538 \r
539 FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const\r
540 {\r
541         FX_FLOAT fFontSize = GetFontSize();\r
542 \r
543         if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())\r
544         {\r
545                 pIterator->SetAt(m_pEdit->GetCaret());\r
546                 CPVT_Word word;\r
547                 CPVT_Section section;\r
548                 if (pIterator->GetWord(word))\r
549                 {\r
550                         fFontSize = word.fFontSize;\r
551                 }\r
552                 else if (HasFlag(PES_RICH))\r
553                 {\r
554                         if (pIterator->GetSection(section))\r
555                         {                               \r
556                                 fFontSize = section.WordProps.fFontSize;\r
557                         }\r
558                 }\r
559         }\r
560 \r
561         return fFontSize;\r
562 }\r
563 \r
564 void CPWL_EditCtrl::SetText(FX_LPCWSTR csText)\r
565 {\r
566         m_pEdit->SetText(csText);\r
567 }\r
568 \r
569 void CPWL_EditCtrl::CopyText()\r
570 {\r
571 }\r
572 \r
573 void CPWL_EditCtrl::PasteText()\r
574 {\r
575 }\r
576 \r
577 void CPWL_EditCtrl::CutText()\r
578 {\r
579 }\r
580 \r
581 void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow)\r
582 {\r
583 }\r
584 \r
585 void CPWL_EditCtrl::InsertText(FX_LPCWSTR csText)\r
586 {\r
587         if (!IsReadOnly())\r
588                 m_pEdit->InsertText(csText);\r
589 }\r
590 \r
591 void CPWL_EditCtrl::InsertWord(FX_WORD word, FX_INT32 nCharset)\r
592 {\r
593         if (!IsReadOnly())\r
594                 m_pEdit->InsertWord(word, nCharset);\r
595 }\r
596 \r
597 void CPWL_EditCtrl::InsertReturn()\r
598 {\r
599         if (!IsReadOnly())\r
600                 m_pEdit->InsertReturn();\r
601 }\r
602 \r
603 void CPWL_EditCtrl::Delete()\r
604 {\r
605         if (!IsReadOnly())\r
606                 m_pEdit->Delete();\r
607 }\r
608 \r
609 void CPWL_EditCtrl::Backspace()\r
610 {\r
611         if (!IsReadOnly())\r
612                 m_pEdit->Backspace();\r
613 }\r
614 \r
615 FX_BOOL CPWL_EditCtrl::CanUndo() const\r
616 {\r
617         return !IsReadOnly() && m_pEdit->CanUndo();\r
618 }\r
619 \r
620 FX_BOOL CPWL_EditCtrl::CanRedo() const\r
621 {\r
622         return !IsReadOnly() && m_pEdit->CanRedo();\r
623 }\r
624 \r
625 void CPWL_EditCtrl::Redo()\r
626 {\r
627         if (CanRedo())\r
628                 m_pEdit->Redo();\r
629 }\r
630 \r
631 void CPWL_EditCtrl::Undo()\r
632 {\r
633         if (CanUndo())\r
634                 m_pEdit->Undo();\r
635 }\r
636 \r
637 void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax, \r
638                                                                                                 FX_FLOAT fContentMin, FX_FLOAT fContentMax, \r
639                                                                                                 FX_FLOAT fSmallStep, FX_FLOAT fBigStep)\r
640 {\r
641         PWL_SCROLL_INFO Info;\r
642 \r
643         Info.fPlateWidth = fPlateMax - fPlateMin;\r
644         Info.fContentMin = fContentMin;\r
645         Info.fContentMax = fContentMax;\r
646         Info.fSmallStep = fSmallStep;\r
647         Info.fBigStep = fBigStep;\r
648 \r
649         this->OnNotify(this,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);\r
650 \r
651 //      PWL_TRACE("set scroll info:%f\n",fContentMax - fContentMin);\r
652 \r
653         if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)\r
654                 || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))\r
655         {\r
656                 this->ShowVScrollBar(FALSE);            \r
657         }\r
658         else\r
659         {\r
660                 this->ShowVScrollBar(TRUE);\r
661         }\r
662 }\r
663 \r
664 void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy)\r
665 {\r
666 //      PWL_TRACE("set scroll position:%f\n",fy);\r
667         this->OnNotify(this,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);\r
668 }\r
669 \r
670 void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot, const CPVT_WordPlace& place)\r
671 {\r
672         PWL_CARET_INFO cInfo;\r
673         cInfo.bVisible = bVisible;\r
674         cInfo.ptHead = ptHead;\r
675         cInfo.ptFoot = ptFoot;\r
676 \r
677         this->OnNotify(this,PNM_SETCARETINFO,(FX_INTPTR)&cInfo,(FX_INTPTR)NULL);\r
678 }\r
679 \r
680 void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps & secProps, const CPVT_WordProps & wordProps)\r
681 {\r
682 }\r
683 \r
684 void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent)\r
685 {\r
686         if (this->IsValid())\r
687         {\r
688                 if (m_pEditNotify)\r
689                 {\r
690                         m_pEditNotify->OnContentChange(rcContent);\r
691                 }\r
692         }\r
693 }\r
694 \r
695 void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect * pRect)\r
696 {\r
697         this->InvalidateRect(pRect);\r
698 }\r
699 \r
700 FX_INT32 CPWL_EditCtrl::GetCharSet() const\r
701 {\r
702         if (m_nCharSet < 0)\r
703                 return DEFAULT_CHARSET; \r
704         else\r
705                 return m_nCharSet;\r
706 }\r
707 \r
708 void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect, FX_INT32 & nStartChar, FX_INT32 & nEndChar) const\r
709 {\r
710         nStartChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top)));\r
711         nEndChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom)));\r
712 }\r
713 \r
714 CFX_WideString CPWL_EditCtrl::GetText(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const\r
715 {\r
716         CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);\r
717         CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);\r
718         return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));\r
719 }\r
720 \r
721 void    CPWL_EditCtrl::SetReadyToInput()\r
722 {\r
723         if (m_bMouseDown)\r
724         {\r
725                 ReleaseCapture();\r
726                 m_bMouseDown = FALSE;\r
727         }\r
728 }\r