| OLD | NEW | 
|---|
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 
| 6 | 6 | 
| 7 #ifndef XFA_FWL_CORE_CFWL_COMBOBOX_H_ | 7 #ifndef XFA_FWL_CORE_CFWL_COMBOBOX_H_ | 
| 8 #define XFA_FWL_CORE_CFWL_COMBOBOX_H_ | 8 #define XFA_FWL_CORE_CFWL_COMBOBOX_H_ | 
| 9 | 9 | 
| 10 #include <memory> | 10 #include <memory> | 
| 11 #include <vector> |  | 
| 12 | 11 | 
| 13 #include "xfa/fwl/core/cfwl_widget.h" | 12 #include "xfa/fwl/core/cfwl_comboboxproxy.h" | 
| 14 #include "xfa/fwl/core/ifwl_combobox.h" | 13 #include "xfa/fwl/core/cfwl_comboedit.h" | 
|  | 14 #include "xfa/fwl/core/cfwl_combolist.h" | 
|  | 15 #include "xfa/fwl/core/cfwl_form.h" | 
|  | 16 #include "xfa/fwl/core/cfwl_listbox.h" | 
|  | 17 #include "xfa/fxgraphics/cfx_graphics.h" | 
|  | 18 | 
|  | 19 class CFWL_WidgetProperties; | 
|  | 20 class CFWL_ComboBox; | 
|  | 21 class CFWL_ComboBoxProxy; | 
|  | 22 class CFWL_FormProxy; | 
|  | 23 class CFWL_ListBox; | 
|  | 24 class CFWL_Widget; | 
|  | 25 | 
|  | 26 #define FWL_STYLEEXT_CMB_DropList (0L << 0) | 
|  | 27 #define FWL_STYLEEXT_CMB_DropDown (1L << 0) | 
|  | 28 #define FWL_STYLEEXT_CMB_Sort (1L << 1) | 
|  | 29 #define FWL_STYLEEXT_CMB_ListDrag (1L << 2) | 
|  | 30 #define FWL_STYLEEXT_CMB_OwnerDraw (1L << 3) | 
|  | 31 #define FWL_STYLEEXT_CMB_EditHNear (0L << 4) | 
|  | 32 #define FWL_STYLEEXT_CMB_EditHCenter (1L << 4) | 
|  | 33 #define FWL_STYLEEXT_CMB_EditHFar (2L << 4) | 
|  | 34 #define FWL_STYLEEXT_CMB_EditVNear (0L << 6) | 
|  | 35 #define FWL_STYLEEXT_CMB_EditVCenter (1L << 6) | 
|  | 36 #define FWL_STYLEEXT_CMB_EditVFar (2L << 6) | 
|  | 37 #define FWL_STYLEEXT_CMB_EditJustified (1L << 8) | 
|  | 38 #define FWL_STYLEEXT_CMB_EditDistributed (2L << 8) | 
|  | 39 #define FWL_STYLEEXT_CMB_EditHAlignMask (3L << 4) | 
|  | 40 #define FWL_STYLEEXT_CMB_EditVAlignMask (3L << 6) | 
|  | 41 #define FWL_STYLEEXT_CMB_EditHAlignModeMask (3L << 8) | 
|  | 42 #define FWL_STYLEEXT_CMB_ListItemLeftAlign (0L << 10) | 
|  | 43 #define FWL_STYLEEXT_CMB_ListItemCenterAlign (1L << 10) | 
|  | 44 #define FWL_STYLEEXT_CMB_ListItemRightAlign (2L << 10) | 
|  | 45 #define FWL_STYLEEXT_CMB_ListItemAlignMask (3L << 10) | 
|  | 46 #define FWL_STYLEEXT_CMB_ListItemText (0L << 12) | 
|  | 47 #define FWL_STYLEEXT_CMB_ListItemIconText (1L << 12) | 
|  | 48 #define FWL_STYLEEXT_CMB_ReadOnly (1L << 13) | 
| 15 | 49 | 
| 16 class CFWL_ComboBox : public CFWL_Widget { | 50 class CFWL_ComboBox : public CFWL_Widget { | 
| 17  public: | 51  public: | 
| 18   explicit CFWL_ComboBox(const CFWL_App* pApp); | 52   explicit CFWL_ComboBox(const CFWL_App* pApp); | 
| 19   ~CFWL_ComboBox() override; | 53   ~CFWL_ComboBox() override; | 
| 20 | 54 | 
| 21   void Initialize(); | 55   // CFWL_Widget | 
|  | 56   FWL_Type GetClassID() const override; | 
|  | 57   void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; | 
|  | 58   void ModifyStylesEx(uint32_t dwStylesExAdded, | 
|  | 59                       uint32_t dwStylesExRemoved) override; | 
|  | 60   void SetStates(uint32_t dwStates, bool bSet = true) override; | 
|  | 61   void Update() override; | 
|  | 62   FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; | 
|  | 63   void DrawWidget(CFX_Graphics* pGraphics, | 
|  | 64                   const CFX_Matrix* pMatrix = nullptr) override; | 
|  | 65   void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; | 
|  | 66   void OnProcessMessage(CFWL_Message* pMessage) override; | 
|  | 67   void OnProcessEvent(CFWL_Event* pEvent) override; | 
|  | 68   void OnDrawWidget(CFX_Graphics* pGraphics, | 
|  | 69                     const CFX_Matrix* pMatrix) override; | 
|  | 70 | 
|  | 71   void GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) const; | 
|  | 72   int32_t GetCurSel() const { return m_iCurSel; } | 
|  | 73   void SetCurSel(int32_t iSel); | 
| 22 | 74 | 
| 23   void AddString(const CFX_WideStringC& wsText); | 75   void AddString(const CFX_WideStringC& wsText); | 
| 24   bool RemoveAt(int32_t iIndex);  // Returns false iff |iIndex| out of range. | 76   bool RemoveAt(int32_t iIndex);  // Returns false iff |iIndex| out of range. | 
| 25   void RemoveAll(); | 77   void RemoveAll(); | 
| 26 | 78 | 
| 27   void GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) const; |  | 
| 28   int32_t GetCurSel() const; |  | 
| 29   void SetCurSel(int32_t iSel); |  | 
| 30 |  | 
| 31   void SetEditText(const CFX_WideString& wsText); | 79   void SetEditText(const CFX_WideString& wsText); | 
| 32   void GetEditText(CFX_WideString& wsText, | 80   void GetEditText(CFX_WideString& wsText, | 
| 33                    int32_t nStart = 0, | 81                    int32_t nStart = 0, | 
| 34                    int32_t nCount = -1) const; | 82                    int32_t nCount = -1) const; | 
| 35 | 83 | 
| 36   void OpenDropDownList(bool bActivate); | 84   void OpenDropDownList(bool bActivate); | 
| 37 | 85 | 
| 38   bool EditCanUndo(); | 86   bool EditCanUndo() const { return m_pEdit->CanUndo(); } | 
| 39   bool EditCanRedo(); | 87   bool EditCanRedo() const { return m_pEdit->CanRedo(); } | 
| 40   bool EditUndo(); | 88   bool EditUndo() { return m_pEdit->Undo(); } | 
| 41   bool EditRedo(); | 89   bool EditRedo() { return m_pEdit->Redo(); } | 
| 42   bool EditCanCopy(); | 90   bool EditCanCopy() const { return m_pEdit->CountSelRanges() > 0; } | 
| 43   bool EditCanCut(); | 91   bool EditCanCut() const { | 
| 44   bool EditCanSelectAll(); | 92     if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) | 
| 45   bool EditCopy(CFX_WideString& wsCopy); | 93       return false; | 
| 46   bool EditCut(CFX_WideString& wsCut); | 94     return EditCanCopy(); | 
| 47   bool EditPaste(const CFX_WideString& wsPaste); | 95   } | 
| 48   void EditSelectAll(); | 96   bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; } | 
| 49   void EditDelete(); | 97   bool EditCopy(CFX_WideString& wsCopy) const { return m_pEdit->Copy(wsCopy); } | 
| 50   void EditDeSelect(); | 98   bool EditCut(CFX_WideString& wsCut) { return m_pEdit->Cut(wsCut); } | 
|  | 99   bool EditPaste(const CFX_WideString& wsPaste) { | 
|  | 100     return m_pEdit->Paste(wsPaste); | 
|  | 101   } | 
|  | 102   void EditSelectAll() { m_pEdit->AddSelRange(0); } | 
|  | 103   void EditDelete() { m_pEdit->ClearText(); } | 
|  | 104   void EditDeSelect() { m_pEdit->ClearSelections(); } | 
| 51 | 105 | 
| 52   void GetBBox(CFX_RectF& rect); | 106   void GetBBox(CFX_RectF& rect) const; | 
| 53   void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); | 107   void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); | 
|  | 108 | 
|  | 109   void DrawStretchHandler(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); | 
|  | 110   bool IsDropListVisible() const { | 
|  | 111     return m_pComboBoxProxy && | 
|  | 112            !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); | 
|  | 113   } | 
|  | 114   void ShowDropList(bool bActivate); | 
|  | 115 | 
|  | 116   CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); } | 
|  | 117 | 
|  | 118   void ProcessSelChanged(bool bLButtonUp); | 
|  | 119   int32_t GetCurrentSelection() const { return m_iCurSel; } | 
|  | 120 | 
|  | 121  private: | 
|  | 122   bool IsDropDownStyle() const { | 
|  | 123     return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown); | 
|  | 124   } | 
|  | 125   void MatchEditText(); | 
|  | 126   void SyncEditText(int32_t iListItem); | 
|  | 127   void Layout(); | 
|  | 128   void ResetTheme(); | 
|  | 129   void ResetEditAlignment(); | 
|  | 130   void ResetListItemAlignment(); | 
|  | 131   void InitProxyForm(); | 
|  | 132   void DisForm_InitComboList(); | 
|  | 133   void DisForm_InitComboEdit(); | 
|  | 134   void DisForm_ShowDropList(bool bActivate); | 
|  | 135   bool DisForm_IsDropListVisible() const { | 
|  | 136     return !(m_pListBox->GetStates() & FWL_WGTSTATE_Invisible); | 
|  | 137   } | 
|  | 138   void DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | 
|  | 139                               uint32_t dwStylesExRemoved); | 
|  | 140   void DisForm_Update(); | 
|  | 141   FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy); | 
|  | 142   void DisForm_DrawWidget(CFX_Graphics* pGraphics, | 
|  | 143                           const CFX_Matrix* pMatrix = nullptr); | 
|  | 144   void DisForm_GetBBox(CFX_RectF& rect) const; | 
|  | 145   void DisForm_Layout(); | 
|  | 146   void OnFocusChanged(CFWL_Message* pMsg, bool bSet = true); | 
|  | 147   void OnLButtonDown(CFWL_MsgMouse* pMsg); | 
|  | 148   void OnLButtonUp(CFWL_MsgMouse* pMsg); | 
|  | 149   void OnMouseMove(CFWL_MsgMouse* pMsg); | 
|  | 150   void OnMouseLeave(CFWL_MsgMouse* pMsg); | 
|  | 151   void OnKey(CFWL_MsgKey* pMsg); | 
|  | 152   void DoSubCtrlKey(CFWL_MsgKey* pMsg); | 
|  | 153   void DisForm_OnProcessMessage(CFWL_Message* pMessage); | 
|  | 154   void DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg); | 
|  | 155   void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet = true); | 
|  | 156   void DisForm_OnKey(CFWL_MsgKey* pMsg); | 
|  | 157 | 
|  | 158   CFX_RectF m_rtClient; | 
|  | 159   CFX_RectF m_rtContent; | 
|  | 160   CFX_RectF m_rtBtn; | 
|  | 161   CFX_RectF m_rtList; | 
|  | 162   CFX_RectF m_rtProxy; | 
|  | 163   CFX_RectF m_rtHandler; | 
|  | 164   std::unique_ptr<CFWL_ComboEdit> m_pEdit; | 
|  | 165   std::unique_ptr<CFWL_ComboList> m_pListBox; | 
|  | 166   CFWL_ComboBoxProxy* m_pComboBoxProxy;  // Can this be a unique_ptr? | 
|  | 167   bool m_bLButtonDown; | 
|  | 168   bool m_bUpFormHandler; | 
|  | 169   int32_t m_iCurSel; | 
|  | 170   int32_t m_iBtnState; | 
|  | 171   FX_FLOAT m_fComboFormHandler; | 
|  | 172   FX_FLOAT m_fItemHeight; | 
| 54 }; | 173 }; | 
| 55 | 174 | 
| 56 #endif  // XFA_FWL_CORE_CFWL_COMBOBOX_H_ | 175 #endif  // XFA_FWL_CORE_CFWL_COMBOBOX_H_ | 
| OLD | NEW | 
|---|