Remove FX_Alloc() null checks now that it can't return NULL.
[pdfium.git] / fpdfsdk / src / pdfwindow / PWL_EditCtrl.cpp
index 2562822..90a198a 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#include "../../include/pdfwindow/PDFWindow.h"\r
-#include "../../include/pdfwindow/PWL_Wnd.h"\r
-#include "../../include/pdfwindow/PWL_EditCtrl.h"\r
-#include "../../include/pdfwindow/PWL_ScrollBar.h"\r
-#include "../../include/pdfwindow/PWL_Utils.h"\r
-#include "../../include/pdfwindow/PWL_Caret.h"\r
-#include "../../include/pdfwindow/PWL_FontMap.h"\r
-\r
-#define IsFloatZero(f)                                         ((f) < 0.0001 && (f) > -0.0001)\r
-#define IsFloatBigger(fa,fb)                           ((fa) > (fb) && !IsFloatZero((fa) - (fb)))\r
-#define IsFloatSmaller(fa,fb)                          ((fa) < (fb) && !IsFloatZero((fa) - (fb)))\r
-#define IsFloatEqual(fa,fb)                                    IsFloatZero((fa)-(fb))\r
-\r
-/* ---------------------------- CPWL_EditCtrl ------------------------------ */\r
-\r
-CPWL_EditCtrl::CPWL_EditCtrl() :\r
-       m_pEdit(NULL),\r
-       m_pEditCaret(NULL),\r
-       m_bMouseDown(FALSE),\r
-       m_pEditNotify(NULL),\r
-       m_nCharSet(DEFAULT_CHARSET),\r
-       m_nCodePage(0)\r
-{\r
-       m_pEdit = IFX_Edit::NewEdit();\r
-       ASSERT(m_pEdit != NULL);\r
-}\r
-\r
-CPWL_EditCtrl::~CPWL_EditCtrl()\r
-{\r
-       IFX_Edit::DelEdit(m_pEdit);\r
-}\r
-\r
-void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM & cp)\r
-{\r
-       cp.eCursorType = FXCT_VBEAM;\r
-}\r
-\r
-void CPWL_EditCtrl::OnCreated()\r
-{\r
-       SetFontSize(this->GetCreationParam().fFontSize);\r
-\r
-       m_pEdit->SetFontMap(this->GetFontMap());\r
-       m_pEdit->SetNotify(this);\r
-       m_pEdit->Initialize();\r
-}\r
-\r
-FX_BOOL CPWL_EditCtrl::IsWndHorV()\r
-{\r
-       CPDF_Matrix mt = GetWindowMatrix();\r
-       CPDF_Point point1(0,1);\r
-       CPDF_Point point2(1,1);\r
-\r
-       mt.Transform(point1.x, point1.y);\r
-       mt.Transform(point2.x, point2.y);\r
-\r
-       return point2.y == point1.y;\r
-}\r
-\r
-void CPWL_EditCtrl::SetCursor()\r
-{\r
-       if (IsValid()) \r
-       {\r
-               if (IFX_SystemHandler* pSH = GetSystemHandler())\r
-               {\r
-                       if (IsWndHorV())\r
-                               pSH->SetCursor(FXCT_VBEAM);\r
-                       else\r
-                               pSH->SetCursor(FXCT_HBEAM);\r
-               }\r
-       }\r
-}\r
-\r
-void CPWL_EditCtrl::RePosChildWnd()\r
-{\r
-       m_pEdit->SetPlateRect(GetClientRect());\r
-}\r
-\r
-void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)\r
-{\r
-       CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);\r
-\r
-       switch (msg)\r
-       {\r
-               case PNM_SETSCROLLINFO:\r
-                       switch (wParam)\r
-                       {\r
-                               case SBT_VSCROLL:\r
-                                       if (CPWL_Wnd * pChild = GetVScrollBar())\r
-                                       {\r
-                                               pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);\r
-                                       }\r
-                                       break;\r
-                       }\r
-                       break;\r
-               case PNM_SETSCROLLPOS:                  \r
-                       switch (wParam)\r
-                       {\r
-                               case SBT_VSCROLL:\r
-                                       if (CPWL_Wnd * pChild = GetVScrollBar())\r
-                                       {\r
-                                               pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);\r
-                                       }\r
-                                       break;\r
-                       }\r
-                       break;\r
-               case PNM_SCROLLWINDOW:\r
-                       {\r
-                               FX_FLOAT fPos = *(FX_FLOAT*)lParam;\r
-                               switch (wParam)\r
-                               {\r
-                                       case SBT_VSCROLL:\r
-                                               m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x,fPos));\r
-                                               break;\r
-                               }\r
-                       }\r
-                       break;\r
-               case PNM_SETCARETINFO:\r
-                       {\r
-                               if (PWL_CARET_INFO * pCaretInfo = (PWL_CARET_INFO *)wParam)\r
-                               {\r
-                                       this->SetCaret(pCaretInfo->bVisible,\r
-                                               pCaretInfo->ptHead,\r
-                                               pCaretInfo->ptFoot);                                    \r
-                               }\r
-                       }\r
-                       break;\r
-       }\r
-}\r
-\r
-void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM & cp)\r
-{\r
-       if (!IsReadOnly())\r
-               CreateEditCaret(cp);\r
-}\r
-\r
-void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM & cp)\r
-{\r
-       if (!m_pEditCaret)\r
-       {\r
-               m_pEditCaret = new CPWL_Caret;  \r
-               m_pEditCaret->SetInvalidRect(GetClientRect());\r
-\r
-               PWL_CREATEPARAM ecp = cp;\r
-               ecp.pParentWnd = this;\r
-               ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;\r
-               ecp.dwBorderWidth = 0;\r
-               ecp.nBorderStyle = PBS_SOLID;\r
-               ecp.rcRectWnd = CPDF_Rect(0,0,0,0);\r
-\r
-               m_pEditCaret->Create(ecp);\r
-       }\r
-}\r
-\r
-void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize)\r
-{\r
-       m_pEdit->SetFontSize(fFontSize);\r
-}\r
-\r
-FX_FLOAT CPWL_EditCtrl::GetFontSize() const\r
-{\r
-       return m_pEdit->GetFontSize();\r
-}\r
-\r
-FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)\r
-{\r
-       if (m_bMouseDown) return TRUE;\r
-\r
-       FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar,nFlag);\r
-\r
-       //FILTER\r
-       switch (nChar)\r
-       {\r
-       default:\r
-               return FALSE;\r
-       case FWL_VKEY_Delete:\r
-       case FWL_VKEY_Up:\r
-       case FWL_VKEY_Down:\r
-       case FWL_VKEY_Left:\r
-       case FWL_VKEY_Right:\r
-       case FWL_VKEY_Home:\r
-       case FWL_VKEY_End:\r
-       case FWL_VKEY_Insert:\r
-       case 'C':\r
-       case 'V':\r
-       case 'X':\r
-       case 'A':\r
-       case 'Z':\r
-       case 'c':\r
-       case 'v':\r
-       case 'x':\r
-       case 'a':\r
-       case 'z':\r
-               break;\r
-       }\r
-\r
-       if (nChar == FWL_VKEY_Delete)\r
-       {\r
-               if (m_pEdit->IsSelected())\r
-                       nChar = FWL_VKEY_Unknown;\r
-       }\r
-\r
-       switch (nChar)\r
-       {\r
-               case FWL_VKEY_Delete:   \r
-                       Delete();\r
-                       return TRUE;\r
-               case FWL_VKEY_Insert:\r
-                       if (IsSHIFTpressed(nFlag))\r
-                               PasteText();\r
-                       return TRUE;\r
-               case FWL_VKEY_Up:\r
-                       m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag),FALSE);\r
-                       return TRUE;\r
-               case FWL_VKEY_Down:\r
-                       m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag),FALSE);\r
-                       return TRUE;\r
-               case FWL_VKEY_Left:\r
-                       m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag),FALSE);\r
-                       return TRUE;\r
-               case FWL_VKEY_Right:\r
-                       m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag),FALSE);\r
-                       return TRUE;\r
-               case FWL_VKEY_Home:\r
-                       m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));\r
-                       return TRUE;\r
-               case FWL_VKEY_End:\r
-                       m_pEdit->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));\r
-                       return TRUE;\r
-               case FWL_VKEY_Unknown:\r
-                       if (!IsSHIFTpressed(nFlag))\r
-                               Clear();\r
-                       else\r
-                               CutText();\r
-                       return TRUE;\r
-               default:\r
-                       break;\r
-       }\r
-       \r
-       return bRet;\r
-}\r
-\r
-FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag)\r
-{\r
-       if (m_bMouseDown) return TRUE;\r
-\r
-       CPWL_Wnd::OnChar(nChar,nFlag);\r
-\r
-       //FILTER\r
-       switch (nChar)\r
-       {\r
-               case 0x0A:\r
-               case 0x1B:\r
-                       return FALSE;           \r
-               default:\r
-                       break;\r
-       }\r
-\r
-       FX_BOOL bCtrl = IsCTRLpressed(nFlag);\r
-       FX_BOOL bAlt = IsALTpressed(nFlag);\r
-       FX_BOOL bShift = IsSHIFTpressed(nFlag);\r
-\r
-       FX_WORD word = nChar;\r
-\r
-       if (bCtrl && !bAlt)\r
-       {\r
-               switch (nChar)\r
-               {\r
-                       case 'C' - 'A' + 1:\r
-                               this->CopyText();\r
-                               return TRUE;\r
-                       case 'V' - 'A' + 1:\r
-                               this->PasteText();\r
-                               return TRUE;\r
-                       case 'X' - 'A' + 1:\r
-                               this->CutText();\r
-                               return TRUE;\r
-                       case 'A' - 'A' + 1:\r
-                               this->SelectAll();\r
-                               return TRUE;\r
-                       case 'Z' - 'A' + 1:\r
-                               if (bShift)\r
-                                       Redo();\r
-                               else\r
-                                       Undo();\r
-                               return TRUE;\r
-                       default:\r
-                               if (nChar < 32)\r
-                                       return FALSE;\r
-               }\r
-       }\r
-\r
-       if (IsReadOnly()) return TRUE;\r
-\r
-       if (m_pEdit->IsSelected() && word ==  FWL_VKEY_Back)\r
-               word = FWL_VKEY_Unknown;\r
-\r
-       Clear();\r
-\r
-       switch (word)\r
-       {\r
-       case FWL_VKEY_Back:\r
-               Backspace();\r
-               break;\r
-       case FWL_VKEY_Return:   \r
-               InsertReturn();\r
-               break;\r
-       case FWL_VKEY_Unknown:\r
-               break;\r
-       default:\r
-               if (IsINSERTpressed(nFlag))\r
-                       Delete();\r
-               InsertWord(word, this->GetCharSet());\r
-               break;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)\r
-{\r
-       CPWL_Wnd::OnLButtonDown(point,nFlag);\r
-\r
-       if (ClientHitTest(point))\r
-       {               \r
-               if (m_bMouseDown)\r
-                       this->InvalidateRect();\r
-\r
-               m_bMouseDown = TRUE;            \r
-               SetCapture();\r
-\r
-               m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)\r
-{\r
-       CPWL_Wnd::OnLButtonUp(point,nFlag);\r
-\r
-       if (m_bMouseDown)\r
-       {\r
-               //can receive keybord message\r
-               if (ClientHitTest(point) && !this->IsFocused())\r
-                       SetFocus();     \r
-\r
-               ReleaseCapture();\r
-               m_bMouseDown = FALSE;\r
-       }\r
-\r
-       return TRUE;\r
-}\r
-\r
-FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)\r
-{\r
-       CPWL_Wnd::OnMouseMove(point,nFlag);\r
-\r
-       if (m_bMouseDown)\r
-               m_pEdit->OnMouseMove(point,FALSE,FALSE);\r
-\r
-       return TRUE;\r
-}\r
-\r
-CPDF_Rect CPWL_EditCtrl::GetContentRect() const\r
-{\r
-       return m_pEdit->GetContentRect();\r
-}\r
-\r
-void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible)\r
-{\r
-       CPDF_Point ptHead(0,0),ptFoot(0,0);\r
-\r
-       if (bVisible)\r
-       {\r
-               GetCaretInfo(ptHead,ptFoot);\r
-       }\r
-\r
-       CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();\r
-       this->IOnSetCaret(bVisible,ptHead,ptFoot,wpTemp);\r
-}\r
-\r
-void CPWL_EditCtrl::GetCaretInfo(CPDF_Point & ptHead, CPDF_Point & ptFoot) const\r
-{\r
-       if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())\r
-       {\r
-               pIterator->SetAt(m_pEdit->GetCaret());\r
-               CPVT_Word word;\r
-               CPVT_Line line;\r
-               if (pIterator->GetWord(word))\r
-               {\r
-                       ptHead.x = word.ptWord.x + word.fWidth;\r
-                       ptHead.y = word.ptWord.y + word.fAscent;\r
-                       ptFoot.x = word.ptWord.x + word.fWidth;\r
-                       ptFoot.y = word.ptWord.y + word.fDescent;\r
-               }\r
-               else if (pIterator->GetLine(line))\r
-               {                               \r
-                       ptHead.x = line.ptLine.x;\r
-                       ptHead.y = line.ptLine.y + line.fLineAscent;\r
-                       ptFoot.x = line.ptLine.x;\r
-                       ptFoot.y = line.ptLine.y + line.fLineDescent;\r
-               }\r
-       }\r
-}\r
-\r
-void CPWL_EditCtrl::GetCaretPos(FX_INT32& x, FX_INT32& y) const\r
-{\r
-       CPDF_Point ptHead(0,0), ptFoot(0,0);\r
-\r
-       GetCaretInfo(ptHead,ptFoot);\r
-\r
-       PWLtoWnd(ptHead, x, y);\r
-}\r
-\r
-void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)\r
-{\r
-       if (m_pEditCaret)\r
-       {\r
-               if (!IsFocused() || m_pEdit->IsSelected())\r
-                       bVisible = FALSE;\r
-\r
-               m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);\r
-       }\r
-}\r
-\r
-FX_BOOL        CPWL_EditCtrl::IsModified() const\r
-{\r
-       return m_pEdit->IsModified();\r
-}\r
-\r
-CFX_WideString CPWL_EditCtrl::GetText() const\r
-{\r
-       return m_pEdit->GetText();\r
-}\r
-\r
-void CPWL_EditCtrl::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)\r
-{\r
-       m_pEdit->SetSel(nStartChar, nEndChar);\r
-}\r
-\r
-void CPWL_EditCtrl::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar ) const\r
-{\r
-       m_pEdit->GetSel(nStartChar, nEndChar);\r
-}\r
-\r
-void CPWL_EditCtrl::Clear()\r
-{\r
-       if (!IsReadOnly())\r
-               m_pEdit->Clear();\r
-}\r
-\r
-void CPWL_EditCtrl::SelectAll()\r
-{\r
-       m_pEdit->SelectAll();\r
-}\r
-\r
-void CPWL_EditCtrl::Paint()\r
-{\r
-       if (m_pEdit)\r
-               m_pEdit->Paint();\r
-}\r
-\r
-void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh)\r
-{\r
-       if (m_pEdit)\r
-               m_pEdit->EnableRefresh(bRefresh);\r
-}\r
-\r
-FX_INT32 CPWL_EditCtrl::GetCaret() const\r
-{\r
-       if (m_pEdit)\r
-               return m_pEdit->GetCaret();\r
-\r
-       return -1;\r
-}\r
-\r
-void CPWL_EditCtrl::SetCaret(FX_INT32 nPos)\r
-{\r
-       if (m_pEdit)\r
-               m_pEdit->SetCaret(nPos);\r
-}\r
-\r
-FX_INT32 CPWL_EditCtrl::GetTotalWords() const\r
-{\r
-       if (m_pEdit)\r
-               return m_pEdit->GetTotalWords();\r
-\r
-       return 0;\r
-}\r
-\r
-void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point)\r
-{\r
-       if (m_pEdit)\r
-               m_pEdit->SetScrollPos(point);\r
-}\r
-\r
-CPDF_Point CPWL_EditCtrl::GetScrollPos() const\r
-{\r
-       if (m_pEdit)\r
-               return m_pEdit->GetScrollPos();\r
-\r
-       return CPDF_Point(0.0f, 0.0f);\r
-}\r
-\r
-CPDF_Font * CPWL_EditCtrl::GetCaretFont() const\r
-{\r
-       FX_INT32 nFontIndex = 0;\r
-\r
-       if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())\r
-       {\r
-               pIterator->SetAt(m_pEdit->GetCaret());\r
-               CPVT_Word word;\r
-               CPVT_Section section;\r
-               if (pIterator->GetWord(word))\r
-               {\r
-                       nFontIndex = word.nFontIndex;\r
-               }\r
-               else if (HasFlag(PES_RICH))\r
-               {\r
-                       if (pIterator->GetSection(section))\r
-                       {                               \r
-                               nFontIndex = section.WordProps.nFontIndex;\r
-                       }\r
-               }\r
-       }\r
-\r
-       if (IFX_Edit_FontMap * pFontMap = GetFontMap())\r
-               return pFontMap->GetPDFFont(nFontIndex);\r
-       else\r
-               return NULL;\r
-}\r
-\r
-FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const\r
-{\r
-       FX_FLOAT fFontSize = GetFontSize();\r
-\r
-       if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())\r
-       {\r
-               pIterator->SetAt(m_pEdit->GetCaret());\r
-               CPVT_Word word;\r
-               CPVT_Section section;\r
-               if (pIterator->GetWord(word))\r
-               {\r
-                       fFontSize = word.fFontSize;\r
-               }\r
-               else if (HasFlag(PES_RICH))\r
-               {\r
-                       if (pIterator->GetSection(section))\r
-                       {                               \r
-                               fFontSize = section.WordProps.fFontSize;\r
-                       }\r
-               }\r
-       }\r
-\r
-       return fFontSize;\r
-}\r
-\r
-void CPWL_EditCtrl::SetText(FX_LPCWSTR csText)\r
-{\r
-       m_pEdit->SetText(csText);\r
-}\r
-\r
-void CPWL_EditCtrl::CopyText()\r
-{\r
-}\r
-\r
-void CPWL_EditCtrl::PasteText()\r
-{\r
-}\r
-\r
-void CPWL_EditCtrl::CutText()\r
-{\r
-}\r
-\r
-void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow)\r
-{\r
-}\r
-\r
-void CPWL_EditCtrl::InsertText(FX_LPCWSTR csText)\r
-{\r
-       if (!IsReadOnly())\r
-               m_pEdit->InsertText(csText);\r
-}\r
-\r
-void CPWL_EditCtrl::InsertWord(FX_WORD word, FX_INT32 nCharset)\r
-{\r
-       if (!IsReadOnly())\r
-               m_pEdit->InsertWord(word, nCharset);\r
-}\r
-\r
-void CPWL_EditCtrl::InsertReturn()\r
-{\r
-       if (!IsReadOnly())\r
-               m_pEdit->InsertReturn();\r
-}\r
-\r
-void CPWL_EditCtrl::Delete()\r
-{\r
-       if (!IsReadOnly())\r
-               m_pEdit->Delete();\r
-}\r
-\r
-void CPWL_EditCtrl::Backspace()\r
-{\r
-       if (!IsReadOnly())\r
-               m_pEdit->Backspace();\r
-}\r
-\r
-FX_BOOL        CPWL_EditCtrl::CanUndo() const\r
-{\r
-       return !IsReadOnly() && m_pEdit->CanUndo();\r
-}\r
-\r
-FX_BOOL        CPWL_EditCtrl::CanRedo() const\r
-{\r
-       return !IsReadOnly() && m_pEdit->CanRedo();\r
-}\r
-\r
-void CPWL_EditCtrl::Redo()\r
-{\r
-       if (CanRedo())\r
-               m_pEdit->Redo();\r
-}\r
-\r
-void CPWL_EditCtrl::Undo()\r
-{\r
-       if (CanUndo())\r
-               m_pEdit->Undo();\r
-}\r
-\r
-void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax, \r
-                                                                                               FX_FLOAT fContentMin, FX_FLOAT fContentMax, \r
-                                                                                               FX_FLOAT fSmallStep, FX_FLOAT fBigStep)\r
-{\r
-       PWL_SCROLL_INFO Info;\r
-\r
-       Info.fPlateWidth = fPlateMax - fPlateMin;\r
-       Info.fContentMin = fContentMin;\r
-       Info.fContentMax = fContentMax;\r
-       Info.fSmallStep = fSmallStep;\r
-       Info.fBigStep = fBigStep;\r
-\r
-       this->OnNotify(this,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);\r
-\r
-//     PWL_TRACE("set scroll info:%f\n",fContentMax - fContentMin);\r
-\r
-       if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)\r
-               || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))\r
-       {\r
-               this->ShowVScrollBar(FALSE);            \r
-       }\r
-       else\r
-       {\r
-               this->ShowVScrollBar(TRUE);\r
-       }\r
-}\r
-\r
-void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy)\r
-{\r
-//     PWL_TRACE("set scroll position:%f\n",fy);\r
-       this->OnNotify(this,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);\r
-}\r
-\r
-void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot, const CPVT_WordPlace& place)\r
-{\r
-       PWL_CARET_INFO cInfo;\r
-       cInfo.bVisible = bVisible;\r
-       cInfo.ptHead = ptHead;\r
-       cInfo.ptFoot = ptFoot;\r
-\r
-       this->OnNotify(this,PNM_SETCARETINFO,(FX_INTPTR)&cInfo,(FX_INTPTR)NULL);\r
-}\r
-\r
-void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps & secProps, const CPVT_WordProps & wordProps)\r
-{\r
-}\r
-\r
-void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent)\r
-{\r
-       if (this->IsValid())\r
-       {\r
-               if (m_pEditNotify)\r
-               {\r
-                       m_pEditNotify->OnContentChange(rcContent);\r
-               }\r
-       }\r
-}\r
-\r
-void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect * pRect)\r
-{\r
-       this->InvalidateRect(pRect);\r
-}\r
-\r
-FX_INT32 CPWL_EditCtrl::GetCharSet() const\r
-{\r
-       if (m_nCharSet < 0)\r
-               return DEFAULT_CHARSET; \r
-       else\r
-               return m_nCharSet;\r
-}\r
-\r
-void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect, FX_INT32 & nStartChar, FX_INT32 & nEndChar) const\r
-{\r
-       nStartChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top)));\r
-       nEndChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom)));\r
-}\r
-\r
-CFX_WideString CPWL_EditCtrl::GetText(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const\r
-{\r
-       CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);\r
-       CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);\r
-       return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));\r
-}\r
-\r
-void   CPWL_EditCtrl::SetReadyToInput()\r
-{\r
-       if (m_bMouseDown)\r
-       {\r
-               ReleaseCapture();\r
-               m_bMouseDown = FALSE;\r
-       }\r
-}\r
+// 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 "../../include/pdfwindow/PDFWindow.h"
+#include "../../include/pdfwindow/PWL_Wnd.h"
+#include "../../include/pdfwindow/PWL_EditCtrl.h"
+#include "../../include/pdfwindow/PWL_ScrollBar.h"
+#include "../../include/pdfwindow/PWL_Utils.h"
+#include "../../include/pdfwindow/PWL_Caret.h"
+#include "../../include/pdfwindow/PWL_FontMap.h"
+
+#define IsFloatZero(f)                                         ((f) < 0.0001 && (f) > -0.0001)
+#define IsFloatBigger(fa,fb)                           ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatSmaller(fa,fb)                          ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
+#define IsFloatEqual(fa,fb)                                    IsFloatZero((fa)-(fb))
+
+/* ---------------------------- CPWL_EditCtrl ------------------------------ */
+
+CPWL_EditCtrl::CPWL_EditCtrl() :
+       m_pEdit(NULL),
+       m_pEditCaret(NULL),
+       m_bMouseDown(FALSE),
+       m_pEditNotify(NULL),
+       m_nCharSet(DEFAULT_CHARSET),
+       m_nCodePage(0)
+{
+       m_pEdit = IFX_Edit::NewEdit();
+       ASSERT(m_pEdit != NULL);
+}
+
+CPWL_EditCtrl::~CPWL_EditCtrl()
+{
+       IFX_Edit::DelEdit(m_pEdit);
+}
+
+void CPWL_EditCtrl::OnCreate(PWL_CREATEPARAM & cp)
+{
+       cp.eCursorType = FXCT_VBEAM;
+}
+
+void CPWL_EditCtrl::OnCreated()
+{
+       SetFontSize(this->GetCreationParam().fFontSize);
+
+       m_pEdit->SetFontMap(this->GetFontMap());
+       m_pEdit->SetNotify(this);
+       m_pEdit->Initialize();
+}
+
+FX_BOOL CPWL_EditCtrl::IsWndHorV()
+{
+       CPDF_Matrix mt = GetWindowMatrix();
+       CPDF_Point point1(0,1);
+       CPDF_Point point2(1,1);
+
+       mt.Transform(point1.x, point1.y);
+       mt.Transform(point2.x, point2.y);
+
+       return point2.y == point1.y;
+}
+
+void CPWL_EditCtrl::SetCursor()
+{
+       if (IsValid()) 
+       {
+               if (IFX_SystemHandler* pSH = GetSystemHandler())
+               {
+                       if (IsWndHorV())
+                               pSH->SetCursor(FXCT_VBEAM);
+                       else
+                               pSH->SetCursor(FXCT_HBEAM);
+               }
+       }
+}
+
+void CPWL_EditCtrl::RePosChildWnd()
+{
+       m_pEdit->SetPlateRect(GetClientRect());
+}
+
+void CPWL_EditCtrl::OnNotify(CPWL_Wnd* pWnd, FX_DWORD msg, FX_INTPTR wParam, FX_INTPTR lParam)
+{
+       CPWL_Wnd::OnNotify(pWnd,msg,wParam,lParam);
+
+       switch (msg)
+       {
+               case PNM_SETSCROLLINFO:
+                       switch (wParam)
+                       {
+                               case SBT_VSCROLL:
+                                       if (CPWL_Wnd * pChild = GetVScrollBar())
+                                       {
+                                               pChild->OnNotify(pWnd,PNM_SETSCROLLINFO,wParam,lParam);
+                                       }
+                                       break;
+                       }
+                       break;
+               case PNM_SETSCROLLPOS:                  
+                       switch (wParam)
+                       {
+                               case SBT_VSCROLL:
+                                       if (CPWL_Wnd * pChild = GetVScrollBar())
+                                       {
+                                               pChild->OnNotify(pWnd,PNM_SETSCROLLPOS,wParam,lParam);
+                                       }
+                                       break;
+                       }
+                       break;
+               case PNM_SCROLLWINDOW:
+                       {
+                               FX_FLOAT fPos = *(FX_FLOAT*)lParam;
+                               switch (wParam)
+                               {
+                                       case SBT_VSCROLL:
+                                               m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x,fPos));
+                                               break;
+                               }
+                       }
+                       break;
+               case PNM_SETCARETINFO:
+                       {
+                               if (PWL_CARET_INFO * pCaretInfo = (PWL_CARET_INFO *)wParam)
+                               {
+                                       this->SetCaret(pCaretInfo->bVisible,
+                                               pCaretInfo->ptHead,
+                                               pCaretInfo->ptFoot);                                    
+                               }
+                       }
+                       break;
+       }
+}
+
+void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM & cp)
+{
+       if (!IsReadOnly())
+               CreateEditCaret(cp);
+}
+
+void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM & cp)
+{
+       if (!m_pEditCaret)
+       {
+               m_pEditCaret = new CPWL_Caret;  
+               m_pEditCaret->SetInvalidRect(GetClientRect());
+
+               PWL_CREATEPARAM ecp = cp;
+               ecp.pParentWnd = this;
+               ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
+               ecp.dwBorderWidth = 0;
+               ecp.nBorderStyle = PBS_SOLID;
+               ecp.rcRectWnd = CPDF_Rect(0,0,0,0);
+
+               m_pEditCaret->Create(ecp);
+       }
+}
+
+void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize)
+{
+       m_pEdit->SetFontSize(fFontSize);
+}
+
+FX_FLOAT CPWL_EditCtrl::GetFontSize() const
+{
+       return m_pEdit->GetFontSize();
+}
+
+FX_BOOL CPWL_EditCtrl::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag)
+{
+       if (m_bMouseDown) return TRUE;
+
+       FX_BOOL bRet = CPWL_Wnd::OnKeyDown(nChar,nFlag);
+
+       //FILTER
+       switch (nChar)
+       {
+       default:
+               return FALSE;
+       case FWL_VKEY_Delete:
+       case FWL_VKEY_Up:
+       case FWL_VKEY_Down:
+       case FWL_VKEY_Left:
+       case FWL_VKEY_Right:
+       case FWL_VKEY_Home:
+       case FWL_VKEY_End:
+       case FWL_VKEY_Insert:
+       case 'C':
+       case 'V':
+       case 'X':
+       case 'A':
+       case 'Z':
+       case 'c':
+       case 'v':
+       case 'x':
+       case 'a':
+       case 'z':
+               break;
+       }
+
+       if (nChar == FWL_VKEY_Delete)
+       {
+               if (m_pEdit->IsSelected())
+                       nChar = FWL_VKEY_Unknown;
+       }
+
+       switch (nChar)
+       {
+               case FWL_VKEY_Delete:   
+                       Delete();
+                       return TRUE;
+               case FWL_VKEY_Insert:
+                       if (IsSHIFTpressed(nFlag))
+                               PasteText();
+                       return TRUE;
+               case FWL_VKEY_Up:
+                       m_pEdit->OnVK_UP(IsSHIFTpressed(nFlag),FALSE);
+                       return TRUE;
+               case FWL_VKEY_Down:
+                       m_pEdit->OnVK_DOWN(IsSHIFTpressed(nFlag),FALSE);
+                       return TRUE;
+               case FWL_VKEY_Left:
+                       m_pEdit->OnVK_LEFT(IsSHIFTpressed(nFlag),FALSE);
+                       return TRUE;
+               case FWL_VKEY_Right:
+                       m_pEdit->OnVK_RIGHT(IsSHIFTpressed(nFlag),FALSE);
+                       return TRUE;
+               case FWL_VKEY_Home:
+                       m_pEdit->OnVK_HOME(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+                       return TRUE;
+               case FWL_VKEY_End:
+                       m_pEdit->OnVK_END(IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+                       return TRUE;
+               case FWL_VKEY_Unknown:
+                       if (!IsSHIFTpressed(nFlag))
+                               Clear();
+                       else
+                               CutText();
+                       return TRUE;
+               default:
+                       break;
+       }
+       
+       return bRet;
+}
+
+FX_BOOL CPWL_EditCtrl::OnChar(FX_WORD nChar, FX_DWORD nFlag)
+{
+       if (m_bMouseDown) return TRUE;
+
+       CPWL_Wnd::OnChar(nChar,nFlag);
+
+       //FILTER
+       switch (nChar)
+       {
+               case 0x0A:
+               case 0x1B:
+                       return FALSE;           
+               default:
+                       break;
+       }
+
+       FX_BOOL bCtrl = IsCTRLpressed(nFlag);
+       FX_BOOL bAlt = IsALTpressed(nFlag);
+       FX_BOOL bShift = IsSHIFTpressed(nFlag);
+
+       FX_WORD word = nChar;
+
+       if (bCtrl && !bAlt)
+       {
+               switch (nChar)
+               {
+                       case 'C' - 'A' + 1:
+                               this->CopyText();
+                               return TRUE;
+                       case 'V' - 'A' + 1:
+                               this->PasteText();
+                               return TRUE;
+                       case 'X' - 'A' + 1:
+                               this->CutText();
+                               return TRUE;
+                       case 'A' - 'A' + 1:
+                               this->SelectAll();
+                               return TRUE;
+                       case 'Z' - 'A' + 1:
+                               if (bShift)
+                                       Redo();
+                               else
+                                       Undo();
+                               return TRUE;
+                       default:
+                               if (nChar < 32)
+                                       return FALSE;
+               }
+       }
+
+       if (IsReadOnly()) return TRUE;
+
+       if (m_pEdit->IsSelected() && word ==  FWL_VKEY_Back)
+               word = FWL_VKEY_Unknown;
+
+       Clear();
+
+       switch (word)
+       {
+       case FWL_VKEY_Back:
+               Backspace();
+               break;
+       case FWL_VKEY_Return:   
+               InsertReturn();
+               break;
+       case FWL_VKEY_Unknown:
+               break;
+       default:
+               if (IsINSERTpressed(nFlag))
+                       Delete();
+               InsertWord(word, this->GetCharSet());
+               break;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag)
+{
+       CPWL_Wnd::OnLButtonDown(point,nFlag);
+
+       if (ClientHitTest(point))
+       {               
+               if (m_bMouseDown)
+                       this->InvalidateRect();
+
+               m_bMouseDown = TRUE;            
+               SetCapture();
+
+               m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(nFlag));
+       }
+
+       return TRUE;
+}
+
+FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point & point, FX_DWORD nFlag)
+{
+       CPWL_Wnd::OnLButtonUp(point,nFlag);
+
+       if (m_bMouseDown)
+       {
+               //can receive keybord message
+               if (ClientHitTest(point) && !this->IsFocused())
+                       SetFocus();     
+
+               ReleaseCapture();
+               m_bMouseDown = FALSE;
+       }
+
+       return TRUE;
+}
+
+FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point & point, FX_DWORD nFlag)
+{
+       CPWL_Wnd::OnMouseMove(point,nFlag);
+
+       if (m_bMouseDown)
+               m_pEdit->OnMouseMove(point,FALSE,FALSE);
+
+       return TRUE;
+}
+
+CPDF_Rect CPWL_EditCtrl::GetContentRect() const
+{
+       return m_pEdit->GetContentRect();
+}
+
+void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible)
+{
+       CPDF_Point ptHead(0,0),ptFoot(0,0);
+
+       if (bVisible)
+       {
+               GetCaretInfo(ptHead,ptFoot);
+       }
+
+       CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
+       this->IOnSetCaret(bVisible,ptHead,ptFoot,wpTemp);
+}
+
+void CPWL_EditCtrl::GetCaretInfo(CPDF_Point & ptHead, CPDF_Point & ptFoot) const
+{
+       if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+       {
+               pIterator->SetAt(m_pEdit->GetCaret());
+               CPVT_Word word;
+               CPVT_Line line;
+               if (pIterator->GetWord(word))
+               {
+                       ptHead.x = word.ptWord.x + word.fWidth;
+                       ptHead.y = word.ptWord.y + word.fAscent;
+                       ptFoot.x = word.ptWord.x + word.fWidth;
+                       ptFoot.y = word.ptWord.y + word.fDescent;
+               }
+               else if (pIterator->GetLine(line))
+               {                               
+                       ptHead.x = line.ptLine.x;
+                       ptHead.y = line.ptLine.y + line.fLineAscent;
+                       ptFoot.x = line.ptLine.x;
+                       ptFoot.y = line.ptLine.y + line.fLineDescent;
+               }
+       }
+}
+
+void CPWL_EditCtrl::GetCaretPos(FX_INT32& x, FX_INT32& y) const
+{
+       CPDF_Point ptHead(0,0), ptFoot(0,0);
+
+       GetCaretInfo(ptHead,ptFoot);
+
+       PWLtoWnd(ptHead, x, y);
+}
+
+void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot)
+{
+       if (m_pEditCaret)
+       {
+               if (!IsFocused() || m_pEdit->IsSelected())
+                       bVisible = FALSE;
+
+               m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
+       }
+}
+
+FX_BOOL        CPWL_EditCtrl::IsModified() const
+{
+       return m_pEdit->IsModified();
+}
+
+CFX_WideString CPWL_EditCtrl::GetText() const
+{
+       return m_pEdit->GetText();
+}
+
+void CPWL_EditCtrl::SetSel(FX_INT32 nStartChar,FX_INT32 nEndChar)
+{
+       m_pEdit->SetSel(nStartChar, nEndChar);
+}
+
+void CPWL_EditCtrl::GetSel(FX_INT32 & nStartChar, FX_INT32 & nEndChar ) const
+{
+       m_pEdit->GetSel(nStartChar, nEndChar);
+}
+
+void CPWL_EditCtrl::Clear()
+{
+       if (!IsReadOnly())
+               m_pEdit->Clear();
+}
+
+void CPWL_EditCtrl::SelectAll()
+{
+       m_pEdit->SelectAll();
+}
+
+void CPWL_EditCtrl::Paint()
+{
+       if (m_pEdit)
+               m_pEdit->Paint();
+}
+
+void CPWL_EditCtrl::EnableRefresh(FX_BOOL bRefresh)
+{
+       if (m_pEdit)
+               m_pEdit->EnableRefresh(bRefresh);
+}
+
+FX_INT32 CPWL_EditCtrl::GetCaret() const
+{
+       if (m_pEdit)
+               return m_pEdit->GetCaret();
+
+       return -1;
+}
+
+void CPWL_EditCtrl::SetCaret(FX_INT32 nPos)
+{
+       if (m_pEdit)
+               m_pEdit->SetCaret(nPos);
+}
+
+FX_INT32 CPWL_EditCtrl::GetTotalWords() const
+{
+       if (m_pEdit)
+               return m_pEdit->GetTotalWords();
+
+       return 0;
+}
+
+void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point)
+{
+       if (m_pEdit)
+               m_pEdit->SetScrollPos(point);
+}
+
+CPDF_Point CPWL_EditCtrl::GetScrollPos() const
+{
+       if (m_pEdit)
+               return m_pEdit->GetScrollPos();
+
+       return CPDF_Point(0.0f, 0.0f);
+}
+
+CPDF_Font * CPWL_EditCtrl::GetCaretFont() const
+{
+       FX_INT32 nFontIndex = 0;
+
+       if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+       {
+               pIterator->SetAt(m_pEdit->GetCaret());
+               CPVT_Word word;
+               CPVT_Section section;
+               if (pIterator->GetWord(word))
+               {
+                       nFontIndex = word.nFontIndex;
+               }
+               else if (HasFlag(PES_RICH))
+               {
+                       if (pIterator->GetSection(section))
+                       {                               
+                               nFontIndex = section.WordProps.nFontIndex;
+                       }
+               }
+       }
+
+       if (IFX_Edit_FontMap * pFontMap = GetFontMap())
+               return pFontMap->GetPDFFont(nFontIndex);
+       else
+               return NULL;
+}
+
+FX_FLOAT CPWL_EditCtrl::GetCaretFontSize() const
+{
+       FX_FLOAT fFontSize = GetFontSize();
+
+       if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator())
+       {
+               pIterator->SetAt(m_pEdit->GetCaret());
+               CPVT_Word word;
+               CPVT_Section section;
+               if (pIterator->GetWord(word))
+               {
+                       fFontSize = word.fFontSize;
+               }
+               else if (HasFlag(PES_RICH))
+               {
+                       if (pIterator->GetSection(section))
+                       {                               
+                               fFontSize = section.WordProps.fFontSize;
+                       }
+               }
+       }
+
+       return fFontSize;
+}
+
+void CPWL_EditCtrl::SetText(FX_LPCWSTR csText)
+{
+       m_pEdit->SetText(csText);
+}
+
+void CPWL_EditCtrl::CopyText()
+{
+}
+
+void CPWL_EditCtrl::PasteText()
+{
+}
+
+void CPWL_EditCtrl::CutText()
+{
+}
+
+void CPWL_EditCtrl::ShowVScrollBar(FX_BOOL bShow)
+{
+}
+
+void CPWL_EditCtrl::InsertText(FX_LPCWSTR csText)
+{
+       if (!IsReadOnly())
+               m_pEdit->InsertText(csText);
+}
+
+void CPWL_EditCtrl::InsertWord(FX_WORD word, FX_INT32 nCharset)
+{
+       if (!IsReadOnly())
+               m_pEdit->InsertWord(word, nCharset);
+}
+
+void CPWL_EditCtrl::InsertReturn()
+{
+       if (!IsReadOnly())
+               m_pEdit->InsertReturn();
+}
+
+void CPWL_EditCtrl::Delete()
+{
+       if (!IsReadOnly())
+               m_pEdit->Delete();
+}
+
+void CPWL_EditCtrl::Backspace()
+{
+       if (!IsReadOnly())
+               m_pEdit->Backspace();
+}
+
+FX_BOOL        CPWL_EditCtrl::CanUndo() const
+{
+       return !IsReadOnly() && m_pEdit->CanUndo();
+}
+
+FX_BOOL        CPWL_EditCtrl::CanRedo() const
+{
+       return !IsReadOnly() && m_pEdit->CanRedo();
+}
+
+void CPWL_EditCtrl::Redo()
+{
+       if (CanRedo())
+               m_pEdit->Redo();
+}
+
+void CPWL_EditCtrl::Undo()
+{
+       if (CanUndo())
+               m_pEdit->Undo();
+}
+
+void CPWL_EditCtrl::IOnSetScrollInfoY(FX_FLOAT fPlateMin, FX_FLOAT fPlateMax, 
+                                                                                               FX_FLOAT fContentMin, FX_FLOAT fContentMax, 
+                                                                                               FX_FLOAT fSmallStep, FX_FLOAT fBigStep)
+{
+       PWL_SCROLL_INFO Info;
+
+       Info.fPlateWidth = fPlateMax - fPlateMin;
+       Info.fContentMin = fContentMin;
+       Info.fContentMax = fContentMax;
+       Info.fSmallStep = fSmallStep;
+       Info.fBigStep = fBigStep;
+
+       this->OnNotify(this,PNM_SETSCROLLINFO,SBT_VSCROLL,(FX_INTPTR)&Info);
+
+//     PWL_TRACE("set scroll info:%f\n",fContentMax - fContentMin);
+
+       if (IsFloatBigger(Info.fPlateWidth,Info.fContentMax-Info.fContentMin)
+               || IsFloatEqual(Info.fPlateWidth,Info.fContentMax-Info.fContentMin))
+       {
+               this->ShowVScrollBar(FALSE);            
+       }
+       else
+       {
+               this->ShowVScrollBar(TRUE);
+       }
+}
+
+void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy)
+{
+//     PWL_TRACE("set scroll position:%f\n",fy);
+       this->OnNotify(this,PNM_SETSCROLLPOS,SBT_VSCROLL,(FX_INTPTR)&fy);
+}
+
+void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, const CPDF_Point & ptHead, const CPDF_Point & ptFoot, const CPVT_WordPlace& place)
+{
+       PWL_CARET_INFO cInfo;
+       cInfo.bVisible = bVisible;
+       cInfo.ptHead = ptHead;
+       cInfo.ptFoot = ptFoot;
+
+       this->OnNotify(this,PNM_SETCARETINFO,(FX_INTPTR)&cInfo,(FX_INTPTR)NULL);
+}
+
+void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps & secProps, const CPVT_WordProps & wordProps)
+{
+}
+
+void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent)
+{
+       if (this->IsValid())
+       {
+               if (m_pEditNotify)
+               {
+                       m_pEditNotify->OnContentChange(rcContent);
+               }
+       }
+}
+
+void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect * pRect)
+{
+       this->InvalidateRect(pRect);
+}
+
+FX_INT32 CPWL_EditCtrl::GetCharSet() const
+{
+       if (m_nCharSet < 0)
+               return DEFAULT_CHARSET; 
+       else
+               return m_nCharSet;
+}
+
+void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect, FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
+{
+       nStartChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top)));
+       nEndChar = m_pEdit->WordPlaceToWordIndex(m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom)));
+}
+
+CFX_WideString CPWL_EditCtrl::GetText(FX_INT32 & nStartChar, FX_INT32 & nEndChar) const
+{
+       CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
+       CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
+       return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
+}
+
+void   CPWL_EditCtrl::SetReadyToInput()
+{
+       if (m_bMouseDown)
+       {
+               ReleaseCapture();
+               m_bMouseDown = FALSE;
+       }
+}