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/fxcrt/numerics/safe_conversions.h"
13#include "core/fxge/cfx_renderdevice.h"
14#include "fpdfsdk/pwl/cpwl_edit.h"
15#include "fpdfsdk/pwl/cpwl_edit_impl.h"
16#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
17#include "fpdfsdk/pwl/ipwl_fillernotify.h"
18#include "public/fpdf_fwlevent.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_ListBox> this_observed(this);
209 WideString swChange = this_observed->GetText();
210 WideString strChangeEx;
211 int nSelStart = 0;
212 int nSelEnd = pdfium::checked_cast<int>(swChange.GetLength());
214 this_observed->GetFillerNotify()->OnBeforeKeyStroke(
215 this_observed->GetAttachedData(), swChange, strChangeEx, nSelStart,
216 nSelEnd, bKeyDown, nFlag);
217 if (!this_observed) {
218 return false;
219 }
220 return result.exit;
221}
222
224 if (m_pListCtrl->IsMultipleSel()) {
225 CFX_FloatRect rcCaret = m_pListCtrl->GetItemRect(m_pListCtrl->GetCaret());
227 return rcCaret;
228 }
229
230 return CPWL_Wnd::GetFocusRect();
231}
232
234 m_pListCtrl->AddString(str);
235}
236
238 return m_pListCtrl->GetText();
239}
240
241void CPWL_ListBox::SetFontSize(float fFontSize) {
242 m_pListCtrl->SetFontSize(fFontSize);
243}
244
245float CPWL_ListBox::GetFontSize() const {
246 return m_pListCtrl->GetFontSize();
247}
248
249void CPWL_ListBox::OnSetScrollInfoY(float fPlateMin,
250 float fPlateMax,
251 float fContentMin,
252 float fContentMax,
253 float fSmallStep,
254 float fBigStep) {
255 PWL_SCROLL_INFO Info;
256 Info.fPlateWidth = fPlateMax - fPlateMin;
257 Info.fContentMin = fContentMin;
258 Info.fContentMax = fContentMax;
259 Info.fSmallStep = fSmallStep;
260 Info.fBigStep = fBigStep;
261 SetScrollInfo(Info);
262
263 CPWL_ScrollBar* pScroll = GetVScrollBar();
264 if (!pScroll)
265 return;
266
268 Info.fContentMax - Info.fContentMin) ||
270 Info.fContentMax - Info.fContentMin)) {
271 if (pScroll->IsVisible() && pScroll->SetVisible(false)) {
273 }
274 return;
275 }
276 if (!pScroll->IsVisible() && pScroll->SetVisible(true)) {
278 }
279}
280
284
286 return InvalidateRect(&rect);
287}
288
289void CPWL_ListBox::Select(int32_t nItemIndex) {
290 m_pListCtrl->Select(nItemIndex);
291}
292
293void CPWL_ListBox::Deselect(int32_t nItemIndex) {
294 m_pListCtrl->Deselect(nItemIndex);
295}
296
297void CPWL_ListBox::SetCaret(int32_t nItemIndex) {
298 m_pListCtrl->SetCaret(nItemIndex);
299}
300
301void CPWL_ListBox::SetTopVisibleIndex(int32_t nItemIndex) {
302 m_pListCtrl->SetTopItem(nItemIndex);
303}
304
305void CPWL_ListBox::ScrollToListItem(int32_t nItemIndex) {
306 m_pListCtrl->ScrollToListItem(nItemIndex);
307}
308
310 return m_pListCtrl->IsMultipleSel();
311}
312
313int32_t CPWL_ListBox::GetCaretIndex() const {
314 return m_pListCtrl->GetCaret();
315}
316
317int32_t CPWL_ListBox::GetCurSel() const {
318 return m_pListCtrl->GetSelect();
319}
320
321bool CPWL_ListBox::IsItemSelected(int32_t nItemIndex) const {
322 return m_pListCtrl->IsItemSelected(nItemIndex);
323}
324
326 m_pListCtrl->ScrollToListItem(m_pListCtrl->GetFirstSelected());
327 return m_pListCtrl->GetTopItem();
328}
329
330int32_t CPWL_ListBox::GetCount() const {
331 return m_pListCtrl->GetCount();
332}
333
335 return m_pListCtrl->GetContentRect();
336}
337
339 return m_pListCtrl->GetFirstHeight();
340}
341
343 float width = static_cast<float>(GetBorderWidth() + GetInnerBorderWidth());
344 return GetWindowRect().GetDeflated(width, width);
345}
346
347bool CPWL_ListBox::OnMouseWheel(Mask<FWL_EVENTFLAG> nFlag,
348 const CFX_PointF& point,
349 const CFX_Vector& delta) {
350 if (delta.y < 0)
351 m_pListCtrl->OnVK_DOWN(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
352 else
353 m_pListCtrl->OnVK_UP(IsSHIFTKeyDown(nFlag), IsCTRLKeyDown(nFlag));
354
356 return true;
357}
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:572
void SetCapture()
Definition cpwl_wnd.cpp:519
virtual bool OnChar(uint16_t nChar, Mask< FWL_EVENTFLAG > nFlag)
Definition cpwl_wnd.cpp:310
IPWL_FillerNotify * GetFillerNotify() const
Definition cpwl_wnd.h:245
bool HasFlag(uint32_t dwFlags) const
Definition cpwl_wnd.cpp:463
virtual CFX_FloatRect GetClientRect() const
Definition cpwl_wnd.cpp:445
CFX_FloatRect GetWindowRect() const
Definition cpwl_wnd.cpp:441
void ReleaseCapture()
Definition cpwl_wnd.cpp:525
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:298
int32_t GetBorderWidth() const
Definition cpwl_wnd.cpp:483
virtual void SetScrollInfo(const PWL_SCROLL_INFO &info)
Definition cpwl_wnd.cpp:429
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
Definition cpwl_wnd.cpp:278
virtual void SetFocus()
Definition cpwl_wnd.cpp:534
bool IsVisible() const
Definition cpwl_wnd.h:204
virtual CFX_FloatRect GetFocusRect() const
Definition cpwl_wnd.cpp:686
virtual bool SetVisible(bool bVisible)
Definition cpwl_wnd.cpp:576
IPWL_FillerNotify::PerWindowData * GetAttachedData() const
Definition cpwl_wnd.h:209
int32_t GetInnerBorderWidth() const
Definition cpwl_wnd.cpp:487
virtual void SetScrollPosition(float pos)
Definition cpwl_wnd.cpp:431
virtual void DrawThisAppearance(CFX_RenderDevice *pDevice, const CFX_Matrix &mtUser2Device)
Definition cpwl_wnd.cpp:250
CPWL_ScrollBar * GetVScrollBar() const
Definition cpwl_wnd.cpp:499
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
CFX_VTemplate< int32_t > CFX_Vector
CFX_PTemplate< float > CFX_PointF
constexpr FX_ARGB ArgbEncode(uint32_t a, uint32_t r, uint32_t g, uint32_t b)
Definition fx_dib.h:188
#define FXSYS_IsFloatBigger(fa, fb)
Definition fx_system.h:37
#define FXSYS_IsFloatEqual(fa, fb)
Definition fx_system.h:41
fxcrt::WideString WideString
Definition widestring.h:207