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
;
309 m_hScrollBar
->SetViewLength(viewLengthX
);
310 m_hScrollBar
->SetObjectLength(objectSizeX
);
311 m_hScrollBar
->SetPageSize(pageSizeX
);
313 int objectSizeY
= m_totalRows
;
315 int viewLengthY
= m_totalRows
;
317 m_vScrollBar
->SetViewLength(viewLengthY
);
318 m_vScrollBar
->SetObjectLength(objectSizeY
);
319 m_vScrollBar
->SetPageSize(pageSizeY
);
324 OnChangeSelectionLabel();
329 // Need to determine various dimensions
330 void wxGenericGrid::UpdateDimensions(void)
332 int canvasWidth
, canvasHeight
;
333 GetSize(&canvasWidth
, &canvasHeight
);
335 if (m_editCreated
&& m_editable
)
337 int controlW
, controlH
;
338 GetTextItem()->GetSize(&controlW
, &controlH
);
339 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
343 m_rightOfSheet
= m_leftOfSheet
+ m_verticalLabelWidth
;
345 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
347 if (m_rightOfSheet
> canvasWidth
)
350 m_rightOfSheet
+= m_colWidths
[i
];
352 m_bottomOfSheet
= m_topOfSheet
+ m_horizontalLabelHeight
;
353 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
355 if (m_bottomOfSheet
> canvasHeight
)
358 m_bottomOfSheet
+= m_rowHeights
[i
];
361 m_totalGridWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
362 for (i
= 0; i
< m_totalCols
; i
++)
364 m_totalGridWidth
+= m_colWidths
[i
];
366 m_totalGridHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
367 for (i
= 0; i
< m_totalRows
; i
++)
369 m_totalGridHeight
+= m_rowHeights
[i
];
373 wxGridCell
*wxGenericGrid::GetCell(int row
, int col
)
378 if ((row
>= m_totalRows
) || (col
>= m_totalCols
))
381 wxGridCell
*cell
= m_gridCells
[row
][col
];
384 m_gridCells
[row
][col
] = OnCreateCell();
385 return m_gridCells
[row
][col
];
391 void wxGenericGrid::SetGridClippingRegion(wxDC
*dc
)
393 int m_scrollWidthHoriz
= 0;
394 int m_scrollWidthVert
= 0;
396 GetClientSize(&cw
, &ch
);
398 if (m_hScrollBar
&& m_hScrollBar
->IsShown())
399 m_scrollWidthHoriz
= m_scrollWidth
;
400 if (m_vScrollBar
&& m_vScrollBar
->IsShown())
401 m_scrollWidthVert
= m_scrollWidth
;
403 // Don't paint over the scrollbars
404 dc
->SetClippingRegion(m_leftOfSheet
, m_topOfSheet
,
405 cw
- m_scrollWidthVert
- m_leftOfSheet
, ch
- m_scrollWidthHoriz
- m_topOfSheet
);
408 void wxGenericGrid::OnPaint(wxPaintEvent
& WXUNUSED(event
))
411 GetClientSize(&w
, &h
);
413 bool useDoubleBuffering
= (bool) USE_DOUBLE_BUFFERING
;
414 if (useDoubleBuffering
)
416 // Reuse the old bitmap if possible
418 if (!m_doubleBufferingBitmap
||
419 (m_doubleBufferingBitmap
->GetWidth() < w
|| m_doubleBufferingBitmap
->GetHeight() < h
))
421 if (m_doubleBufferingBitmap
)
422 delete m_doubleBufferingBitmap
;
423 m_doubleBufferingBitmap
= new wxBitmap(w
, h
);
425 if (!m_doubleBufferingBitmap
|| !m_doubleBufferingBitmap
->Ok())
427 // If we couldn't create a new bitmap, perhaps because resources were low,
428 // then don't complain, just don't double-buffer
429 if (m_doubleBufferingBitmap
)
430 delete m_doubleBufferingBitmap
;
431 m_doubleBufferingBitmap
= NULL
;
432 useDoubleBuffering
= FALSE
;
436 if (useDoubleBuffering
)
438 wxPaintDC
paintDC(this);
439 wxMemoryDC
dc(& paintDC
);
440 dc
.SelectObject(* m_doubleBufferingBitmap
);
444 int vertScrollBarWidth
= m_scrollWidth
;
445 int horizScrollBarHeight
= m_scrollWidth
;
446 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
447 vertScrollBarWidth
= 0;
448 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
449 horizScrollBarHeight
= 0;
451 paintDC
.Blit(m_leftOfSheet
, m_topOfSheet
, w
- vertScrollBarWidth
- m_leftOfSheet
, h
- horizScrollBarHeight
- m_topOfSheet
,
452 &dc
, m_leftOfSheet
, m_topOfSheet
, wxCOPY
);
454 dc
.SelectObject(wxNullBitmap
);
463 void wxGenericGrid::PaintGrid(wxDC
& dc
)
466 dc
.SetOptimization(FALSE
);
468 SetGridClippingRegion(& dc
);
470 DrawLabelAreas(& dc
);
472 DrawEditableArea(& dc
);
473 DrawColumnLabels(& dc
);
478 /* Hilight present cell */
479 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
480 if (m_currentRectVisible
)
483 dc
.DestroyClippingRegion();
484 dc
.SetOptimization(TRUE
);
488 // Erase (some of) the background.
489 // Currently, a Windows-only optimisation.
490 void wxGenericGrid::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
) )
494 dc
.SetOptimization(FALSE
);
497 GetClientSize(& w
, & h
);
498 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
);
499 dc
.SetPen(*wxLIGHT_GREY_PEN
);
501 if (m_hScrollBar
&& m_hScrollBar
->IsShown() && m_vScrollBar
&& m_vScrollBar
->IsShown())
503 dc
.DrawRectangle(w
- m_scrollWidth
, h
- m_scrollWidth
, m_scrollWidth
, m_scrollWidth
);
506 dc
.SetOptimization(TRUE
);
511 void wxGenericGrid::DrawLabelAreas(wxDC
*dc
)
514 GetClientSize(&cw
, &ch
);
516 dc
->SetPen(*wxTRANSPARENT_PEN
);
517 // dc->SetBrush(*dc->GetBackground());
519 // Should blank out any area which isn't going to be painted over.
520 // dc->DrawRectangle(m_leftOfSheet, m_bottomOfSheet, cw - m_leftOfSheet, ch - m_bottomOfSheet);
521 // dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet);
523 // Paint the label areas
524 dc
->SetBrush(*m_labelBackgroundBrush
);
525 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1);
526 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, cw
-m_leftOfSheet
, m_horizontalLabelHeight
+ 1);
527 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1);
528 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, m_verticalLabelWidth
+ 1, ch
-m_topOfSheet
);
531 void wxGenericGrid::DrawEditableArea(wxDC
*dc
)
534 GetClientSize(&cw
, &ch
);
536 dc
->SetPen(*wxTRANSPARENT_PEN
);
537 dc
->SetBrush(*wxTheBrushList
->FindOrCreateBrush(m_cellBackgroundColour
, wxSOLID
));
538 // dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight,
539 // m_rightOfSheet-(m_leftOfSheet+m_verticalLabelWidth) + 1, m_bottomOfSheet - (m_topOfSheet+m_horizontalLabelHeight) + 1);
540 dc
->DrawRectangle(m_leftOfSheet
+m_verticalLabelWidth
, m_topOfSheet
+m_horizontalLabelHeight
,
541 cw
-(m_leftOfSheet
+m_verticalLabelWidth
), ch
- (m_topOfSheet
+m_horizontalLabelHeight
));
544 void wxGenericGrid::DrawGridLines(wxDC
*dc
)
547 GetClientSize(&cw
, &ch
);
553 dc
->SetPen(*m_divisionPen
);
555 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
557 // Draw horizontal grey lines for cells
558 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
560 if (heightCount
> ch
)
564 dc
->DrawLine(m_leftOfSheet
, heightCount
,
567 heightCount
+= m_rowHeights
[i
];
572 if (m_verticalLabelWidth
> 0)
574 dc
->SetPen(*wxBLACK_PEN
);
576 // Draw horizontal black lines for row labels
577 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
578 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
580 if (heightCount
> ch
)
584 dc
->DrawLine(m_leftOfSheet
, heightCount
,
585 m_verticalLabelWidth
, heightCount
);
587 heightCount
+= m_rowHeights
[i
];
590 // Draw a black vertical line for row number cells
591 dc
->DrawLine(m_leftOfSheet
+ m_verticalLabelWidth
, m_topOfSheet
,
592 m_leftOfSheet
+ m_verticalLabelWidth
, ch
);
593 // First vertical line
594 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
, m_leftOfSheet
, ch
);
596 dc
->SetPen(*wxWHITE_PEN
);
598 // Draw highlights on row labels
599 heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
600 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
602 if (heightCount
> ch
)
606 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
607 m_verticalLabelWidth
, heightCount
+1);
608 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
609 m_leftOfSheet
+1, heightCount
+ m_rowHeights
[i
] - 1);
610 heightCount
+= m_rowHeights
[i
];
613 // Last one - down to the floor.
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, ch
);
623 dc
->SetPen(*m_divisionPen
);
625 // Draw vertical grey lines for cells
626 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
627 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
633 // Skip the first one
634 if (i
!= m_scrollPosX
)
636 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
637 widthCount
, m_bottomOfSheet
);
639 widthCount
+= m_colWidths
[i
];
643 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
644 widthCount
, m_bottomOfSheet
);
647 dc
->SetPen(*wxBLACK_PEN
);
649 // Draw two black horizontal lines for column number cells
651 m_leftOfSheet
, m_topOfSheet
,
653 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
+ m_horizontalLabelHeight
,
654 cw
, m_topOfSheet
+ m_horizontalLabelHeight
);
656 if (m_horizontalLabelHeight
> 0)
658 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
660 // Draw black vertical lines for column number cells
661 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
667 dc
->DrawLine(widthCount
, m_topOfSheet
,
668 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
669 widthCount
+= m_colWidths
[i
];
674 dc
->DrawLine(widthCount
, m_topOfSheet
,
675 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
678 dc
->SetPen(*wxWHITE_PEN
);
679 widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
681 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
687 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
688 widthCount
+m_colWidths
[i
], m_topOfSheet
+1);
689 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
690 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
691 widthCount
+= m_colWidths
[i
];
694 // Last one - to the right side of the canvas.
695 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
697 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
698 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
703 void wxGenericGrid::DrawColumnLabels(wxDC
*dc
)
706 GetClientSize(&cw
, &ch
);
708 if (m_horizontalLabelHeight
== 0)
714 // Draw letters for columns
715 rect
.y
= m_topOfSheet
+ 1;
716 rect
.height
= m_horizontalLabelHeight
- 1;
718 dc
->SetTextBackground(m_labelBackgroundColour
);
719 dc
->SetBackgroundMode(wxTRANSPARENT
);
720 // dc->SetTextForeground(m_labelTextColour);
722 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
723 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
729 rect
.x
= 1 + widthCount
;
730 rect
.width
= m_colWidths
[i
];
731 DrawColumnLabel(dc
, &rect
, i
);
733 widthCount
+= m_colWidths
[i
];
738 void wxGenericGrid::DrawColumnLabel(wxDC
*dc
, wxRectangle
*rect
, int col
)
740 wxGridCell
*cell
= GetLabelCell(wxHORIZONTAL
, col
);
749 dc
->SetTextForeground(GetLabelTextColour());
750 dc
->SetFont(*GetLabelTextFont());
751 if ( !cell
->GetTextValue().IsNull() )
752 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxHORIZONTAL
));
756 void wxGenericGrid::DrawRowLabels(wxDC
*dc
)
759 GetClientSize(&cw
, &ch
);
761 if (m_verticalLabelWidth
== 0)
767 // Draw numbers for rows
768 rect
.x
= m_leftOfSheet
;
769 rect
.width
= m_verticalLabelWidth
;
771 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
773 dc
->SetTextBackground(m_labelBackgroundColour
);
774 dc
->SetBackgroundMode(wxTRANSPARENT
);
776 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
778 if (heightCount
> ch
)
782 rect
.y
= 1 + heightCount
;
783 rect
.height
= m_rowHeights
[i
];
784 DrawRowLabel(dc
, &rect
, i
);
786 heightCount
+= m_rowHeights
[i
];
791 void wxGenericGrid::DrawRowLabel(wxDC
*dc
, wxRectangle
*rect
, int row
)
793 wxGridCell
*cell
= GetLabelCell(wxVERTICAL
, row
);
802 dc
->SetTextForeground(GetLabelTextColour());
803 dc
->SetFont(*GetLabelTextFont());
804 if ( !cell
->GetTextValue().IsNull() )
805 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxVERTICAL
));
809 void wxGenericGrid::DrawCells(wxDC
*dc
)
812 GetClientSize(&cw
, &ch
);
816 // Draw value corresponding to each cell
817 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
819 for (j
= m_scrollPosX
; j
< m_totalCols
; j
++)
821 SetCurrentRect(i
, j
, cw
, ch
);
822 if (m_currentRectVisible
)
824 DrawCellBackground(dc
, &m_currentRect
, i
, j
);
825 DrawCellValue(dc
, &m_currentRect
, i
, j
);
827 if (m_currentRect
.x
> cw
)
830 if (m_currentRect
.y
> ch
)
833 dc
->SetBackgroundMode(wxSOLID
);
834 dc
->SetPen(*wxBLACK_PEN
);
837 void wxGenericGrid::DrawCellBackground(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
839 wxGridCell
*cell
= GetCell(row
, col
);
842 dc
->SetBrush(*cell
->GetBackgroundBrush());
843 dc
->SetPen(*wxTRANSPARENT_PEN
);
845 #ifdef 0 // In wxWin 2.0 the dc code is exact. RR.
847 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
849 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
, rect
->height
);
853 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
855 dc
->SetPen(*wxBLACK_PEN
);
859 void wxGenericGrid::DrawCellValue(wxDC
*dc
, wxRectangle
*rect
, int row
, int col
)
861 wxGridCell
*cell
= GetCell(row
, col
);
864 wxBitmap
*bitmap
= cell
->GetCellBitmap();
874 DrawBitmapRect(dc
, bitmap
, &rect2
, cell
->GetAlignment());
878 dc
->SetBackgroundMode(wxTRANSPARENT
);
879 dc
->SetTextForeground(cell
->GetTextColour());
880 dc
->SetFont(*cell
->GetFont());
882 if ( !cell
->GetTextValue().IsNull() )
883 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, cell
->GetAlignment());
888 void wxGenericGrid::AdjustScrollbars(void)
891 GetClientSize(&cw
, &ch
);
893 // To calculate the number of steps for each scrollbar,
894 // we need to see how much will fit onto the canvas
895 // at the present size. So:
896 // 1) Find the *last* row r1 such that when it's at the top of the
897 // window, all the remaining rows are visible.
898 // 2) There should therefore be r1 - 1 steps in the scrollbar.
899 // Similarly with columns.
901 // IGNORE THE ABOVE, it's crap.
902 // We find the view size by seeing how many rows/cols fit on
904 // BUT... this means that the scrollbar should be adjusted every time
905 // it's scrolled, as well as when sized, because with variable size rows/cols,
906 // the number of rows/col visible on the view differs according to what bit
907 // you're looking at. The object length is always the same, but the
908 // view length differs.
910 // Since this may not be known until the end of this function, we should probably call AdjustScrollbars
912 int vertScrollBarWidth
= m_scrollWidth
;
913 int horizScrollBarHeight
= m_scrollWidth
;
914 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
915 vertScrollBarWidth
= 0;
916 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
917 horizScrollBarHeight
= 0;
919 int noHorizSteps
= 0;
922 if (m_totalGridWidth
<= cw
)
929 if (GetLabelSize(wxVERTICAL) > 0)
935 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
937 widthCount
+= m_colWidths
[i
];
938 // A partial bit doesn't count, we still have to scroll to see the
940 if (widthCount
+ m_leftOfSheet
+ m_verticalLabelWidth
> (cw
-vertScrollBarWidth
))
949 if (m_totalGridHeight
<= ch
)
956 if (GetLabelSize(wxHORIZONTAL) > 0)
962 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
964 heightCount
+= m_rowHeights
[i
];
965 // A partial bit doesn't count, we still have to scroll to see the
967 if (heightCount
+ m_topOfSheet
+ m_horizontalLabelHeight
> (ch
-horizScrollBarHeight
))
976 if (m_totalGridWidth
<= cw
)
979 m_hScrollBar
->Show(FALSE
);
985 m_hScrollBar
->Show(TRUE
);
988 if (m_totalGridHeight
<= ch
)
991 m_vScrollBar
->Show(FALSE
);
997 m_vScrollBar
->Show(TRUE
);
1000 UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
1002 vertScrollBarWidth
= m_scrollWidth
;
1003 horizScrollBarHeight
= m_scrollWidth
;
1004 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
1005 vertScrollBarWidth
= 0;
1006 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
1007 horizScrollBarHeight
= 0;
1011 int nCols
= GetCols();
1013 m_hScrollBar->SetPageSize(wxMax(noHorizSteps, 1));
1014 m_hScrollBar->SetViewLength(wxMax(noHorizSteps, 1));
1015 m_hScrollBar->SetObjectLength(nCols);
1017 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetPosition(), wxMax(noHorizSteps
, 1), nCols
, wxMax(noHorizSteps
, 1));
1019 m_hScrollBar
->SetSize(m_leftOfSheet
, ch
- m_scrollWidth
-2,
1020 cw
- vertScrollBarWidth
- m_leftOfSheet
, m_scrollWidth
);
1025 int nRows
= GetRows();
1027 m_vScrollBar->SetPageSize(wxMax(noVertSteps, 1));
1028 m_vScrollBar->SetViewLength(wxMax(noVertSteps, 1));
1029 m_vScrollBar->SetObjectLength(nRows);
1032 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetPosition(), wxMax(noVertSteps
, 1), nRows
, wxMax(noVertSteps
, 1));
1033 m_vScrollBar
->SetSize(cw
- m_scrollWidth
, m_topOfSheet
,
1034 m_scrollWidth
, ch
- m_topOfSheet
- horizScrollBarHeight
);
1038 void wxGenericGrid::OnSize(wxSizeEvent
& WXUNUSED(event
) )
1040 if (!m_vScrollBar
|| !m_hScrollBar
)
1046 GetClientSize(&cw
, &ch
);
1048 if (m_editCreated
&& m_editingPanel
&& GetTextItem() && GetTextItem()->IsShown())
1050 m_editingPanel
->SetSize(0, 0, cw
, m_editControlPosition
.height
+ m_editControlPosition
.y
+ 2);
1051 GetTextItem()->SetSize(m_editControlPosition
.x
, m_editControlPosition
.y
,
1052 cw
- m_editControlPosition
.x
, m_editControlPosition
.height
);
1056 bool wxGenericGrid::CellHitTest(int x
, int y
, int *row
, int *col
)
1058 // Find the selected cell and call OnSelectCell
1059 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1060 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1062 // Calculate the cell number from x and y
1063 x
-= (m_verticalLabelWidth
+ m_leftOfSheet
);
1064 y
-= (m_topOfSheet
+ m_horizontalLabelHeight
);
1068 // Now we need to do a hit test for which row we're on
1069 int currentHeight
= 0;
1070 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1072 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1077 currentHeight
+= m_rowHeights
[i
];
1080 // Now we need to do a hit test for which column we're on
1081 int currentWidth
= 0;
1082 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1084 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1089 currentWidth
+= m_colWidths
[i
];
1096 bool wxGenericGrid::LabelSashHitTest(int x
, int y
, int *orientation
, int *rowOrCol
, int *startPos
)
1101 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= m_topOfSheet
&&
1102 x
<= m_rightOfSheet
&& y
<= (m_topOfSheet
+ m_horizontalLabelHeight
))
1104 // We may be on a column label sash.
1105 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1106 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1108 if (x
>= (currentWidth
+ m_colWidths
[i
] - tolerance
) && x
<= (currentWidth
+ m_colWidths
[i
] + tolerance
))
1110 *orientation
= wxHORIZONTAL
;
1112 *startPos
= currentWidth
;
1115 currentWidth
+= m_colWidths
[i
];
1119 else if (x
>= m_leftOfSheet
&& y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1120 x
<= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
<= m_bottomOfSheet
)
1122 // We may be on a row label sash.
1123 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1124 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1126 if (y
>= (currentHeight
+ m_rowHeights
[i
] - tolerance
) && y
<= (currentHeight
+ m_rowHeights
[i
] + tolerance
))
1128 *orientation
= wxVERTICAL
;
1130 *startPos
= currentHeight
;
1133 currentHeight
+= m_rowHeights
[i
];
1140 bool wxGenericGrid::LabelHitTest(int x
, int y
, int *row
, int *col
)
1142 // Find the selected label
1143 if (x
>= m_leftOfSheet
&& y
>= m_topOfSheet
&&
1144 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1146 // Calculate the cell number from x and y
1152 // Now we need to do a hit test for which row we're on
1153 int currentHeight
= m_horizontalLabelHeight
;
1154 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1156 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1161 currentHeight
+= m_rowHeights
[i
];
1163 if (y
>= 0 && y
<= m_horizontalLabelHeight
)
1168 // Now we need to do a hit test for which column we're on
1169 int currentWidth
= m_verticalLabelWidth
;
1170 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1172 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1177 currentWidth
+= m_colWidths
[i
];
1179 if (x
>= 0 && x
<= m_verticalLabelWidth
)
1184 if ((*col
== -1) || (*row
== -1))
1192 void wxGenericGrid::OnMouseEvent(wxMouseEvent
& ev
)
1196 wxClientDC
dc(this);
1200 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1202 OnSelectCellImplementation(& dc
, row
, col
);
1203 OnCellLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1205 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1207 OnLabelLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1211 else if (ev
.Dragging() && ev
.LeftIsDown())
1213 switch (m_dragStatus
)
1215 case wxGRID_DRAG_NONE
:
1218 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &m_dragRowOrCol
, &m_dragStartPosition
))
1220 if (orientation
== wxHORIZONTAL
)
1222 m_dragStatus
= wxGRID_DRAG_LEFT_RIGHT
;
1223 SetCursor(*m_horizontalSashCursor
);
1224 m_dragLastPosition
= (int)ev
.GetX();
1228 m_dragStatus
= wxGRID_DRAG_UP_DOWN
;
1229 SetCursor(*m_verticalSashCursor
);
1230 m_dragLastPosition
= (int)ev
.GetY();
1232 wxClientDC
dc(this);
1234 dc
.SetLogicalFunction(wxINVERT
);
1235 if (orientation
== wxHORIZONTAL
)
1236 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1238 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1245 case wxGRID_DRAG_LEFT_RIGHT
:
1247 wxClientDC
dc(this);
1249 dc
.SetLogicalFunction(wxINVERT
);
1250 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1252 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1255 m_dragLastPosition
= (int)ev
.GetX();
1256 SetCursor(*m_horizontalSashCursor
);
1259 case wxGRID_DRAG_UP_DOWN
:
1261 wxClientDC
dc(this);
1263 dc
.SetLogicalFunction(wxINVERT
);
1264 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1266 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1269 m_dragLastPosition
= (int)ev
.GetY();
1270 SetCursor(*m_verticalSashCursor
);
1275 else if (ev
.Moving())
1277 int rowOrCol
, orientation
, startPos
;
1278 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &rowOrCol
, &startPos
))
1280 if (orientation
== wxHORIZONTAL
)
1281 SetCursor(*m_horizontalSashCursor
);
1283 SetCursor(*m_verticalSashCursor
);
1286 SetCursor(*wxSTANDARD_CURSOR
);
1288 else if (ev
.LeftUp())
1290 switch (m_dragStatus
)
1292 case wxGRID_DRAG_LEFT_RIGHT
:
1294 wxClientDC
dc(this);
1296 dc
.SetLogicalFunction(wxINVERT
);
1297 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1298 dc
.SetLogicalFunction(wxCOPY
);
1302 if (ev
.GetX() > m_dragStartPosition
)
1304 m_colWidths
[m_dragRowOrCol
] = (short)(ev
.GetX() - m_dragStartPosition
);
1309 SetCursor(*wxSTANDARD_CURSOR
);
1311 GetClientSize(&cw
, &ch
);
1316 case wxGRID_DRAG_UP_DOWN
:
1318 wxClientDC
dc(this);
1320 dc
.SetLogicalFunction(wxINVERT
);
1321 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1322 dc
.SetLogicalFunction(wxCOPY
);
1326 if (ev
.GetY() > m_dragStartPosition
)
1328 m_rowHeights
[m_dragRowOrCol
] = (short)(ev
.GetY() - m_dragStartPosition
);
1333 SetCursor(*wxSTANDARD_CURSOR
);
1337 m_dragStatus
= wxGRID_DRAG_NONE
;
1339 else if (ev
.RightDown())
1342 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1344 OnCellRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1346 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1348 OnLabelRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1353 void wxGenericGrid::OnSelectCellImplementation(wxDC
*dc
, int row
, int col
)
1355 m_wCursorColumn
= col
;
1358 OnChangeSelectionLabel();
1360 SetGridClippingRegion(dc
);
1362 // Remove the highlight from the old cell
1363 if (m_currentRectVisible
)
1366 // Highlight the new cell and copy its content to the edit control
1367 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
1368 wxGridCell
*cell
= GetCell(m_wCursorRow
, m_wCursorColumn
);
1371 if ( cell
->GetTextValue().IsNull() )
1372 m_textItem
->SetValue("");
1374 m_textItem
->SetValue(cell
->GetTextValue());
1377 SetGridClippingRegion(dc
);
1379 // Why isn't this needed for Windows??
1380 // Probably because of the SetValue??
1381 // Arrrrrgh. This isn't needed anywhere, of course. RR.
1383 // HighlightCell(dc);
1385 dc
->DestroyClippingRegion();
1387 OnSelectCell(row
, col
);
1390 wxGridCell
*wxGenericGrid::OnCreateCell(void)
1392 return new wxGridCell(this);
1395 void wxGenericGrid::OnChangeLabels(void)
1399 for (i
= 0; i
< m_totalRows
; i
++)
1401 sprintf(buf
, "%d", i
+1);
1402 SetLabelValue(wxVERTICAL
, buf
, i
);
1404 // A...Z,AA...ZZ,AAA...ZZZ, etc.
1405 for (i
= 0; i
< m_totalCols
; i
++)
1408 int noTimes
= (i
/26 + 1);
1409 int ch
= (i
% 26) + 65;
1411 for (j
= 0; j
< noTimes
; j
++)
1414 sprintf(buf2
, "%c", (char)ch
);
1417 SetLabelValue(wxHORIZONTAL
, buf
, i
);
1421 void wxGenericGrid::OnChangeSelectionLabel(void)
1426 wxString
rowLabel(GetLabelValue(wxVERTICAL
, GetCursorRow()));
1427 wxString
colLabel(GetLabelValue(wxHORIZONTAL
, GetCursorColumn()));
1429 wxString newLabel
= colLabel
+ rowLabel
;
1430 if ((newLabel
.Length() > 0) && (newLabel
.Length() <= 8) && GetTextItem())
1432 // GetTextItem()->SetLabel(newLabel);
1436 void wxGenericGrid::HighlightCell(wxDC
*dc
)
1438 dc
->SetLogicalFunction(wxINVERT
);
1441 dc
->DrawLine( m_currentRect
.x
+ 1,
1442 m_currentRect
.y
+ 1,
1443 m_currentRect
.x
+ m_currentRect
.width
- 1,
1444 m_currentRect
.y
+ 1);
1446 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1447 m_currentRect
.y
+ 1,
1448 m_currentRect
.x
+ m_currentRect
.width
- 1,
1449 m_currentRect
.y
+m_currentRect
.height
- 1 );
1451 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1452 m_currentRect
.y
+ m_currentRect
.height
- 1,
1453 m_currentRect
.x
+ 1,
1454 m_currentRect
.y
+ m_currentRect
.height
- 1);
1456 dc
->DrawLine( m_currentRect
.x
+ 1,
1457 m_currentRect
.y
+ m_currentRect
.height
- 1,
1458 m_currentRect
.x
+ 1,
1459 m_currentRect
.y
+ 1);
1461 dc
->SetLogicalFunction(wxCOPY
);
1464 void wxGenericGrid::DrawCellText(void)
1466 if (!m_currentRectVisible
)
1469 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1473 static char szEdit
[300];
1475 wxClientDC
dc(this);
1478 SetGridClippingRegion(& dc
);
1480 dc
.SetBackgroundMode(wxTRANSPARENT
);
1481 dc
.SetBrush(*cell
->GetBackgroundBrush());
1483 strcpy(szEdit
, m_textItem
->GetValue());
1486 rect
= m_currentRect
;
1492 DrawTextRect(& dc
, " ", &rect
, wxLEFT
);
1493 DrawTextRect(& dc
, szEdit
, &rect
, cell
->GetAlignment());
1495 dc
.DestroyClippingRegion();
1497 dc
.SetBackgroundMode(wxSOLID
);
1502 void wxGenericGrid::SetCurrentRect(int Row
, int Column
, int canvasW
, int canvasH
)
1504 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1506 for (i
= m_scrollPosX
; i
< Column
; i
++)
1507 currentWidth
+= m_colWidths
[i
];
1509 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1510 for (i
= m_scrollPosY
; i
< Row
; i
++)
1511 currentHeight
+= m_rowHeights
[i
];
1513 m_currentRect
.x
= currentWidth
;
1514 m_currentRect
.y
= currentHeight
;
1515 m_currentRect
.width
= m_colWidths
? (m_colWidths
[Column
]) : 0;
1516 m_currentRect
.height
= m_rowHeights
? (m_rowHeights
[Row
]) : 0;
1518 if (Row
< m_scrollPosY
|| Column
< m_scrollPosX
)
1519 m_currentRectVisible
= FALSE
;
1520 else if ((canvasW
!= -1 && canvasH
!= -1) && (m_currentRect
.x
> canvasW
|| m_currentRect
.y
> canvasH
))
1521 m_currentRectVisible
= FALSE
;
1522 else m_currentRectVisible
= TRUE
;
1525 static bool wxRectIntersection(wxRectangle
*rect1
, wxRectangle
*rect2
, wxRectangle
*rect3
)
1527 int x2_1
= rect1
->x
+ rect1
->width
;
1528 int y2_1
= rect1
->y
+ rect1
->height
;
1530 int x2_2
= rect2
->x
+ rect2
->width
;
1531 int y2_2
= rect2
->y
+ rect2
->height
;
1535 // Check for intersection
1536 if ((rect1
->x
> x2_2
) || (rect2
->x
> x2_1
) ||
1537 (rect1
->y
> y2_2
) || (rect2
->y
> y2_1
))
1540 rect3
->x
= rect3
->y
= rect3
->width
= rect3
->height
= 0;
1544 if (rect1
->x
> rect2
->x
)
1545 rect3
->x
= rect1
->x
;
1547 rect3
->x
= rect2
->x
;
1548 if (rect1
->y
> rect2
->y
)
1549 rect3
->y
= rect1
->y
;
1551 rect3
->y
= rect2
->y
;
1562 rect3
->width
= (int)(x2_3
- rect3
->x
);
1563 rect3
->height
= (int)(y2_3
- rect3
->y
);
1567 void wxGenericGrid::DrawTextRect(wxDC
*dc
, const wxString
& text
, wxRectangle
*rect
, int flag
)
1571 // Ultimately, this functionality should be built into wxWindows,
1572 // and optimized for each platform. E.g. on Windows, use DrawText
1573 // passing a clipping rectangle, so that the wxWindows clipping region
1574 // does not have to be used to implement this.
1576 // If we're already clipping, we need to find the intersection
1577 // between current clipping area and text clipping area.
1579 wxRectangle clipRect
;
1580 wxRectangle clipRect2
;
1581 long clipX
, clipY
, clipW
, clipH
;
1582 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1583 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1584 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1586 bool alreadyClipping
= TRUE
;
1588 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1590 alreadyClipping
= FALSE
;
1591 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1592 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1596 // Find intersection.
1597 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1601 if (alreadyClipping
)
1602 dc
->DestroyClippingRegion();
1604 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1605 long textWidth
, textHeight
;
1607 dc
->GetTextExtent(text
, &textWidth
, &textHeight
);
1615 x
= (rect
->x
+ rect
->width
- textWidth
- 1.0);
1616 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1621 x
= (rect
->x
+ (rect
->width
- textWidth
)/2.0);
1622 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1628 x
= (rect
->x
+ 1.0);
1629 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1633 dc
->DrawText(text
, (long)x
, (long)y
);
1635 dc
->DestroyClippingRegion();
1637 // Restore old clipping
1638 if (alreadyClipping
)
1639 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1644 void wxGenericGrid::DrawBitmapRect(wxDC
*dc
, wxBitmap
*bitmap
, wxRectangle
*rect
, int flag
)
1648 // Ultimately, this functionality should be built into wxWindows,
1649 // and optimized for each platform. E.g. on Windows, use DrawText
1650 // passing a clipping rectangle, so that the wxWindows clipping region
1651 // does not have to be used to implement this.
1653 // If we're already clipping, we need to find the intersection
1654 // between current clipping area and text clipping area.
1656 wxRectangle clipRect
;
1657 wxRectangle clipRect2
;
1658 long clipX
, clipY
, clipW
, clipH
;
1659 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1660 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1661 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1663 bool alreadyClipping
= TRUE
;
1665 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1667 alreadyClipping
= FALSE
;
1668 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1669 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1673 // Find intersection.
1674 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1678 if (alreadyClipping
)
1679 dc
->DestroyClippingRegion();
1681 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1682 float bitmapWidth
, bitmapHeight
;
1684 bitmapWidth
= bitmap
->GetWidth();
1685 bitmapHeight
= bitmap
->GetHeight();
1693 x
= (long)(rect
->x
+ rect
->width
- bitmapWidth
- 1);
1694 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1699 x
= (long)(rect
->x
+ (rect
->width
- bitmapWidth
)/2.0);
1700 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1706 x
= (long)(rect
->x
+ 1);
1707 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1712 dcTemp
.SelectObject(*bitmap
);
1714 dc
->Blit( (long)x
, (long)y
, (long)bitmapWidth
, (long)bitmapHeight
, &dcTemp
, 0, 0);
1715 dcTemp
.SelectObject(wxNullBitmap
);
1717 dc
->DestroyClippingRegion();
1719 // Restore old clipping
1720 if (alreadyClipping
)
1721 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1726 void wxGenericGrid::OnActivate(bool active
)
1730 // Edit control should always have the focus
1731 if (GetTextItem() && GetEditable())
1733 GetTextItem()->SetFocus();
1734 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1736 GetTextItem()->SetValue(cell
->GetTextValue());
1741 void wxGenericGrid::SetCellValue(const wxString
& val
, int row
, int col
)
1743 wxGridCell
*cell
= GetCell(row
, col
);
1746 cell
->SetTextValue(val
);
1748 RefreshCell(row
, col
, TRUE
);
1752 void wxGenericGrid::RefreshCell(int row
, int col
, bool setText
)
1754 // Don't refresh within a pair of batch brackets
1755 if (GetBatchCount() > 0)
1759 GetClientSize(&cw
, &ch
);
1761 SetCurrentRect(row
, col
, cw
, ch
);
1762 if (m_currentRectVisible
)
1764 wxGridCell
*cell
= GetCell(row
, col
);
1766 bool currentPos
= FALSE
;
1767 if (row
== m_wCursorRow
&& col
== m_wCursorColumn
&& GetTextItem() && GetTextItem()->IsShown() && setText
)
1769 GetTextItem()->SetValue(cell
->GetTextValue());
1772 // Gets refreshed anyway in MSW
1777 wxClientDC
dc(this);
1779 DrawCellBackground(& dc
, &m_currentRect
, row
, col
);
1780 DrawCellValue(& dc
, &m_currentRect
, row
, col
);
1786 wxString
& wxGenericGrid::GetCellValue(int row
, int col
)
1788 static wxString
emptyString("");
1790 wxGridCell
*cell
= GetCell(row
, col
);
1792 return cell
->GetTextValue();
1797 void wxGenericGrid::SetColumnWidth(int col
, int width
)
1799 if (col
<= m_totalCols
)
1800 m_colWidths
[col
] = width
;
1803 int wxGenericGrid::GetColumnWidth(int col
)
1805 if (col
<= m_totalCols
)
1806 return m_colWidths
[col
];
1811 void wxGenericGrid::SetRowHeight(int row
, int height
)
1813 if (row
<= m_totalRows
)
1814 m_rowHeights
[row
] = height
;
1817 int wxGenericGrid::GetRowHeight(int row
)
1819 if (row
<= m_totalRows
)
1820 return m_rowHeights
[row
];
1825 void wxGenericGrid::SetLabelSize(int orientation
, int sz
)
1827 if (orientation
== wxHORIZONTAL
)
1828 m_horizontalLabelHeight
= sz
;
1830 m_verticalLabelWidth
= sz
;
1832 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1835 int wxGenericGrid::GetLabelSize(int orientation
)
1837 if (orientation
== wxHORIZONTAL
)
1838 return m_horizontalLabelHeight
;
1840 return m_verticalLabelWidth
;
1843 wxGridCell
*wxGenericGrid::GetLabelCell(int orientation
, int pos
)
1845 if (orientation
== wxHORIZONTAL
)
1847 if (m_colLabelCells
&& pos
< m_totalCols
)
1848 return m_colLabelCells
[pos
];
1854 if (m_rowLabelCells
&& pos
< m_totalRows
)
1855 return m_rowLabelCells
[pos
];
1861 void wxGenericGrid::SetLabelValue(int orientation
, const wxString
& val
, int pos
)
1863 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1865 cell
->SetTextValue(val
);
1868 wxString
& wxGenericGrid::GetLabelValue(int orientation
, int pos
)
1870 static wxString emptyString
= "";
1871 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1873 return cell
->GetTextValue();
1878 void wxGenericGrid::SetLabelAlignment(int orientation
, int align
)
1880 if (orientation
== wxHORIZONTAL
)
1881 m_horizontalLabelAlignment
= align
;
1883 m_verticalLabelAlignment
= align
;
1885 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1888 int wxGenericGrid::GetLabelAlignment(int orientation
)
1890 if (orientation
== wxHORIZONTAL
)
1891 return m_horizontalLabelAlignment
;
1893 return m_verticalLabelAlignment
;
1896 void wxGenericGrid::SetLabelTextColour(const wxColour
& colour
)
1898 m_labelTextColour
= colour
;
1902 void wxGenericGrid::SetLabelBackgroundColour(const wxColour
& colour
)
1904 m_labelBackgroundColour
= colour
;
1905 m_labelBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush(m_labelBackgroundColour
, wxSOLID
);
1908 void wxGenericGrid::SetEditable(bool edit
)
1913 int controlW
, controlH
;
1914 m_textItem
->GetSize(&controlW
, &controlH
);
1915 m_editControlPosition
.height
= controlH
;
1917 m_topOfSheet
= m_editControlPosition
.x
+ controlH
+ 2;
1920 m_editingPanel
->Show(TRUE
);
1921 m_textItem
->Show(TRUE
);
1922 m_textItem
->SetFocus();
1930 m_textItem
->Show(FALSE
);
1931 m_editingPanel
->Show(FALSE
);
1935 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1938 GetClientSize(&cw
, &ch
);
1943 int m_scrollWidth = 16;
1944 GetClientSize(&cw, &ch);
1947 m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
1948 m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
1952 void wxGenericGrid::SetCellAlignment(int flag
, int row
, int col
)
1954 wxGridCell
*cell
= GetCell(row
, col
);
1956 cell
->SetAlignment(flag
);
1959 int wxGenericGrid::GetCellAlignment(int row
, int col
)
1961 wxGridCell
*cell
= GetCell(row
, col
);
1963 return cell
->GetAlignment();
1965 return m_cellAlignment
;
1968 void wxGenericGrid::SetCellAlignment(int flag
)
1970 m_cellAlignment
= flag
;
1972 for (i
= 0; i
< GetRows(); i
++)
1973 for (j
= 0; j
< GetCols(); j
++)
1975 GetCell(i
, j
)->SetAlignment(flag
);
1978 int wxGenericGrid::GetCellAlignment(void)
1980 return m_cellAlignment
;
1983 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& col
)
1985 m_cellBackgroundColour
= col
;
1987 for (i
= 0; i
< GetRows(); i
++)
1988 for (j
= 0; j
< GetCols(); j
++)
1990 GetCell(i
, j
)->SetBackgroundColour(col
);
1993 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& val
, int row
, int col
)
1995 wxGridCell
*cell
= GetCell(row
, col
);
1998 cell
->SetBackgroundColour(val
);
1999 RefreshCell(row
, col
);
2003 wxColour
& wxGenericGrid::GetCellBackgroundColour(int row
, int col
)
2005 wxGridCell
*cell
= GetCell(row
, col
);
2007 return cell
->GetBackgroundColour();
2009 return m_cellBackgroundColour
;
2012 void wxGenericGrid::SetCellTextColour(const wxColour
& val
, int row
, int col
)
2014 wxGridCell
*cell
= GetCell(row
, col
);
2017 cell
->SetTextColour(val
);
2018 RefreshCell(row
, col
);
2022 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
, int row
, int col
)
2024 wxGridCell
*cell
= GetCell(row
, col
);
2028 RefreshCell(row
, col
);
2032 wxFont
*wxGenericGrid::GetCellTextFont(int row
, int col
)
2034 wxGridCell
*cell
= GetCell(row
, col
);
2036 return cell
->GetFont();
2038 return m_cellTextFont
;
2041 wxColour
& wxGenericGrid::GetCellTextColour(int row
, int col
)
2043 wxGridCell
*cell
= GetCell(row
, col
);
2045 return cell
->GetTextColour();
2047 return m_cellTextColour
;
2050 void wxGenericGrid::SetCellTextColour(const wxColour
& val
)
2052 m_cellTextColour
= val
;
2054 for (i
= 0; i
< GetRows(); i
++)
2055 for (j
= 0; j
< GetCols(); j
++)
2057 GetCell(i
, j
)->SetTextColour(val
);
2060 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
)
2062 m_cellTextFont
= fnt
;
2064 for (i
= 0; i
< GetRows(); i
++)
2065 for (j
= 0; j
< GetCols(); j
++)
2067 GetCell(i
, j
)->SetFont(fnt
);
2070 void wxGenericGrid::SetCellBitmap(wxBitmap
*bitmap
, int row
, int col
)
2072 wxGridCell
*cell
= GetCell(row
, col
);
2075 cell
->SetCellBitmap(bitmap
);
2076 RefreshCell(row
, col
);
2080 wxBitmap
*wxGenericGrid::GetCellBitmap(int row
, int col
)
2082 wxGridCell
*cell
= GetCell(row
, col
);
2085 return cell
->GetCellBitmap();
2091 bool wxGenericGrid::InsertCols(int pos
, int n
, bool updateLabels
)
2093 if (pos
> m_totalCols
)
2097 return CreateGrid(1, n
);
2102 for (i
= 0; i
< m_totalRows
; i
++)
2104 wxGridCell
**cols
= m_gridCells
[i
];
2105 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
+ n
];
2106 for (j
= 0; j
< pos
; j
++)
2107 newCols
[j
] = cols
[j
];
2108 for (j
= pos
; j
< pos
+ n
; j
++)
2109 newCols
[j
] = new wxGridCell(this);
2110 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2111 newCols
[j
] = cols
[j
- n
];
2114 m_gridCells
[i
] = newCols
;
2118 short *newColWidths
= new short[m_totalCols
+ n
];
2119 for (j
= 0; j
< pos
; j
++)
2120 newColWidths
[j
] = m_colWidths
[j
];
2121 for (j
= pos
; j
< pos
+ n
; j
++)
2122 newColWidths
[j
] = wxGRID_DEFAULT_CELL_WIDTH
;
2123 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2124 newColWidths
[j
] = m_colWidths
[j
- n
];
2125 delete[] m_colWidths
;
2126 m_colWidths
= newColWidths
;
2129 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
+ n
];
2130 for (j
= 0; j
< pos
; j
++)
2131 newLabels
[j
] = m_colLabelCells
[j
];
2132 for (j
= pos
; j
< pos
+ n
; j
++)
2133 newLabels
[j
] = new wxGridCell(this);
2134 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2135 newLabels
[j
] = m_colLabelCells
[j
- n
];
2137 delete[] m_colLabelCells
;
2138 m_colLabelCells
= newLabels
;
2150 bool wxGenericGrid::InsertRows(int pos
, int n
, bool updateLabels
)
2152 if (pos
> m_totalRows
)
2156 return CreateGrid(n
, 1);
2161 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
+ n
];
2164 for (i
= 0; i
< pos
; i
++)
2165 rows
[i
] = m_gridCells
[i
];
2167 for (i
= pos
; i
< pos
+ n
; i
++)
2169 rows
[i
] = new wxGridCell
*[m_totalCols
];
2170 for (j
= 0; j
< m_totalCols
; j
++)
2171 rows
[i
][j
] = new wxGridCell(this);
2174 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2175 rows
[i
] = m_gridCells
[i
- n
];
2177 delete[] m_gridCells
;
2181 short *newRowHeights
= new short[m_totalRows
+ n
];
2182 for (i
= 0; i
< pos
; i
++)
2183 newRowHeights
[i
] = m_rowHeights
[i
];
2184 for (i
= pos
; i
< pos
+ n
; i
++)
2185 newRowHeights
[i
] = wxGRID_DEFAULT_CELL_HEIGHT
;
2186 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2187 newRowHeights
[i
] = m_rowHeights
[i
- n
];
2188 delete[] m_rowHeights
;
2189 m_rowHeights
= newRowHeights
;
2192 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
+ n
];
2193 for (i
= 0; i
< pos
; i
++)
2194 newLabels
[i
] = m_rowLabelCells
[i
];
2195 for (i
= pos
; i
< pos
+ n
; i
++)
2196 newLabels
[i
] = new wxGridCell(this);
2197 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2198 newLabels
[i
] = m_rowLabelCells
[i
- n
];
2200 delete[] m_rowLabelCells
;
2201 m_rowLabelCells
= newLabels
;
2213 bool wxGenericGrid::AppendCols(int n
, bool updateLabels
)
2215 return InsertCols(GetCols(), n
, updateLabels
);
2218 bool wxGenericGrid::AppendRows(int n
, bool updateLabels
)
2220 return InsertRows(GetRows(), n
, updateLabels
);
2223 bool wxGenericGrid::DeleteRows(int pos
, int n
, bool updateLabels
)
2225 if (pos
> m_totalRows
)
2232 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
- n
];
2235 for (i
= 0; i
< pos
; i
++)
2236 rows
[i
] = m_gridCells
[i
];
2238 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2239 rows
[i
-n
] = m_gridCells
[i
];
2241 delete[] m_gridCells
;
2245 short *newRowHeights
= new short[m_totalRows
- n
];
2246 for (i
= 0; i
< pos
; i
++)
2247 newRowHeights
[i
] = m_rowHeights
[i
];
2248 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2249 newRowHeights
[i
-n
] = m_rowHeights
[i
];
2250 delete[] m_rowHeights
;
2251 m_rowHeights
= newRowHeights
;
2254 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
- n
];
2255 for (i
= 0; i
< pos
; i
++)
2256 newLabels
[i
] = m_rowLabelCells
[i
];
2257 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2258 newLabels
[i
-n
] = m_rowLabelCells
[i
];
2260 delete[] m_rowLabelCells
;
2261 m_rowLabelCells
= newLabels
;
2272 bool wxGenericGrid::DeleteCols(int pos
, int n
, bool updateLabels
)
2274 if (pos
+ n
> m_totalCols
)
2282 for (i
= 0; i
< m_totalRows
; i
++)
2284 wxGridCell
**cols
= m_gridCells
[i
];
2285 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
- n
];
2286 for (j
= 0; j
< pos
; j
++)
2287 newCols
[j
] = cols
[j
];
2288 for (j
= pos
; j
< pos
+ n
; j
++)
2290 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2291 newCols
[j
-n
] = cols
[j
];
2294 m_gridCells
[i
] = newCols
;
2298 short *newColWidths
= new short[m_totalCols
- n
];
2299 for (j
= 0; j
< pos
; j
++)
2300 newColWidths
[j
] = m_colWidths
[j
];
2301 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2302 newColWidths
[j
-n
] = m_colWidths
[j
];
2303 delete[] m_colWidths
;
2304 m_colWidths
= newColWidths
;
2307 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
- n
];
2308 for (j
= 0; j
< pos
; j
++)
2309 newLabels
[j
] = m_colLabelCells
[j
];
2310 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2311 newLabels
[j
-n
] = m_colLabelCells
[j
];
2313 delete[] m_colLabelCells
;
2314 m_colLabelCells
= newLabels
;
2325 void wxGenericGrid::SetGridCursor(int row
, int col
)
2327 if (row
>= m_totalRows
|| col
>= m_totalCols
)
2330 if (row
== GetCursorRow() && col
== GetCursorColumn())
2333 wxClientDC
dc(this);
2336 SetGridClippingRegion(& dc
);
2338 if (m_currentRectVisible
)
2339 HighlightCell(& dc
);
2342 m_wCursorColumn
= col
;
2343 SetCurrentRect(row
, col
);
2344 if (m_currentRectVisible
)
2345 HighlightCell(& dc
);
2347 dc
.DestroyClippingRegion();
2355 wxGridCell::wxGridCell(wxGenericGrid
*window
)
2359 backgroundBrush
= NULL
;
2361 textColour
= window
->GetCellTextColour();
2363 textColour
.Set(0,0,0);
2365 backgroundColour
= window
->GetCellBackgroundColour();
2367 backgroundColour
.Set(255,255,255);
2370 font
= window
->GetCellTextFont();
2372 font
= wxTheFontList
->FindOrCreateFont(12, wxSWISS
, wxNORMAL
, wxNORMAL
);
2374 SetBackgroundColour(backgroundColour
);
2377 alignment
= window
->GetCellAlignment();
2382 wxGridCell::~wxGridCell(void)
2386 void wxGridCell::SetBackgroundColour(const wxColour
& colour
)
2388 backgroundColour
= colour
;
2389 backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(backgroundColour
, wxSOLID
);
2392 void wxGenericGrid::OnText(wxCommandEvent
& WXUNUSED(ev
) )
2394 wxGenericGrid
*grid
= this;
2395 wxGridCell
*cell
= grid
->GetCell(grid
->GetCursorRow(), grid
->GetCursorColumn());
2396 if (cell
&& grid
->CurrentCellVisible())
2398 cell
->SetTextValue(grid
->GetTextItem()->GetValue());
2399 wxClientDC
dc(grid
);
2402 grid
->SetGridClippingRegion(& dc
);
2403 grid
->DrawCellBackground(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2404 grid
->DrawCellValue(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2405 grid
->HighlightCell(& dc
);
2406 dc
.DestroyClippingRegion();
2409 grid
->OnCellChange(grid
->GetCursorRow(), grid
->GetCursorColumn());
2411 // grid->DrawCellText();
2415 void wxGenericGrid::OnGridScroll(wxScrollEvent
& ev
)
2417 static bool inScroll
= FALSE
;
2423 wxGenericGrid
*win
= this;
2425 bool change
= FALSE
;
2427 if (ev
.GetEventObject() == win
->GetHorizScrollBar())
2429 change
= (ev
.GetPosition() != m_scrollPosX
);
2430 win
->SetScrollPosX(ev
.GetPosition());
2434 change
= (ev
.GetPosition() != m_scrollPosY
);
2435 win
->SetScrollPosY(ev
.GetPosition());
2438 win
->UpdateDimensions();
2439 win
->SetCurrentRect(win
->GetCursorRow(), win
->GetCursorColumn());
2441 // Because rows and columns can be arbitrary sizes,
2442 // the scrollbars will need to be adjusted to reflect the
2446 if (change
) win
->Refresh(FALSE
);