1 // Copyright 2014 The PDFium Authors 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 XFA_FWL_CFWL_COMBOBOX_H_ 8 #define XFA_FWL_CFWL_COMBOBOX_H_ 9 10 #include "xfa/fgas/graphics/cfgas_gegraphics.h" 11 #include "xfa/fwl/cfwl_comboedit.h" 12 #include "xfa/fwl/cfwl_combolist.h" 13 #include "xfa/fwl/cfwl_listbox.h" 14 #include "xfa/fwl/cfwl_widget.h" 15 16 #define FWL_STYLEEXT_CMB_DropDown (1L << 0) 17 #define FWL_STYLEEXT_CMB_Sort (1L << 1) 18 #define FWL_STYLEEXT_CMB_OwnerDraw (1L << 3) 19 #define FWL_STYLEEXT_CMB_EditHNear 0 20 #define FWL_STYLEEXT_CMB_EditHCenter (1L << 4) 21 #define FWL_STYLEEXT_CMB_EditVNear 0 22 #define FWL_STYLEEXT_CMB_EditVCenter (1L << 6) 23 #define FWL_STYLEEXT_CMB_EditVFar (2L << 6) 24 #define FWL_STYLEEXT_CMB_EditJustified (1L << 8) 25 #define FWL_STYLEEXT_CMB_EditHAlignMask (3L << 4) 26 #define FWL_STYLEEXT_CMB_EditVAlignMask (3L << 6) 27 #define FWL_STYLEEXT_CMB_ListItemLeftAlign 0 28 #define FWL_STYLEEXT_CMB_ListItemCenterAlign (1L << 10) 29 #define FWL_STYLEEXT_CMB_ListItemAlignMask (3L << 10) 30 #define FWL_STYLEEXT_CMB_ReadOnly (1L << 13) 31 32 class CFWL_ComboBox final : public CFWL_Widget { 33 public: 34 CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED; 35 ~CFWL_ComboBox() override; 36 37 // CFWL_Widget 38 void Trace(cppgc::Visitor* visitor) const override; 39 FWL_Type GetClassID() const override; 40 void ModifyStyleExts(uint32_t dwStyleExtsAdded, 41 uint32_t dwStyleExtsRemoved) override; 42 void SetStates(uint32_t dwStates) override; 43 void RemoveStates(uint32_t dwStates) override; 44 void Update() override; 45 FWL_WidgetHit HitTest(const CFX_PointF& point) override; 46 void DrawWidget(CFGAS_GEGraphics* pGraphics, 47 const CFX_Matrix& matrix) override; 48 void OnProcessMessage(CFWL_Message* pMessage) override; 49 void OnProcessEvent(CFWL_Event* pEvent) override; 50 void OnDrawWidget(CFGAS_GEGraphics* pGraphics, 51 const CFX_Matrix& matrix) override; 52 53 WideString GetTextByIndex(int32_t iIndex) const; GetCurSel()54 int32_t GetCurSel() const { return m_iCurSel; } 55 void SetCurSel(int32_t iSel); 56 57 void AddString(const WideString& wsText); 58 void RemoveAt(int32_t iIndex); 59 void RemoveAll(); 60 61 void SetEditText(const WideString& wsText); 62 WideString GetEditText() const; 63 EditCanUndo()64 bool EditCanUndo() const { return m_pEdit->CanUndo(); } EditCanRedo()65 bool EditCanRedo() const { return m_pEdit->CanRedo(); } EditUndo()66 bool EditUndo() { return m_pEdit->Undo(); } EditRedo()67 bool EditRedo() { return m_pEdit->Redo(); } EditCanCopy()68 bool EditCanCopy() const { return m_pEdit->HasSelection(); } EditCanCut()69 bool EditCanCut() const { 70 if (m_pEdit->GetStyleExts() & FWL_STYLEEXT_EDT_ReadOnly) 71 return false; 72 return EditCanCopy(); 73 } EditCanSelectAll()74 bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; } EditCopy()75 absl::optional<WideString> EditCopy() const { return m_pEdit->Copy(); } EditCut()76 absl::optional<WideString> EditCut() { return m_pEdit->Cut(); } EditPaste(const WideString & wsPaste)77 bool EditPaste(const WideString& wsPaste) { return m_pEdit->Paste(wsPaste); } EditSelectAll()78 void EditSelectAll() { m_pEdit->SelectAll(); } EditDelete()79 void EditDelete() { m_pEdit->ClearText(); } EditDeSelect()80 void EditDeSelect() { m_pEdit->ClearSelection(); } 81 82 CFX_RectF GetBBox() const; 83 void EditModifyStyleExts(uint32_t dwStyleExtsAdded, 84 uint32_t dwStyleExtsRemoved); 85 void ShowDropDownList(); 86 void HideDropDownList(); 87 GetComboEdit()88 CFWL_ComboEdit* GetComboEdit() const { return m_pEdit; } 89 90 void ProcessSelChanged(bool bLButtonUp); GetCurrentSelection()91 int32_t GetCurrentSelection() const { return m_iCurSel; } 92 93 private: 94 explicit CFWL_ComboBox(CFWL_App* pApp); 95 IsDropDownStyle()96 bool IsDropDownStyle() const { 97 return !!(GetStyleExts() & FWL_STYLEEXT_CMB_DropDown); 98 } 99 void MatchEditText(); 100 void SyncEditText(int32_t iListItem); 101 void Layout(); 102 void ResetEditAlignment(); 103 void ResetListItemAlignment(); 104 void GetPopupPos(float fMinHeight, 105 float fMaxHeight, 106 const CFX_RectF& rtAnchor, 107 CFX_RectF* pPopupRect); 108 void OnLButtonUp(CFWL_MessageMouse* pMsg); IsDropListVisible()109 bool IsDropListVisible() const { return m_pListBox->IsVisible(); } 110 void OnLButtonDown(CFWL_MessageMouse* pMsg); 111 void OnFocusGained(); 112 void OnFocusLost(); 113 void OnKey(CFWL_MessageKey* pMsg); 114 void RepaintInflatedListBoxRect(); 115 116 CFX_RectF m_ClientRect; 117 CFX_RectF m_ContentRect; 118 CFX_RectF m_BtnRect; 119 cppgc::Member<CFWL_ComboEdit> const m_pEdit; 120 cppgc::Member<CFWL_ComboList> const m_pListBox; 121 int32_t m_iCurSel = -1; 122 Mask<CFWL_PartState> m_iBtnState = CFWL_PartState::kNormal; 123 }; 124 125 #endif // XFA_FWL_CFWL_COMBOBOX_H_ 126