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