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