1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGenericGrid
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "gridg.h"
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
30 #include "wx/string.h"
31 #include "wx/generic/gridg.h"
32 #include "wx/settings.h"
34 // Set to zero to use no double-buffering
36 #define USE_DOUBLE_BUFFERING 1
38 #define USE_DOUBLE_BUFFERING 0
41 #define wxGRID_DRAG_NONE 0
42 #define wxGRID_DRAG_LEFT_RIGHT 1
43 #define wxGRID_DRAG_UP_DOWN 2
45 IMPLEMENT_DYNAMIC_CLASS(wxGenericGrid
, wxPanel
)
47 BEGIN_EVENT_TABLE(wxGenericGrid
, wxPanel
)
48 EVT_SIZE(wxGenericGrid::OnSize
)
49 EVT_PAINT(wxGenericGrid::OnPaint
)
50 EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground
)
51 EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent
)
52 EVT_TEXT(wxGRID_TEXT_CTRL
, wxGenericGrid::OnText
)
53 EVT_COMMAND_SCROLL(wxGRID_HSCROLL
, wxGenericGrid::OnGridScroll
)
54 EVT_COMMAND_SCROLL(wxGRID_VSCROLL
, wxGenericGrid::OnGridScroll
)
57 wxGenericGrid::wxGenericGrid(void)
62 m_cellTextColour
= *wxBLACK
;
63 m_cellBackgroundColour
= *wxWHITE
;
64 m_labelTextColour
= *wxBLACK
;
65 m_labelBackgroundColour
= *wxLIGHT_GREY
;
66 m_labelBackgroundBrush
= NULL
;
67 m_labelTextFont
= NULL
;
68 m_cellTextFont
= NULL
;
70 m_currentRectVisible
= FALSE
;
72 #if defined(__WIN95__)
73 m_scrollWidth
= wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X
);
77 m_dragStatus
= wxGRID_DRAG_NONE
;
79 m_dragStartPosition
= 0;
80 m_dragLastPosition
= 0;
82 m_leftOfSheet
= wxGRID_DEFAULT_SHEET_LEFT
;
83 m_topOfSheet
= wxGRID_DEFAULT_SHEET_TOP
;
84 m_cellHeight
= wxGRID_DEFAULT_CELL_HEIGHT
;
86 m_totalGridHeight
= 0;
89 m_verticalLabelWidth
= wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH
;
90 m_horizontalLabelHeight
= wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT
;
91 m_verticalLabelAlignment
= wxCENTRE
;
92 m_horizontalLabelAlignment
= wxCENTRE
;
93 m_editControlPosition
.x
= wxGRID_DEFAULT_EDIT_X
;
94 m_editControlPosition
.y
= wxGRID_DEFAULT_EDIT_Y
;
95 m_editControlPosition
.width
= wxGRID_DEFAULT_EDIT_WIDTH
;
96 m_editControlPosition
.height
= wxGRID_DEFAULT_EDIT_HEIGHT
;
101 m_editCreated
= FALSE
;
105 m_rowLabelCells
= NULL
;
106 m_colLabelCells
= NULL
;
108 m_horizontalSashCursor
= NULL
;
109 m_verticalSashCursor
= NULL
;
112 bool wxGenericGrid::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
113 long style
, const wxString
& name
)
116 m_editingPanel
= NULL
;
119 m_horizontalSashCursor
= NULL
;
120 m_verticalSashCursor
= NULL
;
121 m_cellTextColour
= *wxBLACK
;
122 m_cellBackgroundColour
= *wxWHITE
;
123 m_labelTextColour
= *wxBLACK
;
124 m_labelBackgroundColour
= *wxLIGHT_GREY
;
125 m_labelBackgroundBrush
= NULL
;
126 m_labelTextFont
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
127 m_cellTextFont
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
129 m_currentRectVisible
= FALSE
;
131 #if defined(__WIN95__)
132 m_scrollWidth
= wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X
);
136 m_dragStatus
= wxGRID_DRAG_NONE
;
138 m_dragStartPosition
= 0;
139 m_dragLastPosition
= 0;
140 m_divisionPen
= wxThePenList
->FindOrCreatePen("LIGHT GREY", 1, wxSOLID
);
141 m_doubleBufferingBitmap
= NULL
;
143 if (!m_horizontalSashCursor
)
145 m_horizontalSashCursor
= new wxCursor(wxCURSOR_SIZEWE
);
146 m_verticalSashCursor
= new wxCursor(wxCURSOR_SIZENS
);
149 SetLabelBackgroundColour(m_labelBackgroundColour
);
151 m_leftOfSheet
= wxGRID_DEFAULT_SHEET_LEFT
;
152 m_topOfSheet
= wxGRID_DEFAULT_SHEET_TOP
;
153 m_cellHeight
= wxGRID_DEFAULT_CELL_HEIGHT
;
154 m_totalGridWidth
= 0;
155 m_totalGridHeight
= 0;
159 m_verticalLabelWidth
= wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH
;
160 m_horizontalLabelHeight
= wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT
;
161 m_verticalLabelAlignment
= wxCENTRE
;
162 m_horizontalLabelAlignment
= wxCENTRE
;
163 m_editControlPosition
.x
= wxGRID_DEFAULT_EDIT_X
;
164 m_editControlPosition
.y
= wxGRID_DEFAULT_EDIT_Y
;
165 m_editControlPosition
.width
= wxGRID_DEFAULT_EDIT_WIDTH
;
166 m_editControlPosition
.height
= wxGRID_DEFAULT_EDIT_HEIGHT
;
174 /* Store the rect. coordinates for the current cell */
175 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
177 m_editCreated
= FALSE
;
182 m_rowLabelCells
= NULL
;
183 m_colLabelCells
= NULL
;
186 wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
188 m_editingPanel
= new wxPanel(this);
190 m_textItem
= new wxTextCtrl(m_editingPanel
, wxGRID_TEXT_CTRL
, "",
191 wxPoint(m_editControlPosition
.x
, m_editControlPosition
.y
), wxSize(m_editControlPosition
.width
, -1),
193 m_textItem
->Show(TRUE
);
194 m_textItem
->SetFocus();
195 int controlW
, controlH
;
197 m_textItem
->GetSize(&controlW
, &controlH
);
198 m_editControlPosition
.height
= controlH
;
200 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
202 m_editCreated
= TRUE
;
204 m_hScrollBar
= new wxScrollBar(this, wxGRID_HSCROLL
, wxPoint(0, 0), wxSize(20, 100), wxHORIZONTAL
);
205 m_vScrollBar
= new wxScrollBar(this, wxGRID_VSCROLL
, wxPoint(0, 0), wxSize(100, 20), wxVERTICAL
);
210 wxGenericGrid::~wxGenericGrid(void)
215 void wxGenericGrid::ClearGrid(void)
220 for (i
= 0; i
< m_totalRows
; i
++)
222 for (j
= 0; j
< m_totalCols
; j
++)
223 if (m_gridCells
[i
][j
])
224 delete m_gridCells
[i
][j
];
225 delete[] m_gridCells
[i
];
227 delete[] m_gridCells
;
231 delete[] m_colWidths
;
234 delete[] m_rowHeights
;
239 for (i
= 0; i
< m_totalRows
; i
++)
240 delete m_rowLabelCells
[i
];
241 delete[] m_rowLabelCells
;
242 m_rowLabelCells
= NULL
;
246 for (i
= 0; i
< m_totalCols
; i
++)
247 delete m_colLabelCells
[i
];
248 delete[] m_colLabelCells
;
249 m_colLabelCells
= NULL
;
251 if (m_doubleBufferingBitmap
)
253 delete m_doubleBufferingBitmap
;
254 m_doubleBufferingBitmap
= NULL
;
258 bool wxGenericGrid::CreateGrid(int nRows
, int nCols
, wxString
**cellValues
, short *widths
,
259 short defaultWidth
, short defaultHeight
)
265 m_colWidths
= new short[nCols
];
266 m_rowHeights
= new short[nRows
];
267 for (i
= 0; i
< nCols
; i
++)
269 m_colWidths
[i
] = widths
[i
];
271 m_colWidths
[i
] = defaultWidth
;
272 for (i
= 0; i
< nRows
; i
++)
273 m_rowHeights
[i
] = defaultHeight
;
275 m_gridCells
= new wxGridCell
**[nRows
];
277 for (i
= 0; i
< nRows
; i
++)
278 m_gridCells
[i
] = new wxGridCell
*[nCols
];
280 for (i
= 0; i
< nRows
; i
++)
281 for (j
= 0; j
< nCols
; j
++)
284 m_gridCells
[i
][j
] = OnCreateCell();
285 m_gridCells
[i
][j
]->SetTextValue(cellValues
[i
][j
]);
288 m_gridCells
[i
][j
] = NULL
;
290 m_rowLabelCells
= new wxGridCell
*[nRows
];
291 for (i
= 0; i
< nRows
; i
++)
292 m_rowLabelCells
[i
] = new wxGridCell(this);
293 m_colLabelCells
= new wxGridCell
*[nCols
];
294 for (i
= 0; i
< nCols
; i
++)
295 m_colLabelCells
[i
] = new wxGridCell(this);
297 m_wCursorRow
= m_wCursorColumn
= 0;
298 SetCurrentRect(0, 0);
300 // Need to determine various dimensions
304 int objectSizeX
= m_totalCols
;
306 int viewLengthX
= m_totalCols
;
307 m_hScrollBar
->SetViewLength(viewLengthX
);
308 m_hScrollBar
->SetObjectLength(objectSizeX
);
309 m_hScrollBar
->SetPageSize(pageSizeX
);
311 int objectSizeY
= m_totalRows
;
313 int viewLengthY
= m_totalRows
;
315 m_vScrollBar
->SetViewLength(viewLengthY
);
316 m_vScrollBar
->SetObjectLength(objectSizeY
);
317 m_vScrollBar
->SetPageSize(pageSizeY
);
322 OnChangeSelectionLabel();
327 // Need to determine various dimensions
328 void wxGenericGrid::UpdateDimensions(void)
330 int canvasWidth
, canvasHeight
;
331 GetSize(&canvasWidth
, &canvasHeight
);
333 if (m_editCreated
&& m_editable
)
335 int controlW
, controlH
;
336 GetTextItem()->GetSize(&controlW
, &controlH
);
337 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
341 m_rightOfSheet
= m_leftOfSheet
+ m_verticalLabelWidth
;
343 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
345 if (m_rightOfSheet
> canvasWidth
)
348 m_rightOfSheet
+= m_colWidths
[i
];
350 m_bottomOfSheet
= m_topOfSheet
+ m_horizontalLabelHeight
;
351 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
353 if (m_bottomOfSheet
> canvasHeight
)
356 m_bottomOfSheet
+= m_rowHeights
[i
];
359 m_totalGridWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
360 for (i
= 0; i
< m_totalCols
; i
++)
362 m_totalGridWidth
+= m_colWidths
[i
];
364 m_totalGridHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
365 for (i
= 0; i
< m_totalRows
; i
++)
367 m_totalGridHeight
+= m_rowHeights
[i
];
371 wxGridCell
*wxGenericGrid::GetCell(int row
, int col
)
376 if ((row
>= m_totalRows
) || (col
>= m_totalCols
))
379 wxGridCell
*cell
= m_gridCells
[row
][col
];
382 m_gridCells
[row
][col
] = OnCreateCell();
383 return m_gridCells
[row
][col
];
389 void wxGenericGrid::SetGridClippingRegion(wxDC
*dc
)
391 int m_scrollWidthHoriz
= 0;
392 int m_scrollWidthVert
= 0;
394 GetClientSize(&cw
, &ch
);
396 if (m_hScrollBar
&& m_hScrollBar
->IsShown())
397 m_scrollWidthHoriz
= m_scrollWidth
;
398 if (m_vScrollBar
&& m_vScrollBar
->IsShown())
399 m_scrollWidthVert
= m_scrollWidth
;
401 // Don't paint over the scrollbars
402 dc
->SetClippingRegion(m_leftOfSheet
, m_topOfSheet
,
403 cw
- m_scrollWidthVert
- m_leftOfSheet
, ch
- m_scrollWidthHoriz
- m_topOfSheet
);
406 void wxGenericGrid::OnPaint(wxPaintEvent
& WXUNUSED(event
))
410 GetClientSize(&w
, &h
);
412 bool useDoubleBuffering
= (bool) USE_DOUBLE_BUFFERING
;
413 if (useDoubleBuffering
)
415 // Reuse the old bitmap if possible
417 if (!m_doubleBufferingBitmap
||
418 (m_doubleBufferingBitmap
->GetWidth() < w
|| m_doubleBufferingBitmap
->GetHeight() < h
))
420 if (m_doubleBufferingBitmap
)
421 delete m_doubleBufferingBitmap
;
422 m_doubleBufferingBitmap
= new wxBitmap(w
, h
);
424 if (!m_doubleBufferingBitmap
|| !m_doubleBufferingBitmap
->Ok())
426 // If we couldn't create a new bitmap, perhaps because resources were low,
427 // then don't complain, just don't double-buffer
428 if (m_doubleBufferingBitmap
)
429 delete m_doubleBufferingBitmap
;
430 m_doubleBufferingBitmap
= NULL
;
431 useDoubleBuffering
= FALSE
;
435 if (useDoubleBuffering
)
437 wxPaintDC
paintDC(this);
438 wxMemoryDC
dc(& paintDC
);
439 dc
.SelectObject(* m_doubleBufferingBitmap
);
443 int vertScrollBarWidth
= m_scrollWidth
;
444 int horizScrollBarHeight
= m_scrollWidth
;
445 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
446 vertScrollBarWidth
= 0;
447 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
448 horizScrollBarHeight
= 0;
450 paintDC
.Blit(m_leftOfSheet
, m_topOfSheet
, w
- vertScrollBarWidth
- m_leftOfSheet
, h
- horizScrollBarHeight
- m_topOfSheet
,
451 &dc
, m_leftOfSheet
, m_topOfSheet
, wxCOPY
);
453 dc
.SelectObject(wxNullBitmap
);
462 void wxGenericGrid::PaintGrid(wxDC
& dc
)
465 dc
.SetOptimization(FALSE
);
467 SetGridClippingRegion(& dc
);
469 DrawLabelAreas(& dc
);
471 DrawEditableArea(& dc
);
472 DrawColumnLabels(& dc
);
477 /* Hilight present cell */
478 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
479 if (m_currentRectVisible
)
482 dc
.DestroyClippingRegion();
483 dc
.SetOptimization(TRUE
);
487 // Erase (some of) the background.
488 // Currently, a Windows-only optimisation.
489 void wxGenericGrid::OnEraseBackground(wxEraseEvent
& event
)
493 dc
.SetOptimization(FALSE
);
496 GetClientSize(& w
, & h
);
497 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
);
498 dc
.SetPen(*wxLIGHT_GREY_PEN
);
500 if (m_hScrollBar
&& m_hScrollBar
->IsShown() && m_vScrollBar
&& m_vScrollBar
->IsShown())
502 dc
.DrawRectangle(w
- m_scrollWidth
, h
- m_scrollWidth
, m_scrollWidth
, m_scrollWidth
);
505 dc
.SetOptimization(TRUE
);
510 void wxGenericGrid::DrawLabelAreas(wxDC
*dc
)
513 GetClientSize(&cw
, &ch
);
515 dc
->SetPen(*wxTRANSPARENT_PEN
);
516 // dc->SetBrush(*dc->GetBackground());
518 // Should blank out any area which isn't going to be painted over.
519 // dc->DrawRectangle(m_leftOfSheet, m_bottomOfSheet, cw - m_leftOfSheet, ch - m_bottomOfSheet);
520 // dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet);
522 // Paint the label areas
523 dc
->SetBrush(*m_labelBackgroundBrush
);
524 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1);
525 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, cw
-m_leftOfSheet
, m_horizontalLabelHeight
+ 1);
526 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1);
527 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, m_verticalLabelWidth
+ 1, ch
-m_topOfSheet
);
530 void wxGenericGrid::DrawEditableArea(wxDC
*dc
)
533 GetClientSize(&cw
, &ch
);
535 dc
->SetPen(*wxTRANSPARENT_PEN
);
536 dc
->SetBrush(*wxTheBrushList
->FindOrCreateBrush(m_cellBackgroundColour
, wxSOLID
));
537 // dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight,
538 // m_rightOfSheet-(m_leftOfSheet+m_verticalLabelWidth) + 1, m_bottomOfSheet - (m_topOfSheet+m_horizontalLabelHeight) + 1);
539 dc
->DrawRectangle(m_leftOfSheet
+m_verticalLabelWidth
, m_topOfSheet
+m_horizontalLabelHeight
,
540 cw
-(m_leftOfSheet
+m_verticalLabelWidth
), ch
- (m_topOfSheet
+m_horizontalLabelHeight
));
543 void wxGenericGrid::DrawGridLines(wxDC
*dc
)
546 GetClientSize(&cw
, &ch
);
552 dc
->SetPen(*m_divisionPen
);
554 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
556 // Draw horizontal grey lines for cells
557 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
559 if (heightCount
> ch
)
563 dc
->DrawLine(m_leftOfSheet
, heightCount
,
566 heightCount
+= m_rowHeights
[i
];
571 if (m_verticalLabelWidth
> 0)
573 dc
->SetPen(*wxBLACK_PEN
);
575 // Draw horizontal black lines for row labels
576 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
577 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
579 if (heightCount
> ch
)
583 dc
->DrawLine(m_leftOfSheet
, heightCount
,
584 m_verticalLabelWidth
, heightCount
);
586 heightCount
+= m_rowHeights
[i
];
589 // Draw a black vertical line for row number cells
590 dc
->DrawLine(m_leftOfSheet
+ m_verticalLabelWidth
, m_topOfSheet
,
591 m_leftOfSheet
+ m_verticalLabelWidth
, ch
);
592 // First vertical line
593 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
, m_leftOfSheet
, ch
);
595 dc
->SetPen(*wxWHITE_PEN
);
597 // Draw highlights on row labels
598 heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
599 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
601 if (heightCount
> ch
)
605 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
606 m_verticalLabelWidth
, heightCount
+1);
607 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
608 m_leftOfSheet
+1, heightCount
+ m_rowHeights
[i
] - 1);
609 heightCount
+= m_rowHeights
[i
];
612 // Last one - down to the floor.
613 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
614 m_verticalLabelWidth
, heightCount
+1);
615 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
616 m_leftOfSheet
+1, ch
);
622 dc
->SetPen(*m_divisionPen
);
624 // Draw vertical grey lines for cells
625 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
626 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
632 // Skip the first one
633 if (i
!= m_scrollPosX
)
635 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
636 widthCount
, m_bottomOfSheet
);
638 widthCount
+= m_colWidths
[i
];
642 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
643 widthCount
, m_bottomOfSheet
);
646 dc
->SetPen(*wxBLACK_PEN
);
648 // Draw two black horizontal lines for column number cells
650 m_leftOfSheet
, m_topOfSheet
,
652 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
+ m_horizontalLabelHeight
,
653 cw
, m_topOfSheet
+ m_horizontalLabelHeight
);
655 if (m_horizontalLabelHeight
> 0)
657 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
659 // Draw black vertical lines for column number cells
660 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
666 dc
->DrawLine(widthCount
, m_topOfSheet
,
667 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
668 widthCount
+= m_colWidths
[i
];
673 dc
->DrawLine(widthCount
, m_topOfSheet
,
674 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
677 dc
->SetPen(*wxWHITE_PEN
);
678 widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
680 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
686 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
687 widthCount
+m_colWidths
[i
], m_topOfSheet
+1);
688 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
689 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
690 widthCount
+= m_colWidths
[i
];
693 // Last one - to the right side of the canvas.
694 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
696 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
697 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
702 void wxGenericGrid::DrawColumnLabels(wxDC
*dc
)
705 GetClientSize(&cw
, &ch
);
707 if (m_horizontalLabelHeight
== 0)
713 // Draw letters for columns
714 rect
.y
= m_topOfSheet
+ 1;
715 rect
.height
= m_horizontalLabelHeight
- 1;
717 dc
->SetTextBackground(m_labelBackgroundColour
);
718 dc
->SetBackgroundMode(wxTRANSPARENT
);
719 // dc->SetTextForeground(m_labelTextColour);
721 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
722 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
728 rect
.x
= 1 + widthCount
;
729 rect
.width
= m_colWidths
[i
];
730 DrawColumnLabel(dc
, &rect
, i
);
732 widthCount
+= m_colWidths
[i
];
737 void wxGenericGrid::DrawColumnLabel(wxDC
*dc
, wxRectangle
*rect
, int col
)
739 wxGridCell
*cell
= GetLabelCell(wxHORIZONTAL
, col
);
748 dc
->SetTextForeground(GetLabelTextColour());
749 dc
->SetFont(*GetLabelTextFont());
750 if ( !cell
->GetTextValue().IsNull() )
751 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxHORIZONTAL
));
755 void wxGenericGrid::DrawRowLabels(wxDC
*dc
)
758 GetClientSize(&cw
, &ch
);
760 if (m_verticalLabelWidth
== 0)
766 // Draw numbers for rows
767 rect
.x
= m_leftOfSheet
;
768 rect
.width
= m_verticalLabelWidth
;
770 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
772 dc
->SetTextBackground(m_labelBackgroundColour
);
773 dc
->SetBackgroundMode(wxTRANSPARENT
);
775 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
777 if (heightCount
> ch
)
781 rect
.y
= 1 + heightCount
;
782 rect
.height
= m_rowHeights
[i
];
783 DrawRowLabel(dc
, &rect
, i
);
785 heightCount
+= m_rowHeights
[i
];
790 void wxGenericGrid::DrawRowLabel(wxDC
*dc
, wxRectangle
*rect
, int row
)
792 wxGridCell
*cell
= GetLabelCell(wxVERTICAL
, row
);
801 dc
->SetTextForeground(GetLabelTextColour());
802 dc
->SetFont(*GetLabelTextFont());
803 if ( !cell
->GetTextValue().IsNull() )
804 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxVERTICAL
));
808 void wxGenericGrid::DrawCells(wxDC
*dc
)
811 GetClientSize(&cw
, &ch
);
815 // Draw value corresponding to each cell
816 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
818 for (j
= m_scrollPosX
; j
< m_totalCols
; j
++)
820 SetCurrentRect(i
, j
, cw
, ch
);
821 if (m_currentRectVisible
)
823 DrawCellBackground(dc
, &m_currentRect
, i
, j
);
824 DrawCellValue(dc
, &m_currentRect
, i
, j
);
826 if (m_currentRect
.x
> cw
)
829 if (m_currentRect
.y
> ch
)
832 dc
->SetBackgroundMode(wxSOLID
);
833 dc
->SetPen(*wxBLACK_PEN
);
836 void wxGenericGrid::DrawCellBackground(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
838 wxGridCell
*cell
= GetCell(row
, col
);
841 dc
->SetBrush(*cell
->GetBackgroundBrush());
842 dc
->SetPen(*wxTRANSPARENT_PEN
);
844 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
846 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
, rect
->height
);
848 dc
->SetPen(*wxBLACK_PEN
);
852 void wxGenericGrid::DrawCellValue(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
854 wxGridCell
*cell
= GetCell(row
, col
);
857 wxBitmap
*bitmap
= cell
->GetCellBitmap();
867 DrawBitmapRect(dc
, bitmap
, &rect2
, cell
->GetAlignment());
871 dc
->SetBackgroundMode(wxTRANSPARENT
);
872 dc
->SetTextForeground(cell
->GetTextColour());
873 dc
->SetFont(*cell
->GetFont());
875 if ( !cell
->GetTextValue().IsNull() )
876 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, cell
->GetAlignment());
881 void wxGenericGrid::AdjustScrollbars(void)
884 GetClientSize(&cw
, &ch
);
886 // To calculate the number of steps for each scrollbar,
887 // we need to see how much will fit onto the canvas
888 // at the present size. So:
889 // 1) Find the *last* row r1 such that when it's at the top of the
890 // window, all the remaining rows are visible.
891 // 2) There should therefore be r1 - 1 steps in the scrollbar.
892 // Similarly with columns.
894 // IGNORE THE ABOVE, it's crap.
895 // We find the view size by seeing how many rows/cols fit on
897 // BUT... this means that the scrollbar should be adjusted every time
898 // it's scrolled, as well as when sized, because with variable size rows/cols,
899 // the number of rows/col visible on the view differs according to what bit
900 // you're looking at. The object length is always the same, but the
901 // view length differs.
903 // Since this may not be known until the end of this function, we should probably call AdjustScrollbars
905 int vertScrollBarWidth
= m_scrollWidth
;
906 int horizScrollBarHeight
= m_scrollWidth
;
907 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
908 vertScrollBarWidth
= 0;
909 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
910 horizScrollBarHeight
= 0;
912 int noHorizSteps
= 0;
915 if (m_totalGridWidth
<= cw
)
922 if (GetLabelSize(wxVERTICAL) > 0)
928 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
930 widthCount
+= m_colWidths
[i
];
931 // A partial bit doesn't count, we still have to scroll to see the
933 if (widthCount
+ m_leftOfSheet
+ m_verticalLabelWidth
> (cw
-vertScrollBarWidth
))
942 if (m_totalGridHeight
<= ch
)
949 if (GetLabelSize(wxHORIZONTAL) > 0)
955 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
957 heightCount
+= m_rowHeights
[i
];
958 // A partial bit doesn't count, we still have to scroll to see the
960 if (heightCount
+ m_topOfSheet
+ m_horizontalLabelHeight
> (ch
-horizScrollBarHeight
))
969 if (m_totalGridWidth
<= cw
)
972 m_hScrollBar
->Show(FALSE
);
978 m_hScrollBar
->Show(TRUE
);
981 if (m_totalGridHeight
<= ch
)
984 m_vScrollBar
->Show(FALSE
);
990 m_vScrollBar
->Show(TRUE
);
993 UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
995 vertScrollBarWidth
= m_scrollWidth
;
996 horizScrollBarHeight
= m_scrollWidth
;
997 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
998 vertScrollBarWidth
= 0;
999 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
1000 horizScrollBarHeight
= 0;
1004 int nCols
= GetCols();
1006 m_hScrollBar->SetPageSize(wxMax(noHorizSteps, 1));
1007 m_hScrollBar->SetViewLength(wxMax(noHorizSteps, 1));
1008 m_hScrollBar->SetObjectLength(nCols);
1010 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetPosition(), wxMax(noHorizSteps
, 1), nCols
, wxMax(noHorizSteps
, 1));
1012 m_hScrollBar
->SetSize(m_leftOfSheet
, ch
- m_scrollWidth
,
1013 cw
- vertScrollBarWidth
- m_leftOfSheet
, m_scrollWidth
);
1018 int nRows
= GetRows();
1020 m_vScrollBar->SetPageSize(wxMax(noVertSteps, 1));
1021 m_vScrollBar->SetViewLength(wxMax(noVertSteps, 1));
1022 m_vScrollBar->SetObjectLength(nRows);
1025 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetPosition(), wxMax(noVertSteps
, 1), nRows
, wxMax(noVertSteps
, 1));
1026 m_vScrollBar
->SetSize(cw
- m_scrollWidth
, m_topOfSheet
,
1027 m_scrollWidth
, ch
- m_topOfSheet
- horizScrollBarHeight
);
1031 void wxGenericGrid::OnSize(wxSizeEvent
& WXUNUSED(event
) )
1033 if (!m_vScrollBar
|| !m_hScrollBar
)
1039 GetClientSize(&cw
, &ch
);
1041 if (m_editCreated
&& m_editingPanel
&& GetTextItem() && GetTextItem()->IsShown())
1043 m_editingPanel
->SetSize(0, 0, cw
, m_editControlPosition
.height
+ m_editControlPosition
.y
+ 2);
1044 GetTextItem()->SetSize(m_editControlPosition
.x
, m_editControlPosition
.y
,
1045 cw
- m_editControlPosition
.x
, m_editControlPosition
.height
);
1049 bool wxGenericGrid::CellHitTest(int x
, int y
, int *row
, int *col
)
1051 // Find the selected cell and call OnSelectCell
1052 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1053 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1055 // Calculate the cell number from x and y
1056 x
-= (m_verticalLabelWidth
+ m_leftOfSheet
);
1057 y
-= (m_topOfSheet
+ m_horizontalLabelHeight
);
1061 // Now we need to do a hit test for which row we're on
1062 int currentHeight
= 0;
1063 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1065 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1070 currentHeight
+= m_rowHeights
[i
];
1073 // Now we need to do a hit test for which column we're on
1074 int currentWidth
= 0;
1075 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1077 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1082 currentWidth
+= m_colWidths
[i
];
1089 bool wxGenericGrid::LabelSashHitTest(int x
, int y
, int *orientation
, int *rowOrCol
, int *startPos
)
1094 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= m_topOfSheet
&&
1095 x
<= m_rightOfSheet
&& y
<= (m_topOfSheet
+ m_horizontalLabelHeight
))
1097 // We may be on a column label sash.
1098 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1099 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1101 if (x
>= (currentWidth
+ m_colWidths
[i
] - tolerance
) && x
<= (currentWidth
+ m_colWidths
[i
] + tolerance
))
1103 *orientation
= wxHORIZONTAL
;
1105 *startPos
= currentWidth
;
1108 currentWidth
+= m_colWidths
[i
];
1112 else if (x
>= m_leftOfSheet
&& y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1113 x
<= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
<= m_bottomOfSheet
)
1115 // We may be on a row label sash.
1116 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1117 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1119 if (y
>= (currentHeight
+ m_rowHeights
[i
] - tolerance
) && y
<= (currentHeight
+ m_rowHeights
[i
] + tolerance
))
1121 *orientation
= wxVERTICAL
;
1123 *startPos
= currentHeight
;
1126 currentHeight
+= m_rowHeights
[i
];
1133 bool wxGenericGrid::LabelHitTest(int x
, int y
, int *row
, int *col
)
1135 // Find the selected label
1136 if (x
>= m_leftOfSheet
&& y
>= m_topOfSheet
&&
1137 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1139 // Calculate the cell number from x and y
1145 // Now we need to do a hit test for which row we're on
1146 int currentHeight
= m_horizontalLabelHeight
;
1147 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1149 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1154 currentHeight
+= m_rowHeights
[i
];
1156 if (y
>= 0 && y
<= m_horizontalLabelHeight
)
1161 // Now we need to do a hit test for which column we're on
1162 int currentWidth
= m_verticalLabelWidth
;
1163 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1165 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1170 currentWidth
+= m_colWidths
[i
];
1172 if (x
>= 0 && x
<= m_verticalLabelWidth
)
1177 if ((*col
== -1) || (*row
== -1))
1185 void wxGenericGrid::OnMouseEvent(wxMouseEvent
& ev
)
1189 wxClientDC
dc(this);
1193 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1195 OnSelectCellImplementation(& dc
, row
, col
);
1196 OnCellLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1198 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1200 OnLabelLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1204 else if (ev
.Dragging() && ev
.LeftIsDown())
1206 switch (m_dragStatus
)
1208 case wxGRID_DRAG_NONE
:
1211 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &m_dragRowOrCol
, &m_dragStartPosition
))
1213 if (orientation
== wxHORIZONTAL
)
1215 m_dragStatus
= wxGRID_DRAG_LEFT_RIGHT
;
1216 SetCursor(*m_horizontalSashCursor
);
1217 m_dragLastPosition
= (int)ev
.GetX();
1221 m_dragStatus
= wxGRID_DRAG_UP_DOWN
;
1222 SetCursor(*m_verticalSashCursor
);
1223 m_dragLastPosition
= (int)ev
.GetY();
1225 wxClientDC
dc(this);
1227 dc
.SetLogicalFunction(wxINVERT
);
1228 if (orientation
== wxHORIZONTAL
)
1229 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1231 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1238 case wxGRID_DRAG_LEFT_RIGHT
:
1240 wxClientDC
dc(this);
1242 dc
.SetLogicalFunction(wxINVERT
);
1243 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1245 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1248 m_dragLastPosition
= (int)ev
.GetX();
1249 SetCursor(*m_horizontalSashCursor
);
1252 case wxGRID_DRAG_UP_DOWN
:
1254 wxClientDC
dc(this);
1256 dc
.SetLogicalFunction(wxINVERT
);
1257 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1259 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1262 m_dragLastPosition
= (int)ev
.GetY();
1263 SetCursor(*m_verticalSashCursor
);
1268 else if (ev
.Moving())
1270 int rowOrCol
, orientation
, startPos
;
1271 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &rowOrCol
, &startPos
))
1273 if (orientation
== wxHORIZONTAL
)
1274 SetCursor(*m_horizontalSashCursor
);
1276 SetCursor(*m_verticalSashCursor
);
1279 SetCursor(*wxSTANDARD_CURSOR
);
1281 else if (ev
.LeftUp())
1283 switch (m_dragStatus
)
1285 case wxGRID_DRAG_LEFT_RIGHT
:
1287 wxClientDC
dc(this);
1289 dc
.SetLogicalFunction(wxINVERT
);
1290 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1291 dc
.SetLogicalFunction(wxCOPY
);
1295 if (ev
.GetX() > m_dragStartPosition
)
1297 m_colWidths
[m_dragRowOrCol
] = (short)(ev
.GetX() - m_dragStartPosition
);
1302 SetCursor(*wxSTANDARD_CURSOR
);
1304 GetClientSize(&cw
, &ch
);
1309 case wxGRID_DRAG_UP_DOWN
:
1311 wxClientDC
dc(this);
1313 dc
.SetLogicalFunction(wxINVERT
);
1314 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1315 dc
.SetLogicalFunction(wxCOPY
);
1319 if (ev
.GetY() > m_dragStartPosition
)
1321 m_rowHeights
[m_dragRowOrCol
] = (short)(ev
.GetY() - m_dragStartPosition
);
1326 SetCursor(*wxSTANDARD_CURSOR
);
1330 m_dragStatus
= wxGRID_DRAG_NONE
;
1332 else if (ev
.RightDown())
1335 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1337 OnCellRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1339 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1341 OnLabelRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1346 void wxGenericGrid::OnSelectCellImplementation(wxDC
*dc
, int row
, int col
)
1348 m_wCursorColumn
= col
;
1351 OnChangeSelectionLabel();
1353 SetGridClippingRegion(dc
);
1355 // Remove the highlight from the old cell
1356 if (m_currentRectVisible
)
1359 // Highlight the new cell and copy its content to the edit control
1360 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
1361 wxGridCell
*cell
= GetCell(m_wCursorRow
, m_wCursorColumn
);
1364 if ( cell
->GetTextValue().IsNull() )
1365 m_textItem
->SetValue("");
1367 m_textItem
->SetValue(cell
->GetTextValue());
1370 SetGridClippingRegion(dc
);
1372 // Why isn't this needed for Windows??
1373 // Probably because of the SetValue??
1377 dc
->DestroyClippingRegion();
1379 OnSelectCell(row
, col
);
1382 wxGridCell
*wxGenericGrid::OnCreateCell(void)
1384 return new wxGridCell(this);
1387 void wxGenericGrid::OnChangeLabels(void)
1391 for (i
= 0; i
< m_totalRows
; i
++)
1393 sprintf(buf
, "%d", i
+1);
1394 SetLabelValue(wxVERTICAL
, buf
, i
);
1396 // A...Z,AA...ZZ,AAA...ZZZ, etc.
1397 for (i
= 0; i
< m_totalCols
; i
++)
1400 int noTimes
= (i
/26 + 1);
1401 int ch
= (i
% 26) + 65;
1403 for (j
= 0; j
< noTimes
; j
++)
1406 sprintf(buf2
, "%c", (char)ch
);
1409 SetLabelValue(wxHORIZONTAL
, buf
, i
);
1413 void wxGenericGrid::OnChangeSelectionLabel(void)
1418 wxString
rowLabel(GetLabelValue(wxVERTICAL
, GetCursorRow()));
1419 wxString
colLabel(GetLabelValue(wxHORIZONTAL
, GetCursorColumn()));
1421 wxString newLabel
= colLabel
+ rowLabel
;
1422 if ((newLabel
.Length() > 0) && (newLabel
.Length() <= 8) && GetTextItem())
1424 // GetTextItem()->SetLabel(newLabel);
1428 void wxGenericGrid::HighlightCell(wxDC
*dc
)
1430 dc
->SetLogicalFunction(wxINVERT
);
1432 dc
->DrawLine(m_currentRect
.x
+ 1, m_currentRect
.y
+ 1, m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+ 1);
1434 dc
->DrawLine(m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+ 1,
1435 m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+m_currentRect
.height
- 1);
1437 dc
->DrawLine(m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+ m_currentRect
.height
- 1,
1438 m_currentRect
.x
+ 1, m_currentRect
.y
+ m_currentRect
.height
- 1);
1440 dc
->DrawLine(m_currentRect
.x
+ 1, m_currentRect
.y
+ m_currentRect
.height
- 1, m_currentRect
.x
+ 1, m_currentRect
.y
+ 1);
1442 dc
->SetLogicalFunction(wxCOPY
);
1445 void wxGenericGrid::DrawCellText(void)
1447 if (!m_currentRectVisible
)
1450 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1454 static char szEdit
[300];
1456 wxClientDC
dc(this);
1459 SetGridClippingRegion(& dc
);
1461 dc
.SetBackgroundMode(wxTRANSPARENT
);
1462 dc
.SetBrush(*cell
->GetBackgroundBrush());
1464 strcpy(szEdit
, m_textItem
->GetValue());
1467 rect
= m_currentRect
;
1473 DrawTextRect(& dc
, " ", &rect
, wxLEFT
);
1474 DrawTextRect(& dc
, szEdit
, &rect
, cell
->GetAlignment());
1476 dc
.DestroyClippingRegion();
1478 dc
.SetBackgroundMode(wxSOLID
);
1483 void wxGenericGrid::SetCurrentRect(int Row
, int Column
, int canvasW
, int canvasH
)
1485 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1487 for (i
= m_scrollPosX
; i
< Column
; i
++)
1488 currentWidth
+= m_colWidths
[i
];
1490 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1491 for (i
= m_scrollPosY
; i
< Row
; i
++)
1492 currentHeight
+= m_rowHeights
[i
];
1494 m_currentRect
.x
= currentWidth
;
1495 m_currentRect
.y
= currentHeight
;
1496 m_currentRect
.width
= m_colWidths
? (m_colWidths
[Column
]) : 0;
1497 m_currentRect
.height
= m_rowHeights
? (m_rowHeights
[Row
]) : 0;
1499 if (Row
< m_scrollPosY
|| Column
< m_scrollPosX
)
1500 m_currentRectVisible
= FALSE
;
1501 else if ((canvasW
!= -1 && canvasH
!= -1) && (m_currentRect
.x
> canvasW
|| m_currentRect
.y
> canvasH
))
1502 m_currentRectVisible
= FALSE
;
1503 else m_currentRectVisible
= TRUE
;
1506 static bool wxRectIntersection(wxRectangle
*rect1
, wxRectangle
*rect2
, wxRectangle
*rect3
)
1508 int x2_1
= rect1
->x
+ rect1
->width
;
1509 int y2_1
= rect1
->y
+ rect1
->height
;
1511 int x2_2
= rect2
->x
+ rect2
->width
;
1512 int y2_2
= rect2
->y
+ rect2
->height
;
1516 // Check for intersection
1517 if ((rect1
->x
> x2_2
) || (rect2
->x
> x2_1
) ||
1518 (rect1
->y
> y2_2
) || (rect2
->y
> y2_1
))
1521 rect3
->x
= rect3
->y
= rect3
->width
= rect3
->height
= 0;
1525 if (rect1
->x
> rect2
->x
)
1526 rect3
->x
= rect1
->x
;
1528 rect3
->x
= rect2
->x
;
1529 if (rect1
->y
> rect2
->y
)
1530 rect3
->y
= rect1
->y
;
1532 rect3
->y
= rect2
->y
;
1543 rect3
->width
= (int)(x2_3
- rect3
->x
);
1544 rect3
->height
= (int)(y2_3
- rect3
->y
);
1548 void wxGenericGrid::DrawTextRect(wxDC
*dc
, const wxString
& text
, wxRectangle
*rect
, int flag
)
1552 // Ultimately, this functionality should be built into wxWindows,
1553 // and optimized for each platform. E.g. on Windows, use DrawText
1554 // passing a clipping rectangle, so that the wxWindows clipping region
1555 // does not have to be used to implement this.
1557 // If we're already clipping, we need to find the intersection
1558 // between current clipping area and text clipping area.
1560 wxRectangle clipRect
;
1561 wxRectangle clipRect2
;
1562 long clipX
, clipY
, clipW
, clipH
;
1563 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1564 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1565 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1567 bool alreadyClipping
= TRUE
;
1569 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1571 alreadyClipping
= FALSE
;
1572 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1573 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1577 // Find intersection.
1578 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1582 if (alreadyClipping
)
1583 dc
->DestroyClippingRegion();
1585 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1586 long textWidth
, textHeight
;
1588 dc
->GetTextExtent(text
, &textWidth
, &textHeight
);
1596 x
= (rect
->x
+ rect
->width
- textWidth
- 1.0);
1597 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1602 x
= (rect
->x
+ (rect
->width
- textWidth
)/2.0);
1603 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1609 x
= (rect
->x
+ 1.0);
1610 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1614 dc
->DrawText(text
, (long)x
, (long)y
);
1616 dc
->DestroyClippingRegion();
1618 // Restore old clipping
1619 if (alreadyClipping
)
1620 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1625 void wxGenericGrid::DrawBitmapRect(wxDC
*dc
, wxBitmap
*bitmap
, wxRectangle
*rect
, int flag
)
1629 // Ultimately, this functionality should be built into wxWindows,
1630 // and optimized for each platform. E.g. on Windows, use DrawText
1631 // passing a clipping rectangle, so that the wxWindows clipping region
1632 // does not have to be used to implement this.
1634 // If we're already clipping, we need to find the intersection
1635 // between current clipping area and text clipping area.
1637 wxRectangle clipRect
;
1638 wxRectangle clipRect2
;
1639 long clipX
, clipY
, clipW
, clipH
;
1640 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1641 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1642 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1644 bool alreadyClipping
= TRUE
;
1646 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1648 alreadyClipping
= FALSE
;
1649 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1650 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1654 // Find intersection.
1655 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1659 if (alreadyClipping
)
1660 dc
->DestroyClippingRegion();
1662 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1663 float bitmapWidth
, bitmapHeight
;
1665 bitmapWidth
= bitmap
->GetWidth();
1666 bitmapHeight
= bitmap
->GetHeight();
1674 x
= (long)(rect
->x
+ rect
->width
- bitmapWidth
- 1);
1675 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1680 x
= (long)(rect
->x
+ (rect
->width
- bitmapWidth
)/2.0);
1681 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1687 x
= (long)(rect
->x
+ 1);
1688 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1693 dcTemp
.SelectObject(*bitmap
);
1695 dc
->Blit( (long)x
, (long)y
, (long)bitmapWidth
, (long)bitmapHeight
, &dcTemp
, 0, 0);
1696 dcTemp
.SelectObject(wxNullBitmap
);
1698 dc
->DestroyClippingRegion();
1700 // Restore old clipping
1701 if (alreadyClipping
)
1702 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1707 void wxGenericGrid::OnActivate(bool active
)
1711 // Edit control should always have the focus
1712 if (GetTextItem() && GetEditable())
1714 GetTextItem()->SetFocus();
1715 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1717 GetTextItem()->SetValue(cell
->GetTextValue());
1722 void wxGenericGrid::SetCellValue(const wxString
& val
, int row
, int col
)
1724 wxGridCell
*cell
= GetCell(row
, col
);
1727 cell
->SetTextValue(val
);
1729 RefreshCell(row
, col
, TRUE
);
1733 void wxGenericGrid::RefreshCell(int row
, int col
, bool setText
)
1735 // Don't refresh within a pair of batch brackets
1736 if (GetBatchCount() > 0)
1740 GetClientSize(&cw
, &ch
);
1742 SetCurrentRect(row
, col
, cw
, ch
);
1743 if (m_currentRectVisible
)
1745 wxGridCell
*cell
= GetCell(row
, col
);
1747 bool currentPos
= FALSE
;
1748 if (row
== m_wCursorRow
&& col
== m_wCursorColumn
&& GetTextItem() && GetTextItem()->IsShown() && setText
)
1750 GetTextItem()->SetValue(cell
->GetTextValue());
1753 // Gets refreshed anyway in MSW
1758 wxClientDC
dc(this);
1760 DrawCellBackground(& dc
, &m_currentRect
, row
, col
);
1761 DrawCellValue(& dc
, &m_currentRect
, row
, col
);
1767 wxString
& wxGenericGrid::GetCellValue(int row
, int col
)
1769 static wxString
emptyString("");
1771 wxGridCell
*cell
= GetCell(row
, col
);
1773 return cell
->GetTextValue();
1778 void wxGenericGrid::SetColumnWidth(int col
, int width
)
1780 if (col
<= m_totalCols
)
1781 m_colWidths
[col
] = width
;
1784 int wxGenericGrid::GetColumnWidth(int col
)
1786 if (col
<= m_totalCols
)
1787 return m_colWidths
[col
];
1792 void wxGenericGrid::SetRowHeight(int row
, int height
)
1794 if (row
<= m_totalRows
)
1795 m_rowHeights
[row
] = height
;
1798 int wxGenericGrid::GetRowHeight(int row
)
1800 if (row
<= m_totalRows
)
1801 return m_rowHeights
[row
];
1806 void wxGenericGrid::SetLabelSize(int orientation
, int sz
)
1808 if (orientation
== wxHORIZONTAL
)
1809 m_horizontalLabelHeight
= sz
;
1811 m_verticalLabelWidth
= sz
;
1813 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1816 int wxGenericGrid::GetLabelSize(int orientation
)
1818 if (orientation
== wxHORIZONTAL
)
1819 return m_horizontalLabelHeight
;
1821 return m_verticalLabelWidth
;
1824 wxGridCell
*wxGenericGrid::GetLabelCell(int orientation
, int pos
)
1826 if (orientation
== wxHORIZONTAL
)
1828 if (m_colLabelCells
&& pos
< m_totalCols
)
1829 return m_colLabelCells
[pos
];
1835 if (m_rowLabelCells
&& pos
< m_totalRows
)
1836 return m_rowLabelCells
[pos
];
1842 void wxGenericGrid::SetLabelValue(int orientation
, const wxString
& val
, int pos
)
1844 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1846 cell
->SetTextValue(val
);
1849 wxString
& wxGenericGrid::GetLabelValue(int orientation
, int pos
)
1851 static wxString emptyString
= "";
1852 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1854 return cell
->GetTextValue();
1859 void wxGenericGrid::SetLabelAlignment(int orientation
, int align
)
1861 if (orientation
== wxHORIZONTAL
)
1862 m_horizontalLabelAlignment
= align
;
1864 m_verticalLabelAlignment
= align
;
1866 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1869 int wxGenericGrid::GetLabelAlignment(int orientation
)
1871 if (orientation
== wxHORIZONTAL
)
1872 return m_horizontalLabelAlignment
;
1874 return m_verticalLabelAlignment
;
1877 void wxGenericGrid::SetLabelTextColour(const wxColour
& colour
)
1879 m_labelTextColour
= colour
;
1883 void wxGenericGrid::SetLabelBackgroundColour(const wxColour
& colour
)
1885 m_labelBackgroundColour
= colour
;
1886 m_labelBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush(m_labelBackgroundColour
, wxSOLID
);
1889 void wxGenericGrid::SetEditable(bool edit
)
1894 int controlW
, controlH
;
1895 m_textItem
->GetSize(&controlW
, &controlH
);
1896 m_editControlPosition
.height
= controlH
;
1898 m_topOfSheet
= m_editControlPosition
.x
+ controlH
+ 2;
1901 m_editingPanel
->Show(TRUE
);
1902 m_textItem
->Show(TRUE
);
1903 m_textItem
->SetFocus();
1911 m_textItem
->Show(FALSE
);
1912 m_editingPanel
->Show(FALSE
);
1916 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1919 GetClientSize(&cw
, &ch
);
1924 int m_scrollWidth = 16;
1925 GetClientSize(&cw, &ch);
1928 m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
1929 m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
1933 void wxGenericGrid::SetCellAlignment(int flag
, int row
, int col
)
1935 wxGridCell
*cell
= GetCell(row
, col
);
1937 cell
->SetAlignment(flag
);
1940 int wxGenericGrid::GetCellAlignment(int row
, int col
)
1942 wxGridCell
*cell
= GetCell(row
, col
);
1944 return cell
->GetAlignment();
1946 return m_cellAlignment
;
1949 void wxGenericGrid::SetCellAlignment(int flag
)
1951 m_cellAlignment
= flag
;
1953 for (i
= 0; i
< GetRows(); i
++)
1954 for (j
= 0; j
< GetCols(); j
++)
1956 GetCell(i
, j
)->SetAlignment(flag
);
1959 int wxGenericGrid::GetCellAlignment(void)
1961 return m_cellAlignment
;
1964 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& col
)
1966 m_cellBackgroundColour
= col
;
1968 for (i
= 0; i
< GetRows(); i
++)
1969 for (j
= 0; j
< GetCols(); j
++)
1971 GetCell(i
, j
)->SetBackgroundColour(col
);
1974 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& val
, int row
, int col
)
1976 wxGridCell
*cell
= GetCell(row
, col
);
1979 cell
->SetBackgroundColour(val
);
1980 RefreshCell(row
, col
);
1984 wxColour
& wxGenericGrid::GetCellBackgroundColour(int row
, int col
)
1986 wxGridCell
*cell
= GetCell(row
, col
);
1988 return cell
->GetBackgroundColour();
1990 return m_cellBackgroundColour
;
1993 void wxGenericGrid::SetCellTextColour(const wxColour
& val
, int row
, int col
)
1995 wxGridCell
*cell
= GetCell(row
, col
);
1998 cell
->SetTextColour(val
);
1999 RefreshCell(row
, col
);
2003 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
, int row
, int col
)
2005 wxGridCell
*cell
= GetCell(row
, col
);
2009 RefreshCell(row
, col
);
2013 wxFont
*wxGenericGrid::GetCellTextFont(int row
, int col
)
2015 wxGridCell
*cell
= GetCell(row
, col
);
2017 return cell
->GetFont();
2019 return m_cellTextFont
;
2022 wxColour
& wxGenericGrid::GetCellTextColour(int row
, int col
)
2024 wxGridCell
*cell
= GetCell(row
, col
);
2026 return cell
->GetTextColour();
2028 return m_cellTextColour
;
2031 void wxGenericGrid::SetCellTextColour(const wxColour
& val
)
2033 m_cellTextColour
= val
;
2035 for (i
= 0; i
< GetRows(); i
++)
2036 for (j
= 0; j
< GetCols(); j
++)
2038 GetCell(i
, j
)->SetTextColour(val
);
2041 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
)
2043 m_cellTextFont
= fnt
;
2045 for (i
= 0; i
< GetRows(); i
++)
2046 for (j
= 0; j
< GetCols(); j
++)
2048 GetCell(i
, j
)->SetFont(fnt
);
2051 void wxGenericGrid::SetCellBitmap(wxBitmap
*bitmap
, int row
, int col
)
2053 wxGridCell
*cell
= GetCell(row
, col
);
2056 cell
->SetCellBitmap(bitmap
);
2057 RefreshCell(row
, col
);
2061 wxBitmap
*wxGenericGrid::GetCellBitmap(int row
, int col
)
2063 wxGridCell
*cell
= GetCell(row
, col
);
2066 return cell
->GetCellBitmap();
2072 bool wxGenericGrid::InsertCols(int pos
, int n
, bool updateLabels
)
2074 if (pos
> m_totalCols
)
2078 return CreateGrid(1, n
);
2083 for (i
= 0; i
< m_totalRows
; i
++)
2085 wxGridCell
**cols
= m_gridCells
[i
];
2086 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
+ n
];
2087 for (j
= 0; j
< pos
; j
++)
2088 newCols
[j
] = cols
[j
];
2089 for (j
= pos
; j
< pos
+ n
; j
++)
2090 newCols
[j
] = new wxGridCell(this);
2091 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2092 newCols
[j
] = cols
[j
- n
];
2095 m_gridCells
[i
] = newCols
;
2099 short *newColWidths
= new short[m_totalCols
+ n
];
2100 for (j
= 0; j
< pos
; j
++)
2101 newColWidths
[j
] = m_colWidths
[j
];
2102 for (j
= pos
; j
< pos
+ n
; j
++)
2103 newColWidths
[j
] = wxGRID_DEFAULT_CELL_WIDTH
;
2104 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2105 newColWidths
[j
] = m_colWidths
[j
- n
];
2106 delete[] m_colWidths
;
2107 m_colWidths
= newColWidths
;
2110 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
+ n
];
2111 for (j
= 0; j
< pos
; j
++)
2112 newLabels
[j
] = m_colLabelCells
[j
];
2113 for (j
= pos
; j
< pos
+ n
; j
++)
2114 newLabels
[j
] = new wxGridCell(this);
2115 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2116 newLabels
[j
] = m_colLabelCells
[j
- n
];
2118 delete[] m_colLabelCells
;
2119 m_colLabelCells
= newLabels
;
2131 bool wxGenericGrid::InsertRows(int pos
, int n
, bool updateLabels
)
2133 if (pos
> m_totalRows
)
2137 return CreateGrid(n
, 1);
2142 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
+ n
];
2145 for (i
= 0; i
< pos
; i
++)
2146 rows
[i
] = m_gridCells
[i
];
2148 for (i
= pos
; i
< pos
+ n
; i
++)
2150 rows
[i
] = new wxGridCell
*[m_totalCols
];
2151 for (j
= 0; j
< m_totalCols
; j
++)
2152 rows
[i
][j
] = new wxGridCell(this);
2155 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2156 rows
[i
] = m_gridCells
[i
- n
];
2158 delete[] m_gridCells
;
2162 short *newRowHeights
= new short[m_totalRows
+ n
];
2163 for (i
= 0; i
< pos
; i
++)
2164 newRowHeights
[i
] = m_rowHeights
[i
];
2165 for (i
= pos
; i
< pos
+ n
; i
++)
2166 newRowHeights
[i
] = wxGRID_DEFAULT_CELL_HEIGHT
;
2167 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2168 newRowHeights
[i
] = m_rowHeights
[i
- n
];
2169 delete[] m_rowHeights
;
2170 m_rowHeights
= newRowHeights
;
2173 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
+ n
];
2174 for (i
= 0; i
< pos
; i
++)
2175 newLabels
[i
] = m_rowLabelCells
[i
];
2176 for (i
= pos
; i
< pos
+ n
; i
++)
2177 newLabels
[i
] = new wxGridCell(this);
2178 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2179 newLabels
[i
] = m_rowLabelCells
[i
- n
];
2181 delete[] m_rowLabelCells
;
2182 m_rowLabelCells
= newLabels
;
2194 bool wxGenericGrid::AppendCols(int n
, bool updateLabels
)
2196 return InsertCols(GetCols(), n
, updateLabels
);
2199 bool wxGenericGrid::AppendRows(int n
, bool updateLabels
)
2201 return InsertRows(GetRows(), n
, updateLabels
);
2204 bool wxGenericGrid::DeleteRows(int pos
, int n
, bool updateLabels
)
2206 if (pos
> m_totalRows
)
2213 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
- n
];
2216 for (i
= 0; i
< pos
; i
++)
2217 rows
[i
] = m_gridCells
[i
];
2219 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2220 rows
[i
-n
] = m_gridCells
[i
];
2222 delete[] m_gridCells
;
2226 short *newRowHeights
= new short[m_totalRows
- n
];
2227 for (i
= 0; i
< pos
; i
++)
2228 newRowHeights
[i
] = m_rowHeights
[i
];
2229 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2230 newRowHeights
[i
-n
] = m_rowHeights
[i
];
2231 delete[] m_rowHeights
;
2232 m_rowHeights
= newRowHeights
;
2235 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
- n
];
2236 for (i
= 0; i
< pos
; i
++)
2237 newLabels
[i
] = m_rowLabelCells
[i
];
2238 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2239 newLabels
[i
-n
] = m_rowLabelCells
[i
];
2241 delete[] m_rowLabelCells
;
2242 m_rowLabelCells
= newLabels
;
2253 bool wxGenericGrid::DeleteCols(int pos
, int n
, bool updateLabels
)
2255 if (pos
+ n
> m_totalCols
)
2263 for (i
= 0; i
< m_totalRows
; i
++)
2265 wxGridCell
**cols
= m_gridCells
[i
];
2266 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
- n
];
2267 for (j
= 0; j
< pos
; j
++)
2268 newCols
[j
] = cols
[j
];
2269 for (j
= pos
; j
< pos
+ n
; j
++)
2271 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2272 newCols
[j
-n
] = cols
[j
];
2275 m_gridCells
[i
] = newCols
;
2279 short *newColWidths
= new short[m_totalCols
- n
];
2280 for (j
= 0; j
< pos
; j
++)
2281 newColWidths
[j
] = m_colWidths
[j
];
2282 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2283 newColWidths
[j
-n
] = m_colWidths
[j
];
2284 delete[] m_colWidths
;
2285 m_colWidths
= newColWidths
;
2288 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
- n
];
2289 for (j
= 0; j
< pos
; j
++)
2290 newLabels
[j
] = m_colLabelCells
[j
];
2291 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2292 newLabels
[j
-n
] = m_colLabelCells
[j
];
2294 delete[] m_colLabelCells
;
2295 m_colLabelCells
= newLabels
;
2306 void wxGenericGrid::SetGridCursor(int row
, int col
)
2308 if (row
>= m_totalRows
|| col
>= m_totalCols
)
2311 if (row
== GetCursorRow() && col
== GetCursorColumn())
2314 wxClientDC
dc(this);
2317 SetGridClippingRegion(& dc
);
2319 if (m_currentRectVisible
)
2320 HighlightCell(& dc
);
2323 m_wCursorColumn
= col
;
2324 SetCurrentRect(row
, col
);
2325 if (m_currentRectVisible
)
2326 HighlightCell(& dc
);
2328 dc
.DestroyClippingRegion();
2336 wxGridCell::wxGridCell(wxGenericGrid
*window
)
2340 backgroundBrush
= NULL
;
2342 textColour
= window
->GetCellTextColour();
2344 textColour
.Set(0,0,0);
2346 backgroundColour
= window
->GetCellBackgroundColour();
2348 backgroundColour
.Set(255,255,255);
2351 font
= window
->GetCellTextFont();
2353 font
= wxTheFontList
->FindOrCreateFont(12, wxSWISS
, wxNORMAL
, wxNORMAL
);
2355 SetBackgroundColour(backgroundColour
);
2358 alignment
= window
->GetCellAlignment();
2363 wxGridCell::~wxGridCell(void)
2367 void wxGridCell::SetBackgroundColour(const wxColour
& colour
)
2369 backgroundColour
= colour
;
2370 backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(backgroundColour
, wxSOLID
);
2373 void wxGenericGrid::OnText(wxCommandEvent
& WXUNUSED(ev
) )
2375 wxGenericGrid
*grid
= this;
2376 wxGridCell
*cell
= grid
->GetCell(grid
->GetCursorRow(), grid
->GetCursorColumn());
2377 if (cell
&& grid
->CurrentCellVisible())
2379 cell
->SetTextValue(grid
->GetTextItem()->GetValue());
2380 wxClientDC
dc(grid
);
2383 grid
->SetGridClippingRegion(& dc
);
2384 grid
->DrawCellBackground(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2385 grid
->DrawCellValue(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2386 grid
->HighlightCell(& dc
);
2387 dc
.DestroyClippingRegion();
2390 grid
->OnCellChange(grid
->GetCursorRow(), grid
->GetCursorColumn());
2392 // grid->DrawCellText();
2396 void wxGenericGrid::OnGridScroll(wxScrollEvent
& ev
)
2398 static bool inScroll
= FALSE
;
2404 wxGenericGrid
*win
= this;
2406 bool change
= FALSE
;
2408 if (ev
.GetEventObject() == win
->GetHorizScrollBar())
2410 change
= (ev
.GetPosition() != m_scrollPosX
);
2411 win
->SetScrollPosX(ev
.GetPosition());
2415 change
= (ev
.GetPosition() != m_scrollPosY
);
2416 win
->SetScrollPosY(ev
.GetPosition());
2419 win
->UpdateDimensions();
2420 win
->SetCurrentRect(win
->GetCursorRow(), win
->GetCursorColumn());
2422 // Because rows and columns can be arbitrary sizes,
2423 // the scrollbars will need to be adjusted to reflect the
2427 if (change
) win
->Refresh(FALSE
);