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