xref: /trunk/main/sc/source/ui/inc/csvtablebox.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // ============================================================================
29 
30 #ifndef _SC_CSVTABLEBOX_HXX
31 #define _SC_CSVTABLEBOX_HXX
32 
33 #include <vcl/ctrl.hxx>
34 #include <vcl/scrbar.hxx>
35 #include "scdllapi.h"
36 #include "csvcontrol.hxx"
37 #include "csvruler.hxx"
38 #include "csvgrid.hxx"
39 
40 
41 class ListBox;
42 class ScAsciiOptions;
43 
44 
45 /* ============================================================================
46 Position: Positions between the characters (the dots in the ruler).
47 Character: The characters (the range from one position to the next).
48 Split: Positions which contain a split to divide characters into groups (columns).
49 Column: The range between two splits.
50 ============================================================================ */
51 
52 /** The control in the CSV import dialog that contains a ruler and a data grid
53     to visualize and modify the current import settings. */
54 class SC_DLLPUBLIC ScCsvTableBox : public ScCsvControl
55 {
56 private:
57     ScCsvLayoutData             maData;             /// Current layout data of the controls.
58 
59     ScCsvRuler                  maRuler;            /// The ruler for fixed width mode.
60     ScCsvGrid                   maGrid;             /// Calc-like data table for fixed width mode.
61     ScrollBar                   maHScroll;          /// Horizontal scroll bar.
62     ScrollBar                   maVScroll;          /// Vertical scroll bar.
63     ScrollBarBox                maScrollBox;        /// For the bottom right edge.
64 
65     Link                        maUpdateTextHdl;    /// Updates all cell texts.
66     Link                        maColTypeHdl;       /// Handler for exporting the column type.
67 
68     ScCsvColStateVec            maFixColStates;     /// Column states in fixed width mode.
69     ScCsvColStateVec            maSepColStates;     /// Column states in separators mode.
70 
71     sal_Int32                   mnFixedWidth;       /// Cached total width for fixed width mode.
72 
73     bool                        mbFixedMode;        /// false = Separators, true = Fixed width.
74 
75     // ------------------------------------------------------------------------
76 public:
77 //UNUSED2009-05 explicit                    ScCsvTableBox( Window* pParent );
78     explicit                    ScCsvTableBox( Window* pParent, const ResId& rResId );
79 
80     // common table box handling ----------------------------------------------
81 public:
82     /** Sets the control to separators mode. */
83     void                        SetSeparatorsMode();
84     /** Sets the control to fixed width mode. */
85     void                        SetFixedWidthMode();
86 
87 private:
88     /** Initialisation on construction. */
89     SC_DLLPRIVATE void                        Init();
90     /** Initializes the children controls (pos/size, scroll bars, ...). */
91     SC_DLLPRIVATE void                        InitControls();
92     /** Initializes size and position data of horizontal scrollbar. */
93     SC_DLLPRIVATE void                        InitHScrollBar();
94     /** Initializes size and position data of vertical scrollbar. */
95     SC_DLLPRIVATE void                        InitVScrollBar();
96 
97     /** Calculates and sets valid position offset nearest to nPos. */
98     SC_DLLPRIVATE inline void                 ImplSetPosOffset( sal_Int32 nPos )
99                                     { maData.mnPosOffset = Max( Min( nPos, GetMaxPosOffset() ), sal_Int32( 0 ) ); }
100     /** Calculates and sets valid line offset nearest to nLine. */
101     SC_DLLPRIVATE inline void                 ImplSetLineOffset( sal_Int32 nLine )
102                                     { maData.mnLineOffset = Max( Min( nLine, GetMaxLineOffset() ), sal_Int32( 0 ) ); }
103     /** Moves controls (not cursors!) so that nPos becomes visible. */
104     SC_DLLPRIVATE void                        MakePosVisible( sal_Int32 nPos );
105 
106     // cell contents ----------------------------------------------------------
107 public:
108     /** Fills all cells of all lines with the passed texts (Unicode strings). */
109     void                        SetUniStrings(
110                                     const String* pTextLines, const String& rSepChars,
111                                     sal_Unicode cTextSep, bool bMergeSep );
112 //UNUSED2009-05 /** Fills all cells of all lines with the passed texts (ByteStrings). */
113 //UNUSED2009-05 void                        SetByteStrings(
114 //UNUSED2009-05                                 const ByteString* pLineTexts, CharSet eCharSet,
115 //UNUSED2009-05                                 const String& rSepChars, sal_Unicode cTextSep, bool bMergeSep );
116 
117     // column settings --------------------------------------------------------
118 public:
119     /** Reads UI strings for data types from the list box. */
120     void                        InitTypes( const ListBox& rListBox );
121     /** Returns the data type of the selected columns. */
122     inline sal_Int32            GetSelColumnType() const { return maGrid.GetSelColumnType(); }
123 
124     /** Fills the options object with current column data. */
125     void                        FillColumnData( ScAsciiOptions& rOptions ) const;
126 
127     // event handling ---------------------------------------------------------
128 public:
129     /** Sets a new handler for "update cell texts" requests. */
130     inline void                 SetUpdateTextHdl( const Link& rHdl ) { maUpdateTextHdl = rHdl; }
131     /** Returns the handler for "update cell texts" requests. */
132     inline const Link&          GetUpdateTextHdl() const { return maUpdateTextHdl; }
133     /** Sets a new handler for "column selection changed" events. */
134     inline void                 SetColTypeHdl( const Link& rHdl ) { maColTypeHdl = rHdl; }
135     /** Returns the handler for "column selection changed" events. */
136     inline const Link&          GetColTypeHdl() const { return maColTypeHdl; }
137 
138 protected:
139     virtual void                Resize();
140     virtual void                DataChanged( const DataChangedEvent& rDCEvt );
141 
142 private:
143     SC_DLLPRIVATE              DECL_LINK( CsvCmdHdl, ScCsvControl* );
144     SC_DLLPRIVATE              DECL_LINK( ScrollHdl, ScrollBar* );
145     SC_DLLPRIVATE              DECL_LINK( ScrollEndHdl, ScrollBar* );
146 
147     // accessibility ----------------------------------------------------------
148 public:
149     /** Creates and returns the accessible object of this control. */
150     virtual XAccessibleRef      CreateAccessible();
151 
152 protected:
153     /** Creates a new accessible object. */
154     virtual ScAccessibleCsvControl* ImplCreateAccessible();
155 };
156 
157 
158 // ============================================================================
159 
160 #endif
161 
162