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 // ============================================================================
22 #ifndef _SC_CSVTABLEBOX_HXX
23 #define _SC_CSVTABLEBOX_HXX
25 #include <vcl/ctrl.hxx>
26 #include <vcl/scrbar.hxx>
28 #include "csvcontrol.hxx"
29 #include "csvruler.hxx"
30 #include "csvgrid.hxx"
37 /* ============================================================================
38 Position: Positions between the characters (the dots in the ruler).
39 Character: The characters (the range from one position to the next).
40 Split: Positions which contain a split to divide characters into groups (columns).
41 Column: The range between two splits.
42 ============================================================================ */
44 /** The control in the CSV import dialog that contains a ruler and a data grid
45 to visualize and modify the current import settings. */
46 class SC_DLLPUBLIC ScCsvTableBox
: public ScCsvControl
49 ScCsvLayoutData maData
; /// Current layout data of the controls.
51 ScCsvRuler maRuler
; /// The ruler for fixed width mode.
52 ScCsvGrid maGrid
; /// Calc-like data table for fixed width mode.
53 ScrollBar maHScroll
; /// Horizontal scroll bar.
54 ScrollBar maVScroll
; /// Vertical scroll bar.
55 ScrollBarBox maScrollBox
; /// For the bottom right edge.
57 Link maUpdateTextHdl
; /// Updates all cell texts.
58 Link maColTypeHdl
; /// Handler for exporting the column type.
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.
67 // ------------------------------------------------------------------------
69 explicit ScCsvTableBox( Window
* pParent
, WinBits nBits
);
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();
82 /** Initializes the children controls (pos/size, scroll bars, ...). */
83 SC_DLLPRIVATE
void InitControls();
84 /** Initializes size and position data of horizontal scrollbar. */
85 SC_DLLPRIVATE
void InitHScrollBar();
86 /** Initializes size and position data of vertical scrollbar. */
87 SC_DLLPRIVATE
void InitVScrollBar();
89 /** Calculates and sets valid position offset nearest to nPos. */
90 SC_DLLPRIVATE
inline void ImplSetPosOffset( sal_Int32 nPos
)
91 { maData
.mnPosOffset
= std::max( std::min( nPos
, GetMaxPosOffset() ), sal_Int32( 0 ) ); }
92 /** Calculates and sets valid line offset nearest to nLine. */
93 SC_DLLPRIVATE
inline void ImplSetLineOffset( sal_Int32 nLine
)
94 { maData
.mnLineOffset
= std::max( std::min( nLine
, GetMaxLineOffset() ), sal_Int32( 0 ) ); }
95 /** Moves controls (not cursors!) so that nPos becomes visible. */
96 SC_DLLPRIVATE
void MakePosVisible( sal_Int32 nPos
);
98 // cell contents ----------------------------------------------------------
100 /** Fills all cells of all lines with the passed texts (Unicode strings). */
102 const OUString
* pTextLines
, const OUString
& rSepChars
,
103 sal_Unicode cTextSep
, bool bMergeSep
);
105 // column settings --------------------------------------------------------
107 /** Reads UI strings for data types from the list box. */
108 void InitTypes( const ListBox
& rListBox
);
109 /** Returns the data type of the selected columns. */
110 inline sal_Int32
GetSelColumnType() const { return maGrid
.GetSelColumnType(); }
112 /** Fills the options object with current column data. */
113 void FillColumnData( ScAsciiOptions
& rOptions
) const;
115 // event handling ---------------------------------------------------------
117 /** Sets a new handler for "update cell texts" requests. */
118 inline void SetUpdateTextHdl( const Link
& rHdl
) { maUpdateTextHdl
= rHdl
; }
119 /** Returns the handler for "update cell texts" requests. */
120 inline const Link
& GetUpdateTextHdl() const { return maUpdateTextHdl
; }
121 /** Sets a new handler for "column selection changed" events. */
122 inline void SetColTypeHdl( const Link
& rHdl
) { maColTypeHdl
= rHdl
; }
123 /** Returns the handler for "column selection changed" events. */
124 inline const Link
& GetColTypeHdl() const { return maColTypeHdl
; }
127 virtual void Resize();
128 virtual void DataChanged( const DataChangedEvent
& rDCEvt
);
129 virtual Size
GetOptimalSize() const;
132 SC_DLLPRIVATE
DECL_LINK( CsvCmdHdl
, ScCsvControl
* );
133 SC_DLLPRIVATE
DECL_LINK( ScrollHdl
, ScrollBar
* );
134 SC_DLLPRIVATE
DECL_LINK( ScrollEndHdl
, ScrollBar
* );
136 // accessibility ----------------------------------------------------------
138 /** Creates and returns the accessible object of this control. */
139 virtual XAccessibleRef
CreateAccessible();
142 /** Creates a new accessible object. */
143 virtual ScAccessibleCsvControl
* ImplCreateAccessible();
147 // ============================================================================
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */