1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_CSVRULER_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_CSVRULER_HXX
23 #include "csvcontrol.hxx"
24 #include "csvsplits.hxx"
27 #include <vcl/virdev.hxx>
29 class ScAccessibleCsvControl
;
32 /** A ruler control for the CSV import dialog. Supports setting and moving
33 splits (which divide lines of data into several columns). */
34 class ScCsvRuler
: public ScCsvControl
37 ScCsvTableBox
* mpTableBox
; /// Grid Parent
39 ScopedVclPtrInstance
<VirtualDevice
> maBackgrDev
;/// Ruler background, scaling.
40 ScopedVclPtrInstance
<VirtualDevice
> maRulerDev
; /// Ruler with splits and cursor.
42 Color maBackColor
; /// Background color.
43 Color maActiveColor
; /// Color for active part of ruler.
44 Color maTextColor
; /// Text and scale color.
45 Color maSplitColor
; /// Split area color.
47 ScCsvSplits maSplits
; /// Vector with split positions.
48 ScCsvSplits maOldSplits
; /// Old state for cancellation.
50 sal_Int32 mnPosCursorLast
; /// Last valid position of cursor.
51 sal_Int32 mnPosMTStart
; /// Start position of mouse tracking.
52 sal_Int32 mnPosMTCurr
; /// Current position of mouse tracking.
53 bool mbPosMTMoved
; /// Tracking: Anytime moved to another position?
55 Size maWinSize
; /// Size of the control.
56 tools::Rectangle maActiveRect
; /// The active area of the ruler.
57 sal_Int32 mnSplitSize
; /// Size of a split circle.
58 bool mbTracking
; /// If currently mouse tracking
61 explicit ScCsvRuler(const ScCsvLayoutData
& rData
, ScCsvTableBox
* pTableBox
);
62 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
63 ScCsvTableBox
* GetTableBox() { return mpTableBox
; }
64 virtual ~ScCsvRuler() override
;
66 // common ruler handling --------------------------------------------------
68 /** Apply current layout data to the ruler. */
69 void ApplyLayout( const ScCsvLayoutData
& rOldData
);
72 /** Reads colors from system settings. */
74 /** Initializes all data dependent from the control's size. */
77 /** Moves cursor to a new position.
78 @param bScroll sal_True = The method may scroll the ruler. */
79 void MoveCursor( sal_Int32 nPos
, bool bScroll
= true );
80 /** Moves cursor to the given direction. */
81 void MoveCursorRel( ScMoveMode eDir
);
82 /** Sets cursor to an existing split, according to eDir. */
83 void MoveCursorToSplit( ScMoveMode eDir
);
84 /** Scrolls data grid vertically. */
85 void ScrollVertRel( ScMoveMode eDir
);
87 // split handling ---------------------------------------------------------
89 /** Returns the split array. */
90 const ScCsvSplits
& GetSplits() const { return maSplits
; }
91 /** Returns the number of splits. */
92 sal_uInt32
GetSplitCount() const
93 { return maSplits
.Count(); }
94 /** Returns the position of the specified split. */
95 sal_Int32
GetSplitPos( sal_uInt32 nIndex
) const
96 { return maSplits
[ nIndex
]; }
97 /** Finds a position nearest to nPos which does not cause scrolling the visible area. */
98 sal_Int32
GetNoScrollPos( sal_Int32 nPos
) const;
100 /** Returns true if at position nPos is a split. */
101 bool HasSplit( sal_Int32 nPos
) const { return maSplits
.HasSplit( nPos
); }
102 /** Inserts a split. */
103 void InsertSplit( sal_Int32 nPos
);
104 /** Removes a split. */
105 void RemoveSplit( sal_Int32 nPos
);
106 /** Moves a split from nPos to nNewPos. */
107 void MoveSplit( sal_Int32 nPos
, sal_Int32 nNewPos
);
108 /** Removes all splits of the ruler. */
109 void RemoveAllSplits();
112 /** Finds next position without a split. */
113 sal_Int32
FindEmptyPos( sal_Int32 nPos
, ScMoveMode eDir
) const;
115 /** Moves split and cursor to nNewPos and commits event. */
116 void MoveCurrSplit( sal_Int32 nNewPos
);
117 /** Moves split and cursor to the given direction and commits event. */
118 void MoveCurrSplitRel( ScMoveMode eDir
);
120 // event handling ---------------------------------------------------------
122 virtual void Resize() override
;
123 virtual void GetFocus() override
;
124 virtual void LoseFocus() override
;
125 virtual void StyleUpdated() override
;
127 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
128 virtual bool MouseMove( const MouseEvent
& rMEvt
) override
;
129 virtual bool MouseButtonUp( const MouseEvent
& rMEvt
) override
;
131 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
133 virtual tools::Rectangle
GetFocusRect() override
;
136 /** Starts tracking at the specified position. */
137 void StartMouseTracking( sal_Int32 nPos
);
138 /** Moves tracking to a new position. */
139 void MoveMouseTracking( sal_Int32 nPos
);
140 /** Applies tracking action for the current tracking position */
141 void EndMouseTracking();
143 // painting ---------------------------------------------------------------
145 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& ) override
;
148 /** Redraws the entire ruler. */
149 void ImplRedraw(vcl::RenderContext
& rRenderContext
);
152 /** Returns the width of the control. */
153 sal_Int32
GetWidth() const { return maWinSize
.Width(); }
154 /** Returns the height of the control. */
155 sal_Int32
GetHeight() const { return maWinSize
.Height(); }
156 /** Update the split size depending on the last width set by CSVCMD_SETCHARWIDTH */
157 void UpdateSplitSize();
159 /** Draws the background and active area to maBackgrDev (only the given X range). */
160 void ImplDrawArea( sal_Int32 nPosX
, sal_Int32 nWidth
);
161 /** Draws the entire ruler background with scaling to maBackgrDev. */
162 void ImplDrawBackgrDev();
164 /** Draws a split to maRulerDev. */
165 void ImplDrawSplit( sal_Int32 nPos
);
166 /** Erases a split from maRulerDev. */
167 void ImplEraseSplit( sal_Int32 nPos
);
168 /** Draws the ruler background, all splits and the cursor to maRulerDev. */
169 void ImplDrawRulerDev();
171 /** Inverts the cursor bar at the specified position in maRulerDev. */
172 void ImplInvertCursor( sal_Int32 nPos
);
174 /** Sets arrow or horizontal split pointer. */
175 void ImplSetMousePointer( sal_Int32 nPos
);
177 // accessibility ----------------------------------------------------------
179 /** Creates a new accessible object. */
180 virtual css::uno::Reference
<css::accessibility::XAccessible
> CreateAccessible() override
;
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */