LibreOffice Module sc (master)  1
csvcontrol.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_CSVCONTROL_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_CSVCONTROL_HXX
22 
23 #include <scdllapi.h>
24 #include <address.hxx>
25 #include "csvsplits.hxx"
26 #include <com/sun/star/uno/Reference.hxx>
27 #include <o3tl/typed_flags_set.hxx>
28 #include <rtl/ref.hxx>
29 #include <vcl/customweld.hxx>
30 #include "AccessibleCsvControl.hxx"
31 
32 namespace com::sun::star::accessibility { class XAccessible; }
33 
35 const sal_Int32 CSV_MINCOLWIDTH = 8;
37 const sal_Int32 CSV_MAXSTRLEN = 0x7FFF;
39 const sal_uInt16 CSV_HDR_TRANSPARENCY = 85;
41 const sal_Int32 CSV_SCROLL_DIST = 3;
42 
44 const sal_Int32 CSV_PREVIEW_LINES = 32; // maximum count of preview lines
46 const sal_Int32 CSV_MAXCOLCOUNT = MAXCOLCOUNT;
47 
49 const sal_Int32 CSV_TYPE_DEFAULT = 0;
51 const sal_Int32 CSV_TYPE_MULTI = -1;
53 const sal_Int32 CSV_TYPE_NOSELECTION = -2;
54 
55 // External used column types.
63 
66 {
67  sal_Int32 mnIndex;
69 
70  ScCsvExpData() : mnIndex( 0 ), mnType( SC_COL_STANDARD ) {}
71  ScCsvExpData( sal_Int32 nIndex, sal_uInt8 nType ) :
72  mnIndex( nIndex ), mnType( nType ) {}
73 };
74 
75 typedef ::std::vector< ScCsvExpData > ScCsvExpDataVec;
76 
79 {
87 };
88 
90 enum class ScCsvDiff : sal_uInt32 {
91  Equal = 0x0000,
92  PosCount = 0x0001,
93  PosOffset = 0x0002,
94  HeaderWidth = 0x0004,
95  CharWidth = 0x0008,
96  LineCount = 0x0010,
97  LineOffset = 0x0020,
98  HeaderHeight = 0x0040,
99  LineHeight = 0x0080,
100  RulerCursor = 0x0100,
101  GridCursor = 0x0200,
102 
105 };
106 namespace o3tl {
107  template<> struct typed_flags<ScCsvDiff> : is_typed_flags<ScCsvDiff, 0x03ff> {};
108 }
109 
110 
114 {
115  // horizontal settings
116  sal_Int32 mnPosCount;
117  sal_Int32 mnPosOffset;
118 
119  sal_Int32 mnWinWidth;
120  sal_Int32 mnHdrWidth;
121  sal_Int32 mnCharWidth;
122 
123  // vertical settings
124  sal_Int32 mnLineCount;
125  sal_Int32 mnLineOffset;
126 
127  sal_Int32 mnWinHeight;
128  sal_Int32 mnHdrHeight;
129  sal_Int32 mnLineHeight;
130 
131  // cursor settings
132  sal_Int32 mnPosCursor;
133  sal_Int32 mnColCursor;
134 
135  mutable sal_Int32 mnNoRepaint;
136  bool mbAppRTL;
137 
138  explicit ScCsvLayoutData();
139 
142  ScCsvDiff GetDiff( const ScCsvLayoutData& rData ) const;
143 };
144 
145 inline bool operator==( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
146 {
147  return rData1.GetDiff( rData2 ) == ScCsvDiff::Equal;
148 }
149 
150 inline bool operator!=( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
151 {
152  return !(rData1 == rData2);
153 }
154 
161 {
162  // misc
165 
166  // modify horizontal dimensions
171 
172  // modify vertical dimensions
177 
178  // cursors/positions
182 
183  // table contents
189 
190  // splits
196 };
197 
200 class ScCsvCmd
201 {
202 private:
204  sal_Int32 mnParam1;
205  sal_Int32 mnParam2;
206 
207 public:
208  explicit ScCsvCmd() : meType( CSVCMD_NONE ),
209  mnParam1( CSV_POS_INVALID ), mnParam2( CSV_POS_INVALID ) {}
210 
211  inline void Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 );
212 
213  ScCsvCmdType GetType() const { return meType; }
214  sal_Int32 GetParam1() const { return mnParam1; }
215  sal_Int32 GetParam2() const { return mnParam2; }
216 };
217 
218 inline void ScCsvCmd::Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
219 {
220  meType = eType; mnParam1 = nParam1; mnParam2 = nParam2;
221 }
222 
225 {
226 private:
230 
231  bool mbValidGfx;
232 
233 protected:
235 
236 public:
237  explicit ScCsvControl(const ScCsvLayoutData& rData);
238  virtual ~ScCsvControl() override;
239 
240  // event handling ---------------------------------------------------------
241 
242  virtual void GetFocus() override;
243  virtual void LoseFocus() override;
244 
246  void AccSendFocusEvent( bool bFocused );
248  void AccSendCaretEvent();
250  void AccSendVisibleEvent();
252  void AccSendSelectionEvent();
254  void AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows = true );
256  void AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
258  void AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
259 
260  ScAccessibleCsvControl* GetAccessible() { return mxAccessible.get(); }
261 
262  // repaint helpers --------------------------------------------------------
263 
265  void InvalidateGfx() { mbValidGfx = false; }
267  void ValidateGfx() { mbValidGfx = true; }
269  bool IsValidGfx() const { return mbValidGfx; }
270 
273  void Repaint( bool bInvalidate = false );
275  void DisableRepaint();
277  void EnableRepaint();
279  bool IsNoRepaint() const { return mrData.mnNoRepaint > 0; }
280 
281  // command handling -------------------------------------------------------
282 
284  void SetCmdHdl( const Link<ScCsvControl&,void>& rHdl ) { maCmdHdl = rHdl; }
286  const ScCsvCmd& GetCmd() const { return maCmd; }
287 
289  void Execute(
290  ScCsvCmdType eType,
291  sal_Int32 nParam1 = CSV_POS_INVALID,
292  sal_Int32 nParam2 = CSV_POS_INVALID );
293 
294  // layout helpers ---------------------------------------------------------
295 
297  const ScCsvLayoutData& GetLayoutData() const { return mrData; }
299  bool IsRTL() const { return mrData.mbAppRTL; }
300 
302  sal_Int32 GetPosCount() const { return mrData.mnPosCount; }
304  sal_Int32 GetVisPosCount() const;
306  sal_Int32 GetFirstVisPos() const { return mrData.mnPosOffset; }
308  sal_Int32 GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); }
310  sal_Int32 GetMaxPosOffset() const;
311 
313  bool IsValidSplitPos( sal_Int32 nPos ) const;
315  bool IsVisibleSplitPos( sal_Int32 nPos ) const;
316 
318  sal_Int32 GetHdrWidth() const { return mrData.mnHdrWidth; }
320  sal_Int32 GetCharWidth() const { return mrData.mnCharWidth; }
322  sal_Int32 GetHdrX() const;
324  sal_Int32 GetFirstX() const;
326  sal_Int32 GetLastX() const;
328  sal_Int32 GetX( sal_Int32 nPos ) const;
330  sal_Int32 GetPosFromX( sal_Int32 nX ) const;
331 
333  sal_Int32 GetLineCount() const { return mrData.mnLineCount; }
335  sal_Int32 GetVisLineCount() const;
337  sal_Int32 GetFirstVisLine() const { return mrData.mnLineOffset; }
339  sal_Int32 GetLastVisLine() const;
341  sal_Int32 GetMaxLineOffset() const;
342 
344  bool IsValidLine( sal_Int32 nLine ) const;
346  bool IsVisibleLine( sal_Int32 nLine ) const;
347 
349  sal_Int32 GetHdrHeight() const { return mrData.mnHdrHeight; }
351  sal_Int32 GetLineHeight() const { return mrData.mnLineHeight; }
353  sal_Int32 GetY( sal_Int32 nLine ) const;
355  sal_Int32 GetLineFromY( sal_Int32 nY ) const;
356 
358  sal_Int32 GetRulerCursorPos() const { return mrData.mnPosCursor; }
360  sal_Int32 GetGridCursorPos() const { return mrData.mnColCursor; }
361 
362  // static helpers ---------------------------------------------------------
363 
365  static void ImplInvertRect( OutputDevice& rOutDev, const tools::Rectangle& rRect );
366 
369  static ScMoveMode GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd );
372  static ScMoveMode GetVertDirection( sal_uInt16 nCode, bool bHomeEnd );
373 };
374 
375 #endif
376 
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScCsvDiff GetDiff(const ScCsvLayoutData &rData) const
Returns differences to rData.
Definition: csvcontrol.cxx:43
Change data line pixel height. [height in pixel}.
Definition: csvcontrol.hxx:179
ScCsvCmdType
Enumeration of possible commands to change any settings of the CSV controls.
Definition: csvcontrol.hxx:160
Repaint all controls. [-].
Definition: csvcontrol.hxx:167
sal_Int32 mnPosOffset
Number of positions.
Definition: csvcontrol.hxx:117
sal_Int32 mnWinHeight
Index of first visible line (0-based).
Definition: csvcontrol.hxx:127
const sal_uInt8 SC_COL_STANDARD
Definition: csvcontrol.hxx:56
sal_Int32 GetParam2() const
Definition: csvcontrol.hxx:215
const sal_uInt8 SC_COL_TEXT
Definition: csvcontrol.hxx:57
const sal_Int32 CSV_POS_INVALID
Constant for an invalid ruler position.
Definition: csvsplits.hxx:30
sal_Int32 GetPosCount() const
Returns the number of available positions.
Definition: csvcontrol.hxx:302
const ScCsvLayoutData & GetLayoutData() const
Returns a reference to the current layout data.
Definition: csvcontrol.hxx:297
sal_uInt8 mnType
Index of a column.
Definition: csvcontrol.hxx:68
ScMoveMode
Specifies which element should be used to perform an action.
Definition: csvcontrol.hxx:78
bool mbAppRTL
>0 = no repaint.
Definition: csvcontrol.hxx:136
sal_Int32 GetLineHeight() const
Returns the height of one line.
Definition: csvcontrol.hxx:351
Set number of first imported line. [line index].
Definition: csvcontrol.hxx:191
Change position/column count. [character count].
Definition: csvcontrol.hxx:168
Update cell texts with current split settings. [-].
Definition: csvcontrol.hxx:186
const ScCsvLayoutData & mrData
Data of last command.
Definition: csvcontrol.hxx:229
ScCsvCmdType meType
Definition: csvcontrol.hxx:203
bool IsValidGfx() const
Returns true, if cached graphic is valid.
Definition: csvcontrol.hxx:269
sal_Int32 mnCharWidth
Width of the header column.
Definition: csvcontrol.hxx:121
sal_Int32 mnWinWidth
Horizontal scroll offset.
Definition: csvcontrol.hxx:119
sal_Int32 GetHdrHeight() const
Returns the height of the header line.
Definition: csvcontrol.hxx:349
void Set(ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2)
Definition: csvcontrol.hxx:218
const SCCOL MAXCOLCOUNT
Definition: address.hxx:64
ScCsvLayoutData()
true = application in RTL mode.
Definition: csvcontrol.cxx:25
Data for a CSV control command.
Definition: csvcontrol.hxx:200
Change width of the header column. [width in pixel].
Definition: csvcontrol.hxx:170
Change height of top header line. [height in pixel].
Definition: csvcontrol.hxx:176
Base class for the CSV ruler and the data grid control.
Definition: csvcontrol.hxx:224
Accessible base class used for CSV controls.
const sal_Int32 CSV_MAXSTRLEN
Maximum length of a cell string.
Definition: csvcontrol.hxx:37
Move ruler cursor to new position. [position].
Definition: csvcontrol.hxx:180
Predecessor of current element in current context.
Definition: csvcontrol.hxx:84
bool IsNoRepaint() const
Returns true, if controls will not repaint.
Definition: csvcontrol.hxx:279
Link< ScCsvControl &, void > maCmdHdl
Definition: csvcontrol.hxx:227
const sal_Int32 CSV_SCROLL_DIST
Minimum distance to border for auto scroll.
Definition: csvcontrol.hxx:41
sal_Int32 GetCharWidth() const
Returns the width of one character column.
Definition: csvcontrol.hxx:320
Exported data of a column (data used in the dialog).
Definition: csvcontrol.hxx:65
ScAccessibleCsvControl * GetAccessible()
Definition: csvcontrol.hxx:260
const ScCsvCmd & GetCmd() const
Returns data of the last command.
Definition: csvcontrol.hxx:286
Inserts or removes a split. [position].
Definition: csvcontrol.hxx:194
bool IsRTL() const
Returns true, if the Right-to-Left layout mode is active.
Definition: csvcontrol.hxx:299
const sal_Int32 CSV_TYPE_NOSELECTION
No column selected.
Definition: csvcontrol.hxx:53
ScCsvExpData()
External type of the column.
Definition: csvcontrol.hxx:70
No command. [-].
Definition: csvcontrol.hxx:164
const sal_Int32 CSV_MINCOLWIDTH
Minimum character count for a column in separators mode.
Definition: csvcontrol.hxx:35
sal_Int32 mnHdrWidth
Width of ruler and data grid.
Definition: csvcontrol.hxx:120
Change number of data lines. [line count].
Definition: csvcontrol.hxx:174
Remove a split. [position].
Definition: csvcontrol.hxx:193
sal_Int32 mnLineCount
Pixel width of one character.
Definition: csvcontrol.hxx:124
Send selected column type to external controls. [-].
Definition: csvcontrol.hxx:188
sal_Int32 GetLastVisPos() const
Returns the last visible position.
Definition: csvcontrol.hxx:308
sal_Int32 mnColCursor
Position of ruler cursor.
Definition: csvcontrol.hxx:133
sal_Int32 GetLineCount() const
Returns the number of data lines.
Definition: csvcontrol.hxx:333
void SetCmdHdl(const Link< ScCsvControl &, void > &rHdl)
Sets a new command handler.
Definition: csvcontrol.hxx:284
bool mbValidGfx
Shared layout data.
Definition: csvcontrol.hxx:231
Last element in current context.
Definition: csvcontrol.hxx:83
Successor of current element in current context.
Definition: csvcontrol.hxx:85
sal_Int32 mnPosCount
Definition: csvcontrol.hxx:116
ScCsvCmd()
Second parameter.
Definition: csvcontrol.hxx:208
Move data grid cursor to new column. [position].
Definition: csvcontrol.hxx:181
sal_Int32 GetFirstVisLine() const
Returns index of first visible line.
Definition: csvcontrol.hxx:337
sal_Int32 mnNoRepaint
Position of grid column cursor.
Definition: csvcontrol.hxx:135
rtl::Reference< ScAccessibleCsvControl > mxAccessible
Content of virtual devices valid?
Definition: csvcontrol.hxx:234
sal_Int32 mnLineHeight
Height of the header line.
Definition: csvcontrol.hxx:129
Change data type of selected columns. [column type].
Definition: csvcontrol.hxx:187
sal_Int32 mnHdrHeight
Height of entire data grid (incl. header).
Definition: csvcontrol.hxx:128
void ValidateGfx()
Sets the graphic valid (next Redraw() will use cached graphic).
Definition: csvcontrol.hxx:267
ScCsvCmd maCmd
External command handler.
Definition: csvcontrol.hxx:228
First element in current context.
Definition: csvcontrol.hxx:82
const sal_Int32 CSV_TYPE_DEFAULT
Default column data type.
Definition: csvcontrol.hxx:49
No action.
Definition: csvcontrol.hxx:81
sal_Int32 mnPosCursor
Height of a data line.
Definition: csvcontrol.hxx:132
bool operator!=(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: csvcontrol.hxx:150
Change position offset (scroll pos). [position].
Definition: csvcontrol.hxx:169
const sal_uInt16 CSV_HDR_TRANSPARENCY
Transparency for header color of selected columns.
Definition: csvcontrol.hxx:39
Move to make passed position visible (for mouse tracking). [position].
Definition: csvcontrol.hxx:184
sal_Int32 mnLineOffset
Number of data lines.
Definition: csvcontrol.hxx:125
sal_Int32 mnIndex
Definition: csvcontrol.hxx:67
Change first visible line. [line index].
Definition: csvcontrol.hxx:175
sal_Int32 GetRulerCursorPos() const
Returns the ruler cursor position.
Definition: csvcontrol.hxx:358
unsigned char sal_uInt8
const sal_Int32 CSV_TYPE_MULTI
Multi selection with different types.
Definition: csvcontrol.hxx:51
const sal_uInt8 SC_COL_MDY
Definition: csvcontrol.hxx:58
const sal_uInt8 SC_COL_ENGLISH
Definition: csvcontrol.hxx:62
sal_Int32 GetHdrWidth() const
Returns the width of the header column.
Definition: csvcontrol.hxx:318
ScCsvExpData(sal_Int32 nIndex, sal_uInt8 nType)
Definition: csvcontrol.hxx:71
ScCsvDiff
Flags for comparison of old and new control layout data.
Definition: csvcontrol.hxx:90
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
Previous page relative to current context.
Definition: csvcontrol.hxx:86
Change character pixel width. [width in pixel].
Definition: csvcontrol.hxx:173
void InvalidateGfx()
Sets the graphic invalid (next Redraw() will not use cached graphic).
Definition: csvcontrol.hxx:265
sal_Int32 mnParam1
The command.
Definition: csvcontrol.hxx:204
const sal_Int32 CSV_MAXCOLCOUNT
Maximum count of columns.
Definition: csvcontrol.hxx:46
sal_Int32 GetParam1() const
Definition: csvcontrol.hxx:214
Insert a split. [position].
Definition: csvcontrol.hxx:192
const sal_uInt8 SC_COL_DMY
Definition: csvcontrol.hxx:59
ScCsvCmdType GetType() const
Definition: csvcontrol.hxx:213
::std::vector< ScCsvExpData > ScCsvExpDataVec
Definition: csvcontrol.hxx:75
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: csvcontrol.hxx:145
Move a split. [old position, new position].
Definition: csvcontrol.hxx:195
const sal_uInt8 SC_COL_SKIP
Definition: csvcontrol.hxx:61
Recalculate splits and cell texts. [-].
Definition: csvcontrol.hxx:185
sal_Int32 GetFirstVisPos() const
Returns the first visible position.
Definition: csvcontrol.hxx:306
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int32 GetGridCursorPos() const
Returns the data grid cursor position (not column index!).
Definition: csvcontrol.hxx:360
const sal_Int32 CSV_PREVIEW_LINES
TODO make string array dynamic.
Definition: csvcontrol.hxx:44
sal_Int32 mnParam2
First parameter.
Definition: csvcontrol.hxx:205
const sal_uInt8 SC_COL_YMD
Definition: csvcontrol.hxx:60
A structure containing all layout data valid for both ruler and data grid (i.e.
Definition: csvcontrol.hxx:113