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