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 // ============================================================================
22 #ifndef _SC_CSVCONTROL_HXX
23 #define _SC_CSVCONTROL_HXX
25 #include <vcl/ctrl.hxx>
28 #include "address.hxx"
29 #include "csvsplits.hxx"
30 #include <com/sun/star/uno/Reference.hxx>
33 class ScAccessibleCsvControl
;
34 namespace com
{ namespace sun
{ namespace star
{ namespace accessibility
{
39 // ============================================================================
41 /** Minimum character count for a column in separators mode. */
42 const sal_Int32 CSV_MINCOLWIDTH
= 8;
43 /** Maximum length of a cell string. */
44 const xub_StrLen CSV_MAXSTRLEN
= 0x7FFF;
45 /** Transparency for header color of selected columns. */
46 const sal_uInt16 CSV_HDR_TRANSPARENCY
= 85;
47 /** Minimum distance to border for auto scroll. */
48 const sal_Int32 CSV_SCROLL_DIST
= 3;
50 //! TODO make string array dynamic
51 const sal_Int32 CSV_PREVIEW_LINES
= 32; // maximum count of preview lines
52 /** Maximum count of columns. */
53 const sal_Int32 CSV_MAXCOLCOUNT
= MAXCOLCOUNT
;
55 /** Default column data type. */
56 const sal_Int32 CSV_TYPE_DEFAULT
= 0;
57 /** Multi selection with different types. */
58 const sal_Int32 CSV_TYPE_MULTI
= -1;
59 /** No column selected. */
60 const sal_Int32 CSV_TYPE_NOSELECTION
= -2;
62 // External used column types.
63 const sal_uInt8 SC_COL_STANDARD
= 1;
64 const sal_uInt8 SC_COL_TEXT
= 2;
65 const sal_uInt8 SC_COL_MDY
= 3;
66 const sal_uInt8 SC_COL_DMY
= 4;
67 const sal_uInt8 SC_COL_YMD
= 5;
68 const sal_uInt8 SC_COL_SKIP
= 9;
69 const sal_uInt8 SC_COL_ENGLISH
= 10;
72 // ============================================================================
74 /** Exported data of a column (data used in the dialog). */
77 sal_Int32 mnIndex
; /// Index of a column.
78 sal_uInt8 mnType
; /// External type of the column.
80 inline ScCsvExpData() : mnIndex( 0 ), mnType( SC_COL_STANDARD
) {}
81 inline ScCsvExpData( xub_StrLen nIndex
, sal_uInt8 nType
) :
82 mnIndex( nIndex
), mnType( nType
) {}
85 typedef ::std::vector
< ScCsvExpData
> ScCsvExpDataVec
;
88 // ============================================================================
90 /** Specifies which element should be used to perform an action. */
93 MOVE_NONE
, /// No action.
94 MOVE_FIRST
, /// First element in current context.
95 MOVE_LAST
, /// Last element in current context.
96 MOVE_PREV
, /// Predecessor of current element in current context.
97 MOVE_NEXT
, /// Successor of current element in current context.
98 MOVE_PREVPAGE
, /// Previous page relative to current context.
99 MOVE_NEXTPAGE
/// Next page relative to current context.
103 // ============================================================================
105 /** Flags for comparison of old and new control layout data. */
106 typedef sal_uInt32 ScCsvDiff
;
108 const ScCsvDiff CSV_DIFF_EQUAL
= 0x00000000;
109 const ScCsvDiff CSV_DIFF_POSCOUNT
= 0x00000001;
110 const ScCsvDiff CSV_DIFF_POSOFFSET
= 0x00000002;
111 const ScCsvDiff CSV_DIFF_HDRWIDTH
= 0x00000004;
112 const ScCsvDiff CSV_DIFF_CHARWIDTH
= 0x00000008;
113 const ScCsvDiff CSV_DIFF_LINECOUNT
= 0x00000010;
114 const ScCsvDiff CSV_DIFF_LINEOFFSET
= 0x00000020;
115 const ScCsvDiff CSV_DIFF_HDRHEIGHT
= 0x00000040;
116 const ScCsvDiff CSV_DIFF_LINEHEIGHT
= 0x00000080;
117 const ScCsvDiff CSV_DIFF_RULERCURSOR
= 0x00000100;
118 const ScCsvDiff CSV_DIFF_GRIDCURSOR
= 0x00000200;
120 const ScCsvDiff CSV_DIFF_HORIZONTAL
= CSV_DIFF_POSCOUNT
| CSV_DIFF_POSOFFSET
| CSV_DIFF_HDRWIDTH
| CSV_DIFF_CHARWIDTH
;
121 const ScCsvDiff CSV_DIFF_VERTICAL
= CSV_DIFF_LINECOUNT
| CSV_DIFF_LINEOFFSET
| CSV_DIFF_HDRHEIGHT
| CSV_DIFF_LINEHEIGHT
;
122 const ScCsvDiff CSV_DIFF_CURSOR
= CSV_DIFF_RULERCURSOR
| CSV_DIFF_GRIDCURSOR
;
125 // ----------------------------------------------------------------------------
127 /** A structure containing all layout data valid for both ruler and data grid
128 (i.e. scroll position or column width). */
129 struct ScCsvLayoutData
131 // horizontal settings
132 sal_Int32 mnPosCount
; /// Number of positions.
133 sal_Int32 mnPosOffset
; /// Horizontal scroll offset.
135 sal_Int32 mnWinWidth
; /// Width of ruler and data grid.
136 sal_Int32 mnHdrWidth
; /// Width of the header column.
137 sal_Int32 mnCharWidth
; /// Pixel width of one character.
140 sal_Int32 mnLineCount
; /// Number of data lines.
141 sal_Int32 mnLineOffset
; /// Index of first visible line (0-based).
143 sal_Int32 mnWinHeight
; /// Height of entire data grid (incl. header).
144 sal_Int32 mnHdrHeight
; /// Height of the header line.
145 sal_Int32 mnLineHeight
; /// Height of a data line.
148 sal_Int32 mnPosCursor
; /// Position of ruler cursor.
149 sal_Int32 mnColCursor
; /// Position of grid column cursor.
151 mutable sal_Int32 mnNoRepaint
; /// >0 = no repaint.
152 bool mbAppRTL
; /// true = application in RTL mode.
154 explicit ScCsvLayoutData();
156 /** Returns differences to rData.
157 @descr For each difference the appropriate bit is set in the returned value. */
158 ScCsvDiff
GetDiff( const ScCsvLayoutData
& rData
) const;
161 inline bool operator==( const ScCsvLayoutData
& rData1
, const ScCsvLayoutData
& rData2
)
163 return rData1
.GetDiff( rData2
) == CSV_DIFF_EQUAL
;
166 inline bool operator!=( const ScCsvLayoutData
& rData1
, const ScCsvLayoutData
& rData2
)
168 return !(rData1
== rData2
);
172 // ============================================================================
174 /** Enumeration of possible commands to change any settings of the CSV controls.
175 @descr Controls have to send commands instead of changing their settings directly.
176 This helps to keep the different controls consistent to each other.
177 A command can contain 0 to 2 sal_Int32 parameters. In the description of each
178 command the required parameters are swown in brackets. [-] means no parameter. */
182 CSVCMD_NONE
, /// No command. [-]
183 CSVCMD_REPAINT
, /// Repaint all controls. [-]
185 // modify horizontal dimensions
186 CSVCMD_SETPOSCOUNT
, /// Change position/column count. [character count]
187 CSVCMD_SETPOSOFFSET
, /// Change position offset (scroll pos). [position]
188 CSVCMD_SETHDRWIDTH
, /// Change width of the header column. [width in pixel]
189 CSVCMD_SETCHARWIDTH
, /// Change character pixel width. [width in pixel]
191 // modify vertical dimensions
192 CSVCMD_SETLINECOUNT
, /// Change number of data lines. [line count]
193 CSVCMD_SETLINEOFFSET
, /// Change first visible line. [line index]
194 CSVCMD_SETHDRHEIGHT
, /// Change height of top header line. [height in pixel]
195 CSVCMD_SETLINEHEIGHT
, /// Change data line pixel height. [height in pixel}
198 CSVCMD_MOVERULERCURSOR
, /// Move ruler cursor to new position. [position]
199 CSVCMD_MOVEGRIDCURSOR
, /// Move data grid cursor to new column. [position]
200 CSVCMD_MAKEPOSVISIBLE
, /// Move to make passed position visible (for mouse tracking). [position]
203 CSVCMD_NEWCELLTEXTS
, /// Recalculate splits and cell texts. [-]
204 CSVCMD_UPDATECELLTEXTS
, /// Update cell texts with current split settings. [-]
205 CSVCMD_SETCOLUMNTYPE
, /// Change data type of selected columns. [column type]
206 CSVCMD_EXPORTCOLUMNTYPE
, /// Send selected column type to external controls. [-]
207 CSVCMD_SETFIRSTIMPORTLINE
, /// Set number of first imported line. [line index]
210 CSVCMD_INSERTSPLIT
, /// Insert a split. [position]
211 CSVCMD_REMOVESPLIT
, /// Remove a split. [position]
212 CSVCMD_TOGGLESPLIT
, /// Inserts or removes a split. [position]
213 CSVCMD_MOVESPLIT
, /// Move a split. [old position, new position]
214 CSVCMD_REMOVEALLSPLITS
/// Remove all splits. [-]
218 // ----------------------------------------------------------------------------
220 /** Data for a CSV control command. The stored position data is aways character based,
221 it's never a column index (required for internal consistency). */
225 ScCsvCmdType meType
; /// The command.
226 sal_Int32 mnParam1
; /// First parameter.
227 sal_Int32 mnParam2
; /// Second parameter.
230 inline explicit ScCsvCmd() : meType( CSVCMD_NONE
),
231 mnParam1( CSV_POS_INVALID
), mnParam2( CSV_POS_INVALID
) {}
233 inline void Set( ScCsvCmdType eType
, sal_Int32 nParam1
, sal_Int32 nParam2
);
235 inline ScCsvCmdType
GetType() const { return meType
; }
236 inline sal_Int32
GetParam1() const { return mnParam1
; }
237 inline sal_Int32
GetParam2() const { return mnParam2
; }
240 inline void ScCsvCmd::Set( ScCsvCmdType eType
, sal_Int32 nParam1
, sal_Int32 nParam2
)
242 meType
= eType
; mnParam1
= nParam1
; mnParam2
= nParam2
;
246 // ============================================================================
248 /** Base class for the CSV ruler and the data grid control. Implements command handling. */
249 class SC_DLLPUBLIC ScCsvControl
: public Control
252 typedef ::std::vector
< OUString
> StringVec
;
253 typedef ::std::vector
< StringVec
> StringVecVec
;
255 typedef ::com::sun::star::uno::Reference
<
256 ::com::sun::star::accessibility::XAccessible
> XAccessibleRef
;
259 Link maCmdHdl
; /// External command handler.
260 ScCsvCmd maCmd
; /// Data of last command.
261 const ScCsvLayoutData
& mrData
; /// Shared layout data.
263 XAccessibleRef mxAccessible
; /// The accessible object of the control.
264 ScAccessibleCsvControl
* mpAccessible
; /// Pointer to the accessible implementation object.
265 bool mbValidGfx
; /// Content of virtual devices valid?
267 // ------------------------------------------------------------------------
269 explicit ScCsvControl( ScCsvControl
& rParent
);
270 explicit ScCsvControl( Window
* pParent
, const ScCsvLayoutData
& rData
, WinBits nBits
);
271 virtual ~ScCsvControl();
273 // event handling ---------------------------------------------------------
275 virtual void GetFocus();
276 virtual void LoseFocus();
278 /** Sends a GetFocus or LoseFocus event to the accessibility object. */
279 void AccSendFocusEvent( bool bFocused
);
280 /** Sends a caret changed event to the accessibility object. */
281 void AccSendCaretEvent();
282 /** Sends a visible area changed event to the accessibility object. */
283 void AccSendVisibleEvent();
284 /** Sends a selection changed event to the accessibility object. */
285 void AccSendSelectionEvent();
286 /** Sends a table model changed event for changed cell contents to the accessibility object. */
287 void AccSendTableUpdateEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
, bool bAllRows
= true );
288 /** Sends a table model changed event for an inserted column to the accessibility object. */
289 void AccSendInsertColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
);
290 /** Sends a table model changed event for a removed column to the accessibility object. */
291 void AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn
, sal_uInt32 nLastColumn
);
293 // repaint helpers --------------------------------------------------------
295 /** Sets the graphic invalid (next Redraw() will not use cached graphic). */
296 inline void InvalidateGfx() { mbValidGfx
= false; }
297 /** Sets the graphic valid (next Redraw() will use cached graphic). */
298 inline void ValidateGfx() { mbValidGfx
= true; }
299 /** Returns true, if cached graphic is valid. */
300 inline bool IsValidGfx() const { return mbValidGfx
; }
302 /** Repaints all controls.
303 @param bInvalidate true = invalidates graphics of this control (not all). */
304 void Repaint( bool bInvalidate
= false );
305 /** Increases no-repaint counter (controls do not repaint until the last EnableRepaint()). */
306 void DisableRepaint();
307 /** Decreases no-repaint counter and repaints if counter reaches 0.
308 @param bInvalidate true = invalidates graphics of this control (not all). */
309 void EnableRepaint( bool bInvalidate
= false );
310 /** Returns true, if controls will not repaint. */
311 inline bool IsNoRepaint() const { return mrData
.mnNoRepaint
> 0; }
313 // command handling -------------------------------------------------------
315 /** Sets a new command handler. */
316 inline void SetCmdHdl( const Link
& rHdl
) { maCmdHdl
= rHdl
; }
317 /** Returns the current command handler. */
318 inline const Link
& GetCmdHdl() const { return maCmdHdl
; }
319 /** Returns data of the last command. */
320 inline const ScCsvCmd
& GetCmd() const { return maCmd
; }
322 /** Executes a command by calling command handler. */
325 sal_Int32 nParam1
= CSV_POS_INVALID
,
326 sal_Int32 nParam2
= CSV_POS_INVALID
);
328 // layout helpers ---------------------------------------------------------
330 /** Returns a reference to the current layout data. */
331 inline const ScCsvLayoutData
& GetLayoutData() const { return mrData
; }
332 /** Returns true, if the Right-to-Left layout mode is active. */
333 inline bool IsRTL() const { return mrData
.mbAppRTL
; }
335 /** Returns the number of available positions. */
336 inline sal_Int32
GetPosCount() const { return mrData
.mnPosCount
; }
337 /** Returns the number of visible positions. */
338 sal_Int32
GetVisPosCount() const;
339 /** Returns the first visible position. */
340 inline sal_Int32
GetFirstVisPos() const { return mrData
.mnPosOffset
; }
341 /** Returns the last visible position. */
342 inline sal_Int32
GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); }
343 /** Returns highest possible position for first visible character. */
344 sal_Int32
GetMaxPosOffset() const;
346 /** Returns true, if it is allowed to set a split at nPos. */
347 bool IsValidSplitPos( sal_Int32 nPos
) const;
348 /** Returns true, if nPos is an allowed AND visible split position. */
349 bool IsVisibleSplitPos( sal_Int32 nPos
) const;
351 /** Returns the width of the header column. */
352 inline sal_Int32
GetHdrWidth() const { return mrData
.mnHdrWidth
; }
353 /** Returns the width of one character column. */
354 inline sal_Int32
GetCharWidth() const { return mrData
.mnCharWidth
; }
355 /** Returns the start position of the header column. */
356 sal_Int32
GetHdrX() const;
357 /** Returns the X position of the first pixel of the data area. */
358 sal_Int32
GetFirstX() const;
359 /** Returns the X position of the last pixel of the data area. */
360 sal_Int32
GetLastX() const;
361 /** Returns output X coordinate of the specified position. */
362 sal_Int32
GetX( sal_Int32 nPos
) const;
363 /** Returns position from output coordinate. */
364 sal_Int32
GetPosFromX( sal_Int32 nX
) const;
366 /** Returns the number of data lines. */
367 inline sal_Int32
GetLineCount() const { return mrData
.mnLineCount
; }
368 /** Returns the number of visible lines (including partly visible bottom line). */
369 sal_Int32
GetVisLineCount() const;
370 /** Returns index of first visible line. */
371 inline sal_Int32
GetFirstVisLine() const { return mrData
.mnLineOffset
; }
372 /** Returns index of last visible line. */
373 sal_Int32
GetLastVisLine() const;
374 /** Returns highest possible index for first line. */
375 sal_Int32
GetMaxLineOffset() const;
377 /** Returns true, if nLine is a valid line index. */
378 bool IsValidLine( sal_Int32 nLine
) const;
379 /** Returns true, if nLine is a valid and visible line index. */
380 bool IsVisibleLine( sal_Int32 nLine
) const;
382 /** Returns the height of the header line. */
383 inline sal_Int32
GetHdrHeight() const { return mrData
.mnHdrHeight
; }
384 /** Returns the height of one line. */
385 inline sal_Int32
GetLineHeight() const { return mrData
.mnLineHeight
; }
386 /** Returns output Y coordinate of the specified line. */
387 sal_Int32
GetY( sal_Int32 nLine
) const;
388 /** Returns line index from output coordinate. */
389 sal_Int32
GetLineFromY( sal_Int32 nY
) const;
391 /** Returns the ruler cursor position. */
392 inline sal_Int32
GetRulerCursorPos() const { return mrData
.mnPosCursor
; }
393 /** Returns the data grid cursor position (not column index!). */
394 inline sal_Int32
GetGridCursorPos() const { return mrData
.mnColCursor
; }
396 // static helpers ---------------------------------------------------------
398 /** Inverts a rectangle in the specified output device. */
399 static void ImplInvertRect( OutputDevice
& rOutDev
, const Rectangle
& rRect
);
401 /** Returns direction code for the keys LEFT, RIGHT, HOME, END.
402 @param bHomeEnd false = ignore HOME and END key. */
403 static ScMoveMode
GetHorzDirection( sal_uInt16 nCode
, bool bHomeEnd
);
404 /** Returns direction code for the keys UP, DOWN, HOME, END, PAGE UP, PAGE DOWN.
405 @param bHomeEnd false = ignore HOME and END key. */
406 static ScMoveMode
GetVertDirection( sal_uInt16 nCode
, bool bHomeEnd
);
408 // accessibility ----------------------------------------------------------
410 /** Creates and returns the accessible object of this control. Do not overwrite in
411 derived classes, use ImplCreateAccessible() instead. */
412 virtual XAccessibleRef
CreateAccessible();
415 /** Derived classes create a new accessible object here. */
416 virtual ScAccessibleCsvControl
* ImplCreateAccessible() = 0;
420 // ============================================================================
424 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */