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