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
cpwl_list_box.cpp
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#include "fpdfsdk/pwl/cpwl_list_box.h"
8
9#include <sstream>
10#include <utility>
11
12#include "core/fxge/cfx_renderdevice.h"
13#include "fpdfsdk/pwl/cpwl_edit.h"
14#include "fpdfsdk/pwl/cpwl_edit_impl.h"
15#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
16#include "fpdfsdk/pwl/ipwl_fillernotify.h"
17#include "public/fpdf_fwlevent.h"
18#include "third_party/base/numerics/safe_conversions.h"
19
21 const CreateParams& cp,
22 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
23 : CPWL_Wnd(cp, std::move(pAttachedData)),
25
26CPWL_ListBox::~CPWL_ListBox() = default;
27
29 m_pListCtrl->SetFontMap(GetFontMap());
30 m_pListCtrl->SetNotify(this);
31
33 m_pListCtrl->SetMultipleSel(HasFlag(PLBS_MULTIPLESEL));
34 m_pListCtrl->SetFontSize(GetCreationParams()->fFontSize);
35
37}
38
40 // Make sure the notifier is removed from the list as we are about to
41 // destroy the notifier and don't want to leave a dangling pointer.
42 m_pListCtrl->SetNotify(nullptr);
43}
44
46 const CFX_Matrix& mtUser2Device) {
47 CPWL_Wnd::DrawThisAppearance(pDevice, mtUser2Device);
48
49 CFX_FloatRect rcPlate = m_pListCtrl->GetPlateRect();
51 CFX_FloatRect rcClient = GetClientRect();
52
53 for (int32_t i = 0, sz = m_pListCtrl->GetCount(); i < sz; i++) {
54 CFX_FloatRect rcItem = m_pListCtrl->GetItemRect(i);
55 if (rcItem.bottom > rcPlate.top || rcItem.top < rcPlate.bottom)
56 continue;
57
58 CFX_PointF ptOffset(rcItem.left, (rcItem.top + rcItem.bottom) * 0.5f);
59 if (CPWL_EditImpl* pEdit = m_pListCtrl->GetItemEdit(i)) {
60 CFX_FloatRect rcContent = pEdit->GetContentRect();
61 rcItem.Intersect(rcContent.Width() > rcClient.Width() ? rcList
62 : rcClient);
63 }
64
65 IPWL_FillerNotify* pSysHandler = GetFillerNotify();
66 if (m_pListCtrl->IsItemSelected(i)) {
67 if (pSysHandler->IsSelectionImplemented()) {
68 m_pListCtrl->GetItemEdit(i)->DrawEdit(
69 pDevice, mtUser2Device, GetTextColor().ToFXColor(255), rcList,
70 ptOffset, nullptr, pSysHandler, GetAttachedData());
72 } else {
73 pDevice->DrawFillRect(&mtUser2Device, rcItem,
74 ArgbEncode(255, 0, 51, 113));
75 m_pListCtrl->GetItemEdit(i)->DrawEdit(
76 pDevice, mtUser2Device, ArgbEncode(255, 255, 255, 255), rcList,
77 ptOffset, nullptr, pSysHandler, GetAttachedData());
78 }
79 } else {
80 m_pListCtrl->GetItemEdit(i)->DrawEdit(
81 pDevice, mtUser2Device, GetTextColor().ToFXColor(255), rcList,
82 ptOffset, nullptr, pSysHandler, nullptr);
83 }
84 }
85}
86
87bool CPWL_ListBox::OnKeyDown(FWL_VKEYCODE nKeyCode, Mask<FWL_EVENTFLAG> nFlag) {
88 CPWL_Wnd::OnKeyDown(nKeyCode, nFlag);
89
90 switch (nKeyCode) {
91 default:
92 return false;
93 case FWL_VKEY_Up:
94 case FWL_VKEY_Down:
95 case FWL_VKEY_Home:
96 case FWL_VKEY_Left:
97 case FWL_VKEY_End:
98 case FWL_VKEY_Right:
99 break;
100 }
101
102 switch (nKeyCode) {
103 case FWL_VKEY_Up:
104 m_pListCtrl->OnVK_UP(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
105 break;
106 case FWL_VKEY_Down:
107 m_pListCtrl->OnVK_DOWN(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
108 break;
109 case FWL_VKEY_Home:
110 m_pListCtrl->OnVK_HOME(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
111 break;
112 case FWL_VKEY_Left:
113 m_pListCtrl->OnVK_LEFT(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
114 break;
115 case FWL_VKEY_End:
116 m_pListCtrl->OnVK_END(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
117 break;
118 case FWL_VKEY_Right:
119 m_pListCtrl->OnVK_RIGHT(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
120 break;
121 default:
122 break;
123 }
125 return true;
126}
127
128bool CPWL_ListBox::OnChar(uint16_t nChar, Mask<FWL_EVENTFLAG> nFlag) {
129 CPWL_Wnd::OnChar(nChar, nFlag);
130
131 if (!m_pListCtrl->OnChar(nChar, IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag)))
132 return false;
133
135 return true;
136}
137
138bool CPWL_ListBox::OnLButtonDown(Mask<FWL_EVENTFLAG> nFlag,
139 const CFX_PointF& point) {
141
142 if (ClientHitTest(point)) {
143 m_bMouseDown = true;
144 SetFocus();
145 SetCapture();
146
147 m_pListCtrl->OnMouseDown(point, IsSHIFTKeyDown(nFlag),
148 IsCTRLKeyDown(nFlag));
149 }
150
151 return true;
152}
153
154bool CPWL_ListBox::OnLButtonUp(Mask<FWL_EVENTFLAG> nFlag,
155 const CFX_PointF& point) {
156 CPWL_Wnd::OnLButtonUp(nFlag, point);
157
158 if (m_bMouseDown) {
160 m_bMouseDown = false;
161 }
163 return true;
164}
165
166void CPWL_ListBox::SetHoverSel(bool bHoverSel) {
167 m_bHoverSel = bHoverSel;
168}
169
170bool CPWL_ListBox::OnMouseMove(Mask<FWL_EVENTFLAG> nFlag,
171 const CFX_PointF& point) {
172 CPWL_Wnd::OnMouseMove(nFlag, point);
173
174 if (m_bHoverSel && !IsCaptureMouse() && ClientHitTest(point))
175 m_pListCtrl->Select(m_pListCtrl->GetItemIndex(point));
176 if (m_bMouseDown)
177 m_pListCtrl->OnMouseMove(point, IsSHIFTKeyDown(nFlag),
178 IsCTRLKeyDown(nFlag));
179
180 return true;
181}
182
184 if (CPWL_Wnd* pChild = GetVScrollBar())
185 pChild->SetScrollInfo(info);
186}
187
189 if (CPWL_Wnd* pChild = GetVScrollBar())
190 pChild->SetScrollPosition(pos);
191}
192
194 m_pListCtrl->SetScrollPos(CFX_PointF(0, pos));
195}
196
199 return false;
200 }
201
202 m_pListCtrl->SetPlateRect(GetListRect());
203 return true;
204}
205
207 Mask<FWL_EVENTFLAG> nFlag) {
208 ObservedPtr<CPWL_Wnd> this_observed(this);
209
210 WideString swChange = GetText();
211 WideString strChangeEx;
212 int nSelStart = 0;
213 int nSelEnd = pdfium::base::checked_cast<int>(swChange.GetLength());
215 GetFillerNotify()->OnBeforeKeyStroke(GetAttachedData(), swChange,
216 strChangeEx, nSelStart, nSelEnd,
217 bKeyDown, nFlag);
218
219 if (!this_observed) {
220 return false;
221 }
222 return result.exit;
223}
224
226 if (m_pListCtrl->IsMultipleSel()) {
227 CFX_FloatRect rcCaret = m_pListCtrl->GetItemRect(m_pListCtrl->GetCaret());
229 return rcCaret;
230 }
231
232 return CPWL_Wnd::GetFocusRect();
233}
234
235void CPWL_ListBox::AddString(const WideString& str) {
236 m_pListCtrl->AddString(str);
237}
238
239WideString CPWL_ListBox::GetText() {
240 return m_pListCtrl->GetText();
241}
242
243void CPWL_ListBox::SetFontSize(float fFontSize) {
244 m_pListCtrl->SetFontSize(fFontSize);
245}
246
247float CPWL_ListBox::GetFontSize() const {
248 return m_pListCtrl->GetFontSize();
249}
250
251void CPWL_ListBox::OnSetScrollInfoY(float fPlateMin,
252 float fPlateMax,
253 float fContentMin,
254 float fContentMax,
255 float fSmallStep,
256 float fBigStep) {
257 PWL_SCROLL_INFO Info;
258 Info.fPlateWidth = fPlateMax - fPlateMin;
259 Info.fContentMin = fContentMin;
260 Info.fContentMax = fContentMax;
261 Info.fSmallStep = fSmallStep;
262 Info.fBigStep = fBigStep;
263 SetScrollInfo(Info);
264
265 CPWL_ScrollBar* pScroll = GetVScrollBar();
266 if (!pScroll)
267 return;
268
270 Info.fContentMax - Info.fContentMin) ||
272 Info.fContentMax - Info.fContentMin)) {
273 if (pScroll->IsVisible() && pScroll->SetVisible(false)) {
275 }
276 return;
277 }
278 if (!pScroll->IsVisible() && pScroll->SetVisible(true)) {
280 }
281}
282
286
288 return InvalidateRect(&rect);
289}
290
291void CPWL_ListBox::Select(int32_t nItemIndex) {
292 m_pListCtrl->Select(nItemIndex);
293}
294
295void CPWL_ListBox::Deselect(int32_t nItemIndex) {
296 m_pListCtrl->Deselect(nItemIndex);
297}
298
299void CPWL_ListBox::SetCaret(int32_t nItemIndex) {
300 m_pListCtrl->SetCaret(nItemIndex);
301}
302
303void CPWL_ListBox::SetTopVisibleIndex(int32_t nItemIndex) {
304 m_pListCtrl->SetTopItem(nItemIndex);
305}
306
307void CPWL_ListBox::ScrollToListItem(int32_t nItemIndex) {
308 m_pListCtrl->ScrollToListItem(nItemIndex);
309}
310
312 return m_pListCtrl->IsMultipleSel();
313}
314
315int32_t CPWL_ListBox::GetCaretIndex() const {
316 return m_pListCtrl->GetCaret();
317}
318
319int32_t CPWL_ListBox::GetCurSel() const {
320 return m_pListCtrl->GetSelect();
321}
322
323bool CPWL_ListBox::IsItemSelected(int32_t nItemIndex) const {
324 return m_pListCtrl->IsItemSelected(nItemIndex);
325}
326
328 m_pListCtrl->ScrollToListItem(m_pListCtrl->GetFirstSelected());
329 return m_pListCtrl->GetTopItem();
330}
331
332int32_t CPWL_ListBox::GetCount() const {
333 return m_pListCtrl->GetCount();
334}
335
337 return m_pListCtrl->GetContentRect();
338}
339
341 return m_pListCtrl->GetFirstHeight();
342}
343
345 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
346 return GetWindowRect().GetDeflated(width, width);
347}
348
349bool CPWL_ListBox::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag,
350 const CFX_PointF& point,
351 const CFX_Vector& delta) {
352 if (delta.y < 0)
353 m_pListCtrl->OnVK_DOWN(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
354 else
355 m_pListCtrl->OnVK_UP(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
356
358 return true;
359}
float Width() const
void Intersect(const CFX_FloatRect &other_rect)
void DrawFillRect(const CFX_Matrix *pUser2Device, const CFX_FloatRect &rect, const FX_COLORREF &color)
CFX_FloatRect GetContentRect() const
void SetScrollPosition(float pos) override
void AddString(const WideString &str)
~CPWL_ListBox() override
void SetTopVisibleIndex(int32_t nItemIndex)
void SetScrollInfo(const PWL_SCROLL_INFO &info) override
void SetHoverSel(bool bHoverSel)
void SetFontSize(float fFontSize) override
void ScrollToListItem(int32_t nItemIndex)
bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag) override
void OnDestroy() override
void ScrollWindowVertically(float pos) override
int32_t GetCurSel() const
float GetFirstHeight() const
bool OnNotifySelectionChanged(bool bKeyDown, Mask< FWL_EVENTFLAG > nFlag)
CFX_FloatRect GetListRect() const
bool OnMouseWheel(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point, const CFX_Vector &delta) override
void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device) override
void Deselect(int32_t nItemIndex)
bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
CFX_FloatRect GetContentRect() const
WideString GetText() override
CPWL_ListBox(const CreateParams &cp, std::unique_ptr< IPWL_FillerNotify::PerWindowData > pAttachedData)
void Select(int32_t nItemIndex)
void OnCreated() override
int32_t GetTopVisibleIndex() const
CFX_FloatRect GetFocusRect() const override
bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
void OnSetScrollPosY(float fy) override
float GetFontSize() const override
bool OnInvalidateRect(const CFX_FloatRect &pRect) override
void SetCaret(int32_t nItemIndex)
void OnSetScrollInfoY(float fPlateMin, float fPlateMax, float fContentMin, float fContentMax, float fSmallStep, float fBigStep) override
bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point) override
int32_t GetCaretIndex() const
int32_t GetCount() const
bool IsMultipleSel() const
bool IsItemSelected(int32_t nItemIndex) const
bool RepositionChildWnd() override
bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag) override
bool ClientHitTest(const CFX_PointF &point) const
Definition cpwl_wnd.cpp:571
void SetCapture()
Definition cpwl_wnd.cpp:518
virtual bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:309
IPWL_FillerNotify * GetFillerNotify() const
Definition cpwl_wnd.h:245
bool HasFlag(uint32_t dwFlags) const
Definition cpwl_wnd.cpp:462
virtual CFX_FloatRect GetClientRect() const
Definition cpwl_wnd.cpp:444
CFX_FloatRect GetWindowRect() const
Definition cpwl_wnd.cpp:440
void ReleaseCapture()
Definition cpwl_wnd.cpp:524
virtual bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool OnMouseMove(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool RepositionChildWnd()
Definition cpwl_wnd.cpp:614
virtual bool OnKeyDown(FWL_VKEYCODE nKeyCode, Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:297
int32_t GetBorderWidth() const
Definition cpwl_wnd.cpp:482
virtual void SetScrollInfo(const PWL_SCROLL_INFO &info)
Definition cpwl_wnd.cpp:428
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
Definition cpwl_wnd.cpp:278
virtual void SetFocus()
Definition cpwl_wnd.cpp:533
bool IsVisible() const
Definition cpwl_wnd.h:204
virtual CFX_FloatRect GetFocusRect() const
Definition cpwl_wnd.cpp:689
virtual bool SetVisible(bool bVisible)
Definition cpwl_wnd.cpp:575
IPWL_FillerNotify::PerWindowData * GetAttachedData() const
Definition cpwl_wnd.h:209
int32_t GetInnerBorderWidth() const
Definition cpwl_wnd.cpp:486
virtual void SetScrollPosition(float pos)
Definition cpwl_wnd.cpp:430
virtual void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
Definition cpwl_wnd.cpp:250
CPWL_ScrollBar * GetVScrollBar() const
Definition cpwl_wnd.cpp:498
virtual bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
virtual bool IsSelectionImplemented() const =0
virtual void OutputSelectedRect(PerWindowData *pWidgetData, const CFX_FloatRect &rect)=0
#define PLBS_MULTIPLESEL
Definition cpwl_wnd.h:55
#define PLBS_HOVERSEL
Definition cpwl_wnd.h:56
@ FWL_VKEY_End
@ FWL_VKEY_Right
@ FWL_VKEY_Up
@ FWL_VKEY_Home
@ FWL_VKEY_Down
@ FWL_VKEY_Left
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:118
#define FXSYS_IsFloatBigger(fa, fb)
Definition fx_system.h:36
#define FXSYS_IsFloatEqual(fa, fb)
Definition fx_system.h:40