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