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