Home | History | Annotate | Download | only in pdfwindow
      1 // Copyright 2014 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef FPDFSDK_PDFWINDOW_PWL_EDIT_H_
      8 #define FPDFSDK_PDFWINDOW_PWL_EDIT_H_
      9 
     10 #include <vector>
     11 
     12 #include "core/fxcrt/fx_basic.h"
     13 #include "fpdfsdk/fxedit/fx_edit.h"
     14 #include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
     15 #include "fpdfsdk/pdfwindow/PWL_Wnd.h"
     16 
     17 class CPDF_PageObjectHolder;
     18 class CPDF_TextObject;
     19 class IFX_Edit_UndoItem;
     20 
     21 class IPWL_Filler_Notify {
     22  public:
     23   virtual ~IPWL_Filler_Notify() {}
     24   virtual void QueryWherePopup(
     25       void* pPrivateData,
     26       FX_FLOAT fPopupMin,
     27       FX_FLOAT fPopupMax,
     28       int32_t& nRet,
     29       FX_FLOAT& fPopupRet) = 0;  // nRet: (0:bottom 1:top)
     30   virtual void OnBeforeKeyStroke(void* pPrivateData,
     31                                  CFX_WideString& strChange,
     32                                  const CFX_WideString& strChangeEx,
     33                                  int nSelStart,
     34                                  int nSelEnd,
     35                                  bool bKeyDown,
     36                                  bool& bRC,
     37                                  bool& bExit,
     38                                  uint32_t nFlag) = 0;
     39 #ifdef PDF_ENABLE_XFA
     40   virtual void OnPopupPreOpen(void* pPrivateData,
     41                               bool& bExit,
     42                               uint32_t nFlag) = 0;
     43   virtual void OnPopupPostOpen(void* pPrivateData,
     44                                bool& bExit,
     45                                uint32_t nFlag) = 0;
     46 #endif  // PDF_ENABLE_XFA
     47 };
     48 
     49 class CPWL_Edit : public CPWL_EditCtrl {
     50  public:
     51   CPWL_Edit();
     52   ~CPWL_Edit() override;
     53 
     54   // CPWL_EditCtrl
     55   CFX_ByteString GetClassName() const override;
     56   void OnDestroy() override;
     57   void OnCreated() override;
     58   void RePosChildWnd() override;
     59   CFX_FloatRect GetClientRect() const override;
     60   void GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) override;
     61   void DrawThisAppearance(CFX_RenderDevice* pDevice,
     62                           CFX_Matrix* pUser2Device) override;
     63   bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) override;
     64   bool OnLButtonDblClk(const CFX_PointF& point, uint32_t nFlag) override;
     65   bool OnRButtonUp(const CFX_PointF& point, uint32_t nFlag) override;
     66   bool OnMouseWheel(short zDelta,
     67                     const CFX_PointF& point,
     68                     uint32_t nFlag) override;
     69   bool OnKeyDown(uint16_t nChar, uint32_t nFlag) override;
     70   bool OnChar(uint16_t nChar, uint32_t nFlag) override;
     71   CFX_FloatRect GetFocusRect() const override;
     72   void OnSetFocus() override;
     73   void OnKillFocus() override;
     74 
     75   void SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat = PEAV_TOP,
     76                        bool bPaint = true);  // 0:top 1:bottom 2:center
     77 
     78   void SetCharArray(int32_t nCharArray);
     79   void SetLimitChar(int32_t nLimitChar);
     80 
     81   void SetCharSpace(FX_FLOAT fCharSpace);
     82 
     83   bool CanSelectAll() const;
     84   bool CanClear() const;
     85   bool CanCopy() const;
     86   bool CanCut() const;
     87 
     88   void CutText();
     89 
     90   void SetText(const CFX_WideString& csText);
     91   void ReplaceSel(const CFX_WideString& csText);
     92 
     93   CFX_ByteString GetTextAppearanceStream(const CFX_PointF& ptOffset) const;
     94   CFX_ByteString GetCaretAppearanceStream(const CFX_PointF& ptOffset) const;
     95   CFX_ByteString GetSelectAppearanceStream(const CFX_PointF& ptOffset) const;
     96 
     97   bool IsTextFull() const;
     98 
     99   static FX_FLOAT GetCharArrayAutoFontSize(CPDF_Font* pFont,
    100                                            const CFX_FloatRect& rcPlate,
    101                                            int32_t nCharArray);
    102 
    103   void SetFillerNotify(IPWL_Filler_Notify* pNotify) {
    104     m_pFillerNotify = pNotify;
    105   }
    106 
    107   bool IsProceedtoOnChar(uint16_t nKeyCode, uint32_t nFlag);
    108   void AttachFFLData(CFFL_FormFiller* pData) { m_pFormFiller = pData; }
    109 
    110   void OnInsertWord(const CPVT_WordPlace& place,
    111                     const CPVT_WordPlace& oldplace);
    112   void OnInsertReturn(const CPVT_WordPlace& place,
    113                       const CPVT_WordPlace& oldplace);
    114   void OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
    115   void OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
    116   void OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
    117   void OnInsertText(const CPVT_WordPlace& place,
    118                     const CPVT_WordPlace& oldplace);
    119 
    120  private:
    121   CPVT_WordRange GetSelectWordRange() const;
    122   virtual void ShowVScrollBar(bool bShow);
    123   bool IsVScrollBarVisible() const;
    124   void SetParamByFlag();
    125 
    126   FX_FLOAT GetCharArrayAutoFontSize(int32_t nCharArray);
    127   CFX_PointF GetWordRightBottomPoint(const CPVT_WordPlace& wpWord);
    128 
    129   CPVT_WordRange CombineWordRange(const CPVT_WordRange& wr1,
    130                                   const CPVT_WordRange& wr2);
    131   CPVT_WordRange GetLatinWordsRange(const CFX_PointF& point) const;
    132   CPVT_WordRange GetLatinWordsRange(const CPVT_WordPlace& place) const;
    133   CPVT_WordRange GetArabicWordsRange(const CPVT_WordPlace& place) const;
    134   CPVT_WordRange GetSameWordsRange(const CPVT_WordPlace& place,
    135                                    bool bLatin,
    136                                    bool bArabic) const;
    137   IPWL_Filler_Notify* m_pFillerNotify;
    138   bool m_bFocus;
    139   CFX_FloatRect m_rcOldWindow;
    140   CFFL_FormFiller* m_pFormFiller;  // Not owned.
    141 };
    142 
    143 #endif  // FPDFSDK_PDFWINDOW_PWL_EDIT_H_
    144