#pragma hdrstop
#endif
-#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
+#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
#include "gridg.cpp"
#else
wxLogWarning( wxT("Called grid table class function InsertRows(pos=%d, N=%d)\n"
"but your derived table class does not override this function"),
pos, numRows );
-
+
return FALSE;
}
wxLogWarning( wxT("Called grid table class function AppendRows(N=%d)\n"
"but your derived table class does not override this function"),
numRows );
-
+
return FALSE;
}
wxLogWarning( wxT("Called grid table class function DeleteRows(pos=%d, N=%d)\n"
"but your derived table class does not override this function"),
pos, numRows );
-
+
return FALSE;
}
wxLogWarning( wxT("Called grid table class function InsertCols(pos=%d, N=%d)\n"
"but your derived table class does not override this function"),
pos, numCols );
-
+
return FALSE;
}
wxLogWarning( wxT("Called grid table class function AppendCols(N=%d)\n"
"but your derived table class does not override this function"),
numCols );
-
+
return FALSE;
}
wxLogWarning( wxT("Called grid table class function DeleteCols(pos=%d, N=%d)\n"
"but your derived table class does not override this function"),
pos, numCols );
-
+
return FALSE;
}
// this is a magic incantation which must be done!
-#include <wx/arrimpl.cpp>
+#include "wx/arrimpl.cpp"
WX_DEFINE_OBJARRAY(wxGridStringArray)
: wxGridTableBase()
{
int row, col;
-
+
m_data.Alloc( numRows );
wxArrayString sa;
{
sa.Add( wxEmptyString );
}
-
+
for ( row = 0; row < numRows; row++ )
{
m_data.Add( sa );
{
int row, col;
int numRows, numCols;
-
+
numRows = m_data.GetCount();
if ( numRows > 0 )
{
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
-
+
if ( pos >= curNumRows )
{
return AppendRows( numRows );
}
-
+
wxArrayString sa;
sa.Alloc( curNumCols );
for ( col = 0; col < curNumCols; col++ )
wxGRIDTABLE_NOTIFY_ROWS_INSERTED,
pos,
numRows );
-
+
GetView()->ProcessTableMessage( msg );
}
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
-
+
wxArrayString sa;
if ( curNumCols > 0 )
{
sa.Add( wxEmptyString );
}
}
-
+
for ( row = 0; row < numRows; row++ )
{
m_data.Add( sa );
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
numRows );
-
+
GetView()->ProcessTableMessage( msg );
}
- return TRUE;
+ return TRUE;
}
bool wxGridStringTable::DeleteRows( size_t pos, size_t numRows )
size_t n;
size_t curNumRows = m_data.GetCount();
-
+
if ( pos >= curNumRows )
{
wxLogError( wxT("Called wxGridStringTable::DeleteRows(pos=%d, N=%d)...\n"
{
numRows = curNumRows - pos;
}
-
+
if ( numRows >= curNumRows )
{
m_data.Empty(); // don't release memory just yet
wxGRIDTABLE_NOTIFY_ROWS_DELETED,
pos,
numRows );
-
+
GetView()->ProcessTableMessage( msg );
}
- return TRUE;
+ return TRUE;
}
bool wxGridStringTable::InsertCols( size_t pos, size_t numCols )
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
-
+
if ( pos >= curNumCols )
{
return AppendCols( numCols );
wxGRIDTABLE_NOTIFY_COLS_INSERTED,
pos,
numCols );
-
+
GetView()->ProcessTableMessage( msg );
}
"Call AppendRows() first") );
return FALSE;
}
-
+
for ( row = 0; row < curNumRows; row++ )
{
for ( n = 0; n < numCols; n++ )
wxGridTableMessage msg( this,
wxGRIDTABLE_NOTIFY_COLS_APPENDED,
numCols );
-
+
GetView()->ProcessTableMessage( msg );
}
size_t curNumRows = m_data.GetCount();
size_t curNumCols = ( curNumRows > 0 ? m_data[0].GetCount() : 0 );
-
+
if ( pos >= curNumCols )
{
- wxLogError( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
- "Pos value is invalid for present table with %d cols"),
- pos, numCols, curNumCols );
- return FALSE;
+ wxLogError( wxT("Called wxGridStringTable::DeleteCols(pos=%d, N=%d)...\n"
+ "Pos value is invalid for present table with %d cols"),
+ pos, numCols, curNumCols );
+ return FALSE;
}
if ( numCols > curNumCols - pos )
{
- numCols = curNumCols - pos;
+ numCols = curNumCols - pos;
}
for ( row = 0; row < curNumRows; row++ )
wxGRIDTABLE_NOTIFY_COLS_DELETED,
pos,
numCols );
-
+
GetView()->ProcessTableMessage( msg );
}
- return TRUE;
+ return TRUE;
}
wxString wxGridStringTable::GetRowLabelValue( int row )
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC_CLASS( wxGridTextCtrl, wxTextCtrl )
-
+
BEGIN_EVENT_TABLE( wxGridTextCtrl, wxTextCtrl )
EVT_KEY_DOWN( wxGridTextCtrl::OnKeyDown )
END_EVENT_TABLE()
ev.Skip();
}
break;
-
+
default:
ev.Skip();
}
IMPLEMENT_DYNAMIC_CLASS( wxGrid, wxPanel )
-
+
BEGIN_EVENT_TABLE( wxGrid, wxPanel )
EVT_PAINT( wxGrid::OnPaint )
EVT_SIZE( wxGrid::OnSize )
EVT_COMMAND_SCROLL( wxGRID_HORIZSCROLL, wxGrid::OnGridScroll)
EVT_COMMAND_SCROLL( wxGRID_VERTSCROLL, wxGrid::OnGridScroll)
END_EVENT_TABLE()
-
+
wxGrid::~wxGrid()
{
//
m_topEditCtrlEnabled = FALSE;
m_topEditCtrl = new wxGridTextCtrl( this,
- FALSE,
- wxGRID_TOPCTRL,
- "",
- wxPoint(10, 10),
- wxSize(WXGRID_DEFAULT_TOPEDIT_WIDTH,
+ FALSE,
+ wxGRID_TOPCTRL,
+ "",
+ wxPoint(10, 10),
+ wxSize(WXGRID_DEFAULT_TOPEDIT_WIDTH,
WXGRID_DEFAULT_TOPEDIT_HEIGHT),
- wxTE_MULTILINE );
- m_topEditCtrl->Show( FALSE );
+ wxTE_MULTILINE );
+ m_topEditCtrl->Show( FALSE );
if ( m_numRows <= 0 )
m_numRows = WXGRID_DEFAULT_NUMBER_ROWS;
//
m_labelFont = this->GetFont();
m_labelFont.SetWeight( m_labelFont.GetWeight() + 2 );
-
+
m_rowLabelHorizAlign = wxLEFT;
m_rowLabelVertAlign = wxCENTRE;
m_rowBottoms.Add( 0 ); // set by CalcDimensions()
}
m_sumRowHeights = m_defaultRowHeight * m_numRows;
-
+
m_colWidths.Alloc( m_numCols );
m_colRights.Alloc( m_numRows );
m_sumColWidths = 0;
m_colRights.Add( 0 ); // set by CalcDimensions()
}
m_sumColWidths = m_defaultColWidth * m_numCols;
-
+
// TODO: improve this ?
//
m_defaultCellFont = this->GetFont();
-
+
m_gridLineColour = wxColour( 0, 0, 255 );
m_gridLinesEnabled = TRUE;
-
+
m_scrollBarWidth = WXGRID_DEFAULT_SCROLLBAR_WIDTH;
m_horizScrollBar = new wxScrollBar( this,
wxPoint(0, 0),
wxSize(10, 10),
wxHORIZONTAL);
-
+
m_vertScrollBar = new wxScrollBar( this,
wxGRID_VERTSCROLL,
wxPoint(0, 0),
m_scrollPosX = 0;
m_scrollPosY = 0;
m_wholeColsVisible = 0;
- m_wholeRowsVisible = 0;
+ m_wholeRowsVisible = 0;
m_firstPaint = TRUE;
m_inOnKeyDown = FALSE;
m_batchCount = 0;
-
+
m_cursorMode = WXGRID_CURSOR_DEFAULT;
m_dragLastPos = -1;
m_dragRowOrCol = -1;
m_selectedTopLeft = wxGridNoCellCoords;
m_selectedBottomRight = wxGridNoCellCoords;
-
+
m_editable = TRUE; // default for whole grid
// TODO: extend this to other types of controls
, wxTE_MULTILINE | wxTE_NO_VSCROLL
#endif
);
-
- m_cellEditCtrl->Show( FALSE );
+
+ m_cellEditCtrl->Show( FALSE );
m_cellEditCtrlEnabled = TRUE;
- m_editCtrlType = wxGRID_TEXTCTRL;
-
+ m_editCtrlType = wxGRID_TEXTCTRL;
+
// This is here in case OnSize does not get called when the grid is
// displayed
//
{
int ctrlW, ctrlH;
m_topEditCtrl->GetSize( &ctrlW, &ctrlH );
-
+
m_top = ctrlH + 20;
}
else
}
}
-
+
// calculate the coords of row bottom edges and col right edges
//
int bottom = m_top + m_colLabelHeight;
{
right += m_colWidths[i];
m_colRights[i] = right;
- }
+ }
+
-
// check how many rows and cols are visible
//
m_wholeRowsVisible = 0;
// A partial col doesn't count, we still have to scroll to
// see the rest of it
if ( m_colRights[i] + vertScrollBarWidth > cw ) break;
-
+
m_wholeColsVisible++ ;
}
}
-
+
if ( m_vertScrollBar )
{
if ( !vertScrollBarWidth )
wxMax(m_wholeRowsVisible, 1),
(m_wholeRowsVisible == 0 ? 1 : m_numRows),
wxMax(m_wholeRowsVisible, 1) );
-
+
m_vertScrollBar->SetSize( cw - m_scrollBarWidth,
m_top,
m_scrollBarWidth,
ch - m_top - horizScrollBarHeight);
}
}
-
+
if ( m_horizScrollBar )
{
if ( !horizScrollBarHeight )
bool wxGrid::Redimension( wxGridTableMessage& msg )
{
int i;
-
+
switch ( msg.GetId() )
{
case wxGRIDTABLE_NOTIFY_ROWS_INSERTED:
m_numRows = 0;
m_rowHeights.Clear();
m_rowBottoms.Clear();
-#endif
+#endif
m_currentCellCoords = wxGridNoCellCoords;
}
else if ( m_currentCellCoords.GetCol() >= m_numCols )
// ----- event handlers
//
-// Generate a grid event based on a mouse event and
+// Generate a grid event based on a mouse event and
// return the result of ProcessEvent()
//
bool wxGrid::SendEvent( const wxEventType type,
- int row, int col,
- wxMouseEvent& mouseEv )
+ int row, int col,
+ wxMouseEvent& mouseEv )
{
if ( type == EVT_GRID_ROW_SIZE ||
- type == EVT_GRID_COL_SIZE )
+ type == EVT_GRID_COL_SIZE )
{
- int rowOrCol = (row == -1 ? col : row);
+ int rowOrCol = (row == -1 ? col : row);
- wxGridSizeEvent gridEvt( GetId(),
- type,
- this,
- rowOrCol,
- mouseEv.GetX(), mouseEv.GetY(),
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ wxGridSizeEvent gridEvt( GetId(),
+ type,
+ this,
+ rowOrCol,
+ mouseEv.GetX(), mouseEv.GetY(),
+ mouseEv.ControlDown(),
+ mouseEv.ShiftDown(),
+ mouseEv.AltDown(),
+ mouseEv.MetaDown() );
- return GetEventHandler()->ProcessEvent(gridEvt);
+ return GetEventHandler()->ProcessEvent(gridEvt);
}
else if ( type == EVT_GRID_RANGE_SELECT )
{
- wxGridRangeSelectEvent gridEvt( GetId(),
- type,
- this,
- m_selectedTopLeft,
- m_selectedBottomRight,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ wxGridRangeSelectEvent gridEvt( GetId(),
+ type,
+ this,
+ m_selectedTopLeft,
+ m_selectedBottomRight,
+ mouseEv.ControlDown(),
+ mouseEv.ShiftDown(),
+ mouseEv.AltDown(),
+ mouseEv.MetaDown() );
- return GetEventHandler()->ProcessEvent(gridEvt);
+ return GetEventHandler()->ProcessEvent(gridEvt);
}
else
{
- wxGridEvent gridEvt( GetId(),
- type,
- this,
- row, col,
- mouseEv.GetX(), mouseEv.GetY(),
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ wxGridEvent gridEvt( GetId(),
+ type,
+ this,
+ row, col,
+ mouseEv.GetX(), mouseEv.GetY(),
+ mouseEv.ControlDown(),
+ mouseEv.ShiftDown(),
+ mouseEv.AltDown(),
+ mouseEv.MetaDown() );
- return GetEventHandler()->ProcessEvent(gridEvt);
+ return GetEventHandler()->ProcessEvent(gridEvt);
}
}
// of ProcessEvent().
//
bool wxGrid::SendEvent( const wxEventType type,
- int row, int col )
+ int row, int col )
{
if ( type == EVT_GRID_ROW_SIZE ||
- type == EVT_GRID_COL_SIZE )
+ type == EVT_GRID_COL_SIZE )
{
- int rowOrCol = (row == -1 ? col : row);
+ int rowOrCol = (row == -1 ? col : row);
- wxGridSizeEvent gridEvt( GetId(),
- type,
- this,
- rowOrCol );
+ wxGridSizeEvent gridEvt( GetId(),
+ type,
+ this,
+ rowOrCol );
- return GetEventHandler()->ProcessEvent(gridEvt);
+ return GetEventHandler()->ProcessEvent(gridEvt);
}
else
{
- wxGridEvent gridEvt( GetId(),
- type,
- this,
- row, col );
+ wxGridEvent gridEvt( GetId(),
+ type,
+ this,
+ row, col );
- return GetEventHandler()->ProcessEvent(gridEvt);
+ return GetEventHandler()->ProcessEvent(gridEvt);
}
}
int cw, ch;
GetClientSize( &cw, &ch );
dc.SetClippingRegion( 0, 0, cw - vs, ch - hs );
-
+
HideCurrentCellHighlight( dc );
-
+
DrawLabelAreas( dc );
DrawColLabels( dc );
DrawRowLabels( dc );
{
if ( m_currentCellCoords == wxGridNoCellCoords )
m_currentCellCoords.Set(0, 0);
-
+
SetEditControlValue();
ShowCellEditControl();
m_firstPaint = FALSE;
int x = ev.GetX();
int y = ev.GetY();
int row, col;
-
+
// ------------------------------------------------------------
//
// Mouse dragging
if ( ev.Dragging() )
{
m_isDragging = TRUE;
-
+
if ( ev.LeftIsDown() )
{
switch( m_cursorMode )
{
if ( !IsSelection() )
{
- SelectBlock( cellCoords, cellCoords );
- }
- else
- {
+ SelectBlock( cellCoords, cellCoords );
+ }
+ else
+ {
// check for the mouse being outside the cell area
// (we still want to let the user grow the selected block)
//
else
cellCoords.SetCol( m_scrollPosX );
}
-
+
if ( cellCoords.GetRow() == -1 )
{
if ( y >= m_bottom )
else
cellCoords.SetRow( m_scrollPosY );
}
-
+
if ( !IsInSelection( cellCoords ) )
- SelectBlock( m_currentCellCoords, cellCoords );
- }
+ SelectBlock( m_currentCellCoords, cellCoords );
+ }
}
}
break;
}
dc.DrawLine( m_left, ev.GetY(),
m_right, ev.GetY());
-
+
m_dragLastPos = ev.GetY();
}
break;
-
+
case WXGRID_CURSOR_RESIZE_COL:
{
wxClientDC dc(this);
}
dc.DrawLine( ev.GetX(), m_top,
ev.GetX(), m_bottom );
-
+
m_dragLastPos = ev.GetX();
}
break;
}
m_isDragging = FALSE;
-
+
// ------------------------------------------------------------
//
// Left mouse button down
row = -1;
col = -1;
wxGridCellCoords cellCoords;
-
+
switch( XYToArea( x, y ) )
{
case WXGRID_ROWLABEL:
break;
default:
-#if 0
+#if 0
wxLogMessage( "outside grid area" );
-#endif
+#endif
break;
}
}
row = -1;
col = -1;
wxGridCellCoords cellCoords;
-
+
switch( XYToArea( x, y ) )
{
case WXGRID_ROWLABEL:
{
// leave both row and col as -1
//
- SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev );
+ SendEvent( EVT_GRID_LABEL_LEFT_DCLICK, row, col, ev );
}
break;
break;
default:
-#if 0
+#if 0
wxLogMessage( "outside grid area" );
-#endif
+#endif
break;
}
}
//
else if ( ev.LeftUp() )
{
- switch ( m_cursorMode )
- {
- case WXGRID_CURSOR_RESIZE_ROW:
- {
- if ( m_dragLastPos >= 0 )
- {
- // erase the last line and resize the row
- //
- wxClientDC dc( this );
- dc.SetLogicalFunction( wxINVERT );
- dc.DrawLine( m_left, m_dragLastPos,
- m_right, m_dragLastPos );
- HideCellEditControl();
- int top = m_top + m_colLabelHeight;
- if ( m_dragRowOrCol > 0 )
- top = m_rowBottoms[m_dragRowOrCol-1];
+ switch ( m_cursorMode )
+ {
+ case WXGRID_CURSOR_RESIZE_ROW:
+ {
+ if ( m_dragLastPos >= 0 )
+ {
+ // erase the last line and resize the row
+ //
+ wxClientDC dc( this );
+ dc.SetLogicalFunction( wxINVERT );
+ dc.DrawLine( m_left, m_dragLastPos,
+ m_right, m_dragLastPos );
+ HideCellEditControl();
+ int top = m_top + m_colLabelHeight;
+ if ( m_dragRowOrCol > 0 )
+ top = m_rowBottoms[m_dragRowOrCol-1];
m_sumRowHeights -= m_rowHeights[ m_dragRowOrCol ];
- m_rowHeights[m_dragRowOrCol] = wxMax( ev.GetY() - top,
- WXGRID_MIN_ROW_HEIGHT );
+ m_rowHeights[m_dragRowOrCol] = wxMax( ev.GetY() - top,
+ WXGRID_MIN_ROW_HEIGHT );
m_sumRowHeights += m_rowHeights[ m_dragRowOrCol ];
- CalcDimensions();
- ShowCellEditControl();
- Refresh();
-
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, ev );
- }
- }
- break;
-
- case WXGRID_CURSOR_RESIZE_COL:
- {
- if ( m_dragLastPos >= 0 )
- {
- // erase the last line and resize the col
- //
- wxClientDC dc( this );
- dc.SetLogicalFunction( wxINVERT );
- dc.DrawLine( m_left, m_dragLastPos,
- m_right, m_dragLastPos );
- HideCellEditControl();
- int left = m_left + m_rowLabelWidth;
- if ( m_dragRowOrCol > 0 )
- left = m_colRights[m_dragRowOrCol-1];
+ CalcDimensions();
+ ShowCellEditControl();
+ Refresh();
+
+ // Note: we are ending the event *after* doing
+ // default processing in this case
+ //
+ SendEvent( EVT_GRID_ROW_SIZE, m_dragRowOrCol, -1, ev );
+ }
+ }
+ break;
+
+ case WXGRID_CURSOR_RESIZE_COL:
+ {
+ if ( m_dragLastPos >= 0 )
+ {
+ // erase the last line and resize the col
+ //
+ wxClientDC dc( this );
+ dc.SetLogicalFunction( wxINVERT );
+ dc.DrawLine( m_left, m_dragLastPos,
+ m_right, m_dragLastPos );
+ HideCellEditControl();
+ int left = m_left + m_rowLabelWidth;
+ if ( m_dragRowOrCol > 0 )
+ left = m_colRights[m_dragRowOrCol-1];
m_sumColWidths -= m_colWidths[m_dragRowOrCol];
- m_colWidths[m_dragRowOrCol] = wxMax( ev.GetX() - left,
- WXGRID_MIN_COL_WIDTH );
+ m_colWidths[m_dragRowOrCol] = wxMax( ev.GetX() - left,
+ WXGRID_MIN_COL_WIDTH );
m_sumColWidths += m_colWidths[m_dragRowOrCol];
- CalcDimensions();
- ShowCellEditControl();
- Refresh();
-
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, ev );
- }
- }
- break;
-
- case WXGRID_CURSOR_SELECT_CELL:
- {
- if ( IsSelection() )
- {
- // Note: we are ending the event *after* doing
- // default processing in this case
- //
- SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, ev );
- }
- }
- break;
- }
-
- m_dragLastPos = -1;
+ CalcDimensions();
+ ShowCellEditControl();
+ Refresh();
+
+ // Note: we are ending the event *after* doing
+ // default processing in this case
+ //
+ SendEvent( EVT_GRID_COL_SIZE, -1, m_dragRowOrCol, ev );
+ }
+ }
+ break;
+
+ case WXGRID_CURSOR_SELECT_CELL:
+ {
+ if ( IsSelection() )
+ {
+ // Note: we are ending the event *after* doing
+ // default processing in this case
+ //
+ SendEvent( EVT_GRID_RANGE_SELECT, -1, -1, ev );
+ }
+ }
+ break;
+ }
+
+ m_dragLastPos = -1;
}
// ------------------------------------------------------------
//
//
else if ( ev.RightDown() )
{
- row = -1;
- col = -1;
- wxGridCellCoords cellCoords;
-
- switch( XYToArea( x, y ) )
- {
-
- case WXGRID_ROWLABEL:
- {
- row = YToRow(y);
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
- {
+ row = -1;
+ col = -1;
+ wxGridCellCoords cellCoords;
+
+ switch( XYToArea( x, y ) )
+ {
+
+ case WXGRID_ROWLABEL:
+ {
+ row = YToRow(y);
+ if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
+ {
// TODO: default processing ?
}
}
case WXGRID_COLLABEL:
{
col = XToCol(x);
- if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
+ if ( !SendEvent( EVT_GRID_LABEL_RIGHT_CLICK, row, col, ev ) )
{
// TODO: default processing ?
}
break;
default:
-#if 0
+#if 0
wxLogMessage( "outside grid area" );
-#endif
+#endif
break;
}
}
//
else if ( ev.RightDClick() )
{
- row = -1;
- col = -1;
- wxGridCellCoords cellCoords;
-
- switch( XYToArea( x, y ) )
- {
-
- case WXGRID_ROWLABEL:
- {
- row = YToRow(y);
- SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
+ row = -1;
+ col = -1;
+ wxGridCellCoords cellCoords;
+
+ switch( XYToArea( x, y ) )
+ {
+
+ case WXGRID_ROWLABEL:
+ {
+ row = YToRow(y);
+ SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
}
break;
case WXGRID_COLLABEL:
{
col = XToCol(x);
- SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
+ SendEvent( EVT_GRID_LABEL_RIGHT_DCLICK, row, col, ev );
}
break;
break;
default:
-#if 0
+#if 0
wxLogMessage( "outside grid area" );
-#endif
+#endif
break;
}
}
}
}
break;
- }
+ }
}
}
}
m_inOnKeyDown = TRUE;
-
+
// propagate the event up and see if it gets processed
//
wxWindow *parent = GetParent();
wxKeyEvent keyEvt( ev );
keyEvt.SetEventObject( parent );
-
+
if ( !parent->GetEventHandler()->ProcessEvent( keyEvt ) )
{
// try local handlers
MoveCursorUp();
}
break;
-
+
case WXK_DOWN:
if ( ev.ControlDown() )
{
ev.Skip();
}
break;
-
+
case WXK_END:
if ( ev.ControlDown() )
{
ev.Skip();
}
break;
-
+
case WXK_PRIOR:
MovePageUp();
break;
case WXK_NEXT:
MovePageDown();
break;
-
+
default:
// now try the cell edit control
//
((wxTextCtrl *)m_topEditCtrl)->
SetValue(((wxTextCtrl *)ctrl)->GetValue());
break;
-
+
case wxGRID_COMBOBOX:
((wxComboBox *)m_topEditCtrl)->
SetValue(((wxComboBox *)ctrl)->GetValue());
((wxTextCtrl *)m_cellEditCtrl)->
SetValue(((wxTextCtrl *)ctrl)->GetValue());
break;
-
+
case wxGRID_COMBOBOX:
((wxComboBox *)m_cellEditCtrl)->
SetValue(((wxComboBox *)ctrl)->GetValue());
}
else
{
- // in the case when in-place editing is turned off we just want to
+ // in the case when in-place editing is turned off we just want to
// echo the text changes in the cell but not yet update the grid table
//
switch ( m_editCtrlType )
case wxGRID_TEXTCTRL:
DrawCellValue( m_currentCellCoords, ((wxTextCtrl *)ctrl)->GetValue() );
break;
-
+
case wxGRID_COMBOBOX:
DrawCellValue( m_currentCellCoords, ((wxComboBox *)ctrl)->GetValue() );
break;
wxWindow *parent = GetParent();
wxScrollEvent scrollEvt( ev );
if (parent->GetEventHandler()->ProcessEvent( scrollEvt )) return;
-
+
HideCellEditControl();
if ( ev.GetEventObject() == m_horizScrollBar )
void wxGrid::ShowCellEditControl()
{
wxRect rect;
-
- if ( IsCellEditControlEnabled() )
+
+ if ( IsCellEditControlEnabled() )
{
if ( !IsVisible( m_currentCellCoords ) )
{
else
{
rect = CellToRect( m_currentCellCoords );
-
+
m_cellEditCtrl->SetSize( rect );
m_cellEditCtrl->Show( TRUE );
// TODO: anything ???
//
break;
-
+
case wxGRID_COMBOBOX:
// TODO: anything ???
//
// TODO: implement this
//
break;
-
+
case wxGRID_COMBOBOX:
// TODO: implement this
//
// TODO: implement this
//
break;
-
+
case wxGRID_COMBOBOX:
// TODO: implement this
//
{
if ( m_table )
{
- wxWindow *ctrl = (wxWindow *)NULL;
+ wxWindow *ctrl = (wxWindow *)NULL;
if ( IsCellEditControlEnabled() )
{
{
return;
}
-
+
bool valueChanged = FALSE;
-
+
switch ( m_editCtrlType )
{
case wxGRID_TEXTCTRL:
// TODO: implement this
//
break;
-
+
case wxGRID_COMBOBOX:
// TODO: implement this
//
break;
}
-
+
if ( valueChanged )
{
SendEvent( EVT_GRID_CELL_CHANGE,
int wxGrid::YToRow( int y )
{
int i;
-
+
if ( y > m_top + m_colLabelHeight )
{
for ( i = m_scrollPosY; i < m_numRows; i++ )
int wxGrid::XToCol( int x )
{
int i;
-
+
if ( x > m_left + m_rowLabelWidth )
{
for ( i = m_scrollPosX; i < m_numCols; i++ )
int wxGrid::YToEdgeOfRow( int y )
{
int i, d;
-
+
if ( y > m_top + m_colLabelHeight )
{
for ( i = m_scrollPosY; i < m_numRows; i++ )
}
return -1;
-
+
}
int wxGrid::XToEdgeOfCol( int x )
{
int i, d;
-
+
if ( x > m_left + m_rowLabelWidth )
{
for ( i = m_scrollPosX; i < m_numCols; i++ )
}
return -1;
-
+
}
}
return rect;
-}
+}
bool wxGrid::MoveCursorUp()
if ( !IsVisible( m_currentCellCoords ) )
MakeCellVisible( m_currentCellCoords );
-
+
return TRUE;
}
if ( !IsVisible( m_currentCellCoords ) )
MakeCellVisible( m_currentCellCoords );
-
+
return TRUE;
}
if ( !IsVisible( m_currentCellCoords ) )
MakeCellVisible( m_currentCellCoords );
-
+
return TRUE;
}
SelectCell( row, m_currentCellCoords.GetCol() );
return TRUE;
}
-
+
return FALSE;
}
{
return FALSE;
}
-
+
// m_scrollPosY will have been updated
//
SelectCell( m_scrollPosY, m_currentCellCoords.GetCol() );
return TRUE;
}
-
+
return FALSE;
}
{
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
-
+
if ( m_table->IsEmptyCell(row, col) )
{
// starting in an empty cell: find the next block of
}
}
}
-
+
SelectCell( row, col );
if ( !IsVisible( m_currentCellCoords ) )
{
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
-
+
if ( m_table->IsEmptyCell(row, col) )
{
// starting in an empty cell: find the next block of
}
}
}
-
+
SelectCell( row, col );
if ( !IsVisible( m_currentCellCoords ) )
{
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
-
+
if ( m_table->IsEmptyCell(row, col) )
{
// starting in an empty cell: find the next block of
}
}
}
-
+
SelectCell( row, col );
if ( !IsVisible( m_currentCellCoords ) )
{
int row = m_currentCellCoords.GetRow();
int col = m_currentCellCoords.GetCol();
-
+
if ( m_table->IsEmptyCell(row, col) )
{
// starting in an empty cell: find the next block of
}
}
}
-
+
SelectCell( row, col );
if ( !IsVisible( m_currentCellCoords ) )
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush( wxBrush(GetLabelBackgroundColour(), wxSOLID) );
-
+
dc.DrawRectangle( m_left, m_top,
cw - m_left, m_colLabelHeight );
-
+
dc.DrawRectangle( m_left, m_top,
m_rowLabelWidth, ch - m_top );
}
int labelLeft = m_left + m_rowLabelWidth;
int i;
-
+
for ( i = m_scrollPosX; i < m_numCols; i++ )
{
if ( labelLeft > cw) break;
rect.x = 1 + labelLeft;
rect.width = m_colWidths[i];
DrawColLabel( dc, rect, i );
-
+
labelLeft += m_colWidths[i];
}
}
GetClientSize( &cw, &ch );
dc.SetPen( *wxBLACK_PEN );
-
+
// horizontal lines
//
dc.DrawLine( m_left, m_top, cw, m_top );
dc.DrawLine(colLeft + 1, m_top + 1,
colLeft + 1, m_top + m_colLabelHeight);
-
+
colLeft += m_colWidths[i];
}
}
rect2.y += 2;
rect2.width -= 5;
rect2.height -= 4;
-
+
dc.SetBackgroundMode( wxTRANSPARENT );
dc.SetTextBackground( GetLabelBackgroundColour() );
dc.SetTextForeground( GetLabelTextColour() );
dc.SetFont( GetLabelFont() );
-
+
int hAlign, vAlign;
GetColLabelAlignment( &hAlign, &vAlign );
DrawTextRectangle( dc, GetColLabelValue( col ), rect2, hAlign, vAlign );
int labelTop = m_top + m_colLabelHeight;
int i;
-
+
for ( i = m_scrollPosY; i < m_numRows; i++ )
{
if ( labelTop > ch ) break;
rect.y = 1 + labelTop;
rect.height = m_rowHeights[i];
DrawRowLabel( dc, rect, i );
-
+
labelTop += m_rowHeights[i];
}
}
GetClientSize( &cw, &ch );
dc.SetPen( *wxBLACK_PEN );
-
+
// vertical lines
//
dc.DrawLine( m_left, m_top, m_left, ch );
dc.DrawLine( m_left + 1, rowTop + 1,
m_left + 1, rowTop + m_rowHeights[i] );
-
+
rowTop += m_rowHeights[i];
}
}
rect2.y += 2;
rect2.width -= 5;
rect2.height -= 4;
-
+
dc.SetBackgroundMode( wxTRANSPARENT );
dc.SetTextBackground( GetLabelBackgroundColour() );
dc.SetTextForeground( GetLabelTextColour() );
dc.SetFont( GetLabelFont() );
-
+
int hAlign, vAlign;
GetRowLabelAlignment( &hAlign, &vAlign );
DrawTextRectangle( dc, GetRowLabelValue( row ), rect2, hAlign, vAlign );
void wxGrid::DrawGridLines( wxDC& dc )
{
if ( !m_gridLinesEnabled || !m_numRows || !m_numCols ) return;
-
+
int i;
int cw, ch;
GetClientSize(&cw, &ch);
void wxGrid::DrawCells( wxDC& dc )
{
if ( !m_numRows || !m_numCols ) return;
-
+
int row, col;
-
+
int cw, ch;
GetClientSize( &cw, &ch );
-
+
wxRect rect;
if ( m_table )
rect2.y += 1;
rect2.width -= 2;
rect2.height -= 2;
-
+
dc.SetBackgroundMode( wxSOLID );
-
+
if ( IsInSelection( row, col ) )
{
// TODO: improve this
rect2.y += 2;
rect2.width -= 5;
rect2.height -= 4;
-
+
dc.SetBackgroundMode( wxTRANSPARENT );
if ( IsInSelection( row, col ) )
dc.SetTextForeground( GetCellTextColour(row, col) );
}
dc.SetFont( GetCellFont(row, col) );
-
+
int hAlign, vAlign;
GetCellAlignment( row, col, &hAlign, &vAlign );
-
+
if ( useValueArg )
{
DrawTextRectangle( dc, value, rect2, hAlign, vAlign );
}
-// this is used to echo text being entered into the top edit control when
+// this is used to echo text being entered into the top edit control when
// in-place editing is turned off
//
void wxGrid::DrawCellValue( const wxGridCellCoords& coords, const wxString& value )
int cw, ch;
GetClientSize( &cw, &ch );
-
+
x = m_colRights[col] - m_colWidths[col];
if ( x >= cw ) return;
-
+
y = m_rowBottoms[row] - m_rowHeights[row];
if ( y >= ch ) return;
if ( !GetBatchCount() )
{
if ( !IsVisible( wxGridCellCoords(row, col) ) ) return;
-
+
int cw, ch;
GetClientSize( &cw, &ch );
-
+
wxRect rect( CellToRect( row, col ) );
if ( m_table )
long textWidth, textHeight;
long lineWidth, lineHeight;
wxArrayString lines;
-
+
// see if we are already clipping
//
wxRect clipRect;
{
GetTextBoxSize( dc, lines, &textWidth, &textHeight );
dc.GetTextExtent( lines[0], &lineWidth, &lineHeight );
-
+
float x, y;
switch ( horizAlign )
{
case wxRIGHT:
- x = rect.x + (rect.width - textWidth - 1.0);
+ x = rect.x + (rect.width - textWidth - 1);
break;
case wxCENTRE:
- x = rect.x + ((rect.width - textWidth)/2.0);
+ x = rect.x + ((rect.width - textWidth)/2);
break;
case wxLEFT:
default:
- x = rect.x + 1.0;
+ x = rect.x + 1;
break;
}
break;
case wxCENTRE:
- y = rect.y + ((rect.height - textHeight)/2.0);
+ y = rect.y + ((rect.height - textHeight)/2);
break;
case wxTOP:
default:
- y = rect.y + 1.0;
+ y = rect.y + 1;
break;
}
y += lineHeight;
}
}
-
+
dc.DestroyClippingRegion();
if (alreadyClipping) dc.SetClippingRegion( clipRect );
}
bool wxGrid::SetModelValues()
{
int row, col;
-
+
if ( m_table )
{
for ( row = m_scrollPosY; row < m_numRows; row++ )
return TRUE;
}
-
+
return FALSE;
}
{
m_numRows = numRows;
m_numCols = numCols;
-
+
m_table = new wxGridStringTable( m_numRows, m_numCols );
m_table->SetView( this );
Init();
m_created = TRUE;
}
-
+
return m_created;
}
wxLogError( wxT("Called wxGrid::InsertRows() before calling CreateGrid()") );
return FALSE;
}
-
+
if ( m_table )
{
bool ok = m_table->InsertRows( pos, numRows );
//
if ( ok )
{
- if ( m_numCols == 0 )
+ if ( m_numCols == 0 )
{
m_table->AppendCols( WXGRID_DEFAULT_NUMBER_COLS );
//
// we should remember what the last non-zero number of cols was ?
//
}
-
+
if ( m_currentCellCoords == wxGridNoCellCoords )
{
// if we have just inserted cols into an empty grid the current
// cell will be undefined...
//
- SelectCell( 0, 0 );
+ SelectCell( 0, 0 );
}
-
+
if ( !GetBatchCount() ) Refresh();
}
bool wxGrid::AppendRows( int numRows, bool WXUNUSED(updateLabels) )
{
// TODO: something with updateLabels flag
-
+
if ( !m_created )
{
wxLogError( wxT("Called wxGrid::AppendRows() before calling CreateGrid()") );
return FALSE;
}
-
+
if ( m_table && m_table->AppendRows( numRows ) )
{
if ( m_currentCellCoords == wxGridNoCellCoords )
// if we have just inserted cols into an empty grid the current
// cell will be undefined...
//
- SelectCell( 0, 0 );
+ SelectCell( 0, 0 );
}
-
+
// the table will have sent the results of the append row
// operation to this view object as a grid table message
//
wxLogError( wxT("Called wxGrid::DeleteRows() before calling CreateGrid()") );
return FALSE;
}
-
+
if ( m_table && m_table->DeleteRows( pos, numRows ) )
{
// the table will have sent the results of the delete row
SetEditControlValue();
else
HideCellEditControl();
-
+
if ( !GetBatchCount() ) Refresh();
return TRUE;
}
bool wxGrid::InsertCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
{
// TODO: something with updateLabels flag
-
+
if ( !m_created )
{
wxLogError( wxT("Called wxGrid::InsertCols() before calling CreateGrid()") );
{
HideCellEditControl();
bool ok = m_table->InsertCols( pos, numCols );
-
+
// the table will have sent the results of the insert col
// operation to this view object as a grid table message
//
// if we have just inserted cols into an empty grid the current
// cell will be undefined...
//
- SelectCell( 0, 0 );
+ SelectCell( 0, 0 );
}
if ( !GetBatchCount() ) Refresh();
}
-
+
SetEditControlValue();
return ok;
}
if ( !m_created )
{
- wxLogError( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
- return FALSE;
+ wxLogError( wxT("Called wxGrid::AppendCols() before calling CreateGrid()") );
+ return FALSE;
}
if ( m_table && m_table->AppendCols( numCols ) )
{
- // the table will have sent the results of the append col
- // operation to this view object as a grid table message
- //
+ // the table will have sent the results of the append col
+ // operation to this view object as a grid table message
+ //
if ( m_currentCellCoords == wxGridNoCellCoords )
{
// if we have just inserted cols into an empty grid the current
// cell will be undefined...
//
- SelectCell( 0, 0 );
+ SelectCell( 0, 0 );
}
- if ( !GetBatchCount() ) Refresh();
- return TRUE;
+ if ( !GetBatchCount() ) Refresh();
+ return TRUE;
}
else
{
- return FALSE;
+ return FALSE;
}
}
bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
{
// TODO: something with updateLabels flag
-
+
if ( !m_created )
{
wxLogError( wxT("Called wxGrid::DeleteCols() before calling CreateGrid()") );
return FALSE;
}
-
+
if ( m_table && m_table->DeleteCols( pos, numCols ) )
{
// the table will have sent the results of the delete col
SetEditControlValue();
else
HideCellEditControl();
-
+
if ( !GetBatchCount() ) Refresh();
return TRUE;
}
return FALSE;
}
}
-
+
if ( !m_editable ) HideCellEditControl();
m_topEditCtrlEnabled = m_editable;
m_cellEditCtrlEnabled = m_editable;
- if ( !m_editable ) ShowCellEditControl();
+ if ( !m_editable ) ShowCellEditControl();
}
}
if ( m_currentCellCoords != wxGridNoCellCoords )
SetEditControlValue();
-
+
ShowCellEditControl();
if ( !GetBatchCount() ) Refresh();
}
enable != m_cellEditCtrlEnabled )
{
wxClientDC dc( this );
-
+
HideCurrentCellHighlight( dc );
HideCellEditControl();
SaveEditControlValue();
-
+
m_cellEditCtrlEnabled = enable;
SetEditControlValue();
{
m_rowLabelHorizAlign = horiz;
}
-
+
if ( vert == wxTOP || vert == wxCENTRE || vert == wxBOTTOM )
{
m_rowLabelVertAlign = vert;
{
m_colLabelHorizAlign = horiz;
}
-
+
if ( vert == wxTOP || vert == wxCENTRE || vert == wxBOTTOM )
{
m_colLabelVertAlign = vert;
void wxGrid::SetGridLineColour( const wxColour& colour )
{
m_gridLineColour = colour;
-
+
wxClientDC dc( this );
DrawGridLines( dc );
}
{
// TODO: replace this temp test code
//
- return wxColour( 255, 255, 255 );
+ return wxColour( 255, 255, 255 );
}
wxColour wxGrid::GetDefaultCellTextColour()
{
// TODO: replace this temp test code
//
- return wxColour( 0, 0, 0 );
+ return wxColour( 0, 0, 0 );
}
wxColour wxGrid::GetCellTextColour( int WXUNUSED(row), int WXUNUSED(col) )
{
// TODO: replace this temp test code
//
- return wxColour( 0, 0, 0 );
+ return wxColour( 0, 0, 0 );
}
{
// TODO: replace this temp test code
//
- return wxColour( 0, 0, 0 );
+ return wxColour( 0, 0, 0 );
}
SetEditControlValue( s );
}
}
-}
+}
{
int lastX = m_scrollPosX;
int lastY = m_scrollPosY;
-
+
if ( row >= 0 && row < m_numRows &&
col >= 0 && col < m_numCols )
{
{
if ( m_selectedTopLeft.GetRow() > row )
m_selectedTopLeft.SetRow( row );
-
+
m_selectedTopLeft.SetCol( 0 );
-
+
if ( m_selectedBottomRight.GetRow() < row )
m_selectedBottomRight.SetRow( row );
-
+
m_selectedBottomRight.SetCol( m_numCols - 1 );
}
else
wxRect rect( SelectionToRect() );
if ( rect != wxGridNoCellRect ) Refresh( TRUE, &rect );
}
-
+
wxGridRangeSelectEvent gridEvt( GetId(),
EVT_GRID_RANGE_SELECT,
this,
void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol )
{
int temp;
-
+
if ( topRow > bottomRow )
{
temp = topRow;
this,
m_selectedTopLeft,
m_selectedBottomRight );
-
+
GetEventHandler()->ProcessEvent(gridEvt);
}
}
m_selectedTopLeft = wxGridNoCellCoords;
m_selectedBottomRight = wxGridNoCellCoords;
}
-}
+}
wxRect wxGrid::SelectionToRect()
{
rect = wxRect( m_left, m_top, 0, 0 );
}
-
+
cellRect = CellToRect( m_selectedBottomRight );
if ( cellRect != wxGridNoCellRect )
{
m_shift = shift;
m_alt = alt;
m_meta = meta;
-
+
SetEventObject(obj);
}
m_shift = shift;
m_alt = alt;
m_meta = meta;
-
+
SetEventObject(obj);
}
IMPLEMENT_DYNAMIC_CLASS( wxGridRangeSelectEvent, wxEvent )
wxGridRangeSelectEvent::wxGridRangeSelectEvent(int id, wxEventType type, wxObject* obj,
- const wxGridCellCoords& topLeft,
- const wxGridCellCoords& bottomRight,
- bool control, bool shift, bool alt, bool meta )
- : wxNotifyEvent( type, id )
+ const wxGridCellCoords& topLeft,
+ const wxGridCellCoords& bottomRight,
+ bool control, bool shift, bool alt, bool meta )
+ : wxNotifyEvent( type, id )
{
m_topLeft = topLeft;
m_bottomRight = bottomRight;