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 _FWL_COMBOBOX_IMP_H 8 #define _FWL_COMBOBOX_IMP_H 9 10 #include <memory> 11 12 #include "xfa/src/fwl/src/basewidget/include/fwl_editimp.h" 13 #include "xfa/src/fwl/src/basewidget/include/fwl_listboximp.h" 14 15 class CFWL_WidgetImp; 16 class CFWL_WidgetImpProperties; 17 class CFWL_WidgetImpDelegate; 18 class CFWL_ListBoxImp; 19 class CFWL_ListBoxImpDelegate; 20 class CFWL_FormProxyImp; 21 class IFWL_Widget; 22 class CFWL_ComboEditImp; 23 class CFWL_ComboEditImpDelegate; 24 class CFWL_ComboListImp; 25 class CFWL_ComboListImpDelegate; 26 class CFWL_ComboBoxImp; 27 class CFWL_ComboBoxImpDelegate; 28 class CFWL_ComboProxyImpDelegate; 29 class CFWL_ComboEditImp : public CFWL_EditImp { 30 public: 31 CFWL_ComboEditImp(const CFWL_WidgetImpProperties& properties, 32 IFWL_Widget* pOuter); 33 34 void ClearSelected(); 35 void SetSelected(); 36 void EndCaret(); 37 void FlagFocus(FX_BOOL bSet); 38 39 protected: 40 void SetComboBoxFocus(FX_BOOL bSet); 41 CFWL_ComboBoxImp* m_pOuter; 42 friend class CFWL_ComboEditImpDelegate; 43 }; 44 class CFWL_ComboEditImpDelegate : public CFWL_EditImpDelegate { 45 public: 46 CFWL_ComboEditImpDelegate(CFWL_ComboEditImp* pOwner); 47 int32_t OnProcessMessage(CFWL_Message* pMessage) override; 48 49 protected: 50 CFWL_ComboEditImp* m_pOwner; 51 }; 52 class CFWL_ComboListImp : public CFWL_ListBoxImp { 53 public: 54 CFWL_ComboListImp(const CFWL_WidgetImpProperties& properties, 55 IFWL_Widget* pOuter); 56 virtual FWL_ERR Initialize(); 57 virtual FWL_ERR Finalize(); 58 int32_t MatchItem(const CFX_WideString& wsMatch); 59 void ChangeSelected(int32_t iSel); 60 int32_t CountItems(); 61 void GetItemRect(int32_t nIndex, CFX_RectF& rtItem); 62 void ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy); 63 void SetFocus(FX_BOOL bSet); 64 FX_BOOL m_bNotifyOwner; 65 friend class CFWL_ComboListImpDelegate; 66 friend class CFWL_ComboBoxImp; 67 }; 68 class CFWL_ComboListImpDelegate : public CFWL_ListBoxImpDelegate { 69 public: 70 CFWL_ComboListImpDelegate(CFWL_ComboListImp* pOwner); 71 int32_t OnProcessMessage(CFWL_Message* pMessage) override; 72 73 protected: 74 void OnDropListFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE); 75 int32_t OnDropListMouseMove(CFWL_MsgMouse* pMsg); 76 int32_t OnDropListLButtonDown(CFWL_MsgMouse* pMsg); 77 int32_t OnDropListLButtonUp(CFWL_MsgMouse* pMsg); 78 int32_t OnDropListKey(CFWL_MsgKey* pKey); 79 void OnDropListKeyDown(CFWL_MsgKey* pKey); 80 CFWL_ComboListImp* m_pOwner; 81 }; 82 class CFWL_ComboBoxImp : public CFWL_WidgetImp { 83 public: 84 CFWL_ComboBoxImp(const CFWL_WidgetImpProperties& properties, 85 IFWL_Widget* pOuter); 86 virtual ~CFWL_ComboBoxImp(); 87 virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const; 88 virtual FX_DWORD GetClassID() const; 89 virtual FWL_ERR Initialize(); 90 virtual FWL_ERR Finalize(); 91 virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE); 92 virtual FWL_ERR ModifyStylesEx(FX_DWORD dwStylesExAdded, 93 FX_DWORD dwStylesExRemoved); 94 virtual FWL_ERR SetStates(FX_DWORD dwStates, FX_BOOL bSet = TRUE); 95 virtual FWL_ERR Update(); 96 virtual FX_DWORD HitTest(FX_FLOAT fx, FX_FLOAT fy); 97 virtual FWL_ERR DrawWidget(CFX_Graphics* pGraphics, 98 const CFX_Matrix* pMatrix = NULL); 99 virtual FWL_ERR SetThemeProvider(IFWL_ThemeProvider* pThemeProvider); 100 virtual int32_t GetCurSel(); 101 virtual FWL_ERR SetCurSel(int32_t iSel); 102 virtual FWL_ERR SetEditText(const CFX_WideString& wsText); 103 virtual int32_t GetEditTextLength() const; 104 virtual FWL_ERR GetEditText(CFX_WideString& wsText, 105 int32_t nStart = 0, 106 int32_t nCount = -1) const; 107 virtual FWL_ERR SetEditSelRange(int32_t nStart, int32_t nCount = -1); 108 virtual int32_t GetEditSelRange(int32_t nIndex, int32_t& nStart); 109 virtual int32_t GetEditLimit(); 110 virtual FWL_ERR SetEditLimit(int32_t nLimit); 111 virtual FWL_ERR EditDoClipboard(int32_t iCmd); 112 virtual FX_BOOL EditRedo(const CFX_ByteStringC& bsRecord); 113 virtual FX_BOOL EditUndo(const CFX_ByteStringC& bsRecord); 114 virtual IFWL_ListBox* GetListBoxt(); 115 virtual FX_BOOL AfterFocusShowDropList(); 116 virtual FX_ERR OpenDropDownList(FX_BOOL bActivate); 117 virtual FX_BOOL EditCanUndo(); 118 virtual FX_BOOL EditCanRedo(); 119 virtual FX_BOOL EditUndo(); 120 virtual FX_BOOL EditRedo(); 121 virtual FX_BOOL EditCanCopy(); 122 virtual FX_BOOL EditCanCut(); 123 virtual FX_BOOL EditCanSelectAll(); 124 virtual FX_BOOL EditCopy(CFX_WideString& wsCopy); 125 virtual FX_BOOL EditCut(CFX_WideString& wsCut); 126 virtual FX_BOOL EditPaste(const CFX_WideString& wsPaste); 127 virtual FX_BOOL EditSelectAll(); 128 virtual FX_BOOL EditDelete(); 129 virtual FX_BOOL EditDeSelect(); 130 virtual FWL_ERR GetBBox(CFX_RectF& rect); 131 virtual FWL_ERR EditModifyStylesEx(FX_DWORD dwStylesExAdded, 132 FX_DWORD dwStylesExRemoved); 133 134 protected: 135 void DrawStretchHandler(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix); 136 FX_FLOAT GetListHeight(); 137 void ShowDropList(FX_BOOL bActivate); 138 FX_BOOL IsDropListShowed(); 139 FX_BOOL IsDropDownStyle() const; 140 void MatchEditText(); 141 void SynchrEditText(int32_t iListItem); 142 void Layout(); 143 void ReSetTheme(); 144 void ReSetEditAlignment(); 145 void ReSetListItemAlignment(); 146 void ProcessSelChanged(FX_BOOL bLButtonUp); 147 void InitProxyForm(); 148 FWL_ERR DisForm_Initialize(); 149 void DisForm_InitComboList(); 150 void DisForm_InitComboEdit(); 151 void DisForm_ShowDropList(FX_BOOL bActivate); 152 FX_BOOL DisForm_IsDropListShowed(); 153 FWL_ERR DisForm_ModifyStylesEx(FX_DWORD dwStylesExAdded, 154 FX_DWORD dwStylesExRemoved); 155 FWL_ERR DisForm_Update(); 156 FX_DWORD DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy); 157 FWL_ERR DisForm_DrawWidget(CFX_Graphics* pGraphics, 158 const CFX_Matrix* pMatrix = NULL); 159 FWL_ERR DisForm_GetBBox(CFX_RectF& rect); 160 void DisForm_Layout(); 161 162 CFX_RectF m_rtClient; 163 CFX_RectF m_rtContent; 164 CFX_RectF m_rtBtn; 165 CFX_RectF m_rtList; 166 CFX_RectF m_rtProxy; 167 CFX_RectF m_rtHandler; 168 std::unique_ptr<IFWL_Edit> m_pEdit; 169 std::unique_ptr<IFWL_ListBox> m_pListBox; 170 IFWL_Form* m_pForm; 171 FX_BOOL m_bLButtonDown; 172 FX_BOOL m_bUpFormHandler; 173 int32_t m_iCurSel; 174 int32_t m_iBtnState; 175 FX_FLOAT m_fComboFormHandler; 176 FX_FLOAT m_fItemHeight; 177 FX_BOOL m_bNeedShowList; 178 CFWL_FormProxyImp* m_pProxy; 179 CFWL_ComboProxyImpDelegate* m_pListProxyDelegate; 180 181 friend class CFWL_ComboListImp; 182 friend class CFWL_ComboEditImp; 183 friend class CFWL_ComboEditImpDelegate; 184 friend class CFWL_ComboListImpDelegate; 185 friend class CFWL_ComboBoxImpDelegate; 186 friend class CFWL_ComboProxyImpDelegate; 187 }; 188 class CFWL_ComboBoxImpDelegate : public CFWL_WidgetImpDelegate { 189 public: 190 CFWL_ComboBoxImpDelegate(CFWL_ComboBoxImp* pOwner); 191 int32_t OnProcessMessage(CFWL_Message* pMessage) override; 192 FWL_ERR OnProcessEvent(CFWL_Event* pEvent) override; 193 FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics, 194 const CFX_Matrix* pMatrix = NULL) override; 195 196 protected: 197 void OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE); 198 void OnLButtonDown(CFWL_MsgMouse* pMsg); 199 void OnLButtonUp(CFWL_MsgMouse* pMsg); 200 void OnMouseMove(CFWL_MsgMouse* pMsg); 201 void OnMouseLeave(CFWL_MsgMouse* pMsg); 202 void OnKey(CFWL_MsgKey* pMsg); 203 void DoSubCtrlKey(CFWL_MsgKey* pMsg); 204 205 protected: 206 int32_t DisForm_OnProcessMessage(CFWL_Message* pMessage); 207 void DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg); 208 void DisForm_OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE); 209 void DisForm_OnKey(CFWL_MsgKey* pMsg); 210 211 protected: 212 CFWL_ComboBoxImp* m_pOwner; 213 friend class CFWL_ComboEditImpDelegate; 214 friend class CFWL_ComboListImpDelegate; 215 }; 216 class CFWL_ComboProxyImpDelegate : public CFWL_WidgetImpDelegate { 217 public: 218 CFWL_ComboProxyImpDelegate(IFWL_Form* pForm, CFWL_ComboBoxImp* pComboBox); 219 int32_t OnProcessMessage(CFWL_Message* pMessage) override; 220 FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics, 221 const CFX_Matrix* pMatrix = NULL) override; Reset()222 void Reset() { m_bLButtonUpSelf = FALSE; } 223 224 protected: 225 void OnLButtonDown(CFWL_MsgMouse* pMsg); 226 void OnLButtonUp(CFWL_MsgMouse* pMsg); 227 void OnMouseMove(CFWL_MsgMouse* pMsg); 228 void OnDeactive(CFWL_MsgDeactivate* pMsg); 229 void OnFocusChanged(CFWL_MsgKillFocus* pMsg, FX_BOOL bSet); 230 FX_BOOL m_bLButtonDown; 231 FX_BOOL m_bLButtonUpSelf; 232 FX_FLOAT m_fStartPos; 233 IFWL_Form* m_pForm; 234 CFWL_ComboBoxImp* m_pComboBox; 235 }; 236 #endif 237