Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1217)

Side by Side Diff: fpdfsdk/src/pdfwindow/PWL_EditCtrl.cpp

Issue 1737593006: Re-land "Replace CPDF_Rect and CPDF_Point with CFX types." (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Ooops. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « fpdfsdk/src/pdfwindow/PWL_Edit.cpp ('k') | fpdfsdk/src/pdfwindow/PWL_Icon.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h" 7 #include "fpdfsdk/include/pdfwindow/PWL_EditCtrl.h"
8 8
9 #include "fpdfsdk/include/pdfwindow/PWL_Caret.h" 9 #include "fpdfsdk/include/pdfwindow/PWL_Caret.h"
10 #include "fpdfsdk/include/pdfwindow/PWL_FontMap.h" 10 #include "fpdfsdk/include/pdfwindow/PWL_FontMap.h"
(...skipping 29 matching lines...) Expand all
40 void CPWL_EditCtrl::OnCreated() { 40 void CPWL_EditCtrl::OnCreated() {
41 SetFontSize(GetCreationParam().fFontSize); 41 SetFontSize(GetCreationParam().fFontSize);
42 42
43 m_pEdit->SetFontMap(GetFontMap()); 43 m_pEdit->SetFontMap(GetFontMap());
44 m_pEdit->SetNotify(this); 44 m_pEdit->SetNotify(this);
45 m_pEdit->Initialize(); 45 m_pEdit->Initialize();
46 } 46 }
47 47
48 FX_BOOL CPWL_EditCtrl::IsWndHorV() { 48 FX_BOOL CPWL_EditCtrl::IsWndHorV() {
49 CFX_Matrix mt = GetWindowMatrix(); 49 CFX_Matrix mt = GetWindowMatrix();
50 CPDF_Point point1(0, 1); 50 CFX_FloatPoint point1(0, 1);
51 CPDF_Point point2(1, 1); 51 CFX_FloatPoint point2(1, 1);
52 52
53 mt.Transform(point1.x, point1.y); 53 mt.Transform(point1.x, point1.y);
54 mt.Transform(point2.x, point2.y); 54 mt.Transform(point2.x, point2.y);
55 55
56 return point2.y == point1.y; 56 return point2.y == point1.y;
57 } 57 }
58 58
59 void CPWL_EditCtrl::SetCursor() { 59 void CPWL_EditCtrl::SetCursor() {
60 if (IsValid()) { 60 if (IsValid()) {
61 if (IFX_SystemHandler* pSH = GetSystemHandler()) { 61 if (IFX_SystemHandler* pSH = GetSystemHandler()) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 if (CPWL_Wnd* pChild = GetVScrollBar()) { 93 if (CPWL_Wnd* pChild = GetVScrollBar()) {
94 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam); 94 pChild->OnNotify(pWnd, PNM_SETSCROLLPOS, wParam, lParam);
95 } 95 }
96 break; 96 break;
97 } 97 }
98 break; 98 break;
99 case PNM_SCROLLWINDOW: { 99 case PNM_SCROLLWINDOW: {
100 FX_FLOAT fPos = *(FX_FLOAT*)lParam; 100 FX_FLOAT fPos = *(FX_FLOAT*)lParam;
101 switch (wParam) { 101 switch (wParam) {
102 case SBT_VSCROLL: 102 case SBT_VSCROLL:
103 m_pEdit->SetScrollPos(CPDF_Point(m_pEdit->GetScrollPos().x, fPos)); 103 m_pEdit->SetScrollPos(
104 CFX_FloatPoint(m_pEdit->GetScrollPos().x, fPos));
104 break; 105 break;
105 } 106 }
106 } break; 107 } break;
107 case PNM_SETCARETINFO: { 108 case PNM_SETCARETINFO: {
108 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) { 109 if (PWL_CARET_INFO* pCaretInfo = (PWL_CARET_INFO*)wParam) {
109 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot); 110 SetCaret(pCaretInfo->bVisible, pCaretInfo->ptHead, pCaretInfo->ptFoot);
110 } 111 }
111 } break; 112 } break;
112 } 113 }
113 } 114 }
114 115
115 void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) { 116 void CPWL_EditCtrl::CreateChildWnd(const PWL_CREATEPARAM& cp) {
116 if (!IsReadOnly()) 117 if (!IsReadOnly())
117 CreateEditCaret(cp); 118 CreateEditCaret(cp);
118 } 119 }
119 120
120 void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) { 121 void CPWL_EditCtrl::CreateEditCaret(const PWL_CREATEPARAM& cp) {
121 if (!m_pEditCaret) { 122 if (!m_pEditCaret) {
122 m_pEditCaret = new CPWL_Caret; 123 m_pEditCaret = new CPWL_Caret;
123 m_pEditCaret->SetInvalidRect(GetClientRect()); 124 m_pEditCaret->SetInvalidRect(GetClientRect());
124 125
125 PWL_CREATEPARAM ecp = cp; 126 PWL_CREATEPARAM ecp = cp;
126 ecp.pParentWnd = this; 127 ecp.pParentWnd = this;
127 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP; 128 ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
128 ecp.dwBorderWidth = 0; 129 ecp.dwBorderWidth = 0;
129 ecp.nBorderStyle = PBS_SOLID; 130 ecp.nBorderStyle = PBS_SOLID;
130 ecp.rcRectWnd = CPDF_Rect(0, 0, 0, 0); 131 ecp.rcRectWnd = CFX_FloatRect(0, 0, 0, 0);
131 132
132 m_pEditCaret->Create(ecp); 133 m_pEditCaret->Create(ecp);
133 } 134 }
134 } 135 }
135 136
136 void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) { 137 void CPWL_EditCtrl::SetFontSize(FX_FLOAT fFontSize) {
137 m_pEdit->SetFontSize(fFontSize); 138 m_pEdit->SetFontSize(fFontSize);
138 } 139 }
139 140
140 FX_FLOAT CPWL_EditCtrl::GetFontSize() const { 141 FX_FLOAT CPWL_EditCtrl::GetFontSize() const {
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 default: 284 default:
284 if (IsINSERTpressed(nFlag)) 285 if (IsINSERTpressed(nFlag))
285 Delete(); 286 Delete();
286 InsertWord(word, GetCharSet()); 287 InsertWord(word, GetCharSet());
287 break; 288 break;
288 } 289 }
289 290
290 return TRUE; 291 return TRUE;
291 } 292 }
292 293
293 FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) { 294 FX_BOOL CPWL_EditCtrl::OnLButtonDown(const CFX_FloatPoint& point,
295 FX_DWORD nFlag) {
294 CPWL_Wnd::OnLButtonDown(point, nFlag); 296 CPWL_Wnd::OnLButtonDown(point, nFlag);
295 297
296 if (ClientHitTest(point)) { 298 if (ClientHitTest(point)) {
297 if (m_bMouseDown) 299 if (m_bMouseDown)
298 InvalidateRect(); 300 InvalidateRect();
299 301
300 m_bMouseDown = TRUE; 302 m_bMouseDown = TRUE;
301 SetCapture(); 303 SetCapture();
302 304
303 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); 305 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
304 } 306 }
305 307
306 return TRUE; 308 return TRUE;
307 } 309 }
308 310
309 FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CPDF_Point& point, FX_DWORD nFlag) { 311 FX_BOOL CPWL_EditCtrl::OnLButtonUp(const CFX_FloatPoint& point,
312 FX_DWORD nFlag) {
310 CPWL_Wnd::OnLButtonUp(point, nFlag); 313 CPWL_Wnd::OnLButtonUp(point, nFlag);
311 314
312 if (m_bMouseDown) { 315 if (m_bMouseDown) {
313 // can receive keybord message 316 // can receive keybord message
314 if (ClientHitTest(point) && !IsFocused()) 317 if (ClientHitTest(point) && !IsFocused())
315 SetFocus(); 318 SetFocus();
316 319
317 ReleaseCapture(); 320 ReleaseCapture();
318 m_bMouseDown = FALSE; 321 m_bMouseDown = FALSE;
319 } 322 }
320 323
321 return TRUE; 324 return TRUE;
322 } 325 }
323 326
324 FX_BOOL CPWL_EditCtrl::OnMouseMove(const CPDF_Point& point, FX_DWORD nFlag) { 327 FX_BOOL CPWL_EditCtrl::OnMouseMove(const CFX_FloatPoint& point,
328 FX_DWORD nFlag) {
325 CPWL_Wnd::OnMouseMove(point, nFlag); 329 CPWL_Wnd::OnMouseMove(point, nFlag);
326 330
327 if (m_bMouseDown) 331 if (m_bMouseDown)
328 m_pEdit->OnMouseMove(point, FALSE, FALSE); 332 m_pEdit->OnMouseMove(point, FALSE, FALSE);
329 333
330 return TRUE; 334 return TRUE;
331 } 335 }
332 336
333 CPDF_Rect CPWL_EditCtrl::GetContentRect() const { 337 CFX_FloatRect CPWL_EditCtrl::GetContentRect() const {
334 return m_pEdit->GetContentRect(); 338 return m_pEdit->GetContentRect();
335 } 339 }
336 340
337 void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) { 341 void CPWL_EditCtrl::SetEditCaret(FX_BOOL bVisible) {
338 CPDF_Point ptHead(0, 0), ptFoot(0, 0); 342 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
339 343
340 if (bVisible) { 344 if (bVisible) {
341 GetCaretInfo(ptHead, ptFoot); 345 GetCaretInfo(ptHead, ptFoot);
342 } 346 }
343 347
344 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace(); 348 CPVT_WordPlace wpTemp = m_pEdit->GetCaretWordPlace();
345 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp); 349 IOnSetCaret(bVisible, ptHead, ptFoot, wpTemp);
346 } 350 }
347 351
348 void CPWL_EditCtrl::GetCaretInfo(CPDF_Point& ptHead, CPDF_Point& ptFoot) const { 352 void CPWL_EditCtrl::GetCaretInfo(CFX_FloatPoint& ptHead,
353 CFX_FloatPoint& ptFoot) const {
349 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { 354 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
350 pIterator->SetAt(m_pEdit->GetCaret()); 355 pIterator->SetAt(m_pEdit->GetCaret());
351 CPVT_Word word; 356 CPVT_Word word;
352 CPVT_Line line; 357 CPVT_Line line;
353 if (pIterator->GetWord(word)) { 358 if (pIterator->GetWord(word)) {
354 ptHead.x = word.ptWord.x + word.fWidth; 359 ptHead.x = word.ptWord.x + word.fWidth;
355 ptHead.y = word.ptWord.y + word.fAscent; 360 ptHead.y = word.ptWord.y + word.fAscent;
356 ptFoot.x = word.ptWord.x + word.fWidth; 361 ptFoot.x = word.ptWord.x + word.fWidth;
357 ptFoot.y = word.ptWord.y + word.fDescent; 362 ptFoot.y = word.ptWord.y + word.fDescent;
358 } else if (pIterator->GetLine(line)) { 363 } else if (pIterator->GetLine(line)) {
359 ptHead.x = line.ptLine.x; 364 ptHead.x = line.ptLine.x;
360 ptHead.y = line.ptLine.y + line.fLineAscent; 365 ptHead.y = line.ptLine.y + line.fLineAscent;
361 ptFoot.x = line.ptLine.x; 366 ptFoot.x = line.ptLine.x;
362 ptFoot.y = line.ptLine.y + line.fLineDescent; 367 ptFoot.y = line.ptLine.y + line.fLineDescent;
363 } 368 }
364 } 369 }
365 } 370 }
366 371
367 void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const { 372 void CPWL_EditCtrl::GetCaretPos(int32_t& x, int32_t& y) const {
368 CPDF_Point ptHead(0, 0), ptFoot(0, 0); 373 CFX_FloatPoint ptHead(0, 0), ptFoot(0, 0);
369 374
370 GetCaretInfo(ptHead, ptFoot); 375 GetCaretInfo(ptHead, ptFoot);
371 376
372 PWLtoWnd(ptHead, x, y); 377 PWLtoWnd(ptHead, x, y);
373 } 378 }
374 379
375 void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible, 380 void CPWL_EditCtrl::SetCaret(FX_BOOL bVisible,
376 const CPDF_Point& ptHead, 381 const CFX_FloatPoint& ptHead,
377 const CPDF_Point& ptFoot) { 382 const CFX_FloatPoint& ptFoot) {
378 if (m_pEditCaret) { 383 if (m_pEditCaret) {
379 if (!IsFocused() || m_pEdit->IsSelected()) 384 if (!IsFocused() || m_pEdit->IsSelected())
380 bVisible = FALSE; 385 bVisible = FALSE;
381 386
382 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot); 387 m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
383 } 388 }
384 } 389 }
385 390
386 CFX_WideString CPWL_EditCtrl::GetText() const { 391 CFX_WideString CPWL_EditCtrl::GetText() const {
387 return m_pEdit->GetText(); 392 return m_pEdit->GetText();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 m_pEdit->SetCaret(nPos); 431 m_pEdit->SetCaret(nPos);
427 } 432 }
428 433
429 int32_t CPWL_EditCtrl::GetTotalWords() const { 434 int32_t CPWL_EditCtrl::GetTotalWords() const {
430 if (m_pEdit) 435 if (m_pEdit)
431 return m_pEdit->GetTotalWords(); 436 return m_pEdit->GetTotalWords();
432 437
433 return 0; 438 return 0;
434 } 439 }
435 440
436 void CPWL_EditCtrl::SetScrollPos(const CPDF_Point& point) { 441 void CPWL_EditCtrl::SetScrollPos(const CFX_FloatPoint& point) {
437 if (m_pEdit) 442 if (m_pEdit)
438 m_pEdit->SetScrollPos(point); 443 m_pEdit->SetScrollPos(point);
439 } 444 }
440 445
441 CPDF_Point CPWL_EditCtrl::GetScrollPos() const { 446 CFX_FloatPoint CPWL_EditCtrl::GetScrollPos() const {
442 if (m_pEdit) 447 if (m_pEdit)
443 return m_pEdit->GetScrollPos(); 448 return m_pEdit->GetScrollPos();
444 449
445 return CPDF_Point(0.0f, 0.0f); 450 return CFX_FloatPoint(0.0f, 0.0f);
446 } 451 }
447 452
448 CPDF_Font* CPWL_EditCtrl::GetCaretFont() const { 453 CPDF_Font* CPWL_EditCtrl::GetCaretFont() const {
449 int32_t nFontIndex = 0; 454 int32_t nFontIndex = 0;
450 455
451 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { 456 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) {
452 pIterator->SetAt(m_pEdit->GetCaret()); 457 pIterator->SetAt(m_pEdit->GetCaret());
453 CPVT_Word word; 458 CPVT_Word word;
454 CPVT_Section section; 459 CPVT_Section section;
455 if (pIterator->GetWord(word)) { 460 if (pIterator->GetWord(word)) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 } else { 568 } else {
564 ShowVScrollBar(TRUE); 569 ShowVScrollBar(TRUE);
565 } 570 }
566 } 571 }
567 572
568 void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) { 573 void CPWL_EditCtrl::IOnSetScrollPosY(FX_FLOAT fy) {
569 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy); 574 OnNotify(this, PNM_SETSCROLLPOS, SBT_VSCROLL, (intptr_t)&fy);
570 } 575 }
571 576
572 void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible, 577 void CPWL_EditCtrl::IOnSetCaret(FX_BOOL bVisible,
573 const CPDF_Point& ptHead, 578 const CFX_FloatPoint& ptHead,
574 const CPDF_Point& ptFoot, 579 const CFX_FloatPoint& ptFoot,
575 const CPVT_WordPlace& place) { 580 const CPVT_WordPlace& place) {
576 PWL_CARET_INFO cInfo; 581 PWL_CARET_INFO cInfo;
577 cInfo.bVisible = bVisible; 582 cInfo.bVisible = bVisible;
578 cInfo.ptHead = ptHead; 583 cInfo.ptHead = ptHead;
579 cInfo.ptFoot = ptFoot; 584 cInfo.ptFoot = ptFoot;
580 585
581 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL); 586 OnNotify(this, PNM_SETCARETINFO, (intptr_t)&cInfo, (intptr_t)NULL);
582 } 587 }
583 588
584 void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps, 589 void CPWL_EditCtrl::IOnCaretChange(const CPVT_SecProps& secProps,
585 const CPVT_WordProps& wordProps) {} 590 const CPVT_WordProps& wordProps) {}
586 591
587 void CPWL_EditCtrl::IOnContentChange(const CPDF_Rect& rcContent) { 592 void CPWL_EditCtrl::IOnContentChange(const CFX_FloatRect& rcContent) {
588 if (IsValid()) { 593 if (IsValid()) {
589 if (m_pEditNotify) { 594 if (m_pEditNotify) {
590 m_pEditNotify->OnContentChange(rcContent); 595 m_pEditNotify->OnContentChange(rcContent);
591 } 596 }
592 } 597 }
593 } 598 }
594 599
595 void CPWL_EditCtrl::IOnInvalidateRect(CPDF_Rect* pRect) { 600 void CPWL_EditCtrl::IOnInvalidateRect(CFX_FloatRect* pRect) {
596 InvalidateRect(pRect); 601 InvalidateRect(pRect);
597 } 602 }
598 603
599 int32_t CPWL_EditCtrl::GetCharSet() const { 604 int32_t CPWL_EditCtrl::GetCharSet() const {
600 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet; 605 return m_nCharSet < 0 ? DEFAULT_CHARSET : m_nCharSet;
601 } 606 }
602 607
603 void CPWL_EditCtrl::GetTextRange(const CPDF_Rect& rect, 608 void CPWL_EditCtrl::GetTextRange(const CFX_FloatRect& rect,
604 int32_t& nStartChar, 609 int32_t& nStartChar,
605 int32_t& nEndChar) const { 610 int32_t& nEndChar) const {
606 nStartChar = m_pEdit->WordPlaceToWordIndex( 611 nStartChar = m_pEdit->WordPlaceToWordIndex(
607 m_pEdit->SearchWordPlace(CPDF_Point(rect.left, rect.top))); 612 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.left, rect.top)));
608 nEndChar = m_pEdit->WordPlaceToWordIndex( 613 nEndChar = m_pEdit->WordPlaceToWordIndex(
609 m_pEdit->SearchWordPlace(CPDF_Point(rect.right, rect.bottom))); 614 m_pEdit->SearchWordPlace(CFX_FloatPoint(rect.right, rect.bottom)));
610 } 615 }
611 616
612 CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar, 617 CFX_WideString CPWL_EditCtrl::GetText(int32_t& nStartChar,
613 int32_t& nEndChar) const { 618 int32_t& nEndChar) const {
614 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar); 619 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStartChar);
615 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar); 620 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEndChar);
616 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd)); 621 return m_pEdit->GetRangeText(CPVT_WordRange(wpStart, wpEnd));
617 } 622 }
618 623
619 void CPWL_EditCtrl::SetReadyToInput() { 624 void CPWL_EditCtrl::SetReadyToInput() {
620 if (m_bMouseDown) { 625 if (m_bMouseDown) {
621 ReleaseCapture(); 626 ReleaseCapture();
622 m_bMouseDown = FALSE; 627 m_bMouseDown = FALSE;
623 } 628 }
624 } 629 }
OLDNEW
« no previous file with comments | « fpdfsdk/src/pdfwindow/PWL_Edit.cpp ('k') | fpdfsdk/src/pdfwindow/PWL_Icon.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698