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 <o3tl/typed_flags_set.hxx>
27 #include <rtl/ref.hxx>
28 #include <vcl/customweld.hxx>
29 #include "AccessibleCsvControl.hxx"
30 
31 namespace com::sun::star::accessibility { class XAccessible; }
32 
34 const sal_Int32 CSV_MINCOLWIDTH = 8;
36 const sal_Int32 CSV_MAXSTRLEN = 0x7FFF;
38 const sal_uInt16 CSV_HDR_TRANSPARENCY = 85;
40 const sal_Int32 CSV_SCROLL_DIST = 3;
41 
43 const sal_Int32 CSV_PREVIEW_LINES = 32; // maximum count of preview lines
45 const sal_Int32 CSV_MAXCOLCOUNT = MAXCOLCOUNT;
46 
48 const sal_Int32 CSV_TYPE_DEFAULT = 0;
50 const sal_Int32 CSV_TYPE_MULTI = -1;
52 const sal_Int32 CSV_TYPE_NOSELECTION = -2;
53 
54 // External used column types.
62 
65 {
66  sal_Int32 mnIndex;
68 
69  ScCsvExpData() : mnIndex( 0 ), mnType( SC_COL_STANDARD ) {}
70  ScCsvExpData( sal_Int32 nIndex, sal_uInt8 nType ) :
71  mnIndex( nIndex ), mnType( nType ) {}
72 };
73 
74 typedef ::std::vector< ScCsvExpData > ScCsvExpDataVec;
75 
78 {
86 };
87 
89 enum class ScCsvDiff : sal_uInt32 {
90  Equal = 0x0000,
91  PosCount = 0x0001,
92  PosOffset = 0x0002,
93  HeaderWidth = 0x0004,
94  CharWidth = 0x0008,
95  LineCount = 0x0010,
96  LineOffset = 0x0020,
97  HeaderHeight = 0x0040,
98  LineHeight = 0x0080,
99  RulerCursor = 0x0100,
100  GridCursor = 0x0200,
101 
104 };
105 namespace o3tl {
106  template<> struct typed_flags<ScCsvDiff> : is_typed_flags<ScCsvDiff, 0x03ff> {};
107 }
108 
109 
113 {
114  // horizontal settings
115  sal_Int32 mnPosCount;
116  sal_Int32 mnPosOffset;
117 
118  sal_Int32 mnWinWidth;
119  sal_Int32 mnHdrWidth;
120  sal_Int32 mnCharWidth;
121 
122  // vertical settings
123  sal_Int32 mnLineCount;
124  sal_Int32 mnLineOffset;
125 
126  sal_Int32 mnWinHeight;
127  sal_Int32 mnHdrHeight;
128  sal_Int32 mnLineHeight;
129 
130  // cursor settings
131  sal_Int32 mnPosCursor;
132  sal_Int32 mnColCursor;
133 
134  mutable sal_Int32 mnNoRepaint;
135  bool mbAppRTL;
136 
137  explicit ScCsvLayoutData();
138 
141  ScCsvDiff GetDiff( const ScCsvLayoutData& rData ) const;
142 };
143 
144 inline bool operator==( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
145 {
146  return rData1.GetDiff( rData2 ) == ScCsvDiff::Equal;
147 }
148 
149 inline bool operator!=( const ScCsvLayoutData& rData1, const ScCsvLayoutData& rData2 )
150 {
151  return !(rData1 == rData2);
152 }
153 
160 {
161  // misc
164 
165  // modify horizontal dimensions
170 
171  // modify vertical dimensions
176 
177  // cursors/positions
181 
182  // table contents
188 
189  // splits
195 };
196 
199 class ScCsvCmd
200 {
201 private:
203  sal_Int32 mnParam1;
204  sal_Int32 mnParam2;
205 
206 public:
207  explicit ScCsvCmd() : meType( CSVCMD_NONE ),
208  mnParam1( CSV_POS_INVALID ), mnParam2( CSV_POS_INVALID ) {}
209 
210  inline void Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 );
211 
212  ScCsvCmdType GetType() const { return meType; }
213  sal_Int32 GetParam1() const { return mnParam1; }
214  sal_Int32 GetParam2() const { return mnParam2; }
215 };
216 
217 inline void ScCsvCmd::Set( ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2 )
218 {
219  meType = eType; mnParam1 = nParam1; mnParam2 = nParam2;
220 }
221 
224 {
225 private:
229 
230  bool mbValidGfx;
231 
232 protected:
234 
235 public:
236  explicit ScCsvControl(const ScCsvLayoutData& rData);
237  virtual ~ScCsvControl() override;
238 
239  // event handling ---------------------------------------------------------
240 
241  virtual void GetFocus() override;
242  virtual void LoseFocus() override;
243 
245  void AccSendFocusEvent( bool bFocused );
247  void AccSendCaretEvent();
249  void AccSendVisibleEvent();
251  void AccSendSelectionEvent();
253  void AccSendTableUpdateEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn, bool bAllRows = true );
255  void AccSendInsertColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
257  void AccSendRemoveColumnEvent( sal_uInt32 nFirstColumn, sal_uInt32 nLastColumn );
258 
259  ScAccessibleCsvControl* GetAccessible() { return mxAccessible.get(); }
260 
261  // repaint helpers --------------------------------------------------------
262 
264  void InvalidateGfx() { mbValidGfx = false; }
266  void ValidateGfx() { mbValidGfx = true; }
268  bool IsValidGfx() const { return mbValidGfx; }
269 
272  void Repaint( bool bInvalidate = false );
274  void DisableRepaint();
276  void EnableRepaint();
278  bool IsNoRepaint() const { return mrData.mnNoRepaint > 0; }
279 
280  // command handling -------------------------------------------------------
281 
283  void SetCmdHdl( const Link<ScCsvControl&,void>& rHdl ) { maCmdHdl = rHdl; }
285  const ScCsvCmd& GetCmd() const { return maCmd; }
286 
288  void Execute(
289  ScCsvCmdType eType,
290  sal_Int32 nParam1 = CSV_POS_INVALID,
291  sal_Int32 nParam2 = CSV_POS_INVALID );
292 
293  // layout helpers ---------------------------------------------------------
294 
296  const ScCsvLayoutData& GetLayoutData() const { return mrData; }
298  bool IsRTL() const { return mrData.mbAppRTL; }
299 
301  sal_Int32 GetPosCount() const { return mrData.mnPosCount; }
303  sal_Int32 GetVisPosCount() const;
305  sal_Int32 GetFirstVisPos() const { return mrData.mnPosOffset; }
307  sal_Int32 GetLastVisPos() const { return GetFirstVisPos() + GetVisPosCount(); }
309  sal_Int32 GetMaxPosOffset() const;
310 
312  bool IsValidSplitPos( sal_Int32 nPos ) const;
314  bool IsVisibleSplitPos( sal_Int32 nPos ) const;
315 
317  sal_Int32 GetHdrWidth() const { return mrData.mnHdrWidth; }
319  sal_Int32 GetCharWidth() const { return mrData.mnCharWidth; }
321  sal_Int32 GetHdrX() const;
323  sal_Int32 GetFirstX() const;
325  sal_Int32 GetLastX() const;
327  sal_Int32 GetX( sal_Int32 nPos ) const;
329  sal_Int32 GetPosFromX( sal_Int32 nX ) const;
330 
332  sal_Int32 GetLineCount() const { return mrData.mnLineCount; }
334  sal_Int32 GetVisLineCount() const;
336  sal_Int32 GetFirstVisLine() const { return mrData.mnLineOffset; }
338  sal_Int32 GetLastVisLine() const;
340  sal_Int32 GetMaxLineOffset() const;
341 
343  bool IsValidLine( sal_Int32 nLine ) const;
345  bool IsVisibleLine( sal_Int32 nLine ) const;
346 
348  sal_Int32 GetHdrHeight() const { return mrData.mnHdrHeight; }
350  sal_Int32 GetLineHeight() const { return mrData.mnLineHeight; }
352  sal_Int32 GetY( sal_Int32 nLine ) const;
354  sal_Int32 GetLineFromY( sal_Int32 nY ) const;
355 
357  sal_Int32 GetRulerCursorPos() const { return mrData.mnPosCursor; }
359  sal_Int32 GetGridCursorPos() const { return mrData.mnColCursor; }
360 
361  // static helpers ---------------------------------------------------------
362 
364  static void ImplInvertRect( OutputDevice& rOutDev, const tools::Rectangle& rRect );
365 
368  static ScMoveMode GetHorzDirection( sal_uInt16 nCode, bool bHomeEnd );
371  static ScMoveMode GetVertDirection( sal_uInt16 nCode, bool bHomeEnd );
372 };
373 
374 #endif
375 
376 /* 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:178
ScCsvCmdType
Enumeration of possible commands to change any settings of the CSV controls.
Definition: csvcontrol.hxx:159
Repaint all controls. [-].
Definition: csvcontrol.hxx:166
sal_Int32 mnPosOffset
Number of positions.
Definition: csvcontrol.hxx:116
sal_Int32 mnWinHeight
Index of first visible line (0-based).
Definition: csvcontrol.hxx:126
const sal_uInt8 SC_COL_STANDARD
Definition: csvcontrol.hxx:55
sal_Int32 GetParam2() const
Definition: csvcontrol.hxx:214
const sal_uInt8 SC_COL_TEXT
Definition: csvcontrol.hxx:56
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:301
const ScCsvLayoutData & GetLayoutData() const
Returns a reference to the current layout data.
Definition: csvcontrol.hxx:296
sal_uInt8 mnType
Index of a column.
Definition: csvcontrol.hxx:67
ScMoveMode
Specifies which element should be used to perform an action.
Definition: csvcontrol.hxx:77
bool mbAppRTL
>0 = no repaint.
Definition: csvcontrol.hxx:135
sal_Int32 GetLineHeight() const
Returns the height of one line.
Definition: csvcontrol.hxx:350
Set number of first imported line. [line index].
Definition: csvcontrol.hxx:190
Change position/column count. [character count].
Definition: csvcontrol.hxx:167
Update cell texts with current split settings. [-].
Definition: csvcontrol.hxx:185
const ScCsvLayoutData & mrData
Data of last command.
Definition: csvcontrol.hxx:228
ScCsvCmdType meType
Definition: csvcontrol.hxx:202
bool IsValidGfx() const
Returns true, if cached graphic is valid.
Definition: csvcontrol.hxx:268
sal_Int32 mnCharWidth
Width of the header column.
Definition: csvcontrol.hxx:120
sal_Int32 mnWinWidth
Horizontal scroll offset.
Definition: csvcontrol.hxx:118
sal_Int32 GetHdrHeight() const
Returns the height of the header line.
Definition: csvcontrol.hxx:348
void Set(ScCsvCmdType eType, sal_Int32 nParam1, sal_Int32 nParam2)
Definition: csvcontrol.hxx:217
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:199
Change width of the header column. [width in pixel].
Definition: csvcontrol.hxx:169
Change height of top header line. [height in pixel].
Definition: csvcontrol.hxx:175
Base class for the CSV ruler and the data grid control.
Definition: csvcontrol.hxx:223
Accessible base class used for CSV controls.
const sal_Int32 CSV_MAXSTRLEN
Maximum length of a cell string.
Definition: csvcontrol.hxx:36
Move ruler cursor to new position. [position].
Definition: csvcontrol.hxx:179
Predecessor of current element in current context.
Definition: csvcontrol.hxx:83
bool IsNoRepaint() const
Returns true, if controls will not repaint.
Definition: csvcontrol.hxx:278
Link< ScCsvControl &, void > maCmdHdl
Definition: csvcontrol.hxx:226
const sal_Int32 CSV_SCROLL_DIST
Minimum distance to border for auto scroll.
Definition: csvcontrol.hxx:40
sal_Int32 GetCharWidth() const
Returns the width of one character column.
Definition: csvcontrol.hxx:319
Exported data of a column (data used in the dialog).
Definition: csvcontrol.hxx:64
ScAccessibleCsvControl * GetAccessible()
Definition: csvcontrol.hxx:259
const ScCsvCmd & GetCmd() const
Returns data of the last command.
Definition: csvcontrol.hxx:285
Inserts or removes a split. [position].
Definition: csvcontrol.hxx:193
bool IsRTL() const
Returns true, if the Right-to-Left layout mode is active.
Definition: csvcontrol.hxx:298
const sal_Int32 CSV_TYPE_NOSELECTION
No column selected.
Definition: csvcontrol.hxx:52
ScCsvExpData()
External type of the column.
Definition: csvcontrol.hxx:69
No command. [-].
Definition: csvcontrol.hxx:163
const sal_Int32 CSV_MINCOLWIDTH
Minimum character count for a column in separators mode.
Definition: csvcontrol.hxx:34
sal_Int32 mnHdrWidth
Width of ruler and data grid.
Definition: csvcontrol.hxx:119
Change number of data lines. [line count].
Definition: csvcontrol.hxx:173
Remove a split. [position].
Definition: csvcontrol.hxx:192
sal_Int32 mnLineCount
Pixel width of one character.
Definition: csvcontrol.hxx:123
Send selected column type to external controls. [-].
Definition: csvcontrol.hxx:187
sal_Int32 GetLastVisPos() const
Returns the last visible position.
Definition: csvcontrol.hxx:307
sal_Int32 mnColCursor
Position of ruler cursor.
Definition: csvcontrol.hxx:132
sal_Int32 GetLineCount() const
Returns the number of data lines.
Definition: csvcontrol.hxx:332
void SetCmdHdl(const Link< ScCsvControl &, void > &rHdl)
Sets a new command handler.
Definition: csvcontrol.hxx:283
bool mbValidGfx
Shared layout data.
Definition: csvcontrol.hxx:230
Last element in current context.
Definition: csvcontrol.hxx:82
Successor of current element in current context.
Definition: csvcontrol.hxx:84
sal_Int32 mnPosCount
Definition: csvcontrol.hxx:115
ScCsvCmd()
Second parameter.
Definition: csvcontrol.hxx:207
Move data grid cursor to new column. [position].
Definition: csvcontrol.hxx:180
sal_Int32 GetFirstVisLine() const
Returns index of first visible line.
Definition: csvcontrol.hxx:336
sal_Int32 mnNoRepaint
Position of grid column cursor.
Definition: csvcontrol.hxx:134
rtl::Reference< ScAccessibleCsvControl > mxAccessible
Content of virtual devices valid?
Definition: csvcontrol.hxx:233
sal_Int32 mnLineHeight
Height of the header line.
Definition: csvcontrol.hxx:128
Change data type of selected columns. [column type].
Definition: csvcontrol.hxx:186
sal_Int32 mnHdrHeight
Height of entire data grid (incl. header).
Definition: csvcontrol.hxx:127
void ValidateGfx()
Sets the graphic valid (next Redraw() will use cached graphic).
Definition: csvcontrol.hxx:266
ScCsvCmd maCmd
External command handler.
Definition: csvcontrol.hxx:227
First element in current context.
Definition: csvcontrol.hxx:81
const sal_Int32 CSV_TYPE_DEFAULT
Default column data type.
Definition: csvcontrol.hxx:48
No action.
Definition: csvcontrol.hxx:80
sal_Int32 mnPosCursor
Height of a data line.
Definition: csvcontrol.hxx:131
bool operator!=(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: csvcontrol.hxx:149
Change position offset (scroll pos). [position].
Definition: csvcontrol.hxx:168
const sal_uInt16 CSV_HDR_TRANSPARENCY
Transparency for header color of selected columns.
Definition: csvcontrol.hxx:38
Move to make passed position visible (for mouse tracking). [position].
Definition: csvcontrol.hxx:183
sal_Int32 mnLineOffset
Number of data lines.
Definition: csvcontrol.hxx:124
sal_Int32 mnIndex
Definition: csvcontrol.hxx:66
Change first visible line. [line index].
Definition: csvcontrol.hxx:174
sal_Int32 GetRulerCursorPos() const
Returns the ruler cursor position.
Definition: csvcontrol.hxx:357
unsigned char sal_uInt8
const sal_Int32 CSV_TYPE_MULTI
Multi selection with different types.
Definition: csvcontrol.hxx:50
const sal_uInt8 SC_COL_MDY
Definition: csvcontrol.hxx:57
const sal_uInt8 SC_COL_ENGLISH
Definition: csvcontrol.hxx:61
sal_Int32 GetHdrWidth() const
Returns the width of the header column.
Definition: csvcontrol.hxx:317
ScCsvExpData(sal_Int32 nIndex, sal_uInt8 nType)
Definition: csvcontrol.hxx:70
ScCsvDiff
Flags for comparison of old and new control layout data.
Definition: csvcontrol.hxx:89
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:400
Previous page relative to current context.
Definition: csvcontrol.hxx:85
Change character pixel width. [width in pixel].
Definition: csvcontrol.hxx:172
void InvalidateGfx()
Sets the graphic invalid (next Redraw() will not use cached graphic).
Definition: csvcontrol.hxx:264
sal_Int32 mnParam1
The command.
Definition: csvcontrol.hxx:203
const sal_Int32 CSV_MAXCOLCOUNT
Maximum count of columns.
Definition: csvcontrol.hxx:45
sal_Int32 GetParam1() const
Definition: csvcontrol.hxx:213
Insert a split. [position].
Definition: csvcontrol.hxx:191
const sal_uInt8 SC_COL_DMY
Definition: csvcontrol.hxx:58
ScCsvCmdType GetType() const
Definition: csvcontrol.hxx:212
::std::vector< ScCsvExpData > ScCsvExpDataVec
Definition: csvcontrol.hxx:74
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: csvcontrol.hxx:144
Move a split. [old position, new position].
Definition: csvcontrol.hxx:194
const sal_uInt8 SC_COL_SKIP
Definition: csvcontrol.hxx:60
Recalculate splits and cell texts. [-].
Definition: csvcontrol.hxx:184
sal_Int32 GetFirstVisPos() const
Returns the first visible position.
Definition: csvcontrol.hxx:305
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
sal_Int32 GetGridCursorPos() const
Returns the data grid cursor position (not column index!).
Definition: csvcontrol.hxx:359
const sal_Int32 CSV_PREVIEW_LINES
TODO make string array dynamic.
Definition: csvcontrol.hxx:43
sal_Int32 mnParam2
First parameter.
Definition: csvcontrol.hxx:204
const sal_uInt8 SC_COL_YMD
Definition: csvcontrol.hxx:59
A structure containing all layout data valid for both ruler and data grid (i.e.
Definition: csvcontrol.hxx:112