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 wxUSE_DOUBLE_BUFFERING 1
38 #define wxUSE_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)
60 m_hScrollBar
= (wxScrollBar
*) NULL
;
61 m_vScrollBar
= (wxScrollBar
*) NULL
;
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
= (wxBrush
*) NULL
;
68 m_labelTextFont
= (wxFont
*) NULL
;
69 m_cellTextFont
= (wxFont
*) NULL
;
70 m_textItem
= (wxTextCtrl
*) 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;
82 m_divisionPen
= (wxPen
*) NULL
;
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;
88 m_colWidths
= (short *) NULL
;
89 m_rowHeights
= (short *) NULL
;
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
;
105 m_gridCells
= (wxGridCell
***) NULL
;
106 m_rowLabelCells
= (wxGridCell
**) NULL
;
107 m_colLabelCells
= (wxGridCell
**) NULL
;
108 m_textItem
= (wxTextCtrl
*) NULL
;
109 m_horizontalSashCursor
= (wxCursor
*) NULL
;
110 m_verticalSashCursor
= (wxCursor
*) NULL
;
113 bool wxGenericGrid::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
114 long style
, const wxString
& name
)
117 m_editingPanel
= (wxPanel
*) NULL
;
118 m_hScrollBar
= (wxScrollBar
*) NULL
;
119 m_vScrollBar
= (wxScrollBar
*) NULL
;
120 m_horizontalSashCursor
= (wxCursor
*) NULL
;
121 m_verticalSashCursor
= (wxCursor
*) 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
= (wxBrush
*) NULL
;
128 m_labelTextFont
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
129 m_cellTextFont
= wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
130 m_textItem
= (wxTextCtrl
*) NULL
;
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
= (wxBitmap
*) 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;
158 m_colWidths
= (short *) NULL
;
159 m_rowHeights
= (short *) NULL
;
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
;
183 m_gridCells
= (wxGridCell
***) NULL
;
184 m_rowLabelCells
= (wxGridCell
**) NULL
;
185 m_colLabelCells
= (wxGridCell
**) NULL
;
186 m_textItem
= (wxTextCtrl
*) 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
;
230 m_gridCells
= (wxGridCell
***) NULL
;
233 delete[] m_colWidths
;
234 m_colWidths
= (short *) NULL
;
236 delete[] m_rowHeights
;
237 m_rowHeights
= (short *) NULL
;
241 for (i
= 0; i
< m_totalRows
; i
++)
242 delete m_rowLabelCells
[i
];
243 delete[] m_rowLabelCells
;
244 m_rowLabelCells
= (wxGridCell
**) NULL
;
248 for (i
= 0; i
< m_totalCols
; i
++)
249 delete m_colLabelCells
[i
];
250 delete[] m_colLabelCells
;
251 m_colLabelCells
= (wxGridCell
**) NULL
;
253 if (m_doubleBufferingBitmap
)
255 delete m_doubleBufferingBitmap
;
256 m_doubleBufferingBitmap
= (wxBitmap
*) 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
] = (wxGridCell
*) 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
)
384 return (wxGridCell
*) NULL
;
386 if ((row
>= m_totalRows
) || (col
>= m_totalCols
))
387 return (wxGridCell
*) NULL
;
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) wxUSE_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
= (wxBitmap
*) 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 // We find the view size by seeing how many rows/cols fit on
903 // BUT... this means that the scrollbar should be adjusted every time
904 // it's scrolled, as well as when sized, because with variable size rows/cols,
905 // the number of rows/col visible on the view differs according to what bit
906 // you're looking at. The object length is always the same, but the
907 // view length differs.
909 // Since this may not be known until the end of this function, we should probably call AdjustScrollbars
911 int vertScrollBarWidth
= m_scrollWidth
;
912 int horizScrollBarHeight
= m_scrollWidth
;
913 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
914 vertScrollBarWidth
= 0;
915 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
916 horizScrollBarHeight
= 0;
918 int noHorizSteps
= 0;
921 if (m_totalGridWidth
+ vertScrollBarWidth
<= cw
)
930 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
932 widthCount
+= m_colWidths
[i
];
933 // A partial bit doesn't count, we still have to scroll to see the
935 if (widthCount
+ m_leftOfSheet
+ m_verticalLabelWidth
> (cw
-vertScrollBarWidth
))
944 if (m_totalGridHeight
+ horizScrollBarHeight
<= ch
)
953 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
955 heightCount
+= m_rowHeights
[i
];
956 // A partial bit doesn't count, we still have to scroll to see the
958 if (heightCount
+ m_topOfSheet
+ m_horizontalLabelHeight
> (ch
-horizScrollBarHeight
))
967 if (m_totalGridWidth
+ vertScrollBarWidth
<= cw
)
970 m_hScrollBar
->Show(FALSE
);
976 m_hScrollBar
->Show(TRUE
);
979 if (m_totalGridHeight
+ horizScrollBarHeight
<= ch
)
982 m_vScrollBar
->Show(FALSE
);
988 m_vScrollBar
->Show(TRUE
);
991 UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
993 vertScrollBarWidth
= m_scrollWidth
;
994 horizScrollBarHeight
= m_scrollWidth
;
995 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
996 vertScrollBarWidth
= 0;
997 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
998 horizScrollBarHeight
= 0;
1002 int nCols
= GetCols();
1003 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetPosition(), wxMax(noHorizSteps
, 1), (noHorizSteps
== 0) ? 1 : nCols
, wxMax(noHorizSteps
, 1));
1005 m_hScrollBar
->SetSize(m_leftOfSheet
, ch
- m_scrollWidth
-2,
1006 cw
- vertScrollBarWidth
- m_leftOfSheet
, m_scrollWidth
);
1011 int nRows
= GetRows();
1013 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetPosition(), wxMax(noVertSteps
, 1), (noVertSteps
== 0) ? 1 : nRows
, wxMax(noVertSteps
, 1));
1014 m_vScrollBar
->SetSize(cw
- m_scrollWidth
, m_topOfSheet
,
1015 m_scrollWidth
, ch
- m_topOfSheet
- horizScrollBarHeight
);
1019 void wxGenericGrid::OnSize(wxSizeEvent
& WXUNUSED(event
) )
1021 if (!m_vScrollBar
|| !m_hScrollBar
)
1027 GetClientSize(&cw
, &ch
);
1029 if (m_editCreated
&& m_editingPanel
&& GetTextItem() && GetTextItem()->IsShown())
1031 m_editingPanel
->SetSize(0, 0, cw
, m_editControlPosition
.height
+ m_editControlPosition
.y
+ 2);
1032 GetTextItem()->SetSize(m_editControlPosition
.x
, m_editControlPosition
.y
,
1033 cw
- m_editControlPosition
.x
, m_editControlPosition
.height
);
1037 bool wxGenericGrid::CellHitTest(int x
, int y
, int *row
, int *col
)
1039 // Find the selected cell and call OnSelectCell
1040 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1041 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1043 // Calculate the cell number from x and y
1044 x
-= (m_verticalLabelWidth
+ m_leftOfSheet
);
1045 y
-= (m_topOfSheet
+ m_horizontalLabelHeight
);
1049 // Now we need to do a hit test for which row we're on
1050 int currentHeight
= 0;
1051 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1053 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1058 currentHeight
+= m_rowHeights
[i
];
1061 // Now we need to do a hit test for which column we're on
1062 int currentWidth
= 0;
1063 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1065 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1070 currentWidth
+= m_colWidths
[i
];
1077 bool wxGenericGrid::LabelSashHitTest(int x
, int y
, int *orientation
, int *rowOrCol
, int *startPos
)
1082 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= m_topOfSheet
&&
1083 x
<= m_rightOfSheet
&& y
<= (m_topOfSheet
+ m_horizontalLabelHeight
))
1085 // We may be on a column label sash.
1086 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1087 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1089 if (x
>= (currentWidth
+ m_colWidths
[i
] - tolerance
) && x
<= (currentWidth
+ m_colWidths
[i
] + tolerance
))
1091 *orientation
= wxHORIZONTAL
;
1093 *startPos
= currentWidth
;
1096 currentWidth
+= m_colWidths
[i
];
1100 else if (x
>= m_leftOfSheet
&& y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1101 x
<= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
<= m_bottomOfSheet
)
1103 // We may be on a row label sash.
1104 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1105 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1107 if (y
>= (currentHeight
+ m_rowHeights
[i
] - tolerance
) && y
<= (currentHeight
+ m_rowHeights
[i
] + tolerance
))
1109 *orientation
= wxVERTICAL
;
1111 *startPos
= currentHeight
;
1114 currentHeight
+= m_rowHeights
[i
];
1121 bool wxGenericGrid::LabelHitTest(int x
, int y
, int *row
, int *col
)
1123 // Find the selected label
1124 if (x
>= m_leftOfSheet
&& y
>= m_topOfSheet
&&
1125 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1127 // Calculate the cell number from x and y
1133 // Now we need to do a hit test for which row we're on
1134 int currentHeight
= m_horizontalLabelHeight
;
1135 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1137 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1142 currentHeight
+= m_rowHeights
[i
];
1144 if (y
>= 0 && y
<= m_horizontalLabelHeight
)
1149 // Now we need to do a hit test for which column we're on
1150 int currentWidth
= m_verticalLabelWidth
;
1151 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1153 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1158 currentWidth
+= m_colWidths
[i
];
1160 if (x
>= 0 && x
<= m_verticalLabelWidth
)
1165 if ((*col
== -1) || (*row
== -1))
1173 void wxGenericGrid::OnMouseEvent(wxMouseEvent
& ev
)
1177 wxClientDC
dc(this);
1181 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1183 OnSelectCellImplementation(& dc
, row
, col
);
1184 OnCellLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1186 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1188 OnLabelLeftClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1192 else if (ev
.Dragging() && ev
.LeftIsDown())
1194 switch (m_dragStatus
)
1196 case wxGRID_DRAG_NONE
:
1199 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &m_dragRowOrCol
, &m_dragStartPosition
))
1201 if (orientation
== wxHORIZONTAL
)
1203 m_dragStatus
= wxGRID_DRAG_LEFT_RIGHT
;
1204 SetCursor(*m_horizontalSashCursor
);
1205 m_dragLastPosition
= (int)ev
.GetX();
1209 m_dragStatus
= wxGRID_DRAG_UP_DOWN
;
1210 SetCursor(*m_verticalSashCursor
);
1211 m_dragLastPosition
= (int)ev
.GetY();
1213 wxClientDC
dc(this);
1215 dc
.SetLogicalFunction(wxINVERT
);
1216 if (orientation
== wxHORIZONTAL
)
1217 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1219 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1226 case wxGRID_DRAG_LEFT_RIGHT
:
1228 wxClientDC
dc(this);
1230 dc
.SetLogicalFunction(wxINVERT
);
1231 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1233 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1236 m_dragLastPosition
= (int)ev
.GetX();
1237 SetCursor(*m_horizontalSashCursor
);
1240 case wxGRID_DRAG_UP_DOWN
:
1242 wxClientDC
dc(this);
1244 dc
.SetLogicalFunction(wxINVERT
);
1245 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1247 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1250 m_dragLastPosition
= (int)ev
.GetY();
1251 SetCursor(*m_verticalSashCursor
);
1256 else if (ev
.Moving())
1258 int rowOrCol
, orientation
, startPos
;
1259 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &rowOrCol
, &startPos
))
1261 if (orientation
== wxHORIZONTAL
)
1262 SetCursor(*m_horizontalSashCursor
);
1264 SetCursor(*m_verticalSashCursor
);
1267 SetCursor(*wxSTANDARD_CURSOR
);
1269 else if (ev
.LeftUp())
1271 switch (m_dragStatus
)
1273 case wxGRID_DRAG_LEFT_RIGHT
:
1275 wxClientDC
dc(this);
1277 dc
.SetLogicalFunction(wxINVERT
);
1278 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1279 dc
.SetLogicalFunction(wxCOPY
);
1283 if (ev
.GetX() > m_dragStartPosition
)
1285 m_colWidths
[m_dragRowOrCol
] = (short)(ev
.GetX() - m_dragStartPosition
);
1290 SetCursor(*wxSTANDARD_CURSOR
);
1292 GetClientSize(&cw
, &ch
);
1297 case wxGRID_DRAG_UP_DOWN
:
1299 wxClientDC
dc(this);
1301 dc
.SetLogicalFunction(wxINVERT
);
1302 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1303 dc
.SetLogicalFunction(wxCOPY
);
1307 if (ev
.GetY() > m_dragStartPosition
)
1309 m_rowHeights
[m_dragRowOrCol
] = (short)(ev
.GetY() - m_dragStartPosition
);
1314 SetCursor(*wxSTANDARD_CURSOR
);
1318 m_dragStatus
= wxGRID_DRAG_NONE
;
1320 else if (ev
.RightDown())
1323 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1325 OnCellRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1327 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1329 OnLabelRightClick(row
, col
, (int)ev
.GetX(), (int)ev
.GetY(), ev
.ControlDown(), ev
.ShiftDown());
1334 void wxGenericGrid::OnSelectCellImplementation(wxDC
*dc
, int row
, int col
)
1336 m_wCursorColumn
= col
;
1339 OnChangeSelectionLabel();
1341 SetGridClippingRegion(dc
);
1343 // Remove the highlight from the old cell
1344 if (m_currentRectVisible
)
1347 // Highlight the new cell and copy its content to the edit control
1348 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
1349 wxGridCell
*cell
= GetCell(m_wCursorRow
, m_wCursorColumn
);
1352 if ( cell
->GetTextValue().IsNull() )
1353 m_textItem
->SetValue("");
1355 m_textItem
->SetValue(cell
->GetTextValue());
1358 SetGridClippingRegion(dc
);
1360 // Why isn't this needed for Windows??
1361 // Probably because of the SetValue??
1362 // Arrrrrgh. This isn't needed anywhere, of course. RR.
1364 // HighlightCell(dc);
1366 dc
->DestroyClippingRegion();
1368 OnSelectCell(row
, col
);
1371 wxGridCell
*wxGenericGrid::OnCreateCell(void)
1373 return new wxGridCell(this);
1376 void wxGenericGrid::OnChangeLabels(void)
1380 for (i
= 0; i
< m_totalRows
; i
++)
1382 sprintf(buf
, "%d", i
+1);
1383 SetLabelValue(wxVERTICAL
, buf
, i
);
1385 // A...Z,AA...ZZ,AAA...ZZZ, etc.
1386 for (i
= 0; i
< m_totalCols
; i
++)
1389 int noTimes
= (i
/26 + 1);
1390 int ch
= (i
% 26) + 65;
1392 for (j
= 0; j
< noTimes
; j
++)
1395 sprintf(buf2
, "%c", (char)ch
);
1398 SetLabelValue(wxHORIZONTAL
, buf
, i
);
1402 void wxGenericGrid::OnChangeSelectionLabel(void)
1407 wxString
rowLabel(GetLabelValue(wxVERTICAL
, GetCursorRow()));
1408 wxString
colLabel(GetLabelValue(wxHORIZONTAL
, GetCursorColumn()));
1410 wxString newLabel
= colLabel
+ rowLabel
;
1411 if ((newLabel
.Length() > 0) && (newLabel
.Length() <= 8) && GetTextItem())
1413 // GetTextItem()->SetLabel(newLabel);
1417 void wxGenericGrid::HighlightCell(wxDC
*dc
)
1419 dc
->SetLogicalFunction(wxINVERT
);
1422 dc
->DrawLine( m_currentRect
.x
+ 1,
1423 m_currentRect
.y
+ 1,
1424 m_currentRect
.x
+ m_currentRect
.width
- 1,
1425 m_currentRect
.y
+ 1);
1427 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1428 m_currentRect
.y
+ 1,
1429 m_currentRect
.x
+ m_currentRect
.width
- 1,
1430 m_currentRect
.y
+m_currentRect
.height
- 1 );
1432 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1433 m_currentRect
.y
+ m_currentRect
.height
- 1,
1434 m_currentRect
.x
+ 1,
1435 m_currentRect
.y
+ m_currentRect
.height
- 1);
1437 dc
->DrawLine( m_currentRect
.x
+ 1,
1438 m_currentRect
.y
+ m_currentRect
.height
- 1,
1439 m_currentRect
.x
+ 1,
1440 m_currentRect
.y
+ 1);
1442 dc
->SetLogicalFunction(wxCOPY
);
1445 void wxGenericGrid::DrawCellText(void)
1447 if (!m_currentRectVisible
)
1450 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1454 static char szEdit
[300];
1456 wxClientDC
dc(this);
1459 SetGridClippingRegion(& dc
);
1461 dc
.SetBackgroundMode(wxTRANSPARENT
);
1462 dc
.SetBrush(*cell
->GetBackgroundBrush());
1464 strcpy(szEdit
, m_textItem
->GetValue());
1467 rect
= m_currentRect
;
1473 DrawTextRect(& dc
, " ", &rect
, wxLEFT
);
1474 DrawTextRect(& dc
, szEdit
, &rect
, cell
->GetAlignment());
1476 dc
.DestroyClippingRegion();
1478 dc
.SetBackgroundMode(wxSOLID
);
1483 void wxGenericGrid::SetCurrentRect(int Row
, int Column
, int canvasW
, int canvasH
)
1485 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1487 for (i
= m_scrollPosX
; i
< Column
; i
++)
1488 currentWidth
+= m_colWidths
[i
];
1490 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1491 for (i
= m_scrollPosY
; i
< Row
; i
++)
1492 currentHeight
+= m_rowHeights
[i
];
1494 m_currentRect
.x
= currentWidth
;
1495 m_currentRect
.y
= currentHeight
;
1496 m_currentRect
.width
= m_colWidths
? (m_colWidths
[Column
]) : 0;
1497 m_currentRect
.height
= m_rowHeights
? (m_rowHeights
[Row
]) : 0;
1499 if (Row
< m_scrollPosY
|| Column
< m_scrollPosX
)
1500 m_currentRectVisible
= FALSE
;
1501 else if ((canvasW
!= -1 && canvasH
!= -1) && (m_currentRect
.x
> canvasW
|| m_currentRect
.y
> canvasH
))
1502 m_currentRectVisible
= FALSE
;
1503 else m_currentRectVisible
= TRUE
;
1506 static bool wxRectIntersection(wxRectangle
*rect1
, wxRectangle
*rect2
, wxRectangle
*rect3
)
1508 int x2_1
= rect1
->x
+ rect1
->width
;
1509 int y2_1
= rect1
->y
+ rect1
->height
;
1511 int x2_2
= rect2
->x
+ rect2
->width
;
1512 int y2_2
= rect2
->y
+ rect2
->height
;
1516 // Check for intersection
1517 if ((rect1
->x
> x2_2
) || (rect2
->x
> x2_1
) ||
1518 (rect1
->y
> y2_2
) || (rect2
->y
> y2_1
))
1521 rect3
->x
= rect3
->y
= rect3
->width
= rect3
->height
= 0;
1525 if (rect1
->x
> rect2
->x
)
1526 rect3
->x
= rect1
->x
;
1528 rect3
->x
= rect2
->x
;
1529 if (rect1
->y
> rect2
->y
)
1530 rect3
->y
= rect1
->y
;
1532 rect3
->y
= rect2
->y
;
1543 rect3
->width
= (int)(x2_3
- rect3
->x
);
1544 rect3
->height
= (int)(y2_3
- rect3
->y
);
1548 void wxGenericGrid::DrawTextRect(wxDC
*dc
, const wxString
& text
, wxRectangle
*rect
, int flag
)
1552 // Ultimately, this functionality should be built into wxWindows,
1553 // and optimized for each platform. E.g. on Windows, use DrawText
1554 // passing a clipping rectangle, so that the wxWindows clipping region
1555 // does not have to be used to implement this.
1557 // If we're already clipping, we need to find the intersection
1558 // between current clipping area and text clipping area.
1560 wxRectangle clipRect
;
1561 wxRectangle clipRect2
;
1562 long clipX
, clipY
, clipW
, clipH
;
1563 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1564 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1565 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1567 bool alreadyClipping
= TRUE
;
1569 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1571 alreadyClipping
= FALSE
;
1572 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1573 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1577 // Find intersection.
1578 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1582 if (alreadyClipping
)
1583 dc
->DestroyClippingRegion();
1585 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1586 long textWidth
, textHeight
;
1588 dc
->GetTextExtent(text
, &textWidth
, &textHeight
);
1596 x
= (rect
->x
+ rect
->width
- textWidth
- 1.0);
1597 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1602 x
= (rect
->x
+ (rect
->width
- textWidth
)/2.0);
1603 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1609 x
= (rect
->x
+ 1.0);
1610 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1614 dc
->DrawText(text
, (long)x
, (long)y
);
1616 dc
->DestroyClippingRegion();
1618 // Restore old clipping
1619 if (alreadyClipping
)
1620 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1625 void wxGenericGrid::DrawBitmapRect(wxDC
*dc
, wxBitmap
*bitmap
, wxRectangle
*rect
, int flag
)
1629 // Ultimately, this functionality should be built into wxWindows,
1630 // and optimized for each platform. E.g. on Windows, use DrawText
1631 // passing a clipping rectangle, so that the wxWindows clipping region
1632 // does not have to be used to implement this.
1634 // If we're already clipping, we need to find the intersection
1635 // between current clipping area and text clipping area.
1637 wxRectangle clipRect
;
1638 wxRectangle clipRect2
;
1639 long clipX
, clipY
, clipW
, clipH
;
1640 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1641 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1642 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1644 bool alreadyClipping
= TRUE
;
1646 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1648 alreadyClipping
= FALSE
;
1649 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1650 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1654 // Find intersection.
1655 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1659 if (alreadyClipping
)
1660 dc
->DestroyClippingRegion();
1662 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1663 float bitmapWidth
, bitmapHeight
;
1665 bitmapWidth
= bitmap
->GetWidth();
1666 bitmapHeight
= bitmap
->GetHeight();
1674 x
= (long)(rect
->x
+ rect
->width
- bitmapWidth
- 1);
1675 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1680 x
= (long)(rect
->x
+ (rect
->width
- bitmapWidth
)/2.0);
1681 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1687 x
= (long)(rect
->x
+ 1);
1688 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1693 dcTemp
.SelectObject(*bitmap
);
1695 dc
->Blit( (long)x
, (long)y
, (long)bitmapWidth
, (long)bitmapHeight
, &dcTemp
, 0, 0);
1696 dcTemp
.SelectObject(wxNullBitmap
);
1698 dc
->DestroyClippingRegion();
1700 // Restore old clipping
1701 if (alreadyClipping
)
1702 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1707 void wxGenericGrid::OnActivate(bool active
)
1711 // Edit control should always have the focus
1712 if (GetTextItem() && GetEditable())
1714 GetTextItem()->SetFocus();
1715 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1717 GetTextItem()->SetValue(cell
->GetTextValue());
1722 void wxGenericGrid::SetCellValue(const wxString
& val
, int row
, int col
)
1724 wxGridCell
*cell
= GetCell(row
, col
);
1727 cell
->SetTextValue(val
);
1729 RefreshCell(row
, col
, TRUE
);
1733 void wxGenericGrid::RefreshCell(int row
, int col
, bool setText
)
1735 // Don't refresh within a pair of batch brackets
1736 if (GetBatchCount() > 0)
1740 GetClientSize(&cw
, &ch
);
1742 SetCurrentRect(row
, col
, cw
, ch
);
1743 if (m_currentRectVisible
)
1745 wxGridCell
*cell
= GetCell(row
, col
);
1747 bool currentPos
= FALSE
;
1748 if (row
== m_wCursorRow
&& col
== m_wCursorColumn
&& GetTextItem() && GetTextItem()->IsShown() && setText
)
1750 GetTextItem()->SetValue(cell
->GetTextValue());
1753 // Gets refreshed anyway in MSW
1758 wxClientDC
dc(this);
1760 DrawCellBackground(& dc
, &m_currentRect
, row
, col
);
1761 DrawCellValue(& dc
, &m_currentRect
, row
, col
);
1767 wxString
& wxGenericGrid::GetCellValue(int row
, int col
)
1769 static wxString
emptyString("");
1771 wxGridCell
*cell
= GetCell(row
, col
);
1773 return cell
->GetTextValue();
1778 void wxGenericGrid::SetColumnWidth(int col
, int width
)
1780 if (col
<= m_totalCols
)
1781 m_colWidths
[col
] = width
;
1784 int wxGenericGrid::GetColumnWidth(int col
)
1786 if (col
<= m_totalCols
)
1787 return m_colWidths
[col
];
1792 void wxGenericGrid::SetRowHeight(int row
, int height
)
1794 if (row
<= m_totalRows
)
1795 m_rowHeights
[row
] = height
;
1798 int wxGenericGrid::GetRowHeight(int row
)
1800 if (row
<= m_totalRows
)
1801 return m_rowHeights
[row
];
1806 void wxGenericGrid::SetLabelSize(int orientation
, int sz
)
1808 if (orientation
== wxHORIZONTAL
)
1809 m_horizontalLabelHeight
= sz
;
1811 m_verticalLabelWidth
= sz
;
1813 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1816 int wxGenericGrid::GetLabelSize(int orientation
)
1818 if (orientation
== wxHORIZONTAL
)
1819 return m_horizontalLabelHeight
;
1821 return m_verticalLabelWidth
;
1824 wxGridCell
*wxGenericGrid::GetLabelCell(int orientation
, int pos
)
1826 if (orientation
== wxHORIZONTAL
)
1828 if (m_colLabelCells
&& pos
< m_totalCols
)
1829 return m_colLabelCells
[pos
];
1831 return (wxGridCell
*) NULL
;
1835 if (m_rowLabelCells
&& pos
< m_totalRows
)
1836 return m_rowLabelCells
[pos
];
1838 return (wxGridCell
*) NULL
;
1842 void wxGenericGrid::SetLabelValue(int orientation
, const wxString
& val
, int pos
)
1844 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1846 cell
->SetTextValue(val
);
1849 wxString
& wxGenericGrid::GetLabelValue(int orientation
, int pos
)
1851 static wxString emptyString
= "";
1852 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1854 return cell
->GetTextValue();
1859 void wxGenericGrid::SetLabelAlignment(int orientation
, int align
)
1861 if (orientation
== wxHORIZONTAL
)
1862 m_horizontalLabelAlignment
= align
;
1864 m_verticalLabelAlignment
= align
;
1866 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1869 int wxGenericGrid::GetLabelAlignment(int orientation
)
1871 if (orientation
== wxHORIZONTAL
)
1872 return m_horizontalLabelAlignment
;
1874 return m_verticalLabelAlignment
;
1877 void wxGenericGrid::SetLabelTextColour(const wxColour
& colour
)
1879 m_labelTextColour
= colour
;
1883 void wxGenericGrid::SetLabelBackgroundColour(const wxColour
& colour
)
1885 m_labelBackgroundColour
= colour
;
1886 m_labelBackgroundBrush
= wxTheBrushList
->FindOrCreateBrush(m_labelBackgroundColour
, wxSOLID
);
1889 void wxGenericGrid::SetEditable(bool edit
)
1894 int controlW
, controlH
;
1895 m_textItem
->GetSize(&controlW
, &controlH
);
1896 m_editControlPosition
.height
= controlH
;
1898 m_topOfSheet
= m_editControlPosition
.x
+ controlH
+ 2;
1901 m_editingPanel
->Show(TRUE
);
1902 m_textItem
->Show(TRUE
);
1903 m_textItem
->SetFocus();
1911 m_textItem
->Show(FALSE
);
1912 m_editingPanel
->Show(FALSE
);
1916 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1919 GetClientSize(&cw
, &ch
);
1924 int m_scrollWidth = 16;
1925 GetClientSize(&cw, &ch);
1928 m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
1929 m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
1933 void wxGenericGrid::SetCellAlignment(int flag
, int row
, int col
)
1935 wxGridCell
*cell
= GetCell(row
, col
);
1937 cell
->SetAlignment(flag
);
1940 int wxGenericGrid::GetCellAlignment(int row
, int col
)
1942 wxGridCell
*cell
= GetCell(row
, col
);
1944 return cell
->GetAlignment();
1946 return m_cellAlignment
;
1949 void wxGenericGrid::SetCellAlignment(int flag
)
1951 m_cellAlignment
= flag
;
1953 for (i
= 0; i
< GetRows(); i
++)
1954 for (j
= 0; j
< GetCols(); j
++)
1956 GetCell(i
, j
)->SetAlignment(flag
);
1959 int wxGenericGrid::GetCellAlignment(void)
1961 return m_cellAlignment
;
1964 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& col
)
1966 m_cellBackgroundColour
= col
;
1968 for (i
= 0; i
< GetRows(); i
++)
1969 for (j
= 0; j
< GetCols(); j
++)
1971 GetCell(i
, j
)->SetBackgroundColour(col
);
1974 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& val
, int row
, int col
)
1976 wxGridCell
*cell
= GetCell(row
, col
);
1979 cell
->SetBackgroundColour(val
);
1980 RefreshCell(row
, col
);
1984 wxColour
& wxGenericGrid::GetCellBackgroundColour(int row
, int col
)
1986 wxGridCell
*cell
= GetCell(row
, col
);
1988 return cell
->GetBackgroundColour();
1990 return m_cellBackgroundColour
;
1993 void wxGenericGrid::SetCellTextColour(const wxColour
& val
, int row
, int col
)
1995 wxGridCell
*cell
= GetCell(row
, col
);
1998 cell
->SetTextColour(val
);
1999 RefreshCell(row
, col
);
2003 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
, int row
, int col
)
2005 wxGridCell
*cell
= GetCell(row
, col
);
2009 RefreshCell(row
, col
);
2013 wxFont
*wxGenericGrid::GetCellTextFont(int row
, int col
)
2015 wxGridCell
*cell
= GetCell(row
, col
);
2017 return cell
->GetFont();
2019 return m_cellTextFont
;
2022 wxColour
& wxGenericGrid::GetCellTextColour(int row
, int col
)
2024 wxGridCell
*cell
= GetCell(row
, col
);
2026 return cell
->GetTextColour();
2028 return m_cellTextColour
;
2031 void wxGenericGrid::SetCellTextColour(const wxColour
& val
)
2033 m_cellTextColour
= val
;
2035 for (i
= 0; i
< GetRows(); i
++)
2036 for (j
= 0; j
< GetCols(); j
++)
2038 GetCell(i
, j
)->SetTextColour(val
);
2041 void wxGenericGrid::SetCellTextFont(wxFont
*fnt
)
2043 m_cellTextFont
= fnt
;
2045 for (i
= 0; i
< GetRows(); i
++)
2046 for (j
= 0; j
< GetCols(); j
++)
2048 GetCell(i
, j
)->SetFont(fnt
);
2051 void wxGenericGrid::SetCellBitmap(wxBitmap
*bitmap
, int row
, int col
)
2053 wxGridCell
*cell
= GetCell(row
, col
);
2056 cell
->SetCellBitmap(bitmap
);
2057 RefreshCell(row
, col
);
2061 wxBitmap
*wxGenericGrid::GetCellBitmap(int row
, int col
)
2063 wxGridCell
*cell
= GetCell(row
, col
);
2066 return cell
->GetCellBitmap();
2069 return (wxBitmap
*) NULL
;
2072 bool wxGenericGrid::InsertCols(int pos
, int n
, bool updateLabels
)
2074 if (pos
> m_totalCols
)
2078 return CreateGrid(1, n
);
2083 for (i
= 0; i
< m_totalRows
; i
++)
2085 wxGridCell
**cols
= m_gridCells
[i
];
2086 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
+ n
];
2087 for (j
= 0; j
< pos
; j
++)
2088 newCols
[j
] = cols
[j
];
2089 for (j
= pos
; j
< pos
+ n
; j
++)
2090 newCols
[j
] = new wxGridCell(this);
2091 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2092 newCols
[j
] = cols
[j
- n
];
2095 m_gridCells
[i
] = newCols
;
2099 short *newColWidths
= new short[m_totalCols
+ n
];
2100 for (j
= 0; j
< pos
; j
++)
2101 newColWidths
[j
] = m_colWidths
[j
];
2102 for (j
= pos
; j
< pos
+ n
; j
++)
2103 newColWidths
[j
] = wxGRID_DEFAULT_CELL_WIDTH
;
2104 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2105 newColWidths
[j
] = m_colWidths
[j
- n
];
2106 delete[] m_colWidths
;
2107 m_colWidths
= newColWidths
;
2110 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
+ n
];
2111 for (j
= 0; j
< pos
; j
++)
2112 newLabels
[j
] = m_colLabelCells
[j
];
2113 for (j
= pos
; j
< pos
+ n
; j
++)
2114 newLabels
[j
] = new wxGridCell(this);
2115 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2116 newLabels
[j
] = m_colLabelCells
[j
- n
];
2118 delete[] m_colLabelCells
;
2119 m_colLabelCells
= newLabels
;
2131 bool wxGenericGrid::InsertRows(int pos
, int n
, bool updateLabels
)
2133 if (pos
> m_totalRows
)
2137 return CreateGrid(n
, 1);
2142 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
+ n
];
2145 for (i
= 0; i
< pos
; i
++)
2146 rows
[i
] = m_gridCells
[i
];
2148 for (i
= pos
; i
< pos
+ n
; i
++)
2150 rows
[i
] = new wxGridCell
*[m_totalCols
];
2151 for (j
= 0; j
< m_totalCols
; j
++)
2152 rows
[i
][j
] = new wxGridCell(this);
2155 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2156 rows
[i
] = m_gridCells
[i
- n
];
2158 delete[] m_gridCells
;
2162 short *newRowHeights
= new short[m_totalRows
+ n
];
2163 for (i
= 0; i
< pos
; i
++)
2164 newRowHeights
[i
] = m_rowHeights
[i
];
2165 for (i
= pos
; i
< pos
+ n
; i
++)
2166 newRowHeights
[i
] = wxGRID_DEFAULT_CELL_HEIGHT
;
2167 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2168 newRowHeights
[i
] = m_rowHeights
[i
- n
];
2169 delete[] m_rowHeights
;
2170 m_rowHeights
= newRowHeights
;
2173 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
+ n
];
2174 for (i
= 0; i
< pos
; i
++)
2175 newLabels
[i
] = m_rowLabelCells
[i
];
2176 for (i
= pos
; i
< pos
+ n
; i
++)
2177 newLabels
[i
] = new wxGridCell(this);
2178 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2179 newLabels
[i
] = m_rowLabelCells
[i
- n
];
2181 delete[] m_rowLabelCells
;
2182 m_rowLabelCells
= newLabels
;
2194 bool wxGenericGrid::AppendCols(int n
, bool updateLabels
)
2196 return InsertCols(GetCols(), n
, updateLabels
);
2199 bool wxGenericGrid::AppendRows(int n
, bool updateLabels
)
2201 return InsertRows(GetRows(), n
, updateLabels
);
2204 bool wxGenericGrid::DeleteRows(int pos
, int n
, bool updateLabels
)
2206 if (pos
> m_totalRows
)
2213 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
- n
];
2216 for (i
= 0; i
< pos
; i
++)
2217 rows
[i
] = m_gridCells
[i
];
2219 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2220 rows
[i
-n
] = m_gridCells
[i
];
2222 delete[] m_gridCells
;
2226 short *newRowHeights
= new short[m_totalRows
- n
];
2227 for (i
= 0; i
< pos
; i
++)
2228 newRowHeights
[i
] = m_rowHeights
[i
];
2229 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2230 newRowHeights
[i
-n
] = m_rowHeights
[i
];
2231 delete[] m_rowHeights
;
2232 m_rowHeights
= newRowHeights
;
2235 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
- n
];
2236 for (i
= 0; i
< pos
; i
++)
2237 newLabels
[i
] = m_rowLabelCells
[i
];
2238 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2239 newLabels
[i
-n
] = m_rowLabelCells
[i
];
2241 delete[] m_rowLabelCells
;
2242 m_rowLabelCells
= newLabels
;
2253 bool wxGenericGrid::DeleteCols(int pos
, int n
, bool updateLabels
)
2255 if (pos
+ n
> m_totalCols
)
2263 for (i
= 0; i
< m_totalRows
; i
++)
2265 wxGridCell
**cols
= m_gridCells
[i
];
2266 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
- n
];
2267 for (j
= 0; j
< pos
; j
++)
2268 newCols
[j
] = cols
[j
];
2269 for (j
= pos
; j
< pos
+ n
; j
++)
2271 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2272 newCols
[j
-n
] = cols
[j
];
2275 m_gridCells
[i
] = newCols
;
2279 short *newColWidths
= new short[m_totalCols
- n
];
2280 for (j
= 0; j
< pos
; j
++)
2281 newColWidths
[j
] = m_colWidths
[j
];
2282 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2283 newColWidths
[j
-n
] = m_colWidths
[j
];
2284 delete[] m_colWidths
;
2285 m_colWidths
= newColWidths
;
2288 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
- n
];
2289 for (j
= 0; j
< pos
; j
++)
2290 newLabels
[j
] = m_colLabelCells
[j
];
2291 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2292 newLabels
[j
-n
] = m_colLabelCells
[j
];
2294 delete[] m_colLabelCells
;
2295 m_colLabelCells
= newLabels
;
2306 void wxGenericGrid::SetGridCursor(int row
, int col
)
2308 if (row
>= m_totalRows
|| col
>= m_totalCols
)
2311 if (row
== GetCursorRow() && col
== GetCursorColumn())
2314 wxClientDC
dc(this);
2317 SetGridClippingRegion(& dc
);
2319 if (m_currentRectVisible
)
2320 HighlightCell(& dc
);
2323 m_wCursorColumn
= col
;
2326 GetClientSize(&cw
, &ch
);
2328 SetCurrentRect(row
, col
, cw
, ch
);
2330 if (m_currentRectVisible
)
2331 HighlightCell(& dc
);
2333 dc
.DestroyClippingRegion();
2341 wxGridCell::wxGridCell(wxGenericGrid
*window
)
2343 cellBitmap
= (wxBitmap
*) NULL
;
2344 font
= (wxFont
*) NULL
;
2345 backgroundBrush
= (wxBrush
*) NULL
;
2347 textColour
= window
->GetCellTextColour();
2349 textColour
.Set(0,0,0);
2351 backgroundColour
= window
->GetCellBackgroundColour();
2353 backgroundColour
.Set(255,255,255);
2356 font
= window
->GetCellTextFont();
2358 font
= wxTheFontList
->FindOrCreateFont(12, wxSWISS
, wxNORMAL
, wxNORMAL
);
2360 SetBackgroundColour(backgroundColour
);
2363 alignment
= window
->GetCellAlignment();
2368 wxGridCell::~wxGridCell(void)
2372 void wxGridCell::SetBackgroundColour(const wxColour
& colour
)
2374 backgroundColour
= colour
;
2375 backgroundBrush
= wxTheBrushList
->FindOrCreateBrush(backgroundColour
, wxSOLID
);
2378 void wxGenericGrid::OnText(wxCommandEvent
& WXUNUSED(ev
) )
2380 wxGenericGrid
*grid
= this;
2381 wxGridCell
*cell
= grid
->GetCell(grid
->GetCursorRow(), grid
->GetCursorColumn());
2382 if (cell
&& grid
->CurrentCellVisible())
2384 cell
->SetTextValue(grid
->GetTextItem()->GetValue());
2385 wxClientDC
dc(grid
);
2388 grid
->SetGridClippingRegion(& dc
);
2389 grid
->DrawCellBackground(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2390 grid
->DrawCellValue(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2391 grid
->HighlightCell(& dc
);
2392 dc
.DestroyClippingRegion();
2395 grid
->OnCellChange(grid
->GetCursorRow(), grid
->GetCursorColumn());
2397 // grid->DrawCellText();
2401 void wxGenericGrid::OnGridScroll(wxScrollEvent
& ev
)
2403 static bool inScroll
= FALSE
;
2409 wxGenericGrid
*win
= this;
2411 bool change
= FALSE
;
2413 if (ev
.GetEventObject() == win
->GetHorizScrollBar())
2415 change
= (ev
.GetPosition() != m_scrollPosX
);
2416 win
->SetScrollPosX(ev
.GetPosition());
2420 change
= (ev
.GetPosition() != m_scrollPosY
);
2421 win
->SetScrollPosY(ev
.GetPosition());
2424 win
->UpdateDimensions();
2426 win
->SetCurrentRect(win
->GetCursorRow(), win
->GetCursorColumn());
2428 // Because rows and columns can be arbitrary sizes,
2429 // the scrollbars will need to be adjusted to reflect the
2433 if (change
) win
->Refresh(FALSE
);