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