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
20namespace pdfium {
21
22#define FWL_STYLEEXT_LTB_MultiSelection (1L << 0)
23#define FWL_STYLEEXT_LTB_LeftAlign (0L << 4)
24#define FWL_STYLEEXT_LTB_CenterAlign (1L << 4)
25#define FWL_STYLEEXT_LTB_RightAlign (2L << 4)
26#define FWL_STYLEEXT_LTB_AlignMask (3L << 4)
27#define FWL_STYLEEXT_LTB_ShowScrollBarFocus (1L << 10)
28
29class CFWL_MessageMouse;
30class CFWL_MessageMouseWheel;
31
32class CFWL_ListBox : public CFWL_Widget {
33 public:
34 class Item {
35 public:
36 explicit Item(const WideString& text);
37 ~Item();
38
39 bool IsSelected() const { return m_bIsSelected; }
40 void SetSelected(bool enable) { m_bIsSelected = enable; }
41 bool IsFocused() const { return m_bIsFocused; }
42 void SetFocused(bool enable) { m_bIsFocused = enable; }
43 CFX_RectF GetRect() const { return m_ItemRect; }
44 void SetRect(const CFX_RectF& rect) { m_ItemRect = rect; }
45 WideString GetText() const { return m_wsText; }
46
47 private:
48 bool m_bIsSelected = false;
49 bool m_bIsFocused = false;
50 CFX_RectF m_ItemRect;
51 const WideString m_wsText;
52 };
53
55 ~CFWL_ListBox() override;
56
57 // CFWL_Widget:
58 void Trace(cppgc::Visitor* visitor) const override;
59 FWL_Type GetClassID() const override;
60 void Update() override;
61 FWL_WidgetHit HitTest(const CFX_PointF& point) override;
62 void DrawWidget(CFGAS_GEGraphics* pGraphics,
63 const CFX_Matrix& matrix) override;
64 void OnProcessMessage(CFWL_Message* pMessage) override;
65 void OnProcessEvent(CFWL_Event* pEvent) override;
66 void OnDrawWidget(CFGAS_GEGraphics* pGraphics,
67 const CFX_Matrix& matrix) override;
68
69 int32_t CountItems(const CFWL_Widget* pWidget) const;
70 Item* GetItem(const CFWL_Widget* pWidget, int32_t nIndex) const;
71 int32_t GetItemIndex(CFWL_Widget* pWidget, Item* pItem);
72 Item* AddString(const WideString& wsAdd);
73 void RemoveAt(int32_t iIndex);
74 void DeleteString(Item* pItem);
75 void DeleteAll();
76 int32_t CountSelItems();
77 Item* GetSelItem(int32_t nIndexSel);
78 int32_t GetSelIndex(int32_t nIndex);
79 void SetSelItem(Item* hItem, bool bSelect);
80 float CalcItemHeight();
81
82 protected:
83 CFWL_ListBox(CFWL_App* pApp,
84 const Properties& properties,
85 CFWL_Widget* pOuter);
86
87 Item* GetListItem(Item* hItem, XFA_FWL_VKEYCODE dwKeyCode);
88 void SetSelection(Item* hStart, Item* hEnd, bool bSelected);
89 Item* GetItemAtPoint(const CFX_PointF& point);
90 bool ScrollToVisible(Item* hItem);
93 bool IsShowVertScrollBar() const;
94 bool IsShowHorzScrollBar() const;
95 bool ScrollBarPropertiesPresent() const;
96 CFWL_ScrollBar* GetVertScrollBar() const { return m_pVertScrollBar; }
97 const CFX_RectF& GetRTClient() const { return m_ClientRect; }
98
99 private:
100 bool IsMultiSelection() const;
101 void ClearSelection();
102 void SelectAll();
103 Item* GetFocusedItem();
104 void SetFocusItem(Item* hItem);
105 void DrawBkground(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
106 void DrawItems(CFGAS_GEGraphics* pGraphics, const CFX_Matrix& mtMatrix);
107 void DrawItem(CFGAS_GEGraphics* pGraphics,
108 Item* hItem,
109 int32_t Index,
110 const CFX_RectF& rtItem,
111 const CFX_Matrix& pMatrix);
112 void DrawStatic(CFGAS_GEGraphics* pGraphics);
113 CFX_SizeF CalcSize();
114 void UpdateItemSize(Item* hItem,
115 CFX_SizeF& size,
116 float fWidth,
117 float fHeight) const;
118 float GetMaxTextWidth();
119 float GetScrollWidth();
120
121 void OnFocusGained();
122 void OnFocusLost();
123 void OnLButtonDown(CFWL_MessageMouse* pMsg);
124 void OnLButtonUp(CFWL_MessageMouse* pMsg);
125 void OnMouseWheel(CFWL_MessageMouseWheel* pMsg);
126 void OnKeyDown(CFWL_MessageKey* pMsg);
127 void OnVK(Item* hItem, bool bShift, bool bCtrl);
128 bool OnScroll(CFWL_ScrollBar* pScrollBar,
129 CFWL_EventScroll::Code dwCode,
130 float fPos);
131
132 CFX_RectF m_ClientRect;
133 CFX_RectF m_StaticRect;
134 CFX_RectF m_ContentRect;
135 cppgc::Member<CFWL_ScrollBar> m_pHorzScrollBar;
136 cppgc::Member<CFWL_ScrollBar> m_pVertScrollBar;
137 FDE_TextStyle m_TTOStyles;
139 bool m_bLButtonDown = false;
140 float m_fItemHeight = 0.0f;
141 float m_fScorllBarWidth = 0.0f;
142 std::vector<std::unique_ptr<Item>> m_ItemArray; // Must outlive `m_hAnchor`.
143 UnownedPtr<Item> m_hAnchor;
144};
145
146} // namespace pdfium
147
148// TODO(crbug.com/42271761): Remove.
149using pdfium::CFWL_ListBox;
150
151#endif // XFA_FWL_CFWL_LISTBOX_H_
#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:40
#define FWL_STYLEEXT_EDT_HAlignModeMask
Definition cfwl_edit.h:41
#define FWL_STYLEEXT_EDT_HAlignMask
Definition cfwl_edit.h:39
#define FWL_STYLEEXT_EDT_VNear
Definition cfwl_edit.h:35
#define FWL_STYLEEXT_EDT_VCenter
Definition cfwl_edit.h:36
#define FWL_STYLEEXT_EDT_ReadOnly
Definition cfwl_edit.h:23
#define FWL_STYLEEXT_EDT_VFar
Definition cfwl_edit.h:37
#define FWL_STYLEEXT_EDT_HNear
Definition cfwl_edit.h:32
#define FWL_STYLEEXT_EDT_Justified
Definition cfwl_edit.h:38
#define FWL_STYLEEXT_EDT_HCenter
Definition cfwl_edit.h:33
#define FWL_STYLEEXT_LTB_CenterAlign
#define FWL_STYLEEXT_LTB_LeftAlign
#define FWL_STATE_WGT_Invisible
Definition cfwl_widget.h:45
#define FWL_STYLE_WGT_VScroll
Definition cfwl_widget.h:39
#define FWL_STATE_WGT_Focused
Definition cfwl_widget.h:44
#define FWL_STYLE_WGT_Border
Definition cfwl_widget.h:38
StateRestorer(CFGAS_GEGraphics *graphics)
void ConcatMatrix(const CFX_Matrix &matrix)
constexpr 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)
bool operator==(const WideString &other) const
WideString()=default
void ProcessSelChanged(bool bLButtonUp)
void Trace(cppgc::Visitor *visitor) const override
std::optional< WideString > EditCut()
bool EditCanSelectAll() const
void SetCurSel(int32_t iSel)
void SetEditText(const WideString &wsText)
void SetStates(uint32_t dwStates) override
void OnProcessEvent(CFWL_Event *pEvent) override
void RemoveAt(int32_t iIndex)
void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved) override
bool EditCanRedo() const
bool EditCanCopy() const
WideString GetTextByIndex(int32_t iIndex) const
std::optional< WideString > EditCopy() const
bool EditPaste(const WideString &wsPaste)
CFX_RectF GetBBox() const
void Update() override
~CFWL_ComboBox() override
FWL_Type GetClassID() const override
void AddString(const WideString &wsText)
WideString GetEditText() const
bool EditCanCut() const
int32_t GetCurSel() const
bool EditCanUndo() const
int32_t GetCurrentSelection() const
void RemoveStates(uint32_t dwStates) override
void EditModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
CFWL_ComboEdit * GetComboEdit() const
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
void OnProcessMessage(CFWL_Message *pMessage) override
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
FWL_WidgetHit HitTest(const CFX_PointF &point) override
void OnProcessMessage(CFWL_Message *pMessage) override
~CFWL_ComboEdit() override
int32_t MatchItem(WideStringView wsMatch)
~CFWL_ComboList() override
void ChangeSelected(int32_t iSel)
void OnProcessMessage(CFWL_Message *pMessage) override
Type GetType() const
Definition cfwl_event.h:41
CFWL_Widget * GetSrcTarget() const
Definition cfwl_event.h:42
Item(const WideString &text)
WideString GetText() const
CFX_RectF GetRect() const
void SetSelected(bool enable)
void SetRect(const CFX_RectF &rect)
void SetFocused(bool enable)
void OnDrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
bool ScrollBarPropertiesPresent() const
bool IsShowHorzScrollBar() const
void Update() override
int32_t GetSelIndex(int32_t nIndex)
Item * GetItemAtPoint(const CFX_PointF &point)
Item * GetItem(const CFWL_Widget *pWidget, int32_t nIndex) const
void DeleteString(Item *pItem)
FWL_Type GetClassID() const override
bool ScrollToVisible(Item *hItem)
void SetSelItem(Item *hItem, bool bSelect)
void RemoveAt(int32_t iIndex)
Item * GetListItem(Item *hItem, XFA_FWL_VKEYCODE dwKeyCode)
CFWL_ListBox(CFWL_App *pApp, const Properties &properties, CFWL_Widget *pOuter)
FWL_WidgetHit HitTest(const CFX_PointF &point) override
const CFX_RectF & GetRTClient() const
Item * GetSelItem(int32_t nIndexSel)
void OnProcessMessage(CFWL_Message *pMessage) override
void DrawWidget(CFGAS_GEGraphics *pGraphics, const CFX_Matrix &matrix) override
int32_t CountItems(const CFWL_Widget *pWidget) const
void SetSelection(Item *hStart, Item *hEnd, bool bSelected)
Item * AddString(const WideString &wsAdd)
CFWL_ScrollBar * GetVertScrollBar() const
~CFWL_ListBox() override
void Trace(cppgc::Visitor *visitor) const override
bool IsShowVertScrollBar() const
void OnProcessEvent(CFWL_Event *pEvent) override
int32_t GetItemIndex(CFWL_Widget *pWidget, Item *pItem)
const uint32_t m_dwKeyCodeOrChar
const KeyCommand m_dwCmd
CFWL_MessageKillFocus(CFWL_Widget *pDstTarget)
Type GetType() const
CFWL_Widget * GetDstTarget() const
void OnProcessMessage(CFWL_Message *pMessage) override
void RepaintRect(const CFX_RectF &pRect)
virtual void RemoveStates(uint32_t dwStates)
void DispatchEvent(CFWL_Event *pEvent)
CFWL_Widget(CFWL_App *app, const Properties &properties, CFWL_Widget *pOuter)
float GetCXBorderSize() const
virtual void ModifyStyleExts(uint32_t dwStyleExtsAdded, uint32_t dwStyleExtsRemoved)
virtual CFX_RectF GetClientRect()
uint32_t GetStyleExts() const
IFWL_ThemeProvider * GetThemeProvider() const
bool IsLocked() const
CFWL_WidgetMgr * GetWidgetMgr() const
Properties m_Properties
virtual void SetStates(uint32_t dwStates)
virtual float GetScrollBarWidth() const =0
virtual CFX_RectF GetUIMargin(const CFWL_ThemePart &pThemePart) const =0
CFX_PTemplate< float > CFX_PointF
CFX_STemplate< float > CFX_SizeF
#define CONSTRUCT_VIA_MAKE_GARBAGE_COLLECTED
Definition heap.h:32
FDE_TextAlignment
Definition cfde_data.h:14
@ XFA_FWL_VKEY_Up
@ XFA_FWL_VKEY_Return
@ XFA_FWL_VKEY_Escape
@ XFA_FWL_VKEY_Down
fxcrt::WideStringView WideStringView
fxcrt::WideString WideString
Definition widestring.h:207