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