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