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

Side by Side Diff: fpdfsdk/pdfwindow/PWL_Edit.cpp

Issue 1923093002: Remove IFX_SystemHandler. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 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/pdfwindow/PWL_Edit.h ('k') | fpdfsdk/pdfwindow/PWL_EditCtrl.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/pdfwindow/PWL_Edit.h" 7 #include "fpdfsdk/pdfwindow/PWL_Edit.h"
8 8
9 #include <vector> 9 #include <vector>
10 10
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 FX_BOOL CPWL_Edit::CanCopy() const { 124 FX_BOOL CPWL_Edit::CanCopy() const {
125 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && 125 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) &&
126 m_pEdit->IsSelected(); 126 m_pEdit->IsSelected();
127 } 127 }
128 128
129 FX_BOOL CPWL_Edit::CanCut() const { 129 FX_BOOL CPWL_Edit::CanCut() const {
130 return CanCopy() && !IsReadOnly(); 130 return CanCopy() && !IsReadOnly();
131 } 131 }
132
133 FX_BOOL CPWL_Edit::CanPaste() const {
134 if (IsReadOnly())
135 return FALSE;
136
137 CFX_WideString swClipboard;
138 if (IFX_SystemHandler* pSH = GetSystemHandler())
139 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
140
141 return !swClipboard.IsEmpty();
142 }
143
144 void CPWL_Edit::CopyText() {
145 if (!CanCopy())
146 return;
147
148 CFX_WideString str = m_pEdit->GetSelText();
149
150 if (IFX_SystemHandler* pSH = GetSystemHandler())
151 pSH->SetClipboardText(GetAttachedHWnd(), str);
152 }
153
154 void CPWL_Edit::PasteText() {
155 if (!CanPaste())
156 return;
157
158 CFX_WideString swClipboard;
159 if (IFX_SystemHandler* pSH = GetSystemHandler())
160 swClipboard = pSH->GetClipboardText(GetAttachedHWnd());
161
162 if (m_pFillerNotify) {
163 FX_BOOL bRC = TRUE;
164 FX_BOOL bExit = FALSE;
165 CFX_WideString strChangeEx;
166 int nSelStart = 0;
167 int nSelEnd = 0;
168 GetSel(nSelStart, nSelEnd);
169 m_pFillerNotify->OnBeforeKeyStroke(GetAttachedData(), swClipboard,
170 strChangeEx, nSelStart, nSelEnd, TRUE,
171 bRC, bExit, 0);
172 if (!bRC)
173 return;
174 if (bExit)
175 return;
176 }
177
178 if (swClipboard.GetLength() > 0) {
179 Clear();
180 InsertText(swClipboard.c_str());
181 }
182 }
183
184 void CPWL_Edit::CutText() { 132 void CPWL_Edit::CutText() {
185 if (!CanCut()) 133 if (!CanCut())
186 return; 134 return;
187
188 CFX_WideString str = m_pEdit->GetSelText();
189
190 if (IFX_SystemHandler* pSH = GetSystemHandler())
191 pSH->SetClipboardText(GetAttachedHWnd(), str);
192
193 m_pEdit->Clear(); 135 m_pEdit->Clear();
194 } 136 }
195 137
196 void CPWL_Edit::OnCreated() { 138 void CPWL_Edit::OnCreated() {
197 CPWL_EditCtrl::OnCreated(); 139 CPWL_EditCtrl::OnCreated();
198 140
199 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { 141 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
200 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); 142 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
201 pScroll->SetTransparency(255); 143 pScroll->SetTransparency(255);
202 } 144 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 } 377 }
436 378
437 CFX_FloatRect rcClip; 379 CFX_FloatRect rcClip;
438 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); 380 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange();
439 CPVT_WordRange* pRange = NULL; 381 CPVT_WordRange* pRange = NULL;
440 382
441 if (!HasFlag(PES_TEXTOVERFLOW)) { 383 if (!HasFlag(PES_TEXTOVERFLOW)) {
442 rcClip = GetClientRect(); 384 rcClip = GetClientRect();
443 pRange = &wrRange; 385 pRange = &wrRange;
444 } 386 }
445 IFX_SystemHandler* pSysHandler = GetSystemHandler(); 387 CFX_SystemHandler* pSysHandler = GetSystemHandler();
446 IFX_Edit::DrawEdit( 388 IFX_Edit::DrawEdit(
447 pDevice, pUser2Device, m_pEdit, 389 pDevice, pUser2Device, m_pEdit,
448 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), 390 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
449 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), 391 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()),
450 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); 392 rcClip, CFX_FloatPoint(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller);
451 } 393 }
452 394
453 FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) { 395 FX_BOOL CPWL_Edit::OnLButtonDown(const CFX_FloatPoint& point, uint32_t nFlag) {
454 CPWL_Wnd::OnLButtonDown(point, nFlag); 396 CPWL_Wnd::OnLButtonDown(point, nFlag);
455 397
(...skipping 14 matching lines...) Expand all
470 uint32_t nFlag) { 412 uint32_t nFlag) {
471 CPWL_Wnd::OnLButtonDblClk(point, nFlag); 413 CPWL_Wnd::OnLButtonDblClk(point, nFlag);
472 414
473 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { 415 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
474 m_pEdit->SelectAll(); 416 m_pEdit->SelectAll();
475 } 417 }
476 418
477 return TRUE; 419 return TRUE;
478 } 420 }
479 421
480 #define WM_PWLEDIT_UNDO 0x01
481 #define WM_PWLEDIT_REDO 0x02
482 #define WM_PWLEDIT_CUT 0x03
483 #define WM_PWLEDIT_COPY 0x04
484 #define WM_PWLEDIT_PASTE 0x05
485 #define WM_PWLEDIT_DELETE 0x06
486 #define WM_PWLEDIT_SELECTALL 0x07
487 #define WM_PWLEDIT_SUGGEST 0x08
488
489 FX_BOOL CPWL_Edit::OnRButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) { 422 FX_BOOL CPWL_Edit::OnRButtonUp(const CFX_FloatPoint& point, uint32_t nFlag) {
490 if (m_bMouseDown) 423 if (m_bMouseDown)
491 return FALSE; 424 return FALSE;
492 425
493 CPWL_Wnd::OnRButtonUp(point, nFlag); 426 CPWL_Wnd::OnRButtonUp(point, nFlag);
494 427
495 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) 428 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
496 return TRUE; 429 return TRUE;
497 430
498 IFX_SystemHandler* pSH = GetSystemHandler(); 431 CFX_SystemHandler* pSH = GetSystemHandler();
499 if (!pSH) 432 if (!pSH)
500 return FALSE; 433 return FALSE;
501 434
502 SetFocus(); 435 SetFocus();
503 436
504 CPVT_WordRange wrLatin = GetLatinWordsRange(point); 437 return FALSE;
505 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin);
506
507 FX_HMENU hPopup = pSH->CreatePopupMenu();
508 if (!hPopup)
509 return FALSE;
510
511 std::vector<CFX_ByteString> sSuggestWords;
512 CFX_FloatPoint ptPopup = point;
513
514 IPWL_Provider* pProvider = GetProvider();
515
516 if (HasFlag(PES_UNDO)) {
517 pSH->AppendMenuItem(
518 hPopup, WM_PWLEDIT_UNDO,
519 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo");
520 pSH->AppendMenuItem(
521 hPopup, WM_PWLEDIT_REDO,
522 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo");
523 pSH->AppendMenuItem(hPopup, 0, L"");
524
525 if (!m_pEdit->CanUndo())
526 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE);
527 if (!m_pEdit->CanRedo())
528 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE);
529 }
530
531 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT,
532 pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t");
533 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY,
534 pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy");
535 pSH->AppendMenuItem(
536 hPopup, WM_PWLEDIT_PASTE,
537 pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste");
538 pSH->AppendMenuItem(
539 hPopup, WM_PWLEDIT_DELETE,
540 pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete");
541
542 CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd());
543 if (swText.IsEmpty())
544 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
545
546 if (!m_pEdit->IsSelected()) {
547 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
548 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
549 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
550 }
551
552 if (IsReadOnly()) {
553 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
554 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE);
555 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE);
556 }
557
558 if (HasFlag(PES_PASSWORD)) {
559 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
560 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
561 }
562
563 if (HasFlag(PES_NOREAD)) {
564 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE);
565 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE);
566 }
567
568 pSH->AppendMenuItem(hPopup, 0, L"");
569 pSH->AppendMenuItem(
570 hPopup, WM_PWLEDIT_SELECTALL,
571 pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All");
572
573 if (m_pEdit->GetTotalWords() == 0) {
574 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE);
575 }
576
577 int32_t x, y;
578 PWLtoWnd(ptPopup, x, y);
579 pSH->ClientToScreen(GetAttachedHWnd(), x, y);
580 pSH->SetCursor(FXCT_ARROW);
581 int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd());
582
583 switch (nCmd) {
584 case WM_PWLEDIT_UNDO:
585 Undo();
586 break;
587 case WM_PWLEDIT_REDO:
588 Redo();
589 break;
590 case WM_PWLEDIT_CUT:
591 CutText();
592 break;
593 case WM_PWLEDIT_COPY:
594 CopyText();
595 break;
596 case WM_PWLEDIT_PASTE:
597 PasteText();
598 break;
599 case WM_PWLEDIT_DELETE:
600 Clear();
601 break;
602 case WM_PWLEDIT_SELECTALL:
603 SelectAll();
604 break;
605 case WM_PWLEDIT_SUGGEST + 0:
606 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
607 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
608 ReplaceSel(sSuggestWords[0].UTF8Decode().c_str());
609 break;
610 case WM_PWLEDIT_SUGGEST + 1:
611 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
612 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
613 ReplaceSel(sSuggestWords[1].UTF8Decode().c_str());
614 break;
615 case WM_PWLEDIT_SUGGEST + 2:
616 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
617 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
618 ReplaceSel(sSuggestWords[2].UTF8Decode().c_str());
619 break;
620 case WM_PWLEDIT_SUGGEST + 3:
621 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
622 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
623 ReplaceSel(sSuggestWords[3].UTF8Decode().c_str());
624 break;
625 case WM_PWLEDIT_SUGGEST + 4:
626 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),
627 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos));
628 ReplaceSel(sSuggestWords[4].UTF8Decode().c_str());
629 break;
630 default:
631 break;
632 }
633
634 pSH->DestroyMenu(hPopup);
635
636 return TRUE;
637 } 438 }
638 439
639 void CPWL_Edit::OnSetFocus() { 440 void CPWL_Edit::OnSetFocus() {
640 SetEditCaret(TRUE); 441 SetEditCaret(TRUE);
641 442
642 if (!IsReadOnly()) { 443 if (!IsReadOnly()) {
643 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) 444 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler())
644 pFocusHandler->OnSetFocus(this); 445 pFocusHandler->OnSetFocus(this);
645 } 446 }
646 447
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 } 939 }
1139 940
1140 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder, 941 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjectHolder* pObjectHolder,
1141 const CFX_FloatPoint& ptOffset) { 942 const CFX_FloatPoint& ptOffset) {
1142 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; 943 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray;
1143 IFX_Edit::GeneratePageObjects( 944 IFX_Edit::GeneratePageObjects(
1144 pObjectHolder, m_pEdit, ptOffset, NULL, 945 pObjectHolder, m_pEdit, ptOffset, NULL,
1145 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), 946 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()),
1146 ObjArray); 947 ObjArray);
1147 } 948 }
OLDNEW
« no previous file with comments | « fpdfsdk/pdfwindow/PWL_Edit.h ('k') | fpdfsdk/pdfwindow/PWL_EditCtrl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698