Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sc/source/ui/inc/olinewin.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
#include <vcl/window.hxx>
23
#include "viewdata.hxx"
24
25
class ScOutlineEntry;
26
class ScOutlineArray;
27
28
enum ScOutlineMode { SC_OUTLINE_HOR, SC_OUTLINE_VER };
29
30
/** The window left of or above the spreadsheet containing the outline groups
31
    and controls to expand/collapse them. */
32
class ScOutlineWindow : public vcl::Window
33
{
34
private:
35
    ScViewData&                 mrViewData;         /// View data containing the document.
36
    ScSplitPos                  meWhich;            /// Which area in split window.
37
    bool                        mbHoriz;            /// true = Horizontal orientation.
38
    bool                        mbMirrorEntries;    /// true = mirror the order of entries (including header)
39
    bool                        mbMirrorLevels;     /// true = mirror the order of levels, including the border
40
41
    Color                       maLineColor;        /// Line color for expanded groups.
42
    tools::Long                        mnHeaderSize;       /// Size of the header area in entry direction.
43
    tools::Long                        mnHeaderPos;        /// Position of the header area in entry direction.
44
    tools::Long                        mnMainFirstPos;     /// First position of main area in entry direction.
45
    tools::Long                        mnMainLastPos;      /// Last position of main area in entry direction.
46
47
    size_t                      mnMTLevel;          /// Mouse tracking: Level of active button.
48
    size_t                      mnMTEntry;          /// Mouse tracking: Entry index of active button.
49
    bool                        mbMTActive;         /// Mouse tracking active?
50
    bool                        mbMTPressed;        /// Mouse tracking: Button currently drawn pressed?
51
52
    tools::Rectangle                   maFocusRect;        /// Focus rectangle on screen.
53
    size_t                      mnFocusLevel;       /// Level of focused button.
54
    size_t                      mnFocusEntry;       /// Entry index of focused button.
55
    bool                        mbDontDrawFocus;    /// Do not redraw focus in next Paint().
56
57
public:
58
                                ScOutlineWindow(
59
                                    vcl::Window* pParent,
60
                                    ScOutlineMode eMode,
61
                                    ScViewData& rViewData,
62
                                    ScSplitPos eWhich );
63
    virtual                     ~ScOutlineWindow() override;
64
    virtual void                dispose() override;
65
66
    /** Sets the size of the header area (width/height dep. on window type). */
67
    void                        SetHeaderSize( tools::Long nNewSize );
68
    /** Returns the width/height the window needs to show all levels. */
69
    tools::Long                        GetDepthSize() const;
70
71
    /** Scrolls the window content by the specified amount of pixels. */
72
    void                        ScrollPixel( tools::Long nDiff );
73
74
    using Window::ShowFocus;
75
76
private:
77
    /** Initializes color and image settings. */
78
    void                        InitSettings();
79
80
    /** Returns the calc document. */
81
0
    ScDocument&          GetDoc() const { return mrViewData.GetDocument(); }
82
    /** Returns the current sheet index. */
83
0
    SCTAB                GetTab() const { return mrViewData.GetTabNo(); }
84
    /** Returns the outline array of the corresponding document. */
85
    const ScOutlineArray*       GetOutlineArray() const;
86
    /** Returns the specified outline entry. */
87
    const ScOutlineEntry*       GetOutlineEntry( size_t nLevel, size_t nEntry ) const;
88
89
    /** Returns true, if the column/row is hidden. */
90
    bool                        IsHidden( SCCOLROW nColRowIndex ) const;
91
    /** Returns true, if the column/row is filtered. */
92
    bool                        IsFiltered( SCCOLROW nColRowIndex ) const;
93
    /** Returns true, if all columns/rows before nColRowIndex are hidden. */
94
    bool                        IsFirstVisible( SCCOLROW nColRowIndex ) const;
95
    /** Returns the currently visible column/row range. */
96
    void                        GetVisibleRange( SCCOLROW& rnColRowStart, SCCOLROW& rnColRowEnd ) const;
97
98
    /** Returns the point in the window of the specified position. */
99
    Point                       GetPoint( tools::Long nLevelPos, tools::Long nEntryPos ) const;
100
    /** Returns the rectangle in the window of the specified position. */
101
    tools::Rectangle                   GetRectangle(
102
                                    tools::Long nLevelStart, tools::Long nEntryStart,
103
                                    tools::Long nLevelEnd, tools::Long nEntryEnd ) const;
104
105
    /** Returns the window size for the level coordinate. */
106
    tools::Long                        GetOutputSizeLevel() const;
107
    /** Returns the window size for the entry coordinate. */
108
    tools::Long                        GetOutputSizeEntry() const;
109
110
    /** Returns the count of levels of the outline array. 0 means no outlines. */
111
    size_t                      GetLevelCount() const;
112
    /** Returns the pixel position of the specified level. */
113
    tools::Long                        GetLevelPos( size_t nLevel ) const;
114
    /** Returns the level of the passed pixel position. */
115
    size_t                      GetLevelFromPos( tools::Long nLevelPos ) const;
116
117
    /** Returns the start coordinate of the specified column/row in the window. */
118
    tools::Long                        GetColRowPos( SCCOLROW nColRowIndex ) const;
119
    /** Returns the entry position of header images. */
120
    tools::Long                        GetHeaderEntryPos() const;
121
    /** Calculates the coordinates the outline entry takes in the window.
122
        @return  false = no part of the group is visible (outside window or collapsed by parent group). */
123
    bool                        GetEntryPos(
124
                                    size_t nLevel, size_t nEntry,
125
                                    tools::Long& rnStartPos, tools::Long& rnEndPos, tools::Long& rnImagePos ) const;
126
    /** Calculates the absolute position of the image of the specified outline entry.
127
        @param nLevel  The level of the entry.
128
        @param nEntry  The entry index or SC_OL_HEADERENTRY for the header image.
129
        @return  false = image is not visible. */
130
    bool                        GetImagePos( size_t nLevel, size_t nEntry, Point& rPos ) const;
131
    /** Returns true, if the button of the specified entry is visible in the window. */
132
    bool                        IsButtonVisible( size_t nLevel, size_t nEntry ) const;
133
134
    /** Returns true, if rPos is inside of a button or over the line of an expanded
135
        group. The outline entry data is stored in the passed variables. */
136
    bool                        ItemHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry, bool& rbButton ) const;
137
    /** Returns true, if rPos is inside of a button.
138
        The button data is stored in the passed variables. */
139
    bool                        ButtonHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry ) const;
140
    /** Returns true, if rPos is over the line of an expanded group.
141
        The outline entry data is stored in the passed variables. */
142
    bool                        LineHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry ) const;
143
144
    /** Performs an action with the specified item.
145
        @param nLevel  The level of the entry.
146
        @param nEntry  The entry index or SC_OL_HEADERENTRY for the header entry. */
147
    void                        DoFunction( size_t nLevel, size_t nEntry ) const;
148
    /** Expands the specified entry (does nothing with header entries). */
149
    void                        DoExpand( size_t nLevel, size_t nEntry ) const;
150
    /** Collapses the specified entry (does nothing with header entries). */
151
    void                        DoCollapse( size_t nLevel, size_t nEntry ) const;
152
153
    /** Returns true, if the focused button is visible in the window. */
154
    bool                        IsFocusButtonVisible() const;
155
156
    /** Calculates index of next/previous focus button in the current level (no paint).
157
        @param bFindVisible  true = repeats until a visible button has been found.
158
        @return  true = focus wrapped from end to start or vice versa. */
159
    bool                        ImplMoveFocusByEntry( bool bForward, bool bFindVisible );
160
    /** Calculates position of focus button in next/previous level (no paint).
161
        @return  true = focus wrapped from end to start or vice versa. */
162
    bool                        ImplMoveFocusByLevel( bool bForward );
163
    /** Calculates position of focus button in tab order.
164
        Repeats until a visible button has been found.
165
        @return  true = focus wrapped from end to start or vice versa. */
166
    bool                        ImplMoveFocusByTabOrder( bool bForward );
167
168
    /** If the focused entry is invisible, tries to move to visible position. */
169
    void                        ImplMoveFocusToVisible( bool bForward );
170
171
    /** Focuses next/previous button in the current level. */
172
    void                        MoveFocusByEntry( bool bForward );
173
    /** Focuses button in next/previous level. */
174
    void                        MoveFocusByLevel( bool bForward );
175
    /** Focuses next/previous button in tab order. */
176
    void                        MoveFocusByTabOrder( bool bForward );
177
178
    /** Starts mouse tracking after click on a button. */
179
    void                        StartMouseTracking( size_t nLevel, size_t nEntry );
180
    /** Returns whether mouse tracking mode is active. */
181
0
    bool                 IsMouseTracking() const { return mbMTActive; }
182
    /** Ends mouse tracking. */
183
    void                        EndMouseTracking();
184
185
    /** Sets a clip region for the window area without header. */
186
    void                        SetEntryAreaClipRegion();
187
    /** Converts coordinates to real window points and draws the line. */
188
    void                        DrawLineRel(
189
                                    tools::Long nLevelStart, tools::Long nEntryStart,
190
                                    tools::Long nLevelEnd, tools::Long nEntryEnd );
191
    /** Converts coordinates to real window points and draws the rectangle. */
192
    void                        DrawRectRel(
193
                                    tools::Long nLevelStart, tools::Long nEntryStart,
194
                                    tools::Long nLevelEnd, tools::Long nEntryEnd );
195
    /** Draws the specified image unpressed. */
196
    void                        DrawImageRel(tools::Long nLevelPos, tools::Long nEntryPos, const OUString& rId);
197
    /** Draws a pressed or unpressed border. */
198
    void                        DrawBorderRel(size_t nLevel, size_t nEntry, bool bPressed);
199
200
    /** Draws the focus rectangle into the focused button. */
201
    void                        ShowFocus();
202
    /** Erases the focus rectangle from the focused button. */
203
    void                        HideFocus();
204
205
    /** Scrolls the specified range of the window in entry-relative direction. */
206
    void                        ScrollRel( tools::Long nEntryDiff, tools::Long nEntryStart, tools::Long nEntryEnd );
207
208
protected:
209
    virtual void                Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
210
211
    virtual void                Resize() override;
212
    virtual void                GetFocus() override;
213
    virtual void                LoseFocus() override;
214
215
    virtual void                MouseMove( const MouseEvent& rMEvt ) override;
216
    virtual void                MouseButtonUp( const MouseEvent& rMEvt ) override;
217
    virtual void                MouseButtonDown( const MouseEvent& rMEvt ) override;
218
219
    virtual void                KeyInput( const KeyEvent& rKEvt ) override;
220
221
public:
222
    virtual void                DataChanged( const DataChangedEvent& rDCEvt ) override;
223
};
224
225
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */