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 .
22 #include <vcl/idle.hxx>
23 #include <vcl/weld.hxx>
25 #include "csvcontrol.hxx"
26 #include "csvruler.hxx"
27 #include "csvgrid.hxx"
34 /* ============================================================================
35 Position: Positions between the characters (the dots in the ruler).
36 Character: The characters (the range from one position to the next).
37 Split: Positions which contain a split to divide characters into groups (columns).
38 Column: The range between two splits.
39 ============================================================================ */
41 /** The control in the CSV import dialog that contains a ruler and a data grid
42 to visualize and modify the current import settings. */
43 class SC_DLLPUBLIC ScCsvTableBox
46 ScCsvLayoutData maData
; /// Current layout data of the controls.
48 std::unique_ptr
<ScCsvRuler
> mxRuler
; /// The ruler for fixed width mode.
49 std::unique_ptr
<ScCsvGrid
> mxGrid
; /// Calc-like data table for fixed width mode.
50 std::unique_ptr
<weld::ScrolledWindow
> mxScroll
; /// Scrolled Window
51 std::unique_ptr
<weld::CustomWeld
> mxRulerWeld
; /// Connect the ruler to its drawingarea
52 std::unique_ptr
<weld::CustomWeld
> mxGridWeld
; /// connect the grid to its drawingarea
54 Link
<ScCsvTableBox
&,void> maUpdateTextHdl
; /// Updates all cell texts.
55 Link
<ScCsvTableBox
&,void> maColTypeHdl
; /// Handler for exporting the column type.
57 Idle maEndScrollIdle
; /// Called when horizontal scrolling has ended
59 ScCsvColStateVec maFixColStates
; /// Column states in fixed width mode.
60 ScCsvColStateVec maSepColStates
; /// Column states in separators mode.
62 sal_Int32 mnFixedWidth
; /// Cached total width for fixed width mode.
64 bool mbFixedMode
; /// false = Separators, true = Fixed width.
67 explicit ScCsvTableBox(weld::Builder
& rBuilder
);
70 /** Finishes initialization. Must be called after constructing a new object. */
73 // common table box handling ----------------------------------------------
76 /** Sets the control to separators mode. */
77 void SetSeparatorsMode();
78 /** Sets the control to fixed width mode. */
79 void SetFixedWidthMode();
80 bool IsFixedWidthMode(){ return mbFixedMode
; }
82 ScCsvRuler
& GetRuler() { return *mxRuler
; }
83 ScCsvGrid
& GetGrid() { return *mxGrid
; }
85 /** Initializes the children controls (pos/size, scroll bars, ...). */
86 SAL_DLLPRIVATE
void InitControls();
89 /** Initializes size and position data of horizontal scrollbar. */
90 SAL_DLLPRIVATE
void InitHScrollBar();
91 /** Initializes size and position data of vertical scrollbar. */
92 SAL_DLLPRIVATE
void InitVScrollBar();
94 /** Calculates and sets valid position offset nearest to nPos. */
95 SAL_DLLPRIVATE
void ImplSetPosOffset( sal_Int32 nPos
)
96 { maData
.mnPosOffset
= std::clamp( nPos
, sal_Int32(0), mxGrid
->GetMaxPosOffset() ); }
97 /** Calculates and sets valid line offset nearest to nLine. */
98 SAL_DLLPRIVATE
void ImplSetLineOffset( sal_Int32 nLine
)
99 { maData
.mnLineOffset
= std::clamp( nLine
, sal_Int32(0), mxGrid
->GetMaxLineOffset() ); }
100 /** Moves controls (not cursors!) so that nPos becomes visible. */
101 SAL_DLLPRIVATE
void MakePosVisible( sal_Int32 nPos
);
103 // cell contents ----------------------------------------------------------
105 /** Fills all cells of all lines with the passed texts (Unicode strings). */
107 const OUString
* pTextLines
, const OUString
& rSepChars
,
108 sal_Unicode cTextSep
, bool bMergeSep
, bool bRemoveSpace
);
110 // column settings --------------------------------------------------------
112 /** Reads UI strings for data types from the list box. */
113 void InitTypes(const weld::ComboBox
& rListBox
);
114 /** Returns the data type of the selected columns. */
115 sal_Int32
GetSelColumnType() const { return mxGrid
->GetSelColumnType(); }
117 /** Fills the options object with current column data. */
118 void FillColumnData( ScAsciiOptions
& rOptions
) const;
120 // event handling ---------------------------------------------------------
122 /** Sets a new handler for "update cell texts" requests. */
123 void SetUpdateTextHdl( const Link
<ScCsvTableBox
&,void>& rHdl
) { maUpdateTextHdl
= rHdl
; }
124 /** Sets a new handler for "column selection changed" events. */
125 void SetColTypeHdl( const Link
<ScCsvTableBox
&,void>& rHdl
) { maColTypeHdl
= rHdl
; }
128 DECL_DLLPRIVATE_LINK( CsvCmdHdl
, ScCsvControl
&, void );
129 DECL_DLLPRIVATE_LINK( HScrollHdl
, weld::ScrolledWindow
&, void );
130 DECL_DLLPRIVATE_LINK( VScrollHdl
, weld::ScrolledWindow
&, void );
131 DECL_DLLPRIVATE_LINK( ScrollEndHdl
, Timer
*, void );
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */