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 #ifndef SVTOOLS_INC_TABLE_TABLECONTROL_HXX
25 #define SVTOOLS_INC_TABLE_TABLECONTROL_HXX
26 
27 #include "svtools/svtdllapi.h"
28 #include "svtools/table/tablemodel.hxx"
29 #include "svtools/accessibletable.hxx"
30 #include "svtools/accessiblefactory.hxx"
31 
32 #include <vcl/ctrl.hxx>
33 #include <vcl/seleng.hxx>
34 
35 #include <boost/shared_ptr.hpp>
36 #include <boost/scoped_ptr.hpp>
37 
38 //........................................................................
39 
40 namespace svt { namespace table
41 {
42 //........................................................................
43 
44     class TableControl_Impl;
45 
46     //====================================================================
47 	//= TableControl
48 	//====================================================================
49     /** a basic control which manages table-like data, i.e. a number of cells
50         organized in <code>m</code> rows and <code>n</code> columns.
51 
52         The control itself does not do any assumptions about the concrete data
53         it displays, this is encapsulated in an instance supporting the
54         ->ITableModel interface.
55 
56         Also, the control does not do any assumptions about how the model's
57         content is rendered. This is the responsibility of a component
58         supporting the ->ITableRenderer interface (the renderer is obtained from
59         the model).
60 
61         The control supports the concept of a <em>current</em> (or <em>active</em>
62         cell).
63 		The control supports accessibility, this is encapsulated in IAccessibleTable
64     */
65     class SVT_DLLPUBLIC TableControl : public Control, public IAccessibleTable
66 	{
67     private:
68         ::boost::shared_ptr< TableControl_Impl >            m_pImpl;
69 
70 
71     public:
72         TableControl( Window* _pParent, WinBits _nStyle );
73         ~TableControl();
74 
75         /// sets a new table model
76         void        SetModel( PTableModel _pModel );
77         /// retrieves the current table model
78         PTableModel GetModel() const;
79 
80         /// returns the top row, i.e. the first visible row
81         RowPos  GetTopRow() const;
82         /// sets a new top row. The top row is the first visible row in the control
83         void    SetTopRow( RowPos _nRow );
84 
85         /** retrieves the current row
86 
87             The current row is the one which contains the active cell.
88 
89             @return
90                 the row index of the active cell, or ->ROW_INVALID
91                 if there is no active cell, e.g. because the table does
92                 not contain any rows or columns.
93         */
94         sal_Int32 GetCurrentRow() const;
95 
96         ITableControl&
97                 getTableControlInterface();
98 
99         /** retrieves the current column
100 
101             The current col is the one which contains the active cell.
102 
103             @return
104                 the column index of the active cell, or ->COL_INVALID
105                 if there is no active cell, e.g. because the table does
106                 not contain any rows or columns.
107         */
108         sal_Int32  GetCurrentColumn() const;
109 
110         /** activates the cell at the given position
111 
112             @return
113                 <sal_True/> if the move was successful, <FALSE/> otherwise. Usual
114                 failure conditions include some other instance vetoing the move,
115                 or impossibility to execute the move at all (for instance because
116                 of invalid coordinates).
117         */
118         bool    GoTo( ColPos _nColumnPos, RowPos _nRow);
119 
120         /** moves the active cell to the given column, by keeping the active row
121 
122             @return
123                 <sal_True/> if the move was successful, <FALSE/> otherwise. Usual
124                 failure conditions include some other instance vetoing the move,
125                 or impossibility to execute the move at all (for instance because
126                 of invalid coordinates).
127         */
GoToColumn(ColPos _nColumn)128         inline  bool    GoToColumn( ColPos _nColumn )
129         {
130             return GoTo( _nColumn, GetCurrentRow() );
131         }
132 
133         /** moves the active cell to the given row, by keeping the active column
134 
135             @return
136                 <sal_True/> if the move was successful, <FALSE/> otherwise. Usual
137                 failure conditions include some other instance vetoing the move,
138                 or impossibility to execute the move at all (for instance because
139                 of invalid coordinates).
140         */
GoToRow(RowPos _nRow)141         bool    GoToRow( RowPos _nRow )
142         {
143             return GoTo( GetCurrentColumn(), _nRow );
144         }
145 
146         SVT_DLLPRIVATE virtual void	Resize();
147         virtual void    Select();
148                 void    SetSelectHdl( const Link& rLink );
149         const Link&     GetSelectHdl() const;
150 
151         /**after removing a row, updates the vector which contains the selected rows
152             if the row, which should be removed, is selected, it will be erased from the vector
153         */
154         SelectionEngine*    getSelEngine();
155         Window&             getDataWindow();
156 
157         // Window overridables
158         virtual void        GetFocus();
159         virtual void        LoseFocus();
160         virtual void        KeyInput( const KeyEvent& rKEvt );
161         virtual void        StateChanged( StateChangedType i_nStateChange );
162 
163         /** Creates and returns the accessible object of the whole GridControl. */
164         SVT_DLLPRIVATE virtual XACC CreateAccessible();
165         SVT_DLLPRIVATE virtual XACC CreateAccessibleControl( sal_Int32 _nIndex );
166         SVT_DLLPRIVATE virtual ::rtl::OUString GetAccessibleObjectName(AccessibleTableControlObjType eObjType, sal_Int32 _nRow, sal_Int32 _nCol) const;
167         SVT_DLLPRIVATE virtual sal_Bool GoToCell( sal_Int32 _nColumnPos, sal_Int32 _nRow );
168         SVT_DLLPRIVATE virtual ::rtl::OUString GetAccessibleObjectDescription(AccessibleTableControlObjType eObjType, sal_Int32 _nPosition = -1) const;
169         SVT_DLLPRIVATE virtual void FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& rStateSet, AccessibleTableControlObjType eObjType ) const;
170 
171         // temporary methods
172         // Those do not really belong into the public API - they're intended for firing A11Y-related events. However,
173         // firing those events should be an implementation internal to the TableControl resp. TableControl_Impl,
174         // instead of something triggered externally.
175         void commitCellEventIfAccessibleAlive( sal_Int16 const i_eventID, const ::com::sun::star::uno::Any& i_newValue, const ::com::sun::star::uno::Any& i_oldValue );
176         void commitTableEventIfAccessibleAlive( sal_Int16 const i_eventID, const ::com::sun::star::uno::Any& i_newValue, const ::com::sun::star::uno::Any& i_oldValue );
177 
178         // .............................................................................................................
179         // IAccessibleTable
180         virtual Rectangle GetWindowExtentsRelative( Window *pRelativeWindow ) const;
181         virtual void GrabFocus();
182         virtual XACC GetAccessible( sal_Bool bCreate = sal_True );
183         virtual Window*	GetAccessibleParentWindow() const;
184         virtual Window*	GetWindowInstance();
185         virtual sal_Int32 GetAccessibleControlCount() const;
186         virtual sal_Bool ConvertPointToControlIndex( sal_Int32& _rnIndex, const Point& _rPoint );
187         virtual	long GetRowCount() const;
188         virtual	long GetColumnCount() const;
189         virtual sal_Bool HasRowHeader() const;
190         virtual sal_Bool ConvertPointToCellAddress( sal_Int32& _rnRow, sal_Int32& _rnColPos, const Point& _rPoint );
191         virtual Rectangle calcHeaderRect( sal_Bool _bIsColumnBar, sal_Bool _bOnScreen = sal_True );
192         virtual Rectangle calcHeaderCellRect( sal_Bool _bIsColumnBar, sal_Int32 nPos);
193         virtual Rectangle calcTableRect( sal_Bool _bOnScreen = sal_True );
194         virtual Rectangle calcCellRect( sal_Int32 _nRowPos, sal_Int32 _nColPos );
195         virtual Rectangle GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 nIndex);
196         virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint);
197         virtual void FillAccessibleStateSetForCell( ::utl::AccessibleStateSetHelper& _rStateSet, sal_Int32 _nRow, sal_uInt16 _nColumnPos ) const;
198         virtual ::rtl::OUString	GetRowDescription( sal_Int32 _nRow ) const;
199         virtual ::rtl::OUString GetRowName(sal_Int32 _nIndex) const;
200         virtual ::rtl::OUString	GetColumnDescription( sal_uInt16 _nColumnPos ) const;
201         virtual ::rtl::OUString	GetColumnName( sal_Int32 _nIndex ) const;
202         virtual ::com::sun::star::uno::Any GetCellContent( sal_Int32 _nRowPos, sal_Int32 _nColPos) const;
203         virtual sal_Bool HasRowHeader();
204         virtual sal_Bool HasColHeader();
205         virtual ::rtl::OUString GetAccessibleCellText(sal_Int32 _nRowPos, sal_Int32 _nColPos) const;
206 
207         virtual sal_Int32 GetSelectedRowCount() const;
208         virtual sal_Int32 GetSelectedRowIndex( sal_Int32 const i_selectionIndex ) const;
209 	    virtual bool IsRowSelected( sal_Int32 const i_rowIndex ) const;
210         virtual void SelectRow( sal_Int32 const i_rowIndex, bool const i_select );
211 	    virtual void SelectAllRows( bool const i_select );
212         // .............................................................................................................
213 
214     private:
215         DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* );
216 
217     private:
218         TableControl();                                 // never implemented
219         TableControl( const TableControl& );            // never implemented
220         TableControl& operator=( const TableControl& ); // never implemented
221 	};
222 
223 //........................................................................
224 } } // namespace svt::table
225 //........................................................................
226 
227 #endif // SVTOOLS_INC_TABLE_TABLECONTROL_HXX
228