xref: /trunk/main/sc/source/ui/inc/csvtablebox.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // ============================================================================
25 
26 #ifndef _SC_CSVTABLEBOX_HXX
27 #define _SC_CSVTABLEBOX_HXX
28 
29 #include <vcl/ctrl.hxx>
30 #include <vcl/scrbar.hxx>
31 #include "scdllapi.h"
32 #include "csvcontrol.hxx"
33 #include "csvruler.hxx"
34 #include "csvgrid.hxx"
35 
36 
37 class ListBox;
38 class ScAsciiOptions;
39 
40 
41 /* ============================================================================
42 Position: Positions between the characters (the dots in the ruler).
43 Character: The characters (the range from one position to the next).
44 Split: Positions which contain a split to divide characters into groups (columns).
45 Column: The range between two splits.
46 ============================================================================ */
47 
48 /** The control in the CSV import dialog that contains a ruler and a data grid
49     to visualize and modify the current import settings. */
50 class SC_DLLPUBLIC ScCsvTableBox : public ScCsvControl
51 {
52 private:
53     ScCsvLayoutData             maData;             /// Current layout data of the controls.
54 
55     ScCsvRuler                  maRuler;            /// The ruler for fixed width mode.
56     ScCsvGrid                   maGrid;             /// Calc-like data table for fixed width mode.
57     ScrollBar                   maHScroll;          /// Horizontal scroll bar.
58     ScrollBar                   maVScroll;          /// Vertical scroll bar.
59     ScrollBarBox                maScrollBox;        /// For the bottom right edge.
60 
61     Link                        maUpdateTextHdl;    /// Updates all cell texts.
62     Link                        maColTypeHdl;       /// Handler for exporting the column type.
63 
64     ScCsvColStateVec            maFixColStates;     /// Column states in fixed width mode.
65     ScCsvColStateVec            maSepColStates;     /// Column states in separators mode.
66 
67     sal_Int32                   mnFixedWidth;       /// Cached total width for fixed width mode.
68 
69     bool                        mbFixedMode;        /// false = Separators, true = Fixed width.
70 
71     // ------------------------------------------------------------------------
72 public:
73 //UNUSED2009-05 explicit                    ScCsvTableBox( Window* pParent );
74     explicit                    ScCsvTableBox( Window* pParent, const ResId& rResId );
75 
76     // common table box handling ----------------------------------------------
77 public:
78     /** Sets the control to separators mode. */
79     void                        SetSeparatorsMode();
80     /** Sets the control to fixed width mode. */
81     void                        SetFixedWidthMode();
82 
83 private:
84     /** Initialisation on construction. */
85     SC_DLLPRIVATE void                        Init();
86     /** Initializes the children controls (pos/size, scroll bars, ...). */
87     SC_DLLPRIVATE void                        InitControls();
88     /** Initializes size and position data of horizontal scrollbar. */
89     SC_DLLPRIVATE void                        InitHScrollBar();
90     /** Initializes size and position data of vertical scrollbar. */
91     SC_DLLPRIVATE void                        InitVScrollBar();
92 
93     /** Calculates and sets valid position offset nearest to nPos. */
ImplSetPosOffset(sal_Int32 nPos)94     SC_DLLPRIVATE inline void                 ImplSetPosOffset( sal_Int32 nPos )
95                                     { maData.mnPosOffset = Max( Min( nPos, GetMaxPosOffset() ), sal_Int32( 0 ) ); }
96     /** Calculates and sets valid line offset nearest to nLine. */
ImplSetLineOffset(sal_Int32 nLine)97     SC_DLLPRIVATE inline void                 ImplSetLineOffset( sal_Int32 nLine )
98                                     { maData.mnLineOffset = Max( Min( nLine, GetMaxLineOffset() ), sal_Int32( 0 ) ); }
99     /** Moves controls (not cursors!) so that nPos becomes visible. */
100     SC_DLLPRIVATE void                        MakePosVisible( sal_Int32 nPos );
101 
102     // cell contents ----------------------------------------------------------
103 public:
104     /** Fills all cells of all lines with the passed texts (Unicode strings). */
105     void                        SetUniStrings(
106                                     const String* pTextLines, const String& rSepChars,
107                                     sal_Unicode cTextSep, bool bMergeSep );
108 //UNUSED2009-05 /** Fills all cells of all lines with the passed texts (ByteStrings). */
109 //UNUSED2009-05 void                        SetByteStrings(
110 //UNUSED2009-05                                 const ByteString* pLineTexts, CharSet eCharSet,
111 //UNUSED2009-05                                 const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep );
112 
113     // column settings --------------------------------------------------------
114 public:
115     /** Reads UI strings for data types from the list box. */
116     void                        InitTypes( const ListBox& rListBox );
117     /** Returns the data type of the selected columns. */
GetSelColumnType() const118     inline sal_Int32            GetSelColumnType() const { return maGrid.GetSelColumnType(); }
119 
120     /** Fills the options object with current column data. */
121     void                        FillColumnData( ScAsciiOptions& rOptions ) const;
122 
123     // event handling ---------------------------------------------------------
124 public:
125     /** Sets a new handler for "update cell texts" requests. */
SetUpdateTextHdl(const Link & rHdl)126     inline void                 SetUpdateTextHdl( const Link& rHdl ) { maUpdateTextHdl = rHdl; }
127     /** Returns the handler for "update cell texts" requests. */
GetUpdateTextHdl() const128     inline const Link&          GetUpdateTextHdl() const { return maUpdateTextHdl; }
129     /** Sets a new handler for "column selection changed" events. */
SetColTypeHdl(const Link & rHdl)130     inline void                 SetColTypeHdl( const Link& rHdl ) { maColTypeHdl = rHdl; }
131     /** Returns the handler for "column selection changed" events. */
GetColTypeHdl() const132     inline const Link&          GetColTypeHdl() const { return maColTypeHdl; }
133 
134 protected:
135     virtual void                Resize();
136     virtual void                DataChanged( const DataChangedEvent& rDCEvt );
137 
138 private:
139     SC_DLLPRIVATE              DECL_LINK( CsvCmdHdl, ScCsvControl* );
140     SC_DLLPRIVATE              DECL_LINK( ScrollHdl, ScrollBar* );
141     SC_DLLPRIVATE              DECL_LINK( ScrollEndHdl, ScrollBar* );
142 
143     // accessibility ----------------------------------------------------------
144 public:
145     /** Creates and returns the accessible object of this control. */
146     virtual XAccessibleRef      CreateAccessible();
147 
148 protected:
149     /** Creates a new accessible object. */
150     virtual ScAccessibleCsvControl* ImplCreateAccessible();
151 };
152 
153 
154 // ============================================================================
155 
156 #endif
157 
158