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 // ============================================================================ 29 30 #ifndef _SC_CSVRULER_HXX 31 #define _SC_CSVRULER_HXX 32 33 #include <vcl/virdev.hxx> 34 #include "csvcontrol.hxx" 35 #include "csvsplits.hxx" 36 #include "scdllapi.h" 37 38 class ScAccessibleCsvControl; 39 40 41 // ============================================================================ 42 43 /** A ruler control for the CSV import dialog. Supports setting and moving 44 splits (which divide lines of data into several columns). */ 45 class SC_DLLPUBLIC ScCsvRuler : public ScCsvControl 46 { 47 private: 48 VirtualDevice maBackgrDev; /// Ruler background, scaling. 49 VirtualDevice maRulerDev; /// Ruler with splits and cursor. 50 51 Color maBackColor; /// Background color. 52 Color maActiveColor; /// Color for active part of ruler. 53 Color maTextColor; /// Text and scale color. 54 Color maSplitColor; /// Split area color. 55 56 ScCsvSplits maSplits; /// Vector with split positions. 57 ScCsvSplits maOldSplits; /// Old state for cancellation. 58 59 sal_Int32 mnPosCursorLast; /// Last valid position of cursor. 60 sal_Int32 mnPosMTStart; /// Start position of mouse tracking. 61 sal_Int32 mnPosMTCurr; /// Current position of mouse tracking. 62 bool mbPosMTMoved; /// Tracking: Anytime moved to another position? 63 64 Size maWinSize; /// Size of the control. 65 Rectangle maActiveRect; /// The active area of the ruler. 66 sal_Int32 mnSplitSize; /// Size of a split circle. 67 68 // ------------------------------------------------------------------------ 69 public: 70 explicit ScCsvRuler( ScCsvControl& rParent ); 71 ~ScCsvRuler(); 72 73 // common ruler handling -------------------------------------------------- 74 public: 75 using Window::SetPosSizePixel; 76 /** Sets position and size of the ruler. The height is calculated internally. */ 77 virtual void SetPosSizePixel( 78 long nX, long nY, 79 long nWidth, long nHeight, 80 sal_uInt16 nFlags = WINDOW_POSSIZE_ALL ); 81 82 /** Apply current layout data to the ruler. */ 83 void ApplyLayout( const ScCsvLayoutData& rOldData ); 84 85 private: 86 /** Reads colors from system settings. */ 87 SC_DLLPRIVATE void InitColors(); 88 /** Initializes all data dependent from the control's size. */ 89 SC_DLLPRIVATE void InitSizeData(); 90 91 /** Moves cursor to a new position. 92 @param bScroll sal_True = The method may scroll the ruler. */ 93 SC_DLLPRIVATE void MoveCursor( sal_Int32 nPos, bool bScroll = true ); 94 /** Moves cursor to the given direction. */ 95 SC_DLLPRIVATE void MoveCursorRel( ScMoveMode eDir ); 96 /** Sets cursor to an existing split, according to eDir. */ 97 SC_DLLPRIVATE void MoveCursorToSplit( ScMoveMode eDir ); 98 /** Scrolls data grid vertically. */ 99 SC_DLLPRIVATE void ScrollVertRel( ScMoveMode eDir ); 100 101 // split handling --------------------------------------------------------- 102 public: 103 /** Returns the split array. */ 104 inline const ScCsvSplits& GetSplits() const { return maSplits; } 105 /** Returns the number of splits. */ 106 inline sal_uInt32 GetSplitCount() const 107 { return maSplits.Count(); } 108 /** Returns the position of the specified split. */ 109 inline sal_Int32 GetSplitPos( sal_uInt32 nIndex ) const 110 { return maSplits[ nIndex ]; } 111 /** Finds a position nearest to nPos which does not cause scrolling the visible area. */ 112 sal_Int32 GetNoScrollPos( sal_Int32 nPos ) const; 113 114 /** Returns true if at position nPos is a split. */ 115 inline bool HasSplit( sal_Int32 nPos ) const { return maSplits.HasSplit( nPos ); } 116 /** Inserts a split. */ 117 void InsertSplit( sal_Int32 nPos ); 118 /** Removes a split. */ 119 void RemoveSplit( sal_Int32 nPos ); 120 /** Moves a split from nPos to nNewPos. */ 121 void MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos ); 122 /** Removes all splits of the ruler. */ 123 void RemoveAllSplits(); 124 125 private: 126 /** Finds next position without a split. */ 127 SC_DLLPRIVATE sal_Int32 FindEmptyPos( sal_Int32 nPos, ScMoveMode eDir ) const; 128 129 /** Moves split and cursor to nNewPos and commits event. */ 130 SC_DLLPRIVATE void MoveCurrSplit( sal_Int32 nNewPos ); 131 /** Moves split and cursor to the given direction and commits event. */ 132 SC_DLLPRIVATE void MoveCurrSplitRel( ScMoveMode eDir ); 133 134 // event handling --------------------------------------------------------- 135 protected: 136 virtual void Resize(); 137 virtual void GetFocus(); 138 virtual void LoseFocus(); 139 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 140 141 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 142 virtual void MouseMove( const MouseEvent& rMEvt ); 143 virtual void Tracking( const TrackingEvent& rTEvt ); 144 145 virtual void KeyInput( const KeyEvent& rKEvt ); 146 147 private: 148 /** Starts tracking at the specified position. */ 149 SC_DLLPRIVATE void StartMouseTracking( sal_Int32 nPos ); 150 /** Moves tracking to a new position. */ 151 SC_DLLPRIVATE void MoveMouseTracking( sal_Int32 nPos ); 152 /** Applies tracking action for the current tracking position. 153 @param bApply sal_True = apply action, sal_False = cancel action. */ 154 SC_DLLPRIVATE void EndMouseTracking( bool bApply ); 155 156 // painting --------------------------------------------------------------- 157 protected: 158 virtual void Paint( const Rectangle& ); 159 160 public: 161 /** Redraws the entire ruler. */ 162 void ImplRedraw(); 163 164 private: 165 /** Returns the width of the control. */ 166 inline sal_Int32 GetWidth() const { return maWinSize.Width(); } 167 /** Returns the height of the control. */ 168 inline sal_Int32 GetHeight() const { return maWinSize.Height(); } 169 170 /** Draws the background and active area to maBackgrDev (only the given X range). */ 171 SC_DLLPRIVATE void ImplDrawArea( sal_Int32 nPosX, sal_Int32 nWidth ); 172 /** Draws the entire ruler background with scaling to maBackgrDev. */ 173 SC_DLLPRIVATE void ImplDrawBackgrDev(); 174 175 /** Draws a split to maRulerDev. */ 176 SC_DLLPRIVATE void ImplDrawSplit( sal_Int32 nPos ); 177 /** Erases a split from maRulerDev. */ 178 SC_DLLPRIVATE void ImplEraseSplit( sal_Int32 nPos ); 179 /** Draws the ruler background, all splits and the cursor to maRulerDev. */ 180 SC_DLLPRIVATE void ImplDrawRulerDev(); 181 182 /** Inverts the cursor bar at the specified position in maRulerDev. */ 183 SC_DLLPRIVATE void ImplInvertCursor( sal_Int32 nPos ); 184 /** Draws directly tracking rectangle to the column with the specified index. */ 185 SC_DLLPRIVATE void ImplDrawTrackingRect(); 186 187 /** Sets arrow or horizontal split pointer. */ 188 SC_DLLPRIVATE void ImplSetMousePointer( sal_Int32 nPos ); 189 190 // accessibility ---------------------------------------------------------- 191 protected: 192 /** Creates a new accessible object. */ 193 virtual ScAccessibleCsvControl* ImplCreateAccessible(); 194 }; 195 196 197 // ============================================================================ 198 199 #endif 200 201