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_labelBackgroundColour
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
67 m_labelBackgroundBrush
= NULL
;
68 m_labelTextFont
= NULL
;
69 m_cellTextFont
= NULL
;
71 m_currentRectVisible
= FALSE
;
73 #if defined(__WIN95__)
74 m_scrollWidth
= wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X
);
78 m_dragStatus
= wxGRID_DRAG_NONE
;
80 m_dragStartPosition
= 0;
81 m_dragLastPosition
= 0;
83 m_leftOfSheet
= wxGRID_DEFAULT_SHEET_LEFT
;
84 m_topOfSheet
= wxGRID_DEFAULT_SHEET_TOP
;
85 m_cellHeight
= wxGRID_DEFAULT_CELL_HEIGHT
;
87 m_totalGridHeight
= 0;
90 m_verticalLabelWidth
= wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH
;
91 m_horizontalLabelHeight
= wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT
;
92 m_verticalLabelAlignment
= wxCENTRE
;
93 m_horizontalLabelAlignment
= wxCENTRE
;
94 m_editControlPosition
.x
= wxGRID_DEFAULT_EDIT_X
;
95 m_editControlPosition
.y
= wxGRID_DEFAULT_EDIT_Y
;
96 m_editControlPosition
.width
= wxGRID_DEFAULT_EDIT_WIDTH
;
97 m_editControlPosition
.height
= wxGRID_DEFAULT_EDIT_HEIGHT
;
102 m_editCreated
= FALSE
;
106 m_rowLabelCells
= NULL
;
107 m_colLabelCells
= NULL
;
109 m_horizontalSashCursor
= NULL
;
110 m_verticalSashCursor
= NULL
;
113 bool wxGenericGrid::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
114 long style
, const wxString
& name
)
117 m_editingPanel
= NULL
;
120 m_horizontalSashCursor
= NULL
;
121 m_verticalSashCursor
= NULL
;
122 m_cellTextColour
= *wxBLACK
;
123 m_cellBackgroundColour
= *wxWHITE
;
124 m_labelTextColour
= *wxBLACK
;
125 // m_labelBackgroundColour = *wxLIGHT_GREY;
126 m_labelBackgroundColour
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
127 m_labelBackgroundBrush
= NULL
;
128 m_labelTextFont
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
129 m_cellTextFont
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
131 m_currentRectVisible
= FALSE
;
133 #if defined(__WIN95__)
134 m_scrollWidth
= wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X
);
138 m_dragStatus
= wxGRID_DRAG_NONE
;
140 m_dragStartPosition
= 0;
141 m_dragLastPosition
= 0;
142 m_divisionPen
= wxThePenList
->FindOrCreatePen("LIGHT GREY", 1, wxSOLID
);
143 m_doubleBufferingBitmap
= NULL
;
145 if (!m_horizontalSashCursor
)
147 m_horizontalSashCursor
= new wxCursor(wxCURSOR_SIZEWE
);
148 m_verticalSashCursor
= new wxCursor(wxCURSOR_SIZENS
);
151 SetLabelBackgroundColour(m_labelBackgroundColour
);
153 m_leftOfSheet
= wxGRID_DEFAULT_SHEET_LEFT
;
154 m_topOfSheet
= wxGRID_DEFAULT_SHEET_TOP
;
155 m_cellHeight
= wxGRID_DEFAULT_CELL_HEIGHT
;
156 m_totalGridWidth
= 0;
157 m_totalGridHeight
= 0;
161 m_verticalLabelWidth
= wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH
;
162 m_horizontalLabelHeight
= wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT
;
163 m_verticalLabelAlignment
= wxCENTRE
;
164 m_horizontalLabelAlignment
= wxCENTRE
;
165 m_editControlPosition
.x
= wxGRID_DEFAULT_EDIT_X
;
166 m_editControlPosition
.y
= wxGRID_DEFAULT_EDIT_Y
;
167 m_editControlPosition
.width
= wxGRID_DEFAULT_EDIT_WIDTH
;
168 m_editControlPosition
.height
= wxGRID_DEFAULT_EDIT_HEIGHT
;
176 /* Store the rect. coordinates for the current cell */
177 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
179 m_editCreated
= FALSE
;
184 m_rowLabelCells
= NULL
;
185 m_colLabelCells
= NULL
;
188 wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
190 m_editingPanel
= new wxPanel(this);
192 m_textItem
= new wxTextCtrl(m_editingPanel
, wxGRID_TEXT_CTRL
, "",
193 wxPoint(m_editControlPosition
.x
, m_editControlPosition
.y
), wxSize(m_editControlPosition
.width
, -1),
195 m_textItem
->Show(TRUE
);
196 m_textItem
->SetFocus();
197 int controlW
, controlH
;
199 m_textItem
->GetSize(&controlW
, &controlH
);
200 m_editControlPosition
.height
= controlH
;
202 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
204 m_editCreated
= TRUE
;
206 m_hScrollBar
= new wxScrollBar(this, wxGRID_HSCROLL
, wxPoint(0, 0), wxSize(20, 100), wxHORIZONTAL
);
207 m_vScrollBar
= new wxScrollBar(this, wxGRID_VSCROLL
, wxPoint(0, 0), wxSize(100, 20), wxVERTICAL
);
212 wxGenericGrid::~wxGenericGrid(void)
217 void wxGenericGrid::ClearGrid(void)
222 for (i
= 0; i
< m_totalRows
; i
++)
224 for (j
= 0; j
< m_totalCols
; j
++)
225 if (m_gridCells
[i
][j
])
226 delete m_gridCells
[i
][j
];
227 delete[] m_gridCells
[i
];
229 delete[] m_gridCells
;
233 delete[] m_colWidths
;
236 delete[] m_rowHeights
;
241 for (i
= 0; i
< m_totalRows
; i
++)
242 delete m_rowLabelCells
[i
];
243 delete[] m_rowLabelCells
;
244 m_rowLabelCells
= NULL
;
248 for (i
= 0; i
< m_totalCols
; i
++)
249 delete m_colLabelCells
[i
];
250 delete[] m_colLabelCells
;
251 m_colLabelCells
= NULL
;
253 if (m_doubleBufferingBitmap
)
255 delete m_doubleBufferingBitmap
;
256 m_doubleBufferingBitmap
= NULL
;
260 bool wxGenericGrid::CreateGrid(int nRows
, int nCols
, wxString
**cellValues
, short *widths
,
261 short defaultWidth
, short defaultHeight
)
267 m_colWidths
= new short[nCols
];
268 m_rowHeights
= new short[nRows
];
269 for (i
= 0; i
< nCols
; i
++)
271 m_colWidths
[i
] = widths
[i
];
273 m_colWidths
[i
] = defaultWidth
;
274 for (i
= 0; i
< nRows
; i
++)
275 m_rowHeights
[i
] = defaultHeight
;
277 m_gridCells
= new wxGridCell
**[nRows
];
279 for (i
= 0; i
< nRows
; i
++)
280 m_gridCells
[i
] = new wxGridCell
*[nCols
];
282 for (i
= 0; i
< nRows
; i
++)
283 for (j
= 0; j
< nCols
; j
++)
286 m_gridCells
[i
][j
] = OnCreateCell();
287 m_gridCells
[i
][j
]->SetTextValue(cellValues
[i
][j
]);
290 m_gridCells
[i
][j
] = NULL
;
292 m_rowLabelCells
= new wxGridCell
*[nRows
];
293 for (i
= 0; i
< nRows
; i
++)
294 m_rowLabelCells
[i
] = new wxGridCell(this);
295 m_colLabelCells
= new wxGridCell
*[nCols
];
296 for (i
= 0; i
< nCols
; i
++)
297 m_colLabelCells
[i
] = new wxGridCell(this);
299 m_wCursorRow
= m_wCursorColumn
= 0;
300 SetCurrentRect(0, 0);
302 // Need to determine various dimensions
306 int objectSizeX
= m_totalCols
;
308 int viewLengthX
= m_totalCols
;
311 m_hScrollBar->SetViewLength(viewLengthX);
312 m_hScrollBar->SetObjectLength(objectSizeX);
313 m_hScrollBar->SetPageSize(pageSizeX);
315 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetPosition(), pageSizeX
, objectSizeX
, viewLengthX
);
317 int objectSizeY
= m_totalRows
;
319 int viewLengthY
= m_totalRows
;
322 m_vScrollBar->SetViewLength(viewLengthY);
323 m_vScrollBar->SetObjectLength(objectSizeY);
324 m_vScrollBar->SetPageSize(pageSizeY);
327 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetPosition(), pageSizeY
, objectSizeY
, viewLengthY
);
332 OnChangeSelectionLabel();
337 // Need to determine various dimensions
338 void wxGenericGrid::UpdateDimensions(void)
340 int canvasWidth
, canvasHeight
;
341 GetSize(&canvasWidth
, &canvasHeight
);
343 if (m_editCreated
&& m_editable
)
345 int controlW
, controlH
;
346 GetTextItem()->GetSize(&controlW
, &controlH
);
347 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
351 m_rightOfSheet
= m_leftOfSheet
+ m_verticalLabelWidth
;
353 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
355 if (m_rightOfSheet
> canvasWidth
)
358 m_rightOfSheet
+= m_colWidths
[i
];
360 m_bottomOfSheet
= m_topOfSheet
+ m_horizontalLabelHeight
;
361 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
363 if (m_bottomOfSheet
> canvasHeight
)
366 m_bottomOfSheet
+= m_rowHeights
[i
];
369 m_totalGridWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
370 for (i
= 0; i
< m_totalCols
; i
++)
372 m_totalGridWidth
+= m_colWidths
[i
];
374 m_totalGridHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
375 for (i
= 0; i
< m_totalRows
; i
++)
377 m_totalGridHeight
+= m_rowHeights
[i
];
381 wxGridCell
*wxGenericGrid::GetCell(int row
, int col
)
386 if ((row
>= m_totalRows
) || (col
>= m_totalCols
))
389 wxGridCell
*cell
= m_gridCells
[row
][col
];
392 m_gridCells
[row
][col
] = OnCreateCell();
393 return m_gridCells
[row
][col
];
399 void wxGenericGrid::SetGridClippingRegion(wxDC
*dc
)
401 int m_scrollWidthHoriz
= 0;
402 int m_scrollWidthVert
= 0;
404 GetClientSize(&cw
, &ch
);
406 if (m_hScrollBar
&& m_hScrollBar
->IsShown())
407 m_scrollWidthHoriz
= m_scrollWidth
;
408 if (m_vScrollBar
&& m_vScrollBar
->IsShown())
409 m_scrollWidthVert
= m_scrollWidth
;
411 // Don't paint over the scrollbars
412 dc
->SetClippingRegion(m_leftOfSheet
, m_topOfSheet
,
413 cw
- m_scrollWidthVert
- m_leftOfSheet
, ch
- m_scrollWidthHoriz
- m_topOfSheet
);
416 void wxGenericGrid::OnPaint(wxPaintEvent
& WXUNUSED(event
))
419 GetClientSize(&w
, &h
);
421 bool useDoubleBuffering
= (bool) USE_DOUBLE_BUFFERING
;
422 if (useDoubleBuffering
)
424 // Reuse the old bitmap if possible
426 if (!m_doubleBufferingBitmap
||
427 (m_doubleBufferingBitmap
->GetWidth() < w
|| m_doubleBufferingBitmap
->GetHeight() < h
))
429 if (m_doubleBufferingBitmap
)
430 delete m_doubleBufferingBitmap
;
431 m_doubleBufferingBitmap
= new wxBitmap(w
, h
);
433 if (!m_doubleBufferingBitmap
|| !m_doubleBufferingBitmap
->Ok())
435 // If we couldn't create a new bitmap, perhaps because resources were low,
436 // then don't complain, just don't double-buffer
437 if (m_doubleBufferingBitmap
)
438 delete m_doubleBufferingBitmap
;
439 m_doubleBufferingBitmap
= NULL
;
440 useDoubleBuffering
= FALSE
;
444 if (useDoubleBuffering
)
446 wxPaintDC
paintDC(this);
447 wxMemoryDC
dc(& paintDC
);
448 dc
.SelectObject(* m_doubleBufferingBitmap
);
452 int vertScrollBarWidth
= m_scrollWidth
;
453 int horizScrollBarHeight
= m_scrollWidth
;
454 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
455 vertScrollBarWidth
= 0;
456 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
457 horizScrollBarHeight
= 0;
459 paintDC
.Blit(m_leftOfSheet
, m_topOfSheet
, w
- vertScrollBarWidth
- m_leftOfSheet
, h
- horizScrollBarHeight
- m_topOfSheet
,
460 &dc
, m_leftOfSheet
, m_topOfSheet
, wxCOPY
);
462 dc
.SelectObject(wxNullBitmap
);
471 void wxGenericGrid::PaintGrid(wxDC
& dc
)
474 dc
.SetOptimization(FALSE
);
476 SetGridClippingRegion(& dc
);
478 DrawLabelAreas(& dc
);
480 DrawEditableArea(& dc
);
481 DrawColumnLabels(& dc
);
486 /* Hilight present cell */
487 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
488 if (m_currentRectVisible
)
491 dc
.DestroyClippingRegion();
492 dc
.SetOptimization(TRUE
);
496 // Erase (some of) the background.
497 // Currently, a Windows-only optimisation.
498 void wxGenericGrid::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
) )
502 dc
.SetOptimization(FALSE
);
505 GetClientSize(& w
, & h
);
506 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
);
507 dc
.SetPen(*wxLIGHT_GREY_PEN
);
509 if (m_hScrollBar
&& m_hScrollBar
->IsShown() && m_vScrollBar
&& m_vScrollBar
->IsShown())
511 dc
.DrawRectangle(w
- m_scrollWidth
, h
- m_scrollWidth
, m_scrollWidth
, m_scrollWidth
);
514 dc
.SetOptimization(TRUE
);
519 void wxGenericGrid::DrawLabelAreas(wxDC
*dc
)
522 GetClientSize(&cw
, &ch
);
524 dc
->SetPen(*wxTRANSPARENT_PEN
);
525 // dc->SetBrush(*dc->GetBackground());
527 // Should blank out any area which isn't going to be painted over.
528 // dc->DrawRectangle(m_leftOfSheet, m_bottomOfSheet, cw - m_leftOfSheet, ch - m_bottomOfSheet);
529 // dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet);
531 // Paint the label areas
532 dc
->SetBrush(*m_labelBackgroundBrush
);
533 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1);
534 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, cw
-m_leftOfSheet
, m_horizontalLabelHeight
+ 1);
535 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1);
536 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, m_verticalLabelWidth
+ 1, ch
-m_topOfSheet
);
539 void wxGenericGrid::DrawEditableArea(wxDC
*dc
)
542 GetClientSize(&cw
, &ch
);
544 dc
->SetPen(*wxTRANSPARENT_PEN
);
545 dc
->SetBrush(*wxTheBrushList
->FindOrCreateBrush(m_cellBackgroundColour
, wxSOLID
));
546 // dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight,
547 // m_rightOfSheet-(m_leftOfSheet+m_verticalLabelWidth) + 1, m_bottomOfSheet - (m_topOfSheet+m_horizontalLabelHeight) + 1);
548 dc
->DrawRectangle(m_leftOfSheet
+m_verticalLabelWidth
, m_topOfSheet
+m_horizontalLabelHeight
,
549 cw
-(m_leftOfSheet
+m_verticalLabelWidth
), ch
- (m_topOfSheet
+m_horizontalLabelHeight
));
552 void wxGenericGrid::DrawGridLines(wxDC
*dc
)
555 GetClientSize(&cw
, &ch
);
561 dc
->SetPen(*m_divisionPen
);
563 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
565 // Draw horizontal grey lines for cells
566 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
568 if (heightCount
> ch
)
572 dc
->DrawLine(m_leftOfSheet
, heightCount
,
575 heightCount
+= m_rowHeights
[i
];
580 if (m_verticalLabelWidth
> 0)
582 dc
->SetPen(*wxBLACK_PEN
);
584 // Draw horizontal black lines for row labels
585 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
586 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
588 if (heightCount
> ch
)
592 dc
->DrawLine(m_leftOfSheet
, heightCount
,
593 m_verticalLabelWidth
, heightCount
);
595 heightCount
+= m_rowHeights
[i
];
598 // Draw a black vertical line for row number cells
599 dc
->DrawLine(m_leftOfSheet
+ m_verticalLabelWidth
, m_topOfSheet
,
600 m_leftOfSheet
+ m_verticalLabelWidth
, ch
);
601 // First vertical line
602 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
, m_leftOfSheet
, ch
);
604 dc
->SetPen(*wxWHITE_PEN
);
606 // Draw highlights on row labels
607 heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
608 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
610 if (heightCount
> ch
)
614 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
615 m_verticalLabelWidth
, heightCount
+1);
616 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
617 m_leftOfSheet
+1, heightCount
+ m_rowHeights
[i
] - 1);
618 heightCount
+= m_rowHeights
[i
];
621 // Last one - down to the floor.
622 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
623 m_verticalLabelWidth
, heightCount
+1);
624 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
625 m_leftOfSheet
+1, ch
);
631 dc
->SetPen(*m_divisionPen
);
633 // Draw vertical grey lines for cells
634 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
635 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
641 // Skip the first one
642 if (i
!= m_scrollPosX
)
644 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
645 widthCount
, m_bottomOfSheet
);
647 widthCount
+= m_colWidths
[i
];
651 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
652 widthCount
, m_bottomOfSheet
);
655 dc
->SetPen(*wxBLACK_PEN
);
657 // Draw two black horizontal lines for column number cells
659 m_leftOfSheet
, m_topOfSheet
,
661 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
+ m_horizontalLabelHeight
,
662 cw
, m_topOfSheet
+ m_horizontalLabelHeight
);
664 if (m_horizontalLabelHeight
> 0)
666 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
668 // Draw black vertical lines for column number cells
669 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
675 dc
->DrawLine(widthCount
, m_topOfSheet
,
676 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
677 widthCount
+= m_colWidths
[i
];
682 dc
->DrawLine(widthCount
, m_topOfSheet
,
683 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
686 dc
->SetPen(*wxWHITE_PEN
);
687 widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
689 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
695 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
696 widthCount
+m_colWidths
[i
], m_topOfSheet
+1);
697 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
698 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
699 widthCount
+= m_colWidths
[i
];
702 // Last one - to the right side of the canvas.
703 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
705 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
706 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
711 void wxGenericGrid::DrawColumnLabels(wxDC
*dc
)
714 GetClientSize(&cw
, &ch
);
716 if (m_horizontalLabelHeight
== 0)
722 // Draw letters for columns
723 rect
.y
= m_topOfSheet
+ 1;
724 rect
.height
= m_horizontalLabelHeight
- 1;
726 dc
->SetTextBackground(m_labelBackgroundColour
);
727 dc
->SetBackgroundMode(wxTRANSPARENT
);
728 // dc->SetTextForeground(m_labelTextColour);
730 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
731 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
737 rect
.x
= 1 + widthCount
;
738 rect
.width
= m_colWidths
[i
];
739 DrawColumnLabel(dc
, &rect
, i
);
741 widthCount
+= m_colWidths
[i
];
746 void wxGenericGrid::DrawColumnLabel(wxDC
*dc
, wxRectangle
*rect
, int col
)
748 wxGridCell
*cell
= GetLabelCell(wxHORIZONTAL
, col
);
757 dc
->SetTextForeground(GetLabelTextColour());
758 dc
->SetFont(*GetLabelTextFont());
759 if ( !cell
->GetTextValue().IsNull() )
760 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxHORIZONTAL
));
764 void wxGenericGrid::DrawRowLabels(wxDC
*dc
)
767 GetClientSize(&cw
, &ch
);
769 if (m_verticalLabelWidth
== 0)
775 // Draw numbers for rows
776 rect
.x
= m_leftOfSheet
;
777 rect
.width
= m_verticalLabelWidth
;
779 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
781 dc
->SetTextBackground(m_labelBackgroundColour
);
782 dc
->SetBackgroundMode(wxTRANSPARENT
);
784 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
786 if (heightCount
> ch
)
790 rect
.y
= 1 + heightCount
;
791 rect
.height
= m_rowHeights
[i
];
792 DrawRowLabel(dc
, &rect
, i
);
794 heightCount
+= m_rowHeights
[i
];
799 void wxGenericGrid::DrawRowLabel(wxDC
*dc
, wxRectangle
*rect
, int row
)
801 wxGridCell
*cell
= GetLabelCell(wxVERTICAL
, row
);
810 dc
->SetTextForeground(GetLabelTextColour());
811 dc
->SetFont(*GetLabelTextFont());
812 if ( !cell
->GetTextValue().IsNull() )
813 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxVERTICAL
));
817 void wxGenericGrid::DrawCells(wxDC
*dc
)
820 GetClientSize(&cw
, &ch
);
824 // Draw value corresponding to each cell
825 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
827 for (j
= m_scrollPosX
; j
< m_totalCols
; j
++)
829 SetCurrentRect(i
, j
, cw
, ch
);
830 if (m_currentRectVisible
)
832 DrawCellBackground(dc
, &m_currentRect
, i
, j
);
833 DrawCellValue(dc
, &m_currentRect
, i
, j
);
835 if (m_currentRect
.x
> cw
)
838 if (m_currentRect
.y
> ch
)
841 dc
->SetBackgroundMode(wxSOLID
);
842 dc
->SetPen(*wxBLACK_PEN
);
845 void wxGenericGrid::DrawCellBackground(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
847 wxGridCell
*cell
= GetCell(row
, col
);
850 dc
->SetBrush(*cell
->GetBackgroundBrush());
851 dc
->SetPen(*wxTRANSPARENT_PEN
);
853 #if 0 // In wxWin 2.0 the dc code is exact. RR.
855 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
857 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
, rect
->height
);
861 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
863 dc
->SetPen(*wxBLACK_PEN
);
867 void wxGenericGrid::DrawCellValue(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
869 wxGridCell
*cell
= GetCell(row
, col
);
872 wxBitmap
*bitmap
= cell
->GetCellBitmap();
882 DrawBitmapRect(dc
, bitmap
, &rect2
, cell
->GetAlignment());
886 dc
->SetBackgroundMode(wxTRANSPARENT
);
887 dc
->SetTextForeground(cell
->GetTextColour());
888 dc
->SetFont(*cell
->GetFont());
890 if ( !cell
->GetTextValue().IsNull() )
891 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, cell
->GetAlignment());
896 void wxGenericGrid::AdjustScrollbars(void)
899 GetClientSize(&cw
, &ch
);
901 // To calculate the number of steps for each scrollbar,
902 // we need to see how much will fit onto the canvas
903 // at the present size. So:
904 // 1) Find the *last* row r1 such that when it's at the top of the
905 // window, all the remaining rows are visible.
906 // 2) There should therefore be r1 - 1 steps in the scrollbar.
907 // Similarly with columns.
909 // IGNORE THE ABOVE, it's crap.
910 // We find the view size by seeing how many rows/cols fit on
912 // BUT... this means that the scrollbar should be adjusted every time
913 // it's scrolled, as well as when sized, because with variable size rows/cols,
914 // the number of rows/col visible on the view differs according to what bit
915 // you're looking at. The object length is always the same, but the
916 // view length differs.
918 // Since this may not be known until the end of this function, we should probably call AdjustScrollbars
920 int vertScrollBarWidth
= m_scrollWidth
;
921 int horizScrollBarHeight
= m_scrollWidth
;
922 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
923 vertScrollBarWidth
= 0;
924 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
925 horizScrollBarHeight
= 0;
927 int noHorizSteps
= 0;
930 if (m_totalGridWidth
<= cw
)
937 if (GetLabelSize(wxVERTICAL) > 0)
943 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
945 widthCount
+= m_colWidths
[i
];
946 // A partial bit doesn't count, we still have to scroll to see the
948 if (widthCount
+ m_leftOfSheet
+ m_verticalLabelWidth
> (cw
-vertScrollBarWidth
))
957 if (m_totalGridHeight
<= ch
)
964 if (GetLabelSize(wxHORIZONTAL) > 0)
970 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
972 heightCount
+= m_rowHeights
[i
];
973 // A partial bit doesn't count, we still have to scroll to see the
975 if (heightCount
+ m_topOfSheet
+ m_horizontalLabelHeight
> (ch
-horizScrollBarHeight
))
984 if (m_totalGridWidth
<= cw
)
987 m_hScrollBar
->Show(FALSE
);
993 m_hScrollBar
->Show(TRUE
);
996 if (m_totalGridHeight
<= ch
)
999 m_vScrollBar
->Show(FALSE
);
1005 m_vScrollBar
->Show(TRUE
);
1008 UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
1010 vertScrollBarWidth
= m_scrollWidth
;
1011 horizScrollBarHeight
= m_scrollWidth
;
1012 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
1013 vertScrollBarWidth
= 0;
1014 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
1015 horizScrollBarHeight
= 0;
1019 int nCols
= GetCols();
1021 m_hScrollBar->SetPageSize(wxMax(noHorizSteps, 1));
1022 m_hScrollBar->SetViewLength(wxMax(noHorizSteps, 1));
1023 m_hScrollBar->SetObjectLength(nCols);
1025 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetPosition(), wxMax(noHorizSteps
, 1), nCols
, wxMax(noHorizSteps
, 1));
1027 m_hScrollBar
->SetSize(m_leftOfSheet
, ch
- m_scrollWidth
-2,
1028 cw
- vertScrollBarWidth
- m_leftOfSheet
, m_scrollWidth
);
1033 int nRows
= GetRows();
1035 m_vScrollBar->SetPageSize(wxMax(noVertSteps, 1));
1036 m_vScrollBar->SetViewLength(wxMax(noVertSteps, 1));
1037 m_vScrollBar->SetObjectLength(nRows);
1040 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetPosition(), wxMax(noVertSteps
, 1), nRows
, wxMax(noVertSteps
, 1));
1041 m_vScrollBar
->SetSize(cw
- m_scrollWidth
, m_topOfSheet
,
1042 m_scrollWidth
, ch
- m_topOfSheet
- horizScrollBarHeight
);
1046 void wxGenericGrid::OnSize(wxSizeEvent
& WXUNUSED(event
) )
1048 if (!m_vScrollBar
|| !m_hScrollBar
)
1054 GetClientSize(&cw
, &ch
);
1056 if (m_editCreated
&& m_editingPanel
&& GetTextItem() && GetTextItem()->IsShown())
1058 m_editingPanel
->SetSize(0, 0, cw
, m_editControlPosition
.height
+ m_editControlPosition
.y
+ 2);
1059 GetTextItem()->SetSize(m_editControlPosition
.x
, m_editControlPosition
.y
,
1060 cw
- m_editControlPosition
.x
, m_editControlPosition
.height
);
1064 bool wxGenericGrid::CellHitTest(int x
, int y
, int *row
, int *col
)
1066 // Find the selected cell and call OnSelectCell
1067 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1068 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1070 // Calculate the cell number from x and y
1071 x
-= (m_verticalLabelWidth
+ m_leftOfSheet
);
1072 y
-= (m_topOfSheet
+ m_horizontalLabelHeight
);
1076 // Now we need to do a hit test for which row we're on
1077 int currentHeight
= 0;
1078 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1080 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1085 currentHeight
+= m_rowHeights
[i
];
1088 // Now we need to do a hit test for which column we're on
1089 int currentWidth
= 0;
1090 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1092 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1097 currentWidth
+= m_colWidths
[i
];
1104 bool wxGenericGrid::LabelSashHitTest(int x
, int y
, int *orientation
, int *rowOrCol
, int *startPos
)
1109 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= m_topOfSheet
&&
1110 x
<= m_rightOfSheet
&& y
<= (m_topOfSheet
+ m_horizontalLabelHeight
))
1112 // We may be on a column label sash.
1113 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1114 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1116 if (x
>= (currentWidth
+ m_colWidths
[i
] - tolerance
) && x
<= (currentWidth
+ m_colWidths
[i
] + tolerance
))
1118 *orientation
= wxHORIZONTAL
;
1120 *startPos
= currentWidth
;
1123 currentWidth
+= m_colWidths
[i
];
1127 else if (x
>= m_leftOfSheet
&& y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1128 x
<= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
<= m_bottomOfSheet
)
1130 // We may be on a row label sash.
1131 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1132 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1134 if (y
>= (currentHeight
+ m_rowHeights
[i
] - tolerance
) && y
<= (currentHeight
+ m_rowHeights
[i
] + tolerance
))
1136 *orientation
= wxVERTICAL
;
1138 *startPos
= currentHeight
;
1141 currentHeight
+= m_rowHeights
[i
];
1148 bool wxGenericGrid::LabelHitTest(int x
, int y
, int *row
, int *col
)
1150 // Find the selected label
1151 if (x
>= m_leftOfSheet
&& y
>= m_topOfSheet
&&
1152 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1154 // Calculate the cell number from x and y
1160 // Now we need to do a hit test for which row we're on
1161 int currentHeight
= m_horizontalLabelHeight
;
1162 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1164 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1169 currentHeight
+= m_rowHeights
[i
];
1171 if (y
>= 0 && y
<= m_horizontalLabelHeight
)
1176 // Now we need to do a hit test for which column we're on
1177 int currentWidth
= m_verticalLabelWidth
;
1178 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1180 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1185 currentWidth
+= m_colWidths
[i
];
1187 if (x
>= 0 && x
<= m_verticalLabelWidth
)
1192 if ((*col
== -1) || (*row
== -1))
1200 void wxGenericGrid::OnMouseEvent(wxMouseEvent
& ev
)
1204 wxClientDC
dc(this);
1208 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1210 OnSelectCellImplementation(& dc
, row
, col
);
1211 OnCellLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1213 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1215 OnLabelLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1219 else if (ev
.Dragging() && ev
.LeftIsDown())
1221 switch (m_dragStatus
)
1223 case wxGRID_DRAG_NONE
:
1226 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &m_dragRowOrCol
, &m_dragStartPosition
))
1228 if (orientation
== wxHORIZONTAL
)
1230 m_dragStatus
= wxGRID_DRAG_LEFT_RIGHT
;
1231 SetCursor(*m_horizontalSashCursor
);
1232 m_dragLastPosition
= (int)ev
.GetX();
1236 m_dragStatus
= wxGRID_DRAG_UP_DOWN
;
1237 SetCursor(*m_verticalSashCursor
);
1238 m_dragLastPosition
= (int)ev
.GetY();
1240 wxClientDC
dc(this);
1242 dc
.SetLogicalFunction(wxINVERT
);
1243 if (orientation
== wxHORIZONTAL
)
1244 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1246 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1253 case wxGRID_DRAG_LEFT_RIGHT
:
1255 wxClientDC
dc(this);
1257 dc
.SetLogicalFunction(wxINVERT
);
1258 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1260 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1263 m_dragLastPosition
= (int)ev
.GetX();
1264 SetCursor(*m_horizontalSashCursor
);
1267 case wxGRID_DRAG_UP_DOWN
:
1269 wxClientDC
dc(this);
1271 dc
.SetLogicalFunction(wxINVERT
);
1272 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1274 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1277 m_dragLastPosition
= (int)ev
.GetY();
1278 SetCursor(*m_verticalSashCursor
);
1283 else if (ev
.Moving())
1285 int rowOrCol
, orientation
, startPos
;
1286 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &rowOrCol
, &startPos
))
1288 if (orientation
== wxHORIZONTAL
)
1289 SetCursor(*m_horizontalSashCursor
);
1291 SetCursor(*m_verticalSashCursor
);
1294 SetCursor(*wxSTANDARD_CURSOR
);
1296 else if (ev
.LeftUp())
1298 switch (m_dragStatus
)
1300 case wxGRID_DRAG_LEFT_RIGHT
:
1302 wxClientDC
dc(this);
1304 dc
.SetLogicalFunction(wxINVERT
);
1305 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1306 dc
.SetLogicalFunction(wxCOPY
);
1310 if (ev
.GetX() > m_dragStartPosition
)
1312 m_colWidths
[m_dragRowOrCol
] = (short)(ev
.GetX() - m_dragStartPosition
);
1317 SetCursor(*wxSTANDARD_CURSOR
);
1319 GetClientSize(&cw
, &ch
);
1324 case wxGRID_DRAG_UP_DOWN
:
1326 wxClientDC
dc(this);
1328 dc
.SetLogicalFunction(wxINVERT
);
1329 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1330 dc
.SetLogicalFunction(wxCOPY
);
1334 if (ev
.GetY() > m_dragStartPosition
)
1336 m_rowHeights
[m_dragRowOrCol
] = (short)(ev
.GetY() - m_dragStartPosition
);
1341 SetCursor(*wxSTANDARD_CURSOR
);
1345 m_dragStatus
= wxGRID_DRAG_NONE
;
1347 else if (ev
.RightDown())
1350 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1352 OnCellRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1354 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1356 OnLabelRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1361 void wxGenericGrid::OnSelectCellImplementation(wxDC
*dc
, int row
, int col
)
1363 m_wCursorColumn
= col
;
1366 OnChangeSelectionLabel();
1368 SetGridClippingRegion(dc
);
1370 // Remove the highlight from the old cell
1371 if (m_currentRectVisible
)
1374 // Highlight the new cell and copy its content to the edit control
1375 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
1376 wxGridCell
*cell
= GetCell(m_wCursorRow
, m_wCursorColumn
);
1379 if ( cell
->GetTextValue().IsNull() )
1380 m_textItem
->SetValue("");
1382 m_textItem
->SetValue(cell
->GetTextValue());
1385 SetGridClippingRegion(dc
);
1387 // Why isn't this needed for Windows??
1388 // Probably because of the SetValue??
1389 // Arrrrrgh. This isn't needed anywhere, of course. RR.
1391 // HighlightCell(dc);
1393 dc
->DestroyClippingRegion();
1395 OnSelectCell(row
, col
);
1398 wxGridCell
*wxGenericGrid::OnCreateCell(void)
1400 return new wxGridCell(this);
1403 void wxGenericGrid::OnChangeLabels(void)
1407 for (i
= 0; i
< m_totalRows
; i
++)
1409 sprintf(buf
, "%d", i
+1);
1410 SetLabelValue(wxVERTICAL
, buf
, i
);
1412 // A...Z,AA...ZZ,AAA...ZZZ, etc.
1413 for (i
= 0; i
< m_totalCols
; i
++)
1416 int noTimes
= (i
/26 + 1);
1417 int ch
= (i
% 26) + 65;
1419 for (j
= 0; j
< noTimes
; j
++)
1422 sprintf(buf2
, "%c", (char)ch
);
1425 SetLabelValue(wxHORIZONTAL
, buf
, i
);
1429 void wxGenericGrid::OnChangeSelectionLabel(void)
1434 wxString
rowLabel(GetLabelValue(wxVERTICAL
, GetCursorRow()));
1435 wxString
colLabel(GetLabelValue(wxHORIZONTAL
, GetCursorColumn()));
1437 wxString newLabel
= colLabel
+ rowLabel
;
1438 if ((newLabel
.Length() > 0) && (newLabel
.Length() <= 8) && GetTextItem())
1440 // GetTextItem()->SetLabel(newLabel);
1444 void wxGenericGrid::HighlightCell(wxDC
*dc
)
1446 dc
->SetLogicalFunction(wxINVERT
);
1449 dc
->DrawLine( m_currentRect
.x
+ 1,
1450 m_currentRect
.y
+ 1,
1451 m_currentRect
.x
+ m_currentRect
.width
- 1,
1452 m_currentRect
.y
+ 1);
1454 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1455 m_currentRect
.y
+ 1,
1456 m_currentRect
.x
+ m_currentRect
.width
- 1,
1457 m_currentRect
.y
+m_currentRect
.height
- 1 );
1459 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1460 m_currentRect
.y
+ m_currentRect
.height
- 1,
1461 m_currentRect
.x
+ 1,
1462 m_currentRect
.y
+ m_currentRect
.height
- 1);
1464 dc
->DrawLine( m_currentRect
.x
+ 1,
1465 m_currentRect
.y
+ m_currentRect
.height
- 1,
1466 m_currentRect
.x
+ 1,
1467 m_currentRect
.y
+ 1);
1469 dc
->SetLogicalFunction(wxCOPY
);
1472 void wxGenericGrid::DrawCellText(void)
1474 if (!m_currentRectVisible
)
1477 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1481 static char szEdit
[300];
1483 wxClientDC
dc(this);
1486 SetGridClippingRegion(& dc
);
1488 dc
.SetBackgroundMode(wxTRANSPARENT
);
1489 dc
.SetBrush(*cell
->GetBackgroundBrush());
1491 strcpy(szEdit
, m_textItem
->GetValue());
1494 rect
= m_currentRect
;
1500 DrawTextRect(& dc
, " ", &rect
, wxLEFT
);
1501 DrawTextRect(& dc
, szEdit
, &rect
, cell
->GetAlignment());
1503 dc
.DestroyClippingRegion();
1505 dc
.SetBackgroundMode(wxSOLID
);
1510 void wxGenericGrid::SetCurrentRect(int Row
, int Column
, int canvasW
, int canvasH
)
1512 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1514 for (i
= m_scrollPosX
; i
< Column
; i
++)
1515 currentWidth
+= m_colWidths
[i
];
1517 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1518 for (i
= m_scrollPosY
; i
< Row
; i
++)
1519 currentHeight
+= m_rowHeights
[i
];
1521 m_currentRect
.x
= currentWidth
;
1522 m_currentRect
.y
= currentHeight
;
1523 m_currentRect
.width
= m_colWidths
? (m_colWidths
[Column
]) : 0;
1524 m_currentRect
.height
= m_rowHeights
? (m_rowHeights
[Row
]) : 0;
1526 if (Row
< m_scrollPosY
|| Column
< m_scrollPosX
)
1527 m_currentRectVisible
= FALSE
;
1528 else if ((canvasW
!= -1 && canvasH
!= -1) && (m_currentRect
.x
> canvasW
|| m_currentRect
.y
> canvasH
))
1529 m_currentRectVisible
= FALSE
;
1530 else m_currentRectVisible
= TRUE
;
1533 static bool wxRectIntersection(wxRectangle
*rect1
, wxRectangle
*rect2
, wxRectangle
*rect3
)
1535 int x2_1
= rect1
->x
+ rect1
->width
;
1536 int y2_1
= rect1
->y
+ rect1
->height
;
1538 int x2_2
= rect2
->x
+ rect2
->width
;
1539 int y2_2
= rect2
->y
+ rect2
->height
;
1543 // Check for intersection
1544 if ((rect1
->x
> x2_2
) || (rect2
->x
> x2_1
) ||
1545 (rect1
->y
> y2_2
) || (rect2
->y
> y2_1
))
1548 rect3
->x
= rect3
->y
= rect3
->width
= rect3
->height
= 0;
1552 if (rect1
->x
> rect2
->x
)
1553 rect3
->x
= rect1
->x
;
1555 rect3
->x
= rect2
->x
;
1556 if (rect1
->y
> rect2
->y
)
1557 rect3
->y
= rect1
->y
;
1559 rect3
->y
= rect2
->y
;
1570 rect3
->width
= (int)(x2_3
- rect3
->x
);
1571 rect3
->height
= (int)(y2_3
- rect3
->y
);
1575 void wxGenericGrid::DrawTextRect(wxDC
*dc
, const wxString
& text
, wxRectangle
*rect
, int flag
)
1579 // Ultimately, this functionality should be built into wxWindows,
1580 // and optimized for each platform. E.g. on Windows, use DrawText
1581 // passing a clipping rectangle, so that the wxWindows clipping region
1582 // does not have to be used to implement this.
1584 // If we're already clipping, we need to find the intersection
1585 // between current clipping area and text clipping area.
1587 wxRectangle clipRect
;
1588 wxRectangle clipRect2
;
1589 long clipX
, clipY
, clipW
, clipH
;
1590 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1591 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1592 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1594 bool alreadyClipping
= TRUE
;
1596 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1598 alreadyClipping
= FALSE
;
1599 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1600 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1604 // Find intersection.
1605 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1609 if (alreadyClipping
)
1610 dc
->DestroyClippingRegion();
1612 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1613 long textWidth
, textHeight
;
1615 dc
->GetTextExtent(text
, &textWidth
, &textHeight
);
1623 x
= (rect
->x
+ rect
->width
- textWidth
- 1.0);
1624 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1629 x
= (rect
->x
+ (rect
->width
- textWidth
)/2.0);
1630 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1636 x
= (rect
->x
+ 1.0);
1637 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1641 dc
->DrawText(text
, (long)x
, (long)y
);
1643 dc
->DestroyClippingRegion();
1645 // Restore old clipping
1646 if (alreadyClipping
)
1647 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1652 void wxGenericGrid::DrawBitmapRect(wxDC
*dc
, wxBitmap
*bitmap
, wxRectangle
*rect
, int flag
)
1656 // Ultimately, this functionality should be built into wxWindows,
1657 // and optimized for each platform. E.g. on Windows, use DrawText
1658 // passing a clipping rectangle, so that the wxWindows clipping region
1659 // does not have to be used to implement this.
1661 // If we're already clipping, we need to find the intersection
1662 // between current clipping area and text clipping area.
1664 wxRectangle clipRect
;
1665 wxRectangle clipRect2
;
1666 long clipX
, clipY
, clipW
, clipH
;
1667 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1668 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1669 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1671 bool alreadyClipping
= TRUE
;
1673 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1675 alreadyClipping
= FALSE
;
1676 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1677 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1681 // Find intersection.
1682 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1686 if (alreadyClipping
)
1687 dc
->DestroyClippingRegion();
1689 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1690 float bitmapWidth
, bitmapHeight
;
1692 bitmapWidth
= bitmap
->GetWidth();
1693 bitmapHeight
= bitmap
->GetHeight();
1701 x
= (long)(rect
->x
+ rect
->width
- bitmapWidth
- 1);
1702 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1707 x
= (long)(rect
->x
+ (rect
->width
- bitmapWidth
)/2.0);
1708 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1714 x
= (long)(rect
->x
+ 1);
1715 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1720 dcTemp
.SelectObject(*bitmap
);
1722 dc
->Blit( (long)x
, (long)y
, (long)bitmapWidth
, (long)bitmapHeight
, &dcTemp
, 0, 0);
1723 dcTemp
.SelectObject(wxNullBitmap
);
1725 dc
->DestroyClippingRegion();
1727 // Restore old clipping
1728 if (alreadyClipping
)
1729 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1734 void wxGenericGrid::OnActivate(bool active
)
1738 // Edit control should always have the focus
1739 if (GetTextItem() && GetEditable())
1741 GetTextItem()->SetFocus();
1742 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1744 GetTextItem()->SetValue(cell
->GetTextValue());
1749 void wxGenericGrid::SetCellValue(const wxString
& val
, int row
, int col
)
1751 wxGridCell
*cell
= GetCell(row
, col
);
1754 cell
->SetTextValue(val
);
1756 RefreshCell(row
, col
, TRUE
);
1760 void wxGenericGrid::RefreshCell(int row
, int col
, bool setText
)
1762 // Don't refresh within a pair of batch brackets
1763 if (GetBatchCount() > 0)
1767 GetClientSize(&cw
, &ch
);
1769 SetCurrentRect(row
, col
, cw
, ch
);
1770 if (m_currentRectVisible
)
1772 wxGridCell
*cell
= GetCell(row
, col
);
1774 bool currentPos
= FALSE
;
1775 if (row
== m_wCursorRow
&& col
== m_wCursorColumn
&& GetTextItem() && GetTextItem()->IsShown() && setText
)
1777 GetTextItem()->SetValue(cell
->GetTextValue());
1780 // Gets refreshed anyway in MSW
1785 wxClientDC
dc(this);
1787 DrawCellBackground(& dc
, &m_currentRect
, row
, col
);
1788 DrawCellValue(& dc
, &m_currentRect
, row
, col
);
1794 wxString
& wxGenericGrid::GetCellValue(int row
, int col
)
1796 static wxString
emptyString("");
1798 wxGridCell
*cell
= GetCell(row
, col
);
1800 return cell
->GetTextValue();
1805 void wxGenericGrid::SetColumnWidth(int col
, int width
)
1807 if (col
<= m_totalCols
)
1808 m_colWidths
[col
] = width
;
1811 int wxGenericGrid::GetColumnWidth(int col
)
1813 if (col
<= m_totalCols
)
1814 return m_colWidths
[col
];
1819 void wxGenericGrid::SetRowHeight(int row
, int height
)
1821 if (row
<= m_totalRows
)
1822 m_rowHeights
[row
] = height
;
1825 int wxGenericGrid::GetRowHeight(int row
)
1827 if (row
<= m_totalRows
)
1828 return m_rowHeights
[row
];
1833 void wxGenericGrid::SetLabelSize(int orientation
, int sz
)
1835 if (orientation
== wxHORIZONTAL
)
1836 m_horizontalLabelHeight
= sz
;
1838 m_verticalLabelWidth
= sz
;
1840 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1843 int wxGenericGrid::GetLabelSize(int orientation
)
1845 if (orientation
== wxHORIZONTAL
)
1846 return m_horizontalLabelHeight
;
1848 return m_verticalLabelWidth
;
1851 wxGridCell
*wxGenericGrid::GetLabelCell(int orientation
, int pos
)
1853 if (orientation
== wxHORIZONTAL
)
1855 if (m_colLabelCells
&& pos
< m_totalCols
)
1856 return m_colLabelCells
[pos
];
1862 if (m_rowLabelCells
&& pos
< m_totalRows
)
1863 return m_rowLabelCells
[pos
];
1869 void wxGenericGrid::SetLabelValue(int orientation
, const wxString
& val
, int pos
)
1871 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1873 cell
->SetTextValue(val
);
1876 wxString
& wxGenericGrid::GetLabelValue(int orientation
, int pos
)
1878 static wxString emptyString
= "";
1879 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1881 return cell
->GetTextValue();
1886 void wxGenericGrid::SetLabelAlignment(int orientation
, int align
)
1888 if (orientation
== wxHORIZONTAL
)
1889 m_horizontalLabelAlignment
= align
;
1891 m_verticalLabelAlignment
= align
;
1893 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1896 int wxGenericGrid::GetLabelAlignment(int orientation
)
1898 if (orientation
== wxHORIZONTAL
)
1899 return m_horizontalLabelAlignment
;
1901 return m_verticalLabelAlignment
;
1904 void wxGenericGrid::SetLabelTextColour(const wxColour
& colour
)
1906 m_labelTextColour
= colour
;
1910 void wxGenericGrid::SetLabelBackgroundColour(const wxColour
& colour
)
1912 m_labelBackgroundColour
= colour
;
1913 m_labelBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush(m_labelBackgroundColour
, wxSOLID
);
1916 void wxGenericGrid::SetEditable(bool edit
)
1921 int controlW
, controlH
;
1922 m_textItem
->GetSize(&controlW
, &controlH
);
1923 m_editControlPosition
.height
= controlH
;
1925 m_topOfSheet
= m_editControlPosition
.x
+ controlH
+ 2;
1928 m_editingPanel
->Show(TRUE
);
1929 m_textItem
->Show(TRUE
);
1930 m_textItem
->SetFocus();
1938 m_textItem
->Show(FALSE
);
1939 m_editingPanel
->Show(FALSE
);
1943 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1946 GetClientSize(&cw
, &ch
);
1951 int m_scrollWidth = 16;
1952 GetClientSize(&cw, &ch);
1955 m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
1956 m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
1960 void wxGenericGrid::SetCellAlignment(int flag
, int row
, int col
)
1962 wxGridCell
*cell
= GetCell(row
, col
);
1964 cell
->SetAlignment(flag
);
1967 int wxGenericGrid::GetCellAlignment(int row
, int col
)
1969 wxGridCell
*cell
= GetCell(row
, col
);
1971 return cell
->GetAlignment();
1973 return m_cellAlignment
;
1976 void wxGenericGrid::SetCellAlignment(int flag
)
1978 m_cellAlignment
= flag
;
1980 for (i
= 0; i
< GetRows(); i
++)
1981 for (j
= 0; j
< GetCols(); j
++)
1983 GetCell(i
, j
)->SetAlignment(flag
);
1986 int wxGenericGrid::GetCellAlignment(void)
1988 return m_cellAlignment
;
1991 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& col
)
1993 m_cellBackgroundColour
= col
;
1995 for (i
= 0; i
< GetRows(); i
++)
1996 for (j
= 0; j
< GetCols(); j
++)
1998 GetCell(i
, j
)->SetBackgroundColour(col
);
2001 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& val
, int row
, int col
)
2003 wxGridCell
*cell
= GetCell(row
, col
);
2006 cell
->SetBackgroundColour(val
);
2007 RefreshCell(row
, col
);
2011 wxColour
& wxGenericGrid::GetCellBackgroundColour(int row
, int col
)
2013 wxGridCell
*cell
= GetCell(row
, col
);
2015 return cell
->GetBackgroundColour();
2017 return m_cellBackgroundColour
;
2020 void wxGenericGrid::SetCellTextColour(const wxColour
& val
, int row
, int col
)
2022 wxGridCell
*cell
= GetCell(row
, col
);
2025 cell
->SetTextColour(val
);
2026 RefreshCell(row
, col
);
2030 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
, int row
, int col
)
2032 wxGridCell
*cell
= GetCell(row
, col
);
2036 RefreshCell(row
, col
);
2040 wxFont
*wxGenericGrid::GetCellTextFont(int row
, int col
)
2042 wxGridCell
*cell
= GetCell(row
, col
);
2044 return cell
->GetFont();
2046 return m_cellTextFont
;
2049 wxColour
& wxGenericGrid::GetCellTextColour(int row
, int col
)
2051 wxGridCell
*cell
= GetCell(row
, col
);
2053 return cell
->GetTextColour();
2055 return m_cellTextColour
;
2058 void wxGenericGrid::SetCellTextColour(const wxColour
& val
)
2060 m_cellTextColour
= val
;
2062 for (i
= 0; i
< GetRows(); i
++)
2063 for (j
= 0; j
< GetCols(); j
++)
2065 GetCell(i
, j
)->SetTextColour(val
);
2068 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
)
2070 m_cellTextFont
= fnt
;
2072 for (i
= 0; i
< GetRows(); i
++)
2073 for (j
= 0; j
< GetCols(); j
++)
2075 GetCell(i
, j
)->SetFont(fnt
);
2078 void wxGenericGrid::SetCellBitmap(wxBitmap
*bitmap
, int row
, int col
)
2080 wxGridCell
*cell
= GetCell(row
, col
);
2083 cell
->SetCellBitmap(bitmap
);
2084 RefreshCell(row
, col
);
2088 wxBitmap
*wxGenericGrid::GetCellBitmap(int row
, int col
)
2090 wxGridCell
*cell
= GetCell(row
, col
);
2093 return cell
->GetCellBitmap();
2099 bool wxGenericGrid::InsertCols(int pos
, int n
, bool updateLabels
)
2101 if (pos
> m_totalCols
)
2105 return CreateGrid(1, n
);
2110 for (i
= 0; i
< m_totalRows
; i
++)
2112 wxGridCell
**cols
= m_gridCells
[i
];
2113 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
+ n
];
2114 for (j
= 0; j
< pos
; j
++)
2115 newCols
[j
] = cols
[j
];
2116 for (j
= pos
; j
< pos
+ n
; j
++)
2117 newCols
[j
] = new wxGridCell(this);
2118 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2119 newCols
[j
] = cols
[j
- n
];
2122 m_gridCells
[i
] = newCols
;
2126 short *newColWidths
= new short[m_totalCols
+ n
];
2127 for (j
= 0; j
< pos
; j
++)
2128 newColWidths
[j
] = m_colWidths
[j
];
2129 for (j
= pos
; j
< pos
+ n
; j
++)
2130 newColWidths
[j
] = wxGRID_DEFAULT_CELL_WIDTH
;
2131 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2132 newColWidths
[j
] = m_colWidths
[j
- n
];
2133 delete[] m_colWidths
;
2134 m_colWidths
= newColWidths
;
2137 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
+ n
];
2138 for (j
= 0; j
< pos
; j
++)
2139 newLabels
[j
] = m_colLabelCells
[j
];
2140 for (j
= pos
; j
< pos
+ n
; j
++)
2141 newLabels
[j
] = new wxGridCell(this);
2142 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2143 newLabels
[j
] = m_colLabelCells
[j
- n
];
2145 delete[] m_colLabelCells
;
2146 m_colLabelCells
= newLabels
;
2158 bool wxGenericGrid::InsertRows(int pos
, int n
, bool updateLabels
)
2160 if (pos
> m_totalRows
)
2164 return CreateGrid(n
, 1);
2169 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
+ n
];
2172 for (i
= 0; i
< pos
; i
++)
2173 rows
[i
] = m_gridCells
[i
];
2175 for (i
= pos
; i
< pos
+ n
; i
++)
2177 rows
[i
] = new wxGridCell
*[m_totalCols
];
2178 for (j
= 0; j
< m_totalCols
; j
++)
2179 rows
[i
][j
] = new wxGridCell(this);
2182 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2183 rows
[i
] = m_gridCells
[i
- n
];
2185 delete[] m_gridCells
;
2189 short *newRowHeights
= new short[m_totalRows
+ n
];
2190 for (i
= 0; i
< pos
; i
++)
2191 newRowHeights
[i
] = m_rowHeights
[i
];
2192 for (i
= pos
; i
< pos
+ n
; i
++)
2193 newRowHeights
[i
] = wxGRID_DEFAULT_CELL_HEIGHT
;
2194 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2195 newRowHeights
[i
] = m_rowHeights
[i
- n
];
2196 delete[] m_rowHeights
;
2197 m_rowHeights
= newRowHeights
;
2200 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
+ n
];
2201 for (i
= 0; i
< pos
; i
++)
2202 newLabels
[i
] = m_rowLabelCells
[i
];
2203 for (i
= pos
; i
< pos
+ n
; i
++)
2204 newLabels
[i
] = new wxGridCell(this);
2205 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2206 newLabels
[i
] = m_rowLabelCells
[i
- n
];
2208 delete[] m_rowLabelCells
;
2209 m_rowLabelCells
= newLabels
;
2221 bool wxGenericGrid::AppendCols(int n
, bool updateLabels
)
2223 return InsertCols(GetCols(), n
, updateLabels
);
2226 bool wxGenericGrid::AppendRows(int n
, bool updateLabels
)
2228 return InsertRows(GetRows(), n
, updateLabels
);
2231 bool wxGenericGrid::DeleteRows(int pos
, int n
, bool updateLabels
)
2233 if (pos
> m_totalRows
)
2240 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
- n
];
2243 for (i
= 0; i
< pos
; i
++)
2244 rows
[i
] = m_gridCells
[i
];
2246 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2247 rows
[i
-n
] = m_gridCells
[i
];
2249 delete[] m_gridCells
;
2253 short *newRowHeights
= new short[m_totalRows
- n
];
2254 for (i
= 0; i
< pos
; i
++)
2255 newRowHeights
[i
] = m_rowHeights
[i
];
2256 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2257 newRowHeights
[i
-n
] = m_rowHeights
[i
];
2258 delete[] m_rowHeights
;
2259 m_rowHeights
= newRowHeights
;
2262 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
- n
];
2263 for (i
= 0; i
< pos
; i
++)
2264 newLabels
[i
] = m_rowLabelCells
[i
];
2265 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2266 newLabels
[i
-n
] = m_rowLabelCells
[i
];
2268 delete[] m_rowLabelCells
;
2269 m_rowLabelCells
= newLabels
;
2280 bool wxGenericGrid::DeleteCols(int pos
, int n
, bool updateLabels
)
2282 if (pos
+ n
> m_totalCols
)
2290 for (i
= 0; i
< m_totalRows
; i
++)
2292 wxGridCell
**cols
= m_gridCells
[i
];
2293 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
- n
];
2294 for (j
= 0; j
< pos
; j
++)
2295 newCols
[j
] = cols
[j
];
2296 for (j
= pos
; j
< pos
+ n
; j
++)
2298 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2299 newCols
[j
-n
] = cols
[j
];
2302 m_gridCells
[i
] = newCols
;
2306 short *newColWidths
= new short[m_totalCols
- n
];
2307 for (j
= 0; j
< pos
; j
++)
2308 newColWidths
[j
] = m_colWidths
[j
];
2309 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2310 newColWidths
[j
-n
] = m_colWidths
[j
];
2311 delete[] m_colWidths
;
2312 m_colWidths
= newColWidths
;
2315 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
- n
];
2316 for (j
= 0; j
< pos
; j
++)
2317 newLabels
[j
] = m_colLabelCells
[j
];
2318 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2319 newLabels
[j
-n
] = m_colLabelCells
[j
];
2321 delete[] m_colLabelCells
;
2322 m_colLabelCells
= newLabels
;
2333 void wxGenericGrid::SetGridCursor(int row
, int col
)
2335 if (row
>= m_totalRows
|| col
>= m_totalCols
)
2338 if (row
== GetCursorRow() && col
== GetCursorColumn())
2341 wxClientDC
dc(this);
2344 SetGridClippingRegion(& dc
);
2346 if (m_currentRectVisible
)
2347 HighlightCell(& dc
);
2350 m_wCursorColumn
= col
;
2351 SetCurrentRect(row
, col
);
2352 if (m_currentRectVisible
)
2353 HighlightCell(& dc
);
2355 dc
.DestroyClippingRegion();
2363 wxGridCell::wxGridCell(wxGenericGrid
*window
)
2367 backgroundBrush
= NULL
;
2369 textColour
= window
->GetCellTextColour();
2371 textColour
.Set(0,0,0);
2373 backgroundColour
= window
->GetCellBackgroundColour();
2375 backgroundColour
.Set(255,255,255);
2378 font
= window
->GetCellTextFont();
2380 font
= wxTheFontList
->FindOrCreateFont(12, wxSWISS
, wxNORMAL
, wxNORMAL
);
2382 SetBackgroundColour(backgroundColour
);
2385 alignment
= window
->GetCellAlignment();
2390 wxGridCell::~wxGridCell(void)
2394 void wxGridCell::SetBackgroundColour(const wxColour
& colour
)
2396 backgroundColour
= colour
;
2397 backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(backgroundColour
, wxSOLID
);
2400 void wxGenericGrid::OnText(wxCommandEvent
& WXUNUSED(ev
) )
2402 wxGenericGrid
*grid
= this;
2403 wxGridCell
*cell
= grid
->GetCell(grid
->GetCursorRow(), grid
->GetCursorColumn());
2404 if (cell
&& grid
->CurrentCellVisible())
2406 cell
->SetTextValue(grid
->GetTextItem()->GetValue());
2407 wxClientDC
dc(grid
);
2410 grid
->SetGridClippingRegion(& dc
);
2411 grid
->DrawCellBackground(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2412 grid
->DrawCellValue(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2413 grid
->HighlightCell(& dc
);
2414 dc
.DestroyClippingRegion();
2417 grid
->OnCellChange(grid
->GetCursorRow(), grid
->GetCursorColumn());
2419 // grid->DrawCellText();
2423 void wxGenericGrid::OnGridScroll(wxScrollEvent
& ev
)
2425 static bool inScroll
= FALSE
;
2431 wxGenericGrid
*win
= this;
2433 bool change
= FALSE
;
2435 if (ev
.GetEventObject() == win
->GetHorizScrollBar())
2437 change
= (ev
.GetPosition() != m_scrollPosX
);
2438 win
->SetScrollPosX(ev
.GetPosition());
2442 change
= (ev
.GetPosition() != m_scrollPosY
);
2443 win
->SetScrollPosY(ev
.GetPosition());
2446 win
->UpdateDimensions();
2447 win
->SetCurrentRect(win
->GetCursorRow(), win
->GetCursorColumn());
2449 // Because rows and columns can be arbitrary sizes,
2450 // the scrollbars will need to be adjusted to reflect the
2454 if (change
) win
->Refresh(FALSE
);