#include "fpdfsdk/pwl/cpwl_edit_impl.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "core/fpdfapi/font/cpdf_font.h"
#include "core/fpdfapi/render/cpdf_renderoptions.h"
#include "core/fpdfapi/render/cpdf_textrenderer.h"
#include "core/fpdfdoc/cpvt_word.h"
#include "core/fpdfdoc/ipvt_fontmap.h"
#include "core/fxcrt/autorestorer.h"
#include "core/fxcrt/check.h"
#include "core/fxcrt/check_op.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxge/cfx_fillrenderoptions.h"
#include "core/fxge/cfx_graphstatedata.h"
#include "core/fxge/cfx_path.h"
#include "core/fxge/cfx_renderdevice.h"
#include "fpdfsdk/pwl/cpwl_edit.h"
#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
#include "fpdfsdk/pwl/ipwl_fillernotify.h"
namespace {
const int kEditUndoMaxItems = …;
void DrawTextString(CFX_RenderDevice* pDevice,
const CFX_PointF& pt,
CPDF_Font* pFont,
float fFontSize,
const CFX_Matrix& mtUser2Device,
const ByteString& str,
FX_ARGB crTextFill) { … }
}
CPWL_EditImpl::Iterator::Iterator(CPWL_EditImpl* pEdit,
CPVT_VariableText::Iterator* pVTIterator)
: … { … }
CPWL_EditImpl::Iterator::~Iterator() = default;
bool CPWL_EditImpl::Iterator::NextWord() { … }
bool CPWL_EditImpl::Iterator::GetWord(CPVT_Word& word) const { … }
bool CPWL_EditImpl::Iterator::GetLine(CPVT_Line& line) const { … }
void CPWL_EditImpl::Iterator::SetAt(int32_t nWordIndex) { … }
void CPWL_EditImpl::Iterator::SetAt(const CPVT_WordPlace& place) { … }
const CPVT_WordPlace& CPWL_EditImpl::Iterator::GetAt() const { … }
class CPWL_EditImpl::Provider final : public CPVT_VariableText::Provider { … };
CPWL_EditImpl::Provider::Provider(IPVT_FontMap* pFontMap)
: … { … }
CPWL_EditImpl::Provider::~Provider() = default;
int CPWL_EditImpl::Provider::GetCharWidth(int32_t nFontIndex, uint16_t word) { … }
int32_t CPWL_EditImpl::Provider::GetWordFontIndex(uint16_t word,
FX_Charset charset,
int32_t nFontIndex) { … }
CPWL_EditImpl::RefreshState::RefreshState() = default;
CPWL_EditImpl::RefreshState::~RefreshState() = default;
void CPWL_EditImpl::RefreshState::BeginRefresh() { … }
void CPWL_EditImpl::RefreshState::Push(const CPVT_WordRange& linerange,
const CFX_FloatRect& rect) { … }
void CPWL_EditImpl::RefreshState::NoAnalyse() { … }
std::vector<CFX_FloatRect>* CPWL_EditImpl::RefreshState::GetRefreshRects() { … }
void CPWL_EditImpl::RefreshState::EndRefresh() { … }
void CPWL_EditImpl::RefreshState::Add(const CFX_FloatRect& new_rect) { … }
CPWL_EditImpl::UndoStack::UndoStack() = default;
CPWL_EditImpl::UndoStack::~UndoStack() = default;
bool CPWL_EditImpl::UndoStack::CanUndo() const { … }
void CPWL_EditImpl::UndoStack::Undo() { … }
bool CPWL_EditImpl::UndoStack::CanRedo() const { … }
CPWL_EditImpl::UndoItemIface* CPWL_EditImpl::UndoStack::GetLastAddItem() { … }
void CPWL_EditImpl::UndoStack::Redo() { … }
void CPWL_EditImpl::UndoStack::AddItem(std::unique_ptr<UndoItemIface> pItem) { … }
void CPWL_EditImpl::UndoStack::RemoveHeads() { … }
void CPWL_EditImpl::UndoStack::RemoveTails() { … }
class CPWL_EditImpl::UndoInsertWord final
: public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoInsertWord::UndoInsertWord(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
FX_Charset charset)
: … { … }
CPWL_EditImpl::UndoInsertWord::~UndoInsertWord() = default;
int CPWL_EditImpl::UndoInsertWord::Redo() { … }
int CPWL_EditImpl::UndoInsertWord::Undo() { … }
class CPWL_EditImpl::UndoInsertReturn final
: public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoInsertReturn::UndoInsertReturn(
CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace)
: … { … }
CPWL_EditImpl::UndoInsertReturn::~UndoInsertReturn() = default;
int CPWL_EditImpl::UndoInsertReturn::Redo() { … }
int CPWL_EditImpl::UndoInsertReturn::Undo() { … }
class CPWL_EditImpl::UndoReplaceSelection final
: public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoReplaceSelection::UndoReplaceSelection(CPWL_EditImpl* pEdit,
bool bIsEnd)
: … { … }
CPWL_EditImpl::UndoReplaceSelection::~UndoReplaceSelection() = default;
int CPWL_EditImpl::UndoReplaceSelection::Redo() { … }
int CPWL_EditImpl::UndoReplaceSelection::Undo() { … }
class CPWL_EditImpl::UndoBackspace final : public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoBackspace::UndoBackspace(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
FX_Charset charset)
: … { … }
CPWL_EditImpl::UndoBackspace::~UndoBackspace() = default;
int CPWL_EditImpl::UndoBackspace::Redo() { … }
int CPWL_EditImpl::UndoBackspace::Undo() { … }
class CPWL_EditImpl::UndoDelete final : public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoDelete::UndoDelete(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
uint16_t word,
FX_Charset charset,
bool bSecEnd)
: … { … }
CPWL_EditImpl::UndoDelete::~UndoDelete() = default;
int CPWL_EditImpl::UndoDelete::Redo() { … }
int CPWL_EditImpl::UndoDelete::Undo() { … }
class CPWL_EditImpl::UndoClear final : public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoClear::UndoClear(CPWL_EditImpl* pEdit,
const CPVT_WordRange& wrSel,
const WideString& swText)
: … { … }
CPWL_EditImpl::UndoClear::~UndoClear() = default;
int CPWL_EditImpl::UndoClear::Redo() { … }
int CPWL_EditImpl::UndoClear::Undo() { … }
class CPWL_EditImpl::UndoInsertText final
: public CPWL_EditImpl::UndoItemIface { … };
CPWL_EditImpl::UndoInsertText::UndoInsertText(CPWL_EditImpl* pEdit,
const CPVT_WordPlace& wpOldPlace,
const CPVT_WordPlace& wpNewPlace,
const WideString& swText,
FX_Charset charset)
: … { … }
CPWL_EditImpl::UndoInsertText::~UndoInsertText() = default;
int CPWL_EditImpl::UndoInsertText::Redo() { … }
int CPWL_EditImpl::UndoInsertText::Undo() { … }
void CPWL_EditImpl::DrawEdit(CFX_RenderDevice* pDevice,
const CFX_Matrix& mtUser2Device,
FX_COLORREF crTextFill,
const CFX_FloatRect& rcClip,
const CFX_PointF& ptOffset,
const CPVT_WordRange* pRange,
IPWL_FillerNotify* pFillerNotify,
IPWL_FillerNotify::PerWindowData* pSystemData) { … }
CPWL_EditImpl::CPWL_EditImpl()
: … { … }
CPWL_EditImpl::~CPWL_EditImpl() = default;
void CPWL_EditImpl::Initialize() { … }
void CPWL_EditImpl::SetFontMap(IPVT_FontMap* pFontMap) { … }
void CPWL_EditImpl::SetNotify(CPWL_Edit* pNotify) { … }
CPWL_EditImpl::Iterator* CPWL_EditImpl::GetIterator() { … }
IPVT_FontMap* CPWL_EditImpl::GetFontMap() { … }
void CPWL_EditImpl::SetPlateRect(const CFX_FloatRect& rect) { … }
void CPWL_EditImpl::SetAlignmentH(int32_t nFormat) { … }
void CPWL_EditImpl::SetAlignmentV(int32_t nFormat) { … }
void CPWL_EditImpl::SetPasswordChar(uint16_t wSubWord) { … }
void CPWL_EditImpl::SetLimitChar(int32_t nLimitChar) { … }
void CPWL_EditImpl::SetCharArray(int32_t nCharArray) { … }
void CPWL_EditImpl::SetMultiLine(bool bMultiLine) { … }
void CPWL_EditImpl::SetAutoReturn(bool bAuto) { … }
void CPWL_EditImpl::SetAutoFontSize(bool bAuto) { … }
void CPWL_EditImpl::SetFontSize(float fFontSize) { … }
void CPWL_EditImpl::SetAutoScroll(bool bAuto) { … }
void CPWL_EditImpl::SetTextOverflow(bool bAllowed) { … }
void CPWL_EditImpl::SetSelection(int32_t nStartChar, int32_t nEndChar) { … }
void CPWL_EditImpl::SetSelection(const CPVT_WordPlace& begin,
const CPVT_WordPlace& end) { … }
std::pair<int32_t, int32_t> CPWL_EditImpl::GetSelection() const { … }
int32_t CPWL_EditImpl::GetCaret() const { … }
CPVT_WordPlace CPWL_EditImpl::GetCaretWordPlace() const { … }
WideString CPWL_EditImpl::GetText() const { … }
WideString CPWL_EditImpl::GetRangeText(const CPVT_WordRange& range) const { … }
WideString CPWL_EditImpl::GetSelectedText() const { … }
int32_t CPWL_EditImpl::GetTotalLines() const { … }
CPVT_WordRange CPWL_EditImpl::GetSelectWordRange() const { … }
void CPWL_EditImpl::SetText(const WideString& sText) { … }
bool CPWL_EditImpl::InsertWord(uint16_t word, FX_Charset charset) { … }
bool CPWL_EditImpl::InsertReturn() { … }
bool CPWL_EditImpl::Backspace() { … }
bool CPWL_EditImpl::Delete() { … }
bool CPWL_EditImpl::ClearSelection() { … }
bool CPWL_EditImpl::InsertText(const WideString& sText, FX_Charset charset) { … }
float CPWL_EditImpl::GetFontSize() const { … }
uint16_t CPWL_EditImpl::GetPasswordChar() const { … }
int32_t CPWL_EditImpl::GetCharArray() const { … }
CFX_FloatRect CPWL_EditImpl::GetContentRect() const { … }
CPVT_WordRange CPWL_EditImpl::GetWholeWordRange() const { … }
CPVT_WordRange CPWL_EditImpl::GetVisibleWordRange() const { … }
CPVT_WordPlace CPWL_EditImpl::SearchWordPlace(const CFX_PointF& point) const { … }
void CPWL_EditImpl::Paint() { … }
void CPWL_EditImpl::RearrangeAll() { … }
void CPWL_EditImpl::RearrangePart(const CPVT_WordRange& range) { … }
void CPWL_EditImpl::SetContentChanged() { … }
void CPWL_EditImpl::SelectAll() { … }
void CPWL_EditImpl::SelectNone() { … }
bool CPWL_EditImpl::IsSelected() const { … }
CFX_PointF CPWL_EditImpl::VTToEdit(const CFX_PointF& point) const { … }
CFX_PointF CPWL_EditImpl::EditToVT(const CFX_PointF& point) const { … }
CFX_FloatRect CPWL_EditImpl::VTToEdit(const CFX_FloatRect& rect) const { … }
void CPWL_EditImpl::SetScrollInfo() { … }
void CPWL_EditImpl::SetScrollPosX(float fx) { … }
void CPWL_EditImpl::SetScrollPosY(float fy) { … }
void CPWL_EditImpl::SetScrollPos(const CFX_PointF& point) { … }
CFX_PointF CPWL_EditImpl::GetScrollPos() const { … }
void CPWL_EditImpl::SetScrollLimit() { … }
void CPWL_EditImpl::ScrollToCaret() { … }
void CPWL_EditImpl::Refresh() { … }
void CPWL_EditImpl::RefreshPushLineRects(const CPVT_WordRange& wr) { … }
void CPWL_EditImpl::RefreshWordRange(const CPVT_WordRange& wr) { … }
void CPWL_EditImpl::SetCaret(const CPVT_WordPlace& place) { … }
void CPWL_EditImpl::SetCaretInfo() { … }
void CPWL_EditImpl::OnMouseDown(const CFX_PointF& point,
bool bShift,
bool bCtrl) { … }
void CPWL_EditImpl::OnMouseMove(const CFX_PointF& point,
bool bShift,
bool bCtrl) { … }
void CPWL_EditImpl::OnVK_UP(bool bShift) { … }
void CPWL_EditImpl::OnVK_DOWN(bool bShift) { … }
void CPWL_EditImpl::OnVK_LEFT(bool bShift) { … }
void CPWL_EditImpl::OnVK_RIGHT(bool bShift) { … }
void CPWL_EditImpl::OnVK_HOME(bool bShift, bool bCtrl) { … }
void CPWL_EditImpl::OnVK_END(bool bShift, bool bCtrl) { … }
bool CPWL_EditImpl::InsertWord(uint16_t word,
FX_Charset charset,
bool bAddUndo) { … }
bool CPWL_EditImpl::InsertReturn(bool bAddUndo) { … }
bool CPWL_EditImpl::Backspace(bool bAddUndo) { … }
bool CPWL_EditImpl::Delete(bool bAddUndo) { … }
bool CPWL_EditImpl::Clear() { … }
bool CPWL_EditImpl::Clear(bool bAddUndo) { … }
bool CPWL_EditImpl::InsertText(const WideString& sText,
FX_Charset charset,
bool bAddUndo) { … }
void CPWL_EditImpl::PaintInsertText(const CPVT_WordPlace& wpOld,
const CPVT_WordPlace& wpNew) { … }
void CPWL_EditImpl::ReplaceAndKeepSelection(const WideString& text) { … }
void CPWL_EditImpl::ReplaceSelection(const WideString& text) { … }
bool CPWL_EditImpl::Redo() { … }
bool CPWL_EditImpl::Undo() { … }
void CPWL_EditImpl::SetCaretOrigin() { … }
CPVT_WordPlace CPWL_EditImpl::WordIndexToWordPlace(int32_t index) const { … }
bool CPWL_EditImpl::IsTextFull() const { … }
bool CPWL_EditImpl::IsTextOverflow() const { … }
bool CPWL_EditImpl::CanUndo() const { … }
bool CPWL_EditImpl::CanRedo() const { … }
void CPWL_EditImpl::EnableRefresh(bool bRefresh) { … }
void CPWL_EditImpl::EnableUndo(bool bUndo) { … }
CPVT_WordPlace CPWL_EditImpl::DoInsertText(const CPVT_WordPlace& place,
const WideString& sText,
FX_Charset charset) { … }
FX_Charset CPWL_EditImpl::GetCharSetFromUnicode(uint16_t word,
FX_Charset nOldCharset) { … }
void CPWL_EditImpl::AddEditUndoItem(
std::unique_ptr<UndoItemIface> pEditUndoItem) { … }
ByteString CPWL_EditImpl::GetPDFWordString(int32_t nFontIndex,
uint16_t Word,
uint16_t SubWord) { … }
CPWL_EditImpl::SelectState::SelectState() = default;
CPWL_EditImpl::SelectState::SelectState(const CPVT_WordRange& range) { … }
CPVT_WordRange CPWL_EditImpl::SelectState::ConvertToWordRange() const { … }
void CPWL_EditImpl::SelectState::Reset() { … }
void CPWL_EditImpl::SelectState::Set(const CPVT_WordPlace& begin,
const CPVT_WordPlace& end) { … }
void CPWL_EditImpl::SelectState::SetEndPos(const CPVT_WordPlace& end) { … }
bool CPWL_EditImpl::SelectState::IsEmpty() const { … }