merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / table / tablecontrol_impl.hxx
blob938e7894140149412aa250e2a84df813be12d4f3
1 /*************************************************************************
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3 *
4 * Copyright 2009 by Sun Microsystems, Inc.
6 * OpenOffice.org - a multi-platform office productivity suite
8 * This file is part of OpenOffice.org.
10 * OpenOffice.org is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License version 3
12 * only, as published by the Free Software Foundation.
14 * OpenOffice.org is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License version 3 for more details
18 * (a copy is included in the LICENSE file that accompanied this code).
20 * You should have received a copy of the GNU Lesser General Public License
21 * version 3 along with OpenOffice.org. If not, see
22 * <http://www.openoffice.org/license.html>
23 * for a copy of the LGPLv3 License.
24 ************************************************************************/
26 #ifndef SVTOOLS_TABLECONTROL_IMPL_HXX
27 #define SVTOOLS_TABLECONTROL_IMPL_HXX
29 #ifndef SVTOOLS_INC_TABLE_TABLEMODEL_HXX
30 #include <svtools/table/tablemodel.hxx>
31 #endif
33 #ifndef SVTOOLS_INC_TABLE_ABSTRACTTABLECONTROL_HXX
34 #include <svtools/table/abstracttablecontrol.hxx>
35 #endif
37 #include <svtools/table/tablemodel.hxx>
38 #include <vector>
39 #include <vcl/seleng.hxx>
41 class ScrollBar;
42 class ScrollBarBox;
44 //........................................................................
45 namespace svt { namespace table
47 //........................................................................
49 typedef ::std::vector< long > ArrayOfLong;
51 class TableControl;
52 class TableDataWindow;
53 class TableFunctionSet;
55 //====================================================================
56 //= TableControl_Impl
57 //====================================================================
58 class TableControl_Impl : public IAbstractTableControl
60 friend class TableGeometry;
61 friend class TableRowGeometry;
62 friend class TableColumnGeometry;
63 friend class SuspendInvariants;
64 friend class TableFunctionSet;
65 private:
66 /// the control whose impl-instance we implemnt
67 TableControl& m_rAntiImpl;
68 /// the model of the table control
69 PTableModel m_pModel;
70 /// the input handler to use, usually the input handler as provided by ->m_pModel
71 PTableInputHandler m_pInputHandler;
72 /// the widths of the single columns, measured in pixel
73 ArrayOfLong m_aColumnWidthsPixel;
74 /** the accumulated widths of the single columns, i.e. their exclusive right borders,
75 <strong<not</strong> counting the space for a possible row header column
77 ArrayOfLong m_aAccColumnWidthsPixel;
78 /// the height of a single row in the table, measured in pixels
79 long m_nRowHeightPixel;
80 /// the height of the column header row in the table, measured in pixels
81 long m_nColHeaderHeightPixel;
82 /// the width of the row header column in the table, measured in pixels
83 long m_nRowHeaderWidthPixel;
85 /// the number of columns in the table control. Cached model value.
86 TableSize m_nColumnCount;
87 /// the number of rows in the table control. Cached model value.
88 TableSize m_nRowCount;
90 ColPos m_nCurColumn;
91 RowPos m_nCurRow;
92 ColPos m_nLeftColumn;
93 RowPos m_nTopRow;
95 sal_Int32 m_nCursorHidden;
97 /** the window to contain all data content, including header bars
99 The window's upper left corner is at position (0,0), relative to the
100 table control, which is the direct parent of the data window.
102 TableDataWindow* m_pDataWindow;
103 /// the vertical scrollbar, if any
104 ScrollBar* m_pVScroll;
105 /// the horizontal scrollbar, if any
106 ScrollBar* m_pHScroll;
107 ScrollBarBox* m_pScrollCorner;
108 //selection engine - for determining selection range, e.g. single, multiple
109 SelectionEngine* m_pSelEngine;
110 //vector which contains the selected rows
111 std::vector<RowPos> m_nRowSelected;
112 //part of selection engine
113 TableFunctionSet* m_pTableFunctionSet;
114 //part of selection engine
115 RowPos m_nAnchor;
119 #if DBG_UTIL
120 #define INV_SCROLL_POSITION 1
121 /** represents a bitmask of invariants to check
123 Actually, impl_checkInvariants checks more invariants than denoted in this
124 bit mask, but only those present here can be disabled temporarily.
126 sal_Int32 m_nRequiredInvariants;
127 #endif
129 public:
132 PTableModel getModel() const;
133 void setModel( PTableModel _pModel );
135 inline const PTableInputHandler& getInputHandler() const { return m_pInputHandler; }
137 inline ColPos getCurColumn() const { return m_nCurColumn; }
138 inline RowPos getCurRow() const { return m_nCurRow; }
139 inline void setCurRow(RowPos curRow){ m_nCurRow = curRow; }
140 inline RowPos getTopRow() const { return m_nTopRow; }
142 inline long getColHeaderHightPixel() const { return m_nColHeaderHeightPixel; }
144 inline const TableControl& getAntiImpl() const { return m_rAntiImpl; }
145 inline TableControl& getAntiImpl() { return m_rAntiImpl; }
146 void setCellContent(CellEntryType* pCellEntryType);
148 public:
149 TableControl_Impl( TableControl& _rAntiImpl );
150 ~TableControl_Impl();
152 #if DBG_UTIL
153 const sal_Char* impl_checkInvariants() const;
154 #endif
155 /** to be called when the anti-impl instance has been resized
157 void onResize();
159 /** paints the table control content which intersects with the given rectangle
161 void doPaintContent( const Rectangle& _rUpdateRect );
163 /** moves the cursor to the cell with the given coordinates
165 To ease the caller's code, the coordinates must not necessarily denote a
166 valid position. If they don't, <FALSE/> will be returned.
168 bool goTo( ColPos _nColumn, RowPos _nRow );
170 /** ensures that the given coordinate is visible
171 @param _nColumn
172 the column position which should be visible. Must be non-negative, and smaller
173 than the column count.
174 @param _nRow
175 the row position which should be visibleMust be non-negative, and smaller
176 than the row count.
177 @param _bAcceptPartialVisibility
178 <TRUE/> if it's okay that the given cooordinate is only partially visible
180 void ensureVisible( ColPos _nColumn, RowPos _nRow, bool _bAcceptPartialVisibility );
181 /** returns the row, which contains the input point*/
182 RowPos getCurrentRow (const Point& rPoint);
184 void setCursorAtCurrentCell(const Point& rPoint);
185 /** proves whether the vector with the selected rows contains the current row*/
186 BOOL isRowSelected(::std::vector<RowPos> selectedRows, RowPos current);
187 /** returns the position of the current row in the selecttion vector */
188 int getRowSelectedNumber(::std::vector<RowPos> selectedRows, RowPos current);
189 /** _rCellRect contains the region, which should be invalidate after some action e.g. selectiong row*/
190 void invalidateSelectedRegion(RowPos _nPrevRow, RowPos _nCurRow, Rectangle& _rCellRect );
191 /** _rCellRect contains the region, which should be invalidate after some action e.g. selectiong row*/
192 //vielleicht kann man mit den anderen verschmelzen, mit einer Überprüfung ob prev==curr?
193 void invalidateSelectedRow( RowPos _nCurRow, Rectangle& _rCellRect );
194 /** to be called when a new row is added to the control*/
195 void invalidateRow(RowPos _nRowPos, Rectangle& _rCellRect );
196 /** returns the vector, which contains the selected rows*/
197 std::vector<RowPos> getSelectedRows();
198 /** updates the vector, which contains the selected rows after removing the row nRowPos*/
199 void removeSelectedRow(RowPos _nRowPos);
200 void invalidateRows(RowPos _nRowStart, Rectangle& _rCellRect );
201 //virtual void DoubleClick();
203 // IAbstractTableControl
204 virtual void hideCursor();
205 virtual void showCursor();
206 virtual bool dispatchAction( TableControlAction _eAction );
207 virtual bool isClickInVisibleArea(const Point& rPoint);
208 virtual SelectionEngine* getSelEngine();
210 TableDataWindow* getDataWindow();
212 private:
213 /** toggles the cursor visibility
215 The method is not bound to the classes public invariants, as it's used in
216 situations where the they must not necessarily be fullfilled.
218 void impl_ni_doSwitchCursor( bool _bOn );
220 /** retrieves the area occupied by the totality of (at least partially) visible cells
222 The returned area includes row and column headers. Also, it takes into
223 account the the fact that there might be less columns than would normally
224 find room in the control.
226 As a result of respecting the partial visibility of rows and columns,
227 the returned area might be larger than the data window's output size.
229 void impl_getAllVisibleCellsArea( Rectangle& _rCellArea ) const;
231 /** retrieves the area occupied by all (at least partially) visible data cells.
233 Effectively, the returned area is the same as returned by ->impl_getAllVisibleCellsArea,
234 minus the row and column header areas.
236 void impl_getAllVisibleDataCellArea( Rectangle& _rCellArea ) const;
238 /** returns the number of visible rows.
240 @param _bAcceptPartialRow
241 specifies whether a possible only partially visible last row is
242 counted, too.
244 TableSize impl_getVisibleRows( bool _bAcceptPartialRow ) const;
246 /** returns the number of visible columns
248 The value may change with different horizontal scroll positions, as
249 different columns have different widths. For instance, if your control is
250 100 pixels wide, and has three columns of width 50, 50, 100, respectively,
251 then this method will return either "2" or "1", depending on which column
252 is the first visible one.
254 @param _bAcceptPartialRow
255 specifies whether a possible only partially visible last row is
256 counted, too.
258 TableSize impl_getVisibleColumns( bool _bAcceptPartialRow ) const;
260 /** determines the rectangle occupied by the given cell
262 void impl_getCellRect( ColPos _nColumn, RowPos _nRow, Rectangle& _rCellRect ) const;
264 /** updates all cached model values
266 The method is not bound to the classes public invariants, as it's used in
267 situations where the they must not necessarily be fullfilled.
269 void impl_ni_updateCachedModelValues();
271 /** updates ->m_aColumnWidthsPixel with the current pixel widths of all model columns
273 The method takes into account the current zoom factor and map mode of the table
274 control, plus any possible COLWIDTH_FIT_TO_VIEW widths in the model columns.
276 The method is not bound to the classes public invariants, as it's used in
277 situations where the they must not necessarily be fullfilled.
279 void impl_ni_updateColumnWidths();
281 /** updates the scrollbars of the control
283 The method is not bound to the classes public invariants, as it's used in
284 situations where the they must not necessarily be fullfilled.
286 This includes both the existence of the scrollbars, and their
287 state.
289 void impl_ni_updateScrollbars();
291 /** scrolls the view by the given number of rows
293 The method is not bound to the classes public invariants, as it's used in
294 situations where the they must not necessarily be fullfilled.
296 @return
297 the number of rows by which the viewport was scrolled. This may differ
298 from the given numbers to scroll in case the begin or the end of the
299 row range were reached.
301 TableSize impl_ni_ScrollRows( TableSize _nRowDelta );
303 /** scrolls the view by the given number of columns
305 The method is not bound to the classes public invariants, as it's used in
306 situations where the they must not necessarily be fullfilled.
308 @return
309 the number of columns by which the viewport was scrolled. This may differ
310 from the given numbers to scroll in case the begin or the end of the
311 column range were reached.
313 TableSize impl_ni_ScrollColumns( TableSize _nRowDelta );
315 DECL_LINK( OnScroll, ScrollBar* );
317 //see seleng.hxx, seleng.cxx, FunctionSet overwritables, part of selection engine
318 class TableFunctionSet : public FunctionSet
320 friend class TableDataWindow;
321 private:
322 TableControl_Impl* m_pTableControl;
323 RowPos m_nCurrentRow;
324 public:
325 TableFunctionSet(TableControl_Impl* _pTableControl);
326 virtual ~TableFunctionSet();
328 virtual void BeginDrag();
329 virtual void CreateAnchor();
330 virtual void DestroyAnchor();
331 virtual BOOL SetCursorAtPoint(const Point& rPoint, BOOL bDontSelectAtCursor);
332 virtual BOOL IsSelectionAtPoint( const Point& rPoint );
333 virtual void DeselectAtPoint( const Point& rPoint );
334 virtual void DeselectAll();
338 //........................................................................
339 } } // namespace svt::table
340 //........................................................................
342 #endif // SVTOOLS_TABLECONTROL_IMPL_HXX