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