Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/include/vcl/toolkit/scrbar.hxx
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
5
 * This Source Code Form is subject to the terms of the Mozilla Public
6
 * License, v. 2.0. If a copy of the MPL was not distributed with this
7
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#pragma once
21
22
#if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS)
23
#error "don't use this in new code"
24
#endif
25
26
#include <config_options.h>
27
#include <vcl/dllapi.h>
28
#include <vcl/ctrl.hxx>
29
#include <vcl/scrollable.hxx>
30
#include <memory>
31
32
struct ImplScrollBarData;
33
34
class UNLESS_MERGELIBS_MORE(VCL_DLLPUBLIC) ScrollBar final : public Control
35
                              , public Scrollable
36
{
37
private:
38
    tools::Rectangle       maBtn1Rect;
39
    tools::Rectangle       maBtn2Rect;
40
    tools::Rectangle       maPage1Rect;
41
    tools::Rectangle       maPage2Rect;
42
    tools::Rectangle       maThumbRect;
43
    tools::Rectangle       maTrackRect;
44
    std::unique_ptr<ImplScrollBarData> mpData;
45
    tools::Long            mnStartPos;
46
    tools::Long            mnMouseOff;
47
    tools::Long            mnThumbPixRange;
48
    tools::Long            mnThumbPixPos;
49
    tools::Long            mnThumbPixSize;
50
    tools::Long            mnMinRange;
51
    tools::Long            mnMaxRange;
52
    tools::Long            mnThumbPos;
53
    tools::Long            mnVisibleSize;
54
    tools::Long            mnLineSize;
55
    tools::Long            mnPageSize;
56
    tools::Long            mnDelta;
57
    sal_uInt16      mnStateFlags;
58
    ScrollType      meScrollType;
59
    bool            mbCalcSize;
60
    bool            mbFullDrag;
61
    bool            mbSwapArrows;
62
    Link<ScrollBar*,void>       maScrollHdl;
63
    Link<ScrollBar*,void>       maEndScrollHdl;
64
65
    SAL_DLLPRIVATE tools::Rectangle*   ImplFindPartRect( const Point& rPt );
66
    using Window::ImplInit;
67
    SAL_DLLPRIVATE void         ImplInit( vcl::Window* pParent, WinBits nStyle );
68
    SAL_DLLPRIVATE void         ImplInitStyle( WinBits nStyle );
69
    SAL_DLLPRIVATE void         ImplUpdateRects( bool bUpdate = true );
70
    SAL_DLLPRIVATE tools::Long         ImplCalcThumbPos( tools::Long nPixPos ) const;
71
    SAL_DLLPRIVATE tools::Long         ImplCalcThumbPosPix( tools::Long nPos ) const;
72
    SAL_DLLPRIVATE void         ImplCalc( bool bUpdate = true );
73
    SAL_DLLPRIVATE void         ImplDraw(vcl::RenderContext& rRenderContext);
74
    using Window::ImplScroll;
75
    SAL_DLLPRIVATE tools::Long         ImplScroll( tools::Long nNewPos, bool bCallEndScroll );
76
    SAL_DLLPRIVATE tools::Long         ImplDoAction( bool bCallEndScroll );
77
    SAL_DLLPRIVATE void         ImplDoMouseAction( const Point& rPos, bool bCallAction = true );
78
    SAL_DLLPRIVATE void         ImplInvert();
79
    SAL_DLLPRIVATE bool         ImplDrawNative(vcl::RenderContext& rRenderContext, sal_uInt16 SystemTextColorFlags);
80
    SAL_DLLPRIVATE void         ImplDragThumb( const Point& rMousePos );
81
    SAL_DLLPRIVATE Size         getCurrentCalcSize() const;
82
    DECL_DLLPRIVATE_LINK( ImplAutoTimerHdl, Timer*, void );
83
84
    bool ImplHitTestBtn1(const Point& rPt) const;
85
    bool ImplHitTestBtn2(const Point& rPt) const;
86
    bool ImplHitTestPageUp(const Point& rPt) const;
87
    bool ImplHitTestPageDown(const Point& rPt) const;
88
    bool ImplHitTestThumb(const Point& rPt) const;
89
90
public:
91
    explicit        ScrollBar( vcl::Window* pParent, WinBits nStyle = WB_VERT );
92
    virtual         ~ScrollBar() override;
93
    virtual void    dispose() override;
94
95
    virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
96
97
    virtual void MouseButtonDown(const MouseEvent& rMEvt) override;
98
    virtual void Tracking(const TrackingEvent& rTEvt) override;
99
    virtual void KeyInput(const KeyEvent& rKEvt) override;
100
    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
101
    virtual void Draw(OutputDevice* pDev, const Point& rPos, SystemTextColorFlags nFlags) override;
102
    virtual void Move() override;
103
    virtual void Resize() override;
104
    virtual void StateChanged(StateChangedType nType) override;
105
    virtual void DataChanged(const DataChangedEvent& rDCEvt) override;
106
    virtual bool PreNotify(NotifyEvent& rNEvt) override;
107
    virtual void GetFocus() override;
108
    virtual void LoseFocus() override;
109
    virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
110
111
    using Window::Scroll;
112
    void Scroll();
113
    void EndScroll();
114
115
    tools::Long     DoScroll( tools::Long nNewPos ) override;
116
    tools::Long     DoScrollAction( ScrollType eScrollType );
117
118
0
    void            EnableDrag() { mbFullDrag = true; }
119
120
    void            SetRangeMin( tools::Long nNewRange ) override;
121
0
    tools::Long     GetRangeMin() const override { return mnMinRange; }
122
    void            SetRangeMax( tools::Long nNewRange ) override;
123
0
    tools::Long     GetRangeMax() const override { return mnMaxRange; }
124
    void            SetRange( const Range& rRange ) override;
125
0
    Range           GetRange() const override { return Range( GetRangeMin(), GetRangeMax() ); }
126
    void            SetThumbPos( tools::Long nThumbPos ) override;
127
0
    tools::Long     GetThumbPos() const override { return mnThumbPos; }
128
0
    void            SetLineSize( tools::Long nNewSize ) override { mnLineSize = nNewSize; }
129
0
    tools::Long     GetLineSize() const override { return mnLineSize; }
130
0
    void            SetPageSize( tools::Long nNewSize ) override { mnPageSize = nNewSize; }
131
0
    tools::Long     GetPageSize() const override { return mnPageSize; }
132
    void            SetVisibleSize( tools::Long nNewSize ) override;
133
0
    tools::Long     GetVisibleSize() const override { return mnVisibleSize; }
134
135
    bool Inactive() const override;
136
137
0
    tools::Long     GetDelta() const { return mnDelta; }
138
0
    ScrollType      GetType() const { return meScrollType; }
139
140
0
    void            SetScrollHdl( const Link<ScrollBar*,void>& rLink ) { maScrollHdl = rLink; }
141
0
    const Link<ScrollBar*,void>&   GetScrollHdl() const { return maScrollHdl; }
142
0
    void            SetEndScrollHdl( const Link<ScrollBar*,void>& rLink ) { maEndScrollHdl = rLink; }
143
144
    virtual Size    GetOptimalSize() const override;
145
146
0
    void            SetSwapArrows( bool bSwap ) { mbSwapArrows = bSwap; }
147
148
    bool            IsHorizontal() const;
149
    tools::Rectangle GetScrollbarRegion() const;
150
};
151
152
153
class UNLESS_MERGELIBS(VCL_DLLPUBLIC) ScrollBarBox final : public vcl::Window
154
{
155
private:
156
    using Window::ImplInit;
157
    SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
158
159
    virtual void ApplySettings(vcl::RenderContext& rRenderContext) override;
160
161
public:
162
    explicit        ScrollBarBox( vcl::Window* pParent, WinBits nStyle = 0 );
163
164
    virtual void    StateChanged( StateChangedType nType ) override;
165
    virtual void    DataChanged( const DataChangedEvent& rDCEvt ) override;
166
};
167
168
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */