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