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