Merge CPWL_EditCtrl into CPWL_Edit
Change-Id: I7cb368afba4c4daccba6b9228071ee8e443ad340
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/79251
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/pwl/BUILD.gn b/fpdfsdk/pwl/BUILD.gn
index 7390119..a1b5ac0 100644
--- a/fpdfsdk/pwl/BUILD.gn
+++ b/fpdfsdk/pwl/BUILD.gn
@@ -19,8 +19,6 @@
"cpwl_combo_box.h",
"cpwl_edit.cpp",
"cpwl_edit.h",
- "cpwl_edit_ctrl.cpp",
- "cpwl_edit_ctrl.h",
"cpwl_edit_impl.cpp",
"cpwl_edit_impl.h",
"cpwl_icon.cpp",
diff --git a/fpdfsdk/pwl/cpwl_edit.cpp b/fpdfsdk/pwl/cpwl_edit.cpp
index 0fd752e..4069ba8 100644
--- a/fpdfsdk/pwl/cpwl_edit.cpp
+++ b/fpdfsdk/pwl/cpwl_edit.cpp
@@ -21,7 +21,6 @@
#include "core/fxge/cfx_renderdevice.h"
#include "core/fxge/fx_font.h"
#include "fpdfsdk/pwl/cpwl_caret.h"
-#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
#include "fpdfsdk/pwl/cpwl_edit_impl.h"
#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
#include "fpdfsdk/pwl/cpwl_wnd.h"
@@ -32,7 +31,10 @@
CPWL_Edit::CPWL_Edit(
const CreateParams& cp,
std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
- : CPWL_EditCtrl(cp, std::move(pAttachedData)) {}
+ : CPWL_Wnd(cp, std::move(pAttachedData)),
+ m_pEdit(std::make_unique<CPWL_EditImpl>()) {
+ GetCreationParams()->eCursorType = FXCT_VBEAM;
+}
CPWL_Edit::~CPWL_Edit() {
DCHECK(!m_bFocus);
@@ -65,7 +67,8 @@
m_pEditCaret->SetClipRect(rect);
}
- return CPWL_EditCtrl::RePosChildWnd();
+ m_pEdit->SetPlateRect(GetClientRect());
+ return true;
}
CFX_FloatRect CPWL_Edit::GetClientRect() const {
@@ -103,7 +106,10 @@
}
void CPWL_Edit::OnCreated() {
- CPWL_EditCtrl::OnCreated();
+ SetFontSize(GetCreationParams()->fFontSize);
+ m_pEdit->SetFontMap(GetFontMap());
+ m_pEdit->SetNotify(this);
+ m_pEdit->Initialize();
if (CPWL_ScrollBar* pScroll = GetVScrollBar()) {
pScroll->RemoveFlag(PWS_AUTOTRANSPARENT);
@@ -111,10 +117,7 @@
}
SetParamByFlag();
-
m_rcOldWindow = GetWindowRect();
-
- m_pEdit->SetOperationNotify(this);
}
void CPWL_Edit::SetParamByFlag() {
@@ -360,7 +363,7 @@
}
}
- bool bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag);
+ bool bRet = OnKeyDownInternal(nChar, nFlag);
// In case of implementation swallow the OnKeyDown event.
if (IsProceedtoOnChar(nChar, nFlag))
@@ -451,7 +454,7 @@
}
}
- return CPWL_EditCtrl::OnChar(nChar, nFlag);
+ return OnCharInternal(nChar, nFlag);
}
bool CPWL_Edit::OnMouseWheel(uint32_t nFlag,
@@ -468,3 +471,396 @@
SetScrollPos(ptScroll);
return true;
}
+
+void CPWL_Edit::OnDestroy() {
+ m_pEditCaret.Release();
+}
+
+bool CPWL_Edit::IsWndHorV() const {
+ CFX_Matrix mt = GetWindowMatrix();
+ return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y;
+}
+
+void CPWL_Edit::SetCursor() {
+ if (IsValid())
+ GetSystemHandler()->SetCursor(IsWndHorV() ? FXCT_VBEAM : FXCT_HBEAM);
+}
+
+WideString CPWL_Edit::GetSelectedText() {
+ return m_pEdit->GetSelectedText();
+}
+
+void CPWL_Edit::ReplaceSelection(const WideString& text) {
+ m_pEdit->ReplaceSelection(text);
+}
+
+bool CPWL_Edit::SelectAllText() {
+ m_pEdit->SelectAll();
+ return true;
+}
+
+void CPWL_Edit::SetScrollInfo(const PWL_SCROLL_INFO& info) {
+ if (CPWL_Wnd* pChild = GetVScrollBar())
+ pChild->SetScrollInfo(info);
+}
+
+void CPWL_Edit::SetScrollPosition(float pos) {
+ if (CPWL_Wnd* pChild = GetVScrollBar())
+ pChild->SetScrollPosition(pos);
+}
+
+void CPWL_Edit::ScrollWindowVertically(float pos) {
+ m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, pos));
+}
+
+void CPWL_Edit::CreateChildWnd(const CreateParams& cp) {
+ if (!IsReadOnly())
+ CreateEditCaret(cp);
+}
+
+void CPWL_Edit::CreateEditCaret(const CreateParams& cp) {
+ if (m_pEditCaret)
+ return;
+
+ CreateParams ecp = cp;
+ ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
+ ecp.dwBorderWidth = 0;
+ ecp.nBorderStyle = BorderStyle::kSolid;
+ ecp.rcRectWnd = CFX_FloatRect();
+
+ auto pCaret = std::make_unique<CPWL_Caret>(ecp, CloneAttachedData());
+ m_pEditCaret = pCaret.get();
+ m_pEditCaret->SetInvalidRect(GetClientRect());
+ AddChild(std::move(pCaret));
+ m_pEditCaret->Realize();
+}
+
+void CPWL_Edit::SetFontSize(float fFontSize) {
+ m_pEdit->SetFontSize(fFontSize);
+}
+
+float CPWL_Edit::GetFontSize() const {
+ return m_pEdit->GetFontSize();
+}
+
+bool CPWL_Edit::OnKeyDownInternal(uint16_t nChar, uint32_t nFlag) {
+ if (m_bMouseDown)
+ return true;
+
+ 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 && 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))
+ ClearSelection();
+ else
+ CutText();
+ return true;
+ default:
+ break;
+ }
+
+ return bRet;
+}
+
+bool CPWL_Edit::OnCharInternal(uint16_t nChar, uint32_t nFlag) {
+ if (m_bMouseDown)
+ return true;
+
+ CPWL_Wnd::OnChar(nChar, nFlag);
+
+ // FILTER
+ switch (nChar) {
+ case 0x0A:
+ case 0x1B:
+ return false;
+ default:
+ break;
+ }
+
+ bool bCtrl = IsCTRLpressed(nFlag);
+ bool bAlt = IsALTpressed(nFlag);
+ bool bShift = IsSHIFTpressed(nFlag);
+
+ uint16_t word = nChar;
+
+ if (bCtrl && !bAlt) {
+ switch (nChar) {
+ case 'C' - 'A' + 1:
+ CopyText();
+ return true;
+ case 'V' - 'A' + 1:
+ PasteText();
+ return true;
+ case 'X' - 'A' + 1:
+ CutText();
+ return true;
+ case 'A' - 'A' + 1:
+ SelectAllText();
+ 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;
+
+ ClearSelection();
+
+ switch (word) {
+ case FWL_VKEY_Back:
+ Backspace();
+ break;
+ case FWL_VKEY_Return:
+ InsertReturn();
+ break;
+ case FWL_VKEY_Unknown:
+ break;
+ default:
+ InsertWord(word, GetCharSet());
+ break;
+ }
+
+ return true;
+}
+
+bool CPWL_Edit::OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnLButtonDown(nFlag, point);
+ if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
+ if (m_bMouseDown && !InvalidateRect(nullptr))
+ return true;
+
+ m_bMouseDown = true;
+ SetCapture();
+ m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
+ }
+ return true;
+}
+
+bool CPWL_Edit::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnLButtonUp(nFlag, point);
+ if (m_bMouseDown) {
+ // can receive keybord message
+ if (ClientHitTest(point) && !IsFocused())
+ SetFocus();
+
+ ReleaseCapture();
+ m_bMouseDown = false;
+ }
+ return true;
+}
+
+bool CPWL_Edit::OnLButtonDblClk(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnLButtonDblClk(nFlag, point);
+ if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
+ m_pEdit->SelectAll();
+
+ return true;
+}
+
+bool CPWL_Edit::OnRButtonUp(uint32_t nFlag, const CFX_PointF& point) {
+ if (m_bMouseDown)
+ return false;
+
+ CPWL_Wnd::OnRButtonUp(nFlag, point);
+ if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
+ return true;
+
+ SetFocus();
+ return false;
+}
+
+bool CPWL_Edit::OnMouseMove(uint32_t nFlag, const CFX_PointF& point) {
+ CPWL_Wnd::OnMouseMove(nFlag, point);
+
+ if (m_bMouseDown)
+ m_pEdit->OnMouseMove(point, false, false);
+
+ return true;
+}
+
+void CPWL_Edit::SetEditCaret(bool bVisible) {
+ CFX_PointF ptHead;
+ CFX_PointF ptFoot;
+ if (bVisible)
+ GetCaretInfo(&ptHead, &ptFoot);
+
+ SetCaret(bVisible, ptHead, ptFoot);
+ // Note, |this| may no longer be viable at this point. If more work needs to
+ // be done, check the return value of SetCaret().
+}
+
+void CPWL_Edit::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
+ CPWL_EditImpl_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;
+ }
+}
+
+bool CPWL_Edit::SetCaret(bool bVisible,
+ const CFX_PointF& ptHead,
+ const CFX_PointF& ptFoot) {
+ if (!m_pEditCaret)
+ return true;
+
+ if (!IsFocused() || m_pEdit->IsSelected())
+ bVisible = false;
+
+ ObservedPtr<CPWL_Edit> thisObserved(this);
+ m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
+ if (!thisObserved)
+ return false;
+
+ return true;
+}
+
+WideString CPWL_Edit::GetText() {
+ return m_pEdit->GetText();
+}
+
+void CPWL_Edit::SetSelection(int32_t nStartChar, int32_t nEndChar) {
+ m_pEdit->SetSelection(nStartChar, nEndChar);
+}
+
+std::pair<int32_t, int32_t> CPWL_Edit::GetSelection() const {
+ return m_pEdit->GetSelection();
+}
+
+void CPWL_Edit::ClearSelection() {
+ if (!IsReadOnly())
+ m_pEdit->ClearSelection();
+}
+
+void CPWL_Edit::SetScrollPos(const CFX_PointF& point) {
+ m_pEdit->SetScrollPos(point);
+}
+
+CFX_PointF CPWL_Edit::GetScrollPos() const {
+ return m_pEdit->GetScrollPos();
+}
+
+void CPWL_Edit::CopyText() {}
+
+void CPWL_Edit::PasteText() {}
+
+void CPWL_Edit::InsertWord(uint16_t word, int32_t nCharset) {
+ if (!IsReadOnly())
+ m_pEdit->InsertWord(word, nCharset);
+}
+
+void CPWL_Edit::InsertReturn() {
+ if (!IsReadOnly())
+ m_pEdit->InsertReturn();
+}
+
+void CPWL_Edit::Delete() {
+ if (!IsReadOnly())
+ m_pEdit->Delete();
+}
+
+void CPWL_Edit::Backspace() {
+ if (!IsReadOnly())
+ m_pEdit->Backspace();
+}
+
+bool CPWL_Edit::CanUndo() {
+ return !IsReadOnly() && m_pEdit->CanUndo();
+}
+
+bool CPWL_Edit::CanRedo() {
+ return !IsReadOnly() && m_pEdit->CanRedo();
+}
+
+bool CPWL_Edit::Undo() {
+ return CanUndo() && m_pEdit->Undo();
+}
+
+bool CPWL_Edit::Redo() {
+ return CanRedo() && m_pEdit->Redo();
+}
+
+int32_t CPWL_Edit::GetCharSet() const {
+ return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
+}
+
+void CPWL_Edit::SetReadyToInput() {
+ if (m_bMouseDown) {
+ ReleaseCapture();
+ m_bMouseDown = false;
+ }
+}
diff --git a/fpdfsdk/pwl/cpwl_edit.h b/fpdfsdk/pwl/cpwl_edit.h
index 3639dce..f0d21aa 100644
--- a/fpdfsdk/pwl/cpwl_edit.h
+++ b/fpdfsdk/pwl/cpwl_edit.h
@@ -11,21 +11,28 @@
#include <utility>
#include "core/fpdfdoc/cpvt_wordrange.h"
+#include "core/fxcrt/fx_codepage.h"
+#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/unowned_ptr.h"
-#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
+#include "fpdfsdk/pwl/cpwl_wnd.h"
#include "fpdfsdk/pwl/ipwl_systemhandler.h"
class CPDF_Font;
+class CPWL_Caret;
+class CPWL_EditImpl;
class IPWL_FillerNotify;
-class CPWL_Edit final : public CPWL_EditCtrl {
+enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT };
+
+enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM };
+
+class CPWL_Edit final : public CPWL_Wnd {
public:
CPWL_Edit(const CreateParams& cp,
std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
~CPWL_Edit() override;
- // CPWL_EditCtrl
- void OnCreated() override;
+ // CPWL_Wnd:
bool RePosChildWnd() override;
CFX_FloatRect GetClientRect() const override;
void DrawThisAppearance(CFX_RenderDevice* pDevice,
@@ -38,12 +45,44 @@
CFX_FloatRect GetFocusRect() const override;
void OnSetFocus() override;
void OnKillFocus() override;
+ void OnCreated() override;
+ void OnDestroy() override;
+ bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
+ bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
+ bool OnLButtonDblClk(uint32_t nFlag, const CFX_PointF& point) override;
+ bool OnRButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
+ bool OnMouseMove(uint32_t nFlag, const CFX_PointF& point) override;
+ void SetScrollInfo(const PWL_SCROLL_INFO& info) override;
+ void SetScrollPosition(float pos) override;
+ void ScrollWindowVertically(float pos) override;
+ void CreateChildWnd(const CreateParams& cp) override;
+ void SetFontSize(float fFontSize) override;
+ float GetFontSize() const override;
+ void SetCursor() override;
+ WideString GetText() override;
+ WideString GetSelectedText() override;
+ void ReplaceSelection(const WideString& text) override;
+ bool SelectAllText() override;
+ bool CanUndo() override;
+ bool CanRedo() override;
+ bool Undo() override;
+ bool Redo() override;
+ void SetSelection(int32_t nStartChar, int32_t nEndChar);
+ std::pair<int32_t, int32_t> GetSelection() const;
+ void ClearSelection();
+
+ CFX_PointF GetScrollPos() const;
+ void SetScrollPos(const CFX_PointF& point);
+
+ void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; }
+ int32_t GetCharSet() const;
+
+ void SetReadyToInput();
void SetAlignFormatVerticalCenter();
void SetCharArray(int32_t nCharArray);
void SetLimitChar(int32_t nLimitChar);
void SetCharSpace(float fCharSpace);
-
bool CanSelectAll() const;
bool CanCopy() const;
bool CanCut() const;
@@ -60,6 +99,9 @@
}
void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; }
+ bool SetCaret(bool bVisible,
+ const CFX_PointF& ptHead,
+ const CFX_PointF& ptFoot);
private:
// In case of implementation swallow the OnKeyDown event. If the event is
@@ -67,12 +109,31 @@
// control means to do.
static bool IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag);
+ bool OnKeyDownInternal(uint16_t nChar, uint32_t nFlag);
+ bool OnCharInternal(uint16_t nChar, uint32_t nFlag);
+
+ void CopyText();
+ void PasteText();
+ void InsertWord(uint16_t word, int32_t nCharset);
+ void InsertReturn();
+ bool IsWndHorV() const;
+ void Delete();
+ void Backspace();
+ void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const;
+ void SetEditCaret(bool bVisible);
+
+ void CreateEditCaret(const CreateParams& cp);
+
CPVT_WordRange GetSelectWordRange() const;
bool IsVScrollBarVisible() const;
void SetParamByFlag();
+ bool m_bMouseDown = false;
bool m_bFocus = false;
+ int32_t m_nCharSet = FX_CHARSET_Default;
CFX_FloatRect m_rcOldWindow;
+ std::unique_ptr<CPWL_EditImpl> const m_pEdit;
+ UnownedPtr<CPWL_Caret> m_pEditCaret;
UnownedPtr<IPWL_FillerNotify> m_pFillerNotify;
UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp b/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
deleted file mode 100644
index 8b06e32..0000000
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.cpp
+++ /dev/null
@@ -1,434 +0,0 @@
-// 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 "fpdfsdk/pwl/cpwl_edit_ctrl.h"
-
-#include <utility>
-
-#include "core/fpdfdoc/cpvt_word.h"
-#include "core/fxge/fx_font.h"
-#include "fpdfsdk/pwl/cpwl_caret.h"
-#include "fpdfsdk/pwl/cpwl_edit_impl.h"
-#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
-#include "fpdfsdk/pwl/cpwl_wnd.h"
-#include "public/fpdf_fwlevent.h"
-
-CPWL_EditCtrl::CPWL_EditCtrl(
- const CreateParams& cp,
- std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData)
- : CPWL_Wnd(cp, std::move(pAttachedData)),
- m_pEdit(std::make_unique<CPWL_EditImpl>()) {
- GetCreationParams()->eCursorType = FXCT_VBEAM;
-}
-
-CPWL_EditCtrl::~CPWL_EditCtrl() = default;
-
-void CPWL_EditCtrl::OnCreated() {
- SetFontSize(GetCreationParams()->fFontSize);
- m_pEdit->SetFontMap(GetFontMap());
- m_pEdit->SetNotify(this);
- m_pEdit->Initialize();
-}
-
-void CPWL_EditCtrl::OnDestroy() {
- m_pEditCaret.Release();
-}
-
-bool CPWL_EditCtrl::IsWndHorV() const {
- CFX_Matrix mt = GetWindowMatrix();
- return mt.Transform(CFX_PointF(1, 1)).y == mt.Transform(CFX_PointF(0, 1)).y;
-}
-
-void CPWL_EditCtrl::SetCursor() {
- if (IsValid())
- GetSystemHandler()->SetCursor(IsWndHorV() ? FXCT_VBEAM : FXCT_HBEAM);
-}
-
-WideString CPWL_EditCtrl::GetSelectedText() {
- return m_pEdit->GetSelectedText();
-}
-
-void CPWL_EditCtrl::ReplaceSelection(const WideString& text) {
- m_pEdit->ReplaceSelection(text);
-}
-
-bool CPWL_EditCtrl::SelectAllText() {
- m_pEdit->SelectAll();
- return true;
-}
-
-bool CPWL_EditCtrl::RePosChildWnd() {
- m_pEdit->SetPlateRect(GetClientRect());
- return true;
-}
-
-void CPWL_EditCtrl::SetScrollInfo(const PWL_SCROLL_INFO& info) {
- if (CPWL_Wnd* pChild = GetVScrollBar())
- pChild->SetScrollInfo(info);
-}
-
-void CPWL_EditCtrl::SetScrollPosition(float pos) {
- if (CPWL_Wnd* pChild = GetVScrollBar())
- pChild->SetScrollPosition(pos);
-}
-
-void CPWL_EditCtrl::ScrollWindowVertically(float pos) {
- m_pEdit->SetScrollPos(CFX_PointF(m_pEdit->GetScrollPos().x, pos));
-}
-
-void CPWL_EditCtrl::CreateChildWnd(const CreateParams& cp) {
- if (!IsReadOnly())
- CreateEditCaret(cp);
-}
-
-void CPWL_EditCtrl::CreateEditCaret(const CreateParams& cp) {
- if (m_pEditCaret)
- return;
-
- CreateParams ecp = cp;
- ecp.dwFlags = PWS_CHILD | PWS_NOREFRESHCLIP;
- ecp.dwBorderWidth = 0;
- ecp.nBorderStyle = BorderStyle::kSolid;
- ecp.rcRectWnd = CFX_FloatRect();
-
- auto pCaret = std::make_unique<CPWL_Caret>(ecp, CloneAttachedData());
- m_pEditCaret = pCaret.get();
- m_pEditCaret->SetInvalidRect(GetClientRect());
- AddChild(std::move(pCaret));
- m_pEditCaret->Realize();
-}
-
-void CPWL_EditCtrl::SetFontSize(float fFontSize) {
- m_pEdit->SetFontSize(fFontSize);
-}
-
-float CPWL_EditCtrl::GetFontSize() const {
- return m_pEdit->GetFontSize();
-}
-
-bool CPWL_EditCtrl::OnKeyDown(uint16_t nChar, uint32_t nFlag) {
- if (m_bMouseDown)
- return true;
-
- 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 && 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))
- ClearSelection();
- else
- CutText();
- return true;
- default:
- break;
- }
-
- return bRet;
-}
-
-bool CPWL_EditCtrl::OnChar(uint16_t nChar, uint32_t nFlag) {
- if (m_bMouseDown)
- return true;
-
- CPWL_Wnd::OnChar(nChar, nFlag);
-
- // FILTER
- switch (nChar) {
- case 0x0A:
- case 0x1B:
- return false;
- default:
- break;
- }
-
- bool bCtrl = IsCTRLpressed(nFlag);
- bool bAlt = IsALTpressed(nFlag);
- bool bShift = IsSHIFTpressed(nFlag);
-
- uint16_t word = nChar;
-
- if (bCtrl && !bAlt) {
- switch (nChar) {
- case 'C' - 'A' + 1:
- CopyText();
- return true;
- case 'V' - 'A' + 1:
- PasteText();
- return true;
- case 'X' - 'A' + 1:
- CutText();
- return true;
- case 'A' - 'A' + 1:
- SelectAllText();
- 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;
-
- ClearSelection();
-
- switch (word) {
- case FWL_VKEY_Back:
- Backspace();
- break;
- case FWL_VKEY_Return:
- InsertReturn();
- break;
- case FWL_VKEY_Unknown:
- break;
- default:
- InsertWord(word, GetCharSet());
- break;
- }
-
- return true;
-}
-
-bool CPWL_EditCtrl::OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnLButtonDown(nFlag, point);
- if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) {
- if (m_bMouseDown && !InvalidateRect(nullptr))
- return true;
-
- m_bMouseDown = true;
- SetCapture();
- m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag));
- }
- return true;
-}
-
-bool CPWL_EditCtrl::OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnLButtonUp(nFlag, point);
- if (m_bMouseDown) {
- // can receive keybord message
- if (ClientHitTest(point) && !IsFocused())
- SetFocus();
-
- ReleaseCapture();
- m_bMouseDown = false;
- }
- return true;
-}
-
-bool CPWL_EditCtrl::OnLButtonDblClk(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnLButtonDblClk(nFlag, point);
- if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point))
- m_pEdit->SelectAll();
-
- return true;
-}
-
-bool CPWL_EditCtrl::OnRButtonUp(uint32_t nFlag, const CFX_PointF& point) {
- if (m_bMouseDown)
- return false;
-
- CPWL_Wnd::OnRButtonUp(nFlag, point);
- if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point))
- return true;
-
- SetFocus();
- return false;
-}
-
-bool CPWL_EditCtrl::OnMouseMove(uint32_t nFlag, const CFX_PointF& point) {
- CPWL_Wnd::OnMouseMove(nFlag, point);
-
- if (m_bMouseDown)
- m_pEdit->OnMouseMove(point, false, false);
-
- return true;
-}
-
-void CPWL_EditCtrl::SetEditCaret(bool bVisible) {
- CFX_PointF ptHead;
- CFX_PointF ptFoot;
- if (bVisible)
- GetCaretInfo(&ptHead, &ptFoot);
-
- SetCaret(bVisible, ptHead, ptFoot);
- // Note, |this| may no longer be viable at this point. If more work needs to
- // be done, check the return value of SetCaret().
-}
-
-void CPWL_EditCtrl::GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const {
- CPWL_EditImpl_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;
- }
-}
-
-bool CPWL_EditCtrl::SetCaret(bool bVisible,
- const CFX_PointF& ptHead,
- const CFX_PointF& ptFoot) {
- if (!m_pEditCaret)
- return true;
-
- if (!IsFocused() || m_pEdit->IsSelected())
- bVisible = false;
-
- ObservedPtr<CPWL_EditCtrl> thisObserved(this);
- m_pEditCaret->SetCaret(bVisible, ptHead, ptFoot);
- if (!thisObserved)
- return false;
-
- return true;
-}
-
-WideString CPWL_EditCtrl::GetText() {
- return m_pEdit->GetText();
-}
-
-void CPWL_EditCtrl::SetSelection(int32_t nStartChar, int32_t nEndChar) {
- m_pEdit->SetSelection(nStartChar, nEndChar);
-}
-
-std::pair<int32_t, int32_t> CPWL_EditCtrl::GetSelection() const {
- return m_pEdit->GetSelection();
-}
-
-void CPWL_EditCtrl::ClearSelection() {
- if (!IsReadOnly())
- m_pEdit->ClearSelection();
-}
-
-void CPWL_EditCtrl::SetScrollPos(const CFX_PointF& point) {
- m_pEdit->SetScrollPos(point);
-}
-
-CFX_PointF CPWL_EditCtrl::GetScrollPos() const {
- return m_pEdit->GetScrollPos();
-}
-
-void CPWL_EditCtrl::CopyText() {}
-
-void CPWL_EditCtrl::PasteText() {}
-
-void CPWL_EditCtrl::CutText() {}
-
-void CPWL_EditCtrl::InsertWord(uint16_t word, int32_t 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();
-}
-
-bool CPWL_EditCtrl::CanUndo() {
- return !IsReadOnly() && m_pEdit->CanUndo();
-}
-
-bool CPWL_EditCtrl::CanRedo() {
- return !IsReadOnly() && m_pEdit->CanRedo();
-}
-
-bool CPWL_EditCtrl::Undo() {
- return CanUndo() && m_pEdit->Undo();
-}
-
-bool CPWL_EditCtrl::Redo() {
- return CanRedo() && m_pEdit->Redo();
-}
-
-int32_t CPWL_EditCtrl::GetCharSet() const {
- return m_nCharSet < 0 ? FX_CHARSET_Default : m_nCharSet;
-}
-
-void CPWL_EditCtrl::SetReadyToInput() {
- if (m_bMouseDown) {
- ReleaseCapture();
- m_bMouseDown = false;
- }
-}
diff --git a/fpdfsdk/pwl/cpwl_edit_ctrl.h b/fpdfsdk/pwl/cpwl_edit_ctrl.h
deleted file mode 100644
index b21eb14..0000000
--- a/fpdfsdk/pwl/cpwl_edit_ctrl.h
+++ /dev/null
@@ -1,96 +0,0 @@
-// 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
-
-#ifndef FPDFSDK_PWL_CPWL_EDIT_CTRL_H_
-#define FPDFSDK_PWL_CPWL_EDIT_CTRL_H_
-
-#include <memory>
-#include <utility>
-
-#include "core/fxcrt/fx_codepage.h"
-#include "core/fxcrt/fx_string.h"
-#include "fpdfsdk/pwl/cpwl_wnd.h"
-
-class CPWL_EditImpl;
-class CPWL_Caret;
-
-enum PWL_EDIT_ALIGNFORMAT_H { PEAH_LEFT = 0, PEAH_MIDDLE, PEAH_RIGHT };
-
-enum PWL_EDIT_ALIGNFORMAT_V { PEAV_TOP = 0, PEAV_CENTER, PEAV_BOTTOM };
-
-class CPWL_EditCtrl : public CPWL_Wnd {
- public:
- CPWL_EditCtrl(
- const CreateParams& cp,
- std::unique_ptr<IPWL_SystemHandler::PerWindowData> pAttachedData);
- ~CPWL_EditCtrl() override;
-
- void SetSelection(int32_t nStartChar, int32_t nEndChar);
- std::pair<int32_t, int32_t> GetSelection() const;
- void ClearSelection();
-
- CFX_PointF GetScrollPos() const;
- void SetScrollPos(const CFX_PointF& point);
-
- void SetCharSet(uint8_t nCharSet) { m_nCharSet = nCharSet; }
- int32_t GetCharSet() const;
-
- void SetReadyToInput();
-
- // CPWL_Wnd:
- void OnCreated() override;
- void OnDestroy() override;
- bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
- bool OnChar(uint16_t nChar, uint32_t nFlag) override;
- bool OnLButtonDown(uint32_t nFlag, const CFX_PointF& point) override;
- bool OnLButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
- bool OnLButtonDblClk(uint32_t nFlag, const CFX_PointF& point) override;
- bool OnRButtonUp(uint32_t nFlag, const CFX_PointF& point) override;
- bool OnMouseMove(uint32_t nFlag, const CFX_PointF& point) override;
- void SetScrollInfo(const PWL_SCROLL_INFO& info) override;
- void SetScrollPosition(float pos) override;
- void ScrollWindowVertically(float pos) override;
- void CreateChildWnd(const CreateParams& cp) override;
- bool RePosChildWnd() override;
- void SetFontSize(float fFontSize) override;
- float GetFontSize() const override;
- void SetCursor() override;
- WideString GetText() override;
- WideString GetSelectedText() override;
- void ReplaceSelection(const WideString& text) override;
- bool SelectAllText() override;
- bool CanUndo() override;
- bool CanRedo() override;
- bool Undo() override;
- bool Redo() override;
-
- bool SetCaret(bool bVisible,
- const CFX_PointF& ptHead,
- const CFX_PointF& ptFoot);
-
- protected:
- void CopyText();
- void PasteText();
- void CutText();
- void InsertWord(uint16_t word, int32_t nCharset);
- void InsertReturn();
- bool IsWndHorV() const;
- void Delete();
- void Backspace();
- void GetCaretInfo(CFX_PointF* ptHead, CFX_PointF* ptFoot) const;
- void SetEditCaret(bool bVisible);
-
- std::unique_ptr<CPWL_EditImpl> const m_pEdit;
- UnownedPtr<CPWL_Caret> m_pEditCaret;
- bool m_bMouseDown = false;
-
- private:
- void CreateEditCaret(const CreateParams& cp);
-
- int32_t m_nCharSet = FX_CHARSET_Default;
-};
-
-#endif // FPDFSDK_PWL_CPWL_EDIT_CTRL_H_
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.cpp b/fpdfsdk/pwl/cpwl_edit_impl.cpp
index b8e1582..c637fae 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.cpp
+++ b/fpdfsdk/pwl/cpwl_edit_impl.cpp
@@ -23,7 +23,6 @@
#include "core/fxge/cfx_pathdata.h"
#include "core/fxge/cfx_renderdevice.h"
#include "fpdfsdk/pwl/cpwl_edit.h"
-#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
#include "fpdfsdk/pwl/ipwl_systemhandler.h"
#include "third_party/base/check.h"
@@ -561,14 +560,10 @@
m_pVT->SetProvider(m_pVTProvider.get());
}
-void CPWL_EditImpl::SetNotify(CPWL_EditCtrl* pNotify) {
+void CPWL_EditImpl::SetNotify(CPWL_Edit* pNotify) {
m_pNotify = pNotify;
}
-void CPWL_EditImpl::SetOperationNotify(CPWL_Edit* pOperationNotify) {
- m_pOperationNotify = pOperationNotify;
-}
-
CPWL_EditImpl_Iterator* CPWL_EditImpl::GetIterator() {
if (!m_pIterator) {
m_pIterator =
diff --git a/fpdfsdk/pwl/cpwl_edit_impl.h b/fpdfsdk/pwl/cpwl_edit_impl.h
index 5c81645..6deb7bd 100644
--- a/fpdfsdk/pwl/cpwl_edit_impl.h
+++ b/fpdfsdk/pwl/cpwl_edit_impl.h
@@ -23,7 +23,6 @@
class CPWL_EditImpl_Provider;
class CFX_RenderDevice;
class CPWL_Edit;
-class CPWL_EditCtrl;
class IPWL_SystemHandler;
class IFX_Edit_UndoItem;
@@ -265,8 +264,7 @@
~CPWL_EditImpl();
void SetFontMap(IPVT_FontMap* pFontMap);
- void SetNotify(CPWL_EditCtrl* pNotify);
- void SetOperationNotify(CPWL_Edit* pOperationNotify);
+ void SetNotify(CPWL_Edit* pNotify);
// Returns an iterator for the contents. Should not be released.
CPWL_EditImpl_Iterator* GetIterator();
@@ -397,8 +395,7 @@
std::unique_ptr<CPWL_EditImpl_Provider> m_pVTProvider;
std::unique_ptr<CPDF_VariableText> m_pVT; // Must outlive |m_pVTProvider|.
- UnownedPtr<CPWL_EditCtrl> m_pNotify;
- UnownedPtr<CPWL_Edit> m_pOperationNotify;
+ UnownedPtr<CPWL_Edit> m_pNotify;
CPVT_WordPlace m_wpCaret;
CPVT_WordPlace m_wpOldCaret;
CPWL_EditImpl_Select m_SelState;
diff --git a/fpdfsdk/pwl/cpwl_list_box.cpp b/fpdfsdk/pwl/cpwl_list_box.cpp
index 8040ba5..c1b1910 100644
--- a/fpdfsdk/pwl/cpwl_list_box.cpp
+++ b/fpdfsdk/pwl/cpwl_list_box.cpp
@@ -11,7 +11,6 @@
#include "core/fxge/cfx_renderdevice.h"
#include "fpdfsdk/pwl/cpwl_edit.h"
-#include "fpdfsdk/pwl/cpwl_edit_ctrl.h"
#include "fpdfsdk/pwl/cpwl_edit_impl.h"
#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
#include "fpdfsdk/pwl/ipwl_fillernotify.h"