summaryrefslogtreecommitdiff
path: root/sc/source/ui/inc/olinewin.hxx
blob: 104f9e8f11da4037a6e7fe14daaeeb11bdc27dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef SC_OLINEWIN_HXX
#define SC_OLINEWIN_HXX

#include "viewdata.hxx"

class ScOutlineEntry;
class ScOutlineArray;
class ScOutlineTable;


// ============================================================================

enum ScOutlineMode { SC_OUTLINE_HOR, SC_OUTLINE_VER };


// ----------------------------------------------------------------------------

/** The window left of or above the spreadsheet containing the outline groups
    and controls to expand/collapse them. */
class ScOutlineWindow : public Window
{
private:
    ScViewData&                 mrViewData;         /// View data containing the document.
    ScSplitPos                  meWhich;            /// Which area in split window.
    bool                        mbHoriz;            /// true = Horizontal orientation.
    bool                        mbMirrorEntries;    /// true = mirror the order of entries (including header)
    bool                        mbMirrorLevels;     /// true = mirror the order of levels, including the border

    ImageList*                  mpSymbols;          /// Symbols for buttons.
    Color                       maLineColor;        /// Line color for expanded groups.
    long                        mnHeaderSize;       /// Size of the header area in entry direction.
    long                        mnHeaderPos;        /// Position of the header area in entry direction.
    long                        mnMainFirstPos;     /// First position of main area in entry direction.
    long                        mnMainLastPos;      /// Last position of main area in entry direction.

    size_t                      mnMTLevel;          /// Mouse tracking: Level of active button.
    size_t                      mnMTEntry;          /// Mouse tracking: Entry index of active button.
    bool                        mbMTActive;         /// Mouse tracking active?
    bool                        mbMTPressed;        /// Mouse tracking: Button currently drawed pressed?

    Rectangle                   maFocusRect;        /// Focus rectangle on screen.
    size_t                      mnFocusLevel;       /// Level of focused button.
    size_t                      mnFocusEntry;       /// Entry index of focused button.
    bool                        mbDontDrawFocus;    /// Do not redraw focus in next Paint().

public:
                                ScOutlineWindow(
                                    Window* pParent,
                                    ScOutlineMode eMode,
                                    ScViewData* pViewData,
                                    ScSplitPos eWhich );
    virtual                     ~ScOutlineWindow();

    /** Sets the size of the header area (width/height dep. on window type). */
    void                        SetHeaderSize( long nNewSize );
    /** Returns the width/height the window needs to show all levels. */
    long                        GetDepthSize() const;

    /** Scrolls the window content by the specified amount of pixels. */
    void                        ScrollPixel( long nDiff );

    using Window::ShowFocus;

private:
    /** Initializes color and image settings. */
    void                        InitSettings();

    /** Returns the calc document. */
    inline ScDocument&          GetDoc() const { return *mrViewData.GetDocument(); }
    /** Returns the current sheet index. */
    inline SCTAB                GetTab() const { return mrViewData.GetTabNo(); }
    /** Returns the outline array of the corresponding document. */
    const ScOutlineArray*       GetOutlineArray() const;
    /** Returns the specified outline entry. */
    const ScOutlineEntry*       GetOutlineEntry( size_t nLevel, size_t nEntry ) const;

    /** Returns true, if the column/row is hidden. */
    bool                        IsHidden( SCCOLROW nColRowIndex ) const;
    /** Returns true, if the column/row is filtered. */
    bool                        IsFiltered( SCCOLROW nColRowIndex ) const;
    /** Returns true, if all columns/rows before nColRowIndex are hidden. */
    bool                        IsFirstVisible( SCCOLROW nColRowIndex ) const;
    /** Returns the currently visible column/row range. */
    void                        GetVisibleRange( SCCOLROW& rnColRowStart, SCCOLROW& rnColRowEnd ) const;

    /** Returns the point in the window of the specified position. */
    Point                       GetPoint( long nLevelPos, long nEntryPos ) const;
    /** Returns the rectangle in the window of the specified position. */
    Rectangle                   GetRectangle(
                                    long nLevelStart, long nEntryStart,
                                    long nLevelEnd, long nEntryEnd ) const;

    /** Returns the window size for the level coordinate. */
    long                        GetOutputSizeLevel() const;
    /** Returns the window size for the entry coordinate. */
    long                        GetOutputSizeEntry() const;

    /** Returns the count of levels of the outline array. 0 means no outlines. */
    size_t                      GetLevelCount() const;
    /** Returns the pixel position of the specified level. */
    long                        GetLevelPos( size_t nLevel ) const;
    /** Returns the level of the passed pixel position. */
    size_t                      GetLevelFromPos( long nLevelPos ) const;

    /** Returns the start coordinate of the specified column/row in the window. */
    long                        GetColRowPos( SCCOLROW nColRowIndex ) const;
    /** Returns the entry position of header images. */
    long                        GetHeaderEntryPos() const;
    /** Calculates the coordinates the outline entry takes in the window.
        @return  false = no part of the group is visible (outside window or collapsed by parent group). */
    bool                        GetEntryPos(
                                    size_t nLevel, size_t nEntry,
                                    long& rnStartPos, long& rnEndPos, long& rnImagePos ) const;
    /** Calculates the absolute position of the image of the specified outline entry.
        @param nLevel  The level of the entry.
        @param nEntry  The entry index or SC_OL_HEADERENTRY for the header image.
        @return  false = image is not visible. */
    bool                        GetImagePos( size_t nLevel, size_t nEntry, Point& rPos ) const;
    /** Returns true, if the button of the specified entry is visible in the window. */
    bool                        IsButtonVisible( size_t nLevel, size_t nEntry ) const;

    /** Returns true, if rPos is inside of a button or over the line of an expanded
        group. The outline entry data is stored in the passed variables. */
    bool                        ItemHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry, bool& rbButton ) const;
    /** Returns true, if rPos is inside of a button.
        The button data is stored in the passed variables. */
    bool                        ButtonHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry ) const;
    /** Returns true, if rPos is over the line of an expanded group.
        The outline entry data is stored in the passed variables. */
    bool                        LineHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry ) const;

    /** Performs an action with the specified item.
        @param nLevel  The level of the entry.
        @param nEntry  The entry index or SC_OL_HEADERENTRY for the header entry. */
    void                        DoFunction( size_t nLevel, size_t nEntry ) const;
    /** Expands the specified entry (does nothing with header entries). */
    void                        DoExpand( size_t nLevel, size_t nEntry ) const;
    /** Collapses the specified entry (does nothing with header entries). */
    void                        DoCollapse( size_t nLevel, size_t nEntry ) const;

    /** Returns true, if the focused button is visible in the window. */
    bool                        IsFocusButtonVisible() const;

    /** Calculates index of next/previous focus button in the current level (no paint).
        @param bFindVisible  true = repeats until a visible button has been found.
        @return  true = focus wrapped from end to start or vice versa. */
    bool                        ImplMoveFocusByEntry( bool bForward, bool bFindVisible );
    /** Calculates position of focus button in next/previous level (no paint).
        @return  true = focus wrapped from end to start or vice versa. */
    bool                        ImplMoveFocusByLevel( bool bForward );
    /** Calculates position of focus button in tab order.
        @param bFindVisible  true = repeats until a visible button has been found.
        @return  true = focus wrapped from end to start or vice versa. */
    bool                        ImplMoveFocusByTabOrder( bool bForward, bool bFindVisible );

    /** If the focused entry is invisible, tries to move to visible position. */
    void                        ImplMoveFocusToVisible( bool bForward );

    /** Focuses next/previous button in the current level. */
    void                        MoveFocusByEntry( bool bForward );
    /** Focuses button in next/previous level. */
    void                        MoveFocusByLevel( bool bForward );
    /** Focuses next/previous button in tab order. */
    void                        MoveFocusByTabOrder( bool bForward );

    /** Starts mouse tracking after click on a button. */
    void                        StartMouseTracking( size_t nLevel, size_t nEntry );
    /** Returns whether mouse tracking mode is active. */
    inline bool                 IsMouseTracking() const { return mbMTActive; }
    /** Ends mouse tracking. */
    void                        EndMouseTracking();

    /** Sets a clip region for the window area without header. */
    void                        SetEntryAreaClipRegion();
    /** Converts coordinates to real window points and draws the line. */
    void                        DrawLineRel(
                                    long nLevelStart, long nEntryStart,
                                    long nLevelEnd, long nEntryEnd );
    /** Converts coordinates to real window points and draws the rectangle. */
    void                        DrawRectRel(
                                    long nLevelStart, long nEntryStart,
                                    long nLevelEnd, long nEntryEnd );
    /** Draws the specified image unpressed. */
    void                        DrawImageRel( long nLevelPos, long nEntryPos, USHORT nId );
    /** Draws a pressed or unpressed border. */
    void                        DrawBorderRel( size_t nLevel, size_t nEntry, bool bPressed );

    /** Draws the focus rectangle into the focused button. */
    void                        ShowFocus();
    /** Erases the focus rectangle from the focused button. */
    void                        HideFocus();

    /** Scrolls the specified range of the window in entry-relative direction. */
    void                        ScrollRel( long nEntryDiff, long nEntryStart, long nEntryEnd );

protected:
    virtual void                Paint( const Rectangle& rRect );

    virtual void                Resize();
    virtual void                GetFocus();
    virtual void                LoseFocus();

    virtual void                MouseMove( const MouseEvent& rMEvt );
    virtual void                MouseButtonUp( const MouseEvent& rMEvt );
    virtual void                MouseButtonDown( const MouseEvent& rMEvt );

    virtual void                KeyInput( const KeyEvent& rKEvt );

public:
    virtual void                DataChanged( const DataChangedEvent& rDCEvt );
};


// ============================================================================

#endif