]>
Commit | Line | Data |
---|---|---|
f85afd4e | 1 | ///////////////////////////////////////////////////////////////////////////// |
43947979 | 2 | // Name: wx/generic/grid.h |
f85afd4e MB |
3 | // Purpose: wxGrid and related classes |
4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn) | |
d4175745 | 5 | // Modified by: Santiago Palacios |
f85afd4e MB |
6 | // Created: 1/08/1999 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward | |
65571936 | 9 | // Licence: wxWindows licence |
f85afd4e MB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
df9fac6d PC |
12 | #ifndef _WX_GENERIC_GRID_H_ |
13 | #define _WX_GENERIC_GRID_H_ | |
14 | ||
15 | #include "wx/defs.h" | |
16 | ||
17 | #if wxUSE_GRID | |
f85afd4e | 18 | |
82edfbe7 VZ |
19 | #include "wx/hashmap.h" |
20 | ||
2d66e025 | 21 | #include "wx/scrolwin.h" |
f85afd4e | 22 | |
816be743 VZ |
23 | // ---------------------------------------------------------------------------- |
24 | // constants | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
23318a53 | 27 | extern WXDLLIMPEXP_DATA_ADV(const char) wxGridNameStr[]; |
61961a3c | 28 | |
f85afd4e MB |
29 | // Default parameters for wxGrid |
30 | // | |
31 | #define WXGRID_DEFAULT_NUMBER_ROWS 10 | |
32 | #define WXGRID_DEFAULT_NUMBER_COLS 10 | |
e6002250 | 33 | #if defined(__WXMSW__) || defined(__WXGTK20__) |
f85afd4e MB |
34 | #define WXGRID_DEFAULT_ROW_HEIGHT 25 |
35 | #else | |
36 | #define WXGRID_DEFAULT_ROW_HEIGHT 30 | |
37 | #endif // __WXMSW__ | |
38 | #define WXGRID_DEFAULT_COL_WIDTH 80 | |
39 | #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 | |
40 | #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 | |
f1567cdd | 41 | #define WXGRID_LABEL_EDGE_ZONE 2 |
f85afd4e MB |
42 | #define WXGRID_MIN_ROW_HEIGHT 15 |
43 | #define WXGRID_MIN_COL_WIDTH 15 | |
44 | #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 | |
f85afd4e | 45 | |
816be743 VZ |
46 | // type names for grid table values |
47 | #define wxGRID_VALUE_STRING _T("string") | |
48 | #define wxGRID_VALUE_BOOL _T("bool") | |
49 | #define wxGRID_VALUE_NUMBER _T("long") | |
50 | #define wxGRID_VALUE_FLOAT _T("double") | |
c4608a8a | 51 | #define wxGRID_VALUE_CHOICE _T("choice") |
816be743 VZ |
52 | |
53 | #define wxGRID_VALUE_TEXT wxGRID_VALUE_STRING | |
54 | #define wxGRID_VALUE_LONG wxGRID_VALUE_NUMBER | |
55 | ||
733f486a VZ |
56 | // magic constant which tells (to some functions) to automatically calculate |
57 | // the appropriate size | |
58 | #define wxGRID_AUTOSIZE (-1) | |
59 | ||
60 | // many wxGrid methods work either with columns or rows, this enum is used for | |
61 | // the parameter indicating which one should it be | |
62 | enum wxGridDirection | |
63 | { | |
64 | wxGRID_COLUMN, | |
05cc594a | 65 | wxGRID_ROW |
733f486a VZ |
66 | }; |
67 | ||
b99be8fb VZ |
68 | // ---------------------------------------------------------------------------- |
69 | // forward declarations | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
b5dbe15d VS |
72 | class WXDLLIMPEXP_FWD_ADV wxGrid; |
73 | class WXDLLIMPEXP_FWD_ADV wxGridCellAttr; | |
74 | class WXDLLIMPEXP_FWD_ADV wxGridCellAttrProviderData; | |
75 | class WXDLLIMPEXP_FWD_ADV wxGridColLabelWindow; | |
76 | class WXDLLIMPEXP_FWD_ADV wxGridCornerLabelWindow; | |
77 | class WXDLLIMPEXP_FWD_ADV wxGridRowLabelWindow; | |
78 | class WXDLLIMPEXP_FWD_ADV wxGridWindow; | |
79 | class WXDLLIMPEXP_FWD_ADV wxGridTypeRegistry; | |
80 | class WXDLLIMPEXP_FWD_ADV wxGridSelection; | |
81 | ||
ad805b9e | 82 | class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl; |
b5dbe15d VS |
83 | class WXDLLIMPEXP_FWD_CORE wxCheckBox; |
84 | class WXDLLIMPEXP_FWD_CORE wxComboBox; | |
85 | class WXDLLIMPEXP_FWD_CORE wxTextCtrl; | |
0e871ad0 | 86 | #if wxUSE_SPINCTRL |
b5dbe15d | 87 | class WXDLLIMPEXP_FWD_CORE wxSpinCtrl; |
0e871ad0 | 88 | #endif |
508011ce | 89 | |
82edfbe7 VZ |
90 | class wxGridFixedIndicesSet; |
91 | ||
bec70262 VZ |
92 | class wxGridOperations; |
93 | class wxGridRowOperations; | |
94 | class wxGridColumnOperations; | |
10a4531d | 95 | class wxGridDirectionOperations; |
bec70262 | 96 | |
29efc6e4 | 97 | |
39bcce60 VZ |
98 | // ---------------------------------------------------------------------------- |
99 | // macros | |
100 | // ---------------------------------------------------------------------------- | |
101 | ||
102 | #define wxSafeIncRef(p) if ( p ) (p)->IncRef() | |
103 | #define wxSafeDecRef(p) if ( p ) (p)->DecRef() | |
104 | ||
ab79958a | 105 | // ---------------------------------------------------------------------------- |
c4608a8a VZ |
106 | // wxGridCellWorker: common base class for wxGridCellRenderer and |
107 | // wxGridCellEditor | |
108 | // | |
109 | // NB: this is more an implementation convenience than a design issue, so this | |
110 | // class is not documented and is not public at all | |
ab79958a VZ |
111 | // ---------------------------------------------------------------------------- |
112 | ||
b42d5f75 | 113 | class WXDLLIMPEXP_ADV wxGridCellWorker : public wxClientDataContainer, public wxRefCounter |
ab79958a VZ |
114 | { |
115 | public: | |
92ffc98a | 116 | wxGridCellWorker() { } |
39bcce60 | 117 | |
c4608a8a VZ |
118 | // interpret renderer parameters: arbitrary string whose interpretatin is |
119 | // left to the derived classes | |
120 | virtual void SetParameters(const wxString& params); | |
121 | ||
122 | protected: | |
123 | // virtual dtor for any base class - private because only DecRef() can | |
124 | // delete us | |
125 | virtual ~wxGridCellWorker(); | |
126 | ||
127 | private: | |
c4608a8a VZ |
128 | // suppress the stupid gcc warning about the class having private dtor and |
129 | // no friends | |
130 | friend class wxGridCellWorkerDummyFriend; | |
131 | }; | |
132 | ||
133 | // ---------------------------------------------------------------------------- | |
134 | // wxGridCellRenderer: this class is responsible for actually drawing the cell | |
135 | // in the grid. You may pass it to the wxGridCellAttr (below) to change the | |
136 | // format of one given cell or to wxGrid::SetDefaultRenderer() to change the | |
137 | // view of all cells. This is an ABC, you will normally use one of the | |
138 | // predefined derived classes or derive your own class from it. | |
139 | // ---------------------------------------------------------------------------- | |
140 | ||
12f190b0 | 141 | class WXDLLIMPEXP_ADV wxGridCellRenderer : public wxGridCellWorker |
c4608a8a VZ |
142 | { |
143 | public: | |
ab79958a VZ |
144 | // draw the given cell on the provided DC inside the given rectangle |
145 | // using the style specified by the attribute and the default or selected | |
146 | // state corresponding to the isSelected value. | |
147 | // | |
148 | // this pure virtual function has a default implementation which will | |
149 | // prepare the DC using the given attribute: it will draw the rectangle | |
150 | // with the bg colour from attr and set the text colour and font | |
151 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 152 | wxGridCellAttr& attr, |
ab79958a VZ |
153 | wxDC& dc, |
154 | const wxRect& rect, | |
155 | int row, int col, | |
156 | bool isSelected) = 0; | |
816be743 | 157 | |
65e4e78e VZ |
158 | // get the preferred size of the cell for its contents |
159 | virtual wxSize GetBestSize(wxGrid& grid, | |
160 | wxGridCellAttr& attr, | |
161 | wxDC& dc, | |
162 | int row, int col) = 0; | |
163 | ||
e72b4213 VZ |
164 | // create a new object which is the copy of this one |
165 | virtual wxGridCellRenderer *Clone() const = 0; | |
ab79958a VZ |
166 | }; |
167 | ||
2796cce3 RD |
168 | // ---------------------------------------------------------------------------- |
169 | // wxGridCellEditor: This class is responsible for providing and manipulating | |
170 | // the in-place edit controls for the grid. Instances of wxGridCellEditor | |
171 | // (actually, instances of derived classes since it is an ABC) can be | |
172 | // associated with the cell attributes for individual cells, rows, columns, or | |
173 | // even for the entire grid. | |
174 | // ---------------------------------------------------------------------------- | |
175 | ||
12f190b0 | 176 | class WXDLLIMPEXP_ADV wxGridCellEditor : public wxGridCellWorker |
2796cce3 RD |
177 | { |
178 | public: | |
179 | wxGridCellEditor(); | |
39bcce60 | 180 | |
2796cce3 | 181 | bool IsCreated() { return m_control != NULL; } |
f6bcfd97 BP |
182 | wxControl* GetControl() { return m_control; } |
183 | void SetControl(wxControl* control) { m_control = control; } | |
2796cce3 | 184 | |
1bd71df9 JS |
185 | wxGridCellAttr* GetCellAttr() { return m_attr; } |
186 | void SetCellAttr(wxGridCellAttr* attr) { m_attr = attr; } | |
187 | ||
2796cce3 RD |
188 | // Creates the actual edit control |
189 | virtual void Create(wxWindow* parent, | |
190 | wxWindowID id, | |
2796cce3 RD |
191 | wxEvtHandler* evtHandler) = 0; |
192 | ||
193 | // Size and position the edit control | |
194 | virtual void SetSize(const wxRect& rect); | |
195 | ||
3da93aae VZ |
196 | // Show or hide the edit control, use the specified attributes to set |
197 | // colours/fonts for it | |
8a3e536c | 198 | virtual void Show(bool show, wxGridCellAttr *attr = NULL); |
2796cce3 | 199 | |
189d0213 VZ |
200 | // Draws the part of the cell not occupied by the control: the base class |
201 | // version just fills it with background colour from the attribute | |
202 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); | |
203 | ||
763163a8 VZ |
204 | |
205 | // The methods called by wxGrid when a cell is edited: first BeginEdit() is | |
206 | // called, then EndEdit() is and if it returns true and if the change is | |
207 | // not vetoed by a user-defined event handler, finally ApplyEdit() is called | |
208 | ||
2796cce3 RD |
209 | // Fetch the value from the table and prepare the edit control |
210 | // to begin editing. Set the focus to the edit control. | |
3da93aae | 211 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; |
2796cce3 | 212 | |
763163a8 VZ |
213 | // Returns false if nothing changed, otherwise returns true and return the |
214 | // new value in its string form in the newval output parameter. | |
215 | // | |
216 | // This should also store the new value in its real type internally so that | |
78e78812 VZ |
217 | // it could be used by ApplyEdit() but it must not modify the grid as the |
218 | // change could still be vetoed. | |
219 | virtual bool EndEdit(int row, int col, const wxGrid *grid, | |
220 | const wxString& oldval, wxString *newval) = 0; | |
763163a8 VZ |
221 | |
222 | // Complete the editing of the current cell by storing the value saved by | |
223 | // the previous call to EndEdit() in the grid | |
224 | virtual void ApplyEdit(int row, int col, wxGrid* grid) = 0; | |
225 | ||
2796cce3 RD |
226 | |
227 | // Reset the value in the control back to its starting value | |
228 | virtual void Reset() = 0; | |
229 | ||
ca65c044 | 230 | // return true to allow the given key to start editing: the base class |
f6bcfd97 BP |
231 | // version only checks that the event has no modifiers. The derived |
232 | // classes are supposed to do "if ( base::IsAcceptedKey() && ... )" in | |
233 | // their IsAcceptedKey() implementation, although, of course, it is not a | |
234 | // mandatory requirment. | |
235 | // | |
236 | // NB: if the key is F2 (special), editing will always start and this | |
237 | // method will not be called at all (but StartingKey() will) | |
238 | virtual bool IsAcceptedKey(wxKeyEvent& event); | |
239 | ||
240 | // If the editor is enabled by pressing keys on the grid, this will be | |
241 | // called to let the editor do something about that first key if desired | |
2c9a89e0 RD |
242 | virtual void StartingKey(wxKeyEvent& event); |
243 | ||
e195a54c VZ |
244 | // if the editor is enabled by clicking on the cell, this method will be |
245 | // called | |
246 | virtual void StartingClick(); | |
247 | ||
2796cce3 RD |
248 | // Some types of controls on some platforms may need some help |
249 | // with the Return key. | |
250 | virtual void HandleReturn(wxKeyEvent& event); | |
251 | ||
252 | // Final cleanup | |
253 | virtual void Destroy(); | |
254 | ||
c4608a8a VZ |
255 | // create a new object which is the copy of this one |
256 | virtual wxGridCellEditor *Clone() const = 0; | |
257 | ||
73145b0e JS |
258 | // added GetValue so we can get the value which is in the control |
259 | virtual wxString GetValue() const = 0; | |
260 | ||
2796cce3 | 261 | protected: |
39bcce60 VZ |
262 | // the dtor is private because only DecRef() can delete us |
263 | virtual ~wxGridCellEditor(); | |
264 | ||
3da93aae | 265 | // the control we show on screen |
2796cce3 | 266 | wxControl* m_control; |
3da93aae | 267 | |
1bd71df9 JS |
268 | // a temporary pointer to the attribute being edited |
269 | wxGridCellAttr* m_attr; | |
270 | ||
3da93aae VZ |
271 | // if we change the colours/font of the control from the default ones, we |
272 | // must restore the default later and we save them here between calls to | |
ca65c044 | 273 | // Show(true) and Show(false) |
3da93aae VZ |
274 | wxColour m_colFgOld, |
275 | m_colBgOld; | |
276 | wxFont m_fontOld; | |
39bcce60 VZ |
277 | |
278 | // suppress the stupid gcc warning about the class having private dtor and | |
279 | // no friends | |
280 | friend class wxGridCellEditorDummyFriend; | |
22f3361e | 281 | |
c0c133e1 | 282 | wxDECLARE_NO_COPY_CLASS(wxGridCellEditor); |
2796cce3 RD |
283 | }; |
284 | ||
3379ed37 | 285 | |
b99be8fb VZ |
286 | // ---------------------------------------------------------------------------- |
287 | // wxGridCellAttr: this class can be used to alter the cells appearance in | |
288 | // the grid by changing their colour/font/... from default. An object of this | |
289 | // class may be returned by wxGridTable::GetAttr(). | |
290 | // ---------------------------------------------------------------------------- | |
291 | ||
b42d5f75 | 292 | class WXDLLIMPEXP_ADV wxGridCellAttr : public wxClientDataContainer, public wxRefCounter |
b99be8fb VZ |
293 | { |
294 | public: | |
19d7140e VZ |
295 | enum wxAttrKind |
296 | { | |
297 | Any, | |
298 | Default, | |
299 | Cell, | |
300 | Row, | |
301 | Col, | |
302 | Merged | |
303 | }; | |
304 | ||
b99be8fb | 305 | // ctors |
1df4050d | 306 | wxGridCellAttr(wxGridCellAttr *attrDefault = NULL) |
b99be8fb | 307 | { |
1df4050d VZ |
308 | Init(attrDefault); |
309 | ||
0767cb6f MB |
310 | // MB: args used to be 0,0 here but wxALIGN_LEFT is 0 |
311 | SetAlignment(-1, -1); | |
b99be8fb VZ |
312 | } |
313 | ||
283b7808 VZ |
314 | // VZ: considering the number of members wxGridCellAttr has now, this ctor |
315 | // seems to be pretty useless... may be we should just remove it? | |
b99be8fb VZ |
316 | wxGridCellAttr(const wxColour& colText, |
317 | const wxColour& colBack, | |
318 | const wxFont& font, | |
319 | int hAlign, | |
320 | int vAlign) | |
321 | : m_colText(colText), m_colBack(colBack), m_font(font) | |
322 | { | |
2e9a6788 | 323 | Init(); |
b99be8fb VZ |
324 | SetAlignment(hAlign, vAlign); |
325 | } | |
326 | ||
39bcce60 VZ |
327 | // creates a new copy of this object |
328 | wxGridCellAttr *Clone() const; | |
19d7140e | 329 | void MergeWith(wxGridCellAttr *mergefrom); |
b99be8fb VZ |
330 | |
331 | // setters | |
332 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
333 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
334 | void SetFont(const wxFont& font) { m_font = font; } | |
335 | void SetAlignment(int hAlign, int vAlign) | |
336 | { | |
337 | m_hAlign = hAlign; | |
338 | m_vAlign = vAlign; | |
339 | } | |
27f35b66 | 340 | void SetSize(int num_rows, int num_cols); |
ca65c044 | 341 | void SetOverflow(bool allow = true) |
ef5df12b | 342 | { m_overflow = allow ? Overflow : SingleCell; } |
ca65c044 | 343 | void SetReadOnly(bool isReadOnly = true) |
19d7140e | 344 | { m_isReadOnly = isReadOnly ? ReadOnly : ReadWrite; } |
b99be8fb | 345 | |
ab79958a VZ |
346 | // takes ownership of the pointer |
347 | void SetRenderer(wxGridCellRenderer *renderer) | |
39bcce60 | 348 | { wxSafeDecRef(m_renderer); m_renderer = renderer; } |
07296f0b | 349 | void SetEditor(wxGridCellEditor* editor) |
39bcce60 | 350 | { wxSafeDecRef(m_editor); m_editor = editor; } |
ab79958a | 351 | |
19d7140e VZ |
352 | void SetKind(wxAttrKind kind) { m_attrkind = kind; } |
353 | ||
b99be8fb VZ |
354 | // accessors |
355 | bool HasTextColour() const { return m_colText.Ok(); } | |
356 | bool HasBackgroundColour() const { return m_colBack.Ok(); } | |
357 | bool HasFont() const { return m_font.Ok(); } | |
0767cb6f | 358 | bool HasAlignment() const { return (m_hAlign != -1 || m_vAlign != -1); } |
2796cce3 | 359 | bool HasRenderer() const { return m_renderer != NULL; } |
07296f0b | 360 | bool HasEditor() const { return m_editor != NULL; } |
19d7140e | 361 | bool HasReadWriteMode() const { return m_isReadOnly != Unset; } |
b63fce94 | 362 | bool HasOverflowMode() const { return m_overflow != UnsetOverflow; } |
3100c3db | 363 | bool HasSize() const { return m_sizeRows != 1 || m_sizeCols != 1; } |
b99be8fb | 364 | |
2796cce3 RD |
365 | const wxColour& GetTextColour() const; |
366 | const wxColour& GetBackgroundColour() const; | |
367 | const wxFont& GetFont() const; | |
368 | void GetAlignment(int *hAlign, int *vAlign) const; | |
27f35b66 | 369 | void GetSize(int *num_rows, int *num_cols) const; |
ef5df12b | 370 | bool GetOverflow() const |
b63fce94 | 371 | { return m_overflow != SingleCell; } |
ef316e23 VZ |
372 | wxGridCellRenderer *GetRenderer(const wxGrid* grid, int row, int col) const; |
373 | wxGridCellEditor *GetEditor(const wxGrid* grid, int row, int col) const; | |
b99be8fb | 374 | |
19d7140e VZ |
375 | bool IsReadOnly() const { return m_isReadOnly == wxGridCellAttr::ReadOnly; } |
376 | ||
377 | wxAttrKind GetKind() { return m_attrkind; } | |
283b7808 | 378 | |
2796cce3 | 379 | void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } |
ab79958a | 380 | |
338d1deb VZ |
381 | protected: |
382 | // the dtor is private because only DecRef() can delete us | |
383 | virtual ~wxGridCellAttr() | |
384 | { | |
385 | wxSafeDecRef(m_renderer); | |
386 | wxSafeDecRef(m_editor); | |
387 | } | |
388 | ||
b99be8fb | 389 | private: |
19d7140e VZ |
390 | enum wxAttrReadMode |
391 | { | |
392 | Unset = -1, | |
393 | ReadWrite, | |
394 | ReadOnly | |
30bc4a8f | 395 | }; |
19d7140e | 396 | |
b63fce94 RD |
397 | enum wxAttrOverflowMode |
398 | { | |
399 | UnsetOverflow = -1, | |
400 | Overflow, | |
401 | SingleCell | |
402 | }; | |
403 | ||
2e9a6788 | 404 | // the common part of all ctors |
1df4050d | 405 | void Init(wxGridCellAttr *attrDefault = NULL); |
2e9a6788 | 406 | |
2e9a6788 | 407 | |
b99be8fb VZ |
408 | wxColour m_colText, |
409 | m_colBack; | |
410 | wxFont m_font; | |
411 | int m_hAlign, | |
412 | m_vAlign; | |
27f35b66 SN |
413 | int m_sizeRows, |
414 | m_sizeCols; | |
ef5df12b RD |
415 | |
416 | wxAttrOverflowMode m_overflow; | |
2e9a6788 | 417 | |
07296f0b RD |
418 | wxGridCellRenderer* m_renderer; |
419 | wxGridCellEditor* m_editor; | |
420 | wxGridCellAttr* m_defGridAttr; | |
ab79958a | 421 | |
19d7140e VZ |
422 | wxAttrReadMode m_isReadOnly; |
423 | ||
424 | wxAttrKind m_attrkind; | |
283b7808 | 425 | |
a68c1246 | 426 | // use Clone() instead |
c0c133e1 | 427 | wxDECLARE_NO_COPY_CLASS(wxGridCellAttr); |
a68c1246 | 428 | |
2e9a6788 VZ |
429 | // suppress the stupid gcc warning about the class having private dtor and |
430 | // no friends | |
431 | friend class wxGridCellAttrDummyFriend; | |
b99be8fb VZ |
432 | }; |
433 | ||
434 | // ---------------------------------------------------------------------------- | |
435 | // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the | |
436 | // cell attributes. | |
437 | // ---------------------------------------------------------------------------- | |
438 | ||
439 | // implementation note: we separate it from wxGridTableBase because we wish to | |
440 | // avoid deriving a new table class if possible, and sometimes it will be | |
441 | // enough to just derive another wxGridCellAttrProvider instead | |
758cbedf VZ |
442 | // |
443 | // the default implementation is reasonably efficient for the generic case, | |
444 | // but you might still wish to implement your own for some specific situations | |
445 | // if you have performance problems with the stock one | |
12f190b0 | 446 | class WXDLLIMPEXP_ADV wxGridCellAttrProvider : public wxClientDataContainer |
b99be8fb VZ |
447 | { |
448 | public: | |
449 | wxGridCellAttrProvider(); | |
450 | virtual ~wxGridCellAttrProvider(); | |
451 | ||
2e9a6788 | 452 | // DecRef() must be called on the returned pointer |
19d7140e VZ |
453 | virtual wxGridCellAttr *GetAttr(int row, int col, |
454 | wxGridCellAttr::wxAttrKind kind ) const; | |
2e9a6788 | 455 | |
758cbedf VZ |
456 | // all these functions take ownership of the pointer, don't call DecRef() |
457 | // on it | |
2e9a6788 | 458 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); |
758cbedf VZ |
459 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); |
460 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
d1c0b4f9 VZ |
461 | |
462 | // these functions must be called whenever some rows/cols are deleted | |
463 | // because the internal data must be updated then | |
4d60017a SN |
464 | void UpdateAttrRows( size_t pos, int numRows ); |
465 | void UpdateAttrCols( size_t pos, int numCols ); | |
b99be8fb VZ |
466 | |
467 | private: | |
468 | void InitData(); | |
469 | ||
470 | wxGridCellAttrProviderData *m_data; | |
22f3361e | 471 | |
c0c133e1 | 472 | wxDECLARE_NO_COPY_CLASS(wxGridCellAttrProvider); |
b99be8fb | 473 | }; |
f85afd4e | 474 | |
10a4531d VZ |
475 | // ---------------------------------------------------------------------------- |
476 | // wxGridCellCoords: location of a cell in the grid | |
477 | // ---------------------------------------------------------------------------- | |
478 | ||
479 | class WXDLLIMPEXP_ADV wxGridCellCoords | |
480 | { | |
481 | public: | |
482 | wxGridCellCoords() { m_row = m_col = -1; } | |
483 | wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } | |
484 | ||
485 | // default copy ctor is ok | |
486 | ||
487 | int GetRow() const { return m_row; } | |
488 | void SetRow( int n ) { m_row = n; } | |
489 | int GetCol() const { return m_col; } | |
490 | void SetCol( int n ) { m_col = n; } | |
491 | void Set( int row, int col ) { m_row = row; m_col = col; } | |
492 | ||
493 | wxGridCellCoords& operator=( const wxGridCellCoords& other ) | |
494 | { | |
495 | if ( &other != this ) | |
496 | { | |
497 | m_row=other.m_row; | |
498 | m_col=other.m_col; | |
499 | } | |
500 | return *this; | |
501 | } | |
502 | ||
503 | bool operator==( const wxGridCellCoords& other ) const | |
504 | { | |
505 | return (m_row == other.m_row && m_col == other.m_col); | |
506 | } | |
507 | ||
508 | bool operator!=( const wxGridCellCoords& other ) const | |
509 | { | |
510 | return (m_row != other.m_row || m_col != other.m_col); | |
511 | } | |
512 | ||
513 | bool operator!() const | |
514 | { | |
515 | return (m_row == -1 && m_col == -1 ); | |
516 | } | |
517 | ||
518 | private: | |
519 | int m_row; | |
520 | int m_col; | |
521 | }; | |
522 | ||
523 | ||
524 | // For comparisons... | |
f85afd4e | 525 | // |
10a4531d VZ |
526 | extern WXDLLIMPEXP_ADV wxGridCellCoords wxGridNoCellCoords; |
527 | extern WXDLLIMPEXP_ADV wxRect wxGridNoCellRect; | |
528 | ||
529 | // An array of cell coords... | |
f85afd4e | 530 | // |
10a4531d VZ |
531 | WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellCoords, wxGridCellCoordsArray, |
532 | class WXDLLIMPEXP_ADV); | |
f85afd4e | 533 | |
10a4531d VZ |
534 | // ---------------------------------------------------------------------------- |
535 | // Grid table classes | |
536 | // ---------------------------------------------------------------------------- | |
f85afd4e | 537 | |
10a4531d VZ |
538 | // the abstract base class |
539 | class WXDLLIMPEXP_ADV wxGridTableBase : public wxObject, | |
540 | public wxClientDataContainer | |
f85afd4e | 541 | { |
60ff3b99 | 542 | public: |
f85afd4e MB |
543 | wxGridTableBase(); |
544 | virtual ~wxGridTableBase(); | |
545 | ||
546 | // You must override these functions in a derived table class | |
547 | // | |
77d2c45c VZ |
548 | |
549 | // return the number of rows and columns in this table | |
e32352cf SN |
550 | virtual int GetNumberRows() = 0; |
551 | virtual int GetNumberCols() = 0; | |
77d2c45c VZ |
552 | |
553 | // the methods above are unfortunately non-const even though they should | |
554 | // have been const -- but changing it now is not possible any longer as it | |
555 | // would break the existing code overriding them, so instead we provide | |
556 | // these const synonyms which can be used from const-correct code | |
557 | int GetRowsCount() const | |
5c33522f | 558 | { return const_cast<wxGridTableBase *>(this)->GetNumberRows(); } |
77d2c45c | 559 | int GetColsCount() const |
5c33522f | 560 | { return const_cast<wxGridTableBase *>(this)->GetNumberCols(); } |
77d2c45c VZ |
561 | |
562 | ||
8acad210 VZ |
563 | virtual bool IsEmptyCell( int row, int col ) |
564 | { | |
565 | return GetValue(row, col).empty(); | |
566 | } | |
10a4531d VZ |
567 | |
568 | bool IsEmpty(const wxGridCellCoords& coord) | |
569 | { | |
570 | return IsEmptyCell(coord.GetRow(), coord.GetCol()); | |
571 | } | |
572 | ||
f2d76237 RD |
573 | virtual wxString GetValue( int row, int col ) = 0; |
574 | virtual void SetValue( int row, int col, const wxString& value ) = 0; | |
575 | ||
576 | // Data type determination and value access | |
577 | virtual wxString GetTypeName( int row, int col ); | |
578 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
579 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
580 | ||
581 | virtual long GetValueAsLong( int row, int col ); | |
582 | virtual double GetValueAsDouble( int row, int col ); | |
583 | virtual bool GetValueAsBool( int row, int col ); | |
584 | ||
585 | virtual void SetValueAsLong( int row, int col, long value ); | |
586 | virtual void SetValueAsDouble( int row, int col, double value ); | |
587 | virtual void SetValueAsBool( int row, int col, bool value ); | |
588 | ||
589 | // For user defined types | |
590 | virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); | |
591 | virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); | |
592 | ||
60ff3b99 | 593 | |
f85afd4e MB |
594 | // Overriding these is optional |
595 | // | |
596 | virtual void SetView( wxGrid *grid ) { m_view = grid; } | |
597 | virtual wxGrid * GetView() const { return m_view; } | |
598 | ||
599 | virtual void Clear() {} | |
600 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
601 | virtual bool AppendRows( size_t numRows = 1 ); | |
602 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
603 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
604 | virtual bool AppendCols( size_t numCols = 1 ); | |
605 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
606 | ||
607 | virtual wxString GetRowLabelValue( int row ); | |
608 | virtual wxString GetColLabelValue( int col ); | |
af111fc3 JS |
609 | virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} |
610 | virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} | |
60ff3b99 | 611 | |
b99be8fb VZ |
612 | // Attribute handling |
613 | // | |
614 | ||
615 | // give us the attr provider to use - we take ownership of the pointer | |
616 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
617 | ||
618 | // get the currently used attr provider (may be NULL) | |
619 | wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } | |
620 | ||
f2d76237 RD |
621 | // Does this table allow attributes? Default implementation creates |
622 | // a wxGridCellAttrProvider if necessary. | |
623 | virtual bool CanHaveAttributes(); | |
624 | ||
b99be8fb | 625 | // by default forwarded to wxGridCellAttrProvider if any. May be |
f2d76237 | 626 | // overridden to handle attributes directly in the table. |
19d7140e VZ |
627 | virtual wxGridCellAttr *GetAttr( int row, int col, |
628 | wxGridCellAttr::wxAttrKind kind ); | |
629 | ||
b99be8fb | 630 | |
758cbedf VZ |
631 | // these functions take ownership of the pointer |
632 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); | |
633 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
634 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
b99be8fb | 635 | |
60ff3b99 VZ |
636 | private: |
637 | wxGrid * m_view; | |
b99be8fb | 638 | wxGridCellAttrProvider *m_attrProvider; |
60ff3b99 | 639 | |
3839f37e | 640 | DECLARE_ABSTRACT_CLASS(wxGridTableBase) |
c0c133e1 | 641 | wxDECLARE_NO_COPY_CLASS(wxGridTableBase); |
f85afd4e MB |
642 | }; |
643 | ||
644 | ||
b99be8fb VZ |
645 | // ---------------------------------------------------------------------------- |
646 | // wxGridTableMessage | |
647 | // ---------------------------------------------------------------------------- | |
f85afd4e MB |
648 | |
649 | // IDs for messages sent from grid table to view | |
650 | // | |
60ff3b99 VZ |
651 | enum wxGridTableRequest |
652 | { | |
f85afd4e MB |
653 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, |
654 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, | |
655 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
656 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
657 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
658 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
659 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
660 | wxGRIDTABLE_NOTIFY_COLS_DELETED | |
661 | }; | |
662 | ||
12f190b0 | 663 | class WXDLLIMPEXP_ADV wxGridTableMessage |
f85afd4e | 664 | { |
60ff3b99 | 665 | public: |
f85afd4e MB |
666 | wxGridTableMessage(); |
667 | wxGridTableMessage( wxGridTableBase *table, int id, | |
668 | int comInt1 = -1, | |
669 | int comInt2 = -1 ); | |
670 | ||
671 | void SetTableObject( wxGridTableBase *table ) { m_table = table; } | |
672 | wxGridTableBase * GetTableObject() const { return m_table; } | |
673 | void SetId( int id ) { m_id = id; } | |
674 | int GetId() { return m_id; } | |
675 | void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } | |
676 | int GetCommandInt() { return m_comInt1; } | |
677 | void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } | |
60ff3b99 VZ |
678 | int GetCommandInt2() { return m_comInt2; } |
679 | ||
680 | private: | |
681 | wxGridTableBase *m_table; | |
682 | int m_id; | |
683 | int m_comInt1; | |
684 | int m_comInt2; | |
22f3361e | 685 | |
c0c133e1 | 686 | wxDECLARE_NO_COPY_CLASS(wxGridTableMessage); |
f85afd4e MB |
687 | }; |
688 | ||
689 | ||
690 | ||
691 | // ------ wxGridStringArray | |
692 | // A 2-dimensional array of strings for data values | |
693 | // | |
694 | ||
160ba750 VS |
695 | WX_DECLARE_OBJARRAY_WITH_DECL(wxArrayString, wxGridStringArray, |
696 | class WXDLLIMPEXP_ADV); | |
2d66e025 | 697 | |
f85afd4e MB |
698 | |
699 | ||
700 | // ------ wxGridStringTable | |
701 | // | |
702 | // Simplest type of data table for a grid for small tables of strings | |
703 | // that are stored in memory | |
704 | // | |
705 | ||
12f190b0 | 706 | class WXDLLIMPEXP_ADV wxGridStringTable : public wxGridTableBase |
f85afd4e | 707 | { |
60ff3b99 | 708 | public: |
f85afd4e MB |
709 | wxGridStringTable(); |
710 | wxGridStringTable( int numRows, int numCols ); | |
f85afd4e MB |
711 | |
712 | // these are pure virtual in wxGridTableBase | |
713 | // | |
5c3313a9 VZ |
714 | virtual int GetNumberRows() { return m_data.size(); } |
715 | virtual int GetNumberCols() { return m_numCols; } | |
716 | virtual wxString GetValue( int row, int col ); | |
717 | virtual void SetValue( int row, int col, const wxString& s ); | |
60ff3b99 | 718 | |
f85afd4e MB |
719 | // overridden functions from wxGridTableBase |
720 | // | |
721 | void Clear(); | |
722 | bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
723 | bool AppendRows( size_t numRows = 1 ); | |
724 | bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
725 | bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
726 | bool AppendCols( size_t numCols = 1 ); | |
727 | bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
728 | ||
729 | void SetRowLabelValue( int row, const wxString& ); | |
730 | void SetColLabelValue( int col, const wxString& ); | |
731 | wxString GetRowLabelValue( int row ); | |
732 | wxString GetColLabelValue( int col ); | |
60ff3b99 VZ |
733 | |
734 | private: | |
735 | wxGridStringArray m_data; | |
736 | ||
5c3313a9 VZ |
737 | // notice that while we don't need to store the number of our rows as it's |
738 | // always equal to the size of m_data array, we do need to store the number | |
739 | // of our columns as we can't retrieve it from m_data when the number of | |
740 | // rows is 0 (see #10818) | |
741 | int m_numCols; | |
742 | ||
60ff3b99 VZ |
743 | // These only get used if you set your own labels, otherwise the |
744 | // GetRow/ColLabelValue functions return wxGridTableBase defaults | |
745 | // | |
746 | wxArrayString m_rowLabels; | |
747 | wxArrayString m_colLabels; | |
748 | ||
fc7a2a60 | 749 | DECLARE_DYNAMIC_CLASS_NO_COPY( wxGridStringTable ) |
f85afd4e MB |
750 | }; |
751 | ||
752 | ||
753 | ||
43947979 | 754 | // ============================================================================ |
f85afd4e | 755 | // Grid view classes |
43947979 VZ |
756 | // ============================================================================ |
757 | ||
574e1c5a VZ |
758 | // ---------------------------------------------------------------------------- |
759 | // wxGridSizesInfo stores information about sizes of the rows or columns. | |
760 | // | |
761 | // It assumes that most of the columns or rows have default size and so stores | |
762 | // the default size separately and uses a hash to map column or row numbers to | |
763 | // their non default size for those which don't have the default size. | |
764 | // ---------------------------------------------------------------------------- | |
765 | ||
82edfbe7 | 766 | // hash map to store positions as the keys and sizes as the values |
574e1c5a VZ |
767 | WX_DECLARE_HASH_MAP_WITH_DECL( unsigned, int, wxIntegerHash, wxIntegerEqual, |
768 | wxUnsignedToIntHashMap, class WXDLLIMPEXP_ADV ); | |
769 | ||
770 | struct WXDLLIMPEXP_ADV wxGridSizesInfo | |
771 | { | |
772 | // default ctor, initialize m_sizeDefault and m_customSizes later | |
773 | wxGridSizesInfo() { } | |
774 | ||
775 | // ctor used by wxGrid::Get{Col,Row}Sizes() | |
776 | wxGridSizesInfo(int defSize, const wxArrayInt& allSizes); | |
777 | ||
778 | // default copy ctor, assignment operator and dtor are ok | |
779 | ||
780 | // Get the size of the element with the given index | |
781 | int GetSize(unsigned pos) const; | |
782 | ||
783 | ||
784 | // default size | |
785 | int m_sizeDefault; | |
786 | ||
787 | // position -> size map containing all elements with non-default size | |
788 | wxUnsignedToIntHashMap m_customSizes; | |
789 | }; | |
790 | ||
b99be8fb VZ |
791 | // ---------------------------------------------------------------------------- |
792 | // wxGrid | |
793 | // ---------------------------------------------------------------------------- | |
f85afd4e | 794 | |
12f190b0 | 795 | class WXDLLIMPEXP_ADV wxGrid : public wxScrolledWindow |
60ff3b99 VZ |
796 | { |
797 | public: | |
bf2c8b31 VZ |
798 | // possible selection modes |
799 | enum wxGridSelectionModes | |
800 | { | |
801 | wxGridSelectCells = 0, // allow selecting anything | |
802 | wxGridSelectRows = 1, // allow selecting only entire rows | |
803 | wxGridSelectColumns = 2, // allow selecting only entire columns | |
804 | wxGridSelectRowsOrColumns = wxGridSelectRows | wxGridSelectColumns | |
805 | }; | |
806 | ||
807 | // creation and destruction | |
808 | // ------------------------ | |
809 | ||
810 | // ctor and Create() create the grid window, as with the other controls | |
ad805b9e | 811 | wxGrid() { Init(); } |
986a98c6 | 812 | |
bf2c8b31 | 813 | wxGrid(wxWindow *parent, |
986a98c6 SC |
814 | wxWindowID id, |
815 | const wxPoint& pos = wxDefaultPosition, | |
816 | const wxSize& size = wxDefaultSize, | |
817 | long style = wxWANTS_CHARS, | |
ad805b9e VZ |
818 | const wxString& name = wxGridNameStr) |
819 | { | |
820 | Init(); | |
821 | ||
822 | Create(parent, id, pos, size, style, name); | |
823 | } | |
60ff3b99 | 824 | |
bf2c8b31 VZ |
825 | bool Create(wxWindow *parent, |
826 | wxWindowID id, | |
827 | const wxPoint& pos = wxDefaultPosition, | |
828 | const wxSize& size = wxDefaultSize, | |
829 | long style = wxWANTS_CHARS, | |
830 | const wxString& name = wxGridNameStr); | |
2d66e025 | 831 | |
e669d97a | 832 | virtual ~wxGrid(); |
f85afd4e | 833 | |
bf2c8b31 VZ |
834 | // however to initialize grid data either CreateGrid() or SetTable() must |
835 | // be also called | |
b5808881 | 836 | |
bf2c8b31 VZ |
837 | // this is basically equivalent to |
838 | // | |
839 | // SetTable(new wxGridStringTable(numRows, numCols), true, selmode) | |
840 | // | |
b5808881 | 841 | bool CreateGrid( int numRows, int numCols, |
801a9641 | 842 | wxGridSelectionModes selmode = wxGridSelectCells ); |
2d66e025 | 843 | |
bf2c8b31 VZ |
844 | bool SetTable( wxGridTableBase *table, |
845 | bool takeOwnership = false, | |
846 | wxGridSelectionModes selmode = wxGridSelectCells ); | |
847 | ||
8a3e536c VZ |
848 | bool ProcessTableMessage(wxGridTableMessage&); |
849 | ||
850 | wxGridTableBase *GetTable() const { return m_table; } | |
851 | ||
bf2c8b31 | 852 | |
801a9641 VZ |
853 | void SetSelectionMode(wxGridSelectionModes selmode); |
854 | wxGridSelectionModes GetSelectionMode() const; | |
60ff3b99 | 855 | |
2d66e025 MB |
856 | // ------ grid dimensions |
857 | // | |
ef316e23 VZ |
858 | int GetNumberRows() const { return m_numRows; } |
859 | int GetNumberCols() const { return m_numCols; } | |
2d66e025 | 860 | |
60ff3b99 | 861 | |
2d66e025 MB |
862 | // ------ display update functions |
863 | // | |
ef316e23 | 864 | wxArrayInt CalcRowLabelsExposed( const wxRegion& reg ) const; |
8fb66724 | 865 | |
ef316e23 VZ |
866 | wxArrayInt CalcColLabelsExposed( const wxRegion& reg ) const; |
867 | wxGridCellCoordsArray CalcCellsExposed( const wxRegion& reg ) const; | |
60ff3b99 | 868 | |
2d66e025 | 869 | |
f85afd4e | 870 | void ClearGrid(); |
10a4531d VZ |
871 | bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true) |
872 | { | |
873 | return DoModifyLines(&wxGridTableBase::InsertRows, | |
874 | pos, numRows, updateLabels); | |
875 | } | |
876 | bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true) | |
877 | { | |
878 | return DoModifyLines(&wxGridTableBase::InsertCols, | |
879 | pos, numCols, updateLabels); | |
880 | } | |
881 | ||
882 | bool AppendRows(int numRows = 1, bool updateLabels = true) | |
883 | { | |
884 | return DoAppendLines(&wxGridTableBase::AppendRows, numRows, updateLabels); | |
885 | } | |
886 | bool AppendCols(int numCols = 1, bool updateLabels = true) | |
887 | { | |
888 | return DoAppendLines(&wxGridTableBase::AppendCols, numCols, updateLabels); | |
889 | } | |
890 | ||
891 | bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true) | |
892 | { | |
893 | return DoModifyLines(&wxGridTableBase::DeleteRows, | |
894 | pos, numRows, updateLabels); | |
895 | } | |
896 | bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true) | |
897 | { | |
898 | return DoModifyLines(&wxGridTableBase::DeleteCols, | |
899 | pos, numCols, updateLabels); | |
900 | } | |
f85afd4e | 901 | |
d10f4bf9 | 902 | void DrawGridCellArea( wxDC& dc , const wxGridCellCoordsArray& cells ); |
7c8a8ad5 | 903 | void DrawGridSpace( wxDC& dc ); |
2d66e025 | 904 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); |
4634a5d6 | 905 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); |
2d66e025 | 906 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); |
d10f4bf9 | 907 | void DrawHighlight(wxDC& dc, const wxGridCellCoordsArray& cells); |
d16c04bb VZ |
908 | |
909 | // this function is called when the current cell highlight must be redrawn | |
910 | // and may be overridden by the user | |
911 | virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); | |
1f1ce288 | 912 | |
6914b57a JS |
913 | virtual void DrawRowLabels( wxDC& dc, const wxArrayInt& rows ); |
914 | virtual void DrawRowLabel( wxDC& dc, int row ); | |
8fb66724 | 915 | |
6914b57a JS |
916 | virtual void DrawColLabels( wxDC& dc, const wxArrayInt& cols ); |
917 | virtual void DrawColLabel( wxDC& dc, int col ); | |
60ff3b99 | 918 | |
ff72f628 | 919 | virtual void DrawCornerLabel(wxDC& dc); |
f85afd4e | 920 | |
2d66e025 | 921 | // ------ Cell text drawing functions |
f85afd4e | 922 | // |
2d66e025 | 923 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, |
4c7277db | 924 | int horizontalAlignment = wxALIGN_LEFT, |
d43851f7 JS |
925 | int verticalAlignment = wxALIGN_TOP, |
926 | int textOrientation = wxHORIZONTAL ); | |
30bc4a8f | 927 | |
d10f4bf9 VZ |
928 | void DrawTextRectangle( wxDC& dc, const wxArrayString& lines, const wxRect&, |
929 | int horizontalAlignment = wxALIGN_LEFT, | |
d43851f7 JS |
930 | int verticalAlignment = wxALIGN_TOP, |
931 | int textOrientation = wxHORIZONTAL ); | |
d10f4bf9 | 932 | |
f85afd4e | 933 | |
ef316e23 | 934 | // Split a string containing newline characters into an array of |
2d66e025 MB |
935 | // strings and return the number of lines |
936 | // | |
ef316e23 | 937 | void StringToLines( const wxString& value, wxArrayString& lines ) const; |
60ff3b99 | 938 | |
fbfb8bcc | 939 | void GetTextBoxSize( const wxDC& dc, |
d10f4bf9 | 940 | const wxArrayString& lines, |
ef316e23 | 941 | long *width, long *height ) const; |
60ff3b99 | 942 | |
2d66e025 | 943 | |
f85afd4e MB |
944 | // ------ |
945 | // Code that does a lot of grid modification can be enclosed | |
946 | // between BeginBatch() and EndBatch() calls to avoid screen | |
947 | // flicker | |
948 | // | |
949 | void BeginBatch() { m_batchCount++; } | |
f6bcfd97 BP |
950 | void EndBatch(); |
951 | ||
f85afd4e MB |
952 | int GetBatchCount() { return m_batchCount; } |
953 | ||
8a3e536c | 954 | virtual void Refresh(bool eraseb = true, const wxRect* rect = NULL); |
27f35b66 | 955 | |
d8232393 MB |
956 | // Use this, rather than wxWindow::Refresh(), to force an |
957 | // immediate repainting of the grid. Has no effect if you are | |
958 | // already inside a BeginBatch / EndBatch block. | |
959 | // | |
960 | // This function is necessary because wxGrid has a minimal OnPaint() | |
961 | // handler to reduce screen flicker. | |
962 | // | |
963 | void ForceRefresh(); | |
d2520c85 | 964 | |
2d66e025 MB |
965 | |
966 | // ------ edit control functions | |
967 | // | |
84035150 | 968 | bool IsEditable() const { return m_editable; } |
2d66e025 MB |
969 | void EnableEditing( bool edit ); |
970 | ||
ca65c044 WS |
971 | void EnableCellEditControl( bool enable = true ); |
972 | void DisableCellEditControl() { EnableCellEditControl(false); } | |
b54ba671 VZ |
973 | bool CanEnableCellControl() const; |
974 | bool IsCellEditControlEnabled() const; | |
f6bcfd97 | 975 | bool IsCellEditControlShown() const; |
2d66e025 | 976 | |
b54ba671 | 977 | bool IsCurrentCellReadOnly() const; |
2d66e025 | 978 | |
2d66e025 MB |
979 | void ShowCellEditControl(); |
980 | void HideCellEditControl(); | |
2d66e025 MB |
981 | void SaveEditControlValue(); |
982 | ||
60ff3b99 | 983 | |
2d66e025 | 984 | // ------ grid location functions |
60ff3b99 | 985 | // Note that all of these functions work with the logical coordinates of |
2d66e025 MB |
986 | // grid cells and labels so you will need to convert from device |
987 | // coordinates for mouse events etc. | |
988 | // | |
8a3e536c VZ |
989 | wxGridCellCoords XYToCell(int x, int y) const; |
990 | void XYToCell(int x, int y, wxGridCellCoords& coords) const | |
991 | { coords = XYToCell(x, y); } | |
992 | wxGridCellCoords XYToCell(const wxPoint& pos) const | |
993 | { return XYToCell(pos.x, pos.y); } | |
994 | ||
cd4f6f5f VZ |
995 | // these functions return the index of the row/columns corresponding to the |
996 | // given logical position in pixels | |
997 | // | |
998 | // if clipToMinMax is false (default, wxNOT_FOUND is returned if the | |
999 | // position is outside any row/column, otherwise the first/last element is | |
1000 | // returned in this case | |
bec70262 | 1001 | int YToRow( int y, bool clipToMinMax = false ) const; |
ef316e23 | 1002 | int XToCol( int x, bool clipToMinMax = false ) const; |
2d66e025 | 1003 | |
ef316e23 VZ |
1004 | int YToEdgeOfRow( int y ) const; |
1005 | int XToEdgeOfCol( int x ) const; | |
2d66e025 | 1006 | |
ef316e23 VZ |
1007 | wxRect CellToRect( int row, int col ) const; |
1008 | wxRect CellToRect( const wxGridCellCoords& coords ) const | |
2d66e025 MB |
1009 | { return CellToRect( coords.GetRow(), coords.GetCol() ); } |
1010 | ||
ef316e23 VZ |
1011 | int GetGridCursorRow() const { return m_currentCellCoords.GetRow(); } |
1012 | int GetGridCursorCol() const { return m_currentCellCoords.GetCol(); } | |
60ff3b99 | 1013 | |
2d66e025 MB |
1014 | // check to see if a cell is either wholly visible (the default arg) or |
1015 | // at least partially visible in the grid window | |
1016 | // | |
ef316e23 VZ |
1017 | bool IsVisible( int row, int col, bool wholeCellVisible = true ) const; |
1018 | bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = true ) const | |
2d66e025 MB |
1019 | { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } |
1020 | void MakeCellVisible( int row, int col ); | |
1021 | void MakeCellVisible( const wxGridCellCoords& coords ) | |
1022 | { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } | |
1023 | ||
60ff3b99 | 1024 | |
2d66e025 MB |
1025 | // ------ grid cursor movement functions |
1026 | // | |
8a3e536c VZ |
1027 | void SetGridCursor(int row, int col) { SetCurrentCell(row, col); } |
1028 | void SetGridCursor(const wxGridCellCoords& c) { SetCurrentCell(c); } | |
1029 | ||
1030 | void GoToCell(int row, int col) | |
1031 | { | |
1032 | if ( SetCurrentCell(row, col) ) | |
1033 | MakeCellVisible(row, col); | |
1034 | } | |
1035 | ||
1036 | void GoToCell(const wxGridCellCoords& coords) | |
1037 | { | |
1038 | if ( SetCurrentCell(coords) ) | |
1039 | MakeCellVisible(coords); | |
1040 | } | |
dfaf42d2 | 1041 | |
5c8fc7c1 SN |
1042 | bool MoveCursorUp( bool expandSelection ); |
1043 | bool MoveCursorDown( bool expandSelection ); | |
1044 | bool MoveCursorLeft( bool expandSelection ); | |
1045 | bool MoveCursorRight( bool expandSelection ); | |
2d66e025 MB |
1046 | bool MovePageDown(); |
1047 | bool MovePageUp(); | |
5c8fc7c1 SN |
1048 | bool MoveCursorUpBlock( bool expandSelection ); |
1049 | bool MoveCursorDownBlock( bool expandSelection ); | |
1050 | bool MoveCursorLeftBlock( bool expandSelection ); | |
1051 | bool MoveCursorRightBlock( bool expandSelection ); | |
2d66e025 | 1052 | |
60ff3b99 | 1053 | |
f85afd4e MB |
1054 | // ------ label and gridline formatting |
1055 | // | |
ef316e23 VZ |
1056 | int GetDefaultRowLabelSize() const { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; } |
1057 | int GetRowLabelSize() const { return m_rowLabelWidth; } | |
1058 | int GetDefaultColLabelSize() const { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; } | |
1059 | int GetColLabelSize() const { return m_colLabelHeight; } | |
1060 | wxColour GetLabelBackgroundColour() const { return m_labelBackgroundColour; } | |
1061 | wxColour GetLabelTextColour() const { return m_labelTextColour; } | |
1062 | wxFont GetLabelFont() const { return m_labelFont; } | |
1063 | void GetRowLabelAlignment( int *horiz, int *vert ) const; | |
1064 | void GetColLabelAlignment( int *horiz, int *vert ) const; | |
1065 | int GetColLabelTextOrientation() const; | |
1066 | wxString GetRowLabelValue( int row ) const; | |
1067 | wxString GetColLabelValue( int col ) const; | |
3d3f3e37 | 1068 | |
ef316e23 VZ |
1069 | wxColour GetCellHighlightColour() const { return m_cellHighlightColour; } |
1070 | int GetCellHighlightPenWidth() const { return m_cellHighlightPenWidth; } | |
1071 | int GetCellHighlightROPenWidth() const { return m_cellHighlightROPenWidth; } | |
f85afd4e | 1072 | |
ad805b9e VZ |
1073 | // this one will use wxHeaderCtrl for the column labels |
1074 | void UseNativeColHeader(bool native = true); | |
1075 | ||
1076 | // this one will still draw them manually but using the native renderer | |
1077 | // instead of using the same appearance as for the row labels | |
1078 | void SetUseNativeColLabels( bool native = true ); | |
1079 | ||
ab79958a | 1080 | void SetRowLabelSize( int width ); |
f85afd4e | 1081 | void SetColLabelSize( int height ); |
0a9ca9c4 RR |
1082 | void HideRowLabels() { SetRowLabelSize( 0 ); } |
1083 | void HideColLabels() { SetColLabelSize( 0 ); } | |
f85afd4e MB |
1084 | void SetLabelBackgroundColour( const wxColour& ); |
1085 | void SetLabelTextColour( const wxColour& ); | |
1086 | void SetLabelFont( const wxFont& ); | |
1087 | void SetRowLabelAlignment( int horiz, int vert ); | |
1088 | void SetColLabelAlignment( int horiz, int vert ); | |
d43851f7 | 1089 | void SetColLabelTextOrientation( int textOrientation ); |
f85afd4e MB |
1090 | void SetRowLabelValue( int row, const wxString& ); |
1091 | void SetColLabelValue( int col, const wxString& ); | |
f6bcfd97 | 1092 | void SetCellHighlightColour( const wxColour& ); |
d2520c85 RD |
1093 | void SetCellHighlightPenWidth(int width); |
1094 | void SetCellHighlightROPenWidth(int width); | |
28a77bc4 | 1095 | |
82edfbe7 VZ |
1096 | |
1097 | // interactive grid mouse operations control | |
1098 | // ----------------------------------------- | |
1099 | ||
1100 | // functions globally enabling row/column interactive resizing (enabled by | |
1101 | // default) | |
ca65c044 WS |
1102 | void EnableDragRowSize( bool enable = true ); |
1103 | void DisableDragRowSize() { EnableDragRowSize( false ); } | |
82edfbe7 | 1104 | |
ca65c044 WS |
1105 | void EnableDragColSize( bool enable = true ); |
1106 | void DisableDragColSize() { EnableDragColSize( false ); } | |
82edfbe7 VZ |
1107 | |
1108 | // if interactive resizing is enabled, some rows/columns can still have | |
1109 | // fixed size | |
1110 | void DisableRowResize(int row) { DoDisableLineResize(row, m_setFixedRows); } | |
1111 | void DisableColResize(int col) { DoDisableLineResize(col, m_setFixedCols); } | |
1112 | ||
1113 | // these functions return whether the given row/column can be | |
1114 | // effectively resized: for this interactive resizing must be enabled | |
1115 | // and this index must not have been passed to DisableRow/ColResize() | |
1116 | bool CanDragRowSize(int row) const | |
1117 | { return m_canDragRowSize && DoCanResizeLine(row, m_setFixedRows); } | |
1118 | bool CanDragColSize(int col) const | |
1119 | { return m_canDragColSize && DoCanResizeLine(col, m_setFixedCols); } | |
1120 | ||
1121 | // interactive column reordering (disabled by default) | |
d4175745 VZ |
1122 | void EnableDragColMove( bool enable = true ); |
1123 | void DisableDragColMove() { EnableDragColMove( false ); } | |
ef316e23 | 1124 | bool CanDragColMove() const { return m_canDragColMove; } |
82edfbe7 VZ |
1125 | |
1126 | // interactive resizing of grid cells (enabled by default) | |
ca65c044 WS |
1127 | void EnableDragGridSize(bool enable = true); |
1128 | void DisableDragGridSize() { EnableDragGridSize(false); } | |
ef316e23 | 1129 | bool CanDragGridSize() const { return m_canDragGridSize; } |
4cfa5de6 | 1130 | |
82edfbe7 | 1131 | // interactive dragging of cells (disabled by default) |
79dbea21 RD |
1132 | void EnableDragCell( bool enable = true ); |
1133 | void DisableDragCell() { EnableDragCell( false ); } | |
ef316e23 | 1134 | bool CanDragCell() const { return m_canDragCell; } |
79dbea21 | 1135 | |
9f7aee01 VZ |
1136 | |
1137 | // grid lines | |
1138 | // ---------- | |
1139 | ||
1140 | // enable or disable drawing of the lines | |
1141 | void EnableGridLines(bool enable = true); | |
1142 | bool GridLinesEnabled() const { return m_gridLinesEnabled; } | |
1143 | ||
1144 | // by default grid lines stop at last column/row, but this may be changed | |
1145 | void ClipHorzGridLines(bool clip) | |
1146 | { DoClipGridLines(m_gridLinesClipHorz, clip); } | |
1147 | void ClipVertGridLines(bool clip) | |
1148 | { DoClipGridLines(m_gridLinesClipVert, clip); } | |
1149 | bool AreHorzGridLinesClipped() const { return m_gridLinesClipHorz; } | |
1150 | bool AreVertGridLinesClipped() const { return m_gridLinesClipVert; } | |
1151 | ||
1152 | // this can be used to change the global grid lines colour | |
1153 | void SetGridLineColour(const wxColour& col); | |
1154 | wxColour GetGridLineColour() const { return m_gridLineColour; } | |
1155 | ||
1156 | // these methods may be overridden to customize individual grid lines | |
1157 | // appearance | |
1158 | virtual wxPen GetDefaultGridLinePen(); | |
1159 | virtual wxPen GetRowGridLinePen(int row); | |
1160 | virtual wxPen GetColGridLinePen(int col); | |
1161 | ||
1162 | ||
1163 | // attributes | |
1164 | // ---------- | |
1165 | ||
27f35b66 SN |
1166 | // this sets the specified attribute for this cell or in this row/col |
1167 | void SetAttr(int row, int col, wxGridCellAttr *attr); | |
758cbedf VZ |
1168 | void SetRowAttr(int row, wxGridCellAttr *attr); |
1169 | void SetColAttr(int col, wxGridCellAttr *attr); | |
1170 | ||
71e60f70 RD |
1171 | // returns the attribute we may modify in place: a new one if this cell |
1172 | // doesn't have any yet or the existing one if it does | |
1173 | // | |
1174 | // DecRef() must be called on the returned pointer, as usual | |
1175 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; | |
1176 | ||
d94c09cd | 1177 | |
0b190b0f VZ |
1178 | // shortcuts for setting the column parameters |
1179 | ||
1180 | // set the format for the data in the column: default is string | |
1181 | void SetColFormatBool(int col); | |
1182 | void SetColFormatNumber(int col); | |
1183 | void SetColFormatFloat(int col, int width = -1, int precision = -1); | |
1184 | void SetColFormatCustom(int col, const wxString& typeName); | |
1185 | ||
f85afd4e MB |
1186 | // ------ row and col formatting |
1187 | // | |
ef316e23 VZ |
1188 | int GetDefaultRowSize() const; |
1189 | int GetRowSize( int row ) const; | |
fe79f76b | 1190 | bool IsRowShown(int row) const { return GetRowSize(row) != 0; } |
ef316e23 VZ |
1191 | int GetDefaultColSize() const; |
1192 | int GetColSize( int col ) const; | |
fe79f76b | 1193 | bool IsColShown(int col) const { return GetColSize(col) != 0; } |
ef316e23 VZ |
1194 | wxColour GetDefaultCellBackgroundColour() const; |
1195 | wxColour GetCellBackgroundColour( int row, int col ) const; | |
1196 | wxColour GetDefaultCellTextColour() const; | |
1197 | wxColour GetCellTextColour( int row, int col ) const; | |
1198 | wxFont GetDefaultCellFont() const; | |
1199 | wxFont GetCellFont( int row, int col ) const; | |
1200 | void GetDefaultCellAlignment( int *horiz, int *vert ) const; | |
1201 | void GetCellAlignment( int row, int col, int *horiz, int *vert ) const; | |
1202 | bool GetDefaultCellOverflow() const; | |
1203 | bool GetCellOverflow( int row, int col ) const; | |
1204 | void GetCellSize( int row, int col, int *num_rows, int *num_cols ) const; | |
bec70262 VZ |
1205 | wxSize GetCellSize(const wxGridCellCoords& coords) |
1206 | { | |
1207 | wxSize s; | |
1208 | GetCellSize(coords.GetRow(), coords.GetCol(), &s.x, &s.y); | |
1209 | return s; | |
1210 | } | |
60ff3b99 | 1211 | |
009c7216 | 1212 | // ------ row and col sizes |
ca65c044 | 1213 | void SetDefaultRowSize( int height, bool resizeExistingRows = false ); |
f85afd4e | 1214 | void SetRowSize( int row, int height ); |
009c7216 VZ |
1215 | void HideRow(int row) { SetRowSize(row, 0); } |
1216 | void ShowRow(int row) { SetRowSize(row, -1); } | |
8fb66724 | 1217 | |
009c7216 | 1218 | void SetDefaultColSize( int width, bool resizeExistingCols = false ); |
f85afd4e | 1219 | void SetColSize( int col, int width ); |
009c7216 VZ |
1220 | void HideCol(int col) { SetColSize(col, 0); } |
1221 | void ShowCol(int col) { SetColSize(col, -1); } | |
1222 | ||
574e1c5a VZ |
1223 | // the row and column sizes can be also set all at once using |
1224 | // wxGridSizesInfo which holds all of them at once | |
1225 | ||
1226 | wxGridSizesInfo GetColSizes() const | |
1227 | { return wxGridSizesInfo(GetDefaultColSize(), m_colWidths); } | |
1228 | wxGridSizesInfo GetRowSizes() const | |
1229 | { return wxGridSizesInfo(GetDefaultRowSize(), m_rowHeights); } | |
1230 | ||
1231 | void SetColSizes(const wxGridSizesInfo& sizeInfo); | |
1232 | void SetRowSizes(const wxGridSizesInfo& sizeInfo); | |
1233 | ||
009c7216 VZ |
1234 | |
1235 | // ------- columns (only, for now) reordering | |
43947979 | 1236 | |
cd4f6f5f VZ |
1237 | // columns index <-> positions mapping: by default, the position of the |
1238 | // column is the same as its index, but the columns can also be reordered | |
1239 | // (either by calling SetColPos() explicitly or by the user dragging the | |
1240 | // columns around) in which case their indices don't correspond to their | |
1241 | // positions on display any longer | |
1242 | // | |
1243 | // internally we always work with indices except for the functions which | |
1244 | // have "Pos" in their names (and which work with columns, not pixels) and | |
1245 | // only the display and hit testing code really cares about display | |
1246 | // positions at all | |
1247 | ||
31ec8b4e VZ |
1248 | // set the positions of all columns at once (this method uses the same |
1249 | // conventions as wxHeaderCtrl::SetColumnsOrder() for the order array) | |
1250 | void SetColumnsOrder(const wxArrayInt& order); | |
1251 | ||
cd4f6f5f VZ |
1252 | // return the column index corresponding to the given (valid) position |
1253 | int GetColAt(int pos) const | |
d4175745 | 1254 | { |
cd4f6f5f | 1255 | return m_colAt.empty() ? pos : m_colAt[pos]; |
d4175745 VZ |
1256 | } |
1257 | ||
cd4f6f5f VZ |
1258 | // reorder the columns so that the column with the given index is now shown |
1259 | // as the position pos | |
1260 | void SetColPos(int idx, int pos); | |
d4175745 | 1261 | |
cd4f6f5f VZ |
1262 | // return the position at which the column with the given index is |
1263 | // displayed: notice that this is a slow operation as we don't maintain the | |
1264 | // reverse mapping currently | |
1265 | int GetColPos(int idx) const | |
d4175745 VZ |
1266 | { |
1267 | if ( m_colAt.IsEmpty() ) | |
cd4f6f5f VZ |
1268 | return idx; |
1269 | ||
1270 | for ( int i = 0; i < m_numCols; i++ ) | |
d4175745 | 1271 | { |
cd4f6f5f VZ |
1272 | if ( m_colAt[i] == idx ) |
1273 | return i; | |
d4175745 VZ |
1274 | } |
1275 | ||
cd4f6f5f VZ |
1276 | wxFAIL_MSG( "invalid column index" ); |
1277 | ||
1278 | return wxNOT_FOUND; | |
d4175745 VZ |
1279 | } |
1280 | ||
009c7216 VZ |
1281 | // reset the columns positions to the default order |
1282 | void ResetColPos(); | |
cd4f6f5f VZ |
1283 | |
1284 | ||
af547d51 | 1285 | // automatically size the column or row to fit to its contents, if |
ca65c044 | 1286 | // setAsMin is true, this optimal width will also be set as minimal width |
af547d51 | 1287 | // for this column |
ca65c044 | 1288 | void AutoSizeColumn( int col, bool setAsMin = true ) |
733f486a | 1289 | { AutoSizeColOrRow(col, setAsMin, wxGRID_COLUMN); } |
ca65c044 | 1290 | void AutoSizeRow( int row, bool setAsMin = true ) |
733f486a | 1291 | { AutoSizeColOrRow(row, setAsMin, wxGRID_ROW); } |
65e4e78e VZ |
1292 | |
1293 | // auto size all columns (very ineffective for big grids!) | |
ca65c044 WS |
1294 | void AutoSizeColumns( bool setAsMin = true ) |
1295 | { (void)SetOrCalcColumnSizes(false, setAsMin); } | |
65e4e78e | 1296 | |
ca65c044 WS |
1297 | void AutoSizeRows( bool setAsMin = true ) |
1298 | { (void)SetOrCalcRowSizes(false, setAsMin); } | |
57c086ef VZ |
1299 | |
1300 | // auto size the grid, that is make the columns/rows of the "right" size | |
1301 | // and also set the grid size to just fit its contents | |
1302 | void AutoSize(); | |
1303 | ||
733f486a VZ |
1304 | // Note for both AutoSizeRowLabelSize and AutoSizeColLabelSize: |
1305 | // If col equals to wxGRID_AUTOSIZE value then function autosizes labels column | |
1306 | // instead of data column. Note that this operation may be slow for large | |
1307 | // tables. | |
d43851f7 JS |
1308 | // autosize row height depending on label text |
1309 | void AutoSizeRowLabelSize( int row ); | |
1310 | ||
1311 | // autosize column width depending on label text | |
1312 | void AutoSizeColLabelSize( int col ); | |
1313 | ||
43947979 VZ |
1314 | // column won't be resized to be lesser width - this must be called during |
1315 | // the grid creation because it won't resize the column if it's already | |
1316 | // narrower than the minimal width | |
1317 | void SetColMinimalWidth( int col, int width ); | |
af547d51 | 1318 | void SetRowMinimalHeight( int row, int width ); |
43947979 | 1319 | |
b8d24d4e RG |
1320 | /* These members can be used to query and modify the minimal |
1321 | * acceptable size of grid rows and columns. Call this function in | |
1322 | * your code which creates the grid if you want to display cells | |
1323 | * with a size smaller than the default acceptable minimum size. | |
1324 | * Like the members SetColMinimalWidth and SetRowMinimalWidth, | |
1325 | * the existing rows or columns will not be checked/resized. | |
1326 | */ | |
1327 | void SetColMinimalAcceptableWidth( int width ); | |
1328 | void SetRowMinimalAcceptableHeight( int width ); | |
1329 | int GetColMinimalAcceptableWidth() const; | |
1330 | int GetRowMinimalAcceptableHeight() const; | |
1331 | ||
f85afd4e MB |
1332 | void SetDefaultCellBackgroundColour( const wxColour& ); |
1333 | void SetCellBackgroundColour( int row, int col, const wxColour& ); | |
1334 | void SetDefaultCellTextColour( const wxColour& ); | |
8fb66724 | 1335 | |
f85afd4e | 1336 | void SetCellTextColour( int row, int col, const wxColour& ); |
f85afd4e MB |
1337 | void SetDefaultCellFont( const wxFont& ); |
1338 | void SetCellFont( int row, int col, const wxFont& ); | |
1339 | void SetDefaultCellAlignment( int horiz, int vert ); | |
1340 | void SetCellAlignment( int row, int col, int horiz, int vert ); | |
27f35b66 SN |
1341 | void SetDefaultCellOverflow( bool allow ); |
1342 | void SetCellOverflow( int row, int col, bool allow ); | |
1343 | void SetCellSize( int row, int col, int num_rows, int num_cols ); | |
f85afd4e | 1344 | |
ab79958a | 1345 | // takes ownership of the pointer |
2796cce3 | 1346 | void SetDefaultRenderer(wxGridCellRenderer *renderer); |
ab79958a | 1347 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); |
2796cce3 | 1348 | wxGridCellRenderer *GetDefaultRenderer() const; |
ef316e23 | 1349 | wxGridCellRenderer* GetCellRenderer(int row, int col) const; |
2796cce3 | 1350 | |
283b7808 | 1351 | // takes ownership of the pointer |
0ba143c9 | 1352 | void SetDefaultEditor(wxGridCellEditor *editor); |
9b4aede2 | 1353 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); |
0ba143c9 | 1354 | wxGridCellEditor *GetDefaultEditor() const; |
ef316e23 | 1355 | wxGridCellEditor* GetCellEditor(int row, int col) const; |
9b4aede2 | 1356 | |
60a67569 | 1357 | |
f2d76237 | 1358 | |
f85afd4e MB |
1359 | // ------ cell value accessors |
1360 | // | |
ef316e23 | 1361 | wxString GetCellValue( int row, int col ) const |
f85afd4e MB |
1362 | { |
1363 | if ( m_table ) | |
1364 | { | |
1365 | return m_table->GetValue( row, col ); | |
1366 | } | |
1367 | else | |
1368 | { | |
1369 | return wxEmptyString; | |
1370 | } | |
1371 | } | |
1372 | ||
ef316e23 | 1373 | wxString GetCellValue( const wxGridCellCoords& coords ) const |
f85afd4e | 1374 | { return GetCellValue( coords.GetRow(), coords.GetCol() ); } |
60ff3b99 | 1375 | |
f85afd4e MB |
1376 | void SetCellValue( int row, int col, const wxString& s ); |
1377 | void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) | |
1378 | { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } | |
f85afd4e | 1379 | |
ca65c044 | 1380 | // returns true if the cell can't be edited |
283b7808 | 1381 | bool IsReadOnly(int row, int col) const; |
60ff3b99 | 1382 | |
283b7808 | 1383 | // make the cell editable/readonly |
ca65c044 | 1384 | void SetReadOnly(int row, int col, bool isReadOnly = true); |
f85afd4e | 1385 | |
aa5b8857 | 1386 | // ------ select blocks of cells |
f85afd4e | 1387 | // |
ca65c044 WS |
1388 | void SelectRow( int row, bool addToSelected = false ); |
1389 | void SelectCol( int col, bool addToSelected = false ); | |
60ff3b99 | 1390 | |
c9097836 | 1391 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, |
ca65c044 | 1392 | bool addToSelected = false ); |
f85afd4e MB |
1393 | |
1394 | void SelectBlock( const wxGridCellCoords& topLeft, | |
c9097836 | 1395 | const wxGridCellCoords& bottomRight, |
ca65c044 | 1396 | bool addToSelected = false ) |
f85afd4e | 1397 | { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), |
c9097836 MB |
1398 | bottomRight.GetRow(), bottomRight.GetCol(), |
1399 | addToSelected ); } | |
f85afd4e MB |
1400 | |
1401 | void SelectAll(); | |
60ff3b99 | 1402 | |
ef316e23 | 1403 | bool IsSelection() const; |
f85afd4e | 1404 | |
aa5b8857 | 1405 | // ------ deselect blocks or cells |
f7b4b343 VZ |
1406 | // |
1407 | void DeselectRow( int row ); | |
1408 | void DeselectCol( int col ); | |
1409 | void DeselectCell( int row, int col ); | |
1410 | ||
f85afd4e MB |
1411 | void ClearSelection(); |
1412 | ||
84035150 | 1413 | bool IsInSelection( int row, int col ) const; |
f85afd4e | 1414 | |
84035150 | 1415 | bool IsInSelection( const wxGridCellCoords& coords ) const |
f85afd4e MB |
1416 | { return IsInSelection( coords.GetRow(), coords.GetCol() ); } |
1417 | ||
aa5b8857 SN |
1418 | wxGridCellCoordsArray GetSelectedCells() const; |
1419 | wxGridCellCoordsArray GetSelectionBlockTopLeft() const; | |
1420 | wxGridCellCoordsArray GetSelectionBlockBottomRight() const; | |
1421 | wxArrayInt GetSelectedRows() const; | |
1422 | wxArrayInt GetSelectedCols() const; | |
c3baf426 SN |
1423 | |
1424 | // This function returns the rectangle that encloses the block of cells | |
1425 | // limited by TopLeft and BottomRight cell in device coords and clipped | |
1426 | // to the client size of the grid window. | |
1427 | // | |
58dd5b3b | 1428 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, |
ef316e23 | 1429 | const wxGridCellCoords & bottomRight ) const; |
c3baf426 | 1430 | |
2796cce3 RD |
1431 | // Access or update the selection fore/back colours |
1432 | wxColour GetSelectionBackground() const | |
1433 | { return m_selectionBackground; } | |
1434 | wxColour GetSelectionForeground() const | |
1435 | { return m_selectionForeground; } | |
1436 | ||
1437 | void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } | |
1438 | void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } | |
1439 | ||
1440 | ||
f2d76237 RD |
1441 | // Methods for a registry for mapping data types to Renderers/Editors |
1442 | void RegisterDataType(const wxString& typeName, | |
1443 | wxGridCellRenderer* renderer, | |
1444 | wxGridCellEditor* editor); | |
73145b0e JS |
1445 | // DJC MAPTEK |
1446 | virtual wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const; | |
99306db2 VZ |
1447 | wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const |
1448 | { return GetDefaultEditorForCell(c.GetRow(), c.GetCol()); } | |
73145b0e JS |
1449 | virtual wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const; |
1450 | virtual wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const; | |
1451 | virtual wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const; | |
f2d76237 | 1452 | |
266e8367 VZ |
1453 | // grid may occupy more space than needed for its rows/columns, this |
1454 | // function allows to set how big this extra space is | |
1455 | void SetMargins(int extraWidth, int extraHeight) | |
1456 | { | |
1457 | m_extraWidth = extraWidth; | |
1458 | m_extraHeight = extraHeight; | |
b8125adf VZ |
1459 | |
1460 | CalcDimensions(); | |
266e8367 | 1461 | } |
f85afd4e | 1462 | |
d2520c85 | 1463 | // Accessors for component windows |
ef316e23 VZ |
1464 | wxWindow* GetGridWindow() const { return (wxWindow*)m_gridWin; } |
1465 | wxWindow* GetGridRowLabelWindow() const { return (wxWindow*)m_rowLabelWin; } | |
ad805b9e | 1466 | wxWindow* GetGridColLabelWindow() const { return m_colWindow; } |
ef316e23 | 1467 | wxWindow* GetGridCornerLabelWindow() const { return (wxWindow*)m_cornerLabelWin; } |
d2520c85 | 1468 | |
3039ade9 VZ |
1469 | // This one can only be called if we are using the native header window |
1470 | wxHeaderCtrl *GetGridColHeader() const | |
1471 | { | |
1472 | wxASSERT_MSG( m_useNativeHeader, "no column header window" ); | |
1473 | ||
1474 | // static_cast<> doesn't work without the full class declaration in | |
1475 | // view and we prefer to avoid adding more compile-time dependencies | |
1476 | // even at the cost of using reinterpret_cast<> | |
1477 | return reinterpret_cast<wxHeaderCtrl *>(m_colWindow); | |
1478 | } | |
1479 | ||
608754c4 JS |
1480 | // Allow adjustment of scroll increment. The default is (15, 15). |
1481 | void SetScrollLineX(int x) { m_scrollLineX = x; } | |
1482 | void SetScrollLineY(int y) { m_scrollLineY = y; } | |
1483 | int GetScrollLineX() const { return m_scrollLineX; } | |
1484 | int GetScrollLineY() const { return m_scrollLineY; } | |
1485 | ||
1edce33f VZ |
1486 | // ------- drag and drop |
1487 | #if wxUSE_DRAG_AND_DROP | |
1488 | virtual void SetDropTarget(wxDropTarget *dropTarget); | |
1489 | #endif // wxUSE_DRAG_AND_DROP | |
bf646121 | 1490 | |
bf2c8b31 | 1491 | |
11393d29 VZ |
1492 | // ------- sorting support |
1493 | ||
1494 | // wxGrid doesn't support sorting on its own but it can indicate the sort | |
1495 | // order in the column header (currently only if native header control is | |
1496 | // used though) | |
1497 | ||
1498 | // return the column currently displaying the sort indicator or wxNOT_FOUND | |
1499 | // if none | |
1500 | int GetSortingColumn() const { return m_sortCol; } | |
1501 | ||
1502 | // return true if this column is currently used for sorting | |
1503 | bool IsSortingBy(int col) const { return GetSortingColumn() == col; } | |
1504 | ||
1505 | // return the current sorting order (on GetSortingColumn()): true for | |
1506 | // ascending sort and false for descending; it doesn't make sense to call | |
1507 | // it if GetSortingColumn() returns wxNOT_FOUND | |
1508 | bool IsSortOrderAscending() const { return m_sortIsAscending; } | |
1509 | ||
1510 | // set the sorting column (or unsets any existing one if wxNOT_FOUND) and | |
1511 | // the order in which to sort | |
1512 | void SetSortingColumn(int col, bool ascending = true); | |
1513 | ||
1514 | // unset any existing sorting column | |
1515 | void UnsetSortingColumn() { SetSortingColumn(wxNOT_FOUND); } | |
1516 | ||
bf2c8b31 | 1517 | #ifdef WXWIN_COMPATIBILITY_2_8 |
f85afd4e MB |
1518 | // ------ For compatibility with previous wxGrid only... |
1519 | // | |
1520 | // ************************************************ | |
1521 | // ** Don't use these in new code because they ** | |
1522 | // ** are liable to disappear in a future ** | |
1523 | // ** revision ** | |
1524 | // ************************************************ | |
1525 | // | |
1526 | ||
1527 | wxGrid( wxWindow *parent, | |
422d0ff0 | 1528 | int x, int y, int w = wxDefaultCoord, int h = wxDefaultCoord, |
ebd773c6 | 1529 | long style = wxWANTS_CHARS, |
f85afd4e | 1530 | const wxString& name = wxPanelNameStr ) |
ad805b9e VZ |
1531 | { |
1532 | Init(); | |
1533 | Create(parent, wxID_ANY, wxPoint(x, y), wxSize(w, h), style, name); | |
1534 | } | |
f85afd4e MB |
1535 | |
1536 | void SetCellValue( const wxString& val, int row, int col ) | |
1537 | { SetCellValue( row, col, val ); } | |
60ff3b99 | 1538 | |
f85afd4e MB |
1539 | void UpdateDimensions() |
1540 | { CalcDimensions(); } | |
1541 | ||
ef316e23 VZ |
1542 | int GetRows() const { return GetNumberRows(); } |
1543 | int GetCols() const { return GetNumberCols(); } | |
1544 | int GetCursorRow() const { return GetGridCursorRow(); } | |
1545 | int GetCursorColumn() const { return GetGridCursorCol(); } | |
60ff3b99 | 1546 | |
ef316e23 VZ |
1547 | int GetScrollPosX() const { return 0; } |
1548 | int GetScrollPosY() const { return 0; } | |
60ff3b99 | 1549 | |
aa5e1f75 SN |
1550 | void SetScrollX( int WXUNUSED(x) ) { } |
1551 | void SetScrollY( int WXUNUSED(y) ) { } | |
f85afd4e MB |
1552 | |
1553 | void SetColumnWidth( int col, int width ) | |
1554 | { SetColSize( col, width ); } | |
60ff3b99 | 1555 | |
ef316e23 | 1556 | int GetColumnWidth( int col ) const |
f85afd4e | 1557 | { return GetColSize( col ); } |
60ff3b99 | 1558 | |
f85afd4e MB |
1559 | void SetRowHeight( int row, int height ) |
1560 | { SetRowSize( row, height ); } | |
60ff3b99 | 1561 | |
7c1cb261 | 1562 | // GetRowHeight() is below |
60ff3b99 | 1563 | |
ef316e23 | 1564 | int GetViewHeight() const // returned num whole rows visible |
2d66e025 | 1565 | { return 0; } |
60ff3b99 | 1566 | |
ef316e23 | 1567 | int GetViewWidth() const // returned num whole cols visible |
2d66e025 | 1568 | { return 0; } |
f85afd4e MB |
1569 | |
1570 | void SetLabelSize( int orientation, int sz ) | |
1571 | { | |
1572 | if ( orientation == wxHORIZONTAL ) | |
1573 | SetColLabelSize( sz ); | |
1574 | else | |
1575 | SetRowLabelSize( sz ); | |
1576 | } | |
1577 | ||
ef316e23 | 1578 | int GetLabelSize( int orientation ) const |
f85afd4e MB |
1579 | { |
1580 | if ( orientation == wxHORIZONTAL ) | |
1581 | return GetColLabelSize(); | |
1582 | else | |
1583 | return GetRowLabelSize(); | |
1584 | } | |
1585 | ||
1586 | void SetLabelAlignment( int orientation, int align ) | |
1587 | { | |
1588 | if ( orientation == wxHORIZONTAL ) | |
1589 | SetColLabelAlignment( align, -1 ); | |
1590 | else | |
1591 | SetRowLabelAlignment( align, -1 ); | |
1592 | } | |
1593 | ||
ef316e23 | 1594 | int GetLabelAlignment( int orientation, int WXUNUSED(align) ) const |
f85afd4e MB |
1595 | { |
1596 | int h, v; | |
1597 | if ( orientation == wxHORIZONTAL ) | |
1598 | { | |
1599 | GetColLabelAlignment( &h, &v ); | |
1600 | return h; | |
1601 | } | |
1602 | else | |
1603 | { | |
1604 | GetRowLabelAlignment( &h, &v ); | |
1605 | return h; | |
1606 | } | |
1607 | } | |
1608 | ||
1609 | void SetLabelValue( int orientation, const wxString& val, int pos ) | |
1610 | { | |
1611 | if ( orientation == wxHORIZONTAL ) | |
1612 | SetColLabelValue( pos, val ); | |
1613 | else | |
1614 | SetRowLabelValue( pos, val ); | |
1615 | } | |
60ff3b99 | 1616 | |
ef316e23 | 1617 | wxString GetLabelValue( int orientation, int pos) const |
f85afd4e MB |
1618 | { |
1619 | if ( orientation == wxHORIZONTAL ) | |
1620 | return GetColLabelValue( pos ); | |
1621 | else | |
1622 | return GetRowLabelValue( pos ); | |
1623 | } | |
1624 | ||
60ff3b99 | 1625 | wxFont GetCellTextFont() const |
2796cce3 | 1626 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1627 | |
af111fc3 | 1628 | wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const |
2796cce3 | 1629 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1630 | |
f85afd4e MB |
1631 | void SetCellTextFont(const wxFont& fnt) |
1632 | { SetDefaultCellFont( fnt ); } | |
60ff3b99 | 1633 | |
f85afd4e MB |
1634 | void SetCellTextFont(const wxFont& fnt, int row, int col) |
1635 | { SetCellFont( row, col, fnt ); } | |
60ff3b99 | 1636 | |
f85afd4e MB |
1637 | void SetCellTextColour(const wxColour& val, int row, int col) |
1638 | { SetCellTextColour( row, col, val ); } | |
60ff3b99 | 1639 | |
f85afd4e MB |
1640 | void SetCellTextColour(const wxColour& col) |
1641 | { SetDefaultCellTextColour( col ); } | |
60ff3b99 | 1642 | |
f85afd4e MB |
1643 | void SetCellBackgroundColour(const wxColour& col) |
1644 | { SetDefaultCellBackgroundColour( col ); } | |
60ff3b99 | 1645 | |
f85afd4e MB |
1646 | void SetCellBackgroundColour(const wxColour& colour, int row, int col) |
1647 | { SetCellBackgroundColour( row, col, colour ); } | |
60ff3b99 | 1648 | |
ef316e23 | 1649 | bool GetEditable() const { return IsEditable(); } |
ca65c044 | 1650 | void SetEditable( bool edit = true ) { EnableEditing( edit ); } |
ef316e23 | 1651 | bool GetEditInPlace() const { return IsCellEditControlEnabled(); } |
8fb66724 | 1652 | |
ca65c044 | 1653 | void SetEditInPlace(bool WXUNUSED(edit) = true) { } |
f85afd4e | 1654 | |
60a67569 | 1655 | void SetCellAlignment( int align, int row, int col) |
4c7277db | 1656 | { SetCellAlignment(row, col, align, wxALIGN_CENTER); } |
60a67569 JS |
1657 | void SetCellAlignment( int WXUNUSED(align) ) {} |
1658 | void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) | |
1659 | { } | |
1660 | void SetDividerPen(const wxPen& WXUNUSED(pen)) { } | |
6fc0f38f | 1661 | wxPen& GetDividerPen() const; |
60a67569 | 1662 | void OnActivate(bool WXUNUSED(active)) {} |
60ff3b99 | 1663 | |
f85afd4e MB |
1664 | // ******** End of compatibility functions ********** |
1665 | ||
2d66e025 MB |
1666 | |
1667 | ||
f85afd4e | 1668 | // ------ control IDs |
2d66e025 | 1669 | enum { wxGRID_CELLCTRL = 2000, |
f85afd4e MB |
1670 | wxGRID_TOPCTRL }; |
1671 | ||
1672 | // ------ control types | |
2d66e025 | 1673 | enum { wxGRID_TEXTCTRL = 2100, |
f85afd4e MB |
1674 | wxGRID_CHECKBOX, |
1675 | wxGRID_CHOICE, | |
1676 | wxGRID_COMBOBOX }; | |
82edfbe7 VZ |
1677 | |
1678 | wxDEPRECATED_INLINE(bool CanDragRowSize() const, return m_canDragRowSize; ) | |
1679 | wxDEPRECATED_INLINE(bool CanDragColSize() const, return m_canDragColSize; ) | |
bf2c8b31 VZ |
1680 | #endif // WXWIN_COMPATIBILITY_2_8 |
1681 | ||
f85afd4e | 1682 | |
bf2c8b31 VZ |
1683 | // override some base class functions |
1684 | virtual bool Enable(bool enable = true); | |
1685 | virtual wxWindow *GetMainWindowOfCompositeControl() | |
1686 | { return (wxWindow*)m_gridWin; } | |
266e8367 VZ |
1687 | virtual void Fit(); |
1688 | ||
86033c4b VZ |
1689 | // implementation only |
1690 | void CancelMouseCapture(); | |
1691 | ||
60ff3b99 | 1692 | protected: |
266e8367 VZ |
1693 | virtual wxSize DoGetBestSize() const; |
1694 | ||
60ff3b99 VZ |
1695 | bool m_created; |
1696 | ||
1697 | wxGridWindow *m_gridWin; | |
60ff3b99 | 1698 | wxGridCornerLabelWindow *m_cornerLabelWin; |
ad805b9e VZ |
1699 | wxGridRowLabelWindow *m_rowLabelWin; |
1700 | ||
1701 | // the real type of the column window depends on m_useNativeHeader value: | |
1702 | // if it is true, its dynamic type is wxHeaderCtrl, otherwise it is | |
1703 | // wxGridColLabelWindow, use accessors below when the real type matters | |
1704 | wxWindow *m_colWindow; | |
1705 | ||
ad805b9e VZ |
1706 | wxGridColLabelWindow *GetColLabelWindow() const |
1707 | { | |
1708 | wxASSERT_MSG( !m_useNativeHeader, "no column label window" ); | |
1709 | ||
1710 | return reinterpret_cast<wxGridColLabelWindow *>(m_colWindow); | |
1711 | } | |
60ff3b99 | 1712 | |
60ff3b99 | 1713 | wxGridTableBase *m_table; |
2796cce3 | 1714 | bool m_ownTable; |
60ff3b99 | 1715 | |
60ff3b99 VZ |
1716 | int m_numRows; |
1717 | int m_numCols; | |
1718 | ||
1719 | wxGridCellCoords m_currentCellCoords; | |
1720 | ||
8a3e536c VZ |
1721 | // the corners of the block being currently selected or wxGridNoCellCoords |
1722 | wxGridCellCoords m_selectedBlockTopLeft; | |
1723 | wxGridCellCoords m_selectedBlockBottomRight; | |
1724 | ||
1725 | // when selecting blocks of cells (either from the keyboard using Shift | |
1726 | // with cursor keys, or by dragging the mouse), the selection is anchored | |
1727 | // at m_currentCellCoords which defines one of the corners of the rectangle | |
1728 | // being selected -- and this variable defines the other corner, i.e. it's | |
1729 | // either m_selectedBlockTopLeft or m_selectedBlockBottomRight depending on | |
1730 | // which of them is not m_currentCellCoords | |
1731 | // | |
1732 | // if no block selection is in process, it is set to wxGridNoCellCoords | |
1733 | wxGridCellCoords m_selectedBlockCorner; | |
1734 | ||
b5808881 | 1735 | wxGridSelection *m_selection; |
8a3e536c | 1736 | |
2796cce3 RD |
1737 | wxColour m_selectionBackground; |
1738 | wxColour m_selectionForeground; | |
60ff3b99 | 1739 | |
7c1cb261 VZ |
1740 | // NB: *never* access m_row/col arrays directly because they are created |
1741 | // on demand, *always* use accessor functions instead! | |
1742 | ||
1743 | // init the m_rowHeights/Bottoms arrays with default values | |
1744 | void InitRowHeights(); | |
1745 | ||
60ff3b99 | 1746 | int m_defaultRowHeight; |
b8d24d4e | 1747 | int m_minAcceptableRowHeight; |
60ff3b99 VZ |
1748 | wxArrayInt m_rowHeights; |
1749 | wxArrayInt m_rowBottoms; | |
1750 | ||
7c1cb261 VZ |
1751 | // init the m_colWidths/Rights arrays |
1752 | void InitColWidths(); | |
1753 | ||
60ff3b99 | 1754 | int m_defaultColWidth; |
b8d24d4e | 1755 | int m_minAcceptableColWidth; |
60ff3b99 VZ |
1756 | wxArrayInt m_colWidths; |
1757 | wxArrayInt m_colRights; | |
bf2c8b31 | 1758 | |
11393d29 VZ |
1759 | int m_sortCol; |
1760 | bool m_sortIsAscending; | |
1761 | ||
ad805b9e VZ |
1762 | bool m_useNativeHeader, |
1763 | m_nativeColumnLabels; | |
7c1cb261 VZ |
1764 | |
1765 | // get the col/row coords | |
1766 | int GetColWidth(int col) const; | |
1767 | int GetColLeft(int col) const; | |
1768 | int GetColRight(int col) const; | |
1769 | ||
1770 | // this function must be public for compatibility... | |
1771 | public: | |
1772 | int GetRowHeight(int row) const; | |
1773 | protected: | |
1774 | ||
1775 | int GetRowTop(int row) const; | |
1776 | int GetRowBottom(int row) const; | |
1777 | ||
60ff3b99 VZ |
1778 | int m_rowLabelWidth; |
1779 | int m_colLabelHeight; | |
1780 | ||
266e8367 VZ |
1781 | // the size of the margin left to the right and bottom of the cell area |
1782 | int m_extraWidth, | |
1783 | m_extraHeight; | |
1784 | ||
60ff3b99 VZ |
1785 | wxColour m_labelBackgroundColour; |
1786 | wxColour m_labelTextColour; | |
1787 | wxFont m_labelFont; | |
1788 | ||
1789 | int m_rowLabelHorizAlign; | |
1790 | int m_rowLabelVertAlign; | |
1791 | int m_colLabelHorizAlign; | |
1792 | int m_colLabelVertAlign; | |
d43851f7 | 1793 | int m_colLabelTextOrientation; |
60ff3b99 VZ |
1794 | |
1795 | bool m_defaultRowLabelValues; | |
1796 | bool m_defaultColLabelValues; | |
1797 | ||
1798 | wxColour m_gridLineColour; | |
1799 | bool m_gridLinesEnabled; | |
9f7aee01 VZ |
1800 | bool m_gridLinesClipHorz, |
1801 | m_gridLinesClipVert; | |
f6bcfd97 | 1802 | wxColour m_cellHighlightColour; |
d2520c85 RD |
1803 | int m_cellHighlightPenWidth; |
1804 | int m_cellHighlightROPenWidth; | |
1805 | ||
60ff3b99 | 1806 | |
266e8367 | 1807 | // common part of AutoSizeColumn/Row() and GetBestSize() |
ca65c044 WS |
1808 | int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true); |
1809 | int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true); | |
266e8367 | 1810 | |
af547d51 | 1811 | // common part of AutoSizeColumn/Row() |
733f486a VZ |
1812 | void AutoSizeColOrRow(int n, bool setAsMin, wxGridDirection direction); |
1813 | ||
1814 | // Calculate the minimum acceptable size for labels area | |
1815 | wxCoord CalcColOrRowLabelAreaMinSize(wxGridDirection direction); | |
af547d51 | 1816 | |
43947979 VZ |
1817 | // if a column has a minimal width, it will be the value for it in this |
1818 | // hash table | |
ba8c1601 MB |
1819 | wxLongToLongHashMap m_colMinWidths, |
1820 | m_rowMinHeights; | |
43947979 | 1821 | |
af547d51 VZ |
1822 | // get the minimal width of the given column/row |
1823 | int GetColMinimalWidth(int col) const; | |
1824 | int GetRowMinimalHeight(int col) const; | |
b99be8fb VZ |
1825 | |
1826 | // do we have some place to store attributes in? | |
ef316e23 | 1827 | bool CanHaveAttributes() const; |
60ff3b99 | 1828 | |
0a976765 VZ |
1829 | // cell attribute cache (currently we only cache 1, may be will do |
1830 | // more/better later) | |
1831 | struct CachedAttr | |
1832 | { | |
1833 | int row, col; | |
1834 | wxGridCellAttr *attr; | |
1835 | } m_attrCache; | |
1836 | ||
1837 | // invalidates the attribute cache | |
1838 | void ClearAttrCache(); | |
1839 | ||
1840 | // adds an attribute to cache | |
1841 | void CacheAttr(int row, int col, wxGridCellAttr *attr) const; | |
1842 | ||
ca65c044 | 1843 | // looks for an attr in cache, returns true if found |
0a976765 VZ |
1844 | bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; |
1845 | ||
1846 | // looks for the attr in cache, if not found asks the table and caches the | |
1847 | // result | |
2e9a6788 | 1848 | wxGridCellAttr *GetCellAttr(int row, int col) const; |
ef316e23 | 1849 | wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) const |
2c9a89e0 | 1850 | { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } |
2e9a6788 | 1851 | |
2796cce3 RD |
1852 | // the default cell attr object for cells that don't have their own |
1853 | wxGridCellAttr* m_defaultCellAttr; | |
1854 | ||
1855 | ||
60ff3b99 VZ |
1856 | bool m_inOnKeyDown; |
1857 | int m_batchCount; | |
1858 | ||
f2d76237 RD |
1859 | |
1860 | wxGridTypeRegistry* m_typeRegistry; | |
1861 | ||
e2b42eeb VZ |
1862 | enum CursorMode |
1863 | { | |
1864 | WXGRID_CURSOR_SELECT_CELL, | |
1865 | WXGRID_CURSOR_RESIZE_ROW, | |
1866 | WXGRID_CURSOR_RESIZE_COL, | |
1867 | WXGRID_CURSOR_SELECT_ROW, | |
d4175745 VZ |
1868 | WXGRID_CURSOR_SELECT_COL, |
1869 | WXGRID_CURSOR_MOVE_COL | |
60ff3b99 VZ |
1870 | }; |
1871 | ||
e2b42eeb | 1872 | // this method not only sets m_cursorMode but also sets the correct cursor |
ca65c044 | 1873 | // for the given mode and, if captureMouse is not false releases the mouse |
e2b42eeb VZ |
1874 | // if it was captured and captures it if it must be captured |
1875 | // | |
1876 | // for this to work, you should always use it and not set m_cursorMode | |
1877 | // directly! | |
1878 | void ChangeCursorMode(CursorMode mode, | |
8a3e536c | 1879 | wxWindow *win = NULL, |
ca65c044 | 1880 | bool captureMouse = true); |
e2b42eeb VZ |
1881 | |
1882 | wxWindow *m_winCapture; // the window which captured the mouse | |
8a3e536c VZ |
1883 | |
1884 | // this variable is used not for finding the correct current cursor but | |
1885 | // mainly for finding out what is going to happen if the mouse starts being | |
1886 | // dragged right now | |
1887 | // | |
1888 | // by default it is WXGRID_CURSOR_SELECT_CELL meaning that nothing else is | |
1889 | // going on, and it is set to one of RESIZE/SELECT/MOVE values while the | |
1890 | // corresponding operation will be started if the user starts dragging the | |
1891 | // mouse from the current position | |
e2b42eeb VZ |
1892 | CursorMode m_cursorMode; |
1893 | ||
8a3e536c | 1894 | |
d4175745 VZ |
1895 | //Column positions |
1896 | wxArrayInt m_colAt; | |
d4175745 | 1897 | |
6e8524b1 MB |
1898 | bool m_canDragRowSize; |
1899 | bool m_canDragColSize; | |
d4175745 | 1900 | bool m_canDragColMove; |
4cfa5de6 | 1901 | bool m_canDragGridSize; |
79dbea21 | 1902 | bool m_canDragCell; |
bec70262 VZ |
1903 | |
1904 | // the last position (horizontal or vertical depending on whether the user | |
1905 | // is resizing a column or a row) where a row or column separator line was | |
1906 | // dragged by the user or -1 of there is no drag operation in progress | |
07296f0b RD |
1907 | int m_dragLastPos; |
1908 | int m_dragRowOrCol; | |
bec70262 | 1909 | |
8a3e536c VZ |
1910 | // true if a drag operation is in progress; when this is true, |
1911 | // m_startDragPos is valid, i.e. not wxDefaultPosition | |
07296f0b | 1912 | bool m_isDragging; |
8a3e536c VZ |
1913 | |
1914 | // the position (in physical coordinates) where the user started dragging | |
1915 | // the mouse or wxDefaultPosition if mouse isn't being dragged | |
1916 | // | |
1917 | // notice that this can be != wxDefaultPosition while m_isDragging is still | |
1918 | // false because we wait until the mouse is moved some distance away before | |
1919 | // setting m_isDragging to true | |
07296f0b | 1920 | wxPoint m_startDragPos; |
60ff3b99 | 1921 | |
75ecbe45 | 1922 | bool m_waitForSlowClick; |
025562fe | 1923 | |
60ff3b99 VZ |
1924 | wxGridCellCoords m_selectionStart; |
1925 | ||
1926 | wxCursor m_rowResizeCursor; | |
1927 | wxCursor m_colResizeCursor; | |
1928 | ||
b54ba671 VZ |
1929 | bool m_editable; // applies to whole grid |
1930 | bool m_cellEditCtrlEnabled; // is in-place edit currently shown? | |
60ff3b99 | 1931 | |
608754c4 JS |
1932 | int m_scrollLineX; // X scroll increment |
1933 | int m_scrollLineY; // Y scroll increment | |
60ff3b99 | 1934 | |
ad805b9e | 1935 | void Init(); // common part of all ctors |
60ff3b99 | 1936 | void Create(); |
ad805b9e | 1937 | void CreateColumnWindow(); |
60ff3b99 | 1938 | void CalcDimensions(); |
7807d81c | 1939 | void CalcWindowSizes(); |
60ff3b99 VZ |
1940 | bool Redimension( wxGridTableMessage& ); |
1941 | ||
1942 | ||
8a3e536c VZ |
1943 | // generate the appropriate grid event and return -1 if it was vetoed, 1 if |
1944 | // it was processed (but not vetoed) and 0 if it wasn't processed | |
1945 | int SendEvent(const wxEventType evtType, | |
1946 | int row, int col, | |
27bb2c8c | 1947 | const wxMouseEvent& e); |
8a3e536c VZ |
1948 | int SendEvent(const wxEventType evtType, |
1949 | const wxGridCellCoords& coords, | |
27bb2c8c | 1950 | const wxMouseEvent& e) |
8a3e536c | 1951 | { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), e); } |
763163a8 VZ |
1952 | int SendEvent(const wxEventType evtType, |
1953 | int row, int col, | |
1954 | const wxString& s = wxString()); | |
1955 | int SendEvent(const wxEventType evtType, | |
1956 | const wxGridCellCoords& coords, | |
1957 | const wxString& s = wxString()) | |
1958 | { return SendEvent(evtType, coords.GetRow(), coords.GetCol(), s); } | |
1959 | int SendEvent(const wxEventType evtType, const wxString& s = wxString()) | |
1960 | { return SendEvent(evtType, m_currentCellCoords, s); } | |
60ff3b99 | 1961 | |
27bb2c8c | 1962 | // send wxEVT_GRID_{ROW,COL}_SIZE |
c5c1ea96 VZ |
1963 | void SendGridSizeEvent(wxEventType type, |
1964 | int row, int col, | |
1965 | const wxMouseEvent& mouseEv); | |
27bb2c8c | 1966 | |
60ff3b99 VZ |
1967 | void OnPaint( wxPaintEvent& ); |
1968 | void OnSize( wxSizeEvent& ); | |
1969 | void OnKeyDown( wxKeyEvent& ); | |
f6bcfd97 | 1970 | void OnKeyUp( wxKeyEvent& ); |
63e2147c | 1971 | void OnChar( wxKeyEvent& ); |
2796cce3 | 1972 | void OnEraseBackground( wxEraseEvent& ); |
60ff3b99 VZ |
1973 | |
1974 | ||
8a3e536c VZ |
1975 | bool SetCurrentCell( const wxGridCellCoords& coords ); |
1976 | bool SetCurrentCell( int row, int col ) | |
1977 | { return SetCurrentCell( wxGridCellCoords(row, col) ); } | |
1978 | ||
60ff3b99 | 1979 | |
8a3e536c VZ |
1980 | // this function is called to extend the block being currently selected |
1981 | // from mouse and keyboard event handlers | |
1982 | void UpdateBlockBeingSelected(int topRow, int leftCol, | |
1983 | int bottomRow, int rightCol); | |
c9097836 | 1984 | |
8a3e536c VZ |
1985 | void UpdateBlockBeingSelected(const wxGridCellCoords& topLeft, |
1986 | const wxGridCellCoords& bottomRight) | |
1987 | { UpdateBlockBeingSelected(topLeft.GetRow(), topLeft.GetCol(), | |
1988 | bottomRight.GetRow(), bottomRight.GetCol()); } | |
60ff3b99 VZ |
1989 | |
1990 | // ------ functions to get/send data (see also public functions) | |
1991 | // | |
1992 | bool GetModelValues(); | |
1993 | bool SetModelValues(); | |
1994 | ||
b5dbe15d | 1995 | friend class WXDLLIMPEXP_FWD_ADV wxGridSelection; |
bec70262 VZ |
1996 | friend class wxGridRowOperations; |
1997 | friend class wxGridColumnOperations; | |
60ff3b99 | 1998 | |
8a3e536c VZ |
1999 | // they call our private Process{{Corner,Col,Row}Label,GridCell}MouseEvent() |
2000 | friend class wxGridCornerLabelWindow; | |
2001 | friend class wxGridColLabelWindow; | |
2002 | friend class wxGridRowLabelWindow; | |
2003 | friend class wxGridWindow; | |
2004 | ||
ad805b9e VZ |
2005 | friend class wxGridHeaderCtrl; |
2006 | ||
69367c56 VZ |
2007 | private: |
2008 | // implement wxScrolledWindow method to return m_gridWin size | |
2009 | virtual wxSize GetSizeAvailableForScrollTarget(const wxSize& size); | |
2010 | ||
9f7aee01 VZ |
2011 | // redraw the grid lines, should be called after changing their attributes |
2012 | void RedrawGridLines(); | |
2013 | ||
2014 | // common part of Clip{Horz,Vert}GridLines | |
2015 | void DoClipGridLines(bool& var, bool clip); | |
2016 | ||
11393d29 VZ |
2017 | // update the sorting indicator shown in the specified column (whose index |
2018 | // must be valid) | |
2019 | // | |
2020 | // this will use GetSortingColumn() and IsSortOrderAscending() to determine | |
2021 | // the sorting indicator to effectively show | |
2022 | void UpdateColumnSortingIndicator(int col); | |
2023 | ||
4797b014 VZ |
2024 | // update the grid after changing the columns order (common part of |
2025 | // SetColPos() and ResetColPos()) | |
2026 | void RefreshAfterColPosChange(); | |
009c7216 | 2027 | |
9f7aee01 | 2028 | |
cd4f6f5f VZ |
2029 | // return the position (not index) of the column at the given logical pixel |
2030 | // position | |
2031 | // | |
2032 | // this always returns a valid position, even if the coordinate is out of | |
2033 | // bounds (in which case first/last column is returned) | |
2034 | int XToPos(int x) const; | |
2035 | ||
2036 | ||
8a3e536c VZ |
2037 | // event handlers and their helpers |
2038 | // -------------------------------- | |
2039 | ||
2040 | // process mouse drag event in WXGRID_CURSOR_SELECT_CELL mode | |
2041 | void DoGridCellDrag(wxMouseEvent& event, | |
2042 | const wxGridCellCoords& coords, | |
2043 | bool isFirstDrag); | |
2044 | ||
2045 | // process row/column resizing drag event | |
2046 | void DoGridLineDrag(wxMouseEvent& event, const wxGridOperations& oper); | |
2047 | ||
2048 | // process mouse drag event in the grid window | |
2049 | void DoGridDragEvent(wxMouseEvent& event, const wxGridCellCoords& coords); | |
2050 | ||
2051 | // process different clicks on grid cells | |
2052 | void DoGridCellLeftDown(wxMouseEvent& event, | |
2053 | const wxGridCellCoords& coords, | |
2054 | const wxPoint& pos); | |
2055 | void DoGridCellLeftDClick(wxMouseEvent& event, | |
2056 | const wxGridCellCoords& coords, | |
2057 | const wxPoint& pos); | |
2058 | void DoGridCellLeftUp(wxMouseEvent& event, const wxGridCellCoords& coords); | |
2059 | ||
2060 | // process movement (but not dragging) event in the grid cell area | |
2061 | void DoGridMouseMoveEvent(wxMouseEvent& event, | |
2062 | const wxGridCellCoords& coords, | |
2063 | const wxPoint& pos); | |
2064 | ||
2065 | // process mouse events in the grid window | |
2066 | void ProcessGridCellMouseEvent(wxMouseEvent& event); | |
2067 | ||
2068 | // process mouse events in the row/column labels/corner windows | |
2069 | void ProcessRowLabelMouseEvent(wxMouseEvent& event); | |
2070 | void ProcessColLabelMouseEvent(wxMouseEvent& event); | |
2071 | void ProcessCornerLabelMouseEvent(wxMouseEvent& event); | |
2072 | ||
11393d29 VZ |
2073 | void DoColHeaderClick(int col); |
2074 | ||
ad805b9e VZ |
2075 | void DoStartResizeCol(int col); |
2076 | void DoUpdateResizeCol(int x); | |
2077 | void DoUpdateResizeColWidth(int w); | |
cd68daf5 | 2078 | void DoStartMoveCol(int col); |
ad805b9e | 2079 | |
27bb2c8c VZ |
2080 | void DoEndDragResizeRow(const wxMouseEvent& event); |
2081 | void DoEndDragResizeCol(const wxMouseEvent& event); | |
cd68daf5 | 2082 | void DoEndMoveCol(int pos); |
8a3e536c | 2083 | |
bec70262 VZ |
2084 | |
2085 | // common implementations of methods defined for both rows and columns | |
2086 | void DeselectLine(int line, const wxGridOperations& oper); | |
27bb2c8c | 2087 | bool DoEndDragResizeLine(const wxGridOperations& oper); |
cd4f6f5f VZ |
2088 | int PosToLinePos(int pos, bool clipToMinMax, |
2089 | const wxGridOperations& oper) const; | |
2090 | int PosToLine(int pos, bool clipToMinMax, | |
2091 | const wxGridOperations& oper) const; | |
10a4531d VZ |
2092 | int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const; |
2093 | ||
2094 | bool DoMoveCursor(bool expandSelection, | |
2095 | const wxGridDirectionOperations& diroper); | |
2096 | bool DoMoveCursorByPage(const wxGridDirectionOperations& diroper); | |
2097 | bool DoMoveCursorByBlock(bool expandSelection, | |
2098 | const wxGridDirectionOperations& diroper); | |
2099 | void AdvanceToNextNonEmpty(wxGridCellCoords& coords, | |
2100 | const wxGridDirectionOperations& diroper); | |
2101 | ||
2102 | // common part of {Insert,Delete}{Rows,Cols} | |
2103 | bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t), | |
2104 | int pos, int num, bool updateLabels); | |
2105 | // Append{Rows,Cols} is a bit different because of one less parameter | |
2106 | bool DoAppendLines(bool (wxGridTableBase::*funcAppend)(size_t), | |
2107 | int num, bool updateLabels); | |
bec70262 | 2108 | |
82edfbe7 | 2109 | // common part of Set{Col,Row}Sizes |
574e1c5a VZ |
2110 | void DoSetSizes(const wxGridSizesInfo& sizeInfo, |
2111 | const wxGridOperations& oper); | |
2112 | ||
82edfbe7 VZ |
2113 | // common part of Disable{Row,Col}Resize and CanDrag{Row,Col}Size |
2114 | void DoDisableLineResize(int line, wxGridFixedIndicesSet *& setFixed); | |
2115 | bool DoCanResizeLine(int line, const wxGridFixedIndicesSet *setFixed) const; | |
2116 | ||
2117 | ||
2118 | ||
2119 | // these sets contain the indices of fixed, i.e. non-resizable | |
2120 | // interactively, grid rows or columns and are NULL if there are no fixed | |
2121 | // elements (which is the default) | |
2122 | wxGridFixedIndicesSet *m_setFixedRows, | |
2123 | *m_setFixedCols; | |
2124 | ||
2d66e025 | 2125 | DECLARE_DYNAMIC_CLASS( wxGrid ) |
f85afd4e | 2126 | DECLARE_EVENT_TABLE() |
c0c133e1 | 2127 | wxDECLARE_NO_COPY_CLASS(wxGrid); |
f85afd4e MB |
2128 | }; |
2129 | ||
b62f94ff VZ |
2130 | // ---------------------------------------------------------------------------- |
2131 | // wxGridUpdateLocker prevents updates to a grid during its lifetime | |
2132 | // ---------------------------------------------------------------------------- | |
2133 | ||
2134 | class WXDLLIMPEXP_ADV wxGridUpdateLocker | |
2135 | { | |
2136 | public: | |
2137 | // if the pointer is NULL, Create() can be called later | |
2138 | wxGridUpdateLocker(wxGrid *grid = NULL) | |
2139 | { | |
2140 | Init(grid); | |
2141 | } | |
2142 | ||
2143 | // can be called if ctor was used with a NULL pointer, must not be called | |
2144 | // more than once | |
2145 | void Create(wxGrid *grid) | |
2146 | { | |
2147 | wxASSERT_MSG( !m_grid, _T("shouldn't be called more than once") ); | |
2148 | ||
2149 | Init(grid); | |
2150 | } | |
2151 | ||
2152 | ~wxGridUpdateLocker() | |
2153 | { | |
2154 | if ( m_grid ) | |
2155 | m_grid->EndBatch(); | |
2156 | } | |
2157 | ||
2158 | private: | |
2159 | void Init(wxGrid *grid) | |
2160 | { | |
2161 | m_grid = grid; | |
2162 | if ( m_grid ) | |
2163 | m_grid->BeginBatch(); | |
2164 | } | |
2165 | ||
2166 | wxGrid *m_grid; | |
2167 | ||
c0c133e1 | 2168 | wxDECLARE_NO_COPY_CLASS(wxGridUpdateLocker); |
b62f94ff VZ |
2169 | }; |
2170 | ||
43947979 VZ |
2171 | // ---------------------------------------------------------------------------- |
2172 | // Grid event class and event types | |
2173 | // ---------------------------------------------------------------------------- | |
f85afd4e | 2174 | |
8b5f6d9d VZ |
2175 | class WXDLLIMPEXP_ADV wxGridEvent : public wxNotifyEvent, |
2176 | public wxKeyboardState | |
f85afd4e | 2177 | { |
60ff3b99 | 2178 | public: |
f85afd4e | 2179 | wxGridEvent() |
8b5f6d9d VZ |
2180 | : wxNotifyEvent() |
2181 | { | |
2182 | Init(-1, -1, -1, -1, false); | |
2183 | } | |
f85afd4e | 2184 | |
8b5f6d9d VZ |
2185 | wxGridEvent(int id, |
2186 | wxEventType type, | |
2187 | wxObject* obj, | |
2188 | int row = -1, int col = -1, | |
2189 | int x = -1, int y = -1, | |
2190 | bool sel = true, | |
2191 | const wxKeyboardState& kbd = wxKeyboardState()) | |
2192 | : wxNotifyEvent(type, id), | |
2193 | wxKeyboardState(kbd) | |
2194 | { | |
2195 | Init(row, col, x, y, sel); | |
2196 | SetEventObject(obj); | |
2197 | } | |
2198 | ||
23318a53 FM |
2199 | // explicitly specifying inline allows gcc < 3.4 to |
2200 | // handle the deprecation attribute even in the constructor. | |
a05e6efe | 2201 | wxDEPRECATED_CONSTRUCTOR( |
8b5f6d9d VZ |
2202 | wxGridEvent(int id, |
2203 | wxEventType type, | |
2204 | wxObject* obj, | |
2205 | int row, int col, | |
2206 | int x, int y, | |
2207 | bool sel, | |
2208 | bool control, | |
2209 | bool shift = false, bool alt = false, bool meta = false)); | |
f85afd4e MB |
2210 | |
2211 | virtual int GetRow() { return m_row; } | |
2212 | virtual int GetCol() { return m_col; } | |
2213 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
5c8fc7c1 | 2214 | bool Selecting() { return m_selecting; } |
2d66e025 | 2215 | |
e1f8ec29 RD |
2216 | virtual wxEvent *Clone() const { return new wxGridEvent(*this); } |
2217 | ||
60ff3b99 VZ |
2218 | protected: |
2219 | int m_row; | |
2220 | int m_col; | |
f85afd4e MB |
2221 | int m_x; |
2222 | int m_y; | |
5c8fc7c1 | 2223 | bool m_selecting; |
8b5f6d9d VZ |
2224 | |
2225 | private: | |
2226 | void Init(int row, int col, int x, int y, bool sel) | |
2227 | { | |
2228 | m_row = row; | |
2229 | m_col = col; | |
2230 | m_x = x; | |
2231 | m_y = y; | |
2232 | m_selecting = sel; | |
2233 | } | |
60ff3b99 | 2234 | |
e1f8ec29 | 2235 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEvent) |
60ff3b99 VZ |
2236 | }; |
2237 | ||
8b5f6d9d VZ |
2238 | class WXDLLIMPEXP_ADV wxGridSizeEvent : public wxNotifyEvent, |
2239 | public wxKeyboardState | |
60ff3b99 VZ |
2240 | { |
2241 | public: | |
f85afd4e | 2242 | wxGridSizeEvent() |
8b5f6d9d VZ |
2243 | : wxNotifyEvent() |
2244 | { | |
2245 | Init(-1, -1, -1); | |
2246 | } | |
2247 | ||
2248 | wxGridSizeEvent(int id, | |
2249 | wxEventType type, | |
2250 | wxObject* obj, | |
2251 | int rowOrCol = -1, | |
2252 | int x = -1, int y = -1, | |
2253 | const wxKeyboardState& kbd = wxKeyboardState()) | |
2254 | : wxNotifyEvent(type, id), | |
2255 | wxKeyboardState(kbd) | |
2256 | { | |
2257 | Init(rowOrCol, x, y); | |
f85afd4e | 2258 | |
8b5f6d9d VZ |
2259 | SetEventObject(obj); |
2260 | } | |
2261 | ||
a05e6efe | 2262 | wxDEPRECATED_CONSTRUCTOR( |
8b5f6d9d VZ |
2263 | wxGridSizeEvent(int id, |
2264 | wxEventType type, | |
2265 | wxObject* obj, | |
2266 | int rowOrCol, | |
2267 | int x, int y, | |
2268 | bool control, | |
2269 | bool shift = false, | |
2270 | bool alt = false, | |
2271 | bool meta = false) ); | |
f85afd4e MB |
2272 | |
2273 | int GetRowOrCol() { return m_rowOrCol; } | |
2274 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
733f486a | 2275 | |
e1f8ec29 | 2276 | virtual wxEvent *Clone() const { return new wxGridSizeEvent(*this); } |
2d66e025 | 2277 | |
60ff3b99 VZ |
2278 | protected: |
2279 | int m_rowOrCol; | |
2280 | int m_x; | |
2281 | int m_y; | |
8b5f6d9d VZ |
2282 | |
2283 | private: | |
2284 | void Init(int rowOrCol, int x, int y) | |
2285 | { | |
2286 | m_rowOrCol = rowOrCol; | |
2287 | m_x = x; | |
2288 | m_y = y; | |
2289 | } | |
60ff3b99 | 2290 | |
e1f8ec29 | 2291 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridSizeEvent) |
f85afd4e MB |
2292 | }; |
2293 | ||
2294 | ||
8b5f6d9d VZ |
2295 | class WXDLLIMPEXP_ADV wxGridRangeSelectEvent : public wxNotifyEvent, |
2296 | public wxKeyboardState | |
f85afd4e | 2297 | { |
60ff3b99 | 2298 | public: |
f85afd4e | 2299 | wxGridRangeSelectEvent() |
60ff3b99 | 2300 | : wxNotifyEvent() |
8b5f6d9d VZ |
2301 | { |
2302 | Init(wxGridNoCellCoords, wxGridNoCellCoords, false); | |
2303 | } | |
f85afd4e | 2304 | |
8b5f6d9d VZ |
2305 | wxGridRangeSelectEvent(int id, |
2306 | wxEventType type, | |
2307 | wxObject* obj, | |
60ff3b99 VZ |
2308 | const wxGridCellCoords& topLeft, |
2309 | const wxGridCellCoords& bottomRight, | |
ca65c044 | 2310 | bool sel = true, |
8b5f6d9d VZ |
2311 | const wxKeyboardState& kbd = wxKeyboardState()) |
2312 | : wxNotifyEvent(type, id), | |
2313 | wxKeyboardState(kbd) | |
2314 | { | |
2315 | Init(topLeft, bottomRight, sel); | |
2316 | ||
2317 | SetEventObject(obj); | |
2318 | } | |
2319 | ||
a05e6efe | 2320 | wxDEPRECATED_CONSTRUCTOR( |
8b5f6d9d VZ |
2321 | wxGridRangeSelectEvent(int id, |
2322 | wxEventType type, | |
2323 | wxObject* obj, | |
2324 | const wxGridCellCoords& topLeft, | |
2325 | const wxGridCellCoords& bottomRight, | |
2326 | bool sel, | |
2327 | bool control, | |
2328 | bool shift = false, | |
2329 | bool alt = false, | |
2330 | bool meta = false) ); | |
f85afd4e MB |
2331 | |
2332 | wxGridCellCoords GetTopLeftCoords() { return m_topLeft; } | |
2333 | wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; } | |
2334 | int GetTopRow() { return m_topLeft.GetRow(); } | |
2335 | int GetBottomRow() { return m_bottomRight.GetRow(); } | |
2336 | int GetLeftCol() { return m_topLeft.GetCol(); } | |
2337 | int GetRightCol() { return m_bottomRight.GetCol(); } | |
5c8fc7c1 | 2338 | bool Selecting() { return m_selecting; } |
733f486a | 2339 | |
e1f8ec29 | 2340 | virtual wxEvent *Clone() const { return new wxGridRangeSelectEvent(*this); } |
2d66e025 | 2341 | |
60ff3b99 | 2342 | protected: |
8b5f6d9d VZ |
2343 | void Init(const wxGridCellCoords& topLeft, |
2344 | const wxGridCellCoords& bottomRight, | |
2345 | bool selecting) | |
2346 | { | |
2347 | m_topLeft = topLeft; | |
2348 | m_bottomRight = bottomRight; | |
2349 | m_selecting = selecting; | |
2350 | } | |
2351 | ||
60ff3b99 VZ |
2352 | wxGridCellCoords m_topLeft; |
2353 | wxGridCellCoords m_bottomRight; | |
5c8fc7c1 | 2354 | bool m_selecting; |
60ff3b99 | 2355 | |
e1f8ec29 | 2356 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridRangeSelectEvent) |
f85afd4e MB |
2357 | }; |
2358 | ||
bf7945ce | 2359 | |
8b5f6d9d VZ |
2360 | class WXDLLIMPEXP_ADV wxGridEditorCreatedEvent : public wxCommandEvent |
2361 | { | |
bf7945ce RD |
2362 | public: |
2363 | wxGridEditorCreatedEvent() | |
2364 | : wxCommandEvent() | |
2365 | { | |
2366 | m_row = 0; | |
2367 | m_col = 0; | |
2368 | m_ctrl = NULL; | |
2369 | } | |
2370 | ||
2371 | wxGridEditorCreatedEvent(int id, wxEventType type, wxObject* obj, | |
2372 | int row, int col, wxControl* ctrl); | |
2373 | ||
2374 | int GetRow() { return m_row; } | |
2375 | int GetCol() { return m_col; } | |
2376 | wxControl* GetControl() { return m_ctrl; } | |
2377 | void SetRow(int row) { m_row = row; } | |
2378 | void SetCol(int col) { m_col = col; } | |
2379 | void SetControl(wxControl* ctrl) { m_ctrl = ctrl; } | |
733f486a | 2380 | |
e1f8ec29 | 2381 | virtual wxEvent *Clone() const { return new wxGridEditorCreatedEvent(*this); } |
bf7945ce RD |
2382 | |
2383 | private: | |
2384 | int m_row; | |
2385 | int m_col; | |
2386 | wxControl* m_ctrl; | |
2387 | ||
e1f8ec29 | 2388 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxGridEditorCreatedEvent) |
bf7945ce RD |
2389 | }; |
2390 | ||
2391 | ||
9b11752c VZ |
2392 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEvent ); |
2393 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEvent ); | |
2394 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEvent ); | |
2395 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_RIGHT_DCLICK, wxGridEvent ); | |
2396 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEvent ); | |
2397 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEvent ); | |
2398 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_LEFT_DCLICK, wxGridEvent ); | |
2399 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_LABEL_RIGHT_DCLICK, wxGridEvent ); | |
2400 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_ROW_SIZE, wxGridSizeEvent ); | |
2401 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SIZE, wxGridSizeEvent ); | |
2402 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_RANGE_SELECT, wxGridRangeSelectEvent ); | |
2403 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGING, wxGridEvent ); | |
2404 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_CHANGED, wxGridEvent ); | |
2405 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_SELECT_CELL, wxGridEvent ); | |
2406 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_SHOWN, wxGridEvent ); | |
2407 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_HIDDEN, wxGridEvent ); | |
2408 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_EDITOR_CREATED, wxGridEditorCreatedEvent ); | |
2409 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_CELL_BEGIN_DRAG, wxGridEvent ); | |
2410 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_MOVE, wxGridEvent ); | |
2411 | wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_ADV, wxEVT_GRID_COL_SORT, wxGridEvent ); | |
749692cc | 2412 | |
f85afd4e MB |
2413 | typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); |
2414 | typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); | |
2415 | typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); | |
bf7945ce | 2416 | typedef void (wxEvtHandler::*wxGridEditorCreatedEventFunction)(wxGridEditorCreatedEvent&); |
f85afd4e | 2417 | |
7fa03f04 | 2418 | #define wxGridEventHandler(func) \ |
3c778901 | 2419 | wxEVENT_HANDLER_CAST(wxGridEventFunction, func) |
7fa03f04 VZ |
2420 | |
2421 | #define wxGridSizeEventHandler(func) \ | |
3c778901 | 2422 | wxEVENT_HANDLER_CAST(wxGridSizeEventFunction, func) |
7fa03f04 VZ |
2423 | |
2424 | #define wxGridRangeSelectEventHandler(func) \ | |
3c778901 | 2425 | wxEVENT_HANDLER_CAST(wxGridRangeSelectEventFunction, func) |
7fa03f04 VZ |
2426 | |
2427 | #define wxGridEditorCreatedEventHandler(func) \ | |
3c778901 | 2428 | wxEVENT_HANDLER_CAST(wxGridEditorCreatedEventFunction, func) |
7fa03f04 VZ |
2429 | |
2430 | #define wx__DECLARE_GRIDEVT(evt, id, fn) \ | |
2431 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEventHandler(fn)) | |
2432 | ||
2433 | #define wx__DECLARE_GRIDSIZEEVT(evt, id, fn) \ | |
2434 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridSizeEventHandler(fn)) | |
2435 | ||
2436 | #define wx__DECLARE_GRIDRANGESELEVT(evt, id, fn) \ | |
2437 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridRangeSelectEventHandler(fn)) | |
2438 | ||
2439 | #define wx__DECLARE_GRIDEDITOREVT(evt, id, fn) \ | |
2440 | wx__DECLARE_EVT1(wxEVT_GRID_ ## evt, id, wxGridEditorCreatedEventHandler(fn)) | |
2441 | ||
2442 | #define EVT_GRID_CMD_CELL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_CLICK, id, fn) | |
2443 | #define EVT_GRID_CMD_CELL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_CLICK, id, fn) | |
2444 | #define EVT_GRID_CMD_CELL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_LEFT_DCLICK, id, fn) | |
2445 | #define EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(CELL_RIGHT_DCLICK, id, fn) | |
2446 | #define EVT_GRID_CMD_LABEL_LEFT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_CLICK, id, fn) | |
2447 | #define EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_CLICK, id, fn) | |
2448 | #define EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_LEFT_DCLICK, id, fn) | |
2449 | #define EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, fn) wx__DECLARE_GRIDEVT(LABEL_RIGHT_DCLICK, id, fn) | |
2450 | #define EVT_GRID_CMD_ROW_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(ROW_SIZE, id, fn) | |
2451 | #define EVT_GRID_CMD_COL_SIZE(id, fn) wx__DECLARE_GRIDSIZEEVT(COL_SIZE, id, fn) | |
5d984f5d | 2452 | #define EVT_GRID_CMD_COL_MOVE(id, fn) wx__DECLARE_GRIDEVT(COL_MOVE, id, fn) |
11393d29 | 2453 | #define EVT_GRID_CMD_COL_SORT(id, fn) wx__DECLARE_GRIDEVT(COL_SORT, id, fn) |
7fa03f04 | 2454 | #define EVT_GRID_CMD_RANGE_SELECT(id, fn) wx__DECLARE_GRIDRANGESELEVT(RANGE_SELECT, id, fn) |
763163a8 VZ |
2455 | #define EVT_GRID_CMD_CELL_CHANGING(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGING, id, fn) |
2456 | #define EVT_GRID_CMD_CELL_CHANGED(id, fn) wx__DECLARE_GRIDEVT(CELL_CHANGED, id, fn) | |
7fa03f04 VZ |
2457 | #define EVT_GRID_CMD_SELECT_CELL(id, fn) wx__DECLARE_GRIDEVT(SELECT_CELL, id, fn) |
2458 | #define EVT_GRID_CMD_EDITOR_SHOWN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_SHOWN, id, fn) | |
2459 | #define EVT_GRID_CMD_EDITOR_HIDDEN(id, fn) wx__DECLARE_GRIDEVT(EDITOR_HIDDEN, id, fn) | |
2460 | #define EVT_GRID_CMD_EDITOR_CREATED(id, fn) wx__DECLARE_GRIDEDITOREVT(EDITOR_CREATED, id, fn) | |
2461 | #define EVT_GRID_CMD_CELL_BEGIN_DRAG(id, fn) wx__DECLARE_GRIDEVT(CELL_BEGIN_DRAG, id, fn) | |
2462 | ||
2463 | // same as above but for any id (exists mainly for backwards compatibility but | |
2464 | // then it's also true that you rarely have multiple grid in the same window) | |
2465 | #define EVT_GRID_CELL_LEFT_CLICK(fn) EVT_GRID_CMD_CELL_LEFT_CLICK(wxID_ANY, fn) | |
2466 | #define EVT_GRID_CELL_RIGHT_CLICK(fn) EVT_GRID_CMD_CELL_RIGHT_CLICK(wxID_ANY, fn) | |
2467 | #define EVT_GRID_CELL_LEFT_DCLICK(fn) EVT_GRID_CMD_CELL_LEFT_DCLICK(wxID_ANY, fn) | |
2468 | #define EVT_GRID_CELL_RIGHT_DCLICK(fn) EVT_GRID_CMD_CELL_RIGHT_DCLICK(wxID_ANY, fn) | |
2469 | #define EVT_GRID_LABEL_LEFT_CLICK(fn) EVT_GRID_CMD_LABEL_LEFT_CLICK(wxID_ANY, fn) | |
2470 | #define EVT_GRID_LABEL_RIGHT_CLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_CLICK(wxID_ANY, fn) | |
2471 | #define EVT_GRID_LABEL_LEFT_DCLICK(fn) EVT_GRID_CMD_LABEL_LEFT_DCLICK(wxID_ANY, fn) | |
2472 | #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) EVT_GRID_CMD_LABEL_RIGHT_DCLICK(wxID_ANY, fn) | |
2473 | #define EVT_GRID_ROW_SIZE(fn) EVT_GRID_CMD_ROW_SIZE(wxID_ANY, fn) | |
2474 | #define EVT_GRID_COL_SIZE(fn) EVT_GRID_CMD_COL_SIZE(wxID_ANY, fn) | |
4d5a1b0a | 2475 | #define EVT_GRID_COL_MOVE(fn) EVT_GRID_CMD_COL_MOVE(wxID_ANY, fn) |
11393d29 | 2476 | #define EVT_GRID_COL_SORT(fn) EVT_GRID_CMD_COL_SORT(wxID_ANY, fn) |
7fa03f04 | 2477 | #define EVT_GRID_RANGE_SELECT(fn) EVT_GRID_CMD_RANGE_SELECT(wxID_ANY, fn) |
763163a8 VZ |
2478 | #define EVT_GRID_CELL_CHANGING(fn) EVT_GRID_CMD_CELL_CHANGING(wxID_ANY, fn) |
2479 | #define EVT_GRID_CELL_CHANGED(fn) EVT_GRID_CMD_CELL_CHANGED(wxID_ANY, fn) | |
7fa03f04 VZ |
2480 | #define EVT_GRID_SELECT_CELL(fn) EVT_GRID_CMD_SELECT_CELL(wxID_ANY, fn) |
2481 | #define EVT_GRID_EDITOR_SHOWN(fn) EVT_GRID_CMD_EDITOR_SHOWN(wxID_ANY, fn) | |
2482 | #define EVT_GRID_EDITOR_HIDDEN(fn) EVT_GRID_CMD_EDITOR_HIDDEN(wxID_ANY, fn) | |
2483 | #define EVT_GRID_EDITOR_CREATED(fn) EVT_GRID_CMD_EDITOR_CREATED(wxID_ANY, fn) | |
2484 | #define EVT_GRID_CELL_BEGIN_DRAG(fn) EVT_GRID_CMD_CELL_BEGIN_DRAG(wxID_ANY, fn) | |
f85afd4e | 2485 | |
763163a8 VZ |
2486 | // we used to have a single wxEVT_GRID_CELL_CHANGE event but it was split into |
2487 | // wxEVT_GRID_CELL_CHANGING and CHANGED ones in wx 2.9.0, however the CHANGED | |
2488 | // is basically the same as the old CHANGE event so we keep the name for | |
2489 | // compatibility | |
2490 | #if WXWIN_COMPATIBILITY_2_8 | |
2491 | #define wxEVT_GRID_CELL_CHANGE wxEVT_GRID_CELL_CHANGED | |
2492 | ||
2493 | #define EVT_GRID_CMD_CELL_CHANGE EVT_GRID_CMD_CELL_CHANGED | |
2494 | #define EVT_GRID_CELL_CHANGE EVT_GRID_CELL_CHANGED | |
2495 | #endif // WXWIN_COMPATIBILITY_2_8 | |
2496 | ||
f85afd4e MB |
2497 | #if 0 // TODO: implement these ? others ? |
2498 | ||
77d4384e RR |
2499 | extern const int wxEVT_GRID_CREATE_CELL; |
2500 | extern const int wxEVT_GRID_CHANGE_LABELS; | |
2501 | extern const int wxEVT_GRID_CHANGE_SEL_LABEL; | |
f85afd4e | 2502 | |
ca65c044 WS |
2503 | #define EVT_GRID_CREATE_CELL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CREATE_CELL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), |
2504 | #define EVT_GRID_CHANGE_LABELS(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_LABELS, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
2505 | #define EVT_GRID_CHANGE_SEL_LABEL(fn) DECLARE_EVENT_TABLE_ENTRY( wxEVT_GRID_CHANGE_SEL_LABEL, wxID_ANY, wxID_ANY, (wxObjectEventFunction) (wxEventFunction) wxStaticCastEvent( wxGridEventFunction, &fn ), NULL ), | |
f85afd4e MB |
2506 | |
2507 | #endif | |
2508 | ||
df9fac6d PC |
2509 | #endif // wxUSE_GRID |
2510 | #endif // _WX_GENERIC_GRID_H_ |