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
)
46 IMPLEMENT_DYNAMIC_CLASS(wxGridEvent
, wxEvent
)
48 BEGIN_EVENT_TABLE(wxGenericGrid
, wxPanel
)
49 EVT_SIZE(wxGenericGrid::OnSize
)
50 EVT_PAINT(wxGenericGrid::OnPaint
)
51 EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground
)
52 EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent
)
53 EVT_TEXT(wxGRID_TEXT_CTRL
, wxGenericGrid::OnText
)
54 EVT_COMMAND_SCROLL(wxGRID_HSCROLL
, wxGenericGrid::OnGridScroll
)
55 EVT_COMMAND_SCROLL(wxGRID_VSCROLL
, wxGenericGrid::OnGridScroll
)
57 // default wxGridEvent handlers
58 EVT_GRID_SELECT_CELL(wxGenericGrid::_OnSelectCell
)
59 EVT_GRID_CREATE_CELL(wxGenericGrid::_OnCreateCell
)
60 EVT_GRID_CHANGE_LABELS(wxGenericGrid::_OnChangeLabels
)
61 EVT_GRID_CHANGE_SEL_LABEL(wxGenericGrid::_OnChangeSelectionLabel
)
62 EVT_GRID_CELL_CHANGE(wxGenericGrid::_OnCellChange
)
63 EVT_GRID_CELL_LCLICK(wxGenericGrid::_OnCellLeftClick
)
64 EVT_GRID_CELL_RCLICK(wxGenericGrid::_OnCellRightClick
)
65 EVT_GRID_LABEL_LCLICK(wxGenericGrid::_OnLabelLeftClick
)
66 EVT_GRID_LABEL_RCLICK(wxGenericGrid::_OnLabelRightClick
)
73 wxGenericGrid::wxGenericGrid(void)
76 m_hScrollBar
= (wxScrollBar
*) NULL
;
77 m_vScrollBar
= (wxScrollBar
*) NULL
;
78 m_cellTextColour
= *wxBLACK
;
79 m_cellBackgroundColour
= *wxWHITE
;
80 m_labelTextColour
= *wxBLACK
;
81 // m_labelBackgroundColour = *wxLIGHT_GREY;
82 m_labelBackgroundColour
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
83 m_labelBackgroundBrush
= wxNullBrush
;
84 m_labelTextFont
= wxNullFont
;
85 m_cellTextFont
= wxNullFont
;
86 m_textItem
= (wxTextCtrl
*) NULL
;
87 m_currentRectVisible
= FALSE
;
89 #if defined(__WIN95__)
90 m_scrollWidth
= wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X
);
94 m_dragStatus
= wxGRID_DRAG_NONE
;
96 m_dragStartPosition
= 0;
97 m_dragLastPosition
= 0;
98 m_divisionPen
= wxNullPen
;
99 m_leftOfSheet
= wxGRID_DEFAULT_SHEET_LEFT
;
100 m_topOfSheet
= wxGRID_DEFAULT_SHEET_TOP
;
101 m_cellHeight
= wxGRID_DEFAULT_CELL_HEIGHT
;
102 m_totalGridWidth
= 0;
103 m_totalGridHeight
= 0;
104 m_colWidths
= (short *) NULL
;
105 m_rowHeights
= (short *) NULL
;
106 m_verticalLabelWidth
= wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH
;
107 m_horizontalLabelHeight
= wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT
;
108 m_verticalLabelAlignment
= wxCENTRE
;
109 m_horizontalLabelAlignment
= wxCENTRE
;
110 m_editControlPosition
.x
= wxGRID_DEFAULT_EDIT_X
;
111 m_editControlPosition
.y
= wxGRID_DEFAULT_EDIT_Y
;
112 m_editControlPosition
.width
= wxGRID_DEFAULT_EDIT_WIDTH
;
113 m_editControlPosition
.height
= wxGRID_DEFAULT_EDIT_HEIGHT
;
118 m_editCreated
= FALSE
;
121 m_gridCells
= (wxGridCell
***) NULL
;
122 m_rowLabelCells
= (wxGridCell
**) NULL
;
123 m_colLabelCells
= (wxGridCell
**) NULL
;
124 m_textItem
= (wxTextCtrl
*) NULL
;
127 bool wxGenericGrid::Create(wxWindow
*parent
, wxWindowID id
, const wxPoint
& pos
, const wxSize
& size
,
128 long style
, const wxString
& name
)
131 m_editingPanel
= (wxPanel
*) NULL
;
132 m_hScrollBar
= (wxScrollBar
*) NULL
;
133 m_vScrollBar
= (wxScrollBar
*) NULL
;
134 m_cellTextColour
= *wxBLACK
;
135 m_cellBackgroundColour
= *wxWHITE
;
136 m_labelTextColour
= *wxBLACK
;
137 // m_labelBackgroundColour = *wxLIGHT_GREY;
138 m_labelBackgroundColour
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
139 m_labelBackgroundBrush
= wxNullBrush
;
140 m_labelTextFont
= * wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxBOLD
);
141 m_cellTextFont
= * wxTheFontList
->FindOrCreateFont(10, wxSWISS
, wxNORMAL
, wxNORMAL
);
142 m_textItem
= (wxTextCtrl
*) NULL
;
143 m_currentRectVisible
= FALSE
;
145 #if defined(__WIN95__)
146 m_scrollWidth
= wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X
);
150 m_dragStatus
= wxGRID_DRAG_NONE
;
152 m_dragStartPosition
= 0;
153 m_dragLastPosition
= 0;
154 m_divisionPen
= * wxThePenList
->FindOrCreatePen("LIGHT GREY", 1, wxSOLID
);
155 m_doubleBufferingBitmap
= (wxBitmap
*) NULL
;
157 if (!m_horizontalSashCursor
.Ok())
159 m_horizontalSashCursor
= wxCursor(wxCURSOR_SIZEWE
);
160 m_verticalSashCursor
= wxCursor(wxCURSOR_SIZENS
);
163 SetLabelBackgroundColour(m_labelBackgroundColour
);
165 m_leftOfSheet
= wxGRID_DEFAULT_SHEET_LEFT
;
166 m_topOfSheet
= wxGRID_DEFAULT_SHEET_TOP
;
167 m_cellHeight
= wxGRID_DEFAULT_CELL_HEIGHT
;
168 m_totalGridWidth
= 0;
169 m_totalGridHeight
= 0;
170 m_colWidths
= (short *) NULL
;
171 m_rowHeights
= (short *) NULL
;
173 m_verticalLabelWidth
= wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH
;
174 m_horizontalLabelHeight
= wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT
;
175 m_verticalLabelAlignment
= wxCENTRE
;
176 m_horizontalLabelAlignment
= wxCENTRE
;
177 m_editControlPosition
.x
= wxGRID_DEFAULT_EDIT_X
;
178 m_editControlPosition
.y
= wxGRID_DEFAULT_EDIT_Y
;
179 m_editControlPosition
.width
= wxGRID_DEFAULT_EDIT_WIDTH
;
180 m_editControlPosition
.height
= wxGRID_DEFAULT_EDIT_HEIGHT
;
188 /* Store the rect. coordinates for the current cell */
189 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
191 m_editCreated
= FALSE
;
195 m_gridCells
= (wxGridCell
***) NULL
;
196 m_rowLabelCells
= (wxGridCell
**) NULL
;
197 m_colLabelCells
= (wxGridCell
**) NULL
;
198 m_textItem
= (wxTextCtrl
*) NULL
;
200 wxPanel::Create(parent
, id
, pos
, size
, style
, name
);
202 m_editingPanel
= new wxPanel(this);
204 m_textItem
= new wxTextCtrl(m_editingPanel
, wxGRID_TEXT_CTRL
, "",
205 wxPoint(m_editControlPosition
.x
, m_editControlPosition
.y
), wxSize(m_editControlPosition
.width
, -1),
207 m_textItem
->Show(TRUE
);
208 m_textItem
->SetFocus();
209 int controlW
, controlH
;
211 m_textItem
->GetSize(&controlW
, &controlH
);
212 m_editControlPosition
.height
= controlH
;
214 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
216 m_editCreated
= TRUE
;
218 m_hScrollBar
= new wxScrollBar(this, wxGRID_HSCROLL
, wxPoint(0, 0), wxSize(20, 100), wxHORIZONTAL
);
219 m_vScrollBar
= new wxScrollBar(this, wxGRID_VSCROLL
, wxPoint(0, 0), wxSize(100, 20), wxVERTICAL
);
224 wxGenericGrid::~wxGenericGrid(void)
229 void wxGenericGrid::ClearGrid(void)
234 for (i
= 0; i
< m_totalRows
; i
++)
236 for (j
= 0; j
< m_totalCols
; j
++)
237 if (m_gridCells
[i
][j
])
238 delete m_gridCells
[i
][j
];
239 delete[] m_gridCells
[i
];
241 delete[] m_gridCells
;
242 m_gridCells
= (wxGridCell
***) NULL
;
245 delete[] m_colWidths
;
246 m_colWidths
= (short *) NULL
;
248 delete[] m_rowHeights
;
249 m_rowHeights
= (short *) NULL
;
253 for (i
= 0; i
< m_totalRows
; i
++)
254 delete m_rowLabelCells
[i
];
255 delete[] m_rowLabelCells
;
256 m_rowLabelCells
= (wxGridCell
**) NULL
;
260 for (i
= 0; i
< m_totalCols
; i
++)
261 delete m_colLabelCells
[i
];
262 delete[] m_colLabelCells
;
263 m_colLabelCells
= (wxGridCell
**) NULL
;
265 if (m_doubleBufferingBitmap
)
267 delete m_doubleBufferingBitmap
;
268 m_doubleBufferingBitmap
= (wxBitmap
*) NULL
;
272 bool wxGenericGrid::CreateGrid(int nRows
, int nCols
, wxString
**cellValues
, short *widths
,
273 short defaultWidth
, short defaultHeight
)
279 m_colWidths
= new short[nCols
];
280 m_rowHeights
= new short[nRows
];
281 for (i
= 0; i
< nCols
; i
++)
283 m_colWidths
[i
] = widths
[i
];
285 m_colWidths
[i
] = defaultWidth
;
286 for (i
= 0; i
< nRows
; i
++)
287 m_rowHeights
[i
] = defaultHeight
;
289 m_gridCells
= new wxGridCell
**[nRows
];
291 for (i
= 0; i
< nRows
; i
++)
292 m_gridCells
[i
] = new wxGridCell
*[nCols
];
294 for (i
= 0; i
< nRows
; i
++)
295 for (j
= 0; j
< nCols
; j
++)
298 //m_gridCells[i][j] = OnCreateCell();
299 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CREATE_CELL
, this, i
, j
);
300 GetEventHandler()->ProcessEvent(g_evt
);
301 m_gridCells
[i
][j
] = g_evt
.m_cell
;
302 m_gridCells
[i
][j
]->SetTextValue(cellValues
[i
][j
]);
305 m_gridCells
[i
][j
] = (wxGridCell
*) NULL
;
307 m_rowLabelCells
= new wxGridCell
*[nRows
];
308 for (i
= 0; i
< nRows
; i
++)
309 m_rowLabelCells
[i
] = new wxGridCell(this);
310 m_colLabelCells
= new wxGridCell
*[nCols
];
311 for (i
= 0; i
< nCols
; i
++)
312 m_colLabelCells
[i
] = new wxGridCell(this);
314 m_wCursorRow
= m_wCursorColumn
= 0;
315 SetCurrentRect(0, 0);
317 // Need to determine various dimensions
321 int objectSizeX
= m_totalCols
;
323 int viewLengthX
= m_totalCols
;
326 m_hScrollBar->SetViewLength(viewLengthX);
327 m_hScrollBar->SetObjectLength(objectSizeX);
328 m_hScrollBar->SetPageSize(pageSizeX);
330 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetThumbPosition(), pageSizeX
, objectSizeX
, viewLengthX
);
332 int objectSizeY
= m_totalRows
;
334 int viewLengthY
= m_totalRows
;
337 m_vScrollBar->SetViewLength(viewLengthY);
338 m_vScrollBar->SetObjectLength(objectSizeY);
339 m_vScrollBar->SetPageSize(pageSizeY);
342 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetThumbPosition(), pageSizeY
, objectSizeY
, viewLengthY
);
347 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS
, this);
348 GetEventHandler()->ProcessEvent(g_evt
);
350 //OnChangeSelectionLabel();
351 wxGridEvent
g_evt2(GetId(), wxEVT_GRID_CHANGE_SEL_LABEL
, this);
352 GetEventHandler()->ProcessEvent(g_evt2
);
357 // Need to determine various dimensions
358 void wxGenericGrid::UpdateDimensions(void)
360 int canvasWidth
, canvasHeight
;
361 GetSize(&canvasWidth
, &canvasHeight
);
363 if (m_editCreated
&& m_editable
)
365 int controlW
, controlH
;
366 GetTextItem()->GetSize(&controlW
, &controlH
);
367 m_topOfSheet
= m_editControlPosition
.y
+ controlH
+ 2;
371 m_rightOfSheet
= m_leftOfSheet
+ m_verticalLabelWidth
;
373 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
375 if (m_rightOfSheet
> canvasWidth
)
378 m_rightOfSheet
+= m_colWidths
[i
];
380 m_bottomOfSheet
= m_topOfSheet
+ m_horizontalLabelHeight
;
381 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
383 if (m_bottomOfSheet
> canvasHeight
)
386 m_bottomOfSheet
+= m_rowHeights
[i
];
389 m_totalGridWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
390 for (i
= 0; i
< m_totalCols
; i
++)
392 m_totalGridWidth
+= m_colWidths
[i
];
394 m_totalGridHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
395 for (i
= 0; i
< m_totalRows
; i
++)
397 m_totalGridHeight
+= m_rowHeights
[i
];
401 wxGridCell
*wxGenericGrid::GetCell(int row
, int col
) const
404 return (wxGridCell
*) NULL
;
406 if ((row
>= m_totalRows
) || (col
>= m_totalCols
))
407 return (wxGridCell
*) NULL
;
409 wxGridCell
*cell
= m_gridCells
[row
][col
];
412 // m_gridCells[row][col] = OnCreateCell();
413 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CREATE_CELL
, (wxGenericGrid
*) this, row
, col
);
414 GetEventHandler()->ProcessEvent(g_evt
);
415 m_gridCells
[row
][col
] = g_evt
.m_cell
;
416 return m_gridCells
[row
][col
];
422 void wxGenericGrid::SetGridClippingRegion(wxDC
*dc
)
424 int m_scrollWidthHoriz
= 0;
425 int m_scrollWidthVert
= 0;
427 GetClientSize(&cw
, &ch
);
429 if (m_hScrollBar
&& m_hScrollBar
->IsShown())
430 m_scrollWidthHoriz
= m_scrollWidth
;
431 if (m_vScrollBar
&& m_vScrollBar
->IsShown())
432 m_scrollWidthVert
= m_scrollWidth
;
434 // Don't paint over the scrollbars
435 dc
->SetClippingRegion(m_leftOfSheet
, m_topOfSheet
,
436 cw
- m_scrollWidthVert
- m_leftOfSheet
, ch
- m_scrollWidthHoriz
- m_topOfSheet
);
439 void wxGenericGrid::OnPaint(wxPaintEvent
& WXUNUSED(event
))
442 GetClientSize(&w
, &h
);
444 bool useDoubleBuffering
= (bool) wxUSE_DOUBLE_BUFFERING
;
445 if (useDoubleBuffering
)
447 // Reuse the old bitmap if possible
449 if (!m_doubleBufferingBitmap
||
450 (m_doubleBufferingBitmap
->GetWidth() < w
|| m_doubleBufferingBitmap
->GetHeight() < h
))
452 if (m_doubleBufferingBitmap
)
453 delete m_doubleBufferingBitmap
;
454 m_doubleBufferingBitmap
= new wxBitmap(w
, h
);
456 if (!m_doubleBufferingBitmap
|| !m_doubleBufferingBitmap
->Ok())
458 // If we couldn't create a new bitmap, perhaps because resources were low,
459 // then don't complain, just don't double-buffer
460 if (m_doubleBufferingBitmap
)
461 delete m_doubleBufferingBitmap
;
462 m_doubleBufferingBitmap
= (wxBitmap
*) NULL
;
463 useDoubleBuffering
= FALSE
;
467 if (useDoubleBuffering
)
469 wxPaintDC
paintDC(this);
470 wxMemoryDC
dc(& paintDC
);
471 dc
.SelectObject(* m_doubleBufferingBitmap
);
475 int vertScrollBarWidth
= m_scrollWidth
;
476 int horizScrollBarHeight
= m_scrollWidth
;
477 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
478 vertScrollBarWidth
= 0;
479 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
480 horizScrollBarHeight
= 0;
482 paintDC
.Blit(m_leftOfSheet
, m_topOfSheet
, w
- vertScrollBarWidth
- m_leftOfSheet
, h
- horizScrollBarHeight
- m_topOfSheet
,
483 &dc
, m_leftOfSheet
, m_topOfSheet
, wxCOPY
);
485 dc
.SelectObject(wxNullBitmap
);
494 void wxGenericGrid::PaintGrid(wxDC
& dc
)
497 dc
.SetOptimization(FALSE
);
499 SetGridClippingRegion(& dc
);
501 DrawLabelAreas(& dc
);
503 DrawEditableArea(& dc
);
504 DrawColumnLabels(& dc
);
509 /* Hilight present cell */
510 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
511 if (m_currentRectVisible
)
514 dc
.DestroyClippingRegion();
515 dc
.SetOptimization(TRUE
);
519 // Erase (some of) the background.
520 // Currently, a Windows-only optimisation.
521 void wxGenericGrid::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
) )
525 dc
.SetOptimization(FALSE
);
528 GetClientSize(& w
, & h
);
529 dc
.SetBrush(*wxLIGHT_GREY_BRUSH
);
530 dc
.SetPen(*wxLIGHT_GREY_PEN
);
532 if (m_hScrollBar
&& m_hScrollBar
->IsShown() && m_vScrollBar
&& m_vScrollBar
->IsShown())
534 dc
.DrawRectangle(w
- m_scrollWidth
, h
- m_scrollWidth
, m_scrollWidth
, m_scrollWidth
);
537 dc
.SetOptimization(TRUE
);
542 void wxGenericGrid::DrawLabelAreas(wxDC
*dc
)
545 GetClientSize(&cw
, &ch
);
547 dc
->SetPen(*wxTRANSPARENT_PEN
);
548 // dc->SetBrush(*dc->GetBackground());
550 // Should blank out any area which isn't going to be painted over.
551 // dc->DrawRectangle(m_leftOfSheet, m_bottomOfSheet, cw - m_leftOfSheet, ch - m_bottomOfSheet);
552 // dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet);
554 // Paint the label areas
555 dc
->SetBrush(m_labelBackgroundBrush
);
556 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1);
557 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, cw
-m_leftOfSheet
, m_horizontalLabelHeight
+ 1);
558 // dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1);
559 dc
->DrawRectangle(m_leftOfSheet
, m_topOfSheet
, m_verticalLabelWidth
+ 1, ch
-m_topOfSheet
);
562 void wxGenericGrid::DrawEditableArea(wxDC
*dc
)
565 GetClientSize(&cw
, &ch
);
567 dc
->SetPen(*wxTRANSPARENT_PEN
);
568 dc
->SetBrush(*wxTheBrushList
->FindOrCreateBrush(m_cellBackgroundColour
, wxSOLID
));
569 // dc->DrawRectangle(m_leftOfSheet+m_verticalLabelWidth, m_topOfSheet+m_horizontalLabelHeight,
570 // m_rightOfSheet-(m_leftOfSheet+m_verticalLabelWidth) + 1, m_bottomOfSheet - (m_topOfSheet+m_horizontalLabelHeight) + 1);
571 dc
->DrawRectangle(m_leftOfSheet
+m_verticalLabelWidth
, m_topOfSheet
+m_horizontalLabelHeight
,
572 cw
-(m_leftOfSheet
+m_verticalLabelWidth
), ch
- (m_topOfSheet
+m_horizontalLabelHeight
));
575 void wxGenericGrid::DrawGridLines(wxDC
*dc
)
578 GetClientSize(&cw
, &ch
);
582 if (m_divisionPen
.Ok())
584 dc
->SetPen(m_divisionPen
);
586 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
588 // Draw horizontal grey lines for cells
589 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
591 if (heightCount
> ch
)
595 dc
->DrawLine(m_leftOfSheet
, heightCount
,
598 heightCount
+= m_rowHeights
[i
];
603 if (m_verticalLabelWidth
> 0)
605 dc
->SetPen(*wxBLACK_PEN
);
607 // Draw horizontal black lines for row labels
608 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
609 for (i
= m_scrollPosY
; i
< (m_totalRows
+1); i
++)
611 if (heightCount
> ch
)
615 dc
->DrawLine(m_leftOfSheet
, heightCount
,
616 m_verticalLabelWidth
, heightCount
);
618 heightCount
+= m_rowHeights
[i
];
621 // Draw a black vertical line for row number cells
622 dc
->DrawLine(m_leftOfSheet
+ m_verticalLabelWidth
, m_topOfSheet
,
623 m_leftOfSheet
+ m_verticalLabelWidth
, ch
);
624 // First vertical line
625 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
, m_leftOfSheet
, ch
);
627 dc
->SetPen(*wxWHITE_PEN
);
629 // Draw highlights on row labels
630 heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
631 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
633 if (heightCount
> ch
)
637 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
638 m_verticalLabelWidth
, heightCount
+1);
639 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
640 m_leftOfSheet
+1, heightCount
+ m_rowHeights
[i
] - 1);
641 heightCount
+= m_rowHeights
[i
];
644 // Last one - down to the floor.
645 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
646 m_verticalLabelWidth
, heightCount
+1);
647 dc
->DrawLine(m_leftOfSheet
+1, heightCount
+1,
648 m_leftOfSheet
+1, ch
);
652 if (m_divisionPen
.Ok())
654 dc
->SetPen(m_divisionPen
);
656 // Draw vertical grey lines for cells
657 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
658 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
664 // Skip the first one
665 if (i
!= m_scrollPosX
)
667 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
668 widthCount
, m_bottomOfSheet
);
670 widthCount
+= m_colWidths
[i
];
674 dc
->DrawLine(widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
,
675 widthCount
, m_bottomOfSheet
);
678 dc
->SetPen(*wxBLACK_PEN
);
680 // Draw two black horizontal lines for column number cells
682 m_leftOfSheet
, m_topOfSheet
,
684 dc
->DrawLine(m_leftOfSheet
, m_topOfSheet
+ m_horizontalLabelHeight
,
685 cw
, m_topOfSheet
+ m_horizontalLabelHeight
);
687 if (m_horizontalLabelHeight
> 0)
689 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
691 // Draw black vertical lines for column number cells
692 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
698 dc
->DrawLine(widthCount
, m_topOfSheet
,
699 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
700 widthCount
+= m_colWidths
[i
];
705 dc
->DrawLine(widthCount
, m_topOfSheet
,
706 widthCount
, m_topOfSheet
+ m_horizontalLabelHeight
);
709 dc
->SetPen(*wxWHITE_PEN
);
710 widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
712 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
718 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
719 widthCount
+m_colWidths
[i
], m_topOfSheet
+1);
720 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
721 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
722 widthCount
+= m_colWidths
[i
];
725 // Last one - to the right side of the canvas.
726 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
728 dc
->DrawLine(widthCount
+1, m_topOfSheet
+1,
729 widthCount
+1, m_topOfSheet
+m_horizontalLabelHeight
);
734 void wxGenericGrid::DrawColumnLabels(wxDC
*dc
)
737 GetClientSize(&cw
, &ch
);
739 if (m_horizontalLabelHeight
== 0)
745 // Draw letters for columns
746 rect
.y
= m_topOfSheet
+ 1;
747 rect
.height
= m_horizontalLabelHeight
- 1;
749 dc
->SetTextBackground(m_labelBackgroundColour
);
750 dc
->SetBackgroundMode(wxTRANSPARENT
);
751 // dc->SetTextForeground(m_labelTextColour);
753 int widthCount
= m_leftOfSheet
+ m_verticalLabelWidth
;
754 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
760 rect
.x
= 1 + widthCount
;
761 rect
.width
= m_colWidths
[i
];
762 DrawColumnLabel(dc
, &rect
, i
);
764 widthCount
+= m_colWidths
[i
];
769 void wxGenericGrid::DrawColumnLabel(wxDC
*dc
, wxRect
*rect
, int col
)
771 wxGridCell
*cell
= GetLabelCell(wxHORIZONTAL
, col
);
780 dc
->SetTextForeground(GetLabelTextColour());
781 dc
->SetFont(GetLabelTextFont());
782 if ( !cell
->GetTextValue().IsNull() )
783 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxHORIZONTAL
));
787 void wxGenericGrid::DrawRowLabels(wxDC
*dc
)
790 GetClientSize(&cw
, &ch
);
792 if (m_verticalLabelWidth
== 0)
798 // Draw numbers for rows
799 rect
.x
= m_leftOfSheet
;
800 rect
.width
= m_verticalLabelWidth
;
802 int heightCount
= m_topOfSheet
+ m_horizontalLabelHeight
;
804 dc
->SetTextBackground(m_labelBackgroundColour
);
805 dc
->SetBackgroundMode(wxTRANSPARENT
);
807 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
809 if (heightCount
> ch
)
813 rect
.y
= 1 + heightCount
;
814 rect
.height
= m_rowHeights
[i
];
815 DrawRowLabel(dc
, &rect
, i
);
817 heightCount
+= m_rowHeights
[i
];
822 void wxGenericGrid::DrawRowLabel(wxDC
*dc
, wxRect
*rect
, int row
)
824 wxGridCell
*cell
= GetLabelCell(wxVERTICAL
, row
);
833 dc
->SetTextForeground(GetLabelTextColour());
834 dc
->SetFont(GetLabelTextFont());
835 if ( !cell
->GetTextValue().IsNull() )
836 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, GetLabelAlignment(wxVERTICAL
));
840 void wxGenericGrid::DrawCells(wxDC
*dc
)
843 GetClientSize(&cw
, &ch
);
847 // Draw value corresponding to each cell
848 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
850 for (j
= m_scrollPosX
; j
< m_totalCols
; j
++)
852 SetCurrentRect(i
, j
, cw
, ch
);
853 if (m_currentRectVisible
)
855 DrawCellBackground(dc
, &m_currentRect
, i
, j
);
856 DrawCellValue(dc
, &m_currentRect
, i
, j
);
858 if (m_currentRect
.x
> cw
)
861 if (m_currentRect
.y
> ch
)
864 dc
->SetBackgroundMode(wxSOLID
);
865 dc
->SetPen(*wxBLACK_PEN
);
868 void wxGenericGrid::DrawCellBackground(wxDC
*dc
, wxRect
*rect
, int row
, int col
)
870 wxGridCell
*cell
= GetCell(row
, col
);
873 dc
->SetBrush(cell
->GetBackgroundBrush());
874 dc
->SetPen(*wxTRANSPARENT_PEN
);
876 #if 0 // In wxWin 2.0 the dc code is exact. RR.
878 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
880 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
, rect
->height
);
884 dc
->DrawRectangle(rect
->x
+1, rect
->y
+1, rect
->width
-1, rect
->height
-1);
886 dc
->SetPen(*wxBLACK_PEN
);
890 void wxGenericGrid::DrawCellValue(wxDC
*dc
, wxRect
*rect
, int row
, int col
)
892 wxGridCell
*cell
= GetCell(row
, col
);
895 wxBitmap
*bitmap
= cell
->GetCellBitmap();
905 DrawBitmapRect(dc
, bitmap
, &rect2
, cell
->GetAlignment());
909 dc
->SetBackgroundMode(wxTRANSPARENT
);
910 dc
->SetTextForeground(cell
->GetTextColour());
911 dc
->SetFont(cell
->GetFont());
913 if ( !cell
->GetTextValue().IsNull() )
914 DrawTextRect(dc
, cell
->GetTextValue(), &rect2
, cell
->GetAlignment());
919 void wxGenericGrid::AdjustScrollbars(void)
922 GetClientSize(&cw
, &ch
);
924 // We find the view size by seeing how many rows/cols fit on
926 // BUT... this means that the scrollbar should be adjusted every time
927 // it's scrolled, as well as when sized, because with variable size rows/cols,
928 // the number of rows/col visible on the view differs according to what bit
929 // you're looking at. The object length is always the same, but the
930 // view length differs.
932 // Since this may not be known until the end of this function, we should probably call AdjustScrollbars
934 int vertScrollBarWidth
= m_scrollWidth
;
935 int horizScrollBarHeight
= m_scrollWidth
;
936 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
937 vertScrollBarWidth
= 0;
938 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
939 horizScrollBarHeight
= 0;
941 int noHorizSteps
= 0;
944 if (m_totalGridWidth
+ vertScrollBarWidth
<= cw
)
953 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
955 widthCount
+= m_colWidths
[i
];
956 // A partial bit doesn't count, we still have to scroll to see the
958 if (widthCount
+ m_leftOfSheet
+ m_verticalLabelWidth
> (cw
-vertScrollBarWidth
))
967 if (m_totalGridHeight
+ horizScrollBarHeight
<= ch
)
976 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
978 heightCount
+= m_rowHeights
[i
];
979 // A partial bit doesn't count, we still have to scroll to see the
981 if (heightCount
+ m_topOfSheet
+ m_horizontalLabelHeight
> (ch
-horizScrollBarHeight
))
990 if (m_totalGridWidth
+ vertScrollBarWidth
<= cw
)
993 m_hScrollBar
->Show(FALSE
);
999 m_hScrollBar
->Show(TRUE
);
1002 if (m_totalGridHeight
+ horizScrollBarHeight
<= ch
)
1005 m_vScrollBar
->Show(FALSE
);
1011 m_vScrollBar
->Show(TRUE
);
1014 UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
1016 vertScrollBarWidth
= m_scrollWidth
;
1017 horizScrollBarHeight
= m_scrollWidth
;
1018 if (m_vScrollBar
&& !m_vScrollBar
->IsShown())
1019 vertScrollBarWidth
= 0;
1020 if (m_hScrollBar
&& !m_hScrollBar
->IsShown())
1021 horizScrollBarHeight
= 0;
1025 int nCols
= GetCols();
1026 m_hScrollBar
->SetScrollbar(m_hScrollBar
->GetThumbPosition(), wxMax(noHorizSteps
, 1), (noHorizSteps
== 0) ? 1 : nCols
, wxMax(noHorizSteps
, 1));
1028 m_hScrollBar
->SetSize(m_leftOfSheet
, ch
- m_scrollWidth
-2,
1029 cw
- vertScrollBarWidth
- m_leftOfSheet
, m_scrollWidth
);
1034 int nRows
= GetRows();
1036 m_vScrollBar
->SetScrollbar(m_vScrollBar
->GetThumbPosition(), wxMax(noVertSteps
, 1), (noVertSteps
== 0) ? 1 : nRows
, wxMax(noVertSteps
, 1));
1037 m_vScrollBar
->SetSize(cw
- m_scrollWidth
, m_topOfSheet
,
1038 m_scrollWidth
, ch
- m_topOfSheet
- horizScrollBarHeight
);
1042 void wxGenericGrid::OnSize(wxSizeEvent
& WXUNUSED(event
) )
1044 if (!m_vScrollBar
|| !m_hScrollBar
)
1050 GetClientSize(&cw
, &ch
);
1052 if (m_editCreated
&& m_editingPanel
&& GetTextItem() && GetTextItem()->IsShown())
1054 m_editingPanel
->SetSize(0, 0, cw
, m_editControlPosition
.height
+ m_editControlPosition
.y
+ 2);
1055 GetTextItem()->SetSize(m_editControlPosition
.x
, m_editControlPosition
.y
,
1056 cw
- m_editControlPosition
.x
, m_editControlPosition
.height
);
1060 bool wxGenericGrid::CellHitTest(int x
, int y
, int *row
, int *col
)
1062 // Find the selected cell and call OnSelectCell
1063 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1064 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1066 // Calculate the cell number from x and y
1067 x
-= (m_verticalLabelWidth
+ m_leftOfSheet
);
1068 y
-= (m_topOfSheet
+ m_horizontalLabelHeight
);
1072 // Now we need to do a hit test for which row we're on
1073 int currentHeight
= 0;
1074 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1076 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1081 currentHeight
+= m_rowHeights
[i
];
1084 // Now we need to do a hit test for which column we're on
1085 int currentWidth
= 0;
1086 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1088 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1093 currentWidth
+= m_colWidths
[i
];
1100 bool wxGenericGrid::LabelSashHitTest(int x
, int y
, int *orientation
, int *rowOrCol
, int *startPos
)
1105 if (x
>= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
>= m_topOfSheet
&&
1106 x
<= m_rightOfSheet
&& y
<= (m_topOfSheet
+ m_horizontalLabelHeight
))
1108 // We may be on a column label sash.
1109 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1110 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1112 if (x
>= (currentWidth
+ m_colWidths
[i
] - tolerance
) && x
<= (currentWidth
+ m_colWidths
[i
] + tolerance
))
1114 *orientation
= wxHORIZONTAL
;
1116 *startPos
= currentWidth
;
1119 currentWidth
+= m_colWidths
[i
];
1123 else if (x
>= m_leftOfSheet
&& y
>= (m_topOfSheet
+ m_horizontalLabelHeight
) &&
1124 x
<= (m_leftOfSheet
+ m_verticalLabelWidth
) && y
<= m_bottomOfSheet
)
1126 // We may be on a row label sash.
1127 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1128 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1130 if (y
>= (currentHeight
+ m_rowHeights
[i
] - tolerance
) && y
<= (currentHeight
+ m_rowHeights
[i
] + tolerance
))
1132 *orientation
= wxVERTICAL
;
1134 *startPos
= currentHeight
;
1137 currentHeight
+= m_rowHeights
[i
];
1144 bool wxGenericGrid::LabelHitTest(int x
, int y
, int *row
, int *col
)
1146 // Find the selected label
1147 if (x
>= m_leftOfSheet
&& y
>= m_topOfSheet
&&
1148 x
<= m_rightOfSheet
&& y
<= m_bottomOfSheet
)
1150 // Calculate the cell number from x and y
1156 // Now we need to do a hit test for which row we're on
1157 int currentHeight
= m_horizontalLabelHeight
;
1158 for (i
= m_scrollPosY
; i
< m_totalRows
; i
++)
1160 if (y
>= currentHeight
&& y
<= (currentHeight
+ m_rowHeights
[i
]))
1165 currentHeight
+= m_rowHeights
[i
];
1167 if (y
>= 0 && y
<= m_horizontalLabelHeight
)
1172 // Now we need to do a hit test for which column we're on
1173 int currentWidth
= m_verticalLabelWidth
;
1174 for (i
= m_scrollPosX
; i
< m_totalCols
; i
++)
1176 if (x
>= currentWidth
&& x
<= (currentWidth
+ m_colWidths
[i
]))
1181 currentWidth
+= m_colWidths
[i
];
1183 if (x
>= 0 && x
<= m_verticalLabelWidth
)
1188 if ((*col
== -1) || (*row
== -1))
1196 void wxGenericGrid::OnMouseEvent(wxMouseEvent
& ev
)
1200 wxClientDC
dc(this);
1204 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1206 OnSelectCellImplementation(& dc
, row
, col
);
1208 //OnCellLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
1209 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CELL_LCLICK
, this,
1210 row
, col
, (int)ev
.GetX(), (int)ev
.GetY(),
1211 ev
.ControlDown(), ev
.ShiftDown());
1212 GetEventHandler()->ProcessEvent(g_evt
);
1215 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1217 //OnLabelLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
1218 wxGridEvent
g_evt(GetId(), wxEVT_GRID_LABEL_LCLICK
, this,
1219 row
, col
, (int)ev
.GetX(), (int)ev
.GetY(),
1220 ev
.ControlDown(), ev
.ShiftDown());
1221 GetEventHandler()->ProcessEvent(g_evt
);
1226 else if (ev
.Dragging() && ev
.LeftIsDown())
1228 switch (m_dragStatus
)
1230 case wxGRID_DRAG_NONE
:
1233 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &m_dragRowOrCol
, &m_dragStartPosition
))
1235 if (orientation
== wxHORIZONTAL
)
1237 m_dragStatus
= wxGRID_DRAG_LEFT_RIGHT
;
1238 SetCursor(m_horizontalSashCursor
);
1239 m_dragLastPosition
= (int)ev
.GetX();
1243 m_dragStatus
= wxGRID_DRAG_UP_DOWN
;
1244 SetCursor(m_verticalSashCursor
);
1245 m_dragLastPosition
= (int)ev
.GetY();
1247 wxClientDC
dc(this);
1249 dc
.SetLogicalFunction(wxINVERT
);
1250 if (orientation
== wxHORIZONTAL
)
1251 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1253 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1260 case wxGRID_DRAG_LEFT_RIGHT
:
1262 wxClientDC
dc(this);
1264 dc
.SetLogicalFunction(wxINVERT
);
1265 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1267 dc
.DrawLine((int)ev
.GetX(), m_topOfSheet
, (int)ev
.GetX(), m_bottomOfSheet
);
1270 m_dragLastPosition
= (int)ev
.GetX();
1271 SetCursor(m_horizontalSashCursor
);
1274 case wxGRID_DRAG_UP_DOWN
:
1276 wxClientDC
dc(this);
1278 dc
.SetLogicalFunction(wxINVERT
);
1279 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1281 dc
.DrawLine(m_leftOfSheet
, (int)ev
.GetY(), m_rightOfSheet
, (int)ev
.GetY());
1284 m_dragLastPosition
= (int)ev
.GetY();
1285 SetCursor(m_verticalSashCursor
);
1290 else if (ev
.Moving())
1292 int rowOrCol
, orientation
, startPos
;
1293 if (LabelSashHitTest((int)ev
.GetX(), (int)ev
.GetY(), &orientation
, &rowOrCol
, &startPos
))
1295 if (orientation
== wxHORIZONTAL
)
1296 SetCursor(m_horizontalSashCursor
);
1298 SetCursor(m_verticalSashCursor
);
1301 SetCursor(*wxSTANDARD_CURSOR
);
1303 else if (ev
.LeftUp())
1305 switch (m_dragStatus
)
1307 case wxGRID_DRAG_LEFT_RIGHT
:
1309 wxClientDC
dc(this);
1311 dc
.SetLogicalFunction(wxINVERT
);
1312 dc
.DrawLine(m_dragLastPosition
, m_topOfSheet
, m_dragLastPosition
, m_bottomOfSheet
);
1313 dc
.SetLogicalFunction(wxCOPY
);
1317 if (ev
.GetX() > m_dragStartPosition
)
1319 m_colWidths
[m_dragRowOrCol
] = (short)(ev
.GetX() - m_dragStartPosition
);
1324 SetCursor(*wxSTANDARD_CURSOR
);
1326 GetClientSize(&cw
, &ch
);
1331 case wxGRID_DRAG_UP_DOWN
:
1333 wxClientDC
dc(this);
1335 dc
.SetLogicalFunction(wxINVERT
);
1336 dc
.DrawLine(m_leftOfSheet
, m_dragLastPosition
, m_rightOfSheet
, m_dragLastPosition
);
1337 dc
.SetLogicalFunction(wxCOPY
);
1341 if (ev
.GetY() > m_dragStartPosition
)
1343 m_rowHeights
[m_dragRowOrCol
] = (short)(ev
.GetY() - m_dragStartPosition
);
1348 SetCursor(*wxSTANDARD_CURSOR
);
1352 m_dragStatus
= wxGRID_DRAG_NONE
;
1354 else if (ev
.RightDown())
1357 if (CellHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1359 //OnCellRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
1360 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CELL_RCLICK
, this,
1361 row
, col
, (int)ev
.GetX(), (int)ev
.GetY(),
1362 ev
.ControlDown(), ev
.ShiftDown());
1363 GetEventHandler()->ProcessEvent(g_evt
);
1366 if (LabelHitTest((int)ev
.GetX(), (int)ev
.GetY(), &row
, &col
))
1368 //OnLabelRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
1369 wxGridEvent
g_evt(GetId(), wxEVT_GRID_LABEL_RCLICK
, this,
1370 row
, col
, (int)ev
.GetX(), (int)ev
.GetY(),
1371 ev
.ControlDown(), ev
.ShiftDown());
1372 GetEventHandler()->ProcessEvent(g_evt
);
1377 void wxGenericGrid::OnSelectCellImplementation(wxDC
*dc
, int row
, int col
)
1379 m_wCursorColumn
= col
;
1382 //OnChangeSelectionLabel();
1383 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CHANGE_SEL_LABEL
, this);
1384 GetEventHandler()->ProcessEvent(g_evt
);
1386 SetGridClippingRegion(dc
);
1388 // Remove the highlight from the old cell
1389 if (m_currentRectVisible
)
1392 // Highlight the new cell and copy its content to the edit control
1393 SetCurrentRect(m_wCursorRow
, m_wCursorColumn
);
1394 wxGridCell
*cell
= GetCell(m_wCursorRow
, m_wCursorColumn
);
1397 if ( cell
->GetTextValue().IsNull() )
1398 m_textItem
->SetValue("");
1400 m_textItem
->SetValue(cell
->GetTextValue());
1403 SetGridClippingRegion(dc
);
1405 // 1) Why isn't this needed for Windows??
1406 // Probably because of the SetValue?? JS.
1407 // 2) Arrrrrgh. This isn't needed anywhere,
1408 // of course. One hour of debugging... RR.
1410 // HighlightCell(dc);
1412 dc
->DestroyClippingRegion();
1414 //OnSelectCell(row, col);
1415 wxGridEvent
g_evt2(GetId(), wxEVT_GRID_SELECT_CELL
, this, row
, col
);
1416 GetEventHandler()->ProcessEvent(g_evt2
);
1419 wxGridCell
*wxGenericGrid::OnCreateCell(void)
1421 return new wxGridCell(this);
1424 void wxGenericGrid::OnChangeLabels(void)
1428 for (i
= 0; i
< m_totalRows
; i
++)
1430 sprintf(buf
, "%d", i
+1);
1431 SetLabelValue(wxVERTICAL
, buf
, i
);
1433 // A...Z,AA...ZZ,AAA...ZZZ, etc.
1434 for (i
= 0; i
< m_totalCols
; i
++)
1437 int noTimes
= (i
/26 + 1);
1438 int ch
= (i
% 26) + 65;
1440 for (j
= 0; j
< noTimes
; j
++)
1443 sprintf(buf2
, "%c", (char)ch
);
1446 SetLabelValue(wxHORIZONTAL
, buf
, i
);
1450 void wxGenericGrid::OnChangeSelectionLabel(void)
1455 wxString
rowLabel(GetLabelValue(wxVERTICAL
, GetCursorRow()));
1456 wxString
colLabel(GetLabelValue(wxHORIZONTAL
, GetCursorColumn()));
1458 wxString newLabel
= colLabel
+ rowLabel
;
1459 if ((newLabel
.Length() > 0) && (newLabel
.Length() <= 8) && GetTextItem())
1461 // GetTextItem()->SetLabel(newLabel);
1465 void wxGenericGrid::HighlightCell(wxDC
*dc
)
1467 dc
->SetLogicalFunction(wxINVERT
);
1470 dc
->DrawLine( m_currentRect
.x
+ 1,
1471 m_currentRect
.y
+ 1,
1472 m_currentRect
.x
+ m_currentRect
.width
- 1,
1473 m_currentRect
.y
+ 1);
1475 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1476 m_currentRect
.y
+ 1,
1477 m_currentRect
.x
+ m_currentRect
.width
- 1,
1478 m_currentRect
.y
+m_currentRect
.height
- 1 );
1480 dc
->DrawLine( m_currentRect
.x
+ m_currentRect
.width
- 1,
1481 m_currentRect
.y
+ m_currentRect
.height
- 1,
1482 m_currentRect
.x
+ 1,
1483 m_currentRect
.y
+ m_currentRect
.height
- 1);
1485 dc
->DrawLine( m_currentRect
.x
+ 1,
1486 m_currentRect
.y
+ m_currentRect
.height
- 1,
1487 m_currentRect
.x
+ 1,
1488 m_currentRect
.y
+ 1);
1490 dc
->SetLogicalFunction(wxCOPY
);
1493 void wxGenericGrid::DrawCellText(void)
1495 if (!m_currentRectVisible
)
1498 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1502 static char szEdit
[300];
1504 wxClientDC
dc(this);
1507 SetGridClippingRegion(& dc
);
1509 dc
.SetBackgroundMode(wxTRANSPARENT
);
1510 dc
.SetBrush(cell
->GetBackgroundBrush());
1512 strcpy(szEdit
, m_textItem
->GetValue());
1515 rect
= m_currentRect
;
1521 DrawTextRect(& dc
, " ", &rect
, wxLEFT
);
1522 DrawTextRect(& dc
, szEdit
, &rect
, cell
->GetAlignment());
1524 dc
.DestroyClippingRegion();
1526 dc
.SetBackgroundMode(wxSOLID
);
1531 void wxGenericGrid::SetCurrentRect(int Row
, int Column
, int canvasW
, int canvasH
)
1533 int currentWidth
= m_leftOfSheet
+ m_verticalLabelWidth
;
1535 for (i
= m_scrollPosX
; i
< Column
; i
++)
1536 currentWidth
+= m_colWidths
[i
];
1538 int currentHeight
= m_topOfSheet
+ m_horizontalLabelHeight
;
1539 for (i
= m_scrollPosY
; i
< Row
; i
++)
1540 currentHeight
+= m_rowHeights
[i
];
1542 m_currentRect
.x
= currentWidth
;
1543 m_currentRect
.y
= currentHeight
;
1544 m_currentRect
.width
= m_colWidths
? (m_colWidths
[Column
]) : 0;
1545 m_currentRect
.height
= m_rowHeights
? (m_rowHeights
[Row
]) : 0;
1547 if (Row
< m_scrollPosY
|| Column
< m_scrollPosX
)
1548 m_currentRectVisible
= FALSE
;
1549 else if ((canvasW
!= -1 && canvasH
!= -1) && (m_currentRect
.x
> canvasW
|| m_currentRect
.y
> canvasH
))
1550 m_currentRectVisible
= FALSE
;
1551 else m_currentRectVisible
= TRUE
;
1554 static bool wxRectIntersection(wxRect
*rect1
, wxRect
*rect2
, wxRect
*rect3
)
1556 int x2_1
= rect1
->x
+ rect1
->width
;
1557 int y2_1
= rect1
->y
+ rect1
->height
;
1559 int x2_2
= rect2
->x
+ rect2
->width
;
1560 int y2_2
= rect2
->y
+ rect2
->height
;
1564 // Check for intersection
1565 if ((rect1
->x
> x2_2
) || (rect2
->x
> x2_1
) ||
1566 (rect1
->y
> y2_2
) || (rect2
->y
> y2_1
))
1569 rect3
->x
= rect3
->y
= rect3
->width
= rect3
->height
= 0;
1573 if (rect1
->x
> rect2
->x
)
1574 rect3
->x
= rect1
->x
;
1576 rect3
->x
= rect2
->x
;
1577 if (rect1
->y
> rect2
->y
)
1578 rect3
->y
= rect1
->y
;
1580 rect3
->y
= rect2
->y
;
1591 rect3
->width
= (int)(x2_3
- rect3
->x
);
1592 rect3
->height
= (int)(y2_3
- rect3
->y
);
1596 void wxGenericGrid::DrawTextRect(wxDC
*dc
, const wxString
& text
, wxRect
*rect
, int flag
)
1600 // Ultimately, this functionality should be built into wxWindows,
1601 // and optimized for each platform. E.g. on Windows, use DrawText
1602 // passing a clipping rectangle, so that the wxWindows clipping region
1603 // does not have to be used to implement this.
1605 // If we're already clipping, we need to find the intersection
1606 // between current clipping area and text clipping area.
1610 long clipX
, clipY
, clipW
, clipH
;
1611 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1612 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1613 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1615 bool alreadyClipping
= TRUE
;
1617 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1619 alreadyClipping
= FALSE
;
1620 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1621 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1625 // Find intersection.
1626 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1630 if (alreadyClipping
)
1631 dc
->DestroyClippingRegion();
1633 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1634 long textWidth
, textHeight
;
1636 dc
->GetTextExtent(text
, &textWidth
, &textHeight
);
1644 x
= (rect
->x
+ rect
->width
- textWidth
- 1.0);
1645 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1650 x
= (rect
->x
+ (rect
->width
- textWidth
)/2.0);
1651 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1657 x
= (rect
->x
+ 1.0);
1658 y
= (rect
->y
+ (rect
->height
- textHeight
)/2.0);
1662 dc
->DrawText(text
, (long)x
, (long)y
);
1664 dc
->DestroyClippingRegion();
1666 // Restore old clipping
1667 if (alreadyClipping
)
1668 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1673 void wxGenericGrid::DrawBitmapRect(wxDC
*dc
, wxBitmap
*bitmap
, wxRect
*rect
, int flag
)
1677 // Ultimately, this functionality should be built into wxWindows,
1678 // and optimized for each platform. E.g. on Windows, use DrawText
1679 // passing a clipping rectangle, so that the wxWindows clipping region
1680 // does not have to be used to implement this.
1682 // If we're already clipping, we need to find the intersection
1683 // between current clipping area and text clipping area.
1687 long clipX
, clipY
, clipW
, clipH
;
1688 dc
->GetClippingBox(&clipX
, &clipY
, &clipW
, &clipH
);
1689 clipRect
.x
= (int)clipX
; clipRect
.y
= (int)clipY
;
1690 clipRect
.width
= (int)clipW
; clipRect
.height
= (int)clipH
;
1692 bool alreadyClipping
= TRUE
;
1694 if (clipRect
.x
== 0 && clipRect
.y
== 0 && clipRect
.width
== 0 && clipRect
.height
== 0)
1696 alreadyClipping
= FALSE
;
1697 clipRect2
.x
= rect
->x
; clipRect2
.y
= rect
->y
;
1698 clipRect2
.width
= rect
->width
; clipRect2
.height
= rect
->height
;
1702 // Find intersection.
1703 if (!wxRectIntersection(rect
, &clipRect
, &clipRect2
))
1707 if (alreadyClipping
)
1708 dc
->DestroyClippingRegion();
1710 dc
->SetClippingRegion(clipRect2
.x
, clipRect2
.y
, clipRect2
.width
, clipRect2
.height
);
1711 float bitmapWidth
, bitmapHeight
;
1713 bitmapWidth
= bitmap
->GetWidth();
1714 bitmapHeight
= bitmap
->GetHeight();
1722 x
= (long)(rect
->x
+ rect
->width
- bitmapWidth
- 1);
1723 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1728 x
= (long)(rect
->x
+ (rect
->width
- bitmapWidth
)/2.0);
1729 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1735 x
= (long)(rect
->x
+ 1);
1736 y
= (long)(rect
->y
+ (rect
->height
- bitmapHeight
)/2.0);
1741 dcTemp
.SelectObject(*bitmap
);
1743 dc
->Blit( (long)x
, (long)y
, (long)bitmapWidth
, (long)bitmapHeight
, &dcTemp
, 0, 0);
1744 dcTemp
.SelectObject(wxNullBitmap
);
1746 dc
->DestroyClippingRegion();
1748 // Restore old clipping
1749 if (alreadyClipping
)
1750 dc
->SetClippingRegion(clipRect
.x
, clipRect
.y
, clipRect
.width
, clipRect
.height
);
1755 void wxGenericGrid::OnActivate(bool active
)
1759 // Edit control should always have the focus
1760 if (GetTextItem() && GetEditable())
1762 GetTextItem()->SetFocus();
1763 wxGridCell
*cell
= GetCell(GetCursorRow(), GetCursorColumn());
1765 GetTextItem()->SetValue(cell
->GetTextValue());
1770 void wxGenericGrid::SetCellValue(const wxString
& val
, int row
, int col
)
1772 wxGridCell
*cell
= GetCell(row
, col
);
1775 cell
->SetTextValue(val
);
1777 RefreshCell(row
, col
, TRUE
);
1781 void wxGenericGrid::RefreshCell(int row
, int col
, bool setText
)
1783 // Don't refresh within a pair of batch brackets
1784 if (GetBatchCount() > 0)
1788 GetClientSize(&cw
, &ch
);
1790 SetCurrentRect(row
, col
, cw
, ch
);
1791 if (m_currentRectVisible
)
1793 wxGridCell
*cell
= GetCell(row
, col
);
1795 bool currentPos
= FALSE
;
1796 if (row
== m_wCursorRow
&& col
== m_wCursorColumn
&& GetTextItem() && GetTextItem()->IsShown() && setText
)
1798 GetTextItem()->SetValue(cell
->GetTextValue());
1801 // Gets refreshed anyway in MSW
1806 wxClientDC
dc(this);
1808 DrawCellBackground(& dc
, &m_currentRect
, row
, col
);
1809 DrawCellValue(& dc
, &m_currentRect
, row
, col
);
1815 wxString
& wxGenericGrid::GetCellValue(int row
, int col
) const
1817 static wxString
emptyString("");
1819 wxGridCell
*cell
= GetCell(row
, col
);
1821 return cell
->GetTextValue();
1826 void wxGenericGrid::SetColumnWidth(int col
, int width
)
1828 if (col
<= m_totalCols
)
1829 m_colWidths
[col
] = width
;
1832 int wxGenericGrid::GetColumnWidth(int col
) const
1834 if (col
<= m_totalCols
)
1835 return m_colWidths
[col
];
1840 void wxGenericGrid::SetRowHeight(int row
, int height
)
1842 if (row
<= m_totalRows
)
1843 m_rowHeights
[row
] = height
;
1846 int wxGenericGrid::GetRowHeight(int row
) const
1848 if (row
<= m_totalRows
)
1849 return m_rowHeights
[row
];
1854 void wxGenericGrid::SetLabelSize(int orientation
, int sz
)
1856 if (orientation
== wxHORIZONTAL
)
1857 m_horizontalLabelHeight
= sz
;
1859 m_verticalLabelWidth
= sz
;
1861 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1864 int wxGenericGrid::GetLabelSize(int orientation
) const
1866 if (orientation
== wxHORIZONTAL
)
1867 return m_horizontalLabelHeight
;
1869 return m_verticalLabelWidth
;
1872 wxGridCell
*wxGenericGrid::GetLabelCell(int orientation
, int pos
) const
1874 if (orientation
== wxHORIZONTAL
)
1876 if (m_colLabelCells
&& pos
< m_totalCols
)
1877 return m_colLabelCells
[pos
];
1879 return (wxGridCell
*) NULL
;
1883 if (m_rowLabelCells
&& pos
< m_totalRows
)
1884 return m_rowLabelCells
[pos
];
1886 return (wxGridCell
*) NULL
;
1890 void wxGenericGrid::SetLabelValue(int orientation
, const wxString
& val
, int pos
)
1892 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1894 cell
->SetTextValue(val
);
1897 wxString
& wxGenericGrid::GetLabelValue(int orientation
, int pos
) const
1899 static wxString emptyString
= "";
1900 wxGridCell
*cell
= GetLabelCell(orientation
, pos
);
1902 return cell
->GetTextValue();
1907 void wxGenericGrid::SetLabelAlignment(int orientation
, int align
)
1909 if (orientation
== wxHORIZONTAL
)
1910 m_horizontalLabelAlignment
= align
;
1912 m_verticalLabelAlignment
= align
;
1914 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1917 int wxGenericGrid::GetLabelAlignment(int orientation
) const
1919 if (orientation
== wxHORIZONTAL
)
1920 return m_horizontalLabelAlignment
;
1922 return m_verticalLabelAlignment
;
1925 void wxGenericGrid::SetLabelTextColour(const wxColour
& colour
)
1927 m_labelTextColour
= colour
;
1931 void wxGenericGrid::SetLabelBackgroundColour(const wxColour
& colour
)
1933 m_labelBackgroundColour
= colour
;
1934 m_labelBackgroundBrush
= * wxTheBrushList
->FindOrCreateBrush(m_labelBackgroundColour
, wxSOLID
);
1937 void wxGenericGrid::SetEditable(bool edit
)
1942 int controlW
, controlH
;
1943 m_textItem
->GetSize(&controlW
, &controlH
);
1944 m_editControlPosition
.height
= controlH
;
1946 m_topOfSheet
= m_editControlPosition
.x
+ controlH
+ 2;
1949 m_editingPanel
->Show(TRUE
);
1950 m_textItem
->Show(TRUE
);
1951 m_textItem
->SetFocus();
1959 m_textItem
->Show(FALSE
);
1960 m_editingPanel
->Show(FALSE
);
1964 SetCurrentRect(GetCursorRow(), GetCursorColumn());
1967 GetClientSize(&cw
, &ch
);
1972 int m_scrollWidth = 16;
1973 GetClientSize(&cw, &ch);
1976 m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
1977 m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
1981 void wxGenericGrid::SetCellAlignment(int flag
, int row
, int col
)
1983 wxGridCell
*cell
= GetCell(row
, col
);
1985 cell
->SetAlignment(flag
);
1988 int wxGenericGrid::GetCellAlignment(int row
, int col
) const
1990 wxGridCell
*cell
= GetCell(row
, col
);
1992 return cell
->GetAlignment();
1994 return m_cellAlignment
;
1997 void wxGenericGrid::SetCellAlignment(int flag
)
1999 m_cellAlignment
= flag
;
2001 for (i
= 0; i
< GetRows(); i
++)
2002 for (j
= 0; j
< GetCols(); j
++)
2004 GetCell(i
, j
)->SetAlignment(flag
);
2007 int wxGenericGrid::GetCellAlignment(void) const
2009 return m_cellAlignment
;
2012 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& col
)
2014 m_cellBackgroundColour
= col
;
2016 for (i
= 0; i
< GetRows(); i
++)
2017 for (j
= 0; j
< GetCols(); j
++)
2019 GetCell(i
, j
)->SetBackgroundColour(col
);
2022 void wxGenericGrid::SetCellBackgroundColour(const wxColour
& val
, int row
, int col
)
2024 wxGridCell
*cell
= GetCell(row
, col
);
2027 cell
->SetBackgroundColour(val
);
2028 RefreshCell(row
, col
);
2032 wxColour
& wxGenericGrid::GetCellBackgroundColour(int row
, int col
) const
2034 wxGridCell
*cell
= GetCell(row
, col
);
2036 return cell
->GetBackgroundColour();
2038 return (wxColour
&) m_cellBackgroundColour
;
2041 void wxGenericGrid::SetCellTextColour(const wxColour
& val
, int row
, int col
)
2043 wxGridCell
*cell
= GetCell(row
, col
);
2046 cell
->SetTextColour(val
);
2047 RefreshCell(row
, col
);
2051 void wxGenericGrid::SetCellTextFont(const wxFont
& fnt
, int row
, int col
)
2053 wxGridCell
*cell
= GetCell(row
, col
);
2057 RefreshCell(row
, col
);
2061 wxFont
& wxGenericGrid::GetCellTextFont(int row
, int col
) const
2063 wxGridCell
*cell
= GetCell(row
, col
);
2065 return (wxFont
&) cell
->GetFont();
2067 return (wxFont
&) m_cellTextFont
;
2070 wxColour
& wxGenericGrid::GetCellTextColour(int row
, int col
) const
2072 wxGridCell
*cell
= GetCell(row
, col
);
2074 return (wxColour
&) cell
->GetTextColour();
2076 return (wxColour
&) m_cellTextColour
;
2079 void wxGenericGrid::SetCellTextColour(const wxColour
& val
)
2081 m_cellTextColour
= val
;
2083 for (i
= 0; i
< GetRows(); i
++)
2084 for (j
= 0; j
< GetCols(); j
++)
2086 GetCell(i
, j
)->SetTextColour(val
);
2089 void wxGenericGrid::SetCellTextFont(const wxFont
& fnt
)
2091 m_cellTextFont
= fnt
;
2093 for (i
= 0; i
< GetRows(); i
++)
2094 for (j
= 0; j
< GetCols(); j
++)
2096 GetCell(i
, j
)->SetFont(fnt
);
2099 void wxGenericGrid::SetCellBitmap(wxBitmap
*bitmap
, int row
, int col
)
2101 wxGridCell
*cell
= GetCell(row
, col
);
2104 cell
->SetCellBitmap(bitmap
);
2105 RefreshCell(row
, col
);
2109 wxBitmap
*wxGenericGrid::GetCellBitmap(int row
, int col
) const
2111 wxGridCell
*cell
= GetCell(row
, col
);
2114 return cell
->GetCellBitmap();
2117 return (wxBitmap
*) NULL
;
2120 bool wxGenericGrid::InsertCols(int pos
, int n
, bool updateLabels
)
2122 if (pos
> m_totalCols
)
2126 return CreateGrid(1, n
);
2131 for (i
= 0; i
< m_totalRows
; i
++)
2133 wxGridCell
**cols
= m_gridCells
[i
];
2134 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
+ n
];
2135 for (j
= 0; j
< pos
; j
++)
2136 newCols
[j
] = cols
[j
];
2137 for (j
= pos
; j
< pos
+ n
; j
++)
2138 newCols
[j
] = new wxGridCell(this);
2139 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2140 newCols
[j
] = cols
[j
- n
];
2143 m_gridCells
[i
] = newCols
;
2147 short *newColWidths
= new short[m_totalCols
+ n
];
2148 for (j
= 0; j
< pos
; j
++)
2149 newColWidths
[j
] = m_colWidths
[j
];
2150 for (j
= pos
; j
< pos
+ n
; j
++)
2151 newColWidths
[j
] = wxGRID_DEFAULT_CELL_WIDTH
;
2152 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2153 newColWidths
[j
] = m_colWidths
[j
- n
];
2154 delete[] m_colWidths
;
2155 m_colWidths
= newColWidths
;
2158 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
+ n
];
2159 for (j
= 0; j
< pos
; j
++)
2160 newLabels
[j
] = m_colLabelCells
[j
];
2161 for (j
= pos
; j
< pos
+ n
; j
++)
2162 newLabels
[j
] = new wxGridCell(this);
2163 for (j
= pos
+ n
; j
< m_totalCols
+ n
; j
++)
2164 newLabels
[j
] = m_colLabelCells
[j
- n
];
2166 delete[] m_colLabelCells
;
2167 m_colLabelCells
= newLabels
;
2173 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS
, this);
2174 GetEventHandler()->ProcessEvent(g_evt
);
2183 bool wxGenericGrid::InsertRows(int pos
, int n
, bool updateLabels
)
2185 if (pos
> m_totalRows
)
2189 return CreateGrid(n
, 1);
2194 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
+ n
];
2197 for (i
= 0; i
< pos
; i
++)
2198 rows
[i
] = m_gridCells
[i
];
2200 for (i
= pos
; i
< pos
+ n
; i
++)
2202 rows
[i
] = new wxGridCell
*[m_totalCols
];
2203 for (j
= 0; j
< m_totalCols
; j
++)
2204 rows
[i
][j
] = new wxGridCell(this);
2207 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2208 rows
[i
] = m_gridCells
[i
- n
];
2210 delete[] m_gridCells
;
2214 short *newRowHeights
= new short[m_totalRows
+ n
];
2215 for (i
= 0; i
< pos
; i
++)
2216 newRowHeights
[i
] = m_rowHeights
[i
];
2217 for (i
= pos
; i
< pos
+ n
; i
++)
2218 newRowHeights
[i
] = wxGRID_DEFAULT_CELL_HEIGHT
;
2219 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2220 newRowHeights
[i
] = m_rowHeights
[i
- n
];
2221 delete[] m_rowHeights
;
2222 m_rowHeights
= newRowHeights
;
2225 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
+ n
];
2226 for (i
= 0; i
< pos
; i
++)
2227 newLabels
[i
] = m_rowLabelCells
[i
];
2228 for (i
= pos
; i
< pos
+ n
; i
++)
2229 newLabels
[i
] = new wxGridCell(this);
2230 for (i
= pos
+ n
; i
< m_totalRows
+ n
; i
++)
2231 newLabels
[i
] = m_rowLabelCells
[i
- n
];
2233 delete[] m_rowLabelCells
;
2234 m_rowLabelCells
= newLabels
;
2240 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS
, this);
2241 GetEventHandler()->ProcessEvent(g_evt
);
2250 bool wxGenericGrid::AppendCols(int n
, bool updateLabels
)
2252 return InsertCols(GetCols(), n
, updateLabels
);
2255 bool wxGenericGrid::AppendRows(int n
, bool updateLabels
)
2257 return InsertRows(GetRows(), n
, updateLabels
);
2260 bool wxGenericGrid::DeleteRows(int pos
, int n
, bool updateLabels
)
2262 if (pos
> m_totalRows
)
2269 wxGridCell
***rows
= new wxGridCell
**[m_totalRows
- n
];
2272 for (i
= 0; i
< pos
; i
++)
2273 rows
[i
] = m_gridCells
[i
];
2275 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2276 rows
[i
-n
] = m_gridCells
[i
];
2278 delete[] m_gridCells
;
2282 short *newRowHeights
= new short[m_totalRows
- n
];
2283 for (i
= 0; i
< pos
; i
++)
2284 newRowHeights
[i
] = m_rowHeights
[i
];
2285 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2286 newRowHeights
[i
-n
] = m_rowHeights
[i
];
2287 delete[] m_rowHeights
;
2288 m_rowHeights
= newRowHeights
;
2291 wxGridCell
**newLabels
= new wxGridCell
*[m_totalRows
- n
];
2292 for (i
= 0; i
< pos
; i
++)
2293 newLabels
[i
] = m_rowLabelCells
[i
];
2294 for (i
= pos
+ n
; i
< m_totalRows
; i
++)
2295 newLabels
[i
-n
] = m_rowLabelCells
[i
];
2297 delete[] m_rowLabelCells
;
2298 m_rowLabelCells
= newLabels
;
2304 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS
, this);
2305 GetEventHandler()->ProcessEvent(g_evt
);
2312 bool wxGenericGrid::DeleteCols(int pos
, int n
, bool updateLabels
)
2314 if (pos
+ n
> m_totalCols
)
2322 for (i
= 0; i
< m_totalRows
; i
++)
2324 wxGridCell
**cols
= m_gridCells
[i
];
2325 wxGridCell
**newCols
= new wxGridCell
*[m_totalCols
- n
];
2326 for (j
= 0; j
< pos
; j
++)
2327 newCols
[j
] = cols
[j
];
2328 for (j
= pos
; j
< pos
+ n
; j
++)
2330 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2331 newCols
[j
-n
] = cols
[j
];
2334 m_gridCells
[i
] = newCols
;
2338 short *newColWidths
= new short[m_totalCols
- n
];
2339 for (j
= 0; j
< pos
; j
++)
2340 newColWidths
[j
] = m_colWidths
[j
];
2341 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2342 newColWidths
[j
-n
] = m_colWidths
[j
];
2343 delete[] m_colWidths
;
2344 m_colWidths
= newColWidths
;
2347 wxGridCell
**newLabels
= new wxGridCell
*[m_totalCols
- n
];
2348 for (j
= 0; j
< pos
; j
++)
2349 newLabels
[j
] = m_colLabelCells
[j
];
2350 for (j
= pos
+ n
; j
< m_totalCols
; j
++)
2351 newLabels
[j
-n
] = m_colLabelCells
[j
];
2353 delete[] m_colLabelCells
;
2354 m_colLabelCells
= newLabels
;
2360 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS
, this);
2361 GetEventHandler()->ProcessEvent(g_evt
);
2368 void wxGenericGrid::SetGridCursor(int row
, int col
)
2370 if (row
>= m_totalRows
|| col
>= m_totalCols
)
2373 if (row
== GetCursorRow() && col
== GetCursorColumn())
2376 wxClientDC
dc(this);
2379 SetGridClippingRegion(& dc
);
2381 if (m_currentRectVisible
)
2382 HighlightCell(& dc
);
2385 m_wCursorColumn
= col
;
2388 GetClientSize(&cw
, &ch
);
2390 SetCurrentRect(row
, col
, cw
, ch
);
2392 if (m_currentRectVisible
)
2393 HighlightCell(& dc
);
2395 dc
.DestroyClippingRegion();
2403 wxGridCell::wxGridCell(wxGenericGrid
*window
)
2405 cellBitmap
= (wxBitmap
*) NULL
;
2407 backgroundBrush
= wxNullBrush
;
2409 textColour
= window
->GetCellTextColour();
2411 textColour
.Set(0,0,0);
2413 backgroundColour
= window
->GetCellBackgroundColour();
2415 backgroundColour
.Set(255,255,255);
2418 font
= window
->GetCellTextFont();
2420 font
= * wxTheFontList
->FindOrCreateFont(12, wxSWISS
, wxNORMAL
, wxNORMAL
);
2422 SetBackgroundColour(backgroundColour
);
2425 alignment
= window
->GetCellAlignment();
2430 wxGridCell::~wxGridCell(void)
2434 void wxGridCell::SetBackgroundColour(const wxColour
& colour
)
2436 backgroundColour
= colour
;
2437 backgroundBrush
= * wxTheBrushList
->FindOrCreateBrush(backgroundColour
, wxSOLID
);
2440 void wxGenericGrid::OnText(wxCommandEvent
& WXUNUSED(ev
) )
2442 wxGenericGrid
*grid
= this;
2443 wxGridCell
*cell
= grid
->GetCell(grid
->GetCursorRow(), grid
->GetCursorColumn());
2444 if (cell
&& grid
->CurrentCellVisible())
2446 cell
->SetTextValue(grid
->GetTextItem()->GetValue());
2447 wxClientDC
dc(grid
);
2450 grid
->SetGridClippingRegion(& dc
);
2451 grid
->DrawCellBackground(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2452 grid
->DrawCellValue(& dc
, &grid
->GetCurrentRect(), grid
->GetCursorRow(), grid
->GetCursorColumn());
2453 grid
->HighlightCell(& dc
);
2454 dc
.DestroyClippingRegion();
2457 //grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn());
2458 wxGridEvent
g_evt(GetId(), wxEVT_GRID_CELL_CHANGE
, grid
,
2459 grid
->GetCursorRow(), grid
->GetCursorColumn());
2460 GetEventHandler()->ProcessEvent(g_evt
);
2462 // grid->DrawCellText();
2466 void wxGenericGrid::OnGridScroll(wxScrollEvent
& ev
)
2468 static bool inScroll
= FALSE
;
2474 wxGenericGrid
*win
= this;
2476 bool change
= FALSE
;
2478 if (ev
.GetEventObject() == win
->GetHorizScrollBar())
2480 change
= (ev
.GetPosition() != m_scrollPosX
);
2481 win
->SetScrollPosX(ev
.GetPosition());
2485 change
= (ev
.GetPosition() != m_scrollPosY
);
2486 win
->SetScrollPosY(ev
.GetPosition());
2489 win
->UpdateDimensions();
2491 win
->SetCurrentRect(win
->GetCursorRow(), win
->GetCursorColumn());
2493 // Because rows and columns can be arbitrary sizes,
2494 // the scrollbars will need to be adjusted to reflect the
2498 if (change
) win
->Refresh(FALSE
);
2504 //----------------------------------------------------------------------
2505 // Default wxGridEvent handlers
2506 // (just redirect to the pre-existing virtual methods)
2508 void wxGenericGrid::_OnSelectCell(wxGridEvent
& ev
)
2510 OnSelectCell(ev
.m_row
, ev
.m_col
);
2513 void wxGenericGrid::_OnCreateCell(wxGridEvent
& ev
)
2515 ev
.m_cell
= OnCreateCell();
2518 void wxGenericGrid::_OnChangeLabels(wxGridEvent
& WXUNUSED(ev
))
2523 void wxGenericGrid::_OnChangeSelectionLabel(wxGridEvent
& WXUNUSED(ev
))
2525 OnChangeSelectionLabel();
2528 void wxGenericGrid::_OnCellChange(wxGridEvent
& ev
)
2530 OnCellChange(ev
.m_row
, ev
.m_col
);
2533 void wxGenericGrid::_OnCellLeftClick(wxGridEvent
& ev
)
2535 OnCellLeftClick(ev
.m_row
, ev
.m_col
, ev
.m_x
, ev
.m_y
, ev
.m_control
, ev
.m_shift
);
2538 void wxGenericGrid::_OnCellRightClick(wxGridEvent
& ev
)
2540 OnCellRightClick(ev
.m_row
, ev
.m_col
, ev
.m_x
, ev
.m_y
, ev
.m_control
, ev
.m_shift
);
2543 void wxGenericGrid::_OnLabelLeftClick(wxGridEvent
& ev
)
2545 OnLabelLeftClick(ev
.m_row
, ev
.m_col
, ev
.m_x
, ev
.m_y
, ev
.m_control
, ev
.m_shift
);
2548 void wxGenericGrid::_OnLabelRightClick(wxGridEvent
& ev
)
2550 OnLabelRightClick(ev
.m_row
, ev
.m_col
, ev
.m_x
, ev
.m_y
, ev
.m_control
, ev
.m_shift
);