1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include <sal/types.h>
23 #include <vcl/seleng.hxx>
24 #include <vcl/window.hxx>
25 
26 #include <table/tabletypes.hxx>
27 #include <table/tablemodel.hxx>
28 
29 namespace svt::table
30 {
31     //= TableControlAction
32     enum TableControlAction
33     {
34         /// moves the cursor in the table control one row up, if possible, by keeping the current column
35         cursorUp,
36         /// moves the cursor in the table control one row down, if possible, by keeping the current column
37         cursorDown,
38         /// moves the cursor in the table control one column to the left, if possible, by keeping the current row
39         cursorLeft,
40         /// moves the cursor in the table control one column to the right, if possible, by keeping the current row
41         cursorRight,
42         /// moves the cursor to the beginning of the current line
43         cursorToLineStart,
44         /// moves the cursor to the end of the current line
45         cursorToLineEnd,
46         /// moves the cursor to the first row, keeping the current column
47         cursorToFirstLine,
48         /// moves the cursor to the last row, keeping the current column
49         cursorToLastLine,
50         /// moves the cursor one page up, keeping the current column
51         cursorPageUp,
52         /// moves the cursor one page down, keeping the current column
53         cursorPageDown,
54         /// moves the cursor to the top-most, left-most cell
55         cursorTopLeft,
56         /// moves the cursor to the bottom-most, right-most cell
57         cursorBottomRight,
58         /// selects the row, where the actual cursor is
59         cursorSelectRow,
60         /// selects the rows, above the actual cursor is
61         cursorSelectRowUp,
62         /// selects the row, beneath the actual cursor is
63         cursorSelectRowDown,
64         /// selects the row, from the actual cursor till top
65         cursorSelectRowAreaTop,
66         /// selects the row, from the actual cursor till bottom
67         cursorSelectRowAreaBottom,
68 
69         /// invalid and final enumeration value, not to be actually used
70         invalidTableControlAction
71     };
72 
73 
74     //= TableCellArea
75 
76     enum TableCellArea
77     {
78         CellContent,
79         ColumnDivider
80     };
81 
82 
83     //= TableCell
84 
85     struct TableCell
86     {
87         ColPos          nColumn;
88         RowPos          nRow;
89         TableCellArea   eArea;
90 
TableCellsvt::table::TableCell91         TableCell( ColPos const i_column, RowPos const i_row )
92             :nColumn( i_column )
93             ,nRow( i_row )
94             ,eArea( CellContent )
95         {
96         }
97     };
98 
99 
100     //= ColumnMetrics
101 
102     struct ColumnMetrics
103     {
104         /** the start of the column, in pixels. Might be negative, in case the column is scrolled out of the visible
105             area. Note: see below.
106         */
107         tools::Long    nStartPixel;
108 
109         /** the end of the column, in pixels, plus 1. Effectively, this is the accumulated width of all columns
110             up to the current one.
111 
112             Huh? Earlier you said that the nStartPixel of columns
113             scrolled out (to the left) of the visible area is
114             negative. Also, where is the promise that there is no gap
115             between columns? The above claim would be true only if the
116             first column always started at zero, and there is never a
117             gap. So these doc comments are inconsistent. How
118             surprising.
119         */
120         tools::Long    nEndPixel;
121 
ColumnMetricssvt::table::ColumnMetrics122         ColumnMetrics()
123             :nStartPixel(0)
124             ,nEndPixel(0)
125         {
126         }
127 
ColumnMetricssvt::table::ColumnMetrics128         ColumnMetrics( tools::Long const i_start, tools::Long const i_end )
129             :nStartPixel( i_start )
130             ,nEndPixel( i_end )
131         {
132         }
133     };
134 
135 
136     //= TableArea
137 
138     enum class TableArea
139     {
140         ColumnHeaders,
141         RowHeaders,
142         All
143     };
144 
145 
146     //= ITableControl
147 
148     /** defines a callback interface to be implemented by a concrete table control
149     */
150     class SAL_NO_VTABLE ITableControl
151     {
152     public:
153         /** hides the cell cursor
154 
155             The method cares for successive calls, that is, for every call to
156             ->hideCursor(), you need one call to ->showCursor. Only if the number
157             of both calls matches, the cursor is really shown.
158 
159             @see showCursor
160         */
161         virtual void    hideCursor() = 0;
162 
163         /** shows the cell cursor
164 
165             @see hideCursor
166         */
167         virtual void    showCursor() = 0;
168 
169         /** dispatches an action to the table control
170 
171             @return
172                 <TRUE/> if the action could be dispatched successfully, <FALSE/> otherwise. Usual
173                 failure conditions include some other instance vetoing the action, or impossibility
174                 to execute the action at all (for instance moving up one row when already positioned
175                 on the very first row).
176 
177             @see TableControlAction
178         */
179         virtual bool    dispatchAction( TableControlAction _eAction ) = 0;
180 
181         /** returns selection engine*/
182         virtual SelectionEngine* getSelEngine() = 0;
183 
184         /** returns the table model
185 
186             The returned model is guaranteed to not be <NULL/>.
187         */
188         virtual PTableModel getModel() const = 0;
189 
190         /// returns the index of the currently active column
191         virtual ColPos  getCurrentColumn() const = 0;
192 
193         /// returns the index of the currently active row
194         virtual RowPos  getCurrentRow() const = 0;
195 
196         /// activates the given cell
197         virtual void    activateCell( ColPos const i_col, RowPos const i_row ) = 0;
198 
199         /// retrieves the size of the table window, in pixels
200         virtual ::Size  getTableSizePixel() const = 0;
201 
202         /// sets a new mouse pointer for the table window
203         virtual void    setPointer( PointerStyle i_pointer ) = 0;
204 
205         /// captures the mouse to the table window
206         virtual void    captureMouse() = 0;
207 
208         /// releases the mouse, after it had previously been captured
209         virtual void    releaseMouse() = 0;
210 
211         /// invalidates the table window
212         virtual void    invalidate( TableArea const i_what ) = 0;
213 
214         /// calculates a width, given in pixels, into an AppFont-based width
215         virtual tools::Long    pixelWidthToAppFont( tools::Long const i_pixels ) const = 0;
216 
217         /// shows a tracking rectangle
218         virtual void    showTracking( tools::Rectangle const & i_location, ShowTrackFlags const i_flags ) = 0;
219 
220         /// hides a previously shown tracking rectangle
221         virtual void    hideTracking() = 0;
222 
223         /// does a hit test for the given pixel coordinates
224         virtual TableCell       hitTest( const Point& rPoint ) const = 0;
225 
226         /// retrieves the metrics for a given column
227         virtual ColumnMetrics   getColumnMetrics( ColPos const i_column ) const = 0;
228 
229         /// determines whether a given row is selected
230         virtual bool isRowSelected( RowPos _nRow ) const = 0;
231 
~ITableControl()232         virtual ~ITableControl() {};
233     };
234 
235 } // namespace svt::table
236 
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
238