1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/private/grid.h
3 // Purpose: Private wxGrid structures
4 // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)
5 // Modified by: Santiago Palacios
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRID_PRIVATE_H_
13 #define _WX_GENERIC_GRID_PRIVATE_H_
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
23 WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridCellAttr
*, wxArrayAttrs
,
24 class WXDLLIMPEXP_ADV
);
26 struct wxGridCellWithAttr
28 wxGridCellWithAttr(int row
, int col
, wxGridCellAttr
*attr_
)
29 : coords(row
, col
), attr(attr_
)
34 wxGridCellWithAttr(const wxGridCellWithAttr
& other
)
35 : coords(other
.coords
),
41 wxGridCellWithAttr
& operator=(const wxGridCellWithAttr
& other
)
43 coords
= other
.coords
;
44 if (attr
!= other
.attr
)
53 void ChangeAttr(wxGridCellAttr
* new_attr
)
57 // "Delete" (i.e. DecRef) the old attribute.
60 // Take ownership of the new attribute, i.e. no IncRef.
69 wxGridCellCoords coords
;
73 WX_DECLARE_OBJARRAY_WITH_DECL(wxGridCellWithAttr
, wxGridCellWithAttrArray
,
74 class WXDLLIMPEXP_ADV
);
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 // header column providing access to the column information stored in wxGrid
82 // via wxHeaderColumn interface
83 class wxGridHeaderColumn
: public wxHeaderColumn
86 wxGridHeaderColumn(wxGrid
*grid
, int col
)
92 virtual wxString
GetTitle() const { return m_grid
->GetColLabelValue(m_col
); }
93 virtual wxBitmap
GetBitmap() const { return wxNullBitmap
; }
94 virtual int GetWidth() const { return m_grid
->GetColSize(m_col
); }
95 virtual int GetMinWidth() const { return 0; }
96 virtual wxAlignment
GetAlignment() const
100 m_grid
->GetColLabelAlignment(&horz
, &vert
);
102 return static_cast<wxAlignment
>(horz
);
105 virtual int GetFlags() const
107 // we can't know in advance whether we can sort by this column or not
108 // with wxGrid API so suppose we can by default
109 int flags
= wxCOL_SORTABLE
;
110 if ( m_grid
->CanDragColSize(m_col
) )
111 flags
|= wxCOL_RESIZABLE
;
112 if ( m_grid
->CanDragColMove() )
113 flags
|= wxCOL_REORDERABLE
;
114 if ( GetWidth() == 0 )
115 flags
|= wxCOL_HIDDEN
;
120 virtual bool IsSortKey() const
122 return m_grid
->IsSortingBy(m_col
);
125 virtual bool IsSortOrderAscending() const
127 return m_grid
->IsSortOrderAscending();
131 // these really should be const but are not because the column needs to be
132 // assignable to be used in a wxVector (in STL build, in non-STL build we
133 // avoid the need for this)
138 // header control retreiving column information from the grid
139 class wxGridHeaderCtrl
: public wxHeaderCtrl
142 wxGridHeaderCtrl(wxGrid
*owner
)
143 : wxHeaderCtrl(owner
,
148 (owner
->CanDragColMove() ? wxHD_ALLOW_REORDER
: 0))
153 virtual const wxHeaderColumn
& GetColumn(unsigned int idx
) const
155 return m_columns
[idx
];
159 wxGrid
*GetOwner() const { return static_cast<wxGrid
*>(GetParent()); }
161 static wxMouseEvent
GetDummyMouseEvent()
163 // make up a dummy event for the grid event to use -- unfortunately we
164 // can't do anything else here
166 e
.SetState(wxGetMouseState());
170 // override the base class method to update our m_columns array
171 virtual void OnColumnCountChanging(unsigned int count
)
173 const unsigned countOld
= m_columns
.size();
174 if ( count
< countOld
)
176 // just discard the columns which don't exist any more (notice that
177 // we can't use resize() here as it would require the vector
178 // value_type, i.e. wxGridHeaderColumn to be default constructible,
180 m_columns
.erase(m_columns
.begin() + count
, m_columns
.end());
182 else // new columns added
184 // add columns for the new elements
185 for ( unsigned n
= countOld
; n
< count
; n
++ )
186 m_columns
.push_back(wxGridHeaderColumn(GetOwner(), n
));
190 // override to implement column auto sizing
191 virtual bool UpdateColumnWidthToFit(unsigned int idx
, int widthTitle
)
193 // TODO: currently grid doesn't support computing the column best width
194 // from its contents so we just use the best label width as is
195 GetOwner()->SetColSize(idx
, widthTitle
);
200 // overridden to react to the actions using the columns popup menu
201 virtual void UpdateColumnVisibility(unsigned int idx
, bool show
)
203 GetOwner()->SetColSize(idx
, show
? wxGRID_AUTOSIZE
: 0);
205 // as this is done by the user we should notify the main program about
207 GetOwner()->SendGridSizeEvent(wxEVT_GRID_COL_SIZE
, -1, idx
,
208 GetDummyMouseEvent());
211 // overridden to react to the columns order changes in the customization
213 virtual void UpdateColumnsOrder(const wxArrayInt
& order
)
215 GetOwner()->SetColumnsOrder(order
);
219 // event handlers forwarding wxHeaderCtrl events to wxGrid
220 void OnClick(wxHeaderCtrlEvent
& event
)
222 GetOwner()->SendEvent(wxEVT_GRID_LABEL_LEFT_CLICK
,
223 -1, event
.GetColumn(),
224 GetDummyMouseEvent());
226 GetOwner()->DoColHeaderClick(event
.GetColumn());
229 void OnDoubleClick(wxHeaderCtrlEvent
& event
)
231 if ( !GetOwner()->SendEvent(wxEVT_GRID_LABEL_LEFT_DCLICK
,
232 -1, event
.GetColumn(),
233 GetDummyMouseEvent()) )
239 void OnRightClick(wxHeaderCtrlEvent
& event
)
241 if ( !GetOwner()->SendEvent(wxEVT_GRID_LABEL_RIGHT_CLICK
,
242 -1, event
.GetColumn(),
243 GetDummyMouseEvent()) )
249 void OnBeginResize(wxHeaderCtrlEvent
& event
)
251 GetOwner()->DoStartResizeCol(event
.GetColumn());
256 void OnResizing(wxHeaderCtrlEvent
& event
)
258 GetOwner()->DoUpdateResizeColWidth(event
.GetWidth());
261 void OnEndResize(wxHeaderCtrlEvent
& event
)
263 // we again need to pass a mouse event to be used for the grid event
264 // generation but we don't have it here so use a dummy one as in
265 // UpdateColumnVisibility()
267 e
.SetState(wxGetMouseState());
268 GetOwner()->DoEndDragResizeCol(e
);
273 void OnBeginReorder(wxHeaderCtrlEvent
& event
)
275 GetOwner()->DoStartMoveCol(event
.GetColumn());
278 void OnEndReorder(wxHeaderCtrlEvent
& event
)
280 GetOwner()->DoEndMoveCol(event
.GetNewOrder());
283 wxVector
<wxGridHeaderColumn
> m_columns
;
285 DECLARE_EVENT_TABLE()
286 wxDECLARE_NO_COPY_CLASS(wxGridHeaderCtrl
);
289 // common base class for various grid subwindows
290 class WXDLLIMPEXP_ADV wxGridSubwindow
: public wxWindow
293 wxGridSubwindow(wxGrid
*owner
,
294 int additionalStyle
= 0,
295 const wxString
& name
= wxPanelNameStr
)
296 : wxWindow(owner
, wxID_ANY
,
297 wxDefaultPosition
, wxDefaultSize
,
298 wxBORDER_NONE
| additionalStyle
,
304 virtual bool AcceptsFocus() const { return false; }
306 wxGrid
*GetOwner() { return m_owner
; }
309 void OnMouseCaptureLost(wxMouseCaptureLostEvent
& event
);
313 DECLARE_EVENT_TABLE()
314 wxDECLARE_NO_COPY_CLASS(wxGridSubwindow
);
317 class WXDLLIMPEXP_ADV wxGridRowLabelWindow
: public wxGridSubwindow
320 wxGridRowLabelWindow(wxGrid
*parent
)
321 : wxGridSubwindow(parent
)
327 void OnPaint( wxPaintEvent
& event
);
328 void OnMouseEvent( wxMouseEvent
& event
);
329 void OnMouseWheel( wxMouseEvent
& event
);
331 DECLARE_EVENT_TABLE()
332 wxDECLARE_NO_COPY_CLASS(wxGridRowLabelWindow
);
336 class WXDLLIMPEXP_ADV wxGridColLabelWindow
: public wxGridSubwindow
339 wxGridColLabelWindow(wxGrid
*parent
)
340 : wxGridSubwindow(parent
)
346 void OnPaint( wxPaintEvent
& event
);
347 void OnMouseEvent( wxMouseEvent
& event
);
348 void OnMouseWheel( wxMouseEvent
& event
);
350 DECLARE_EVENT_TABLE()
351 wxDECLARE_NO_COPY_CLASS(wxGridColLabelWindow
);
355 class WXDLLIMPEXP_ADV wxGridCornerLabelWindow
: public wxGridSubwindow
358 wxGridCornerLabelWindow(wxGrid
*parent
)
359 : wxGridSubwindow(parent
)
364 void OnMouseEvent( wxMouseEvent
& event
);
365 void OnMouseWheel( wxMouseEvent
& event
);
366 void OnPaint( wxPaintEvent
& event
);
368 DECLARE_EVENT_TABLE()
369 wxDECLARE_NO_COPY_CLASS(wxGridCornerLabelWindow
);
372 class WXDLLIMPEXP_ADV wxGridWindow
: public wxGridSubwindow
375 wxGridWindow(wxGrid
*parent
)
376 : wxGridSubwindow(parent
,
377 wxWANTS_CHARS
| wxCLIP_CHILDREN
,
383 virtual void ScrollWindow( int dx
, int dy
, const wxRect
*rect
);
385 virtual bool AcceptsFocus() const { return true; }
388 void OnPaint( wxPaintEvent
&event
);
389 void OnMouseWheel( wxMouseEvent
& event
);
390 void OnMouseEvent( wxMouseEvent
& event
);
391 void OnKeyDown( wxKeyEvent
& );
392 void OnKeyUp( wxKeyEvent
& );
393 void OnChar( wxKeyEvent
& );
394 void OnEraseBackground( wxEraseEvent
& );
395 void OnFocus( wxFocusEvent
& );
397 DECLARE_EVENT_TABLE()
398 wxDECLARE_NO_COPY_CLASS(wxGridWindow
);
401 // ----------------------------------------------------------------------------
402 // the internal data representation used by wxGridCellAttrProvider
403 // ----------------------------------------------------------------------------
405 // this class stores attributes set for cells
406 class WXDLLIMPEXP_ADV wxGridCellAttrData
409 void SetAttr(wxGridCellAttr
*attr
, int row
, int col
);
410 wxGridCellAttr
*GetAttr(int row
, int col
) const;
411 void UpdateAttrRows( size_t pos
, int numRows
);
412 void UpdateAttrCols( size_t pos
, int numCols
);
415 // searches for the attr for given cell, returns wxNOT_FOUND if not found
416 int FindIndex(int row
, int col
) const;
418 wxGridCellWithAttrArray m_attrs
;
421 // this class stores attributes set for rows or columns
422 class WXDLLIMPEXP_ADV wxGridRowOrColAttrData
425 // empty ctor to suppress warnings
426 wxGridRowOrColAttrData() {}
427 ~wxGridRowOrColAttrData();
429 void SetAttr(wxGridCellAttr
*attr
, int rowOrCol
);
430 wxGridCellAttr
*GetAttr(int rowOrCol
) const;
431 void UpdateAttrRowsOrCols( size_t pos
, int numRowsOrCols
);
434 wxArrayInt m_rowsOrCols
;
435 wxArrayAttrs m_attrs
;
438 // NB: this is just a wrapper around 3 objects: one which stores cell
439 // attributes, and 2 others for row/col ones
440 class WXDLLIMPEXP_ADV wxGridCellAttrProviderData
443 wxGridCellAttrData m_cellAttrs
;
444 wxGridRowOrColAttrData m_rowAttrs
,
448 // ----------------------------------------------------------------------------
449 // operations classes abstracting the difference between operating on rows and
451 // ----------------------------------------------------------------------------
453 // This class allows to write a function only once because by using its methods
454 // it will apply to both columns and rows.
456 // This is an abstract interface definition, the two concrete implementations
457 // below should be used when working with rows and columns respectively.
458 class wxGridOperations
461 // Returns the operations in the other direction, i.e. wxGridRowOperations
462 // if this object is a wxGridColumnOperations and vice versa.
463 virtual wxGridOperations
& Dual() const = 0;
465 // Return the number of rows or columns.
466 virtual int GetNumberOfLines(const wxGrid
*grid
) const = 0;
468 // Return the selection mode which allows selecting rows or columns.
469 virtual wxGrid::wxGridSelectionModes
GetSelectionMode() const = 0;
471 // Make a wxGridCellCoords from the given components: thisDir is row or
472 // column and otherDir is column or row
473 virtual wxGridCellCoords
MakeCoords(int thisDir
, int otherDir
) const = 0;
475 // Calculate the scrolled position of the given abscissa or ordinate.
476 virtual int CalcScrolledPosition(wxGrid
*grid
, int pos
) const = 0;
478 // Selects the horizontal or vertical component from the given object.
479 virtual int Select(const wxGridCellCoords
& coords
) const = 0;
480 virtual int Select(const wxPoint
& pt
) const = 0;
481 virtual int Select(const wxSize
& sz
) const = 0;
482 virtual int Select(const wxRect
& r
) const = 0;
483 virtual int& Select(wxRect
& r
) const = 0;
485 // Returns width or height of the rectangle
486 virtual int& SelectSize(wxRect
& r
) const = 0;
488 // Make a wxSize such that Select() applied to it returns first component
489 virtual wxSize
MakeSize(int first
, int second
) const = 0;
491 // Sets the row or column component of the given cell coordinates
492 virtual void Set(wxGridCellCoords
& coords
, int line
) const = 0;
495 // Draws a line parallel to the row or column, i.e. horizontal or vertical:
496 // pos is the horizontal or vertical position of the line and start and end
497 // are the coordinates of the line extremities in the other direction
499 DrawParallelLine(wxDC
& dc
, int start
, int end
, int pos
) const = 0;
501 // Draw a horizontal or vertical line across the given rectangle
502 // (this is implemented in terms of above and uses Select() to extract
503 // start and end from the given rectangle)
504 void DrawParallelLineInRect(wxDC
& dc
, const wxRect
& rect
, int pos
) const
506 const int posStart
= Select(rect
.GetPosition());
507 DrawParallelLine(dc
, posStart
, posStart
+ Select(rect
.GetSize()), pos
);
511 // Return the index of the row or column at the given pixel coordinate.
513 PosToLine(const wxGrid
*grid
, int pos
, bool clip
= false) const = 0;
515 // Get the top/left position, in pixels, of the given row or column
516 virtual int GetLineStartPos(const wxGrid
*grid
, int line
) const = 0;
518 // Get the bottom/right position, in pixels, of the given row or column
519 virtual int GetLineEndPos(const wxGrid
*grid
, int line
) const = 0;
521 // Get the height/width of the given row/column
522 virtual int GetLineSize(const wxGrid
*grid
, int line
) const = 0;
524 // Get wxGrid::m_rowBottoms/m_colRights array
525 virtual const wxArrayInt
& GetLineEnds(const wxGrid
*grid
) const = 0;
527 // Get default height row height or column width
528 virtual int GetDefaultLineSize(const wxGrid
*grid
) const = 0;
530 // Return the minimal acceptable row height or column width
531 virtual int GetMinimalAcceptableLineSize(const wxGrid
*grid
) const = 0;
533 // Return the minimal row height or column width
534 virtual int GetMinimalLineSize(const wxGrid
*grid
, int line
) const = 0;
536 // Set the row height or column width
537 virtual void SetLineSize(wxGrid
*grid
, int line
, int size
) const = 0;
539 // Set the row default height or column default width
540 virtual void SetDefaultLineSize(wxGrid
*grid
, int size
, bool resizeExisting
) const = 0;
543 // Return the index of the line at the given position
545 // NB: currently this is always identity for the rows as reordering is only
546 // implemented for the lines
547 virtual int GetLineAt(const wxGrid
*grid
, int pos
) const = 0;
549 // Return the display position of the line with the given index.
551 // NB: As GetLineAt(), currently this is always identity for rows.
552 virtual int GetLinePos(const wxGrid
*grid
, int line
) const = 0;
554 // Return the index of the line just before the given one.
555 virtual int GetLineBefore(const wxGrid
* grid
, int line
) const = 0;
557 // Get the row or column label window
558 virtual wxWindow
*GetHeaderWindow(wxGrid
*grid
) const = 0;
560 // Get the width or height of the row or column label window
561 virtual int GetHeaderWindowSize(wxGrid
*grid
) const = 0;
564 // This class is never used polymorphically but give it a virtual dtor
565 // anyhow to suppress g++ complaints about it
566 virtual ~wxGridOperations() { }
569 class wxGridRowOperations
: public wxGridOperations
572 virtual wxGridOperations
& Dual() const;
574 virtual int GetNumberOfLines(const wxGrid
*grid
) const
575 { return grid
->GetNumberRows(); }
577 virtual wxGrid::wxGridSelectionModes
GetSelectionMode() const
578 { return wxGrid::wxGridSelectRows
; }
580 virtual wxGridCellCoords
MakeCoords(int thisDir
, int otherDir
) const
581 { return wxGridCellCoords(thisDir
, otherDir
); }
583 virtual int CalcScrolledPosition(wxGrid
*grid
, int pos
) const
584 { return grid
->CalcScrolledPosition(wxPoint(pos
, 0)).x
; }
586 virtual int Select(const wxGridCellCoords
& c
) const { return c
.GetRow(); }
587 virtual int Select(const wxPoint
& pt
) const { return pt
.x
; }
588 virtual int Select(const wxSize
& sz
) const { return sz
.x
; }
589 virtual int Select(const wxRect
& r
) const { return r
.x
; }
590 virtual int& Select(wxRect
& r
) const { return r
.x
; }
591 virtual int& SelectSize(wxRect
& r
) const { return r
.width
; }
592 virtual wxSize
MakeSize(int first
, int second
) const
593 { return wxSize(first
, second
); }
594 virtual void Set(wxGridCellCoords
& coords
, int line
) const
595 { coords
.SetRow(line
); }
597 virtual void DrawParallelLine(wxDC
& dc
, int start
, int end
, int pos
) const
598 { dc
.DrawLine(start
, pos
, end
, pos
); }
600 virtual int PosToLine(const wxGrid
*grid
, int pos
, bool clip
= false) const
601 { return grid
->YToRow(pos
, clip
); }
602 virtual int GetLineStartPos(const wxGrid
*grid
, int line
) const
603 { return grid
->GetRowTop(line
); }
604 virtual int GetLineEndPos(const wxGrid
*grid
, int line
) const
605 { return grid
->GetRowBottom(line
); }
606 virtual int GetLineSize(const wxGrid
*grid
, int line
) const
607 { return grid
->GetRowHeight(line
); }
608 virtual const wxArrayInt
& GetLineEnds(const wxGrid
*grid
) const
609 { return grid
->m_rowBottoms
; }
610 virtual int GetDefaultLineSize(const wxGrid
*grid
) const
611 { return grid
->GetDefaultRowSize(); }
612 virtual int GetMinimalAcceptableLineSize(const wxGrid
*grid
) const
613 { return grid
->GetRowMinimalAcceptableHeight(); }
614 virtual int GetMinimalLineSize(const wxGrid
*grid
, int line
) const
615 { return grid
->GetRowMinimalHeight(line
); }
616 virtual void SetLineSize(wxGrid
*grid
, int line
, int size
) const
617 { grid
->SetRowSize(line
, size
); }
618 virtual void SetDefaultLineSize(wxGrid
*grid
, int size
, bool resizeExisting
) const
619 { grid
->SetDefaultRowSize(size
, resizeExisting
); }
621 virtual int GetLineAt(const wxGrid
* WXUNUSED(grid
), int pos
) const
622 { return pos
; } // TODO: implement row reordering
623 virtual int GetLinePos(const wxGrid
* WXUNUSED(grid
), int line
) const
624 { return line
; } // TODO: implement row reordering
626 virtual int GetLineBefore(const wxGrid
* WXUNUSED(grid
), int line
) const
627 { return line
? line
- 1 : line
; }
629 virtual wxWindow
*GetHeaderWindow(wxGrid
*grid
) const
630 { return grid
->GetGridRowLabelWindow(); }
631 virtual int GetHeaderWindowSize(wxGrid
*grid
) const
632 { return grid
->GetRowLabelSize(); }
635 class wxGridColumnOperations
: public wxGridOperations
638 virtual wxGridOperations
& Dual() const;
640 virtual int GetNumberOfLines(const wxGrid
*grid
) const
641 { return grid
->GetNumberCols(); }
643 virtual wxGrid::wxGridSelectionModes
GetSelectionMode() const
644 { return wxGrid::wxGridSelectColumns
; }
646 virtual wxGridCellCoords
MakeCoords(int thisDir
, int otherDir
) const
647 { return wxGridCellCoords(otherDir
, thisDir
); }
649 virtual int CalcScrolledPosition(wxGrid
*grid
, int pos
) const
650 { return grid
->CalcScrolledPosition(wxPoint(0, pos
)).y
; }
652 virtual int Select(const wxGridCellCoords
& c
) const { return c
.GetCol(); }
653 virtual int Select(const wxPoint
& pt
) const { return pt
.y
; }
654 virtual int Select(const wxSize
& sz
) const { return sz
.y
; }
655 virtual int Select(const wxRect
& r
) const { return r
.y
; }
656 virtual int& Select(wxRect
& r
) const { return r
.y
; }
657 virtual int& SelectSize(wxRect
& r
) const { return r
.height
; }
658 virtual wxSize
MakeSize(int first
, int second
) const
659 { return wxSize(second
, first
); }
660 virtual void Set(wxGridCellCoords
& coords
, int line
) const
661 { coords
.SetCol(line
); }
663 virtual void DrawParallelLine(wxDC
& dc
, int start
, int end
, int pos
) const
664 { dc
.DrawLine(pos
, start
, pos
, end
); }
666 virtual int PosToLine(const wxGrid
*grid
, int pos
, bool clip
= false) const
667 { return grid
->XToCol(pos
, clip
); }
668 virtual int GetLineStartPos(const wxGrid
*grid
, int line
) const
669 { return grid
->GetColLeft(line
); }
670 virtual int GetLineEndPos(const wxGrid
*grid
, int line
) const
671 { return grid
->GetColRight(line
); }
672 virtual int GetLineSize(const wxGrid
*grid
, int line
) const
673 { return grid
->GetColWidth(line
); }
674 virtual const wxArrayInt
& GetLineEnds(const wxGrid
*grid
) const
675 { return grid
->m_colRights
; }
676 virtual int GetDefaultLineSize(const wxGrid
*grid
) const
677 { return grid
->GetDefaultColSize(); }
678 virtual int GetMinimalAcceptableLineSize(const wxGrid
*grid
) const
679 { return grid
->GetColMinimalAcceptableWidth(); }
680 virtual int GetMinimalLineSize(const wxGrid
*grid
, int line
) const
681 { return grid
->GetColMinimalWidth(line
); }
682 virtual void SetLineSize(wxGrid
*grid
, int line
, int size
) const
683 { grid
->SetColSize(line
, size
); }
684 virtual void SetDefaultLineSize(wxGrid
*grid
, int size
, bool resizeExisting
) const
685 { grid
->SetDefaultColSize(size
, resizeExisting
); }
687 virtual int GetLineAt(const wxGrid
*grid
, int pos
) const
688 { return grid
->GetColAt(pos
); }
689 virtual int GetLinePos(const wxGrid
*grid
, int line
) const
690 { return grid
->GetColPos(line
); }
692 virtual int GetLineBefore(const wxGrid
* grid
, int line
) const
693 { return grid
->GetColAt(wxMax(0, grid
->GetColPos(line
) - 1)); }
695 virtual wxWindow
*GetHeaderWindow(wxGrid
*grid
) const
696 { return grid
->GetGridColLabelWindow(); }
697 virtual int GetHeaderWindowSize(wxGrid
*grid
) const
698 { return grid
->GetColLabelSize(); }
701 // This class abstracts the difference between operations going forward
702 // (down/right) and backward (up/left) and allows to use the same code for
703 // functions which differ only in the direction of grid traversal.
705 // Notice that all operations in this class work with display positions and not
706 // internal indices which can be different if the columns were reordered.
708 // Like wxGridOperations it's an ABC with two concrete subclasses below. Unlike
709 // it, this is a normal object and not just a function dispatch table and has a
712 // Note: the explanation of this discrepancy is the existence of (very useful)
713 // Dual() method in wxGridOperations which forces us to make wxGridOperations a
714 // function dispatcher only.
715 class wxGridDirectionOperations
718 // The oper parameter to ctor selects whether we work with rows or columns
719 wxGridDirectionOperations(wxGrid
*grid
, const wxGridOperations
& oper
)
725 // Check if the component of this point in our direction is at the
726 // boundary, i.e. is the first/last row/column
727 virtual bool IsAtBoundary(const wxGridCellCoords
& coords
) const = 0;
729 // Increment the component of this point in our direction
730 virtual void Advance(wxGridCellCoords
& coords
) const = 0;
732 // Find the line at the given distance, in pixels, away from this one
733 // (this uses clipping, i.e. anything after the last line is counted as the
734 // last one and anything before the first one as 0)
736 // TODO: Implementation of this method currently doesn't support column
737 // reordering as it mixes up indices and positions. But this doesn't
738 // really matter as it's only called for rows (Page Up/Down only work
739 // vertically) and row reordering is not currently supported. We'd
740 // need to fix it if this ever changes however.
741 virtual int MoveByPixelDistance(int line
, int distance
) const = 0;
743 // This class is never used polymorphically but give it a virtual dtor
744 // anyhow to suppress g++ complaints about it
745 virtual ~wxGridDirectionOperations() { }
748 // Get the position of the row or column from the given coordinates pair.
750 // This is just a shortcut to avoid repeating m_oper and m_grid multiple
751 // times in the derived classes code.
752 int GetLinePos(const wxGridCellCoords
& coords
) const
754 return m_oper
.GetLinePos(m_grid
, m_oper
.Select(coords
));
757 // Get the index of the row or column from the position.
758 int GetLineAt(int pos
) const
760 return m_oper
.GetLineAt(m_grid
, pos
);
763 // Check if the given line is visible, i.e. has non 0 size.
764 bool IsLineVisible(int line
) const
766 return m_oper
.GetLineSize(m_grid
, line
) != 0;
770 wxGrid
* const m_grid
;
771 const wxGridOperations
& m_oper
;
774 class wxGridBackwardOperations
: public wxGridDirectionOperations
777 wxGridBackwardOperations(wxGrid
*grid
, const wxGridOperations
& oper
)
778 : wxGridDirectionOperations(grid
, oper
)
782 virtual bool IsAtBoundary(const wxGridCellCoords
& coords
) const
784 wxASSERT_MSG( m_oper
.Select(coords
) >= 0, "invalid row/column" );
786 int pos
= GetLinePos(coords
);
789 // Check the previous line.
790 int line
= GetLineAt(--pos
);
791 if ( IsLineVisible(line
) )
793 // There is another visible line before this one, hence it's
799 // We reached the boundary without finding any visible lines.
803 virtual void Advance(wxGridCellCoords
& coords
) const
805 int pos
= GetLinePos(coords
);
808 // This is not supposed to happen if IsAtBoundary() returned false.
809 wxCHECK_RET( pos
, "can't advance when already at boundary" );
811 int line
= GetLineAt(--pos
);
812 if ( IsLineVisible(line
) )
814 m_oper
.Set(coords
, line
);
820 virtual int MoveByPixelDistance(int line
, int distance
) const
822 int pos
= m_oper
.GetLineStartPos(m_grid
, line
);
823 return m_oper
.PosToLine(m_grid
, pos
- distance
+ 1, true);
827 // Please refer to the comments above when reading this class code, it's
828 // absolutely symmetrical to wxGridBackwardOperations.
829 class wxGridForwardOperations
: public wxGridDirectionOperations
832 wxGridForwardOperations(wxGrid
*grid
, const wxGridOperations
& oper
)
833 : wxGridDirectionOperations(grid
, oper
),
834 m_numLines(oper
.GetNumberOfLines(grid
))
838 virtual bool IsAtBoundary(const wxGridCellCoords
& coords
) const
840 wxASSERT_MSG( m_oper
.Select(coords
) < m_numLines
, "invalid row/column" );
842 int pos
= GetLinePos(coords
);
843 while ( pos
< m_numLines
- 1 )
845 int line
= GetLineAt(++pos
);
846 if ( IsLineVisible(line
) )
853 virtual void Advance(wxGridCellCoords
& coords
) const
855 int pos
= GetLinePos(coords
);
858 wxCHECK_RET( pos
< m_numLines
- 1,
859 "can't advance when already at boundary" );
861 int line
= GetLineAt(++pos
);
862 if ( IsLineVisible(line
) )
864 m_oper
.Set(coords
, line
);
870 virtual int MoveByPixelDistance(int line
, int distance
) const
872 int pos
= m_oper
.GetLineStartPos(m_grid
, line
);
873 return m_oper
.PosToLine(m_grid
, pos
+ distance
, true);
877 const int m_numLines
;
880 // ----------------------------------------------------------------------------
881 // data structures used for the data type registry
882 // ----------------------------------------------------------------------------
884 struct wxGridDataTypeInfo
886 wxGridDataTypeInfo(const wxString
& typeName
,
887 wxGridCellRenderer
* renderer
,
888 wxGridCellEditor
* editor
)
889 : m_typeName(typeName
), m_renderer(renderer
), m_editor(editor
)
892 ~wxGridDataTypeInfo()
894 wxSafeDecRef(m_renderer
);
895 wxSafeDecRef(m_editor
);
899 wxGridCellRenderer
* m_renderer
;
900 wxGridCellEditor
* m_editor
;
902 wxDECLARE_NO_COPY_CLASS(wxGridDataTypeInfo
);
906 WX_DEFINE_ARRAY_WITH_DECL_PTR(wxGridDataTypeInfo
*, wxGridDataTypeInfoArray
,
907 class WXDLLIMPEXP_ADV
);
910 class WXDLLIMPEXP_ADV wxGridTypeRegistry
913 wxGridTypeRegistry() {}
914 ~wxGridTypeRegistry();
916 void RegisterDataType(const wxString
& typeName
,
917 wxGridCellRenderer
* renderer
,
918 wxGridCellEditor
* editor
);
920 // find one of already registered data types
921 int FindRegisteredDataType(const wxString
& typeName
);
923 // try to FindRegisteredDataType(), if this fails and typeName is one of
924 // standard typenames, register it and return its index
925 int FindDataType(const wxString
& typeName
);
927 // try to FindDataType(), if it fails see if it is not one of already
928 // registered data types with some params in which case clone the
929 // registered data type and set params for it
930 int FindOrCloneDataType(const wxString
& typeName
);
932 wxGridCellRenderer
* GetRenderer(int index
);
933 wxGridCellEditor
* GetEditor(int index
);
936 wxGridDataTypeInfoArray m_typeinfo
;
940 #endif // _WX_GENERIC_GRID_PRIVATE_H_