]>
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) | |
5 | // Modified by: | |
6 | // Created: 1/08/1999 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Michael Bedward | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
f85afd4e MB |
12 | #include "wx/defs.h" |
13 | ||
14 | #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) | |
15 | #include "gridg.h" | |
16 | #else | |
17 | ||
18 | #ifndef __WXGRID_H__ | |
19 | #define __WXGRID_H__ | |
20 | ||
21 | #ifdef __GNUG__ | |
22 | #pragma interface "grid.h" | |
23 | #endif | |
24 | ||
43947979 | 25 | #include "wx/hash.h" |
f85afd4e | 26 | #include "wx/panel.h" |
2d66e025 | 27 | #include "wx/scrolwin.h" |
f85afd4e MB |
28 | #include "wx/string.h" |
29 | #include "wx/scrolbar.h" | |
30 | #include "wx/event.h" | |
f85afd4e MB |
31 | #include "wx/combobox.h" |
32 | #include "wx/dynarray.h" | |
025562fe | 33 | #include "wx/timer.h" |
f85afd4e MB |
34 | |
35 | // Default parameters for wxGrid | |
36 | // | |
37 | #define WXGRID_DEFAULT_NUMBER_ROWS 10 | |
38 | #define WXGRID_DEFAULT_NUMBER_COLS 10 | |
39 | #ifdef __WXMSW__ | |
40 | #define WXGRID_DEFAULT_ROW_HEIGHT 25 | |
41 | #else | |
42 | #define WXGRID_DEFAULT_ROW_HEIGHT 30 | |
43 | #endif // __WXMSW__ | |
44 | #define WXGRID_DEFAULT_COL_WIDTH 80 | |
45 | #define WXGRID_DEFAULT_COL_LABEL_HEIGHT 32 | |
46 | #define WXGRID_DEFAULT_ROW_LABEL_WIDTH 82 | |
47 | #define WXGRID_LABEL_EDGE_ZONE 5 | |
48 | #define WXGRID_MIN_ROW_HEIGHT 15 | |
49 | #define WXGRID_MIN_COL_WIDTH 15 | |
50 | #define WXGRID_DEFAULT_SCROLLBAR_WIDTH 16 | |
f85afd4e | 51 | |
b99be8fb VZ |
52 | // ---------------------------------------------------------------------------- |
53 | // forward declarations | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
ab79958a VZ |
56 | class WXDLLEXPORT wxGrid; |
57 | class WXDLLEXPORT wxGridCellAttr; | |
b99be8fb | 58 | class WXDLLEXPORT wxGridCellAttrProviderData; |
b99be8fb VZ |
59 | class WXDLLEXPORT wxGridColLabelWindow; |
60 | class WXDLLEXPORT wxGridCornerLabelWindow; | |
ab79958a VZ |
61 | class WXDLLEXPORT wxGridRowLabelWindow; |
62 | class WXDLLEXPORT wxGridTableBase; | |
b99be8fb | 63 | class WXDLLEXPORT wxGridWindow; |
f2d76237 | 64 | class WXDLLEXPORT wxGridTypeRegistry; |
ab79958a | 65 | |
508011ce VZ |
66 | class WXDLLEXPORT wxCheckBox; |
67 | class WXDLLEXPORT wxTextCtrl; | |
68 | ||
ab79958a VZ |
69 | // ---------------------------------------------------------------------------- |
70 | // wxGridCellRenderer: this class is responsible for actually drawing the cell | |
71 | // in the grid. You may pass it to the wxGridCellAttr (below) to change the | |
72 | // format of one given cell or to wxGrid::SetDefaultRenderer() to change the | |
73 | // view of all cells. This is an ABC, you will normally use one of the | |
74 | // predefined derived classes or derive oyur own class from it. | |
75 | // ---------------------------------------------------------------------------- | |
76 | ||
77 | class WXDLLEXPORT wxGridCellRenderer | |
78 | { | |
79 | public: | |
80 | // draw the given cell on the provided DC inside the given rectangle | |
81 | // using the style specified by the attribute and the default or selected | |
82 | // state corresponding to the isSelected value. | |
83 | // | |
84 | // this pure virtual function has a default implementation which will | |
85 | // prepare the DC using the given attribute: it will draw the rectangle | |
86 | // with the bg colour from attr and set the text colour and font | |
87 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 88 | wxGridCellAttr& attr, |
ab79958a VZ |
89 | wxDC& dc, |
90 | const wxRect& rect, | |
91 | int row, int col, | |
92 | bool isSelected) = 0; | |
93 | }; | |
94 | ||
95 | // the default renderer for the cells containing string data | |
96 | class WXDLLEXPORT wxGridCellStringRenderer : public wxGridCellRenderer | |
97 | { | |
98 | public: | |
99 | // draw the string | |
100 | virtual void Draw(wxGrid& grid, | |
2796cce3 | 101 | wxGridCellAttr& attr, |
ab79958a VZ |
102 | wxDC& dc, |
103 | const wxRect& rect, | |
104 | int row, int col, | |
105 | bool isSelected); | |
106 | }; | |
f85afd4e | 107 | |
508011ce VZ |
108 | // renderer for boolean fields |
109 | class WXDLLEXPORT wxGridCellBoolRenderer : public wxGridCellRenderer | |
110 | { | |
111 | public: | |
112 | ||
113 | // draw a check mark or nothing | |
114 | virtual void Draw(wxGrid& grid, | |
115 | wxGridCellAttr& attr, | |
116 | wxDC& dc, | |
117 | const wxRect& rect, | |
118 | int row, int col, | |
119 | bool isSelected); | |
120 | }; | |
2796cce3 RD |
121 | |
122 | // ---------------------------------------------------------------------------- | |
123 | // wxGridCellEditor: This class is responsible for providing and manipulating | |
124 | // the in-place edit controls for the grid. Instances of wxGridCellEditor | |
125 | // (actually, instances of derived classes since it is an ABC) can be | |
126 | // associated with the cell attributes for individual cells, rows, columns, or | |
127 | // even for the entire grid. | |
128 | // ---------------------------------------------------------------------------- | |
129 | ||
130 | class WXDLLEXPORT wxGridCellEditor | |
131 | { | |
132 | public: | |
133 | wxGridCellEditor(); | |
134 | virtual ~wxGridCellEditor(); | |
135 | ||
136 | bool IsCreated() { return m_control != NULL; } | |
137 | ||
138 | // Creates the actual edit control | |
139 | virtual void Create(wxWindow* parent, | |
140 | wxWindowID id, | |
2796cce3 RD |
141 | wxEvtHandler* evtHandler) = 0; |
142 | ||
143 | // Size and position the edit control | |
144 | virtual void SetSize(const wxRect& rect); | |
145 | ||
3da93aae VZ |
146 | // Show or hide the edit control, use the specified attributes to set |
147 | // colours/fonts for it | |
148 | virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); | |
2796cce3 | 149 | |
189d0213 VZ |
150 | // Draws the part of the cell not occupied by the control: the base class |
151 | // version just fills it with background colour from the attribute | |
152 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); | |
153 | ||
2796cce3 RD |
154 | // Fetch the value from the table and prepare the edit control |
155 | // to begin editing. Set the focus to the edit control. | |
3da93aae | 156 | virtual void BeginEdit(int row, int col, wxGrid* grid) = 0; |
2796cce3 RD |
157 | |
158 | // Complete the editing of the current cell. If saveValue is | |
159 | // true then send the new value back to the table. Returns true | |
160 | // if the value has changed. If necessary, the control may be | |
161 | // destroyed. | |
3da93aae | 162 | virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid) = 0; |
2796cce3 RD |
163 | |
164 | // Reset the value in the control back to its starting value | |
165 | virtual void Reset() = 0; | |
166 | ||
fb295790 RD |
167 | // If the editor is enabled by pressing keys on the grid, |
168 | // this will be called to let the editor do something about | |
169 | // that first key if desired. | |
2c9a89e0 RD |
170 | virtual void StartingKey(wxKeyEvent& event); |
171 | ||
e195a54c VZ |
172 | // if the editor is enabled by clicking on the cell, this method will be |
173 | // called | |
174 | virtual void StartingClick(); | |
175 | ||
2796cce3 RD |
176 | // Some types of controls on some platforms may need some help |
177 | // with the Return key. | |
178 | virtual void HandleReturn(wxKeyEvent& event); | |
179 | ||
180 | // Final cleanup | |
181 | virtual void Destroy(); | |
182 | ||
183 | protected: | |
3da93aae | 184 | // the control we show on screen |
2796cce3 | 185 | wxControl* m_control; |
3da93aae VZ |
186 | |
187 | // if we change the colours/font of the control from the default ones, we | |
188 | // must restore the default later and we save them here between calls to | |
189 | // Show(TRUE) and Show(FALSE) | |
190 | wxColour m_colFgOld, | |
191 | m_colBgOld; | |
192 | wxFont m_fontOld; | |
2796cce3 RD |
193 | }; |
194 | ||
508011ce | 195 | // the editor for string/text data |
2796cce3 RD |
196 | class WXDLLEXPORT wxGridCellTextEditor : public wxGridCellEditor |
197 | { | |
198 | public: | |
199 | wxGridCellTextEditor(); | |
200 | ||
201 | virtual void Create(wxWindow* parent, | |
202 | wxWindowID id, | |
2796cce3 RD |
203 | wxEvtHandler* evtHandler); |
204 | ||
189d0213 VZ |
205 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr); |
206 | ||
3da93aae VZ |
207 | virtual void BeginEdit(int row, int col, wxGrid* grid); |
208 | virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid); | |
2796cce3 RD |
209 | |
210 | virtual void Reset(); | |
2c9a89e0 | 211 | virtual void StartingKey(wxKeyEvent& event); |
2796cce3 RD |
212 | virtual void HandleReturn(wxKeyEvent& event); |
213 | ||
b54ba671 VZ |
214 | protected: |
215 | wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; } | |
2796cce3 RD |
216 | |
217 | private: | |
218 | wxString m_startValue; | |
219 | }; | |
220 | ||
508011ce VZ |
221 | // the editor for boolean data |
222 | class WXDLLEXPORT wxGridCellBoolEditor : public wxGridCellEditor | |
223 | { | |
224 | public: | |
225 | virtual void Create(wxWindow* parent, | |
226 | wxWindowID id, | |
227 | wxEvtHandler* evtHandler); | |
228 | ||
229 | virtual void SetSize(const wxRect& rect); | |
230 | virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); | |
231 | ||
232 | virtual void BeginEdit(int row, int col, wxGrid* grid); | |
233 | virtual bool EndEdit(int row, int col, bool saveValue, wxGrid* grid); | |
234 | ||
235 | virtual void Reset(); | |
e195a54c | 236 | virtual void StartingClick(); |
508011ce VZ |
237 | |
238 | protected: | |
239 | wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } | |
240 | ||
241 | private: | |
242 | bool m_startValue; | |
508011ce VZ |
243 | }; |
244 | ||
b99be8fb VZ |
245 | // ---------------------------------------------------------------------------- |
246 | // wxGridCellAttr: this class can be used to alter the cells appearance in | |
247 | // the grid by changing their colour/font/... from default. An object of this | |
248 | // class may be returned by wxGridTable::GetAttr(). | |
249 | // ---------------------------------------------------------------------------- | |
250 | ||
251 | class WXDLLEXPORT wxGridCellAttr | |
252 | { | |
253 | public: | |
254 | // ctors | |
255 | wxGridCellAttr() | |
256 | { | |
2e9a6788 | 257 | Init(); |
b99be8fb VZ |
258 | SetAlignment(0, 0); |
259 | } | |
260 | ||
283b7808 VZ |
261 | // VZ: considering the number of members wxGridCellAttr has now, this ctor |
262 | // seems to be pretty useless... may be we should just remove it? | |
b99be8fb VZ |
263 | wxGridCellAttr(const wxColour& colText, |
264 | const wxColour& colBack, | |
265 | const wxFont& font, | |
266 | int hAlign, | |
267 | int vAlign) | |
268 | : m_colText(colText), m_colBack(colBack), m_font(font) | |
269 | { | |
2e9a6788 | 270 | Init(); |
b99be8fb VZ |
271 | SetAlignment(hAlign, vAlign); |
272 | } | |
273 | ||
274 | // default copy ctor ok | |
275 | ||
2e9a6788 VZ |
276 | // this class is ref counted: it is created with ref count of 1, so |
277 | // calling DecRef() once will delete it. Calling IncRef() allows to lock | |
278 | // it until the matching DecRef() is called | |
279 | void IncRef() { m_nRef++; } | |
280 | void DecRef() { if ( !--m_nRef ) delete this; } | |
0a976765 | 281 | void SafeIncRef() { if ( this ) IncRef(); } |
2e9a6788 VZ |
282 | void SafeDecRef() { if ( this ) DecRef(); } |
283 | ||
b99be8fb VZ |
284 | // setters |
285 | void SetTextColour(const wxColour& colText) { m_colText = colText; } | |
286 | void SetBackgroundColour(const wxColour& colBack) { m_colBack = colBack; } | |
287 | void SetFont(const wxFont& font) { m_font = font; } | |
288 | void SetAlignment(int hAlign, int vAlign) | |
289 | { | |
290 | m_hAlign = hAlign; | |
291 | m_vAlign = vAlign; | |
292 | } | |
283b7808 | 293 | void SetReadOnly(bool isReadOnly = TRUE) { m_isReadOnly = isReadOnly; } |
b99be8fb | 294 | |
ab79958a VZ |
295 | // takes ownership of the pointer |
296 | void SetRenderer(wxGridCellRenderer *renderer) | |
297 | { delete m_renderer; m_renderer = renderer; } | |
07296f0b RD |
298 | void SetEditor(wxGridCellEditor* editor) |
299 | { delete m_editor; m_editor = editor; } | |
ab79958a | 300 | |
b99be8fb VZ |
301 | // accessors |
302 | bool HasTextColour() const { return m_colText.Ok(); } | |
303 | bool HasBackgroundColour() const { return m_colBack.Ok(); } | |
304 | bool HasFont() const { return m_font.Ok(); } | |
305 | bool HasAlignment() const { return m_hAlign || m_vAlign; } | |
2796cce3 | 306 | bool HasRenderer() const { return m_renderer != NULL; } |
07296f0b | 307 | bool HasEditor() const { return m_editor != NULL; } |
b99be8fb | 308 | |
2796cce3 RD |
309 | const wxColour& GetTextColour() const; |
310 | const wxColour& GetBackgroundColour() const; | |
311 | const wxFont& GetFont() const; | |
312 | void GetAlignment(int *hAlign, int *vAlign) const; | |
f2d76237 RD |
313 | wxGridCellRenderer *GetRenderer(wxGridCellRenderer* def) const; |
314 | wxGridCellEditor *GetEditor(wxGridCellEditor* def) const; | |
b99be8fb | 315 | |
283b7808 VZ |
316 | bool IsReadOnly() const { return m_isReadOnly; } |
317 | ||
2796cce3 | 318 | void SetDefAttr(wxGridCellAttr* defAttr) { m_defGridAttr = defAttr; } |
ab79958a | 319 | |
b99be8fb | 320 | private: |
2e9a6788 | 321 | // the common part of all ctors |
283b7808 VZ |
322 | void Init() |
323 | { | |
07296f0b | 324 | m_nRef = 1; |
283b7808 VZ |
325 | |
326 | m_isReadOnly = FALSE; | |
327 | ||
07296f0b RD |
328 | m_renderer = NULL; |
329 | m_editor = NULL; | |
330 | } | |
2e9a6788 VZ |
331 | |
332 | // the dtor is private because only DecRef() can delete us | |
07296f0b | 333 | ~wxGridCellAttr() { delete m_renderer; delete m_editor; } |
2e9a6788 VZ |
334 | |
335 | // the ref count - when it goes to 0, we die | |
336 | size_t m_nRef; | |
337 | ||
b99be8fb VZ |
338 | wxColour m_colText, |
339 | m_colBack; | |
340 | wxFont m_font; | |
341 | int m_hAlign, | |
342 | m_vAlign; | |
2e9a6788 | 343 | |
07296f0b RD |
344 | wxGridCellRenderer* m_renderer; |
345 | wxGridCellEditor* m_editor; | |
346 | wxGridCellAttr* m_defGridAttr; | |
ab79958a | 347 | |
283b7808 VZ |
348 | bool m_isReadOnly; |
349 | ||
2e9a6788 VZ |
350 | // suppress the stupid gcc warning about the class having private dtor and |
351 | // no friends | |
352 | friend class wxGridCellAttrDummyFriend; | |
b99be8fb VZ |
353 | }; |
354 | ||
355 | // ---------------------------------------------------------------------------- | |
356 | // wxGridCellAttrProvider: class used by wxGridTableBase to retrieve/store the | |
357 | // cell attributes. | |
358 | // ---------------------------------------------------------------------------- | |
359 | ||
360 | // implementation note: we separate it from wxGridTableBase because we wish to | |
361 | // avoid deriving a new table class if possible, and sometimes it will be | |
362 | // enough to just derive another wxGridCellAttrProvider instead | |
758cbedf VZ |
363 | // |
364 | // the default implementation is reasonably efficient for the generic case, | |
365 | // but you might still wish to implement your own for some specific situations | |
366 | // if you have performance problems with the stock one | |
b99be8fb VZ |
367 | class WXDLLEXPORT wxGridCellAttrProvider |
368 | { | |
369 | public: | |
370 | wxGridCellAttrProvider(); | |
371 | virtual ~wxGridCellAttrProvider(); | |
372 | ||
2e9a6788 | 373 | // DecRef() must be called on the returned pointer |
b99be8fb | 374 | virtual wxGridCellAttr *GetAttr(int row, int col) const; |
2e9a6788 | 375 | |
758cbedf VZ |
376 | // all these functions take ownership of the pointer, don't call DecRef() |
377 | // on it | |
2e9a6788 | 378 | virtual void SetAttr(wxGridCellAttr *attr, int row, int col); |
758cbedf VZ |
379 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); |
380 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
d1c0b4f9 VZ |
381 | |
382 | // these functions must be called whenever some rows/cols are deleted | |
383 | // because the internal data must be updated then | |
4d60017a SN |
384 | void UpdateAttrRows( size_t pos, int numRows ); |
385 | void UpdateAttrCols( size_t pos, int numCols ); | |
b99be8fb VZ |
386 | |
387 | private: | |
388 | void InitData(); | |
389 | ||
390 | wxGridCellAttrProviderData *m_data; | |
391 | }; | |
f85afd4e MB |
392 | |
393 | ////////////////////////////////////////////////////////////////////// | |
394 | // | |
395 | // Grid table classes | |
396 | // | |
397 | ////////////////////////////////////////////////////////////////////// | |
398 | ||
399 | ||
2d66e025 | 400 | class WXDLLEXPORT wxGridTableBase : public wxObject |
f85afd4e | 401 | { |
60ff3b99 | 402 | public: |
f85afd4e MB |
403 | wxGridTableBase(); |
404 | virtual ~wxGridTableBase(); | |
405 | ||
406 | // You must override these functions in a derived table class | |
407 | // | |
408 | virtual long GetNumberRows() = 0; | |
409 | virtual long GetNumberCols() = 0; | |
f85afd4e | 410 | virtual bool IsEmptyCell( int row, int col ) = 0; |
f2d76237 RD |
411 | virtual wxString GetValue( int row, int col ) = 0; |
412 | virtual void SetValue( int row, int col, const wxString& value ) = 0; | |
413 | ||
414 | // Data type determination and value access | |
415 | virtual wxString GetTypeName( int row, int col ); | |
416 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
417 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
418 | ||
419 | virtual long GetValueAsLong( int row, int col ); | |
420 | virtual double GetValueAsDouble( int row, int col ); | |
421 | virtual bool GetValueAsBool( int row, int col ); | |
422 | ||
423 | virtual void SetValueAsLong( int row, int col, long value ); | |
424 | virtual void SetValueAsDouble( int row, int col, double value ); | |
425 | virtual void SetValueAsBool( int row, int col, bool value ); | |
426 | ||
427 | // For user defined types | |
428 | virtual void* GetValueAsCustom( int row, int col, const wxString& typeName ); | |
429 | virtual void SetValueAsCustom( int row, int col, const wxString& typeName, void* value ); | |
430 | ||
60ff3b99 | 431 | |
f85afd4e MB |
432 | // Overriding these is optional |
433 | // | |
434 | virtual void SetView( wxGrid *grid ) { m_view = grid; } | |
435 | virtual wxGrid * GetView() const { return m_view; } | |
436 | ||
437 | virtual void Clear() {} | |
438 | virtual bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
439 | virtual bool AppendRows( size_t numRows = 1 ); | |
440 | virtual bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
441 | virtual bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
442 | virtual bool AppendCols( size_t numCols = 1 ); | |
443 | virtual bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
444 | ||
445 | virtual wxString GetRowLabelValue( int row ); | |
446 | virtual wxString GetColLabelValue( int col ); | |
af111fc3 JS |
447 | virtual void SetRowLabelValue( int WXUNUSED(row), const wxString& ) {} |
448 | virtual void SetColLabelValue( int WXUNUSED(col), const wxString& ) {} | |
60ff3b99 | 449 | |
b99be8fb VZ |
450 | // Attribute handling |
451 | // | |
452 | ||
453 | // give us the attr provider to use - we take ownership of the pointer | |
454 | void SetAttrProvider(wxGridCellAttrProvider *attrProvider); | |
455 | ||
456 | // get the currently used attr provider (may be NULL) | |
457 | wxGridCellAttrProvider *GetAttrProvider() const { return m_attrProvider; } | |
458 | ||
f2d76237 RD |
459 | // Does this table allow attributes? Default implementation creates |
460 | // a wxGridCellAttrProvider if necessary. | |
461 | virtual bool CanHaveAttributes(); | |
462 | ||
463 | ||
4d60017a | 464 | // change row/col number in attribute if needed |
f2d76237 RD |
465 | virtual void UpdateAttrRows( size_t pos, int numRows ); |
466 | virtual void UpdateAttrCols( size_t pos, int numCols ); | |
4d60017a | 467 | |
b99be8fb | 468 | // by default forwarded to wxGridCellAttrProvider if any. May be |
f2d76237 | 469 | // overridden to handle attributes directly in the table. |
b99be8fb VZ |
470 | virtual wxGridCellAttr *GetAttr( int row, int col ); |
471 | ||
758cbedf VZ |
472 | // these functions take ownership of the pointer |
473 | virtual void SetAttr(wxGridCellAttr* attr, int row, int col); | |
474 | virtual void SetRowAttr(wxGridCellAttr *attr, int row); | |
475 | virtual void SetColAttr(wxGridCellAttr *attr, int col); | |
b99be8fb | 476 | |
60ff3b99 VZ |
477 | private: |
478 | wxGrid * m_view; | |
b99be8fb | 479 | wxGridCellAttrProvider *m_attrProvider; |
60ff3b99 | 480 | |
f85afd4e MB |
481 | DECLARE_ABSTRACT_CLASS( wxGridTableBase ); |
482 | }; | |
483 | ||
484 | ||
b99be8fb VZ |
485 | // ---------------------------------------------------------------------------- |
486 | // wxGridTableMessage | |
487 | // ---------------------------------------------------------------------------- | |
f85afd4e MB |
488 | |
489 | // IDs for messages sent from grid table to view | |
490 | // | |
60ff3b99 VZ |
491 | enum wxGridTableRequest |
492 | { | |
f85afd4e MB |
493 | wxGRIDTABLE_REQUEST_VIEW_GET_VALUES = 2000, |
494 | wxGRIDTABLE_REQUEST_VIEW_SEND_VALUES, | |
495 | wxGRIDTABLE_NOTIFY_ROWS_INSERTED, | |
496 | wxGRIDTABLE_NOTIFY_ROWS_APPENDED, | |
497 | wxGRIDTABLE_NOTIFY_ROWS_DELETED, | |
498 | wxGRIDTABLE_NOTIFY_COLS_INSERTED, | |
499 | wxGRIDTABLE_NOTIFY_COLS_APPENDED, | |
500 | wxGRIDTABLE_NOTIFY_COLS_DELETED | |
501 | }; | |
502 | ||
2d66e025 | 503 | class WXDLLEXPORT wxGridTableMessage |
f85afd4e | 504 | { |
60ff3b99 | 505 | public: |
f85afd4e MB |
506 | wxGridTableMessage(); |
507 | wxGridTableMessage( wxGridTableBase *table, int id, | |
508 | int comInt1 = -1, | |
509 | int comInt2 = -1 ); | |
510 | ||
511 | void SetTableObject( wxGridTableBase *table ) { m_table = table; } | |
512 | wxGridTableBase * GetTableObject() const { return m_table; } | |
513 | void SetId( int id ) { m_id = id; } | |
514 | int GetId() { return m_id; } | |
515 | void SetCommandInt( int comInt1 ) { m_comInt1 = comInt1; } | |
516 | int GetCommandInt() { return m_comInt1; } | |
517 | void SetCommandInt2( int comInt2 ) { m_comInt2 = comInt2; } | |
60ff3b99 VZ |
518 | int GetCommandInt2() { return m_comInt2; } |
519 | ||
520 | private: | |
521 | wxGridTableBase *m_table; | |
522 | int m_id; | |
523 | int m_comInt1; | |
524 | int m_comInt2; | |
f85afd4e MB |
525 | }; |
526 | ||
527 | ||
528 | ||
529 | // ------ wxGridStringArray | |
530 | // A 2-dimensional array of strings for data values | |
531 | // | |
532 | ||
2d66e025 MB |
533 | WX_DECLARE_EXPORTED_OBJARRAY(wxArrayString, wxGridStringArray); |
534 | ||
f85afd4e MB |
535 | |
536 | ||
537 | // ------ wxGridStringTable | |
538 | // | |
539 | // Simplest type of data table for a grid for small tables of strings | |
540 | // that are stored in memory | |
541 | // | |
542 | ||
2d66e025 | 543 | class WXDLLEXPORT wxGridStringTable : public wxGridTableBase |
f85afd4e | 544 | { |
60ff3b99 | 545 | public: |
f85afd4e MB |
546 | wxGridStringTable(); |
547 | wxGridStringTable( int numRows, int numCols ); | |
548 | ~wxGridStringTable(); | |
549 | ||
550 | // these are pure virtual in wxGridTableBase | |
551 | // | |
552 | long GetNumberRows(); | |
553 | long GetNumberCols(); | |
554 | wxString GetValue( int row, int col ); | |
555 | void SetValue( int row, int col, const wxString& s ); | |
556 | bool IsEmptyCell( int row, int col ); | |
60ff3b99 | 557 | |
f85afd4e MB |
558 | // overridden functions from wxGridTableBase |
559 | // | |
560 | void Clear(); | |
561 | bool InsertRows( size_t pos = 0, size_t numRows = 1 ); | |
562 | bool AppendRows( size_t numRows = 1 ); | |
563 | bool DeleteRows( size_t pos = 0, size_t numRows = 1 ); | |
564 | bool InsertCols( size_t pos = 0, size_t numCols = 1 ); | |
565 | bool AppendCols( size_t numCols = 1 ); | |
566 | bool DeleteCols( size_t pos = 0, size_t numCols = 1 ); | |
567 | ||
568 | void SetRowLabelValue( int row, const wxString& ); | |
569 | void SetColLabelValue( int col, const wxString& ); | |
570 | wxString GetRowLabelValue( int row ); | |
571 | wxString GetColLabelValue( int col ); | |
60ff3b99 VZ |
572 | |
573 | private: | |
574 | wxGridStringArray m_data; | |
575 | ||
576 | // These only get used if you set your own labels, otherwise the | |
577 | // GetRow/ColLabelValue functions return wxGridTableBase defaults | |
578 | // | |
579 | wxArrayString m_rowLabels; | |
580 | wxArrayString m_colLabels; | |
581 | ||
f85afd4e MB |
582 | DECLARE_DYNAMIC_CLASS( wxGridStringTable ) |
583 | }; | |
584 | ||
585 | ||
586 | ||
43947979 | 587 | // ============================================================================ |
f85afd4e | 588 | // Grid view classes |
43947979 VZ |
589 | // ============================================================================ |
590 | ||
591 | // ---------------------------------------------------------------------------- | |
592 | // wxGridCellCoords: location of a cell in the grid | |
593 | // ---------------------------------------------------------------------------- | |
f85afd4e | 594 | |
2d66e025 | 595 | class WXDLLEXPORT wxGridCellCoords |
f85afd4e | 596 | { |
60ff3b99 | 597 | public: |
f85afd4e MB |
598 | wxGridCellCoords() { m_row = m_col = -1; } |
599 | wxGridCellCoords( int r, int c ) { m_row = r; m_col = c; } | |
600 | ||
601 | // default copy ctor is ok | |
602 | ||
603 | long GetRow() const { return m_row; } | |
604 | void SetRow( long n ) { m_row = n; } | |
605 | long GetCol() const { return m_col; } | |
606 | void SetCol( long n ) { m_col = n; } | |
607 | void Set( long row, long col ) { m_row = row; m_col = col; } | |
60ff3b99 | 608 | |
f85afd4e MB |
609 | wxGridCellCoords& operator=( const wxGridCellCoords& other ) |
610 | { | |
611 | if ( &other != this ) | |
612 | { | |
613 | m_row=other.m_row; | |
614 | m_col=other.m_col; | |
615 | } | |
616 | return *this; | |
617 | } | |
618 | ||
508011ce | 619 | bool operator==( const wxGridCellCoords& other ) const |
f85afd4e MB |
620 | { |
621 | return (m_row == other.m_row && m_col == other.m_col); | |
622 | } | |
623 | ||
508011ce | 624 | bool operator!=( const wxGridCellCoords& other ) const |
f85afd4e MB |
625 | { |
626 | return (m_row != other.m_row || m_col != other.m_col); | |
627 | } | |
628 | ||
508011ce | 629 | bool operator!() const |
f85afd4e MB |
630 | { |
631 | return (m_row == -1 && m_col == -1 ); | |
632 | } | |
60ff3b99 VZ |
633 | |
634 | private: | |
635 | long m_row; | |
636 | long m_col; | |
f85afd4e MB |
637 | }; |
638 | ||
639 | ||
640 | // For comparisons... | |
641 | // | |
642 | extern wxGridCellCoords wxGridNoCellCoords; | |
643 | extern wxRect wxGridNoCellRect; | |
644 | ||
2d66e025 MB |
645 | // An array of cell coords... |
646 | // | |
647 | WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellCoords, wxGridCellCoordsArray); | |
648 | ||
b99be8fb VZ |
649 | // ---------------------------------------------------------------------------- |
650 | // wxGrid | |
651 | // ---------------------------------------------------------------------------- | |
f85afd4e | 652 | |
60ff3b99 VZ |
653 | class WXDLLEXPORT wxGrid : public wxScrolledWindow |
654 | { | |
655 | public: | |
f85afd4e | 656 | wxGrid() |
b99be8fb | 657 | { |
2c9a89e0 | 658 | Create(); |
58dd5b3b | 659 | } |
60ff3b99 | 660 | |
f85afd4e MB |
661 | wxGrid( wxWindow *parent, |
662 | wxWindowID id, | |
663 | const wxPoint& pos = wxDefaultPosition, | |
664 | const wxSize& size = wxDefaultSize, | |
665 | long style = 0, | |
2d66e025 MB |
666 | const wxString& name = wxPanelNameStr ); |
667 | ||
60ff3b99 | 668 | ~wxGrid(); |
f85afd4e | 669 | |
2d66e025 MB |
670 | bool CreateGrid( int numRows, int numCols ); |
671 | ||
60ff3b99 | 672 | |
2d66e025 MB |
673 | // ------ grid dimensions |
674 | // | |
675 | int GetNumberRows() { return m_numRows; } | |
676 | int GetNumberCols() { return m_numCols; } | |
677 | ||
60ff3b99 | 678 | |
2d66e025 MB |
679 | // ------ display update functions |
680 | // | |
60ff3b99 | 681 | void CalcRowLabelsExposed( wxRegion& reg ); |
8fb66724 | 682 | |
60ff3b99 VZ |
683 | void CalcColLabelsExposed( wxRegion& reg ); |
684 | void CalcCellsExposed( wxRegion& reg ); | |
685 | ||
2d66e025 | 686 | |
2d66e025 MB |
687 | // ------ event handlers |
688 | // | |
689 | void ProcessRowLabelMouseEvent( wxMouseEvent& event ); | |
690 | void ProcessColLabelMouseEvent( wxMouseEvent& event ); | |
691 | void ProcessCornerLabelMouseEvent( wxMouseEvent& event ); | |
60ff3b99 | 692 | void ProcessGridCellMouseEvent( wxMouseEvent& event ); |
2d66e025 | 693 | bool ProcessTableMessage( wxGridTableMessage& ); |
f85afd4e | 694 | |
6d004f67 MB |
695 | void DoEndDragResizeRow(); |
696 | void DoEndDragResizeCol(); | |
60ff3b99 | 697 | |
f85afd4e | 698 | wxGridTableBase * GetTable() const { return m_table; } |
2796cce3 | 699 | bool SetTable( wxGridTableBase *table, bool takeOwnership=FALSE ); |
f85afd4e MB |
700 | |
701 | void ClearGrid(); | |
702 | bool InsertRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); | |
703 | bool AppendRows( int numRows = 1, bool updateLabels=TRUE ); | |
704 | bool DeleteRows( int pos = 0, int numRows = 1, bool updateLabels=TRUE ); | |
705 | bool InsertCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); | |
706 | bool AppendCols( int numCols = 1, bool updateLabels=TRUE ); | |
60ff3b99 | 707 | bool DeleteCols( int pos = 0, int numCols = 1, bool updateLabels=TRUE ); |
f85afd4e | 708 | |
2d66e025 MB |
709 | void DrawGridCellArea( wxDC& dc ); |
710 | void DrawCellBorder( wxDC& dc, const wxGridCellCoords& ); | |
4634a5d6 | 711 | void DrawAllGridLines( wxDC& dc, const wxRegion & reg ); |
2d66e025 | 712 | void DrawCell( wxDC& dc, const wxGridCellCoords& ); |
d16c04bb VZ |
713 | void DrawHighlight(wxDC& dc); |
714 | ||
715 | // this function is called when the current cell highlight must be redrawn | |
716 | // and may be overridden by the user | |
717 | virtual void DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ); | |
1f1ce288 | 718 | |
2d66e025 MB |
719 | void DrawRowLabels( wxDC& dc ); |
720 | void DrawRowLabel( wxDC& dc, int row ); | |
8fb66724 | 721 | |
2d66e025 MB |
722 | void DrawColLabels( wxDC& dc ); |
723 | void DrawColLabel( wxDC& dc, int col ); | |
60ff3b99 | 724 | |
f85afd4e | 725 | |
2d66e025 | 726 | // ------ Cell text drawing functions |
f85afd4e | 727 | // |
2d66e025 MB |
728 | void DrawTextRectangle( wxDC& dc, const wxString&, const wxRect&, |
729 | int horizontalAlignment = wxLEFT, | |
730 | int verticalAlignment = wxTOP ); | |
f85afd4e | 731 | |
2d66e025 MB |
732 | // Split a string containing newline chararcters into an array of |
733 | // strings and return the number of lines | |
734 | // | |
735 | void StringToLines( const wxString& value, wxArrayString& lines ); | |
60ff3b99 | 736 | |
2d66e025 MB |
737 | void GetTextBoxSize( wxDC& dc, |
738 | wxArrayString& lines, | |
739 | long *width, long *height ); | |
60ff3b99 | 740 | |
2d66e025 | 741 | |
f85afd4e MB |
742 | // ------ |
743 | // Code that does a lot of grid modification can be enclosed | |
744 | // between BeginBatch() and EndBatch() calls to avoid screen | |
745 | // flicker | |
746 | // | |
747 | void BeginBatch() { m_batchCount++; } | |
748 | void EndBatch() { if ( m_batchCount > 0 ) m_batchCount--; } | |
749 | int GetBatchCount() { return m_batchCount; } | |
750 | ||
2d66e025 MB |
751 | |
752 | // ------ edit control functions | |
753 | // | |
754 | bool IsEditable() { return m_editable; } | |
755 | void EnableEditing( bool edit ); | |
756 | ||
b54ba671 VZ |
757 | void EnableCellEditControl( bool enable = TRUE ); |
758 | void DisableCellEditControl() { EnableCellEditControl(FALSE); } | |
759 | bool CanEnableCellControl() const; | |
760 | bool IsCellEditControlEnabled() const; | |
2d66e025 | 761 | |
b54ba671 | 762 | bool IsCurrentCellReadOnly() const; |
2d66e025 | 763 | |
2d66e025 MB |
764 | void ShowCellEditControl(); |
765 | void HideCellEditControl(); | |
766 | void SetEditControlValue( const wxString& s = wxEmptyString ); | |
767 | void SaveEditControlValue(); | |
768 | ||
60ff3b99 | 769 | |
2d66e025 | 770 | // ------ grid location functions |
60ff3b99 | 771 | // Note that all of these functions work with the logical coordinates of |
2d66e025 MB |
772 | // grid cells and labels so you will need to convert from device |
773 | // coordinates for mouse events etc. | |
774 | // | |
775 | void XYToCell( int x, int y, wxGridCellCoords& ); | |
776 | int YToRow( int y ); | |
777 | int XToCol( int x ); | |
778 | ||
779 | int YToEdgeOfRow( int y ); | |
780 | int XToEdgeOfCol( int x ); | |
781 | ||
782 | wxRect CellToRect( int row, int col ); | |
783 | wxRect CellToRect( const wxGridCellCoords& coords ) | |
784 | { return CellToRect( coords.GetRow(), coords.GetCol() ); } | |
785 | ||
786 | int GetGridCursorRow() { return m_currentCellCoords.GetRow(); } | |
787 | int GetGridCursorCol() { return m_currentCellCoords.GetCol(); } | |
60ff3b99 | 788 | |
2d66e025 MB |
789 | // check to see if a cell is either wholly visible (the default arg) or |
790 | // at least partially visible in the grid window | |
791 | // | |
792 | bool IsVisible( int row, int col, bool wholeCellVisible = TRUE ); | |
793 | bool IsVisible( const wxGridCellCoords& coords, bool wholeCellVisible = TRUE ) | |
794 | { return IsVisible( coords.GetRow(), coords.GetCol(), wholeCellVisible ); } | |
795 | void MakeCellVisible( int row, int col ); | |
796 | void MakeCellVisible( const wxGridCellCoords& coords ) | |
797 | { MakeCellVisible( coords.GetRow(), coords.GetCol() ); } | |
798 | ||
60ff3b99 | 799 | |
2d66e025 MB |
800 | // ------ grid cursor movement functions |
801 | // | |
dfaf42d2 | 802 | void SetGridCursor( int row, int col ) |
b27f2615 | 803 | { SetCurrentCell( wxGridCellCoords(row, col) ); } |
dfaf42d2 | 804 | |
2d66e025 MB |
805 | bool MoveCursorUp(); |
806 | bool MoveCursorDown(); | |
807 | bool MoveCursorLeft(); | |
808 | bool MoveCursorRight(); | |
809 | bool MovePageDown(); | |
810 | bool MovePageUp(); | |
811 | bool MoveCursorUpBlock(); | |
812 | bool MoveCursorDownBlock(); | |
813 | bool MoveCursorLeftBlock(); | |
814 | bool MoveCursorRightBlock(); | |
815 | ||
60ff3b99 | 816 | |
f85afd4e MB |
817 | // ------ label and gridline formatting |
818 | // | |
819 | int GetDefaultRowLabelSize() { return WXGRID_DEFAULT_ROW_LABEL_WIDTH; } | |
820 | int GetRowLabelSize() { return m_rowLabelWidth; } | |
60ff3b99 | 821 | int GetDefaultColLabelSize() { return WXGRID_DEFAULT_COL_LABEL_HEIGHT; } |
f85afd4e MB |
822 | int GetColLabelSize() { return m_colLabelHeight; } |
823 | wxColour GetLabelBackgroundColour() { return m_labelBackgroundColour; } | |
824 | wxColour GetLabelTextColour() { return m_labelTextColour; } | |
825 | wxFont GetLabelFont() { return m_labelFont; } | |
826 | void GetRowLabelAlignment( int *horiz, int *vert ); | |
827 | void GetColLabelAlignment( int *horiz, int *vert ); | |
828 | wxString GetRowLabelValue( int row ); | |
829 | wxString GetColLabelValue( int col ); | |
830 | wxColour GetGridLineColour() { return m_gridLineColour; } | |
831 | ||
ab79958a | 832 | void SetRowLabelSize( int width ); |
f85afd4e MB |
833 | void SetColLabelSize( int height ); |
834 | void SetLabelBackgroundColour( const wxColour& ); | |
835 | void SetLabelTextColour( const wxColour& ); | |
836 | void SetLabelFont( const wxFont& ); | |
837 | void SetRowLabelAlignment( int horiz, int vert ); | |
838 | void SetColLabelAlignment( int horiz, int vert ); | |
839 | void SetRowLabelValue( int row, const wxString& ); | |
840 | void SetColLabelValue( int col, const wxString& ); | |
841 | void SetGridLineColour( const wxColour& ); | |
6e8524b1 MB |
842 | |
843 | void EnableDragRowSize( bool enable = TRUE ); | |
844 | void DisableDragRowSize() { EnableDragRowSize( FALSE ); } | |
845 | bool CanDragRowSize() { return m_canDragRowSize; } | |
846 | void EnableDragColSize( bool enable = TRUE ); | |
847 | void DisableDragColSize() { EnableDragColSize( FALSE ); } | |
848 | bool CanDragColSize() { return m_canDragColSize; } | |
f85afd4e | 849 | |
758cbedf VZ |
850 | // this sets the specified attribute for all cells in this row/col |
851 | void SetRowAttr(int row, wxGridCellAttr *attr); | |
852 | void SetColAttr(int col, wxGridCellAttr *attr); | |
853 | ||
f85afd4e MB |
854 | void EnableGridLines( bool enable = TRUE ); |
855 | bool GridLinesEnabled() { return m_gridLinesEnabled; } | |
856 | ||
f85afd4e MB |
857 | // ------ row and col formatting |
858 | // | |
859 | int GetDefaultRowSize(); | |
860 | int GetRowSize( int row ); | |
861 | int GetDefaultColSize(); | |
862 | int GetColSize( int col ); | |
863 | wxColour GetDefaultCellBackgroundColour(); | |
864 | wxColour GetCellBackgroundColour( int row, int col ); | |
865 | wxColour GetDefaultCellTextColour(); | |
866 | wxColour GetCellTextColour( int row, int col ); | |
f85afd4e MB |
867 | wxFont GetDefaultCellFont(); |
868 | wxFont GetCellFont( int row, int col ); | |
869 | void GetDefaultCellAlignment( int *horiz, int *vert ); | |
870 | void GetCellAlignment( int row, int col, int *horiz, int *vert ); | |
60ff3b99 | 871 | |
f85afd4e MB |
872 | void SetDefaultRowSize( int height, bool resizeExistingRows = FALSE ); |
873 | void SetRowSize( int row, int height ); | |
874 | void SetDefaultColSize( int width, bool resizeExistingCols = FALSE ); | |
8fb66724 | 875 | |
f85afd4e | 876 | void SetColSize( int col, int width ); |
43947979 VZ |
877 | |
878 | // column won't be resized to be lesser width - this must be called during | |
879 | // the grid creation because it won't resize the column if it's already | |
880 | // narrower than the minimal width | |
881 | void SetColMinimalWidth( int col, int width ); | |
882 | ||
f85afd4e MB |
883 | void SetDefaultCellBackgroundColour( const wxColour& ); |
884 | void SetCellBackgroundColour( int row, int col, const wxColour& ); | |
885 | void SetDefaultCellTextColour( const wxColour& ); | |
8fb66724 | 886 | |
f85afd4e | 887 | void SetCellTextColour( int row, int col, const wxColour& ); |
f85afd4e MB |
888 | void SetDefaultCellFont( const wxFont& ); |
889 | void SetCellFont( int row, int col, const wxFont& ); | |
890 | void SetDefaultCellAlignment( int horiz, int vert ); | |
891 | void SetCellAlignment( int row, int col, int horiz, int vert ); | |
892 | ||
ab79958a | 893 | // takes ownership of the pointer |
2796cce3 | 894 | void SetDefaultRenderer(wxGridCellRenderer *renderer); |
ab79958a | 895 | void SetCellRenderer(int row, int col, wxGridCellRenderer *renderer); |
2796cce3 RD |
896 | wxGridCellRenderer *GetDefaultRenderer() const; |
897 | wxGridCellRenderer* GetCellRenderer(int row, int col); | |
898 | ||
283b7808 | 899 | // takes ownership of the pointer |
0ba143c9 | 900 | void SetDefaultEditor(wxGridCellEditor *editor); |
9b4aede2 | 901 | void SetCellEditor(int row, int col, wxGridCellEditor *editor); |
0ba143c9 | 902 | wxGridCellEditor *GetDefaultEditor() const; |
9b4aede2 RD |
903 | wxGridCellEditor* GetCellEditor(int row, int col); |
904 | ||
60a67569 | 905 | |
f2d76237 | 906 | |
f85afd4e MB |
907 | // ------ cell value accessors |
908 | // | |
909 | wxString GetCellValue( int row, int col ) | |
910 | { | |
911 | if ( m_table ) | |
912 | { | |
913 | return m_table->GetValue( row, col ); | |
914 | } | |
915 | else | |
916 | { | |
917 | return wxEmptyString; | |
918 | } | |
919 | } | |
920 | ||
921 | wxString GetCellValue( const wxGridCellCoords& coords ) | |
922 | { return GetCellValue( coords.GetRow(), coords.GetCol() ); } | |
60ff3b99 | 923 | |
f85afd4e MB |
924 | void SetCellValue( int row, int col, const wxString& s ); |
925 | void SetCellValue( const wxGridCellCoords& coords, const wxString& s ) | |
926 | { SetCellValue( coords.GetRow(), coords.GetCol(), s ); } | |
f85afd4e | 927 | |
283b7808 VZ |
928 | // returns TRUE if the cell can't be edited |
929 | bool IsReadOnly(int row, int col) const; | |
60ff3b99 | 930 | |
283b7808 VZ |
931 | // make the cell editable/readonly |
932 | void SetReadOnly(int row, int col, bool isReadOnly = TRUE); | |
f85afd4e MB |
933 | |
934 | // ------ selections of blocks of cells | |
935 | // | |
936 | void SelectRow( int row, bool addToSelected = FALSE ); | |
937 | void SelectCol( int col, bool addToSelected = FALSE ); | |
60ff3b99 | 938 | |
f85afd4e MB |
939 | void SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol ); |
940 | ||
941 | void SelectBlock( const wxGridCellCoords& topLeft, | |
942 | const wxGridCellCoords& bottomRight ) | |
943 | { SelectBlock( topLeft.GetRow(), topLeft.GetCol(), | |
944 | bottomRight.GetRow(), bottomRight.GetCol() ); } | |
945 | ||
946 | void SelectAll(); | |
60ff3b99 | 947 | |
f85afd4e MB |
948 | bool IsSelection() |
949 | { return ( m_selectedTopLeft != wxGridNoCellCoords && | |
950 | m_selectedBottomRight != wxGridNoCellCoords ); | |
951 | } | |
952 | ||
953 | void ClearSelection(); | |
954 | ||
955 | bool IsInSelection( int row, int col ) | |
956 | { return ( IsSelection() && | |
957 | row >= m_selectedTopLeft.GetRow() && | |
958 | col >= m_selectedTopLeft.GetCol() && | |
959 | row <= m_selectedBottomRight.GetRow() && | |
960 | col <= m_selectedBottomRight.GetCol() ); | |
961 | } | |
962 | ||
963 | bool IsInSelection( const wxGridCellCoords& coords ) | |
964 | { return IsInSelection( coords.GetRow(), coords.GetCol() ); } | |
965 | ||
966 | void GetSelection( int* topRow, int* leftCol, int* bottomRow, int* rightCol ) | |
967 | { | |
968 | // these will all be -1 if there is no selected block | |
969 | // | |
970 | *topRow = m_selectedTopLeft.GetRow(); | |
971 | *leftCol = m_selectedTopLeft.GetCol(); | |
972 | *bottomRow = m_selectedBottomRight.GetRow(); | |
973 | *rightCol = m_selectedBottomRight.GetCol(); | |
974 | } | |
975 | ||
c3baf426 SN |
976 | |
977 | // This function returns the rectangle that encloses the block of cells | |
978 | // limited by TopLeft and BottomRight cell in device coords and clipped | |
979 | // to the client size of the grid window. | |
980 | // | |
58dd5b3b | 981 | wxRect BlockToDeviceRect( const wxGridCellCoords & topLeft, |
b99be8fb | 982 | const wxGridCellCoords & bottomRight ); |
c3baf426 | 983 | |
2d66e025 MB |
984 | // This function returns the rectangle that encloses the selected cells |
985 | // in device coords and clipped to the client size of the grid window. | |
f85afd4e | 986 | // |
c3baf426 SN |
987 | wxRect SelectionToDeviceRect() |
988 | { | |
b99be8fb VZ |
989 | return BlockToDeviceRect( m_selectedTopLeft, |
990 | m_selectedBottomRight ); | |
991 | } | |
60ff3b99 | 992 | |
2796cce3 RD |
993 | // Access or update the selection fore/back colours |
994 | wxColour GetSelectionBackground() const | |
995 | { return m_selectionBackground; } | |
996 | wxColour GetSelectionForeground() const | |
997 | { return m_selectionForeground; } | |
998 | ||
999 | void SetSelectionBackground(const wxColour& c) { m_selectionBackground = c; } | |
1000 | void SetSelectionForeground(const wxColour& c) { m_selectionForeground = c; } | |
1001 | ||
1002 | ||
f2d76237 RD |
1003 | // Methods for a registry for mapping data types to Renderers/Editors |
1004 | void RegisterDataType(const wxString& typeName, | |
1005 | wxGridCellRenderer* renderer, | |
1006 | wxGridCellEditor* editor); | |
1007 | wxGridCellEditor* GetDefaultEditorForCell(int row, int col); | |
1008 | wxGridCellRenderer* GetDefaultRendererForCell(int row, int col); | |
1009 | wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName); | |
1010 | wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName); | |
1011 | ||
1012 | ||
f85afd4e MB |
1013 | |
1014 | // ------ For compatibility with previous wxGrid only... | |
1015 | // | |
1016 | // ************************************************ | |
1017 | // ** Don't use these in new code because they ** | |
1018 | // ** are liable to disappear in a future ** | |
1019 | // ** revision ** | |
1020 | // ************************************************ | |
1021 | // | |
1022 | ||
1023 | wxGrid( wxWindow *parent, | |
1024 | int x = -1, int y = -1, int w = -1, int h = -1, | |
1025 | long style = 0, | |
1026 | const wxString& name = wxPanelNameStr ) | |
2d66e025 | 1027 | : wxScrolledWindow( parent, -1, wxPoint(x,y), wxSize(w,h), style, name ) |
60ff3b99 | 1028 | { |
f85afd4e | 1029 | Create(); |
60ff3b99 | 1030 | } |
f85afd4e MB |
1031 | |
1032 | void SetCellValue( const wxString& val, int row, int col ) | |
1033 | { SetCellValue( row, col, val ); } | |
60ff3b99 | 1034 | |
f85afd4e MB |
1035 | void UpdateDimensions() |
1036 | { CalcDimensions(); } | |
1037 | ||
1038 | int GetRows() { return GetNumberRows(); } | |
1039 | int GetCols() { return GetNumberCols(); } | |
1040 | int GetCursorRow() { return GetGridCursorRow(); } | |
1041 | int GetCursorColumn() { return GetGridCursorCol(); } | |
60ff3b99 | 1042 | |
2d66e025 MB |
1043 | int GetScrollPosX() { return 0; } |
1044 | int GetScrollPosY() { return 0; } | |
60ff3b99 | 1045 | |
2d66e025 MB |
1046 | void SetScrollX( int x ) { } |
1047 | void SetScrollY( int y ) { } | |
f85afd4e MB |
1048 | |
1049 | void SetColumnWidth( int col, int width ) | |
1050 | { SetColSize( col, width ); } | |
60ff3b99 | 1051 | |
f85afd4e MB |
1052 | int GetColumnWidth( int col ) |
1053 | { return GetColSize( col ); } | |
60ff3b99 | 1054 | |
f85afd4e MB |
1055 | void SetRowHeight( int row, int height ) |
1056 | { SetRowSize( row, height ); } | |
60ff3b99 | 1057 | |
7c1cb261 | 1058 | // GetRowHeight() is below |
60ff3b99 | 1059 | |
2d66e025 MB |
1060 | int GetViewHeight() // returned num whole rows visible |
1061 | { return 0; } | |
60ff3b99 | 1062 | |
2d66e025 MB |
1063 | int GetViewWidth() // returned num whole cols visible |
1064 | { return 0; } | |
f85afd4e MB |
1065 | |
1066 | void SetLabelSize( int orientation, int sz ) | |
1067 | { | |
1068 | if ( orientation == wxHORIZONTAL ) | |
1069 | SetColLabelSize( sz ); | |
1070 | else | |
1071 | SetRowLabelSize( sz ); | |
1072 | } | |
1073 | ||
1074 | int GetLabelSize( int orientation ) | |
1075 | { | |
1076 | if ( orientation == wxHORIZONTAL ) | |
1077 | return GetColLabelSize(); | |
1078 | else | |
1079 | return GetRowLabelSize(); | |
1080 | } | |
1081 | ||
1082 | void SetLabelAlignment( int orientation, int align ) | |
1083 | { | |
1084 | if ( orientation == wxHORIZONTAL ) | |
1085 | SetColLabelAlignment( align, -1 ); | |
1086 | else | |
1087 | SetRowLabelAlignment( align, -1 ); | |
1088 | } | |
1089 | ||
af111fc3 | 1090 | int GetLabelAlignment( int orientation, int WXUNUSED(align) ) |
f85afd4e MB |
1091 | { |
1092 | int h, v; | |
1093 | if ( orientation == wxHORIZONTAL ) | |
1094 | { | |
1095 | GetColLabelAlignment( &h, &v ); | |
1096 | return h; | |
1097 | } | |
1098 | else | |
1099 | { | |
1100 | GetRowLabelAlignment( &h, &v ); | |
1101 | return h; | |
1102 | } | |
1103 | } | |
1104 | ||
1105 | void SetLabelValue( int orientation, const wxString& val, int pos ) | |
1106 | { | |
1107 | if ( orientation == wxHORIZONTAL ) | |
1108 | SetColLabelValue( pos, val ); | |
1109 | else | |
1110 | SetRowLabelValue( pos, val ); | |
1111 | } | |
60ff3b99 | 1112 | |
f85afd4e MB |
1113 | wxString GetLabelValue( int orientation, int pos) |
1114 | { | |
1115 | if ( orientation == wxHORIZONTAL ) | |
1116 | return GetColLabelValue( pos ); | |
1117 | else | |
1118 | return GetRowLabelValue( pos ); | |
1119 | } | |
1120 | ||
60ff3b99 | 1121 | wxFont GetCellTextFont() const |
2796cce3 | 1122 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1123 | |
af111fc3 | 1124 | wxFont GetCellTextFont(int WXUNUSED(row), int WXUNUSED(col)) const |
2796cce3 | 1125 | { return m_defaultCellAttr->GetFont(); } |
60ff3b99 | 1126 | |
f85afd4e MB |
1127 | void SetCellTextFont(const wxFont& fnt) |
1128 | { SetDefaultCellFont( fnt ); } | |
60ff3b99 | 1129 | |
f85afd4e MB |
1130 | void SetCellTextFont(const wxFont& fnt, int row, int col) |
1131 | { SetCellFont( row, col, fnt ); } | |
60ff3b99 | 1132 | |
f85afd4e MB |
1133 | void SetCellTextColour(const wxColour& val, int row, int col) |
1134 | { SetCellTextColour( row, col, val ); } | |
60ff3b99 | 1135 | |
f85afd4e MB |
1136 | void SetCellTextColour(const wxColour& col) |
1137 | { SetDefaultCellTextColour( col ); } | |
60ff3b99 | 1138 | |
f85afd4e MB |
1139 | void SetCellBackgroundColour(const wxColour& col) |
1140 | { SetDefaultCellBackgroundColour( col ); } | |
60ff3b99 | 1141 | |
f85afd4e MB |
1142 | void SetCellBackgroundColour(const wxColour& colour, int row, int col) |
1143 | { SetCellBackgroundColour( row, col, colour ); } | |
60ff3b99 | 1144 | |
f85afd4e MB |
1145 | bool GetEditable() { return IsEditable(); } |
1146 | void SetEditable( bool edit = TRUE ) { EnableEditing( edit ); } | |
1147 | bool GetEditInPlace() { return IsCellEditControlEnabled(); } | |
8fb66724 | 1148 | |
1f1ce288 | 1149 | void SetEditInPlace(bool edit = TRUE) { } |
f85afd4e | 1150 | |
60a67569 JS |
1151 | void SetCellAlignment( int align, int row, int col) |
1152 | { SetCellAlignment(row, col, align, wxCENTER); } | |
1153 | void SetCellAlignment( int WXUNUSED(align) ) {} | |
1154 | void SetCellBitmap(wxBitmap *WXUNUSED(bitmap), int WXUNUSED(row), int WXUNUSED(col)) | |
1155 | { } | |
1156 | void SetDividerPen(const wxPen& WXUNUSED(pen)) { } | |
1157 | wxPen& GetDividerPen() const { return wxNullPen; } | |
1158 | void OnActivate(bool WXUNUSED(active)) {} | |
60ff3b99 | 1159 | |
f85afd4e MB |
1160 | // ******** End of compatibility functions ********** |
1161 | ||
2d66e025 MB |
1162 | |
1163 | ||
f85afd4e | 1164 | // ------ control IDs |
2d66e025 | 1165 | enum { wxGRID_CELLCTRL = 2000, |
f85afd4e MB |
1166 | wxGRID_TOPCTRL }; |
1167 | ||
1168 | // ------ control types | |
2d66e025 | 1169 | enum { wxGRID_TEXTCTRL = 2100, |
f85afd4e MB |
1170 | wxGRID_CHECKBOX, |
1171 | wxGRID_CHOICE, | |
1172 | wxGRID_COMBOBOX }; | |
1173 | ||
508011ce VZ |
1174 | // for wxGridCellBoolEditor |
1175 | wxWindow *GetGridWindow() const; | |
1176 | ||
60ff3b99 VZ |
1177 | protected: |
1178 | bool m_created; | |
4634a5d6 | 1179 | bool m_displayed; |
60ff3b99 VZ |
1180 | |
1181 | wxGridWindow *m_gridWin; | |
1182 | wxGridRowLabelWindow *m_rowLabelWin; | |
1183 | wxGridColLabelWindow *m_colLabelWin; | |
1184 | wxGridCornerLabelWindow *m_cornerLabelWin; | |
1185 | ||
60ff3b99 | 1186 | wxGridTableBase *m_table; |
2796cce3 | 1187 | bool m_ownTable; |
60ff3b99 VZ |
1188 | |
1189 | int m_left; | |
1190 | int m_top; | |
1191 | int m_right; | |
1192 | int m_bottom; | |
1193 | ||
1194 | int m_numRows; | |
1195 | int m_numCols; | |
1196 | ||
1197 | wxGridCellCoords m_currentCellCoords; | |
1198 | ||
1199 | wxGridCellCoords m_selectedTopLeft; | |
1200 | wxGridCellCoords m_selectedBottomRight; | |
2796cce3 RD |
1201 | wxColour m_selectionBackground; |
1202 | wxColour m_selectionForeground; | |
60ff3b99 | 1203 | |
7c1cb261 VZ |
1204 | // NB: *never* access m_row/col arrays directly because they are created |
1205 | // on demand, *always* use accessor functions instead! | |
1206 | ||
1207 | // init the m_rowHeights/Bottoms arrays with default values | |
1208 | void InitRowHeights(); | |
1209 | ||
60ff3b99 VZ |
1210 | int m_defaultRowHeight; |
1211 | wxArrayInt m_rowHeights; | |
1212 | wxArrayInt m_rowBottoms; | |
1213 | ||
7c1cb261 VZ |
1214 | // init the m_colWidths/Rights arrays |
1215 | void InitColWidths(); | |
1216 | ||
60ff3b99 VZ |
1217 | int m_defaultColWidth; |
1218 | wxArrayInt m_colWidths; | |
1219 | wxArrayInt m_colRights; | |
7c1cb261 VZ |
1220 | |
1221 | // get the col/row coords | |
1222 | int GetColWidth(int col) const; | |
1223 | int GetColLeft(int col) const; | |
1224 | int GetColRight(int col) const; | |
1225 | ||
1226 | // this function must be public for compatibility... | |
1227 | public: | |
1228 | int GetRowHeight(int row) const; | |
1229 | protected: | |
1230 | ||
1231 | int GetRowTop(int row) const; | |
1232 | int GetRowBottom(int row) const; | |
1233 | ||
60ff3b99 VZ |
1234 | int m_rowLabelWidth; |
1235 | int m_colLabelHeight; | |
1236 | ||
1237 | wxColour m_labelBackgroundColour; | |
1238 | wxColour m_labelTextColour; | |
1239 | wxFont m_labelFont; | |
1240 | ||
1241 | int m_rowLabelHorizAlign; | |
1242 | int m_rowLabelVertAlign; | |
1243 | int m_colLabelHorizAlign; | |
1244 | int m_colLabelVertAlign; | |
1245 | ||
1246 | bool m_defaultRowLabelValues; | |
1247 | bool m_defaultColLabelValues; | |
1248 | ||
1249 | wxColour m_gridLineColour; | |
1250 | bool m_gridLinesEnabled; | |
1251 | ||
43947979 VZ |
1252 | // if a column has a minimal width, it will be the value for it in this |
1253 | // hash table | |
1254 | wxHashTable m_colMinWidths; | |
1255 | ||
1256 | // get the minimal width of the given column | |
1257 | int GetColMinimalWidth(int col) const; | |
b99be8fb VZ |
1258 | |
1259 | // do we have some place to store attributes in? | |
1260 | bool CanHaveAttributes(); | |
60ff3b99 | 1261 | |
2e9a6788 VZ |
1262 | // returns the attribute we may modify in place: a new one if this cell |
1263 | // doesn't have any yet or the existing one if it does | |
1264 | // | |
1265 | // DecRef() must be called on the returned pointer, as usual | |
0a976765 VZ |
1266 | wxGridCellAttr *GetOrCreateCellAttr(int row, int col) const; |
1267 | ||
1268 | // cell attribute cache (currently we only cache 1, may be will do | |
1269 | // more/better later) | |
1270 | struct CachedAttr | |
1271 | { | |
1272 | int row, col; | |
1273 | wxGridCellAttr *attr; | |
1274 | } m_attrCache; | |
1275 | ||
1276 | // invalidates the attribute cache | |
1277 | void ClearAttrCache(); | |
1278 | ||
1279 | // adds an attribute to cache | |
1280 | void CacheAttr(int row, int col, wxGridCellAttr *attr) const; | |
1281 | ||
1282 | // looks for an attr in cache, returns TRUE if found | |
1283 | bool LookupAttr(int row, int col, wxGridCellAttr **attr) const; | |
1284 | ||
1285 | // looks for the attr in cache, if not found asks the table and caches the | |
1286 | // result | |
2e9a6788 | 1287 | wxGridCellAttr *GetCellAttr(int row, int col) const; |
2c9a89e0 RD |
1288 | wxGridCellAttr *GetCellAttr(const wxGridCellCoords& coords ) |
1289 | { return GetCellAttr( coords.GetRow(), coords.GetCol() ); } | |
2e9a6788 | 1290 | |
2796cce3 RD |
1291 | // the default cell attr object for cells that don't have their own |
1292 | wxGridCellAttr* m_defaultCellAttr; | |
1293 | ||
1294 | ||
60ff3b99 VZ |
1295 | wxGridCellCoordsArray m_cellsExposed; |
1296 | wxArrayInt m_rowsExposed; | |
1297 | wxArrayInt m_colsExposed; | |
1298 | wxArrayInt m_rowLabelsExposed; | |
1299 | wxArrayInt m_colLabelsExposed; | |
1300 | ||
1301 | bool m_inOnKeyDown; | |
1302 | int m_batchCount; | |
1303 | ||
f2d76237 RD |
1304 | |
1305 | wxGridTypeRegistry* m_typeRegistry; | |
1306 | ||
e2b42eeb VZ |
1307 | enum CursorMode |
1308 | { | |
1309 | WXGRID_CURSOR_SELECT_CELL, | |
1310 | WXGRID_CURSOR_RESIZE_ROW, | |
1311 | WXGRID_CURSOR_RESIZE_COL, | |
1312 | WXGRID_CURSOR_SELECT_ROW, | |
1313 | WXGRID_CURSOR_SELECT_COL | |
60ff3b99 VZ |
1314 | }; |
1315 | ||
e2b42eeb VZ |
1316 | // this method not only sets m_cursorMode but also sets the correct cursor |
1317 | // for the given mode and, if captureMouse is not FALSE releases the mouse | |
1318 | // if it was captured and captures it if it must be captured | |
1319 | // | |
1320 | // for this to work, you should always use it and not set m_cursorMode | |
1321 | // directly! | |
1322 | void ChangeCursorMode(CursorMode mode, | |
1323 | wxWindow *win = (wxWindow *)NULL, | |
1324 | bool captureMouse = TRUE); | |
1325 | ||
1326 | wxWindow *m_winCapture; // the window which captured the mouse | |
1327 | CursorMode m_cursorMode; | |
1328 | ||
6e8524b1 MB |
1329 | bool m_canDragRowSize; |
1330 | bool m_canDragColSize; | |
07296f0b RD |
1331 | int m_dragLastPos; |
1332 | int m_dragRowOrCol; | |
1333 | bool m_isDragging; | |
1334 | wxPoint m_startDragPos; | |
60ff3b99 | 1335 | |
75ecbe45 | 1336 | bool m_waitForSlowClick; |
025562fe | 1337 | |
60ff3b99 VZ |
1338 | wxGridCellCoords m_selectionStart; |
1339 | ||
1340 | wxCursor m_rowResizeCursor; | |
1341 | wxCursor m_colResizeCursor; | |
1342 | ||
b54ba671 VZ |
1343 | bool m_editable; // applies to whole grid |
1344 | bool m_cellEditCtrlEnabled; // is in-place edit currently shown? | |
60ff3b99 VZ |
1345 | |
1346 | ||
1347 | void Create(); | |
1348 | void Init(); | |
1349 | void CalcDimensions(); | |
7807d81c | 1350 | void CalcWindowSizes(); |
60ff3b99 VZ |
1351 | bool Redimension( wxGridTableMessage& ); |
1352 | ||
1353 | ||
b54ba671 VZ |
1354 | bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& ); |
1355 | bool SendEvent( const wxEventType, int row, int col ); | |
1356 | bool SendEvent( const wxEventType type) | |
1357 | { | |
1358 | return SendEvent(type, | |
1359 | m_currentCellCoords.GetRow(), | |
1360 | m_currentCellCoords.GetCol()); | |
1361 | } | |
60ff3b99 VZ |
1362 | |
1363 | void OnPaint( wxPaintEvent& ); | |
1364 | void OnSize( wxSizeEvent& ); | |
1365 | void OnKeyDown( wxKeyEvent& ); | |
2796cce3 | 1366 | void OnEraseBackground( wxEraseEvent& ); |
60ff3b99 VZ |
1367 | |
1368 | ||
1369 | void SetCurrentCell( const wxGridCellCoords& coords ); | |
1370 | void SetCurrentCell( int row, int col ) | |
1371 | { SetCurrentCell( wxGridCellCoords(row, col) ); } | |
1372 | ||
1373 | ||
1374 | // ------ functions to get/send data (see also public functions) | |
1375 | // | |
1376 | bool GetModelValues(); | |
1377 | bool SetModelValues(); | |
1378 | ||
1379 | ||
2d66e025 | 1380 | DECLARE_DYNAMIC_CLASS( wxGrid ) |
f85afd4e MB |
1381 | DECLARE_EVENT_TABLE() |
1382 | }; | |
1383 | ||
1384 | ||
f2d76237 | 1385 | |
43947979 VZ |
1386 | // ---------------------------------------------------------------------------- |
1387 | // Grid event class and event types | |
1388 | // ---------------------------------------------------------------------------- | |
f85afd4e MB |
1389 | |
1390 | class WXDLLEXPORT wxGridEvent : public wxNotifyEvent | |
1391 | { | |
60ff3b99 | 1392 | public: |
f85afd4e MB |
1393 | wxGridEvent() |
1394 | : wxNotifyEvent(), m_row(-1), m_col(-1), m_x(-1), m_y(-1), | |
1395 | m_control(0), m_meta(0), m_shift(0), m_alt(0) | |
1396 | { | |
1397 | } | |
1398 | ||
1399 | wxGridEvent(int id, wxEventType type, wxObject* obj, | |
1400 | int row=-1, int col=-1, int x=-1, int y=-1, | |
1401 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); | |
1402 | ||
1403 | virtual int GetRow() { return m_row; } | |
1404 | virtual int GetCol() { return m_col; } | |
1405 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
1406 | bool ControlDown() { return m_control; } | |
1407 | bool MetaDown() { return m_meta; } | |
1408 | bool ShiftDown() { return m_shift; } | |
1409 | bool AltDown() { return m_alt; } | |
2d66e025 | 1410 | |
60ff3b99 VZ |
1411 | protected: |
1412 | int m_row; | |
1413 | int m_col; | |
f85afd4e MB |
1414 | int m_x; |
1415 | int m_y; | |
1416 | bool m_control; | |
1417 | bool m_meta; | |
1418 | bool m_shift; | |
1419 | bool m_alt; | |
60ff3b99 VZ |
1420 | |
1421 | DECLARE_DYNAMIC_CLASS(wxGridEvent) | |
1422 | }; | |
1423 | ||
60ff3b99 VZ |
1424 | class WXDLLEXPORT wxGridSizeEvent : public wxNotifyEvent |
1425 | { | |
1426 | public: | |
f85afd4e MB |
1427 | wxGridSizeEvent() |
1428 | : wxNotifyEvent(), m_rowOrCol(-1), m_x(-1), m_y(-1), | |
1429 | m_control(0), m_meta(0), m_shift(0), m_alt(0) | |
1430 | { | |
1431 | } | |
1432 | ||
1433 | wxGridSizeEvent(int id, wxEventType type, wxObject* obj, | |
1434 | int rowOrCol=-1, int x=-1, int y=-1, | |
1435 | bool control=FALSE, bool shift=FALSE, bool alt=FALSE, bool meta=FALSE); | |
1436 | ||
1437 | int GetRowOrCol() { return m_rowOrCol; } | |
1438 | wxPoint GetPosition() { return wxPoint( m_x, m_y ); } | |
1439 | bool ControlDown() { return m_control; } | |
1440 | bool MetaDown() { return m_meta; } | |
1441 | bool ShiftDown() { return m_shift; } | |
1442 | bool AltDown() { return m_alt; } | |
2d66e025 | 1443 | |
60ff3b99 VZ |
1444 | protected: |
1445 | int m_rowOrCol; | |
1446 | int m_x; | |
1447 | int m_y; | |
1448 | bool m_control; | |
1449 | bool m_meta; | |
1450 | bool m_shift; | |
1451 | bool m_alt; | |
1452 | ||
2d66e025 | 1453 | DECLARE_DYNAMIC_CLASS(wxGridSizeEvent) |
f85afd4e MB |
1454 | }; |
1455 | ||
1456 | ||
1457 | class WXDLLEXPORT wxGridRangeSelectEvent : public wxNotifyEvent | |
1458 | { | |
60ff3b99 | 1459 | public: |
f85afd4e | 1460 | wxGridRangeSelectEvent() |
60ff3b99 VZ |
1461 | : wxNotifyEvent() |
1462 | { | |
1463 | m_topLeft = wxGridNoCellCoords; | |
1464 | m_bottomRight = wxGridNoCellCoords; | |
1465 | m_control = FALSE; | |
1466 | m_meta = FALSE; | |
1467 | m_shift = FALSE; | |
1468 | m_alt = FALSE; | |
1469 | } | |
f85afd4e MB |
1470 | |
1471 | wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj, | |
60ff3b99 VZ |
1472 | const wxGridCellCoords& topLeft, |
1473 | const wxGridCellCoords& bottomRight, | |
1474 | bool control=FALSE, bool shift=FALSE, | |
1475 | bool alt=FALSE, bool meta=FALSE); | |
f85afd4e MB |
1476 | |
1477 | wxGridCellCoords GetTopLeftCoords() { return m_topLeft; } | |
1478 | wxGridCellCoords GetBottomRightCoords() { return m_bottomRight; } | |
1479 | int GetTopRow() { return m_topLeft.GetRow(); } | |
1480 | int GetBottomRow() { return m_bottomRight.GetRow(); } | |
1481 | int GetLeftCol() { return m_topLeft.GetCol(); } | |
1482 | int GetRightCol() { return m_bottomRight.GetCol(); } | |
1483 | bool ControlDown() { return m_control; } | |
1484 | bool MetaDown() { return m_meta; } | |
1485 | bool ShiftDown() { return m_shift; } | |
1486 | bool AltDown() { return m_alt; } | |
2d66e025 | 1487 | |
60ff3b99 VZ |
1488 | protected: |
1489 | wxGridCellCoords m_topLeft; | |
1490 | wxGridCellCoords m_bottomRight; | |
1491 | bool m_control; | |
1492 | bool m_meta; | |
1493 | bool m_shift; | |
1494 | bool m_alt; | |
1495 | ||
2d66e025 | 1496 | DECLARE_DYNAMIC_CLASS(wxGridRangeSelectEvent) |
f85afd4e MB |
1497 | }; |
1498 | ||
b54ba671 VZ |
1499 | // TODO move to wx/event.h |
1500 | const wxEventType wxEVT_GRID_CELL_LEFT_CLICK = wxEVT_FIRST + 1580; | |
1501 | const wxEventType wxEVT_GRID_CELL_RIGHT_CLICK = wxEVT_FIRST + 1581; | |
1502 | const wxEventType wxEVT_GRID_CELL_LEFT_DCLICK = wxEVT_FIRST + 1582; | |
1503 | const wxEventType wxEVT_GRID_CELL_RIGHT_DCLICK = wxEVT_FIRST + 1583; | |
1504 | const wxEventType wxEVT_GRID_LABEL_LEFT_CLICK = wxEVT_FIRST + 1584; | |
1505 | const wxEventType wxEVT_GRID_LABEL_RIGHT_CLICK = wxEVT_FIRST + 1585; | |
1506 | const wxEventType wxEVT_GRID_LABEL_LEFT_DCLICK = wxEVT_FIRST + 1586; | |
1507 | const wxEventType wxEVT_GRID_LABEL_RIGHT_DCLICK = wxEVT_FIRST + 1587; | |
1508 | const wxEventType wxEVT_GRID_ROW_SIZE = wxEVT_FIRST + 1588; | |
1509 | const wxEventType wxEVT_GRID_COL_SIZE = wxEVT_FIRST + 1589; | |
1510 | const wxEventType wxEVT_GRID_RANGE_SELECT = wxEVT_FIRST + 1590; | |
1511 | const wxEventType wxEVT_GRID_CELL_CHANGE = wxEVT_FIRST + 1591; | |
1512 | const wxEventType wxEVT_GRID_SELECT_CELL = wxEVT_FIRST + 1592; | |
1513 | const wxEventType wxEVT_GRID_EDITOR_SHOWN = wxEVT_FIRST + 1593; | |
1514 | const wxEventType wxEVT_GRID_EDITOR_HIDDEN = wxEVT_FIRST + 1594; | |
749692cc | 1515 | |
f85afd4e MB |
1516 | |
1517 | typedef void (wxEvtHandler::*wxGridEventFunction)(wxGridEvent&); | |
1518 | typedef void (wxEvtHandler::*wxGridSizeEventFunction)(wxGridSizeEvent&); | |
1519 | typedef void (wxEvtHandler::*wxGridRangeSelectEventFunction)(wxGridRangeSelectEvent&); | |
1520 | ||
b54ba671 VZ |
1521 | #define EVT_GRID_CELL_LEFT_CLICK(fn) { wxEVT_GRID_CELL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
1522 | #define EVT_GRID_CELL_RIGHT_CLICK(fn) { wxEVT_GRID_CELL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1523 | #define EVT_GRID_CELL_LEFT_DCLICK(fn) { wxEVT_GRID_CELL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1524 | #define EVT_GRID_CELL_RIGHT_DCLICK(fn) { wxEVT_GRID_CELL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1525 | #define EVT_GRID_LABEL_LEFT_CLICK(fn) { wxEVT_GRID_LABEL_LEFT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1526 | #define EVT_GRID_LABEL_RIGHT_CLICK(fn) { wxEVT_GRID_LABEL_RIGHT_CLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1527 | #define EVT_GRID_LABEL_LEFT_DCLICK(fn) { wxEVT_GRID_LABEL_LEFT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1528 | #define EVT_GRID_LABEL_RIGHT_DCLICK(fn) { wxEVT_GRID_LABEL_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1529 | #define EVT_GRID_ROW_SIZE(fn) { wxEVT_GRID_ROW_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL }, | |
1530 | #define EVT_GRID_COL_SIZE(fn) { wxEVT_GRID_COL_SIZE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridSizeEventFunction) &fn, NULL }, | |
1531 | #define EVT_GRID_RANGE_SELECT(fn) { wxEVT_GRID_RANGE_SELECT, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridRangeSelectEventFunction) &fn, NULL }, | |
1532 | #define EVT_GRID_CELL_CHANGE(fn) { wxEVT_GRID_CELL_CHANGE, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1533 | #define EVT_GRID_SELECT_CELL(fn) { wxEVT_GRID_SELECT_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1534 | #define EVT_GRID_EDITOR_SHOWN(fn) { wxEVT_GRID_EDITOR_SHOWN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1535 | #define EVT_GRID_EDITOR_HIDDEN(fn) { wxEVT_GRID_EDITOR_HIDDEN, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
f85afd4e MB |
1536 | |
1537 | ||
1538 | #if 0 // TODO: implement these ? others ? | |
1539 | ||
b54ba671 VZ |
1540 | const wxEventType wxEVT_GRID_CREATE_CELL = wxEVT_FIRST + 1576; |
1541 | const wxEventType wxEVT_GRID_CHANGE_LABELS = wxEVT_FIRST + 1577; | |
1542 | const wxEventType wxEVT_GRID_CHANGE_SEL_LABEL = wxEVT_FIRST + 1578; | |
f85afd4e | 1543 | |
b54ba671 VZ |
1544 | #define EVT_GRID_CREATE_CELL(fn) { wxEVT_GRID_CREATE_CELL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, |
1545 | #define EVT_GRID_CHANGE_LABELS(fn) { wxEVT_GRID_CHANGE_LABELS, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
1546 | #define EVT_GRID_CHANGE_SEL_LABEL(fn) { wxEVT_GRID_CHANGE_SEL_LABEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxGridEventFunction) &fn, NULL }, | |
f85afd4e MB |
1547 | |
1548 | #endif | |
1549 | ||
1550 | #endif // #ifndef __WXGRID_H__ | |
1551 | ||
1552 | #endif // ifndef wxUSE_NEW_GRID | |
8fb66724 | 1553 |