xref: /aoo42x/main/sc/source/ui/inc/olinewin.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_OLINEWIN_HXX
25 #define SC_OLINEWIN_HXX
26 
27 #include "viewdata.hxx"
28 
29 class ScOutlineEntry;
30 class ScOutlineArray;
31 class ScOutlineTable;
32 
33 
34 // ============================================================================
35 
36 enum ScOutlineMode { SC_OUTLINE_HOR, SC_OUTLINE_VER };
37 
38 
39 // ----------------------------------------------------------------------------
40 
41 /** The window left of or above the spreadsheet containing the outline groups
42     and controls to expand/collapse them. */
43 class ScOutlineWindow : public Window
44 {
45 private:
46     ScViewData&                 mrViewData;         /// View data containing the document.
47     ScSplitPos                  meWhich;            /// Which area in split window.
48     bool                        mbHoriz;            /// true = Horizontal orientation.
49     bool                        mbMirrorEntries;    /// true = mirror the order of entries (including header)
50     bool                        mbMirrorLevels;     /// true = mirror the order of levels, including the border
51 
52     ImageList*                  mpSymbols;          /// Symbols for buttons.
53     Color                       maLineColor;        /// Line color for expanded groups.
54     long                        mnHeaderSize;       /// Size of the header area in entry direction.
55     long                        mnHeaderPos;        /// Position of the header area in entry direction.
56     long                        mnMainFirstPos;     /// First position of main area in entry direction.
57     long                        mnMainLastPos;      /// Last position of main area in entry direction.
58 
59     size_t                      mnMTLevel;          /// Mouse tracking: Level of active button.
60     size_t                      mnMTEntry;          /// Mouse tracking: Entry index of active button.
61     bool                        mbMTActive;         /// Mouse tracking active?
62     bool                        mbMTPressed;        /// Mouse tracking: Button currently drawed pressed?
63 
64     Rectangle                   maFocusRect;        /// Focus rectangle on screen.
65     size_t                      mnFocusLevel;       /// Level of focused button.
66     size_t                      mnFocusEntry;       /// Entry index of focused button.
67     bool                        mbDontDrawFocus;    /// Do not redraw focus in next Paint().
68 
69 public:
70                                 ScOutlineWindow(
71                                     Window* pParent,
72                                     ScOutlineMode eMode,
73                                     ScViewData* pViewData,
74                                     ScSplitPos eWhich );
75     virtual                     ~ScOutlineWindow();
76 
77     /** Sets the size of the header area (width/height dep. on window type). */
78     void                        SetHeaderSize( long nNewSize );
79     /** Returns the width/height the window needs to show all levels. */
80     long                        GetDepthSize() const;
81 
82     /** Scrolls the window content by the specified amount of pixels. */
83     void                        ScrollPixel( long nDiff );
84 
85     using Window::ShowFocus;
86 
87 private:
88     /** Initializes color and image settings. */
89     void                        InitSettings();
90 
91     /** Returns the calc document. */
GetDoc() const92     inline ScDocument&          GetDoc() const { return *mrViewData.GetDocument(); }
93     /** Returns the current sheet index. */
GetTab() const94     inline SCTAB                GetTab() const { return mrViewData.GetTabNo(); }
95     /** Returns the outline array of the corresponding document. */
96     const ScOutlineArray*       GetOutlineArray() const;
97     /** Returns the specified outline entry. */
98     const ScOutlineEntry*       GetOutlineEntry( size_t nLevel, size_t nEntry ) const;
99 
100     /** Returns true, if the column/row is hidden. */
101     bool                        IsHidden( SCCOLROW nColRowIndex ) const;
102     /** Returns true, if the column/row is filtered. */
103     bool                        IsFiltered( SCCOLROW nColRowIndex ) const;
104     /** Returns true, if all columns/rows before nColRowIndex are hidden. */
105     bool                        IsFirstVisible( SCCOLROW nColRowIndex ) const;
106     /** Returns the currently visible column/row range. */
107     void                        GetVisibleRange( SCCOLROW& rnColRowStart, SCCOLROW& rnColRowEnd ) const;
108 
109     /** Returns the point in the window of the specified position. */
110     Point                       GetPoint( long nLevelPos, long nEntryPos ) const;
111     /** Returns the rectangle in the window of the specified position. */
112     Rectangle                   GetRectangle(
113                                     long nLevelStart, long nEntryStart,
114                                     long nLevelEnd, long nEntryEnd ) const;
115 
116     /** Returns the window size for the level coordinate. */
117     long                        GetOutputSizeLevel() const;
118     /** Returns the window size for the entry coordinate. */
119     long                        GetOutputSizeEntry() const;
120 
121     /** Returns the count of levels of the outline array. 0 means no outlines. */
122     size_t                      GetLevelCount() const;
123     /** Returns the pixel position of the specified level. */
124     long                        GetLevelPos( size_t nLevel ) const;
125     /** Returns the level of the passed pixel position. */
126     size_t                      GetLevelFromPos( long nLevelPos ) const;
127 
128     /** Returns the start coordinate of the specified column/row in the window. */
129     long                        GetColRowPos( SCCOLROW nColRowIndex ) const;
130     /** Returns the entry position of header images. */
131     long                        GetHeaderEntryPos() const;
132     /** Calculates the coordinates the outline entry takes in the window.
133         @return  false = no part of the group is visible (outside window or collapsed by parent group). */
134     bool                        GetEntryPos(
135                                     size_t nLevel, size_t nEntry,
136                                     long& rnStartPos, long& rnEndPos, long& rnImagePos ) const;
137     /** Calculates the absolute position of the image of the specified outline entry.
138         @param nLevel  The level of the entry.
139         @param nEntry  The entry index or SC_OL_HEADERENTRY for the header image.
140         @return  false = image is not visible. */
141     bool                        GetImagePos( size_t nLevel, size_t nEntry, Point& rPos ) const;
142     /** Returns true, if the button of the specified entry is visible in the window. */
143     bool                        IsButtonVisible( size_t nLevel, size_t nEntry ) const;
144 
145     /** Returns true, if rPos is inside of a button or over the line of an expanded
146         group. The outline entry data is stored in the passed variables. */
147     bool                        ItemHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry, bool& rbButton ) const;
148     /** Returns true, if rPos is inside of a button.
149         The button data is stored in the passed variables. */
150     bool                        ButtonHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry ) const;
151     /** Returns true, if rPos is over the line of an expanded group.
152         The outline entry data is stored in the passed variables. */
153     bool                        LineHit( const Point& rPos, size_t& rnLevel, size_t& rnEntry ) const;
154 
155     /** Performs an action with the specified item.
156         @param nLevel  The level of the entry.
157         @param nEntry  The entry index or SC_OL_HEADERENTRY for the header entry. */
158     void                        DoFunction( size_t nLevel, size_t nEntry ) const;
159     /** Expands the specified entry (does nothing with header entries). */
160     void                        DoExpand( size_t nLevel, size_t nEntry ) const;
161     /** Collapses the specified entry (does nothing with header entries). */
162     void                        DoCollapse( size_t nLevel, size_t nEntry ) const;
163 
164     /** Returns true, if the focused button is visible in the window. */
165     bool                        IsFocusButtonVisible() const;
166 
167     /** Calculates index of next/previous focus button in the current level (no paint).
168         @param bFindVisible  true = repeats until a visible button has been found.
169         @return  true = focus wrapped from end to start or vice versa. */
170     bool                        ImplMoveFocusByEntry( bool bForward, bool bFindVisible );
171     /** Calculates position of focus button in next/previous level (no paint).
172         @return  true = focus wrapped from end to start or vice versa. */
173     bool                        ImplMoveFocusByLevel( bool bForward );
174     /** Calculates position of focus button in tab order.
175         @param bFindVisible  true = repeats until a visible button has been found.
176         @return  true = focus wrapped from end to start or vice versa. */
177     bool                        ImplMoveFocusByTabOrder( bool bForward, bool bFindVisible );
178 
179     /** If the focused entry is invisible, tries to move to visible position. */
180     void                        ImplMoveFocusToVisible( bool bForward );
181 
182     /** Focuses next/previous button in the current level. */
183     void                        MoveFocusByEntry( bool bForward );
184     /** Focuses button in next/previous level. */
185     void                        MoveFocusByLevel( bool bForward );
186     /** Focuses next/previous button in tab order. */
187     void                        MoveFocusByTabOrder( bool bForward );
188 
189     /** Starts mouse tracking after click on a button. */
190     void                        StartMouseTracking( size_t nLevel, size_t nEntry );
191     /** Returns whether mouse tracking mode is active. */
IsMouseTracking() const192     inline bool                 IsMouseTracking() const { return mbMTActive; }
193     /** Ends mouse tracking. */
194     void                        EndMouseTracking();
195 
196     /** Sets a clip region for the window area without header. */
197     void                        SetEntryAreaClipRegion();
198     /** Converts coordinates to real window points and draws the line. */
199     void                        DrawLineRel(
200                                     long nLevelStart, long nEntryStart,
201                                     long nLevelEnd, long nEntryEnd );
202     /** Converts coordinates to real window points and draws the rectangle. */
203     void                        DrawRectRel(
204                                     long nLevelStart, long nEntryStart,
205                                     long nLevelEnd, long nEntryEnd );
206     /** Draws the specified image unpressed. */
207     void                        DrawImageRel( long nLevelPos, long nEntryPos, sal_uInt16 nId );
208     /** Draws a pressed or unpressed border. */
209     void                        DrawBorderRel( size_t nLevel, size_t nEntry, bool bPressed );
210 
211     /** Draws the focus rectangle into the focused button. */
212     void                        ShowFocus();
213     /** Erases the focus rectangle from the focused button. */
214     void                        HideFocus();
215 
216     /** Scrolls the specified range of the window in entry-relative direction. */
217     void                        ScrollRel( long nEntryDiff, long nEntryStart, long nEntryEnd );
218 
219 protected:
220     virtual void                Paint( const Rectangle& rRect );
221 
222     virtual void                Resize();
223     virtual void                GetFocus();
224     virtual void                LoseFocus();
225 
226     virtual void                MouseMove( const MouseEvent& rMEvt );
227     virtual void                MouseButtonUp( const MouseEvent& rMEvt );
228     virtual void                MouseButtonDown( const MouseEvent& rMEvt );
229 
230     virtual void                KeyInput( const KeyEvent& rKEvt );
231 
232 public:
233     virtual void                DataChanged( const DataChangedEvent& rDCEvt );
234 };
235 
236 
237 // ============================================================================
238 
239 #endif
240 
241