Revert "FX Bool considered harmful, part 3"
[pdfium.git] / fpdfsdk / include / fsdk_baseform.h
index a163999..edbd5e4 100644 (file)
@@ -1,7 +1,7 @@
 // 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_INCLUDE_FSDK_BASEFORM_H_
@@ -13,6 +13,8 @@
 #include <ctime>
 #endif
 
+#include <map>
+
 #include "../../core/include/fpdfapi/fpdf_parser.h"
 #include "../../core/include/fpdfdoc/fpdf_doc.h"
 #include "../../core/include/fxcrt/fx_basic.h"
@@ -42,7 +44,7 @@ typedef struct _PDFSDK_FieldAction
                bFieldFull = FALSE;
                bRC = TRUE;
        }
-       
+
        FX_BOOL                                 bModifier;              //in
        FX_BOOL                                 bShift;                 //in
        int                                             nCommitKey;             //in
@@ -56,14 +58,14 @@ typedef struct _PDFSDK_FieldAction
        FX_BOOL                                 bFieldFull;             //in
        FX_BOOL                                 bRC;                    //in[out]
 }PDFSDK_FieldAction;
-class CPDFSDK_Widget:public CPDFSDK_Annot
+class CPDFSDK_Widget : public CPDFSDK_Annot
 {
 public:
        CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm);
        virtual ~CPDFSDK_Widget();
 
        virtual CFX_ByteString                  GetSubType() const;
-       
+
        virtual CPDF_Action                             GetAAction(CPDF_AAction::AActionType eAAT);
 
        int                                                             GetFieldType() const;
@@ -74,7 +76,7 @@ public:
        FIELDFLAG_REQUIRED
        FIELDFLAG_NOEXPORT
        */
-       
+
        int                                                             GetFieldFlags() const;
        int                                                             GetRotate() const;
 
@@ -111,10 +113,10 @@ public:
        void                                                    ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChanged);
        void                                                    ResetFieldAppearance(FX_BOOL bValueChanged);
        void                                                    UpdateField();
-       CFX_WideString                                  OnFormat(int nCommitKey, FX_BOOL& bFormated);
-       
+       CFX_WideString                                  OnFormat(FX_BOOL& bFormated);
+
 //Message.
-       FX_BOOL                                                 OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data, 
+       FX_BOOL                                                 OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAction& data,
                                                                                                CPDFSDK_PageView* pPageView);
 
        CPDFSDK_InterForm*                              GetInterForm() const {return m_pInterForm;}
@@ -123,14 +125,14 @@ public:
        static CPDF_FormControl*                GetFormControl(CPDF_InterForm* pInterForm, CPDF_Dictionary* pAnnotDict);
 
        void                                                    DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPageView);
-       
+
        void                                                    SetAppModified();
        void                                                    ClearAppModified();
        FX_BOOL                                                 IsAppModified() const;
-       
+
        int32_t                                         GetAppearanceAge() const;
        int32_t                                         GetValueAge() const;
-       
+
 private:
        void                                                    ResetAppearance_PushButton();
        void                                                    ResetAppearance_CheckBox();
@@ -138,18 +140,18 @@ private:
        void                                                    ResetAppearance_ComboBox(const FX_WCHAR* sValue);
        void                                                    ResetAppearance_ListBox();
        void                                                    ResetAppearance_TextField(const FX_WCHAR* sValue);
-       
+
        CPDF_Rect                                               GetClientRect() const;
        CPDF_Rect                                               GetRotatedRect() const;
-       
+
        CFX_ByteString                                  GetBackgroundAppStream() const;
        CFX_ByteString                                  GetBorderAppStream() const;
        CPDF_Matrix                                             GetMatrix() const;
-       
+
        CPWL_Color                                              GetTextPWLColor() const;
        CPWL_Color                                              GetBorderPWLColor() const;
        CPWL_Color                                              GetFillPWLColor() const;
-       
+
        void                                                    AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_Stream* pImage);
        void                                                    RemoveAppearance(const CFX_ByteString& sAPType);
 public:
@@ -165,29 +167,25 @@ private:
        int32_t                                         m_nValueAge;
 };
 
-#define CPDFSDK_WidgetMap                              CFX_MapPtrTemplate<CPDF_FormControl*, CPDFSDK_Widget*>
-
 class CPDFSDK_InterForm : public CPDF_FormNotify
 {
 public:
-       CPDFSDK_InterForm(CPDFSDK_Document* pDocument);
-       virtual ~CPDFSDK_InterForm();
-       
-public:
-       virtual void                                    Destroy();
-       virtual CPDF_InterForm*                 GetInterForm();
-       
-       CPDFSDK_Document*                               GetDocument();
+       explicit CPDFSDK_InterForm(CPDFSDK_Document* pDocument);
+       ~CPDFSDK_InterForm() override;
+
+       CPDF_InterForm* GetInterForm() const { return m_pInterForm; }
+       CPDFSDK_Document* GetDocument() const { return m_pDocument; }
+
        FX_BOOL                                                 HighlightWidgets();
-       
+
        CPDFSDK_Widget*                                 GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL bNext) const;
        CPDFSDK_Widget*                                 GetWidget(CPDF_FormControl* pControl) const;
        void                                                    GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArray& widgets);
        void                                                    GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets);
-       
+
        void                                                    AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidget);
        void                                                    RemoveMap(CPDF_FormControl* pControl);
-       
+
        void                                                    EnableCalculate(FX_BOOL bEnabled);
        FX_BOOL                                                 IsCalculateEnabled() const;
 
@@ -198,26 +196,25 @@ public:
        void                                                    OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC);
        void                                                    OnValidate(CPDF_FormField* pFormField, CFX_WideString& csValue, FX_BOOL& bRC);
        void                                                    OnCalculate(CPDF_FormField* pFormField = NULL);
-       CFX_WideString                                  OnFormat(CPDF_FormField* pFormField, int nCommitKey, FX_BOOL& bFormated);
-       
+       CFX_WideString                                  OnFormat(CPDF_FormField* pFormField, FX_BOOL& bFormated);
+
        void                                                    ResetFieldAppearance(CPDF_FormField* pFormField, const FX_WCHAR* sValue, FX_BOOL bValueChanged);
        void                                                    UpdateField(CPDF_FormField* pFormField);
-       
-public:
+
        FX_BOOL                                                 DoAction_Hide(const CPDF_Action& action);
        FX_BOOL                                                 DoAction_SubmitForm(const CPDF_Action& action);
        FX_BOOL                                                 DoAction_ResetForm(const CPDF_Action& action);
        FX_BOOL                                                 DoAction_ImportData(const CPDF_Action& action);
-       
+
        void                                                    GetFieldFromObjects(const CFX_PtrArray& objects, CFX_PtrArray& fields);
        FX_BOOL                                                 IsValidField(CPDF_Dictionary* pFieldDict);
-       FX_BOOL                                                 SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields, 
+       FX_BOOL                                                 SubmitFields(const CFX_WideString& csDestination, const CFX_PtrArray& fields,
                FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncoded);
        FX_BOOL                                                 SubmitForm(const CFX_WideString& sDestination, FX_BOOL bUrlEncoded);
        FX_BOOL                                                 ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf);
        FX_BOOL                                                 ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,FX_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf);
        CFX_WideString                                  GetTemporaryFileName(const CFX_WideString& sFileExt);
-       
+
 private:
        virtual int                                             BeforeValueChange(const CPDF_FormField* pField, CFX_WideString& csValue);
        virtual int                                             AfterValueChange(const CPDF_FormField* pField);
@@ -228,19 +225,19 @@ private:
        virtual int                                             AfterFormReset(const CPDF_InterForm* pForm);
        virtual int                                             BeforeFormImportData(const CPDF_InterForm* pForm);
        virtual int                                             AfterFormImportData(const CPDF_InterForm* pForm);
-       
-private:
+
        FX_BOOL                                                 FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_WideString csTxtFile);
        FX_BOOL                                                 FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize);
        int                                                             GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Dictionary* pAnnotDict) const;
        void                                                    DoFDFBuffer(CFX_ByteString sBuffer);
-       
-private:
-       CPDFSDK_Document*                               m_pDocument;
-       CPDF_InterForm*                                 m_pInterForm;
-       CPDFSDK_WidgetMap                               m_Map;
-       FX_BOOL                                                 m_bCalculate;
-       FX_BOOL                                                 m_bBusy;
+
+    using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
+
+    CPDFSDK_Document* m_pDocument;
+    CPDF_InterForm* m_pInterForm;
+    CPDFSDK_WidgetMap m_Map;
+    FX_BOOL m_bCalculate;
+    FX_BOOL m_bBusy;
 
 public:
        FX_BOOL IsNeedHighLight(int nFieldType);