LibreOffice Module sc (master)  1
csvgrid.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 #pragma once
21 
22 #include <vcl/virdev.hxx>
23 #include <unotools/options.hxx>
24 
25 #include <vector>
26 #include <memory>
27 #include <scdllapi.h>
28 #include <editutil.hxx>
29 #include "csvcontrol.hxx"
30 #include "csvsplits.hxx"
31 
32 namespace svtools { class ColorConfig; }
33 class EditEngine;
34 class ScAsciiOptions;
36 class ScCsvTableBox;
37 
39 
42 {
43  sal_Int32 mnType;
45 
46  explicit ScCsvColState( sal_Int32 nType = CSV_TYPE_DEFAULT ) :
47  mnType( nType ), mbColumnSelected( false ) {}
48 
49  bool IsSelected() const { return mbColumnSelected; }
50  void Select( bool bSel ) { mbColumnSelected = bSel; }
51 };
52 
53 typedef ::std::vector< ScCsvColState > ScCsvColStateVec;
54 
58 {
59 private:
63  std::unique_ptr<weld::Menu> mxPopup;
64 
75 
76  std::unique_ptr< ScEditEngineDefaulter >
82 
85  std::vector<OUString> maTypeNames;
86  std::vector< std::vector<OUString> > maTexts;
87 
88  sal_Int32 mnFirstImpLine;
89  sal_uInt32 mnRecentSelCol;
90  sal_uInt32 mnMTCurrCol;
91  bool mbTracking;
93 
94 public:
95  explicit ScCsvGrid(const ScCsvLayoutData& rData, std::unique_ptr<weld::Menu> xPopup, ScCsvTableBox* pTableBox);
96  virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
97  ScCsvTableBox* GetTableBox() { return mpTableBox; }
98  virtual ~ScCsvGrid() override;
99 
101  void Init();
102 
103  // common grid handling ---------------------------------------------------
104 public:
106  void UpdateLayoutData();
108  void UpdateOffsetX();
110  void ApplyLayout( const ScCsvLayoutData& rOldData );
112  void SetFirstImportedLine( sal_Int32 nLine );
113 
115  sal_Int32 GetNoScrollCol( sal_Int32 nPos ) const;
116 
117 private:
119  SAL_DLLPRIVATE void InitColors();
121  SAL_DLLPRIVATE void InitFonts();
123  SAL_DLLPRIVATE void InitSizeData();
124 
125  // split handling ---------------------------------------------------------
126 public:
128  void InsertSplit( sal_Int32 nPos );
130  void RemoveSplit( sal_Int32 nPos );
132  void MoveSplit( sal_Int32 nPos, sal_Int32 nNewPos );
134  void RemoveAllSplits();
136  void SetSplits( const ScCsvSplits& rSplits );
137 
138 private:
140  SAL_DLLPRIVATE bool ImplInsertSplit( sal_Int32 nPos );
142  SAL_DLLPRIVATE bool ImplRemoveSplit( sal_Int32 nPos );
144  SAL_DLLPRIVATE void ImplClearSplits();
145 
146  // columns/column types ---------------------------------------------------
147 public:
149  sal_uInt32 GetColumnCount() const { return maColStates.size(); }
151  sal_uInt32 GetFirstVisColumn() const;
153  sal_uInt32 GetLastVisColumn() const;
154 
156  bool IsValidColumn( sal_uInt32 nColIndex ) const;
158  bool IsVisibleColumn( sal_uInt32 nColIndex ) const;
159 
161  sal_Int32 GetColumnX( sal_uInt32 nColIndex ) const;
163  sal_uInt32 GetColumnFromX( sal_Int32 nX ) const;
164 
166  sal_Int32 GetColumnPos( sal_uInt32 nColIndex ) const { return maSplits[ nColIndex ]; }
168  sal_uInt32 GetColumnFromPos( sal_Int32 nPos ) const;
170  sal_Int32 GetColumnWidth( sal_uInt32 nColIndex ) const;
171 
173  const ScCsvColStateVec& GetColumnStates() const { return maColStates; }
175  void SetColumnStates( ScCsvColStateVec&& rColStates );
177  sal_Int32 GetSelColumnType() const;
179  void SetSelColumnType( sal_Int32 nType );
181  void SetTypeNames( std::vector<OUString>&& rTypeNames );
183  OUString GetColumnTypeName( sal_uInt32 nColIndex ) const;
184 
186  void FillColumnDataSep( ScAsciiOptions& rOptions ) const;
188  void FillColumnDataFix( ScAsciiOptions& rOptions ) const;
189 
190 private:
192  SAL_DLLPRIVATE sal_Int32 GetColumnType( sal_uInt32 nColIndex ) const;
194  SAL_DLLPRIVATE void SetColumnType( sal_uInt32 nColIndex, sal_Int32 nColType );
195 
197  SAL_DLLPRIVATE void ScrollVertRel( ScMoveMode eDir );
199  SAL_DLLPRIVATE void ExecutePopup( const Point& rPos );
200 
201  // selection handling -----------------------------------------------------
202 public:
204  bool IsSelected( sal_uInt32 nColIndex ) const;
206  sal_uInt32 GetFirstSelected() const;
208  sal_uInt32 GetNextSelected( sal_uInt32 nFromIndex ) const;
210  void Select( sal_uInt32 nColIndex, bool bSelect = true );
212  void ToggleSelect( sal_uInt32 nColIndex );
214  void SelectRange( sal_uInt32 nColIndex1, sal_uInt32 nColIndex2, bool bSelect = true );
216  void SelectAll( bool bSelect = true );
217 
219  sal_uInt32 GetFocusColumn() const { return GetColumnFromPos( GetGridCursorPos() ); }
220 
221 private:
223  SAL_DLLPRIVATE void MoveCursor( sal_uInt32 nColIndex );
225  SAL_DLLPRIVATE void MoveCursorRel( ScMoveMode eDir );
226 
228  SAL_DLLPRIVATE void ImplClearSelection();
229 
231  SAL_DLLPRIVATE void DoSelectAction( sal_uInt32 nColIndex, sal_uInt16 nModifier );
232 
233  // cell contents ----------------------------------------------------------
234 public:
236  void ImplSetTextLineSep(
237  sal_Int32 nLine, const OUString& rTextLine,
238  const OUString& rSepChars, sal_Unicode cTextSep, bool bMergeSep, bool bRemoveSpace = false );
240  void ImplSetTextLineFix( sal_Int32 nLine, const OUString& rTextLine );
241 
243  OUString GetCellText( sal_uInt32 nColIndex, sal_Int32 nLine ) const;
244 
245  // event handling ---------------------------------------------------------
246 protected:
247  virtual void Resize() override;
248  virtual void GetFocus() override;
249  virtual void LoseFocus() override;
250 
251  virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
252  virtual bool MouseMove( const MouseEvent& rMEvt ) override;
253  virtual bool MouseButtonUp( const MouseEvent& rMEvt ) override;
254  virtual bool KeyInput( const KeyEvent& rKEvt ) override;
255  virtual bool Command( const CommandEvent& rCEvt ) override;
256 
257  virtual tools::Rectangle GetFocusRect() override;
258 
259  virtual void StyleUpdated() override;
260 
262 
263  // painting ---------------------------------------------------------------
264 protected:
265  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
266 
267 public:
269  void ImplRedraw(vcl::RenderContext& rRenderContext);
271  EditEngine* GetEditEngine();
272 
273 private:
275  sal_Int32 GetWidth() const { return maWinSize.Width(); }
277  sal_Int32 GetHeight() const { return maWinSize.Height(); }
278 
280  SAL_DLLPRIVATE void ImplSetColumnClipRegion( OutputDevice& rOutDev, sal_uInt32 nColIndex );
282  SAL_DLLPRIVATE void ImplDrawColumnHeader( OutputDevice& rOutDev, sal_uInt32 nColIndex, Color aFillColor );
283 
285  SAL_DLLPRIVATE void ImplDrawCellText( const Point& rPos, const OUString& rText );
287  SAL_DLLPRIVATE void ImplDrawFirstLineSep( bool bSet );
289  SAL_DLLPRIVATE void ImplDrawColumnBackgr( sal_uInt32 nColIndex );
291  SAL_DLLPRIVATE void ImplDrawRowHeaders();
293  SAL_DLLPRIVATE void ImplDrawBackgrDev();
294 
296  SAL_DLLPRIVATE void ImplDrawColumnSelection( sal_uInt32 nColIndex );
298  SAL_DLLPRIVATE void ImplDrawGridDev();
299 
301  SAL_DLLPRIVATE void ImplDrawColumn( sal_uInt32 nColIndex );
302 
304  SAL_DLLPRIVATE void ImplDrawHorzScrolled( sal_Int32 nOldPos );
305 
307  SAL_DLLPRIVATE void ImplInvertCursor( sal_Int32 nPos );
308 
309  // accessibility ----------------------------------------------------------
310 protected:
312  virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
313 };
314 
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Color maGridPBColor
Table grid color.
Definition: csvgrid.hxx:68
ConfigurationHints
vcl::Font maMonoFont
Font for column and row headers.
Definition: csvgrid.hxx:79
bool mbTracking
Current column of mouse tracking.
Definition: csvgrid.hxx:91
ScCsvSplits maSplits
Paper size for edit engine.
Definition: csvgrid.hxx:83
::svtools::ColorConfig * mpColorConfig
Popup menu for column types.
Definition: csvgrid.hxx:65
Color maGridColor
Cell background color.
Definition: csvgrid.hxx:67
void Init()
const ScCsvColStateVec & GetColumnStates() const
Returns the vector with the states of all columns.
Definition: csvgrid.hxx:173
bool mbColumnSelected
Data type.
Definition: csvgrid.hxx:44
ScMoveMode
Specifies which element should be used to perform an action.
Definition: csvcontrol.hxx:76
virtual bool MouseButtonUp(const MouseEvent &)
Color maHeaderBackColor
Text color for data area.
Definition: csvgrid.hxx:71
vcl::Font maHeaderFont
For drawing cell texts.
Definition: csvgrid.hxx:78
virtual bool MouseMove(const MouseEvent &)
VclPtr< VirtualDevice > mpGridDev
Grid background, headers, cell texts.
Definition: csvgrid.hxx:62
Base class for the CSV ruler and the data grid control.
Definition: csvcontrol.hxx:222
Accessible base class used for CSV controls.
constexpr tools::Long Width() const
bool mbMTSelecting
True if Mouse tracking.
Definition: csvgrid.hxx:92
Color maTextColor
Background color for unused area.
Definition: csvgrid.hxx:70
sal_uInt16 sal_Unicode
virtual void GetFocus() override
Definition: csvcontrol.cxx:74
ScCsvColState(sal_Int32 nType=CSV_TYPE_DEFAULT)
Definition: csvgrid.hxx:46
std::vector< std::vector< OUString > > maTexts
UI names of data types.
Definition: csvgrid.hxx:86
VclPtr< VirtualDevice > mpBackgrDev
Grid Parent.
Definition: csvgrid.hxx:61
sal_Int32 mnType
Definition: csvgrid.hxx:43
const sal_uInt32 CSV_VEC_NOTFOUND
Constant for an invalid vector index.
Definition: csvsplits.hxx:27
ScCsvTableBox * mpTableBox
Definition: csvgrid.hxx:60
sal_uInt32 mnMTCurrCol
Index of most recently selected column.
Definition: csvgrid.hxx:90
std::vector< OUString > maTypeNames
State of each column.
Definition: csvgrid.hxx:85
Color maAppBackColor
Grid color for "first imported line" delimiter.
Definition: csvgrid.hxx:69
const sal_uInt32 CSV_COLUMN_INVALID
Definition: csvgrid.hxx:38
virtual tools::Rectangle GetFocusRect()
A vector of column splits that supports inserting, removing and moving splits.
Definition: csvsplits.hxx:32
void Select(bool bSel)
Definition: csvgrid.hxx:50
sal_uInt32 GetFocusColumn() const
Returns index of the focused column.
Definition: csvgrid.hxx:219
ScCsvTableBox * GetTableBox()
Definition: csvgrid.hxx:97
virtual bool KeyInput(const KeyEvent &)
sal_Int32 mnFirstImpLine
2D-vector for cell texts.
Definition: csvgrid.hxx:88
sal_uInt32 GetColumnCount() const
Returns the number of columns.
Definition: csvgrid.hxx:149
const sal_Int32 CSV_TYPE_DEFAULT
Default column data type.
Definition: csvcontrol.hxx:47
::std::vector< ScCsvColState > ScCsvColStateVec
Definition: csvgrid.hxx:53
The control in the CSV import dialog that contains a ruler and a data grid to visualize and modify th...
Definition: csvtablebox.hxx:43
virtual void LoseFocus() override
Definition: csvcontrol.cxx:80
constexpr tools::Long Height() const
std::unique_ptr< ScEditEngineDefaulter > mpEditEngine
Header color of selected columns.
Definition: csvgrid.hxx:77
ScCsvColStateVec maColStates
Vector with split positions.
Definition: csvgrid.hxx:84
virtual bool MouseButtonDown(const MouseEvent &)
Color maHeaderGridColor
Background color for headers.
Definition: csvgrid.hxx:72
Color maBackColor
Application color configuration.
Definition: csvgrid.hxx:66
sal_Int32 GetHeight() const
Returns the height of the control.
Definition: csvgrid.hxx:277
Size maWinSize
Monospace font for data cells.
Definition: csvgrid.hxx:80
sal_uInt32 mnRecentSelCol
First imported line (0-based).
Definition: csvgrid.hxx:89
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea)
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:398
Size maEdEngSize
Size of the control.
Definition: csvgrid.hxx:81
virtual void ConfigurationChanged(ConfigurationBroadcaster *p, ConfigurationHints nHint)=0
virtual bool Command(const CommandEvent &)
Color maHeaderTextColor
Grid color for headers.
Definition: csvgrid.hxx:73
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
bool IsSelected() const
Definition: csvgrid.hxx:49
sal_Int32 GetWidth() const
Returns the width of the control.
Definition: csvgrid.hxx:275
sal_Int32 GetGridCursorPos() const
Returns the data grid cursor position (not column index!).
Definition: csvcontrol.hxx:358
sal_Int32 GetColumnPos(sal_uInt32 nColIndex) const
Returns start position of the column with the specified index.
Definition: csvgrid.hxx:166
Color maSelectColor
Text color for headers.
Definition: csvgrid.hxx:74
A data grid control for the CSV import dialog.
Definition: csvgrid.hxx:57
std::unique_ptr< weld::Menu > mxPopup
Data grid with selection and cursor.
Definition: csvgrid.hxx:63
A structure containing all layout data valid for both ruler and data grid (i.e.
Definition: csvcontrol.hxx:111
This struct contains the state of one table column.
Definition: csvgrid.hxx:41