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