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