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_CFWL_LISTBOX_H_ 8 #define XFA_FWL_CFWL_LISTBOX_H_ 9 10 #include <memory> 11 #include <vector> 12 13 #include "xfa/fwl/cfwl_edit.h" 14 #include "xfa/fwl/cfwl_event.h" 15 #include "xfa/fwl/cfwl_listbox.h" 16 #include "xfa/fwl/cfwl_listitem.h" 17 #include "xfa/fwl/cfwl_widget.h" 18 #include "xfa/fwl/cfwl_widgetproperties.h" 19 20 #define FWL_STYLEEXT_LTB_MultiSelection (1L << 0) 21 #define FWL_STYLEEXT_LTB_LeftAlign (0L << 4) 22 #define FWL_STYLEEXT_LTB_CenterAlign (1L << 4) 23 #define FWL_STYLEEXT_LTB_RightAlign (2L << 4) 24 #define FWL_STYLEEXT_LTB_AlignMask (3L << 4) 25 #define FWL_STYLEEXT_LTB_ShowScrollBarFocus (1L << 10) 26 #define FWL_ITEMSTATE_LTB_Selected (1L << 0) 27 #define FWL_ITEMSTATE_LTB_Focused (1L << 1) 28 29 class CFWL_MessageKillFocus; 30 class CFWL_MessageMouse; 31 class CFWL_MessageMouseWheel; 32 class CFX_DIBitmap; 33 34 class CFWL_ListBox : public CFWL_Widget { 35 public: 36 explicit CFWL_ListBox(const CFWL_App* pApp, 37 std::unique_ptr<CFWL_WidgetProperties> properties, 38 CFWL_Widget* pOuter); 39 ~CFWL_ListBox() override; 40 41 // CFWL_Widget 42 FWL_Type GetClassID() const override; 43 void Update() override; 44 FWL_WidgetHit HitTest(const CFX_PointF& point) override; 45 void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override; 46 void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override; 47 void OnProcessMessage(CFWL_Message* pMessage) override; 48 void OnProcessEvent(CFWL_Event* pEvent) override; 49 void OnDrawWidget(CXFA_Graphics* pGraphics, 50 const CFX_Matrix& matrix) override; 51 52 int32_t CountItems(const CFWL_Widget* pWidget) const; 53 CFWL_ListItem* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const; 54 int32_t GetItemIndex(CFWL_Widget* pWidget, CFWL_ListItem* pItem); 55 56 CFWL_ListItem* AddString(const WideStringView& wsAdd); 57 void RemoveAt(int32_t iIndex); 58 void DeleteString(CFWL_ListItem* pItem); 59 void DeleteAll(); 60 61 int32_t CountSelItems(); 62 CFWL_ListItem* GetSelItem(int32_t nIndexSel); 63 int32_t GetSelIndex(int32_t nIndex); 64 void SetSelItem(CFWL_ListItem* hItem, bool bSelect); 65 GetItemHeight()66 float GetItemHeight() const { return m_fItemHeight; } 67 float CalcItemHeight(); 68 69 protected: 70 CFWL_ListItem* GetListItem(CFWL_ListItem* hItem, uint32_t dwKeyCode); 71 void SetSelection(CFWL_ListItem* hStart, CFWL_ListItem* hEnd, bool bSelected); 72 CFWL_ListItem* GetItemAtPoint(const CFX_PointF& point); 73 bool ScrollToVisible(CFWL_ListItem* hItem); 74 void InitVerticalScrollBar(); 75 void InitHorizontalScrollBar(); 76 bool IsShowScrollBar(bool bVert); GetVertScrollBar()77 CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar.get(); } GetRTClient()78 const CFX_RectF& GetRTClient() const { return m_rtClient; } 79 80 private: 81 void SetSelectionDirect(CFWL_ListItem* hItem, bool bSelect); 82 bool IsMultiSelection() const; 83 bool IsItemSelected(CFWL_ListItem* hItem); 84 void ClearSelection(); 85 void SelectAll(); 86 CFWL_ListItem* GetFocusedItem(); 87 void SetFocusItem(CFWL_ListItem* hItem); 88 void DrawBkground(CXFA_Graphics* pGraphics, 89 IFWL_ThemeProvider* pTheme, 90 const CFX_Matrix* pMatrix); 91 void DrawItems(CXFA_Graphics* pGraphics, 92 IFWL_ThemeProvider* pTheme, 93 const CFX_Matrix* pMatrix); 94 void DrawItem(CXFA_Graphics* pGraphics, 95 IFWL_ThemeProvider* pTheme, 96 CFWL_ListItem* hItem, 97 int32_t Index, 98 const CFX_RectF& rtItem, 99 const CFX_Matrix* pMatrix); 100 void DrawStatic(CXFA_Graphics* pGraphics, IFWL_ThemeProvider* pTheme); 101 CFX_SizeF CalcSize(bool bAutoSize); 102 void UpdateItemSize(CFWL_ListItem* hItem, 103 CFX_SizeF& size, 104 float fWidth, 105 float fHeight, 106 bool bAutoSize) const; 107 float GetMaxTextWidth(); 108 float GetScrollWidth(); 109 110 void OnFocusChanged(CFWL_Message* pMsg, bool bSet); 111 void OnLButtonDown(CFWL_MessageMouse* pMsg); 112 void OnLButtonUp(CFWL_MessageMouse* pMsg); 113 void OnMouseWheel(CFWL_MessageMouseWheel* pMsg); 114 void OnKeyDown(CFWL_MessageKey* pMsg); 115 void OnVK(CFWL_ListItem* hItem, bool bShift, bool bCtrl); 116 bool OnScroll(CFWL_ScrollBar* pScrollBar, 117 CFWL_EventScroll::Code dwCode, 118 float fPos); 119 120 CFX_RectF m_rtClient; 121 CFX_RectF m_rtStatic; 122 CFX_RectF m_rtConent; 123 std::unique_ptr<CFWL_ScrollBar> m_pHorzScrollBar; 124 std::unique_ptr<CFWL_ScrollBar> m_pVertScrollBar; 125 FDE_TextStyle m_dwTTOStyles; 126 FDE_TextAlignment m_iTTOAligns; 127 CFWL_ListItem* m_hAnchor; 128 float m_fItemHeight; 129 float m_fScorllBarWidth; 130 bool m_bLButtonDown; 131 IFWL_ThemeProvider* m_pScrollBarTP; 132 std::vector<std::unique_ptr<CFWL_ListItem>> m_ItemArray; 133 }; 134 135 #endif // XFA_FWL_CFWL_LISTBOX_H_ 136