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