FX_BOOL considered harmful, part 2.
[pdfium.git] / fpdfsdk / include / pdfwindow / PWL_Edit.h
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_INCLUDE_PDFWINDOW_PWL_EDIT_H_
8 #define FPDFSDK_INCLUDE_PDFWINDOW_PWL_EDIT_H_
9
10 #include "../../../core/include/fxcrt/fx_basic.h"
11 #include "PWL_EditCtrl.h"
12 #include "PWL_Wnd.h"
13
14 class CPWL_Edit;
15 class IPWL_Filler_Notify;
16 class IPWL_SpellCheck;
17
18 class IPWL_Filler_Notify
19 {
20 public:
21         virtual ~IPWL_Filler_Notify() { }
22         virtual void                                    QueryWherePopup(void* pPrivateData, FX_FLOAT fPopupMin,FX_FLOAT fPopupMax,
23                                                                                 int32_t & nRet, FX_FLOAT & fPopupRet) = 0; //nRet: (0:bottom 1:top)
24         virtual void                                    OnBeforeKeyStroke(bool bEditOrList, void* pPrivateData, int32_t nKeyCode,
25                                                                                 CFX_WideString & strChange, const CFX_WideString& strChangeEx,
26                                                                                 int nSelStart, int nSelEnd,
27                                                                                 bool bKeyDown, bool & bRC, bool & bExit, FX_DWORD nFlag) = 0;
28         virtual void                                    OnAfterKeyStroke(bool bEditOrList, void* pPrivateData, bool & bExit, FX_DWORD nFlag) = 0;
29 };
30
31 class PWL_CLASS CPWL_Edit : public CPWL_EditCtrl, public IFX_Edit_OprNotify
32 {
33 public:
34         CPWL_Edit();
35         virtual ~CPWL_Edit();
36
37 public:
38         virtual CFX_ByteString                  GetClassName() const;
39         virtual void                                    OnDestroy();
40         virtual void                                    OnCreated();
41         virtual void                                    RePosChildWnd();
42         virtual CPDF_Rect                               GetClientRect() const;
43
44         virtual void                                    GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream);
45         virtual void                                    DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser2Device);
46
47         virtual bool                                    OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag);
48         virtual bool                                    OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag);
49         virtual bool                                    OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag);
50         virtual bool                                    OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD nFlag);
51
52         virtual bool                                    OnKeyDown(FX_WORD nChar, FX_DWORD nFlag);
53         virtual bool                                    OnChar(FX_WORD nChar, FX_DWORD nFlag);
54
55         virtual CPDF_Rect                               GetFocusRect() const;
56
57 public:
58         void                                                    SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat = PEAH_LEFT, bool bPaint = true);        //0:left 1:right 2:middle
59         void                                                    SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat = PEAV_TOP, bool bPaint = true); //0:top 1:bottom 2:center
60
61         void                                                    SetCharArray(int32_t nCharArray);
62         void                                                    SetLimitChar(int32_t nLimitChar);
63
64         void                                                    SetHorzScale(int32_t nHorzScale, bool bPaint = true);
65         void                                                    SetCharSpace(FX_FLOAT fCharSpace, bool bPaint = true);
66
67         void                                                    SetLineLeading(FX_FLOAT fLineLeading, bool bPaint = true);
68
69         void                                                    EnableSpellCheck(bool bEnabled);
70
71         bool                                                    CanSelectAll() const;
72         bool                                                    CanClear() const;
73         bool                                                    CanCopy() const;
74         bool                                                    CanCut() const;
75         bool                                                    CanPaste() const;
76
77         virtual void                                    CopyText();
78         virtual void                                    PasteText();
79         virtual void                                    CutText();
80
81         virtual void                                    SetText(const FX_WCHAR* csText);
82         void                                                    ReplaceSel(const FX_WCHAR* csText);
83
84         CFX_ByteString                                  GetTextAppearanceStream(const CPDF_Point & ptOffset) const;
85         CFX_ByteString                                  GetCaretAppearanceStream(const CPDF_Point & ptOffset) const;
86         CFX_ByteString                                  GetSelectAppearanceStream(const CPDF_Point & ptOffset) const;
87
88         bool                                                    IsTextFull() const;
89
90         static FX_FLOAT                                 GetCharArrayAutoFontSize(CPDF_Font* pFont, const CPDF_Rect& rcPlate, int32_t nCharArray);
91
92         void                                                    SetFillerNotify(IPWL_Filler_Notify* pNotify) {m_pFillerNotify = pNotify;}
93
94         void                                                    GeneratePageObjects(CPDF_PageObjects* pPageObjects,
95                                                                                 const CPDF_Point& ptOffset, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray);
96         void                                                    GeneratePageObjects(CPDF_PageObjects* pPageObjects,
97                                                                                 const CPDF_Point& ptOffset);
98
99 protected:
100         virtual void                                    OnSetFocus();
101         virtual void                                    OnKillFocus();
102
103 protected:
104         virtual void                                    OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
105         virtual void                                    OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
106         virtual void                                    OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
107         virtual void                                    OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
108         virtual void                                    OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
109         virtual void                                    OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
110         virtual void                                    OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace& oldplace);
111         virtual void                                    OnAddUndo(IFX_Edit_UndoItem* pUndoItem);
112
113 private:
114         CPVT_WordRange                                  GetSelectWordRange() const;
115         virtual void                                    ShowVScrollBar(bool bShow);
116         bool                                                    IsVScrollBarVisible() const;
117         void                                                    SetParamByFlag();
118
119         FX_FLOAT                                                GetCharArrayAutoFontSize(int32_t nCharArray);
120         CPDF_Point                                              GetWordRightBottomPoint(const CPVT_WordPlace& wpWord);
121
122         CPVT_WordRange                                  CombineWordRange(const CPVT_WordRange& wr1, const CPVT_WordRange& wr2);
123         CPVT_WordRange                                  GetLatinWordsRange(const CPDF_Point & point) const;
124         CPVT_WordRange                                  GetLatinWordsRange(const CPVT_WordPlace & place) const;
125         CPVT_WordRange                                  GetArabicWordsRange(const CPVT_WordPlace & place) const;
126         CPVT_WordRange                                  GetSameWordsRange(const CPVT_WordPlace & place, bool bLatin, bool bArabic) const;
127
128         void                                                    AjustArabicWords(const CPVT_WordRange& wr);
129 public:
130         bool                                                    IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag);
131 private:
132         IPWL_Filler_Notify*                             m_pFillerNotify;
133         IPWL_SpellCheck*                                m_pSpellCheck;
134         bool                                                    m_bFocus;
135         CPDF_Rect                                               m_rcOldWindow;
136 public:
137         void                                                    AttachFFLData(void* pData) {m_pFormFiller = pData;}
138 private:
139         void*                                                   m_pFormFiller;
140 };
141
142 #endif  // FPDFSDK_INCLUDE_PDFWINDOW_PWL_EDIT_H_