// Name: gridg.cpp
// Purpose: wxGenericGrid
// Author: Julian Smart
-// Modified by:
+// Modified by: Michael Bedward 20 Apr 1999
+// Added edit in place facility
// Created: 04/01/98
// RCS-ID: $Id$
// Copyright: (c) Julian Smart and Markus Holzem
#endif
#ifndef WX_PRECOMP
-#include "wx/wx.h"
+ #include "wx/utils.h"
+ #include "wx/dcclient.h"
+ #include "wx/dcmemory.h"
+ #include "wx/textctrl.h"
#endif
#include <string.h>
// Set to zero to use no double-buffering
#ifdef __WXMSW__
-#define USE_DOUBLE_BUFFERING 1
+ #define wxUSE_DOUBLE_BUFFERING 1
#else
-#define USE_DOUBLE_BUFFERING 0
+ #define wxUSE_DOUBLE_BUFFERING 0
#endif
#define wxGRID_DRAG_NONE 0
#define wxGRID_DRAG_UP_DOWN 2
IMPLEMENT_DYNAMIC_CLASS(wxGenericGrid, wxPanel)
+IMPLEMENT_DYNAMIC_CLASS(wxGridEvent, wxEvent)
BEGIN_EVENT_TABLE(wxGenericGrid, wxPanel)
- EVT_SIZE(wxGenericGrid::OnSize)
- EVT_PAINT(wxGenericGrid::OnPaint)
- EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground)
- EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent)
+ EVT_SIZE(wxGenericGrid::OnSize)
+ EVT_PAINT(wxGenericGrid::OnPaint)
+ EVT_ERASE_BACKGROUND(wxGenericGrid::OnEraseBackground)
+ EVT_MOUSE_EVENTS(wxGenericGrid::OnMouseEvent)
EVT_TEXT(wxGRID_TEXT_CTRL, wxGenericGrid::OnText)
+ EVT_TEXT(wxGRID_EDIT_IN_PLACE_TEXT_CTRL, wxGenericGrid::OnTextInPlace)
EVT_COMMAND_SCROLL(wxGRID_HSCROLL, wxGenericGrid::OnGridScroll)
EVT_COMMAND_SCROLL(wxGRID_VSCROLL, wxGenericGrid::OnGridScroll)
+
+ // default wxGridEvent handlers
+ EVT_GRID_SELECT_CELL(wxGenericGrid::_OnSelectCell)
+ EVT_GRID_CREATE_CELL(wxGenericGrid::_OnCreateCell)
+ EVT_GRID_CHANGE_LABELS(wxGenericGrid::_OnChangeLabels)
+ EVT_GRID_CHANGE_SEL_LABEL(wxGenericGrid::_OnChangeSelectionLabel)
+ EVT_GRID_CELL_CHANGE(wxGenericGrid::_OnCellChange)
+ EVT_GRID_CELL_LCLICK(wxGenericGrid::_OnCellLeftClick)
+ EVT_GRID_CELL_RCLICK(wxGenericGrid::_OnCellRightClick)
+ EVT_GRID_LABEL_LCLICK(wxGenericGrid::_OnLabelLeftClick)
+ EVT_GRID_LABEL_RCLICK(wxGenericGrid::_OnLabelRightClick)
+
END_EVENT_TABLE()
+
wxGenericGrid::wxGenericGrid(void)
{
m_batchCount = 0;
- m_hScrollBar = NULL;
- m_vScrollBar = NULL;
+ m_hScrollBar = (wxScrollBar *) NULL;
+ m_vScrollBar = (wxScrollBar *) NULL;
m_cellTextColour = *wxBLACK;
m_cellBackgroundColour = *wxWHITE;
m_labelTextColour = *wxBLACK;
- m_labelBackgroundColour = *wxLIGHT_GREY;
- m_labelBackgroundBrush = NULL;
- m_labelTextFont = NULL;
- m_cellTextFont = NULL;
- m_textItem = NULL;
+// m_labelBackgroundColour = *wxLIGHT_GREY;
+ m_labelBackgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
+ m_labelBackgroundBrush = wxNullBrush;
+ m_labelTextFont = wxNullFont;
+ m_cellTextFont = wxNullFont;
+ m_textItem = (wxTextCtrl *) NULL;
m_currentRectVisible = FALSE;
m_editable = TRUE;
+
+ m_editInPlace = TRUE;
+ m_inOnTextInPlace = FALSE;
+
#if defined(__WIN95__)
m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
+#elif defined(__WXGTK__)
+ m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
#else
m_scrollWidth = 16;
#endif
m_dragRowOrCol = 0;
m_dragStartPosition = 0;
m_dragLastPosition = 0;
- m_divisionPen = NULL;
+ m_divisionPen = wxNullPen;
m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT;
m_topOfSheet = wxGRID_DEFAULT_SHEET_TOP;
m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT;
m_totalGridWidth = 0;
m_totalGridHeight = 0;
- m_colWidths = NULL;
- m_rowHeights = NULL;
+ m_colWidths = (short *) NULL;
+ m_rowHeights = (short *) NULL;
m_verticalLabelWidth = wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH;
m_horizontalLabelHeight = wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT;
m_verticalLabelAlignment = wxCENTRE;
m_editCreated = FALSE;
m_totalRows = 0;
m_totalCols = 0;
- m_gridCells = NULL;
- m_rowLabelCells = NULL;
- m_colLabelCells = NULL;
- m_textItem = NULL;
- m_horizontalSashCursor = NULL;
- m_verticalSashCursor = NULL;
+ m_gridCells = (wxGridCell ***) NULL;
+ m_rowLabelCells = (wxGridCell **) NULL;
+ m_colLabelCells = (wxGridCell **) NULL;
+ m_textItem = (wxTextCtrl *) NULL;
}
bool wxGenericGrid::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
long style, const wxString& name)
{
m_batchCount = 0;
- m_editingPanel = NULL;
- m_hScrollBar = NULL;
- m_vScrollBar = NULL;
- m_horizontalSashCursor = NULL;
- m_verticalSashCursor = NULL;
+ m_editingPanel = (wxPanel *) NULL;
+ m_hScrollBar = (wxScrollBar *) NULL;
+ m_vScrollBar = (wxScrollBar *) NULL;
m_cellTextColour = *wxBLACK;
m_cellBackgroundColour = *wxWHITE;
m_labelTextColour = *wxBLACK;
- m_labelBackgroundColour = *wxLIGHT_GREY;
- m_labelBackgroundBrush = NULL;
- m_labelTextFont = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxBOLD);
- m_cellTextFont = wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
- m_textItem = NULL;
+// m_labelBackgroundColour = *wxLIGHT_GREY;
+ m_labelBackgroundColour = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
+ m_labelBackgroundBrush = wxNullBrush;
+ m_labelTextFont = * wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxBOLD);
+ m_cellTextFont = * wxTheFontList->FindOrCreateFont(10, wxSWISS, wxNORMAL, wxNORMAL);
+ m_textItem = (wxTextCtrl *) NULL;
m_currentRectVisible = FALSE;
m_editable = TRUE;
#if defined(__WIN95__)
m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
+#elif defined(__WXGTK__)
+ m_scrollWidth = wxSystemSettings::GetSystemMetric(wxSYS_VSCROLL_X);
#else
m_scrollWidth = 16;
#endif
m_dragRowOrCol = 0;
m_dragStartPosition = 0;
m_dragLastPosition = 0;
- m_divisionPen = wxThePenList->FindOrCreatePen("LIGHT GREY", 1, wxSOLID);
- m_doubleBufferingBitmap = NULL;
+ m_divisionPen = * wxThePenList->FindOrCreatePen("LIGHT GREY", 1, wxSOLID);
+ m_doubleBufferingBitmap = (wxBitmap *) NULL;
- if (!m_horizontalSashCursor)
+ if (!m_horizontalSashCursor.Ok())
{
- m_horizontalSashCursor = new wxCursor(wxCURSOR_SIZEWE);
- m_verticalSashCursor = new wxCursor(wxCURSOR_SIZENS);
+ m_horizontalSashCursor = wxCursor(wxCURSOR_SIZEWE);
+ m_verticalSashCursor = wxCursor(wxCURSOR_SIZENS);
}
-
+
SetLabelBackgroundColour(m_labelBackgroundColour);
m_leftOfSheet = wxGRID_DEFAULT_SHEET_LEFT;
m_cellHeight = wxGRID_DEFAULT_CELL_HEIGHT;
m_totalGridWidth = 0;
m_totalGridHeight = 0;
- m_colWidths = NULL;
- m_rowHeights = NULL;
+ m_colWidths = (short *) NULL;
+ m_rowHeights = (short *) NULL;
m_verticalLabelWidth = wxGRID_DEFAULT_VERTICAL_LABEL_WIDTH;
m_horizontalLabelHeight = wxGRID_DEFAULT_HORIZONAL_LABEL_HEIGHT;
m_totalRows = 0;
m_totalCols = 0;
- m_gridCells = NULL;
- m_rowLabelCells = NULL;
- m_colLabelCells = NULL;
- m_textItem = NULL;
+ m_gridCells = (wxGridCell ***) NULL;
+ m_rowLabelCells = (wxGridCell **) NULL;
+ m_colLabelCells = (wxGridCell **) NULL;
+ m_textItem = (wxTextCtrl *) NULL;
wxPanel::Create(parent, id, pos, size, style, name);
m_editingPanel = new wxPanel(this);
m_textItem = new wxTextCtrl(m_editingPanel, wxGRID_TEXT_CTRL, "",
- wxPoint(m_editControlPosition.x, m_editControlPosition.y), wxSize(m_editControlPosition.width, -1),
- 0);
+ wxPoint(m_editControlPosition.x, m_editControlPosition.y),
+ wxSize(m_editControlPosition.width, -1),
+ 0);
m_textItem->Show(TRUE);
m_textItem->SetFocus();
int controlW, controlH;
-
+
m_textItem->GetSize(&controlW, &controlH);
m_editControlPosition.height = controlH;
m_hScrollBar = new wxScrollBar(this, wxGRID_HSCROLL, wxPoint(0, 0), wxSize(20, 100), wxHORIZONTAL);
m_vScrollBar = new wxScrollBar(this, wxGRID_VSCROLL, wxPoint(0, 0), wxSize(100, 20), wxVERTICAL);
+// SetSize(pos.x, pos.y, size.x, size.y);
+
+ m_inPlaceTextItem = new wxTextCtrl( (wxPanel*)this, wxGRID_EDIT_IN_PLACE_TEXT_CTRL, "",
+ wxPoint( m_currentRect.x-2, m_currentRect.y-2 ),
+ wxSize( m_currentRect.width+4, m_currentRect.height+4 ),
+ wxNO_BORDER );
+ m_inPlaceTextItem->Show(TRUE);
+ m_inPlaceTextItem->SetFocus();
+
return TRUE;
}
delete[] m_gridCells[i];
}
delete[] m_gridCells;
- m_gridCells = NULL;
+ m_gridCells = (wxGridCell ***) NULL;
}
if (m_colWidths)
delete[] m_colWidths;
- m_colWidths = NULL;
+ m_colWidths = (short *) NULL;
if (m_rowHeights)
delete[] m_rowHeights;
- m_rowHeights = NULL;
+ m_rowHeights = (short *) NULL;
if (m_rowLabelCells)
{
for (i = 0; i < m_totalRows; i++)
delete m_rowLabelCells[i];
delete[] m_rowLabelCells;
- m_rowLabelCells = NULL;
+ m_rowLabelCells = (wxGridCell **) NULL;
}
if (m_colLabelCells)
{
for (i = 0; i < m_totalCols; i++)
delete m_colLabelCells[i];
delete[] m_colLabelCells;
- m_colLabelCells = NULL;
+ m_colLabelCells = (wxGridCell **) NULL;
}
if (m_doubleBufferingBitmap)
{
delete m_doubleBufferingBitmap;
- m_doubleBufferingBitmap = NULL;
+ m_doubleBufferingBitmap = (wxBitmap *) NULL;
}
}
for (j = 0; j < nCols; j++)
if (cellValues)
{
- m_gridCells[i][j] = OnCreateCell();
+ //m_gridCells[i][j] = OnCreateCell();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CREATE_CELL, this, i, j);
+ GetEventHandler()->ProcessEvent(g_evt);
+ m_gridCells[i][j] = g_evt.m_cell;
m_gridCells[i][j]->SetTextValue(cellValues[i][j]);
}
else
- m_gridCells[i][j] = NULL;
+ m_gridCells[i][j] = (wxGridCell *) NULL;
m_rowLabelCells = new wxGridCell *[nRows];
for (i = 0; i < nRows; i++)
int objectSizeX = m_totalCols;
int pageSizeX = 1;
int viewLengthX = m_totalCols;
+
+/*
m_hScrollBar->SetViewLength(viewLengthX);
m_hScrollBar->SetObjectLength(objectSizeX);
m_hScrollBar->SetPageSize(pageSizeX);
+*/
+ m_hScrollBar->SetScrollbar(m_hScrollBar->GetThumbPosition(), pageSizeX, objectSizeX, viewLengthX);
int objectSizeY = m_totalRows;
int pageSizeY = 1;
int viewLengthY = m_totalRows;
+/*
m_vScrollBar->SetViewLength(viewLengthY);
m_vScrollBar->SetObjectLength(objectSizeY);
m_vScrollBar->SetPageSize(pageSizeY);
+*/
+
+ m_vScrollBar->SetScrollbar(m_vScrollBar->GetThumbPosition(), pageSizeY, objectSizeY, viewLengthY);
AdjustScrollbars();
- OnChangeLabels();
- OnChangeSelectionLabel();
-
+ //OnChangeLabels();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this);
+ GetEventHandler()->ProcessEvent(g_evt);
+
+ //OnChangeSelectionLabel();
+ wxGridEvent g_evt2(GetId(), wxEVT_GRID_CHANGE_SEL_LABEL, this);
+ GetEventHandler()->ProcessEvent(g_evt2);
+
return TRUE;
}
{
int canvasWidth, canvasHeight;
GetSize(&canvasWidth, &canvasHeight);
-
+
if (m_editCreated && m_editable)
{
int controlW, controlH;
else
m_bottomOfSheet += m_rowHeights[i];
}
-
+
m_totalGridWidth = m_leftOfSheet + m_verticalLabelWidth;
for (i = 0; i < m_totalCols; i++)
{
}
}
-wxGridCell *wxGenericGrid::GetCell(int row, int col)
+wxGridCell *wxGenericGrid::GetCell(int row, int col) const
{
if (!m_gridCells)
- return NULL;
+ return (wxGridCell *) NULL;
if ((row >= m_totalRows) || (col >= m_totalCols))
- return NULL;
-
+ return (wxGridCell *) NULL;
+
wxGridCell *cell = m_gridCells[row][col];
if (!cell)
{
- m_gridCells[row][col] = OnCreateCell();
+ // m_gridCells[row][col] = OnCreateCell();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CREATE_CELL, (wxGenericGrid*) this, row, col);
+ GetEventHandler()->ProcessEvent(g_evt);
+ m_gridCells[row][col] = g_evt.m_cell;
return m_gridCells[row][col];
}
else
int w, h;
GetClientSize(&w, &h);
- bool useDoubleBuffering = (bool) USE_DOUBLE_BUFFERING;
+ bool useDoubleBuffering = (bool) wxUSE_DOUBLE_BUFFERING;
if (useDoubleBuffering)
{
// Reuse the old bitmap if possible
// then don't complain, just don't double-buffer
if (m_doubleBufferingBitmap)
delete m_doubleBufferingBitmap;
- m_doubleBufferingBitmap = NULL;
+ m_doubleBufferingBitmap = (wxBitmap *) NULL;
useDoubleBuffering = FALSE;
}
}
/* Hilight present cell */
SetCurrentRect(m_wCursorRow, m_wCursorColumn);
- if (m_currentRectVisible)
+ if (m_currentRectVisible && !(m_editable && m_editInPlace))
HighlightCell(& dc);
dc.DestroyClippingRegion();
// Erase (some of) the background.
// Currently, a Windows-only optimisation.
-void wxGenericGrid::OnEraseBackground(wxEraseEvent& event)
+void wxGenericGrid::OnEraseBackground(wxEraseEvent& WXUNUSED(event) )
{
wxClientDC dc(this);
dc.BeginDrawing();
// dc->DrawRectangle(m_rightOfSheet, m_topOfSheet, cw - m_rightOfSheet, ch - m_topOfSheet);
// Paint the label areas
- dc->SetBrush(*m_labelBackgroundBrush);
+ dc->SetBrush(m_labelBackgroundBrush);
// dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_rightOfSheet - m_leftOfSheet + 1, m_horizontalLabelHeight + 1);
dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, cw-m_leftOfSheet, m_horizontalLabelHeight + 1);
// dc->DrawRectangle(m_leftOfSheet, m_topOfSheet, m_verticalLabelWidth + 1, m_bottomOfSheet - m_topOfSheet + 1);
{
int cw, ch;
GetClientSize(&cw, &ch);
-
+
int i;
- if (m_divisionPen)
+ if (m_divisionPen.Ok())
{
- dc->SetPen(*m_divisionPen);
+ dc->SetPen(m_divisionPen);
int heightCount = m_topOfSheet + m_horizontalLabelHeight;
}
- if (m_divisionPen)
+ if (m_divisionPen.Ok())
{
- dc->SetPen(*m_divisionPen);
+ dc->SetPen(m_divisionPen);
// Draw vertical grey lines for cells
int widthCount = m_leftOfSheet + m_verticalLabelWidth;
if (m_horizontalLabelHeight == 0)
return;
-
+
int i;
- wxRectangle rect;
+ wxRect rect;
// Draw letters for columns
rect.y = m_topOfSheet + 1;
dc->SetTextBackground(m_labelBackgroundColour);
dc->SetBackgroundMode(wxTRANSPARENT);
// dc->SetTextForeground(m_labelTextColour);
-
+
int widthCount = m_leftOfSheet + m_verticalLabelWidth;
for (i = m_scrollPosX; i < m_totalCols; i++)
{
}
}
-void wxGenericGrid::DrawColumnLabel(wxDC *dc, wxRectangle *rect, int col)
+void wxGenericGrid::DrawColumnLabel(wxDC *dc, wxRect *rect, int col)
{
wxGridCell *cell = GetLabelCell(wxHORIZONTAL, col);
if (cell)
{
- wxRectangle rect2;
+ wxRect rect2;
rect2 = *rect;
rect2.x += 3;
rect2.y += 2;
rect2.width -= 5;
rect2.height -= 4;
dc->SetTextForeground(GetLabelTextColour());
- dc->SetFont(*GetLabelTextFont());
+ dc->SetFont(GetLabelTextFont());
if ( !cell->GetTextValue().IsNull() )
DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxHORIZONTAL));
}
return;
int i;
- wxRectangle rect;
-
+ wxRect rect;
+
// Draw numbers for rows
rect.x = m_leftOfSheet;
rect.width = m_verticalLabelWidth;
rect.y = 1 + heightCount;
rect.height = m_rowHeights[i];
DrawRowLabel(dc, &rect, i);
-
+
heightCount += m_rowHeights[i];
}
}
}
-void wxGenericGrid::DrawRowLabel(wxDC *dc, wxRectangle *rect, int row)
+void wxGenericGrid::DrawRowLabel(wxDC *dc, wxRect *rect, int row)
{
wxGridCell *cell = GetLabelCell(wxVERTICAL, row);
if (cell)
{
- wxRectangle rect2;
+ wxRect rect2;
rect2 = *rect;
rect2.x += 3;
rect2.y += 2;
rect2.width -= 5;
rect2.height -= 4;
dc->SetTextForeground(GetLabelTextColour());
- dc->SetFont(*GetLabelTextFont());
+ dc->SetFont(GetLabelTextFont());
if ( !cell->GetTextValue().IsNull() )
DrawTextRect(dc, cell->GetTextValue(), &rect2, GetLabelAlignment(wxVERTICAL));
}
GetClientSize(&cw, &ch);
int i,j;
-
+
// Draw value corresponding to each cell
for (i = m_scrollPosY; i < m_totalRows; i++)
{
dc->SetPen(*wxBLACK_PEN);
}
-void wxGenericGrid::DrawCellBackground(wxDC *dc, wxRectangle *rect, int row, int col)
+void wxGenericGrid::DrawCellBackground(wxDC *dc, wxRect *rect, int row, int col)
{
wxGridCell *cell = GetCell(row, col);
if (cell)
{
- dc->SetBrush(*cell->GetBackgroundBrush());
+ dc->SetBrush(cell->GetBackgroundBrush());
dc->SetPen(*wxTRANSPARENT_PEN);
+
+#if 0 // In wxWin 2.0 the dc code is exact. RR.
#ifdef __WXMOTIF__
dc->DrawRectangle(rect->x+1, rect->y+1, rect->width-1, rect->height-1);
#else
dc->DrawRectangle(rect->x+1, rect->y+1, rect->width, rect->height);
#endif
+#endif
+
+ dc->DrawRectangle(rect->x+1, rect->y+1, rect->width-1, rect->height-1);
+
dc->SetPen(*wxBLACK_PEN);
}
}
-void wxGenericGrid::DrawCellValue(wxDC *dc, wxRectangle *rect, int row, int col)
+void wxGenericGrid::DrawCellValue(wxDC *dc, wxRect *rect, int row, int col)
{
wxGridCell *cell = GetCell(row, col);
if (cell)
{
wxBitmap *bitmap = cell->GetCellBitmap();
- wxRectangle rect2;
+ wxRect rect2;
rect2 = *rect;
rect2.x += 3;
rect2.y += 2;
{
dc->SetBackgroundMode(wxTRANSPARENT);
dc->SetTextForeground(cell->GetTextColour());
- dc->SetFont(*cell->GetFont());
+ dc->SetFont(cell->GetFont());
if ( !cell->GetTextValue().IsNull() )
DrawTextRect(dc, cell->GetTextValue(), &rect2, cell->GetAlignment());
{
int cw, ch;
GetClientSize(&cw, &ch);
-
- // To calculate the number of steps for each scrollbar,
- // we need to see how much will fit onto the canvas
- // at the present size. So:
- // 1) Find the *last* row r1 such that when it's at the top of the
- // window, all the remaining rows are visible.
- // 2) There should therefore be r1 - 1 steps in the scrollbar.
- // Similarly with columns.
-
- // IGNORE THE ABOVE, it's crap.
+
// We find the view size by seeing how many rows/cols fit on
// the current view.
// BUT... this means that the scrollbar should be adjusted every time
vertScrollBarWidth = 0;
if (m_hScrollBar && !m_hScrollBar->IsShown())
horizScrollBarHeight = 0;
-
+
int noHorizSteps = 0;
int noVertSteps = 0;
-
- if (m_totalGridWidth <= cw)
+
+ if (m_totalGridWidth + vertScrollBarWidth <= cw)
noHorizSteps = 0;
else
{
noHorizSteps = 0;
int widthCount = 0;
-/*
- if (GetLabelSize(wxVERTICAL) > 0)
- noHorizSteps ++;
-*/
int i;
int nx = 0;
nx ++;
}
-
+
noHorizSteps += nx;
}
- if (m_totalGridHeight <= ch)
+ if (m_totalGridHeight + horizScrollBarHeight <= ch)
noVertSteps = 0;
else
{
noVertSteps = 0;
int heightCount = 0;
-/*
- if (GetLabelSize(wxHORIZONTAL) > 0)
- noVertSteps ++;
-*/
int i;
int ny = 0;
else
ny ++;
}
-
+
noVertSteps += ny;
}
-
- if (m_totalGridWidth <= cw)
+
+ if (m_totalGridWidth + vertScrollBarWidth <= cw)
{
if ( m_hScrollBar )
m_hScrollBar->Show(FALSE);
}
else
{
- if ( m_hScrollBar )
- m_hScrollBar->Show(TRUE);
+ if ( m_hScrollBar )
+ m_hScrollBar->Show(TRUE);
}
- if (m_totalGridHeight <= ch)
+ if (m_totalGridHeight + horizScrollBarHeight <= ch)
{
- if ( m_vScrollBar )
- m_vScrollBar->Show(FALSE);
- SetScrollPosY(0);
+ if ( m_vScrollBar )
+ m_vScrollBar->Show(FALSE);
+ SetScrollPosY(0);
}
else
{
- if ( m_vScrollBar )
- m_vScrollBar->Show(TRUE);
+ if ( m_vScrollBar )
+ m_vScrollBar->Show(TRUE);
}
UpdateDimensions(); // Necessary in case m_scrollPosX/Y changed
if (m_hScrollBar && !m_hScrollBar->IsShown())
horizScrollBarHeight = 0;
- if (m_hScrollBar)
+ if (m_hScrollBar && m_hScrollBar->IsShown())
{
int nCols = GetCols();
+ m_hScrollBar->SetScrollbar(m_hScrollBar->GetThumbPosition(), wxMax(noHorizSteps, 1), (noHorizSteps == 0) ? 1 : nCols, wxMax(noHorizSteps, 1));
+
/*
- m_hScrollBar->SetPageSize(wxMax(noHorizSteps, 1));
- m_hScrollBar->SetViewLength(wxMax(noHorizSteps, 1));
- m_hScrollBar->SetObjectLength(nCols);
+ m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth -2, // why -2 ? Robert.
+ cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth);
*/
- m_hScrollBar->SetScrollbar(m_hScrollBar->GetPosition(), wxMax(noHorizSteps, 1), nCols, wxMax(noHorizSteps, 1));
-
m_hScrollBar->SetSize(m_leftOfSheet, ch - m_scrollWidth,
cw - vertScrollBarWidth - m_leftOfSheet, m_scrollWidth);
+
}
-
- if (m_vScrollBar)
+
+ if (m_vScrollBar && m_vScrollBar->IsShown())
{
int nRows = GetRows();
-/*
- m_vScrollBar->SetPageSize(wxMax(noVertSteps, 1));
- m_vScrollBar->SetViewLength(wxMax(noVertSteps, 1));
- m_vScrollBar->SetObjectLength(nRows);
-*/
- m_vScrollBar->SetScrollbar(m_vScrollBar->GetPosition(), wxMax(noVertSteps, 1), nRows, wxMax(noVertSteps, 1));
+ m_vScrollBar->SetScrollbar(m_vScrollBar->GetThumbPosition(), wxMax(noVertSteps, 1), (noVertSteps == 0) ? 1 : nRows, wxMax(noVertSteps, 1));
m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
m_scrollWidth, ch - m_topOfSheet - horizScrollBarHeight);
}
return;
AdjustScrollbars();
-
+
int cw, ch;
GetClientSize(&cw, &ch);
{
m_editingPanel->SetSize(0, 0, cw, m_editControlPosition.height + m_editControlPosition.y + 2);
GetTextItem()->SetSize(m_editControlPosition.x, m_editControlPosition.y,
- cw - m_editControlPosition.x, m_editControlPosition.height);
+ cw - 2*m_editControlPosition.x, m_editControlPosition.height);
}
}
y -= (m_topOfSheet + m_horizontalLabelHeight);
int i;
-
+
// Now we need to do a hit test for which row we're on
int currentHeight = 0;
for (i = m_scrollPosY; i < m_totalRows; i++)
}
currentHeight += m_rowHeights[i];
}
-
+
// Now we need to do a hit test for which column we're on
int currentWidth = 0;
for (i = m_scrollPosX; i < m_totalCols; i++)
{
int i;
int tolerance = 3;
-
+
if (x >= (m_leftOfSheet + m_verticalLabelWidth) && y >= m_topOfSheet &&
x <= m_rightOfSheet && y <= (m_topOfSheet + m_horizontalLabelHeight))
{
{
wxClientDC dc(this);
dc.BeginDrawing();
-
+
int row, col;
if (CellHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col))
{
OnSelectCellImplementation(& dc, row, col);
- OnCellLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+
+ //OnCellLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_LCLICK, this,
+ row, col, (int)ev.GetX(), (int)ev.GetY(),
+ ev.ControlDown(), ev.ShiftDown());
+ GetEventHandler()->ProcessEvent(g_evt);
+
}
if (LabelHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col))
{
- OnLabelLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ //OnLabelLeftClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_LABEL_LCLICK, this,
+ row, col, (int)ev.GetX(), (int)ev.GetY(),
+ ev.ControlDown(), ev.ShiftDown());
+ GetEventHandler()->ProcessEvent(g_evt);
+
}
dc.EndDrawing();
}
if (orientation == wxHORIZONTAL)
{
m_dragStatus = wxGRID_DRAG_LEFT_RIGHT;
- SetCursor(*m_horizontalSashCursor);
+ SetCursor(m_horizontalSashCursor);
m_dragLastPosition = (int)ev.GetX();
}
else
{
m_dragStatus = wxGRID_DRAG_UP_DOWN;
- SetCursor(*m_verticalSashCursor);
+ SetCursor(m_verticalSashCursor);
m_dragLastPosition = (int)ev.GetY();
}
wxClientDC dc(this);
else
dc.DrawLine(m_leftOfSheet, (int)ev.GetY(), m_rightOfSheet, (int)ev.GetY());
dc.EndDrawing();
-
+
CaptureMouse();
}
break;
dc.EndDrawing();
m_dragLastPosition = (int)ev.GetX();
- SetCursor(*m_horizontalSashCursor);
+ SetCursor(m_horizontalSashCursor);
break;
}
case wxGRID_DRAG_UP_DOWN:
dc.EndDrawing();
m_dragLastPosition = (int)ev.GetY();
- SetCursor(*m_verticalSashCursor);
+ SetCursor(m_verticalSashCursor);
break;
}
}
if (LabelSashHitTest((int)ev.GetX(), (int)ev.GetY(), &orientation, &rowOrCol, &startPos))
{
if (orientation == wxHORIZONTAL)
- SetCursor(*m_horizontalSashCursor);
+ SetCursor(m_horizontalSashCursor);
else
- SetCursor(*m_verticalSashCursor);
+ SetCursor(m_verticalSashCursor);
}
else
SetCursor(*wxSTANDARD_CURSOR);
int row, col;
if (CellHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col))
{
- OnCellRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ //OnCellRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_RCLICK, this,
+ row, col, (int)ev.GetX(), (int)ev.GetY(),
+ ev.ControlDown(), ev.ShiftDown());
+ GetEventHandler()->ProcessEvent(g_evt);
+
}
if (LabelHitTest((int)ev.GetX(), (int)ev.GetY(), &row, &col))
{
- OnLabelRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ //OnLabelRightClick(row, col, (int)ev.GetX(), (int)ev.GetY(), ev.ControlDown(), ev.ShiftDown());
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_LABEL_RCLICK, this,
+ row, col, (int)ev.GetX(), (int)ev.GetY(),
+ ev.ControlDown(), ev.ShiftDown());
+ GetEventHandler()->ProcessEvent(g_evt);
}
}
}
m_wCursorColumn = col;
m_wCursorRow = row;
- OnChangeSelectionLabel();
+ //OnChangeSelectionLabel();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_SEL_LABEL, this);
+ GetEventHandler()->ProcessEvent(g_evt);
SetGridClippingRegion(dc);
// Remove the highlight from the old cell
- if (m_currentRectVisible)
- HighlightCell(dc);
+ if ( m_currentRectVisible && !(m_editable && m_editInPlace) )
+ {
+ HighlightCell(dc);
+ }
+
// Highlight the new cell and copy its content to the edit control
SetCurrentRect(m_wCursorRow, m_wCursorColumn);
SetGridClippingRegion(dc);
- // Why isn't this needed for Windows??
- // Probably because of the SetValue??
-#ifndef __WXMSW__
- HighlightCell(dc);
+
+ if ( m_editable && m_editInPlace )
+ {
+ m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2,
+ m_currentRect.width+4, m_currentRect.height+4 );
+
+ if ( cell )
+ {
+ if ( cell->GetTextValue().IsNull() )
+ {
+ m_inPlaceTextItem->SetValue( "" );
+ }
+ else
+ {
+ m_inPlaceTextItem->SetFont( cell->GetFont() );
+ m_inPlaceTextItem->SetValue( cell->GetTextValue() );
+ }
+ }
+
+ m_inPlaceTextItem->Show(TRUE);
+ m_inPlaceTextItem->SetFocus();
+ }
+ else
+ {
+ // 1) Why isn't this needed for Windows??
+ // Probably because of the SetValue?? JS.
+ // 2) Arrrrrgh. This isn't needed anywhere,
+ // of course. One hour of debugging... RR.
+ //
+ // 3) It *is* needed for Motif - michael
+ //
+#ifdef __WXMOTIF__
+ if ( !(m_editable && m_editInPlace) )
+ HighlightCell(dc);
#endif
+ }
+
dc->DestroyClippingRegion();
-
+
OnSelectCell(row, col);
+ wxGridEvent g_evt2(GetId(), wxEVT_GRID_SELECT_CELL, this, row, col);
+ GetEventHandler()->ProcessEvent(g_evt2);
}
wxGridCell *wxGenericGrid::OnCreateCell(void)
{
if (!GetEditable())
return;
-
+
wxString rowLabel(GetLabelValue(wxVERTICAL, GetCursorRow()));
wxString colLabel(GetLabelValue(wxHORIZONTAL, GetCursorColumn()));
-
+
wxString newLabel = colLabel + rowLabel;
if ((newLabel.Length() > 0) && (newLabel.Length() <= 8) && GetTextItem())
{
void wxGenericGrid::HighlightCell(wxDC *dc)
{
dc->SetLogicalFunction(wxINVERT);
+
// Top
- dc->DrawLine(m_currentRect.x + 1, m_currentRect.y + 1, m_currentRect.x + m_currentRect.width - 1, m_currentRect.y + 1);
+ dc->DrawLine( m_currentRect.x + 1,
+ m_currentRect.y + 1,
+ m_currentRect.x + m_currentRect.width - 1,
+ m_currentRect.y + 1);
// Right
- dc->DrawLine(m_currentRect.x + m_currentRect.width - 1, m_currentRect.y + 1,
- m_currentRect.x + m_currentRect.width - 1, m_currentRect.y +m_currentRect.height - 1);
+ dc->DrawLine( m_currentRect.x + m_currentRect.width - 1,
+ m_currentRect.y + 1,
+ m_currentRect.x + m_currentRect.width - 1,
+ m_currentRect.y +m_currentRect.height - 1 );
// Bottom
- dc->DrawLine(m_currentRect.x + m_currentRect.width - 1, m_currentRect.y + m_currentRect.height - 1,
- m_currentRect.x + 1, m_currentRect.y + m_currentRect.height - 1);
+ dc->DrawLine( m_currentRect.x + m_currentRect.width - 1,
+ m_currentRect.y + m_currentRect.height - 1,
+ m_currentRect.x + 1,
+ m_currentRect.y + m_currentRect.height - 1);
// Left
- dc->DrawLine(m_currentRect.x + 1, m_currentRect.y + m_currentRect.height - 1, m_currentRect.x + 1, m_currentRect.y + 1);
+ dc->DrawLine( m_currentRect.x + 1,
+ m_currentRect.y + m_currentRect.height - 1,
+ m_currentRect.x + 1,
+ m_currentRect.y + 1);
dc->SetLogicalFunction(wxCOPY);
}
{
if (!m_currentRectVisible)
return;
-
+
wxGridCell *cell = GetCell(GetCursorRow(), GetCursorColumn());
if (!cell)
return;
-
- static char szEdit[300];
wxClientDC dc(this);
dc.BeginDrawing();
SetGridClippingRegion(& dc);
dc.SetBackgroundMode(wxTRANSPARENT);
- dc.SetBrush(*cell->GetBackgroundBrush());
+ dc.SetBrush(cell->GetBackgroundBrush());
- strcpy(szEdit, m_textItem->GetValue());
+ wxString editValue = m_textItem->GetValue();
- wxRectangle rect;
+ wxRect rect;
rect = m_currentRect;
rect.x += 3;
rect.y += 2;
rect.width -= 5;
rect.height -= 4;
+ // FIXME: what's this string of spaces supposed to represent?
DrawTextRect(& dc, " ", &rect, wxLEFT);
- DrawTextRect(& dc, szEdit, &rect, cell->GetAlignment());
-
+ DrawTextRect(& dc, editValue, &rect, cell->GetAlignment());
+
dc.DestroyClippingRegion();
-
+
dc.SetBackgroundMode(wxSOLID);
dc.EndDrawing();
else m_currentRectVisible = TRUE;
}
-static bool wxRectIntersection(wxRectangle *rect1, wxRectangle *rect2, wxRectangle *rect3)
+static bool wxRectIntersection(wxRect *rect1, wxRect *rect2, wxRect *rect3)
{
int x2_1 = rect1->x + rect1->width;
int y2_1 = rect1->y + rect1->height;
int x2_2 = rect2->x + rect2->width;
int y2_2 = rect2->y + rect2->height;
-
+
int x2_3, y2_3;
-
+
// Check for intersection
if ((rect1->x > x2_2) || (rect2->x > x2_1) ||
(rect1->y > y2_2) || (rect2->y > y2_1))
rect3->y = rect1->y;
else
rect3->y = rect2->y;
-
+
if (x2_1 > x2_2)
x2_3 = x2_2;
else
y2_3 = y2_2;
else
y2_3 = y2_1;
-
+
rect3->width = (int)(x2_3 - rect3->x);
rect3->height = (int)(y2_3 - rect3->y);
return TRUE;
}
-void wxGenericGrid::DrawTextRect(wxDC *dc, const wxString& text, wxRectangle *rect, int flag)
+void wxGenericGrid::DrawTextRect(wxDC *dc, const wxString& text, wxRect *rect, int flag)
{
dc->BeginDrawing();
-
+
// Ultimately, this functionality should be built into wxWindows,
// and optimized for each platform. E.g. on Windows, use DrawText
// passing a clipping rectangle, so that the wxWindows clipping region
// does not have to be used to implement this.
-
+
// If we're already clipping, we need to find the intersection
// between current clipping area and text clipping area.
-
- wxRectangle clipRect;
- wxRectangle clipRect2;
+
+ wxRect clipRect;
+ wxRect clipRect2;
long clipX, clipY, clipW, clipH;
dc->GetClippingBox(&clipX, &clipY, &clipW, &clipH);
clipRect.x = (int)clipX; clipRect.y = (int)clipY;
clipRect.width = (int)clipW; clipRect.height = (int)clipH;
-
+
bool alreadyClipping = TRUE;
if (clipRect.x == 0 && clipRect.y == 0 && clipRect.width == 0 && clipRect.height == 0)
if (alreadyClipping)
dc->DestroyClippingRegion();
-
+
dc->SetClippingRegion(clipRect2.x, clipRect2.y, clipRect2.width, clipRect2.height);
long textWidth, textHeight;
-
+
dc->GetTextExtent(text, &textWidth, &textHeight);
-
+
// Do alignment
float x,y;
switch (flag)
}
}
dc->DrawText(text, (long)x, (long)y );
-
+
dc->DestroyClippingRegion();
// Restore old clipping
dc->EndDrawing();
}
-void wxGenericGrid::DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRectangle *rect, int flag)
+void wxGenericGrid::DrawBitmapRect(wxDC *dc, wxBitmap *bitmap, wxRect *rect, int flag)
{
dc->BeginDrawing();
-
+
// Ultimately, this functionality should be built into wxWindows,
// and optimized for each platform. E.g. on Windows, use DrawText
// passing a clipping rectangle, so that the wxWindows clipping region
// does not have to be used to implement this.
-
+
// If we're already clipping, we need to find the intersection
// between current clipping area and text clipping area.
-
- wxRectangle clipRect;
- wxRectangle clipRect2;
+
+ wxRect clipRect;
+ wxRect clipRect2;
long clipX, clipY, clipW, clipH;
dc->GetClippingBox(&clipX, &clipY, &clipW, &clipH);
clipRect.x = (int)clipX; clipRect.y = (int)clipY;
clipRect.width = (int)clipW; clipRect.height = (int)clipH;
-
+
bool alreadyClipping = TRUE;
if (clipRect.x == 0 && clipRect.y == 0 && clipRect.width == 0 && clipRect.height == 0)
if (alreadyClipping)
dc->DestroyClippingRegion();
-
+
dc->SetClippingRegion(clipRect2.x, clipRect2.y, clipRect2.width, clipRect2.height);
float bitmapWidth, bitmapHeight;
-
+
bitmapWidth = bitmap->GetWidth();
bitmapHeight = bitmap->GetHeight();
-
+
// Do alignment
long x,y;
switch (flag)
}
wxMemoryDC dcTemp;
dcTemp.SelectObject(*bitmap);
-
+
dc->Blit( (long)x, (long)y, (long)bitmapWidth, (long)bitmapHeight, &dcTemp, 0, 0);
dcTemp.SelectObject(wxNullBitmap);
-
+
dc->DestroyClippingRegion();
// Restore old clipping
// Don't refresh within a pair of batch brackets
if (GetBatchCount() > 0)
return;
-
+
int cw, ch;
GetClientSize(&cw, &ch);
}
}
-wxString& wxGenericGrid::GetCellValue(int row, int col)
+wxString& wxGenericGrid::GetCellValue(int row, int col) const
{
static wxString emptyString("");
-
+
wxGridCell *cell = GetCell(row, col);
if (cell)
return cell->GetTextValue();
m_colWidths[col] = width;
}
-int wxGenericGrid::GetColumnWidth(int col)
+int wxGenericGrid::GetColumnWidth(int col) const
{
if (col <= m_totalCols)
return m_colWidths[col];
m_rowHeights[row] = height;
}
-int wxGenericGrid::GetRowHeight(int row)
+int wxGenericGrid::GetRowHeight(int row) const
{
if (row <= m_totalRows)
return m_rowHeights[row];
SetCurrentRect(GetCursorRow(), GetCursorColumn());
}
-int wxGenericGrid::GetLabelSize(int orientation)
+int wxGenericGrid::GetLabelSize(int orientation) const
{
if (orientation == wxHORIZONTAL)
return m_horizontalLabelHeight;
return m_verticalLabelWidth;
}
-wxGridCell *wxGenericGrid::GetLabelCell(int orientation, int pos)
+wxGridCell *wxGenericGrid::GetLabelCell(int orientation, int pos) const
{
if (orientation == wxHORIZONTAL)
{
if (m_colLabelCells && pos < m_totalCols)
return m_colLabelCells[pos];
else
- return NULL;
+ return (wxGridCell *) NULL;
}
else
{
if (m_rowLabelCells && pos < m_totalRows)
return m_rowLabelCells[pos];
else
- return NULL;
+ return (wxGridCell *) NULL;
}
}
cell->SetTextValue(val);
}
-wxString& wxGenericGrid::GetLabelValue(int orientation, int pos)
+wxString& wxGenericGrid::GetLabelValue(int orientation, int pos) const
{
static wxString emptyString = "";
wxGridCell *cell = GetLabelCell(orientation, pos);
SetCurrentRect(GetCursorRow(), GetCursorColumn());
}
-int wxGenericGrid::GetLabelAlignment(int orientation)
+int wxGenericGrid::GetLabelAlignment(int orientation) const
{
if (orientation == wxHORIZONTAL)
return m_horizontalLabelAlignment;
void wxGenericGrid::SetLabelBackgroundColour(const wxColour& colour)
{
m_labelBackgroundColour = colour;
- m_labelBackgroundBrush = wxTheBrushList->FindOrCreateBrush(m_labelBackgroundColour, wxSOLID);
+ m_labelBackgroundBrush = * wxTheBrushList->FindOrCreateBrush(m_labelBackgroundColour, wxSOLID);
}
void wxGenericGrid::SetEditable(bool edit)
m_textItem->Show(TRUE);
m_textItem->SetFocus();
}
+
+ if (m_inPlaceTextItem)
+ {
+ m_inPlaceTextItem->Show(TRUE);
+ m_inPlaceTextItem->SetFocus();
+ }
}
else
{
m_textItem->Show(FALSE);
m_editingPanel->Show(FALSE);
}
+
+ if ( m_inPlaceTextItem )
+ {
+ m_inPlaceTextItem->Show(FALSE);
+ }
}
UpdateDimensions();
SetCurrentRect(GetCursorRow(), GetCursorColumn());
int cw, ch;
int m_scrollWidth = 16;
GetClientSize(&cw, &ch);
-
+
if (m_vScrollBar)
m_vScrollBar->SetSize(cw - m_scrollWidth, m_topOfSheet,
m_scrollWidth, ch - m_topOfSheet - m_scrollWidth);
*/
}
+
+void wxGenericGrid::SetEditInPlace(bool edit)
+{
+ if ( m_editInPlace != edit )
+ {
+ m_editInPlace = edit;
+
+ if ( m_editInPlace ) // switched on
+ {
+ if ( m_currentRectVisible && m_editable )
+ {
+ m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2,
+ m_currentRect.width+4, m_currentRect.height+4 );
+
+ wxGridCell *cell = GetCell(m_wCursorRow, m_wCursorColumn);
+
+ if ( cell )
+ {
+ if ( cell->GetTextValue().IsNull() )
+ {
+ m_inPlaceTextItem->SetValue( "" );
+ }
+ else
+ {
+ m_inPlaceTextItem->SetFont( cell->GetFont() );
+ m_inPlaceTextItem->SetValue( cell->GetTextValue() );
+ }
+ }
+
+ m_inPlaceTextItem->Show( TRUE );
+ m_inPlaceTextItem->SetFocus();
+ }
+ }
+ else // switched off
+ {
+ m_inPlaceTextItem->Show( FALSE );
+ }
+ }
+}
+
+
void wxGenericGrid::SetCellAlignment(int flag, int row, int col)
{
wxGridCell *cell = GetCell(row, col);
cell->SetAlignment(flag);
}
-int wxGenericGrid::GetCellAlignment(int row, int col)
+int wxGenericGrid::GetCellAlignment(int row, int col) const
{
wxGridCell *cell = GetCell(row, col);
if (cell)
GetCell(i, j)->SetAlignment(flag);
}
-int wxGenericGrid::GetCellAlignment(void)
+int wxGenericGrid::GetCellAlignment(void) const
{
return m_cellAlignment;
}
}
}
-wxColour& wxGenericGrid::GetCellBackgroundColour(int row, int col)
+wxColour& wxGenericGrid::GetCellBackgroundColour(int row, int col) const
{
wxGridCell *cell = GetCell(row, col);
if (cell)
return cell->GetBackgroundColour();
else
- return m_cellBackgroundColour;
+ return (wxColour&) m_cellBackgroundColour;
}
void wxGenericGrid::SetCellTextColour(const wxColour& val, int row, int col)
}
}
-void wxGenericGrid::SetCellTextFont(wxFont *fnt, int row, int col)
+void wxGenericGrid::SetCellTextFont(const wxFont& fnt, int row, int col)
{
wxGridCell *cell = GetCell(row, col);
if (cell)
}
}
-wxFont *wxGenericGrid::GetCellTextFont(int row, int col)
+wxFont& wxGenericGrid::GetCellTextFont(int row, int col) const
{
wxGridCell *cell = GetCell(row, col);
if (cell)
- return cell->GetFont();
+ return (wxFont&) cell->GetFont();
else
- return m_cellTextFont;
+ return (wxFont&) m_cellTextFont;
}
-wxColour& wxGenericGrid::GetCellTextColour(int row, int col)
+wxColour& wxGenericGrid::GetCellTextColour(int row, int col) const
{
wxGridCell *cell = GetCell(row, col);
if (cell)
- return cell->GetTextColour();
+ return (wxColour&) cell->GetTextColour();
else
- return m_cellTextColour;
+ return (wxColour&) m_cellTextColour;
}
void wxGenericGrid::SetCellTextColour(const wxColour& val)
GetCell(i, j)->SetTextColour(val);
}
-void wxGenericGrid::SetCellTextFont(wxFont *fnt)
+void wxGenericGrid::SetCellTextFont(const wxFont& fnt)
{
m_cellTextFont = fnt;
int i,j;
}
}
-wxBitmap *wxGenericGrid::GetCellBitmap(int row, int col)
+wxBitmap *wxGenericGrid::GetCellBitmap(int row, int col) const
{
wxGridCell *cell = GetCell(row, col);
if (cell)
return cell->GetCellBitmap();
}
else
- return NULL;
+ return (wxBitmap *) NULL;
}
bool wxGenericGrid::InsertCols(int pos, int n, bool updateLabels)
{
if (pos > m_totalCols)
return FALSE;
-
+
if (!m_gridCells)
return CreateGrid(1, n);
else
newCols[j] = new wxGridCell(this);
for (j = pos + n; j < m_totalCols + n; j++)
newCols[j] = cols[j - n];
-
+
delete[] cols;
m_gridCells[i] = newCols;
}
m_totalCols += n;
- if (updateLabels)
- OnChangeLabels();
+ if (updateLabels) {
+ //OnChangeLabels();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this);
+ GetEventHandler()->ProcessEvent(g_evt);
+ }
+
UpdateDimensions();
AdjustScrollbars();
return TRUE;
{
if (pos > m_totalRows)
return FALSE;
-
+
if (!m_gridCells)
return CreateGrid(n, 1);
else
{
int i, j;
-
+
wxGridCell ***rows = new wxGridCell **[m_totalRows + n];
// Cells
for (j = 0; j < m_totalCols; j++)
rows[i][j] = new wxGridCell(this);
}
-
+
for (i = pos + n; i < m_totalRows + n; i++)
rows[i] = m_gridCells[i - n];
m_totalRows += n;
- if (updateLabels)
- OnChangeLabels();
+ if (updateLabels) {
+ //OnChangeLabels();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this);
+ GetEventHandler()->ProcessEvent(g_evt);
+ }
+
UpdateDimensions();
AdjustScrollbars();
return TRUE;
return FALSE;
int i;
-
+
wxGridCell ***rows = new wxGridCell **[m_totalRows - n];
// Cells
m_totalRows -= n;
- if (updateLabels)
- OnChangeLabels();
+ if (updateLabels){
+ //OnChangeLabels();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this);
+ GetEventHandler()->ProcessEvent(g_evt);
+ }
UpdateDimensions();
AdjustScrollbars();
return TRUE;
delete cols[j];
for (j = pos + n; j < m_totalCols; j++)
newCols[j-n] = cols[j];
-
+
delete[] cols;
m_gridCells[i] = newCols;
}
m_totalCols -= n;
- if (updateLabels)
- OnChangeLabels();
+ if (updateLabels) {
+ //OnChangeLabels();
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CHANGE_LABELS, this);
+ GetEventHandler()->ProcessEvent(g_evt);
+ }
UpdateDimensions();
AdjustScrollbars();
return TRUE;
{
if (row >= m_totalRows || col >= m_totalCols)
return;
-
+
if (row == GetCursorRow() && col == GetCursorColumn())
return;
-
+
wxClientDC dc(this);
dc.BeginDrawing();
-
+
SetGridClippingRegion(& dc);
- if (m_currentRectVisible)
+ if (m_currentRectVisible && !(m_editable && m_editInPlace) )
HighlightCell(& dc);
-
+
m_wCursorRow = row;
m_wCursorColumn = col;
- SetCurrentRect(row, col);
- if (m_currentRectVisible)
+
+ int cw, ch;
+ GetClientSize(&cw, &ch);
+
+ SetCurrentRect(row, col, cw, ch);
+
+ if (m_currentRectVisible && !(m_editable && m_editInPlace) )
HighlightCell(& dc);
dc.DestroyClippingRegion();
/*
* Grid cell
*/
-
+
wxGridCell::wxGridCell(wxGenericGrid *window)
{
- cellBitmap = NULL;
- font = NULL;
- backgroundBrush = NULL;
+ cellBitmap = (wxBitmap *) NULL;
+ font = wxNullFont;
+ backgroundBrush = wxNullBrush;
if (window)
textColour = window->GetCellTextColour();
else
backgroundColour = window->GetCellBackgroundColour();
else
backgroundColour.Set(255,255,255);
-
+
if (window)
font = window->GetCellTextFont();
else
- font = wxTheFontList->FindOrCreateFont(12, wxSWISS, wxNORMAL, wxNORMAL);
-
+ font = * wxTheFontList->FindOrCreateFont(12, wxSWISS, wxNORMAL, wxNORMAL);
+
SetBackgroundColour(backgroundColour);
-
+
if (window)
alignment = window->GetCellAlignment();
else
void wxGridCell::SetBackgroundColour(const wxColour& colour)
{
backgroundColour = colour;
- backgroundBrush = wxTheBrushList->FindOrCreateBrush(backgroundColour, wxSOLID);
+ backgroundBrush = * wxTheBrushList->FindOrCreateBrush(backgroundColour, wxSOLID);
}
void wxGenericGrid::OnText(wxCommandEvent& WXUNUSED(ev) )
{
- wxGenericGrid *grid = this;
- wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn());
- if (cell && grid->CurrentCellVisible())
- {
- cell->SetTextValue(grid->GetTextItem()->GetValue());
- wxClientDC dc(grid);
+ // michael - added this conditional to prevent change to
+ // grid cell text when edit control is hidden but still has
+ // focus
+ //
+ if ( m_editable )
+ {
+ wxGenericGrid *grid = this;
+ wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn());
+ if (cell && grid->CurrentCellVisible())
+ {
+ cell->SetTextValue(grid->GetTextItem()->GetValue());
+ if ( m_editInPlace && !m_inOnTextInPlace )
+ {
+ m_inPlaceTextItem->SetValue( grid->GetTextItem()->GetValue() );
+ }
+
+ wxClientDC dc(grid);
+
+ dc.BeginDrawing();
+ grid->SetGridClippingRegion(& dc);
+ grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
+ grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
+ if ( !(m_editable && m_editInPlace ) ) grid->HighlightCell(& dc);
+ dc.DestroyClippingRegion();
+ dc.EndDrawing();
+
+ //grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn());
+ wxGridEvent g_evt(GetId(), wxEVT_GRID_CELL_CHANGE, grid,
+ grid->GetCursorRow(), grid->GetCursorColumn());
+ GetEventHandler()->ProcessEvent(g_evt);
+
+ // grid->DrawCellText();
+ }
+ }
+}
- dc.BeginDrawing();
- grid->SetGridClippingRegion(& dc);
- grid->DrawCellBackground(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
- grid->DrawCellValue(& dc, &grid->GetCurrentRect(), grid->GetCursorRow(), grid->GetCursorColumn());
- grid->HighlightCell(& dc);
- dc.DestroyClippingRegion();
- dc.EndDrawing();
-
- grid->OnCellChange(grid->GetCursorRow(), grid->GetCursorColumn());
-
-// grid->DrawCellText();
- }
+void wxGenericGrid::OnTextInPlace(wxCommandEvent& ev )
+{
+ if ( m_editable )
+ {
+ wxGenericGrid *grid = this;
+ wxGridCell *cell = grid->GetCell(grid->GetCursorRow(), grid->GetCursorColumn());
+ if (cell && grid->CurrentCellVisible())
+ {
+ m_inOnTextInPlace = TRUE;
+ grid->GetTextItem()->SetValue( m_inPlaceTextItem->GetValue() );
+ OnText( ev );
+ m_inOnTextInPlace = FALSE;
+ }
+ }
}
void wxGenericGrid::OnGridScroll(wxScrollEvent& ev)
if ( inScroll )
return;
+ if ( m_editInPlace ) m_inPlaceTextItem->Show(FALSE);
+
inScroll = TRUE;
wxGenericGrid *win = this;
bool change = FALSE;
-
+
if (ev.GetEventObject() == win->GetHorizScrollBar())
{
change = (ev.GetPosition() != m_scrollPosX);
}
win->UpdateDimensions();
+
win->SetCurrentRect(win->GetCursorRow(), win->GetCursorColumn());
// Because rows and columns can be arbitrary sizes,
AdjustScrollbars();
if (change) win->Refresh(FALSE);
+
+ if ( m_editInPlace && m_currentRectVisible )
+ {
+ m_inPlaceTextItem->SetSize( m_currentRect.x-2, m_currentRect.y-2,
+ m_currentRect.width+4, m_currentRect.height+4 );
+ m_inPlaceTextItem->Show( TRUE );
+ m_inPlaceTextItem->SetFocus();
+ }
+
inScroll = FALSE;
-
+
+}
+
+
+//----------------------------------------------------------------------
+// Default wxGridEvent handlers
+// (just redirect to the pre-existing virtual methods)
+
+void wxGenericGrid::_OnSelectCell(wxGridEvent& ev)
+{
+ OnSelectCell(ev.m_row, ev.m_col);
+}
+
+void wxGenericGrid::_OnCreateCell(wxGridEvent& ev)
+{
+ ev.m_cell = OnCreateCell();
}
+
+void wxGenericGrid::_OnChangeLabels(wxGridEvent& WXUNUSED(ev))
+{
+ OnChangeLabels();
+}
+
+void wxGenericGrid::_OnChangeSelectionLabel(wxGridEvent& WXUNUSED(ev))
+{
+ OnChangeSelectionLabel();
+}
+
+void wxGenericGrid::_OnCellChange(wxGridEvent& ev)
+{
+ OnCellChange(ev.m_row, ev.m_col);
+}
+
+void wxGenericGrid::_OnCellLeftClick(wxGridEvent& ev)
+{
+ OnCellLeftClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
+}
+
+void wxGenericGrid::_OnCellRightClick(wxGridEvent& ev)
+{
+ OnCellRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
+}
+
+void wxGenericGrid::_OnLabelLeftClick(wxGridEvent& ev)
+{
+ OnLabelLeftClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
+}
+
+void wxGenericGrid::_OnLabelRightClick(wxGridEvent& ev)
+{
+ OnLabelRightClick(ev.m_row, ev.m_col, ev.m_x, ev.m_y, ev.m_control, ev.m_shift);
+}
+
+