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
))
409 GetClientSize(&w
, &h
);
411 bool useDoubleBuffering
= (bool) USE_DOUBLE_BUFFERING
;
412 if (useDoubleBuffering
)
414 // Reuse the old bitmap if possible
416 if (!m_doubleBufferingBitmap
||
417 (m_doubleBufferingBitmap
->GetWidth() < w
|| m_doubleBufferingBitmap
->GetHeight() < h
))
419 if (m_doubleBufferingBitmap
)
420 delete m_doubleBufferingBitmap
;
421 m_doubleBufferingBitmap
= new wxBitmap(w
, h
);
423 if (!m_doubleBufferingBitmap
|| !m_doubleBufferingBitmap
->Ok())
425 // If we couldn't create a new bitmap, perhaps because resources were low,
426 // then don't complain, just don't double-buffer
427 if (m_doubleBufferingBitmap
)
428 delete m_doubleBufferingBitmap
;
429 m_doubleBufferingBitmap
= NULL
;
430 useDoubleBuffering
= FALSE
;
434 if (useDoubleBuffering
)
436 wxPaintDC
paintDC(this);
437 wxMemoryDC
dc(& paintDC
);
438 dc
.SelectObject(* m_doubleBufferingBitmap
);
442 int vertScrollBarWidth
= m_scrollWidth
;
443 int horizScrollBarHeight
= m_scrollWidth
;
444 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
445 vertScrollBarWidth
= 0;
446 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
447 horizScrollBarHeight
= 0;
449 paintDC
.Blit(m_leftOfSheet
, m_topOfSheet
, w
- vertScrollBarWidth
- m_leftOfSheet
, h
- horizScrollBarHeight
- m_topOfSheet
,
450 &dc
, m_leftOfSheet
, m_topOfSheet
, wxCOPY
);
452 dc
.SelectObject(wxNullBitmap
);
461 void wxGenericGrid::PaintGrid(wxDC
& dc
)
464 dc
.SetOptimization(FALSE
);
466 SetGridClippingRegion(& dc
);
468 DrawLabelAreas(& dc
);
470 DrawEditableArea(& dc
);
471 DrawColumnLabels(& dc
);
476 /* Hilight present cell */
477 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
478 if (m_currentRectVisible
)
481 dc
.DestroyClippingRegion();
482 dc
.SetOptimization(TRUE
);
486 // Erase (some of) the background.
487 // Currently, a Windows-only optimisation.
488 void wxGenericGrid::OnEraseBackground(wxEraseEvent
& event
)
492 dc
.SetOptimization(FALSE
);
495 GetClientSize(& w
, & h
);
496 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
);
497 dc
.SetPen(*wxLIGHT_GREY_PEN
);
499 if (m_hScrollBar
&& m_hScrollBar
->IsShown() && m_vScrollBar
&& m_vScrollBar
->IsShown())
501 dc
.DrawRectangle(w
- m_scrollWidth
, h
- m_scrollWidth
, m_scrollWidth
, m_scrollWidth
);
504 dc
.SetOptimization(TRUE
);
509 void wxGenericGrid::DrawLabelAreas(wxDC
*dc
)
512 GetClientSize(&cw
, &ch
);
514 dc
->SetPen(*wxTRANSPARENT_PEN
);
515 // dc->SetBrush(*dc->GetBackground());
517 // Should blank out any area which isn't going to be painted over.
518 // dc->DrawRectangle(m_leftOfSheet, m_bottomOfSheet, cw - m_leftOfSheet, ch - m_bottomOfSheet);
519 // dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet);
521 // Paint the label areas
522 dc
->SetBrush(*m_labelBackgroundBrush
);
523 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1);
524 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, cw
-m_leftOfSheet
, m_horizontalLabelHeight
+ 1);
525 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1);
526 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, m_verticalLabelWidth
+ 1, ch
-m_topOfSheet
);
529 void wxGenericGrid::DrawEditableArea(wxDC
*dc
)
532 GetClientSize(&cw
, &ch
);
534 dc
->SetPen(*wxTRANSPARENT_PEN
);
535 dc
->SetBrush(*wxTheBrushList
->FindOrCreateBrush(m_cellBackgroundColour
, wxSOLID
));
536 // dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight,
537 // m_rightOfSheet-(m_leftOfSheet+m_verticalLabelWidth) + 1, m_bottomOfSheet - (m_topOfSheet+m_horizontalLabelHeight) + 1);
538 dc
->DrawRectangle(m_leftOfSheet
+m_verticalLabelWidth
, m_topOfSheet
+m_horizontalLabelHeight
,
539 cw
-(m_leftOfSheet
+m_verticalLabelWidth
), ch
- (m_topOfSheet
+m_horizontalLabelHeight
));
542 void wxGenericGrid::DrawGridLines(wxDC
*dc
)
545 GetClientSize(&cw
, &ch
);
551 dc
->SetPen(*m_divisionPen
);
553 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
555 // Draw horizontal grey lines for cells
556 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
558 if (heightCount
> ch
)
562 dc
->DrawLine(m_leftOfSheet
, heightCount
,
565 heightCount
+= m_rowHeights
[i
];
570 if (m_verticalLabelWidth
> 0)
572 dc
->SetPen(*wxBLACK_PEN
);
574 // Draw horizontal black lines for row labels
575 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
576 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
578 if (heightCount
> ch
)
582 dc
->DrawLine(m_leftOfSheet
, heightCount
,
583 m_verticalLabelWidth
, heightCount
);
585 heightCount
+= m_rowHeights
[i
];
588 // Draw a black vertical line for row number cells
589 dc
->DrawLine(m_leftOfSheet
+ m_verticalLabelWidth
, m_topOfSheet
,
590 m_leftOfSheet
+ m_verticalLabelWidth
, ch
);
591 // First vertical line
592 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
, m_leftOfSheet
, ch
);
594 dc
->SetPen(*wxWHITE_PEN
);
596 // Draw highlights on row labels
597 heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
598 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
600 if (heightCount
> ch
)
604 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
605 m_verticalLabelWidth
, heightCount
+1);
606 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
607 m_leftOfSheet
+1, heightCount
+ m_rowHeights
[i
] - 1);
608 heightCount
+= m_rowHeights
[i
];
611 // Last one - down to the floor.
612 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
613 m_verticalLabelWidth
, heightCount
+1);
614 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
615 m_leftOfSheet
+1, ch
);
621 dc
->SetPen(*m_divisionPen
);
623 // Draw vertical grey lines for cells
624 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
625 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
631 // Skip the first one
632 if (i
!= m_scrollPosX
)
634 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
635 widthCount
, m_bottomOfSheet
);
637 widthCount
+= m_colWidths
[i
];
641 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
642 widthCount
, m_bottomOfSheet
);
645 dc
->SetPen(*wxBLACK_PEN
);
647 // Draw two black horizontal lines for column number cells
649 m_leftOfSheet
, m_topOfSheet
,
651 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
+ m_horizontalLabelHeight
,
652 cw
, m_topOfSheet
+ m_horizontalLabelHeight
);
654 if (m_horizontalLabelHeight
> 0)
656 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
658 // Draw black vertical lines for column number cells
659 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
665 dc
->DrawLine(widthCount
, m_topOfSheet
,
666 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
667 widthCount
+= m_colWidths
[i
];
672 dc
->DrawLine(widthCount
, m_topOfSheet
,
673 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
676 dc
->SetPen(*wxWHITE_PEN
);
677 widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
679 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
685 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
686 widthCount
+m_colWidths
[i
], m_topOfSheet
+1);
687 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
688 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
689 widthCount
+= m_colWidths
[i
];
692 // Last one - to the right side of the canvas.
693 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
695 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
696 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
701 void wxGenericGrid::DrawColumnLabels(wxDC
*dc
)
704 GetClientSize(&cw
, &ch
);
706 if (m_horizontalLabelHeight
== 0)
712 // Draw letters for columns
713 rect
.y
= m_topOfSheet
+ 1;
714 rect
.height
= m_horizontalLabelHeight
- 1;
716 dc
->SetTextBackground(m_labelBackgroundColour
);
717 dc
->SetBackgroundMode(wxTRANSPARENT
);
718 // dc->SetTextForeground(m_labelTextColour);
720 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
721 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
727 rect
.x
= 1 + widthCount
;
728 rect
.width
= m_colWidths
[i
];
729 DrawColumnLabel(dc
, &rect
, i
);
731 widthCount
+= m_colWidths
[i
];
736 void wxGenericGrid::DrawColumnLabel(wxDC
*dc
, wxRectangle
*rect
, int col
)
738 wxGridCell
*cell
= GetLabelCell(wxHORIZONTAL
, col
);
747 dc
->SetTextForeground(GetLabelTextColour());
748 dc
->SetFont(*GetLabelTextFont());
749 if ( !cell
->GetTextValue().IsNull() )
750 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxHORIZONTAL
));
754 void wxGenericGrid::DrawRowLabels(wxDC
*dc
)
757 GetClientSize(&cw
, &ch
);
759 if (m_verticalLabelWidth
== 0)
765 // Draw numbers for rows
766 rect
.x
= m_leftOfSheet
;
767 rect
.width
= m_verticalLabelWidth
;
769 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
771 dc
->SetTextBackground(m_labelBackgroundColour
);
772 dc
->SetBackgroundMode(wxTRANSPARENT
);
774 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
776 if (heightCount
> ch
)
780 rect
.y
= 1 + heightCount
;
781 rect
.height
= m_rowHeights
[i
];
782 DrawRowLabel(dc
, &rect
, i
);
784 heightCount
+= m_rowHeights
[i
];
789 void wxGenericGrid::DrawRowLabel(wxDC
*dc
, wxRectangle
*rect
, int row
)
791 wxGridCell
*cell
= GetLabelCell(wxVERTICAL
, row
);
800 dc
->SetTextForeground(GetLabelTextColour());
801 dc
->SetFont(*GetLabelTextFont());
802 if ( !cell
->GetTextValue().IsNull() )
803 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxVERTICAL
));
807 void wxGenericGrid::DrawCells(wxDC
*dc
)
810 GetClientSize(&cw
, &ch
);
814 // Draw value corresponding to each cell
815 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
817 for (j
= m_scrollPosX
; j
< m_totalCols
; j
++)
819 SetCurrentRect(i
, j
, cw
, ch
);
820 if (m_currentRectVisible
)
822 DrawCellBackground(dc
, &m_currentRect
, i
, j
);
823 DrawCellValue(dc
, &m_currentRect
, i
, j
);
825 if (m_currentRect
.x
> cw
)
828 if (m_currentRect
.y
> ch
)
831 dc
->SetBackgroundMode(wxSOLID
);
832 dc
->SetPen(*wxBLACK_PEN
);
835 void wxGenericGrid::DrawCellBackground(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
837 wxGridCell
*cell
= GetCell(row
, col
);
840 dc
->SetBrush(*cell
->GetBackgroundBrush());
841 dc
->SetPen(*wxTRANSPARENT_PEN
);
843 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
845 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
, rect
->height
);
847 dc
->SetPen(*wxBLACK_PEN
);
851 void wxGenericGrid::DrawCellValue(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
853 wxGridCell
*cell
= GetCell(row
, col
);
856 wxBitmap
*bitmap
= cell
->GetCellBitmap();
866 DrawBitmapRect(dc
, bitmap
, &rect2
, cell
->GetAlignment());
870 dc
->SetBackgroundMode(wxTRANSPARENT
);
871 dc
->SetTextForeground(cell
->GetTextColour());
872 dc
->SetFont(*cell
->GetFont());
874 if ( !cell
->GetTextValue().IsNull() )
875 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, cell
->GetAlignment());
880 void wxGenericGrid::AdjustScrollbars(void)
883 GetClientSize(&cw
, &ch
);
885 // To calculate the number of steps for each scrollbar,
886 // we need to see how much will fit onto the canvas
887 // at the present size. So:
888 // 1) Find the *last* row r1 such that when it's at the top of the
889 // window, all the remaining rows are visible.
890 // 2) There should therefore be r1 - 1 steps in the scrollbar.
891 // Similarly with columns.
893 // IGNORE THE ABOVE, it's crap.
894 // We find the view size by seeing how many rows/cols fit on
896 // BUT... this means that the scrollbar should be adjusted every time
897 // it's scrolled, as well as when sized, because with variable size rows/cols,
898 // the number of rows/col visible on the view differs according to what bit
899 // you're looking at. The object length is always the same, but the
900 // view length differs.
902 // Since this may not be known until the end of this function, we should probably call AdjustScrollbars
904 int vertScrollBarWidth
= m_scrollWidth
;
905 int horizScrollBarHeight
= m_scrollWidth
;
906 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
907 vertScrollBarWidth
= 0;
908 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
909 horizScrollBarHeight
= 0;
911 int noHorizSteps
= 0;
914 if (m_totalGridWidth
<= cw
)
921 if (GetLabelSize(wxVERTICAL) > 0)
927 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
929 widthCount
+= m_colWidths
[i
];
930 // A partial bit doesn't count, we still have to scroll to see the
932 if (widthCount
+ m_leftOfSheet
+ m_verticalLabelWidth
> (cw
-vertScrollBarWidth
))
941 if (m_totalGridHeight
<= ch
)
948 if (GetLabelSize(wxHORIZONTAL) > 0)
954 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
956 heightCount
+= m_rowHeights
[i
];
957 // A partial bit doesn't count, we still have to scroll to see the
959 if (heightCount
+ m_topOfSheet
+ m_horizontalLabelHeight
> (ch
-horizScrollBarHeight
))
968 if (m_totalGridWidth
<= cw
)
971 m_hScrollBar
->Show(FALSE
);
977 m_hScrollBar
->Show(TRUE
);
980 if (m_totalGridHeight
<= ch
)
983 m_vScrollBar
->Show(FALSE
);
989 m_vScrollBar
->Show(TRUE
);
992 UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
994 vertScrollBarWidth
= m_scrollWidth
;
995 horizScrollBarHeight
= m_scrollWidth
;
996 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
997 vertScrollBarWidth
= 0;
998 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
999 horizScrollBarHeight
= 0;
1003 int nCols
= GetCols();
1005 m_hScrollBar->SetPageSize(wxMax(noHorizSteps, 1));
1006 m_hScrollBar->SetViewLength(wxMax(noHorizSteps, 1));
1007 m_hScrollBar->SetObjectLength(nCols);
1009 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetPosition(), wxMax(noHorizSteps
, 1), nCols
, wxMax(noHorizSteps
, 1));
1011 m_hScrollBar
->SetSize(m_leftOfSheet
, ch
- m_scrollWidth
,
1012 cw
- vertScrollBarWidth
- m_leftOfSheet
, m_scrollWidth
);
1017 int nRows
= GetRows();
1019 m_vScrollBar->SetPageSize(wxMax(noVertSteps, 1));
1020 m_vScrollBar->SetViewLength(wxMax(noVertSteps, 1));
1021 m_vScrollBar->SetObjectLength(nRows);
1024 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetPosition(), wxMax(noVertSteps
, 1), nRows
, wxMax(noVertSteps
, 1));
1025 m_vScrollBar
->SetSize(cw
- m_scrollWidth
, m_topOfSheet
,
1026 m_scrollWidth
, ch
- m_topOfSheet
- horizScrollBarHeight
);
1030 void wxGenericGrid::OnSize(wxSizeEvent
& WXUNUSED(event
) )
1032 if (!m_vScrollBar
|| !m_hScrollBar
)
1038 GetClientSize(&cw
, &ch
);
1040 if (m_editCreated
&& m_editingPanel
&& GetTextItem() && GetTextItem()->IsShown())
1042 m_editingPanel
->SetSize(0, 0, cw
, m_editControlPosition
.height
+ m_editControlPosition
.y
+ 2);
1043 GetTextItem()->SetSize(m_editControlPosition
.x
, m_editControlPosition
.y
,
1044 cw
- m_editControlPosition
.x
, m_editControlPosition
.height
);
1048 bool wxGenericGrid::CellHitTest(int x
, int y
, int *row
, int *col
)
1050 // Find the selected cell and call OnSelectCell
1051 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1052 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1054 // Calculate the cell number from x and y
1055 x
-= (m_verticalLabelWidth
+ m_leftOfSheet
);
1056 y
-= (m_topOfSheet
+ m_horizontalLabelHeight
);
1060 // Now we need to do a hit test for which row we're on
1061 int currentHeight
= 0;
1062 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1064 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1069 currentHeight
+= m_rowHeights
[i
];
1072 // Now we need to do a hit test for which column we're on
1073 int currentWidth
= 0;
1074 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1076 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1081 currentWidth
+= m_colWidths
[i
];
1088 bool wxGenericGrid::LabelSashHitTest(int x
, int y
, int *orientation
, int *rowOrCol
, int *startPos
)
1093 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= m_topOfSheet
&&
1094 x
<= m_rightOfSheet
&& y
<= (m_topOfSheet
+ m_horizontalLabelHeight
))
1096 // We may be on a column label sash.
1097 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1098 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1100 if (x
>= (currentWidth
+ m_colWidths
[i
] - tolerance
) && x
<= (currentWidth
+ m_colWidths
[i
] + tolerance
))
1102 *orientation
= wxHORIZONTAL
;
1104 *startPos
= currentWidth
;
1107 currentWidth
+= m_colWidths
[i
];
1111 else if (x
>= m_leftOfSheet
&& y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1112 x
<= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
<= m_bottomOfSheet
)
1114 // We may be on a row label sash.
1115 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1116 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1118 if (y
>= (currentHeight
+ m_rowHeights
[i
] - tolerance
) && y
<= (currentHeight
+ m_rowHeights
[i
] + tolerance
))
1120 *orientation
= wxVERTICAL
;
1122 *startPos
= currentHeight
;
1125 currentHeight
+= m_rowHeights
[i
];
1132 bool wxGenericGrid::LabelHitTest(int x
, int y
, int *row
, int *col
)
1134 // Find the selected label
1135 if (x
>= m_leftOfSheet
&& y
>= m_topOfSheet
&&
1136 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1138 // Calculate the cell number from x and y
1144 // Now we need to do a hit test for which row we're on
1145 int currentHeight
= m_horizontalLabelHeight
;
1146 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1148 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1153 currentHeight
+= m_rowHeights
[i
];
1155 if (y
>= 0 && y
<= m_horizontalLabelHeight
)
1160 // Now we need to do a hit test for which column we're on
1161 int currentWidth
= m_verticalLabelWidth
;
1162 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1164 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1169 currentWidth
+= m_colWidths
[i
];
1171 if (x
>= 0 && x
<= m_verticalLabelWidth
)
1176 if ((*col
== -1) || (*row
== -1))
1184 void wxGenericGrid::OnMouseEvent(wxMouseEvent
& ev
)
1188 wxClientDC
dc(this);
1192 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1194 OnSelectCellImplementation(& dc
, row
, col
);
1195 OnCellLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1197 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1199 OnLabelLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1203 else if (ev
.Dragging() && ev
.LeftIsDown())
1205 switch (m_dragStatus
)
1207 case wxGRID_DRAG_NONE
:
1210 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &m_dragRowOrCol
, &m_dragStartPosition
))
1212 if (orientation
== wxHORIZONTAL
)
1214 m_dragStatus
= wxGRID_DRAG_LEFT_RIGHT
;
1215 SetCursor(*m_horizontalSashCursor
);
1216 m_dragLastPosition
= (int)ev
.GetX();
1220 m_dragStatus
= wxGRID_DRAG_UP_DOWN
;
1221 SetCursor(*m_verticalSashCursor
);
1222 m_dragLastPosition
= (int)ev
.GetY();
1224 wxClientDC
dc(this);
1226 dc
.SetLogicalFunction(wxINVERT
);
1227 if (orientation
== wxHORIZONTAL
)
1228 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1230 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1237 case wxGRID_DRAG_LEFT_RIGHT
:
1239 wxClientDC
dc(this);
1241 dc
.SetLogicalFunction(wxINVERT
);
1242 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1244 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1247 m_dragLastPosition
= (int)ev
.GetX();
1248 SetCursor(*m_horizontalSashCursor
);
1251 case wxGRID_DRAG_UP_DOWN
:
1253 wxClientDC
dc(this);
1255 dc
.SetLogicalFunction(wxINVERT
);
1256 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1258 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1261 m_dragLastPosition
= (int)ev
.GetY();
1262 SetCursor(*m_verticalSashCursor
);
1267 else if (ev
.Moving())
1269 int rowOrCol
, orientation
, startPos
;
1270 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &rowOrCol
, &startPos
))
1272 if (orientation
== wxHORIZONTAL
)
1273 SetCursor(*m_horizontalSashCursor
);
1275 SetCursor(*m_verticalSashCursor
);
1278 SetCursor(*wxSTANDARD_CURSOR
);
1280 else if (ev
.LeftUp())
1282 switch (m_dragStatus
)
1284 case wxGRID_DRAG_LEFT_RIGHT
:
1286 wxClientDC
dc(this);
1288 dc
.SetLogicalFunction(wxINVERT
);
1289 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1290 dc
.SetLogicalFunction(wxCOPY
);
1294 if (ev
.GetX() > m_dragStartPosition
)
1296 m_colWidths
[m_dragRowOrCol
] = (short)(ev
.GetX() - m_dragStartPosition
);
1301 SetCursor(*wxSTANDARD_CURSOR
);
1303 GetClientSize(&cw
, &ch
);
1308 case wxGRID_DRAG_UP_DOWN
:
1310 wxClientDC
dc(this);
1312 dc
.SetLogicalFunction(wxINVERT
);
1313 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1314 dc
.SetLogicalFunction(wxCOPY
);
1318 if (ev
.GetY() > m_dragStartPosition
)
1320 m_rowHeights
[m_dragRowOrCol
] = (short)(ev
.GetY() - m_dragStartPosition
);
1325 SetCursor(*wxSTANDARD_CURSOR
);
1329 m_dragStatus
= wxGRID_DRAG_NONE
;
1331 else if (ev
.RightDown())
1334 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1336 OnCellRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1338 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1340 OnLabelRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1345 void wxGenericGrid::OnSelectCellImplementation(wxDC
*dc
, int row
, int col
)
1347 m_wCursorColumn
= col
;
1350 OnChangeSelectionLabel();
1352 SetGridClippingRegion(dc
);
1354 // Remove the highlight from the old cell
1355 if (m_currentRectVisible
)
1358 // Highlight the new cell and copy its content to the edit control
1359 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
1360 wxGridCell
*cell
= GetCell(m_wCursorRow
, m_wCursorColumn
);
1363 if ( cell
->GetTextValue().IsNull() )
1364 m_textItem
->SetValue("");
1366 m_textItem
->SetValue(cell
->GetTextValue());
1369 SetGridClippingRegion(dc
);
1371 // Why isn't this needed for Windows??
1372 // Probably because of the SetValue??
1376 dc
->DestroyClippingRegion();
1378 OnSelectCell(row
, col
);
1381 wxGridCell
*wxGenericGrid::OnCreateCell(void)
1383 return new wxGridCell(this);
1386 void wxGenericGrid::OnChangeLabels(void)
1390 for (i
= 0; i
< m_totalRows
; i
++)
1392 sprintf(buf
, "%d", i
+1);
1393 SetLabelValue(wxVERTICAL
, buf
, i
);
1395 // A...Z,AA...ZZ,AAA...ZZZ, etc.
1396 for (i
= 0; i
< m_totalCols
; i
++)
1399 int noTimes
= (i
/26 + 1);
1400 int ch
= (i
% 26) + 65;
1402 for (j
= 0; j
< noTimes
; j
++)
1405 sprintf(buf2
, "%c", (char)ch
);
1408 SetLabelValue(wxHORIZONTAL
, buf
, i
);
1412 void wxGenericGrid::OnChangeSelectionLabel(void)
1417 wxString
rowLabel(GetLabelValue(wxVERTICAL
, GetCursorRow()));
1418 wxString
colLabel(GetLabelValue(wxHORIZONTAL
, GetCursorColumn()));
1420 wxString newLabel
= colLabel
+ rowLabel
;
1421 if ((newLabel
.Length() > 0) && (newLabel
.Length() <= 8) && GetTextItem())
1423 // GetTextItem()->SetLabel(newLabel);
1427 void wxGenericGrid::HighlightCell(wxDC
*dc
)
1429 dc
->SetLogicalFunction(wxINVERT
);
1431 dc
->DrawLine(m_currentRect
.x
+ 1, m_currentRect
.y
+ 1, m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+ 1);
1433 dc
->DrawLine(m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+ 1,
1434 m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+m_currentRect
.height
- 1);
1436 dc
->DrawLine(m_currentRect
.x
+ m_currentRect
.width
- 1, m_currentRect
.y
+ m_currentRect
.height
- 1,
1437 m_currentRect
.x
+ 1, m_currentRect
.y
+ m_currentRect
.height
- 1);
1439 dc
->DrawLine(m_currentRect
.x
+ 1, m_currentRect
.y
+ m_currentRect
.height
- 1, m_currentRect
.x
+ 1, m_currentRect
.y
+ 1);
1441 dc
->SetLogicalFunction(wxCOPY
);
1444 void wxGenericGrid::DrawCellText(void)
1446 if (!m_currentRectVisible
)
1449 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1453 static char szEdit
[300];
1455 wxClientDC
dc(this);
1458 SetGridClippingRegion(& dc
);
1460 dc
.SetBackgroundMode(wxTRANSPARENT
);
1461 dc
.SetBrush(*cell
->GetBackgroundBrush());
1463 strcpy(szEdit
, m_textItem
->GetValue());
1466 rect
= m_currentRect
;
1472 DrawTextRect(& dc
, " ", &rect
, wxLEFT
);
1473 DrawTextRect(& dc
, szEdit
, &rect
, cell
->GetAlignment());
1475 dc
.DestroyClippingRegion();
1477 dc
.SetBackgroundMode(wxSOLID
);
1482 void wxGenericGrid::SetCurrentRect(int Row
, int Column
, int canvasW
, int canvasH
)
1484 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1486 for (i
= m_scrollPosX
; i
< Column
; i
++)
1487 currentWidth
+= m_colWidths
[i
];
1489 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1490 for (i
= m_scrollPosY
; i
< Row
; i
++)
1491 currentHeight
+= m_rowHeights
[i
];
1493 m_currentRect
.x
= currentWidth
;
1494 m_currentRect
.y
= currentHeight
;
1495 m_currentRect
.width
= m_colWidths
? (m_colWidths
[Column
]) : 0;
1496 m_currentRect
.height
= m_rowHeights
? (m_rowHeights
[Row
]) : 0;
1498 if (Row
< m_scrollPosY
|| Column
< m_scrollPosX
)
1499 m_currentRectVisible
= FALSE
;
1500 else if ((canvasW
!= -1 && canvasH
!= -1) && (m_currentRect
.x
> canvasW
|| m_currentRect
.y
> canvasH
))
1501 m_currentRectVisible
= FALSE
;
1502 else m_currentRectVisible
= TRUE
;
1505 static bool wxRectIntersection(wxRectangle
*rect1
, wxRectangle
*rect2
, wxRectangle
*rect3
)
1507 int x2_1
= rect1
->x
+ rect1
->width
;
1508 int y2_1
= rect1
->y
+ rect1
->height
;
1510 int x2_2
= rect2
->x
+ rect2
->width
;
1511 int y2_2
= rect2
->y
+ rect2
->height
;
1515 // Check for intersection
1516 if ((rect1
->x
> x2_2
) || (rect2
->x
> x2_1
) ||
1517 (rect1
->y
> y2_2
) || (rect2
->y
> y2_1
))
1520 rect3
->x
= rect3
->y
= rect3
->width
= rect3
->height
= 0;
1524 if (rect1
->x
> rect2
->x
)
1525 rect3
->x
= rect1
->x
;
1527 rect3
->x
= rect2
->x
;
1528 if (rect1
->y
> rect2
->y
)
1529 rect3
->y
= rect1
->y
;
1531 rect3
->y
= rect2
->y
;
1542 rect3
->width
= (int)(x2_3
- rect3
->x
);
1543 rect3
->height
= (int)(y2_3
- rect3
->y
);
1547 void wxGenericGrid::DrawTextRect(wxDC
*dc
, const wxString
& text
, wxRectangle
*rect
, int flag
)
1551 // Ultimately, this functionality should be built into wxWindows,
1552 // and optimized for each platform. E.g. on Windows, use DrawText
1553 // passing a clipping rectangle, so that the wxWindows clipping region
1554 // does not have to be used to implement this.
1556 // If we're already clipping, we need to find the intersection
1557 // between current clipping area and text clipping area.
1559 wxRectangle clipRect
;
1560 wxRectangle clipRect2
;
1561 long clipX
, clipY
, clipW
, clipH
;
1562 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1563 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1564 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1566 bool alreadyClipping
= TRUE
;
1568 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1570 alreadyClipping
= FALSE
;
1571 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1572 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1576 // Find intersection.
1577 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1581 if (alreadyClipping
)
1582 dc
->DestroyClippingRegion();
1584 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1585 long textWidth
, textHeight
;
1587 dc
->GetTextExtent(text
, &textWidth
, &textHeight
);
1595 x
= (rect
->x
+ rect
->width
- textWidth
- 1.0);
1596 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1601 x
= (rect
->x
+ (rect
->width
- textWidth
)/2.0);
1602 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1608 x
= (rect
->x
+ 1.0);
1609 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1613 dc
->DrawText(text
, (long)x
, (long)y
);
1615 dc
->DestroyClippingRegion();
1617 // Restore old clipping
1618 if (alreadyClipping
)
1619 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1624 void wxGenericGrid::DrawBitmapRect(wxDC
*dc
, wxBitmap
*bitmap
, wxRectangle
*rect
, int flag
)
1628 // Ultimately, this functionality should be built into wxWindows,
1629 // and optimized for each platform. E.g. on Windows, use DrawText
1630 // passing a clipping rectangle, so that the wxWindows clipping region
1631 // does not have to be used to implement this.
1633 // If we're already clipping, we need to find the intersection
1634 // between current clipping area and text clipping area.
1636 wxRectangle clipRect
;
1637 wxRectangle clipRect2
;
1638 long clipX
, clipY
, clipW
, clipH
;
1639 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1640 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1641 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1643 bool alreadyClipping
= TRUE
;
1645 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1647 alreadyClipping
= FALSE
;
1648 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1649 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1653 // Find intersection.
1654 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1658 if (alreadyClipping
)
1659 dc
->DestroyClippingRegion();
1661 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1662 float bitmapWidth
, bitmapHeight
;
1664 bitmapWidth
= bitmap
->GetWidth();
1665 bitmapHeight
= bitmap
->GetHeight();
1673 x
= (long)(rect
->x
+ rect
->width
- bitmapWidth
- 1);
1674 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1679 x
= (long)(rect
->x
+ (rect
->width
- bitmapWidth
)/2.0);
1680 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1686 x
= (long)(rect
->x
+ 1);
1687 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1692 dcTemp
.SelectObject(*bitmap
);
1694 dc
->Blit( (long)x
, (long)y
, (long)bitmapWidth
, (long)bitmapHeight
, &dcTemp
, 0, 0);
1695 dcTemp
.SelectObject(wxNullBitmap
);
1697 dc
->DestroyClippingRegion();
1699 // Restore old clipping
1700 if (alreadyClipping
)
1701 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1706 void wxGenericGrid::OnActivate(bool active
)
1710 // Edit control should always have the focus
1711 if (GetTextItem() && GetEditable())
1713 GetTextItem()->SetFocus();
1714 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1716 GetTextItem()->SetValue(cell
->GetTextValue());
1721 void wxGenericGrid::SetCellValue(const wxString
& val
, int row
, int col
)
1723 wxGridCell
*cell
= GetCell(row
, col
);
1726 cell
->SetTextValue(val
);
1728 RefreshCell(row
, col
, TRUE
);
1732 void wxGenericGrid::RefreshCell(int row
, int col
, bool setText
)
1734 // Don't refresh within a pair of batch brackets
1735 if (GetBatchCount() > 0)
1739 GetClientSize(&cw
, &ch
);
1741 SetCurrentRect(row
, col
, cw
, ch
);
1742 if (m_currentRectVisible
)
1744 wxGridCell
*cell
= GetCell(row
, col
);
1746 bool currentPos
= FALSE
;
1747 if (row
== m_wCursorRow
&& col
== m_wCursorColumn
&& GetTextItem() && GetTextItem()->IsShown() && setText
)
1749 GetTextItem()->SetValue(cell
->GetTextValue());
1752 // Gets refreshed anyway in MSW
1757 wxClientDC
dc(this);
1759 DrawCellBackground(& dc
, &m_currentRect
, row
, col
);
1760 DrawCellValue(& dc
, &m_currentRect
, row
, col
);
1766 wxString
& wxGenericGrid::GetCellValue(int row
, int col
)
1768 static wxString
emptyString("");
1770 wxGridCell
*cell
= GetCell(row
, col
);
1772 return cell
->GetTextValue();
1777 void wxGenericGrid::SetColumnWidth(int col
, int width
)
1779 if (col
<= m_totalCols
)
1780 m_colWidths
[col
] = width
;
1783 int wxGenericGrid::GetColumnWidth(int col
)
1785 if (col
<= m_totalCols
)
1786 return m_colWidths
[col
];
1791 void wxGenericGrid::SetRowHeight(int row
, int height
)
1793 if (row
<= m_totalRows
)
1794 m_rowHeights
[row
] = height
;
1797 int wxGenericGrid::GetRowHeight(int row
)
1799 if (row
<= m_totalRows
)
1800 return m_rowHeights
[row
];
1805 void wxGenericGrid::SetLabelSize(int orientation
, int sz
)
1807 if (orientation
== wxHORIZONTAL
)
1808 m_horizontalLabelHeight
= sz
;
1810 m_verticalLabelWidth
= sz
;
1812 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1815 int wxGenericGrid::GetLabelSize(int orientation
)
1817 if (orientation
== wxHORIZONTAL
)
1818 return m_horizontalLabelHeight
;
1820 return m_verticalLabelWidth
;
1823 wxGridCell
*wxGenericGrid::GetLabelCell(int orientation
, int pos
)
1825 if (orientation
== wxHORIZONTAL
)
1827 if (m_colLabelCells
&& pos
< m_totalCols
)
1828 return m_colLabelCells
[pos
];
1834 if (m_rowLabelCells
&& pos
< m_totalRows
)
1835 return m_rowLabelCells
[pos
];
1841 void wxGenericGrid::SetLabelValue(int orientation
, const wxString
& val
, int pos
)
1843 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1845 cell
->SetTextValue(val
);
1848 wxString
& wxGenericGrid::GetLabelValue(int orientation
, int pos
)
1850 static wxString emptyString
= "";
1851 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1853 return cell
->GetTextValue();
1858 void wxGenericGrid::SetLabelAlignment(int orientation
, int align
)
1860 if (orientation
== wxHORIZONTAL
)
1861 m_horizontalLabelAlignment
= align
;
1863 m_verticalLabelAlignment
= align
;
1865 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1868 int wxGenericGrid::GetLabelAlignment(int orientation
)
1870 if (orientation
== wxHORIZONTAL
)
1871 return m_horizontalLabelAlignment
;
1873 return m_verticalLabelAlignment
;
1876 void wxGenericGrid::SetLabelTextColour(const wxColour
& colour
)
1878 m_labelTextColour
= colour
;
1882 void wxGenericGrid::SetLabelBackgroundColour(const wxColour
& colour
)
1884 m_labelBackgroundColour
= colour
;
1885 m_labelBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush(m_labelBackgroundColour
, wxSOLID
);
1888 void wxGenericGrid::SetEditable(bool edit
)
1893 int controlW
, controlH
;
1894 m_textItem
->GetSize(&controlW
, &controlH
);
1895 m_editControlPosition
.height
= controlH
;
1897 m_topOfSheet
= m_editControlPosition
.x
+ controlH
+ 2;
1900 m_editingPanel
->Show(TRUE
);
1901 m_textItem
->Show(TRUE
);
1902 m_textItem
->SetFocus();
1910 m_textItem
->Show(FALSE
);
1911 m_editingPanel
->Show(FALSE
);
1915 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1918 GetClientSize(&cw
, &ch
);
1923 int m_scrollWidth = 16;
1924 GetClientSize(&cw, &ch);
1927 m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
1928 m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
1932 void wxGenericGrid::SetCellAlignment(int flag
, int row
, int col
)
1934 wxGridCell
*cell
= GetCell(row
, col
);
1936 cell
->SetAlignment(flag
);
1939 int wxGenericGrid::GetCellAlignment(int row
, int col
)
1941 wxGridCell
*cell
= GetCell(row
, col
);
1943 return cell
->GetAlignment();
1945 return m_cellAlignment
;
1948 void wxGenericGrid::SetCellAlignment(int flag
)
1950 m_cellAlignment
= flag
;
1952 for (i
= 0; i
< GetRows(); i
++)
1953 for (j
= 0; j
< GetCols(); j
++)
1955 GetCell(i
, j
)->SetAlignment(flag
);
1958 int wxGenericGrid::GetCellAlignment(void)
1960 return m_cellAlignment
;
1963 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& col
)
1965 m_cellBackgroundColour
= col
;
1967 for (i
= 0; i
< GetRows(); i
++)
1968 for (j
= 0; j
< GetCols(); j
++)
1970 GetCell(i
, j
)->SetBackgroundColour(col
);
1973 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& val
, int row
, int col
)
1975 wxGridCell
*cell
= GetCell(row
, col
);
1978 cell
->SetBackgroundColour(val
);
1979 RefreshCell(row
, col
);
1983 wxColour
& wxGenericGrid::GetCellBackgroundColour(int row
, int col
)
1985 wxGridCell
*cell
= GetCell(row
, col
);
1987 return cell
->GetBackgroundColour();
1989 return m_cellBackgroundColour
;
1992 void wxGenericGrid::SetCellTextColour(const wxColour
& val
, int row
, int col
)
1994 wxGridCell
*cell
= GetCell(row
, col
);
1997 cell
->SetTextColour(val
);
1998 RefreshCell(row
, col
);
2002 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
, int row
, int col
)
2004 wxGridCell
*cell
= GetCell(row
, col
);
2008 RefreshCell(row
, col
);
2012 wxFont
*wxGenericGrid::GetCellTextFont(int row
, int col
)
2014 wxGridCell
*cell
= GetCell(row
, col
);
2016 return cell
->GetFont();
2018 return m_cellTextFont
;
2021 wxColour
& wxGenericGrid::GetCellTextColour(int row
, int col
)
2023 wxGridCell
*cell
= GetCell(row
, col
);
2025 return cell
->GetTextColour();
2027 return m_cellTextColour
;
2030 void wxGenericGrid::SetCellTextColour(const wxColour
& val
)
2032 m_cellTextColour
= val
;
2034 for (i
= 0; i
< GetRows(); i
++)
2035 for (j
= 0; j
< GetCols(); j
++)
2037 GetCell(i
, j
)->SetTextColour(val
);
2040 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
)
2042 m_cellTextFont
= fnt
;
2044 for (i
= 0; i
< GetRows(); i
++)
2045 for (j
= 0; j
< GetCols(); j
++)
2047 GetCell(i
, j
)->SetFont(fnt
);
2050 void wxGenericGrid::SetCellBitmap(wxBitmap
*bitmap
, int row
, int col
)
2052 wxGridCell
*cell
= GetCell(row
, col
);
2055 cell
->SetCellBitmap(bitmap
);
2056 RefreshCell(row
, col
);
2060 wxBitmap
*wxGenericGrid::GetCellBitmap(int row
, int col
)
2062 wxGridCell
*cell
= GetCell(row
, col
);
2065 return cell
->GetCellBitmap();
2071 bool wxGenericGrid::InsertCols(int pos
, int n
, bool updateLabels
)
2073 if (pos
> m_totalCols
)
2077 return CreateGrid(1, n
);
2082 for (i
= 0; i
< m_totalRows
; i
++)
2084 wxGridCell
**cols
= m_gridCells
[i
];
2085 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
+ n
];
2086 for (j
= 0; j
< pos
; j
++)
2087 newCols
[j
] = cols
[j
];
2088 for (j
= pos
; j
< pos
+ n
; j
++)
2089 newCols
[j
] = new wxGridCell(this);
2090 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2091 newCols
[j
] = cols
[j
- n
];
2094 m_gridCells
[i
] = newCols
;
2098 short *newColWidths
= new short[m_totalCols
+ n
];
2099 for (j
= 0; j
< pos
; j
++)
2100 newColWidths
[j
] = m_colWidths
[j
];
2101 for (j
= pos
; j
< pos
+ n
; j
++)
2102 newColWidths
[j
] = wxGRID_DEFAULT_CELL_WIDTH
;
2103 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2104 newColWidths
[j
] = m_colWidths
[j
- n
];
2105 delete[] m_colWidths
;
2106 m_colWidths
= newColWidths
;
2109 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
+ n
];
2110 for (j
= 0; j
< pos
; j
++)
2111 newLabels
[j
] = m_colLabelCells
[j
];
2112 for (j
= pos
; j
< pos
+ n
; j
++)
2113 newLabels
[j
] = new wxGridCell(this);
2114 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2115 newLabels
[j
] = m_colLabelCells
[j
- n
];
2117 delete[] m_colLabelCells
;
2118 m_colLabelCells
= newLabels
;
2130 bool wxGenericGrid::InsertRows(int pos
, int n
, bool updateLabels
)
2132 if (pos
> m_totalRows
)
2136 return CreateGrid(n
, 1);
2141 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
+ n
];
2144 for (i
= 0; i
< pos
; i
++)
2145 rows
[i
] = m_gridCells
[i
];
2147 for (i
= pos
; i
< pos
+ n
; i
++)
2149 rows
[i
] = new wxGridCell
*[m_totalCols
];
2150 for (j
= 0; j
< m_totalCols
; j
++)
2151 rows
[i
][j
] = new wxGridCell(this);
2154 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2155 rows
[i
] = m_gridCells
[i
- n
];
2157 delete[] m_gridCells
;
2161 short *newRowHeights
= new short[m_totalRows
+ n
];
2162 for (i
= 0; i
< pos
; i
++)
2163 newRowHeights
[i
] = m_rowHeights
[i
];
2164 for (i
= pos
; i
< pos
+ n
; i
++)
2165 newRowHeights
[i
] = wxGRID_DEFAULT_CELL_HEIGHT
;
2166 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2167 newRowHeights
[i
] = m_rowHeights
[i
- n
];
2168 delete[] m_rowHeights
;
2169 m_rowHeights
= newRowHeights
;
2172 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
+ n
];
2173 for (i
= 0; i
< pos
; i
++)
2174 newLabels
[i
] = m_rowLabelCells
[i
];
2175 for (i
= pos
; i
< pos
+ n
; i
++)
2176 newLabels
[i
] = new wxGridCell(this);
2177 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2178 newLabels
[i
] = m_rowLabelCells
[i
- n
];
2180 delete[] m_rowLabelCells
;
2181 m_rowLabelCells
= newLabels
;
2193 bool wxGenericGrid::AppendCols(int n
, bool updateLabels
)
2195 return InsertCols(GetCols(), n
, updateLabels
);
2198 bool wxGenericGrid::AppendRows(int n
, bool updateLabels
)
2200 return InsertRows(GetRows(), n
, updateLabels
);
2203 bool wxGenericGrid::DeleteRows(int pos
, int n
, bool updateLabels
)
2205 if (pos
> m_totalRows
)
2212 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
- n
];
2215 for (i
= 0; i
< pos
; i
++)
2216 rows
[i
] = m_gridCells
[i
];
2218 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2219 rows
[i
-n
] = m_gridCells
[i
];
2221 delete[] m_gridCells
;
2225 short *newRowHeights
= new short[m_totalRows
- n
];
2226 for (i
= 0; i
< pos
; i
++)
2227 newRowHeights
[i
] = m_rowHeights
[i
];
2228 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2229 newRowHeights
[i
-n
] = m_rowHeights
[i
];
2230 delete[] m_rowHeights
;
2231 m_rowHeights
= newRowHeights
;
2234 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
- n
];
2235 for (i
= 0; i
< pos
; i
++)
2236 newLabels
[i
] = m_rowLabelCells
[i
];
2237 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2238 newLabels
[i
-n
] = m_rowLabelCells
[i
];
2240 delete[] m_rowLabelCells
;
2241 m_rowLabelCells
= newLabels
;
2252 bool wxGenericGrid::DeleteCols(int pos
, int n
, bool updateLabels
)
2254 if (pos
+ n
> m_totalCols
)
2262 for (i
= 0; i
< m_totalRows
; i
++)
2264 wxGridCell
**cols
= m_gridCells
[i
];
2265 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
- n
];
2266 for (j
= 0; j
< pos
; j
++)
2267 newCols
[j
] = cols
[j
];
2268 for (j
= pos
; j
< pos
+ n
; j
++)
2270 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2271 newCols
[j
-n
] = cols
[j
];
2274 m_gridCells
[i
] = newCols
;
2278 short *newColWidths
= new short[m_totalCols
- n
];
2279 for (j
= 0; j
< pos
; j
++)
2280 newColWidths
[j
] = m_colWidths
[j
];
2281 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2282 newColWidths
[j
-n
] = m_colWidths
[j
];
2283 delete[] m_colWidths
;
2284 m_colWidths
= newColWidths
;
2287 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
- n
];
2288 for (j
= 0; j
< pos
; j
++)
2289 newLabels
[j
] = m_colLabelCells
[j
];
2290 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2291 newLabels
[j
-n
] = m_colLabelCells
[j
];
2293 delete[] m_colLabelCells
;
2294 m_colLabelCells
= newLabels
;
2305 void wxGenericGrid::SetGridCursor(int row
, int col
)
2307 if (row
>= m_totalRows
|| col
>= m_totalCols
)
2310 if (row
== GetCursorRow() && col
== GetCursorColumn())
2313 wxClientDC
dc(this);
2316 SetGridClippingRegion(& dc
);
2318 if (m_currentRectVisible
)
2319 HighlightCell(& dc
);
2322 m_wCursorColumn
= col
;
2323 SetCurrentRect(row
, col
);
2324 if (m_currentRectVisible
)
2325 HighlightCell(& dc
);
2327 dc
.DestroyClippingRegion();
2335 wxGridCell::wxGridCell(wxGenericGrid
*window
)
2339 backgroundBrush
= NULL
;
2341 textColour
= window
->GetCellTextColour();
2343 textColour
.Set(0,0,0);
2345 backgroundColour
= window
->GetCellBackgroundColour();
2347 backgroundColour
.Set(255,255,255);
2350 font
= window
->GetCellTextFont();
2352 font
= wxTheFontList
->FindOrCreateFont(12, wxSWISS
, wxNORMAL
, wxNORMAL
);
2354 SetBackgroundColour(backgroundColour
);
2357 alignment
= window
->GetCellAlignment();
2362 wxGridCell::~wxGridCell(void)
2366 void wxGridCell::SetBackgroundColour(const wxColour
& colour
)
2368 backgroundColour
= colour
;
2369 backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(backgroundColour
, wxSOLID
);
2372 void wxGenericGrid::OnText(wxCommandEvent
& WXUNUSED(ev
) )
2374 wxGenericGrid
*grid
= this;
2375 wxGridCell
*cell
= grid
->GetCell(grid
->GetCursorRow(), grid
->GetCursorColumn());
2376 if (cell
&& grid
->CurrentCellVisible())
2378 cell
->SetTextValue(grid
->GetTextItem()->GetValue());
2379 wxClientDC
dc(grid
);
2382 grid
->SetGridClippingRegion(& dc
);
2383 grid
->DrawCellBackground(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2384 grid
->DrawCellValue(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2385 grid
->HighlightCell(& dc
);
2386 dc
.DestroyClippingRegion();
2389 grid
->OnCellChange(grid
->GetCursorRow(), grid
->GetCursorColumn());
2391 // grid->DrawCellText();
2395 void wxGenericGrid::OnGridScroll(wxScrollEvent
& ev
)
2397 static bool inScroll
= FALSE
;
2403 wxGenericGrid
*win
= this;
2405 bool change
= FALSE
;
2407 if (ev
.GetEventObject() == win
->GetHorizScrollBar())
2409 change
= (ev
.GetPosition() != m_scrollPosX
);
2410 win
->SetScrollPosX(ev
.GetPosition());
2414 change
= (ev
.GetPosition() != m_scrollPosY
);
2415 win
->SetScrollPosY(ev
.GetPosition());
2418 win
->UpdateDimensions();
2419 win
->SetCurrentRect(win
->GetCursorRow(), win
->GetCursorColumn());
2421 // Because rows and columns can be arbitrary sizes,
2422 // the scrollbars will need to be adjusted to reflect the
2426 if (change
) win
->Refresh(FALSE
);