tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / csvruler.hxx
blob5173f0d20002c373c172c01d49cbc84b6ca45996
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include "csvcontrol.hxx"
23 #include "csvsplits.hxx"
25 #include <vcl/virdev.hxx>
27 class ScAccessibleCsvControl;
28 class ScCsvTableBox;
30 /** A ruler control for the CSV import dialog. Supports setting and moving
31 splits (which divide lines of data into several columns). */
32 class ScCsvRuler : public ScCsvControl
34 private:
35 ScCsvTableBox* mpTableBox; /// Grid Parent
37 ScopedVclPtrInstance<VirtualDevice> maBackgrDev;/// Ruler background, scaling.
38 ScopedVclPtrInstance<VirtualDevice> maRulerDev; /// Ruler with splits and cursor.
40 Color maBackColor; /// Background color.
41 Color maActiveColor; /// Color for active part of ruler.
42 Color maTextColor; /// Text and scale color.
43 Color maSplitColor; /// Split area color.
45 ScCsvSplits maSplits; /// Vector with split positions.
46 ScCsvSplits maOldSplits; /// Old state for cancellation.
48 sal_Int32 mnPosCursorLast; /// Last valid position of cursor.
49 sal_Int32 mnPosMTStart; /// Start position of mouse tracking.
50 sal_Int32 mnPosMTCurr; /// Current position of mouse tracking.
51 bool mbPosMTMoved; /// Tracking: Anytime moved to another position?
53 Size maWinSize; /// Size of the control.
54 tools::Rectangle maActiveRect; /// The active area of the ruler.
55 sal_Int32 mnSplitSize; /// Size of a split circle.
56 bool mbTracking; /// If currently mouse tracking
58 public:
59 explicit ScCsvRuler(const ScCsvLayoutData& rData, ScCsvTableBox* pTableBox);
60 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
61 ScCsvTableBox* GetTableBox() { return mpTableBox; }
62 virtual ~ScCsvRuler() override;
64 // common ruler handling --------------------------------------------------
65 public:
66 /** Apply current layout data to the ruler. */
67 void ApplyLayout( const ScCsvLayoutData& rOldData );
69 private:
70 /** Reads colors from system settings. */
71 void InitColors();
72 /** Initializes all data dependent from the control's size. */
73 void InitSizeData();
75 /** Moves cursor to a new position.
76 @param bScroll sal_True = The method may scroll the ruler. */
77 void MoveCursor( sal_Int32 nPos, bool bScroll = true );
78 /** Moves cursor to the given direction. */
79 void MoveCursorRel( ScMoveMode eDir );
80 /** Sets cursor to an existing split, according to eDir. */
81 void MoveCursorToSplit( ScMoveMode eDir );
82 /** Scrolls data grid vertically. */
83 void ScrollVertRel( ScMoveMode eDir );
85 // split handling ---------------------------------------------------------
86 public:
87 /** Returns the split array. */
88 const ScCsvSplits& GetSplits() const { return maSplits; }
89 /** Returns the number of splits. */
90 sal_uInt32 GetSplitCount() const
91 { return maSplits.Count(); }
92 /** Returns the position of the specified split. */
93 sal_Int32 GetSplitPos( sal_uInt32 nIndex ) const
94 { return maSplits[ nIndex ]; }
95 /** Finds a position nearest to nPos which does not cause scrolling the visible area. */
96 sal_Int32 GetNoScrollPos( sal_Int32 nPos ) const;
98 /** Returns true if at position nPos is a split. */
99 bool HasSplit( sal_Int32 nPos ) const { return maSplits.HasSplit( nPos ); }
100 /** Inserts a split. */
101 void InsertSplit( sal_Int32 nPos );
102 /** Removes a split. */
103 void RemoveSplit( sal_Int32 nPos );
104 /** Moves a split from nPos to nNewPos. */
105 void MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos );
106 /** Removes all splits of the ruler. */
107 void RemoveAllSplits();
109 private:
110 /** Finds next position without a split. */
111 sal_Int32 FindEmptyPos( sal_Int32 nPos, ScMoveMode eDir ) const;
113 /** Moves split and cursor to nNewPos and commits event. */
114 void MoveCurrSplit( sal_Int32 nNewPos );
115 /** Moves split and cursor to the given direction and commits event. */
116 void MoveCurrSplitRel( ScMoveMode eDir );
118 // event handling ---------------------------------------------------------
119 protected:
120 virtual void Resize() override;
121 virtual void GetFocus() override;
122 virtual void LoseFocus() override;
123 virtual void StyleUpdated() override;
125 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
126 virtual bool MouseMove( const MouseEvent& rMEvt ) override;
127 virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override;
129 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
131 virtual tools::Rectangle GetFocusRect() override;
133 private:
134 /** Starts tracking at the specified position. */
135 void StartMouseTracking( sal_Int32 nPos );
136 /** Moves tracking to a new position. */
137 void MoveMouseTracking( sal_Int32 nPos );
138 /** Applies tracking action for the current tracking position */
139 void EndMouseTracking();
141 // painting ---------------------------------------------------------------
142 protected:
143 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
145 public:
146 /** Redraws the entire ruler. */
147 void ImplRedraw(vcl::RenderContext& rRenderContext);
149 private:
150 /** Returns the width of the control. */
151 sal_Int32 GetWidth() const { return maWinSize.Width(); }
152 /** Returns the height of the control. */
153 sal_Int32 GetHeight() const { return maWinSize.Height(); }
154 /** Update the split size depending on the last width set by CSVCMD_SETCHARWIDTH */
155 void UpdateSplitSize();
157 /** Draws the background and active area to maBackgrDev (only the given X range). */
158 void ImplDrawArea( sal_Int32 nPosX, sal_Int32 nWidth );
159 /** Draws the entire ruler background with scaling to maBackgrDev. */
160 void ImplDrawBackgrDev();
162 /** Draws a split to maRulerDev. */
163 void ImplDrawSplit( sal_Int32 nPos );
164 /** Erases a split from maRulerDev. */
165 void ImplEraseSplit( sal_Int32 nPos );
166 /** Draws the ruler background, all splits and the cursor to maRulerDev. */
167 void ImplDrawRulerDev();
169 /** Inverts the cursor bar at the specified position in maRulerDev. */
170 void ImplInvertCursor( sal_Int32 nPos );
172 /** Sets arrow or horizontal split pointer. */
173 void ImplSetMousePointer( sal_Int32 nPos );
175 // accessibility ----------------------------------------------------------
176 protected:
177 /** Creates a new accessible object. */
178 virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */