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 .
20 #ifndef INCLUDED_SC_SOURCE_UI_INC_CSVTABLEBOX_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_CSVTABLEBOX_HXX
23 #include <vcl/idle.hxx>
24 #include <vcl/weld.hxx>
26 #include "csvcontrol.hxx"
27 #include "csvruler.hxx"
28 #include "csvgrid.hxx"
35 /* ============================================================================
36 Position: Positions between the characters (the dots in the ruler).
37 Character: The characters (the range from one position to the next).
38 Split: Positions which contain a split to divide characters into groups (columns).
39 Column: The range between two splits.
40 ============================================================================ */
42 /** The control in the CSV import dialog that contains a ruler and a data grid
43 to visualize and modify the current import settings. */
44 class SC_DLLPUBLIC ScCsvTableBox
47 ScCsvLayoutData maData
; /// Current layout data of the controls.
49 std::unique_ptr
<ScCsvRuler
> mxRuler
; /// The ruler for fixed width mode.
50 std::unique_ptr
<ScCsvGrid
> mxGrid
; /// Calc-like data table for fixed width mode.
51 std::unique_ptr
<weld::ScrolledWindow
> mxScroll
; /// Scrolled Window
52 std::unique_ptr
<weld::CustomWeld
> mxRulerWeld
; /// Connect the ruler to its drawingarea
53 std::unique_ptr
<weld::CustomWeld
> mxGridWeld
; /// connect the grid to its drawingarea
55 Link
<ScCsvTableBox
&,void> maUpdateTextHdl
; /// Updates all cell texts.
56 Link
<ScCsvTableBox
&,void> maColTypeHdl
; /// Handler for exporting the column type.
58 Idle maEndScrollIdle
; /// Called when horizontal scrolling has ended
60 ScCsvColStateVec maFixColStates
; /// Column states in fixed width mode.
61 ScCsvColStateVec maSepColStates
; /// Column states in separators mode.
63 sal_Int32 mnFixedWidth
; /// Cached total width for fixed width mode.
65 bool mbFixedMode
; /// false = Separators, true = Fixed width.
68 explicit ScCsvTableBox(weld::Builder
& rBuilder
);
71 /** Finishes initialization. Must be called after constructing a new object. */
74 // 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();
81 ScCsvRuler
& GetRuler() { return *mxRuler
; }
82 ScCsvGrid
& GetGrid() { return *mxGrid
; }
84 /** Initializes the children controls (pos/size, scroll bars, ...). */
85 SAL_DLLPRIVATE
void InitControls();
88 /** Initializes size and position data of horizontal scrollbar. */
89 SAL_DLLPRIVATE
void InitHScrollBar();
90 /** Initializes size and position data of vertical scrollbar. */
91 SAL_DLLPRIVATE
void InitVScrollBar();
93 /** Calculates and sets valid position offset nearest to nPos. */
94 SAL_DLLPRIVATE
void ImplSetPosOffset( sal_Int32 nPos
)
95 { maData
.mnPosOffset
= std::max( std::min( nPos
, mxGrid
->GetMaxPosOffset() ), sal_Int32( 0 ) ); }
96 /** Calculates and sets valid line offset nearest to nLine. */
97 SAL_DLLPRIVATE
void ImplSetLineOffset( sal_Int32 nLine
)
98 { maData
.mnLineOffset
= std::max( std::min( nLine
, mxGrid
->GetMaxLineOffset() ), sal_Int32( 0 ) ); }
99 /** Moves controls (not cursors!) so that nPos becomes visible. */
100 SAL_DLLPRIVATE
void MakePosVisible( sal_Int32 nPos
);
102 // cell contents ----------------------------------------------------------
104 /** Fills all cells of all lines with the passed texts (Unicode strings). */
106 const OUString
* pTextLines
, const OUString
& rSepChars
,
107 sal_Unicode cTextSep
, bool bMergeSep
, bool bRemoveSpace
);
109 // column settings --------------------------------------------------------
111 /** Reads UI strings for data types from the list box. */
112 void InitTypes(const weld::ComboBox
& rListBox
);
113 /** Returns the data type of the selected columns. */
114 sal_Int32
GetSelColumnType() const { return mxGrid
->GetSelColumnType(); }
116 /** Fills the options object with current column data. */
117 void FillColumnData( ScAsciiOptions
& rOptions
) const;
119 // event handling ---------------------------------------------------------
121 /** Sets a new handler for "update cell texts" requests. */
122 void SetUpdateTextHdl( const Link
<ScCsvTableBox
&,void>& rHdl
) { maUpdateTextHdl
= rHdl
; }
123 /** Sets a new handler for "column selection changed" events. */
124 void SetColTypeHdl( const Link
<ScCsvTableBox
&,void>& rHdl
) { maColTypeHdl
= rHdl
; }
127 DECL_DLLPRIVATE_LINK( CsvCmdHdl
, ScCsvControl
&, void );
128 DECL_DLLPRIVATE_LINK( HScrollHdl
, weld::ScrolledWindow
&, void );
129 DECL_DLLPRIVATE_LINK( VScrollHdl
, weld::ScrolledWindow
&, void );
130 DECL_DLLPRIVATE_LINK( ScrollEndHdl
, Timer
*, void );
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */