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/ctrl.hxx>
24 #include <vcl/scrbar.hxx>
25 #include <vcl/vclptr.hxx>
27 #include "csvcontrol.hxx"
28 #include "csvruler.hxx"
29 #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
: public ScCsvControl
46 ScCsvLayoutData maData
; /// Current layout data of the controls.
48 VclPtr
<ScCsvRuler
> maRuler
; /// The ruler for fixed width mode.
49 VclPtr
<ScCsvGrid
> maGrid
; /// Calc-like data table for fixed width mode.
50 VclPtr
<ScrollBar
> maHScroll
; /// Horizontal scroll bar.
51 VclPtr
<ScrollBar
> maVScroll
; /// Vertical scroll bar.
52 VclPtr
<ScrollBarBox
> maScrollBox
; /// For the bottom right edge.
54 Link
<> maUpdateTextHdl
; /// Updates all cell texts.
55 Link
<> maColTypeHdl
; /// Handler for exporting the column type.
57 ScCsvColStateVec maFixColStates
; /// Column states in fixed width mode.
58 ScCsvColStateVec maSepColStates
; /// Column states in separators mode.
60 sal_Int32 mnFixedWidth
; /// Cached total width for fixed width mode.
62 bool mbFixedMode
; /// false = Separators, true = Fixed width.
65 explicit ScCsvTableBox( vcl::Window
* pParent
, WinBits nBits
);
66 virtual ~ScCsvTableBox();
67 virtual void dispose() SAL_OVERRIDE
;
69 /** Finishes initialization. Must be called after constructing a new object. */
72 // common table box handling ----------------------------------------------
74 /** Sets the control to separators mode. */
75 void SetSeparatorsMode();
76 /** Sets the control to fixed width mode. */
77 void SetFixedWidthMode();
80 /** Initializes the children controls (pos/size, scroll bars, ...). */
81 SAL_DLLPRIVATE
void InitControls();
82 /** Initializes size and position data of horizontal scrollbar. */
83 SAL_DLLPRIVATE
void InitHScrollBar();
84 /** Initializes size and position data of vertical scrollbar. */
85 SAL_DLLPRIVATE
void InitVScrollBar();
87 /** Calculates and sets valid position offset nearest to nPos. */
88 SAL_DLLPRIVATE
inline void ImplSetPosOffset( sal_Int32 nPos
)
89 { maData
.mnPosOffset
= std::max( std::min( nPos
, GetMaxPosOffset() ), sal_Int32( 0 ) ); }
90 /** Calculates and sets valid line offset nearest to nLine. */
91 SAL_DLLPRIVATE
inline void ImplSetLineOffset( sal_Int32 nLine
)
92 { maData
.mnLineOffset
= std::max( std::min( nLine
, GetMaxLineOffset() ), sal_Int32( 0 ) ); }
93 /** Moves controls (not cursors!) so that nPos becomes visible. */
94 SAL_DLLPRIVATE
void MakePosVisible( sal_Int32 nPos
);
96 // cell contents ----------------------------------------------------------
98 /** Fills all cells of all lines with the passed texts (Unicode strings). */
100 const OUString
* pTextLines
, const OUString
& rSepChars
,
101 sal_Unicode cTextSep
, bool bMergeSep
);
103 // column settings --------------------------------------------------------
105 /** Reads UI strings for data types from the list box. */
106 void InitTypes( const ListBox
& rListBox
);
107 /** Returns the data type of the selected columns. */
108 inline sal_Int32
GetSelColumnType() const { return maGrid
->GetSelColumnType(); }
110 /** Fills the options object with current column data. */
111 void FillColumnData( ScAsciiOptions
& rOptions
) const;
113 // event handling ---------------------------------------------------------
115 /** Sets a new handler for "update cell texts" requests. */
116 inline void SetUpdateTextHdl( const Link
<>& rHdl
) { maUpdateTextHdl
= rHdl
; }
117 /** Returns the handler for "update cell texts" requests. */
118 inline const Link
<>& GetUpdateTextHdl() const { return maUpdateTextHdl
; }
119 /** Sets a new handler for "column selection changed" events. */
120 inline void SetColTypeHdl( const Link
<>& rHdl
) { maColTypeHdl
= rHdl
; }
121 /** Returns the handler for "column selection changed" events. */
122 inline const Link
<>& GetColTypeHdl() const { return maColTypeHdl
; }
125 virtual void Resize() SAL_OVERRIDE
;
126 virtual void DataChanged( const DataChangedEvent
& rDCEvt
) SAL_OVERRIDE
;
127 virtual Size
GetOptimalSize() const SAL_OVERRIDE
;
130 DECL_DLLPRIVATE_LINK( CsvCmdHdl
, ScCsvControl
* );
131 DECL_DLLPRIVATE_LINK( ScrollHdl
, ScrollBar
* );
132 DECL_DLLPRIVATE_LINK( ScrollEndHdl
, ScrollBar
* );
134 // accessibility ----------------------------------------------------------
136 /** Creates and returns the accessible object of this control. */
137 virtual XAccessibleRef
CreateAccessible() SAL_OVERRIDE
;
140 /** Creates a new accessible object. */
141 virtual ScAccessibleCsvControl
* ImplCreateAccessible() SAL_OVERRIDE
;
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */