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