Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / ui / inc / csvcontrol.hxx
bloba7d7a9765c9d759d82a72a34594cf2db6e037240
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 #ifndef INCLUDED_SC_SOURCE_UI_INC_CSVCONTROL_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_CSVCONTROL_HXX
23 #include <vcl/ctrl.hxx>
24 #include <scdllapi.h>
25 #include <address.hxx>
26 #include "csvsplits.hxx"
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <o3tl/typed_flags_set.hxx>
29 #include <rtl/ref.hxx>
30 #include <vcl/customweld.hxx>
31 #include "AccessibleCsvControl.hxx"
33 namespace com { namespace sun { namespace star { namespace accessibility {
34 class XAccessible;
35 } } } }
37 /** Minimum character count for a column in separators mode. */
38 const sal_Int32 CSV_MINCOLWIDTH = 8;
39 /** Maximum length of a cell string. */
40 const sal_Int32 CSV_MAXSTRLEN = 0x7FFF;
41 /** Transparency for header color of selected columns. */
42 const sal_uInt16 CSV_HDR_TRANSPARENCY = 85;
43 /** Minimum distance to border for auto scroll. */
44 const sal_Int32 CSV_SCROLL_DIST = 3;
46 //! TODO make string array dynamic
47 const sal_Int32 CSV_PREVIEW_LINES = 32; // maximum count of preview lines
48 /** Maximum count of columns. */
49 const sal_Int32 CSV_MAXCOLCOUNT = MAXCOLCOUNT;
51 /** Default column data type. */
52 const sal_Int32 CSV_TYPE_DEFAULT = 0;
53 /** Multi selection with different types. */
54 const sal_Int32 CSV_TYPE_MULTI = -1;
55 /** No column selected. */
56 const sal_Int32 CSV_TYPE_NOSELECTION = -2;
58 // External used column types.
59 const sal_uInt8 SC_COL_STANDARD = 1;
60 const sal_uInt8 SC_COL_TEXT = 2;
61 const sal_uInt8 SC_COL_MDY = 3;
62 const sal_uInt8 SC_COL_DMY = 4;
63 const sal_uInt8 SC_COL_YMD = 5;
64 const sal_uInt8 SC_COL_SKIP = 9;
65 const sal_uInt8 SC_COL_ENGLISH = 10;
67 /** Exported data of a column (data used in the dialog). */
68 struct ScCsvExpData
70 sal_Int32 mnIndex; /// Index of a column.
71 sal_uInt8 mnType; /// External type of the column.
73 ScCsvExpData() : mnIndex( 0 ), mnType( SC_COL_STANDARD ) {}
74 ScCsvExpData( sal_Int32 nIndex, sal_uInt8 nType ) :
75 mnIndex( nIndex ), mnType( nType ) {}
78 typedef ::std::vector< ScCsvExpData > ScCsvExpDataVec;
80 /** Specifies which element should be used to perform an action. */
81 enum ScMoveMode
83 MOVE_NONE, /// No action.
84 MOVE_FIRST, /// First element in current context.
85 MOVE_LAST, /// Last element in current context.
86 MOVE_PREV, /// Predecessor of current element in current context.
87 MOVE_NEXT, /// Successor of current element in current context.
88 MOVE_PREVPAGE, /// Previous page relative to current context.
89 MOVE_NEXTPAGE /// Next page relative to current context.
92 /** Flags for comparison of old and new control layout data. */
93 enum class ScCsvDiff : sal_uInt32 {
94 Equal = 0x0000,
95 PosCount = 0x0001,
96 PosOffset = 0x0002,
97 HeaderWidth = 0x0004,
98 CharWidth = 0x0008,
99 LineCount = 0x0010,
100 LineOffset = 0x0020,
101 HeaderHeight = 0x0040,
102 LineHeight = 0x0080,
103 RulerCursor = 0x0100,
104 GridCursor = 0x0200,
106 HorizontalMask = PosCount | PosOffset | HeaderWidth | CharWidth,
107 VerticalMask = LineCount | LineOffset | HeaderHeight | LineHeight
109 namespace o3tl {
110 template<> struct typed_flags<ScCsvDiff> : is_typed_flags<ScCsvDiff, 0x03ff> {};
114 /** A structure containing all layout data valid for both ruler and data grid
115 (i.e. scroll position or column width). */
116 struct ScCsvLayoutData
118 // horizontal settings
119 sal_Int32 mnPosCount; /// Number of positions.
120 sal_Int32 mnPosOffset; /// Horizontal scroll offset.
122 sal_Int32 mnWinWidth; /// Width of ruler and data grid.
123 sal_Int32 mnHdrWidth; /// Width of the header column.
124 sal_Int32 mnCharWidth; /// Pixel width of one character.
126 // vertical settings
127 sal_Int32 mnLineCount; /// Number of data lines.
128 sal_Int32 mnLineOffset; /// Index of first visible line (0-based).
130 sal_Int32 mnWinHeight; /// Height of entire data grid (incl. header).
131 sal_Int32 mnHdrHeight; /// Height of the header line.
132 sal_Int32 mnLineHeight; /// Height of a data line.
134 // cursor settings
135 sal_Int32 mnPosCursor; /// Position of ruler cursor.
136 sal_Int32 mnColCursor; /// Position of grid column cursor.
138 mutable sal_Int32 mnNoRepaint; /// >0 = no repaint.
139 bool const mbAppRTL; /// true = application in RTL mode.
141 explicit ScCsvLayoutData();
143 /** Returns differences to rData.
144 @descr For each difference the appropriate bit is set in the returned value. */
145 ScCsvDiff GetDiff( const ScCsvLayoutData& rData ) const;
148 inline bool operator==( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
150 return rData1.GetDiff( rData2 ) == ScCsvDiff::Equal;
153 inline bool operator!=( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
155 return !(rData1 == rData2);
158 /** Enumeration of possible commands to change any settings of the CSV controls.
159 @descr Controls have to send commands instead of changing their settings directly.
160 This helps to keep the different controls consistent to each other.
161 A command can contain 0 to 2 sal_Int32 parameters. In the description of each
162 command the required parameters are shown in brackets. [-] means no parameter. */
163 enum ScCsvCmdType
165 // misc
166 CSVCMD_NONE, /// No command. [-]
167 CSVCMD_REPAINT, /// Repaint all controls. [-]
169 // modify horizontal dimensions
170 CSVCMD_SETPOSCOUNT, /// Change position/column count. [character count]
171 CSVCMD_SETPOSOFFSET, /// Change position offset (scroll pos). [position]
172 CSVCMD_SETHDRWIDTH, /// Change width of the header column. [width in pixel]
173 CSVCMD_SETCHARWIDTH, /// Change character pixel width. [width in pixel]
175 // modify vertical dimensions
176 CSVCMD_SETLINECOUNT, /// Change number of data lines. [line count]
177 CSVCMD_SETLINEOFFSET, /// Change first visible line. [line index]
178 CSVCMD_SETHDRHEIGHT, /// Change height of top header line. [height in pixel]
179 CSVCMD_SETLINEHEIGHT, /// Change data line pixel height. [height in pixel}
181 // cursors/positions
182 CSVCMD_MOVERULERCURSOR, /// Move ruler cursor to new position. [position]
183 CSVCMD_MOVEGRIDCURSOR, /// Move data grid cursor to new column. [position]
184 CSVCMD_MAKEPOSVISIBLE, /// Move to make passed position visible (for mouse tracking). [position]
186 // table contents
187 CSVCMD_NEWCELLTEXTS, /// Recalculate splits and cell texts. [-]
188 CSVCMD_UPDATECELLTEXTS, /// Update cell texts with current split settings. [-]
189 CSVCMD_SETCOLUMNTYPE, /// Change data type of selected columns. [column type]
190 CSVCMD_EXPORTCOLUMNTYPE, /// Send selected column type to external controls. [-]
191 CSVCMD_SETFIRSTIMPORTLINE, /// Set number of first imported line. [line index]
193 // splits
194 CSVCMD_INSERTSPLIT, /// Insert a split. [position]
195 CSVCMD_REMOVESPLIT, /// Remove a split. [position]
196 CSVCMD_TOGGLESPLIT, /// Inserts or removes a split. [position]
197 CSVCMD_MOVESPLIT, /// Move a split. [old position, new position]
198 CSVCMD_REMOVEALLSPLITS /// Remove all splits. [-]
201 /** Data for a CSV control command. The stored position data is always character based,
202 it's never a column index (required for internal consistency). */
203 class ScCsvCmd
205 private:
206 ScCsvCmdType meType; /// The command.
207 sal_Int32 mnParam1; /// First parameter.
208 sal_Int32 mnParam2; /// Second parameter.
210 public:
211 explicit ScCsvCmd() : meType( CSVCMD_NONE ),
212 mnParam1( CSV_POS_INVALID ), mnParam2( CSV_POS_INVALID ) {}
214 inline void Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 );
216 ScCsvCmdType GetType() const { return meType; }
217 sal_Int32 GetParam1() const { return mnParam1; }
218 sal_Int32 GetParam2() const { return mnParam2; }
221 inline void ScCsvCmd::Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
223 meType = eType; mnParam1 = nParam1; mnParam2 = nParam2;
226 /** Base class for the CSV ruler and the data grid control. Implements command handling. */
227 class SC_DLLPUBLIC ScCsvControl : public weld::CustomWidgetController
229 private:
230 Link<ScCsvControl&,void> maCmdHdl; /// External command handler.
231 ScCsvCmd maCmd; /// Data of last command.
232 const ScCsvLayoutData& mrData; /// Shared layout data.
234 bool mbValidGfx; /// Content of virtual devices valid?
236 protected:
237 rtl::Reference<ScAccessibleCsvControl> mxAccessible; /// Reference to the accessible implementation object.
239 public:
240 explicit ScCsvControl(const ScCsvLayoutData& rData);
241 virtual ~ScCsvControl() override;
243 // event handling ---------------------------------------------------------
245 virtual void GetFocus() override;
246 virtual void LoseFocus() override;
248 /** Sends a GetFocus or LoseFocus event to the accessibility object. */
249 void AccSendFocusEvent( bool bFocused );
250 /** Sends a caret changed event to the accessibility object. */
251 void AccSendCaretEvent();
252 /** Sends a visible area changed event to the accessibility object. */
253 void AccSendVisibleEvent();
254 /** Sends a selection changed event to the accessibility object. */
255 void AccSendSelectionEvent();
256 /** Sends a table model changed event for changed cell contents to the accessibility object. */
257 void AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows = true );
258 /** Sends a table model changed event for an inserted column to the accessibility object. */
259 void AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
260 /** Sends a table model changed event for a removed column to the accessibility object. */
261 void AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
263 ScAccessibleCsvControl* GetAccessible() { return mxAccessible.get(); }
265 // repaint helpers --------------------------------------------------------
267 /** Sets the graphic invalid (next Redraw() will not use cached graphic). */
268 void InvalidateGfx() { mbValidGfx = false; }
269 /** Sets the graphic valid (next Redraw() will use cached graphic). */
270 void ValidateGfx() { mbValidGfx = true; }
271 /** Returns true, if cached graphic is valid. */
272 bool IsValidGfx() const { return mbValidGfx; }
274 /** Repaints all controls.
275 @param bInvalidate true = invalidates graphics of this control (not all). */
276 void Repaint( bool bInvalidate = false );
277 /** Increases no-repaint counter (controls do not repaint until the last EnableRepaint()). */
278 void DisableRepaint();
279 /** Decreases no-repaint counter and repaints if counter reaches 0. */
280 void EnableRepaint();
281 /** Returns true, if controls will not repaint. */
282 bool IsNoRepaint() const { return mrData.mnNoRepaint > 0; }
284 // command handling -------------------------------------------------------
286 /** Sets a new command handler. */
287 void SetCmdHdl( const Link<ScCsvControl&,void>& rHdl ) { maCmdHdl = rHdl; }
288 /** Returns data of the last command. */
289 const ScCsvCmd& GetCmd() const { return maCmd; }
291 /** Executes a command by calling command handler. */
292 void Execute(
293 ScCsvCmdType eType,
294 sal_Int32 nParam1 = CSV_POS_INVALID,
295 sal_Int32 nParam2 = CSV_POS_INVALID );
297 // layout helpers ---------------------------------------------------------
299 /** Returns a reference to the current layout data. */
300 const ScCsvLayoutData& GetLayoutData() const { return mrData; }
301 /** Returns true, if the Right-to-Left layout mode is active. */
302 bool IsRTL() const { return mrData.mbAppRTL; }
304 /** Returns the number of available positions. */
305 sal_Int32 GetPosCount() const { return mrData.mnPosCount; }
306 /** Returns the number of visible positions. */
307 sal_Int32 GetVisPosCount() const;
308 /** Returns the first visible position. */
309 sal_Int32 GetFirstVisPos() const { return mrData.mnPosOffset; }
310 /** Returns the last visible position. */
311 sal_Int32 GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); }
312 /** Returns highest possible position for first visible character. */
313 sal_Int32 GetMaxPosOffset() const;
315 /** Returns true, if it is allowed to set a split at nPos. */
316 bool IsValidSplitPos( sal_Int32 nPos ) const;
317 /** Returns true, if nPos is an allowed AND visible split position. */
318 bool IsVisibleSplitPos( sal_Int32 nPos ) const;
320 /** Returns the width of the header column. */
321 sal_Int32 GetHdrWidth() const { return mrData.mnHdrWidth; }
322 /** Returns the width of one character column. */
323 sal_Int32 GetCharWidth() const { return mrData.mnCharWidth; }
324 /** Returns the start position of the header column. */
325 sal_Int32 GetHdrX() const;
326 /** Returns the X position of the first pixel of the data area. */
327 sal_Int32 GetFirstX() const;
328 /** Returns the X position of the last pixel of the data area. */
329 sal_Int32 GetLastX() const;
330 /** Returns output X coordinate of the specified position. */
331 sal_Int32 GetX( sal_Int32 nPos ) const;
332 /** Returns position from output coordinate. */
333 sal_Int32 GetPosFromX( sal_Int32 nX ) const;
335 /** Returns the number of data lines. */
336 sal_Int32 GetLineCount() const { return mrData.mnLineCount; }
337 /** Returns the number of visible lines (including partly visible bottom line). */
338 sal_Int32 GetVisLineCount() const;
339 /** Returns index of first visible line. */
340 sal_Int32 GetFirstVisLine() const { return mrData.mnLineOffset; }
341 /** Returns index of last visible line. */
342 sal_Int32 GetLastVisLine() const;
343 /** Returns highest possible index for first line. */
344 sal_Int32 GetMaxLineOffset() const;
346 /** Returns true, if nLine is a valid line index. */
347 bool IsValidLine( sal_Int32 nLine ) const;
348 /** Returns true, if nLine is a valid and visible line index. */
349 bool IsVisibleLine( sal_Int32 nLine ) const;
351 /** Returns the height of the header line. */
352 sal_Int32 GetHdrHeight() const { return mrData.mnHdrHeight; }
353 /** Returns the height of one line. */
354 sal_Int32 GetLineHeight() const { return mrData.mnLineHeight; }
355 /** Returns output Y coordinate of the specified line. */
356 sal_Int32 GetY( sal_Int32 nLine ) const;
357 /** Returns line index from output coordinate. */
358 sal_Int32 GetLineFromY( sal_Int32 nY ) const;
360 /** Returns the ruler cursor position. */
361 sal_Int32 GetRulerCursorPos() const { return mrData.mnPosCursor; }
362 /** Returns the data grid cursor position (not column index!). */
363 sal_Int32 GetGridCursorPos() const { return mrData.mnColCursor; }
365 // static helpers ---------------------------------------------------------
367 /** Inverts a rectangle in the specified output device. */
368 static void ImplInvertRect( OutputDevice& rOutDev, const tools::Rectangle& rRect );
370 /** Returns direction code for the keys LEFT, RIGHT, HOME, END.
371 @param bHomeEnd false = ignore HOME and END key. */
372 static ScMoveMode GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd );
373 /** Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN.
374 @param bHomeEnd false = ignore HOME and END key. */
375 static ScMoveMode GetVertDirection( sal_uInt16 nCode, bool bHomeEnd );
378 #endif
380 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */