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