/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/include/wx/generic/grid.h
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/include/wx/generic/grid.h

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22