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