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