7#include "fpdfsdk/pwl/cpwl_scroll_bar.h"
15#include "core/fxcrt/check.h"
16#include "core/fxge/cfx_fillrenderoptions.h"
17#include "core/fxge/cfx_path.h"
18#include "core/fxge/cfx_renderdevice.h"
19#include "fpdfsdk/pwl/cpwl_wnd.h"
23constexpr float kButtonWidth = 9.0f;
24constexpr float kPosButtonMinWidth = 2.0f;
110 std::unique_ptr<IPWL_FillerNotify::PerWindowData> pAttachedData)
122 m_pMinButton.ExtractAsDangling();
123 m_pMaxButton.ExtractAsDangling();
124 m_pPosButton.ExtractAsDangling();
129 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
134 kButtonWidth * 2 + kPosButtonMinWidth + 2)) {
141 (rcClient
.top - rcClient
.bottom - kPosButtonMinWidth - 2) / 2;
148 if (!this_observed->SetVisible(
false)) {
153 if (this_observed->m_pMinButton) {
154 this_observed->m_pMinButton->Move(rcMinButton,
true,
false);
155 if (!this_observed) {
159 if (this_observed->m_pMaxButton) {
160 this_observed->m_pMaxButton->Move(rcMaxButton,
true,
false);
161 if (!this_observed) {
165 return this_observed->MovePosButton(
false);
177 &mtUser2Device
, CFX_PointF(rectWnd
.left + 2.0f, rectWnd
.top - 2.0f)
,
182 &mtUser2Device
, CFX_PointF(rectWnd
.right - 2.0f, rectWnd
.top - 2.0f)
,
200 if (m_pPosButton && m_pPosButton->IsVisible()) {
205 rcClient
.top - kButtonWidth
);
215 if (!MovePosButton(
true))
217 NotifyScrollWindow();
222 if (!MovePosButton(
true))
224 NotifyScrollWindow();
244 m_bMouseDown =
false;
249 if (info
== m_OriginInfo)
265 if (child == m_pMinButton)
266 OnMinButtonLBDown(pos);
267 else if (child == m_pMaxButton)
268 OnMaxButtonLBDown(pos);
269 else if (child == m_pPosButton)
270 OnPosButtonLBDown(pos);
274 if (child == m_pMinButton)
275 OnMinButtonLBUp(pos);
276 else if (child == m_pMaxButton)
277 OnMaxButtonLBUp(pos);
278 else if (child == m_pPosButton)
279 OnPosButtonLBUp(pos);
283 if (child == m_pMinButton)
284 OnMinButtonMouseMove(pos);
285 else if (child == m_pMaxButton)
286 OnMaxButtonMouseMove(pos);
287 else if (child == m_pPosButton)
288 OnPosButtonMouseMove(pos);
291void CPWL_ScrollBar::CreateButtons(
const CreateParams& cp) {
292 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
299 if (!this_observed->m_pMinButton) {
301 std::make_unique<CPWL_SBButton>(scp, this_observed->CloneAttachedData(),
303 this_observed->m_pMinButton = pButton.get();
304 this_observed->AddChild(
std::move(pButton));
305 this_observed->m_pMinButton->Realize();
307 if (!this_observed->m_pMaxButton) {
309 std::make_unique<CPWL_SBButton>(scp, this_observed->CloneAttachedData(),
311 this_observed->m_pMaxButton = pButton.get();
312 this_observed->AddChild(
std::move(pButton));
313 this_observed->m_pMaxButton->Realize();
315 if (!this_observed->m_pPosButton) {
317 std::make_unique<CPWL_SBButton>(scp, this_observed->CloneAttachedData(),
319 this_observed->m_pPosButton = pButton.get();
320 if (this_observed->m_pPosButton->SetVisible(
false) && this_observed) {
321 this_observed->AddChild(
std::move(pButton));
322 this_observed->m_pPosButton->Realize();
331void CPWL_ScrollBar::SetScrollRange(
float fMin,
333 float fClientWidth) {
334 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
335 if (!this_observed->m_pPosButton) {
338 this_observed->m_sData.SetScrollRange(fMin, fMax);
339 this_observed->m_sData.SetClientWidth(fClientWidth);
343 (
void)this_observed->m_pPosButton->SetVisible(
false);
349 if (!this_observed->m_pPosButton->SetVisible(
true) || !this_observed) {
353 (
void)this_observed->MovePosButton(
true);
358void CPWL_ScrollBar::SetScrollPos(
float fPos) {
362 (
void)MovePosButton(
true);
368void CPWL_ScrollBar::SetScrollStep(
float fBigStep,
float fSmallStep) {
373bool CPWL_ScrollBar::MovePosButton(
bool bRefresh) {
374 ObservedPtr<CPWL_ScrollBar> this_observed(
this);
379 if (this_observed->m_pPosButton->IsVisible()) {
381 float fTop = this_observed->TrueToFace(m_sData
.fScrollPos);
385 fBottom = fTop - kPosButtonMinWidth;
389 fTop = fBottom + kPosButtonMinWidth;
395 this_observed->m_pPosButton->Move(rcPosButton,
true, bRefresh);
396 if (!this_observed) {
403void CPWL_ScrollBar::OnMinButtonLBDown(
const CFX_PointF& point) {
405 if (!MovePosButton(
true))
408 NotifyScrollWindow();
410 m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(),
this, 100);
413void CPWL_ScrollBar::OnMinButtonLBUp(
const CFX_PointF& point) {}
415void CPWL_ScrollBar::OnMinButtonMouseMove(
const CFX_PointF& point) {}
417void CPWL_ScrollBar::OnMaxButtonLBDown(
const CFX_PointF& point) {
419 if (!MovePosButton(
true))
422 NotifyScrollWindow();
424 m_pTimer = std::make_unique<CFX_Timer>(GetTimerHandler(),
this, 100);
427void CPWL_ScrollBar::OnMaxButtonLBUp(
const CFX_PointF& point) {}
429void CPWL_ScrollBar::OnMaxButtonMouseMove(
const CFX_PointF& point) {}
431void CPWL_ScrollBar::OnPosButtonLBDown(
const CFX_PointF& point) {
437 m_fOldPosButton = rcPosButton
.top;
441void CPWL_ScrollBar::OnPosButtonLBUp(
const CFX_PointF& point) {
442 m_bMouseDown =
false;
445void CPWL_ScrollBar::OnPosButtonMouseMove(
const CFX_PointF& point) {
446 if (fabs(point.y - m_nOldPos) < 1)
450 float fNewPos = FaceToTrue(m_fOldPosButton + point.y - m_nOldPos);
463 if (!MovePosButton(
true))
466 NotifyScrollWindow();
471void CPWL_ScrollBar::NotifyScrollWindow() {
482 if (!m_pMinButton || !m_pMaxButton)
491 if (rcClient
.top - rcClient
.bottom > fMinHeight + fMaxHeight + 2) {
503float CPWL_ScrollBar::TrueToFace(
float fTrue) {
506 fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
507 return rcPosArea
.top -
508 fTrue * (rcPosArea
.top - rcPosArea
.bottom) / fFactWidth;
511float CPWL_ScrollBar::FaceToTrue(
float fFace) {
514 fFactWidth = fFactWidth == 0 ? 1 : fFactWidth;
515 return (rcPosArea
.top - fFace) * fFactWidth /
530 if (sTemp
== m_sData)
533 if (!MovePosButton(
true))
536 NotifyScrollWindow();
bool Contains(const CFX_PointF &point) const
constexpr CFX_FloatRect(float l, float b, float r, float t)
CFX_FloatRect & operator=(const CFX_FloatRect &that)=default
void DrawStrokeLine(const CFX_Matrix *pUser2Device, const CFX_PointF &ptMoveTo, const CFX_PointF &ptLineTo, const FX_COLORREF &color, float fWidth)
virtual void ScrollWindowVertically(float pos)
CFX_Color GetBackgroundColor() const
bool HasFlag(uint32_t dwFlags) const
virtual CFX_FloatRect GetClientRect() const
CFX_FloatRect GetWindowRect() const
CPWL_Wnd * GetParentWindow() const
void SetTransparency(int32_t nTransparency)
virtual bool OnLButtonUp(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
CreateParams * GetCreationParams()
virtual bool InvalidateRect(const CFX_FloatRect *pRect)
int32_t GetTransparency()
virtual bool OnLButtonDown(Mask< FWL_EVENTFLAG > nFlag, const CFX_PointF &point)
#define PWS_AUTOTRANSPARENT
#define PWS_NOREFRESHCLIP
CFX_PTemplate< float > CFX_PointF
#define FXSYS_IsFloatBigger(fa, fb)
#define FXSYS_IsFloatEqual(fa, fb)
#define FXSYS_IsFloatSmaller(fa, fb)
void Set(float min, float max)