| OLD | NEW |
| (Empty) |
| 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 XFA_FWL_CORE_IFWL_COMBOBOX_H_ | |
| 8 #define XFA_FWL_CORE_IFWL_COMBOBOX_H_ | |
| 9 | |
| 10 #include <memory> | |
| 11 | |
| 12 #include "xfa/fwl/core/cfwl_comboboxproxy.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/ifwl_listbox.h" | |
| 17 #include "xfa/fxgraphics/cfx_graphics.h" | |
| 18 | |
| 19 class CFWL_WidgetProperties; | |
| 20 class IFWL_ComboBox; | |
| 21 class CFWL_ComboBoxProxy; | |
| 22 class CFWL_FormProxy; | |
| 23 class IFWL_ListBox; | |
| 24 class IFWL_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) | |
| 49 | |
| 50 class IFWL_ComboBox : public IFWL_Widget { | |
| 51 public: | |
| 52 explicit IFWL_ComboBox(const CFWL_App* app, | |
| 53 std::unique_ptr<CFWL_WidgetProperties> properties); | |
| 54 ~IFWL_ComboBox() override; | |
| 55 | |
| 56 // IFWL_Widget | |
| 57 FWL_Type GetClassID() const override; | |
| 58 void GetWidgetRect(CFX_RectF& rect, bool bAutoSize = false) override; | |
| 59 void ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 60 uint32_t dwStylesExRemoved) override; | |
| 61 void SetStates(uint32_t dwStates, bool bSet = true) override; | |
| 62 void Update() override; | |
| 63 FWL_WidgetHit HitTest(FX_FLOAT fx, FX_FLOAT fy) override; | |
| 64 void DrawWidget(CFX_Graphics* pGraphics, | |
| 65 const CFX_Matrix* pMatrix = nullptr) override; | |
| 66 void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; | |
| 67 void OnProcessMessage(CFWL_Message* pMessage) override; | |
| 68 void OnProcessEvent(CFWL_Event* pEvent) override; | |
| 69 void OnDrawWidget(CFX_Graphics* pGraphics, | |
| 70 const CFX_Matrix* pMatrix) override; | |
| 71 | |
| 72 void GetTextByIndex(int32_t iIndex, CFX_WideString& wsText) const; | |
| 73 int32_t GetCurSel() const { return m_iCurSel; } | |
| 74 void SetCurSel(int32_t iSel); | |
| 75 | |
| 76 void AddString(const CFX_WideStringC& wsText); | |
| 77 bool RemoveAt(int32_t iIndex); // Returns false iff |iIndex| out of range. | |
| 78 void RemoveAll(); | |
| 79 | |
| 80 void SetEditText(const CFX_WideString& wsText); | |
| 81 void GetEditText(CFX_WideString& wsText, | |
| 82 int32_t nStart = 0, | |
| 83 int32_t nCount = -1) const; | |
| 84 | |
| 85 void OpenDropDownList(bool bActivate); | |
| 86 | |
| 87 bool EditCanUndo() const { return m_pEdit->CanUndo(); } | |
| 88 bool EditCanRedo() const { return m_pEdit->CanRedo(); } | |
| 89 bool EditUndo() { return m_pEdit->Undo(); } | |
| 90 bool EditRedo() { return m_pEdit->Redo(); } | |
| 91 bool EditCanCopy() const { return m_pEdit->CountSelRanges() > 0; } | |
| 92 bool EditCanCut() const { | |
| 93 if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) | |
| 94 return false; | |
| 95 return EditCanCopy(); | |
| 96 } | |
| 97 bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; } | |
| 98 bool EditCopy(CFX_WideString& wsCopy) const { return m_pEdit->Copy(wsCopy); } | |
| 99 bool EditCut(CFX_WideString& wsCut) { return m_pEdit->Cut(wsCut); } | |
| 100 bool EditPaste(const CFX_WideString& wsPaste) { | |
| 101 return m_pEdit->Paste(wsPaste); | |
| 102 } | |
| 103 void EditSelectAll() { m_pEdit->AddSelRange(0); } | |
| 104 void EditDelete() { m_pEdit->ClearText(); } | |
| 105 void EditDeSelect() { m_pEdit->ClearSelections(); } | |
| 106 | |
| 107 void GetBBox(CFX_RectF& rect) const; | |
| 108 void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved); | |
| 109 | |
| 110 void DrawStretchHandler(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); | |
| 111 bool IsDropListVisible() const { | |
| 112 return m_pComboBoxProxy && | |
| 113 !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); | |
| 114 } | |
| 115 void ShowDropList(bool bActivate); | |
| 116 | |
| 117 CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); } | |
| 118 | |
| 119 void ProcessSelChanged(bool bLButtonUp); | |
| 120 int32_t GetCurrentSelection() const { return m_iCurSel; } | |
| 121 | |
| 122 private: | |
| 123 bool IsDropDownStyle() const { | |
| 124 return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown); | |
| 125 } | |
| 126 void MatchEditText(); | |
| 127 void SyncEditText(int32_t iListItem); | |
| 128 void Layout(); | |
| 129 void ResetTheme(); | |
| 130 void ResetEditAlignment(); | |
| 131 void ResetListItemAlignment(); | |
| 132 void InitProxyForm(); | |
| 133 void DisForm_InitComboList(); | |
| 134 void DisForm_InitComboEdit(); | |
| 135 void DisForm_ShowDropList(bool bActivate); | |
| 136 bool DisForm_IsDropListVisible() const { | |
| 137 return !(m_pListBox->GetStates() & FWL_WGTSTATE_Invisible); | |
| 138 } | |
| 139 void DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 140 uint32_t dwStylesExRemoved); | |
| 141 void DisForm_Update(); | |
| 142 FWL_WidgetHit DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy); | |
| 143 void DisForm_DrawWidget(CFX_Graphics* pGraphics, | |
| 144 const CFX_Matrix* pMatrix = nullptr); | |
| 145 void DisForm_GetBBox(CFX_RectF& rect) const; | |
| 146 void DisForm_Layout(); | |
| 147 void OnFocusChanged(CFWL_Message* pMsg, bool bSet = true); | |
| 148 void OnLButtonDown(CFWL_MsgMouse* pMsg); | |
| 149 void OnLButtonUp(CFWL_MsgMouse* pMsg); | |
| 150 void OnMouseMove(CFWL_MsgMouse* pMsg); | |
| 151 void OnMouseLeave(CFWL_MsgMouse* pMsg); | |
| 152 void OnKey(CFWL_MsgKey* pMsg); | |
| 153 void DoSubCtrlKey(CFWL_MsgKey* pMsg); | |
| 154 void DisForm_OnProcessMessage(CFWL_Message* pMessage); | |
| 155 void DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg); | |
| 156 void DisForm_OnFocusChanged(CFWL_Message* pMsg, bool bSet = true); | |
| 157 void DisForm_OnKey(CFWL_MsgKey* pMsg); | |
| 158 | |
| 159 CFX_RectF m_rtClient; | |
| 160 CFX_RectF m_rtContent; | |
| 161 CFX_RectF m_rtBtn; | |
| 162 CFX_RectF m_rtList; | |
| 163 CFX_RectF m_rtProxy; | |
| 164 CFX_RectF m_rtHandler; | |
| 165 std::unique_ptr<CFWL_ComboEdit> m_pEdit; | |
| 166 std::unique_ptr<CFWL_ComboList> m_pListBox; | |
| 167 CFWL_ComboBoxProxy* m_pComboBoxProxy; // Can this be a unique_ptr? | |
| 168 bool m_bLButtonDown; | |
| 169 bool m_bUpFormHandler; | |
| 170 int32_t m_iCurSel; | |
| 171 int32_t m_iBtnState; | |
| 172 FX_FLOAT m_fComboFormHandler; | |
| 173 FX_FLOAT m_fItemHeight; | |
| 174 }; | |
| 175 | |
| 176 #endif // XFA_FWL_CORE_IFWL_COMBOBOX_H_ | |
| OLD | NEW |