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