Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cfwl_listbox.h
Go to the documentation of this file.
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_LISTBOX_H_
8#define XFA_FWL_CFWL_LISTBOX_H_
9
10#include <memory>
11#include <vector>
12
13#include "core/fxcrt/unowned_ptr.h"
14#include "xfa/fwl/cfwl_edit.h"
15#include "xfa/fwl/cfwl_event.h"
16#include "xfa/fwl/cfwl_listbox.h"
17#include "xfa/fwl/cfwl_widget.h"
18#include "xfa/fwl/fwl_widgetdef.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
27class CFWL_MessageMouse;
28class CFWL_MessageMouseWheel;
29
30class CFWL_ListBox : public CFWL_Widget {
31 public:
32 class Item {
33 public:
34 explicit Item(const WideString& text);
35 ~Item();
36
37 bool IsSelected() const { return m_bIsSelected; }
38 void SetSelected(bool enable) { m_bIsSelected = enable; }
39 bool IsFocused() const { return m_bIsFocused; }
40 void SetFocused(bool enable) { m_bIsFocused = enable; }
41 CFX_RectF GetRect() const { return m_ItemRect; }
42 void SetRect(const CFX_RectF& rect) { m_ItemRect = rect; }
43 WideString GetText() const { return m_wsText; }
44
45 private:
46 bool m_bIsSelected = false;
47 bool m_bIsFocused = false;
48 CFX_RectF m_ItemRect;
49 const WideString m_wsText;
50 };
51
53 ~CFWL_ListBox() override;
54
55 // CFWL_Widget:
56 void Trace(cppgc::Visitor* visitor) const override;
57 FWL_Type GetClassID() const override;
58 void Update() override;
59 FWL_WidgetHit HitTest(const CFX_PointF& point) override;
60 void DrawWidget(CFGAS_GEGraphics* pGraphics,
61 const CFX_Matrix& matrix) override;
62 void OnProcessMessage(CFWL_Message* pMessage) override;
63 void OnProcessEvent(CFWL_Event* pEvent) override;
64 void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
65 const CFX_Matrix& matrix) override;
66
67 int32_t CountItems(const CFWL_Widget* pWidget) const;
68 Item* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const;
69 int32_t GetItemIndex(CFWL_Widget* pWidget, Item* pItem);
70 Item* AddString(const WideString& wsAdd);
71 void RemoveAt(int32_t iIndex);
72 void DeleteString(Item* pItem);
73 void DeleteAll();
74 int32_t CountSelItems();
75 Item* GetSelItem(int32_t nIndexSel);
76 int32_t GetSelIndex(int32_t nIndex);
77 void SetSelItem(Item* hItem, bool bSelect);
78 float CalcItemHeight();
79
80 protected:
81 CFWL_ListBox(CFWL_App* pApp,
82 const Properties& properties,
83 CFWL_Widget* pOuter);
84
85 Item* GetListItem(Item* hItem, XFA_FWL_VKEYCODE dwKeyCode);
86 void SetSelection(Item* hStart, Item* hEnd, bool bSelected);
87 Item* GetItemAtPoint(const CFX_PointF& point);
88 bool ScrollToVisible(Item* hItem);
91 bool IsShowVertScrollBar() const;
92 bool IsShowHorzScrollBar() const;
93 bool ScrollBarPropertiesPresent() const;
94 CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar; }
95 const CFX_RectF& GetRTClient() const { return m_ClientRect; }
96
97 private:
98 bool IsMultiSelection() const;
99 void ClearSelection();
100 void SelectAll();
101 Item* GetFocusedItem();
102 void SetFocusItem(Item* hItem);
103 void DrawBkground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
104 void DrawItems(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
105 void DrawItem(CFGAS_GEGraphics* pGraphics,
106 Item* hItem,
107 int32_t Index,
108 const CFX_RectF& rtItem,
109 const CFX_Matrix& pMatrix);
110 void DrawStatic(CFGAS_GEGraphics* pGraphics);
111 CFX_SizeF CalcSize();
112 void UpdateItemSize(Item* hItem,
113 CFX_SizeF& size,
114 float fWidth,
115 float fHeight) const;
116 float GetMaxTextWidth();
117 float GetScrollWidth();
118
119 void OnFocusGained();
120 void OnFocusLost();
121 void OnLButtonDown(CFWL_MessageMouse* pMsg);
122 void OnLButtonUp(CFWL_MessageMouse* pMsg);
123 void OnMouseWheel(CFWL_MessageMouseWheel* pMsg);
124 void OnKeyDown(CFWL_MessageKey* pMsg);
125 void OnVK(Item* hItem, bool bShift, bool bCtrl);
126 bool OnScroll(CFWL_ScrollBar* pScrollBar,
127 CFWL_EventScroll::Code dwCode,
128 float fPos);
129
130 CFX_RectF m_ClientRect;
131 CFX_RectF m_StaticRect;
132 CFX_RectF m_ContentRect;
133 cppgc::Member<CFWL_ScrollBar> m_pHorzScrollBar;
134 cppgc::Member<CFWL_ScrollBar> m_pVertScrollBar;
135 FDE_TextStyle m_TTOStyles;
137 bool m_bLButtonDown = false;
138 float m_fItemHeight = 0.0f;
139 float m_fScorllBarWidth = 0.0f;
140 std::vector<std::unique_ptr<Item>> m_ItemArray; // Must outlive `m_hAnchor`.
141 UnownedPtr<Item> m_hAnchor;
142};
143
144#endif // XFA_FWL_CFWL_LISTBOX_H_
FDE_TextAlignment
Definition cfde_data.h:12
#define FWL_STYLEEXT_CMB_ListItemAlignMask
#define FWL_STYLEEXT_CMB_EditHAlignMask
#define FWL_STYLEEXT_CMB_EditVCenter
#define FWL_STYLEEXT_CMB_EditVFar
#define FWL_STYLEEXT_CMB_DropDown
#define FWL_STYLEEXT_CMB_ListItemCenterAlign
#define FWL_STYLEEXT_CMB_EditHCenter
#define FWL_STYLEEXT_CMB_EditVAlignMask
#define FWL_STYLEEXT_CMB_ReadOnly
#define FWL_STYLEEXT_CMB_EditJustified
#define FWL_STYLEEXT_EDT_VAlignMask
Definition cfwl_edit.h:36
#define FWL_STYLEEXT_EDT_HAlignModeMask
Definition cfwl_edit.h:37
#define FWL_STYLEEXT_EDT_HAlignMask
Definition cfwl_edit.h:35
#define FWL_STYLEEXT_EDT_VNear
Definition cfwl_edit.h:31
#define FWL_STYLEEXT_EDT_VCenter
Definition cfwl_edit.h:32
#define FWL_STYLEEXT_EDT_ReadOnly
Definition cfwl_edit.h:19
#define FWL_STYLEEXT_EDT_VFar
Definition cfwl_edit.h:33
#define FWL_STYLEEXT_EDT_HNear
Definition cfwl_edit.h:28
#define FWL_STYLEEXT_EDT_Justified
Definition cfwl_edit.h:34
#define FWL_STYLEEXT_EDT_HCenter
Definition cfwl_edit.h:29
#define FWL_STYLEEXT_LTB_CenterAlign
#define FWL_STYLEEXT_LTB_LeftAlign
CFWL_PartState
#define FWL_STATE_WGT_Invisible
Definition cfwl_widget.h:43
#define FWL_STYLE_WGT_VScroll
Definition cfwl_widget.h:37
FWL_Type
Definition cfwl_widget.h:46
#define FWL_STATE_WGT_Focused
Definition cfwl_widget.h:42
#define FWL_STYLE_WGT_Border
Definition cfwl_widget.h:36
StateRestorer(CFGAS_GEGraphics *graphics)
void ConcatMatrix(const CFX_Matrix &matrix)
void ProcessSelChanged(bool bLButtonUp)
void OnProcessMessage(CFWL_Message *pMessage) override
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
bool EditCanUndo() const
WideString GetTextByIndex(int32_t iIndex) const
void EditDeSelect()
bool EditCanCut() const
~CFWL_ComboBox() override
void EditSelectAll()
void EditModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
FWL_Type GetClassID() const override
CFWL_ComboEdit * GetComboEdit() const
void AddString(const WideString &wsText)
FWL_WidgetHit HitTest(const CFX_PointF &point) override
void SetStates(uint32_t dwStates) override
absl::optional< WideString > EditCut()
bool EditCanSelectAll() const
void Update() override
bool EditCanCopy() const
void SetCurSel(int32_t iSel)
void RemoveStates(uint32_t dwStates) override
void OnProcessEvent(CFWL_Event *pEvent) override
CFX_RectF GetBBox() const
WideString GetEditText() const
int32_t GetCurrentSelection() const
absl::optional< WideString > EditCopy() const
void RemoveAt(int32_t iIndex)
void Trace(cppgc::Visitor *visitor) const override
bool EditPaste(const WideString &wsPaste)
int32_t GetCurSel() const
void SetEditText(const WideString &wsText)
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved) override
bool EditCanRedo() const
void OnProcessMessage(CFWL_Message *pMessage) override
~CFWL_ComboEdit() override
~CFWL_ComboList() override
void ChangeSelected(int32_t iSel)
void OnProcessMessage(CFWL_Message *pMessage) override
int32_t MatchItem(WideStringView wsMatch)
float GetPos() const
Code GetScrollCode() const
Type GetType() const
Definition cfwl_event.h:39
CFWL_Widget * GetSrcTarget() const
Definition cfwl_event.h:40
void SetSelected(bool enable)
bool IsSelected() const
CFX_RectF GetRect() const
Item(const WideString &text)
void SetFocused(bool enable)
bool IsFocused() const
void SetRect(const CFX_RectF &rect)
WideString GetText() const
bool ScrollBarPropertiesPresent() const
void SetSelItem(Item *hItem, bool bSelect)
FWL_WidgetHit HitTest(const CFX_PointF &point) override
void Trace(cppgc::Visitor *visitor) const override
Item * GetSelItem(int32_t nIndexSel)
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
int32_t CountItems(const CFWL_Widget *pWidget) const
bool ScrollToVisible(Item *hItem)
int32_t GetItemIndex(CFWL_Widget *pWidget, Item *pItem)
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void InitHorizontalScrollBar()
void SetSelection(Item *hStart, Item *hEnd, bool bSelected)
bool IsShowVertScrollBar() const
Item * GetItem(const CFWL_Widget *pWidget, int32_t nIndex) const
void RemoveAt(int32_t iIndex)
FWL_Type GetClassID() const override
bool IsShowHorzScrollBar() const
void OnProcessEvent(CFWL_Event *pEvent) override
int32_t CountSelItems()
Item * GetListItem(Item *hItem, XFA_FWL_VKEYCODE dwKeyCode)
void Update() override
void OnProcessMessage(CFWL_Message *pMessage) override
Item * GetItemAtPoint(const CFX_PointF &point)
CFWL_ScrollBar * GetVertScrollBar() const
~CFWL_ListBox() override
CFWL_ListBox(CFWL_App *pApp, const Properties &properties, CFWL_Widget *pOuter)
const CFX_RectF & GetRTClient() const
void DeleteString(Item *pItem)
void InitVerticalScrollBar()
Item * AddString(const WideString &wsAdd)
float CalcItemHeight()
int32_t GetSelIndex(int32_t nIndex)
const KeyCommand m_dwCmd
const uint32_t m_dwKeyCodeOrChar
CFWL_MessageKillFocus(CFWL_Widget *pDstTarget)
const MouseCommand m_dwCmd
Type GetType() const
CFWL_Widget * GetDstTarget() const
CFX_RectF m_PartRect
uint32_t GetStyleExts() const
CFWL_Widget(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
virtual void SetStates(uint32_t dwStates)
Properties m_Properties
void OnProcessMessage(CFWL_Message *pMessage) override
float GetCXBorderSize() const
CFX_RectF m_WidgetRect
void RepaintRect(const CFX_RectF &pRect)
virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
IFWL_ThemeProvider * GetThemeProvider() const
virtual CFX_RectF GetClientRect()
CFWL_WidgetMgr * GetWidgetMgr() const
virtual void RemoveStates(uint32_t dwStates)
void DispatchEvent(CFWL_Event *pEvent)
bool IsLocked() const
CFX_Matrix(float a1, float b1, float c1, float d1, float e1, float f1)
void Concat(const CFX_Matrix &right)
void Offset(float dx, float dy)
bool IsEmpty(float fEpsilon) const
void Deflate(float off_left, float off_top, float off_right, float off_bottom)
void Inflate(float x, float y)
CFX_RectF & operator=(const CFX_RectF &other)=default
bool Contains(const PointType &p) const
float right() const
constexpr CFX_RectF(float dst_left, float dst_top, float dst_width, float dst_height)
void Union(const CFX_RectF &rt)
virtual CFX_RectF GetUIMargin(const CFWL_ThemePart &pThemePart) const =0
virtual float GetScrollBarWidth() const =0
bool operator==(const WideString &other) const
XFA_FWL_VKEYCODE
@ XFA_FWL_VKEY_Down
@ XFA_FWL_VKEY_Escape
@ XFA_FWL_VKEY_Return
@ XFA_FWL_VKEY_Up
FWL_WidgetHit
#define CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED
Definition heap.h:32