#include "wx/generic/gridsel.h"
-const wxChar wxGridNameStr[] = wxT("grid");
+const char wxGridNameStr[] = "grid";
#if defined(__WXMOTIF__)
#define WXUNUSED_MOTIF(identifier) WXUNUSED(identifier)
if ((ctrl || alt) && !(ctrl && alt))
return false;
- int key = 0;
- bool keyOk = true;
-
-#ifdef __WXGTK20__
- // If it's a F-Key or other special key then it shouldn't start the
- // editor.
- if (event.GetKeyCode() >= WXK_START)
- return false;
-#endif
#if wxUSE_UNICODE
// if the unicode key code is not really a unicode character (it may
// be a function key or etc., the platforms appear to always give us a
// small value in this case) then fallback to the ASCII key code but
// don't do anything for function keys or etc.
- key = event.GetUnicodeKey();
- if (key <= 127)
- {
- key = event.GetKeyCode();
- keyOk = (key <= 127);
- }
+ if ( event.GetUnicodeKey() > 127 && event.GetKeyCode() > 127 )
+ return false;
#else
- key = event.GetKeyCode();
- keyOk = (key <= 255);
+ if ( event.GetKeyCode() > 255 )
+ return false;
#endif
- return keyOk;
+ return true;
}
void wxGridCellEditor::StartingKey(wxKeyEvent& event)
m_data[row][col] = value;
}
-bool wxGridStringTable::IsEmptyCell( int row, int col )
-{
- wxCHECK_MSG( (row < GetNumberRows()) && (col < GetNumberCols()),
- true,
- _T("invalid row or column index in wxGridStringTable") );
-
- return (m_data[row][col] == wxEmptyString);
-}
-
void wxGridStringTable::Clear()
{
int row, col;
void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event )
{
- m_owner->GetEventHandler()->ProcessEvent( event );
+ if (!m_owner->GetEventHandler()->ProcessEvent( event ))
+ event.Skip();
}
//////////////////////////////////////////////////////////////////////
void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event )
{
- m_owner->GetEventHandler()->ProcessEvent( event );
+ if (!m_owner->GetEventHandler()->ProcessEvent( event ))
+ event.Skip();
}
//////////////////////////////////////////////////////////////////////
void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event )
{
- m_owner->GetEventHandler()->ProcessEvent(event);
+ if (!m_owner->GetEventHandler()->ProcessEvent(event))
+ event.Skip();
}
//////////////////////////////////////////////////////////////////////
wxGridCellCoordsArray dirtyCells = m_owner->CalcCellsExposed( reg );
m_owner->DrawGridCellArea( dc, dirtyCells );
+ m_owner->DrawGridSpace( dc );
+
m_owner->DrawAllGridLines( dc, reg );
- m_owner->DrawGridSpace( dc );
m_owner->DrawHighlight( dc, dirtyCells );
}
void wxGridWindow::OnMouseWheel( wxMouseEvent& event )
{
- m_owner->GetEventHandler()->ProcessEvent( event );
+ if (!m_owner->GetEventHandler()->ProcessEvent( event ))
+ event.Skip();
}
// This seems to be required for wxMotif/wxGTK otherwise the mouse
wxGrid::~wxGrid()
{
+ if ( m_winCapture )
+ m_winCapture->ReleaseMouse();
+
+ // Ensure that the editor control is destroyed before the grid is,
+ // otherwise we crash later when the editor tries to do something with the
+ // half destroyed grid
+ HideCellEditControl();
+
// Must do this or ~wxScrollHelper will pop the wrong event handler
SetTargetWindow(this);
ClearAttrCache();
m_gridLineColour = wxColour( 192,192,192 );
m_gridLinesEnabled = true;
+ m_gridLinesClipHorz =
+ m_gridLinesClipVert = true;
m_cellHighlightColour = *wxBLACK;
m_cellHighlightPenWidth = 2;
m_cellHighlightROPenWidth = 1;
m_colWidths.Add( m_defaultColWidth, m_numCols );
- int colRight = 0;
for ( int i = 0; i < m_numCols; i++ )
{
- colRight = ( GetColPos( i ) + 1 ) * m_defaultColWidth;
+ int colRight = ( GetColPos( i ) + 1 ) * m_defaultColWidth;
m_colRights.Add( colRight );
}
}
if ( m_winCapture )
{
- if (m_winCapture->HasCapture())
- m_winCapture->ReleaseMouse();
+ m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
{
if (m_winCapture)
{
- if (m_winCapture->HasCapture())
- m_winCapture->ReleaseMouse();
+ m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
//
void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) )
{
- if ( !m_gridLinesEnabled || !m_numRows || !m_numCols )
+ if ( !m_gridLinesEnabled )
return;
int top, bottom, left, right;
CalcUnscrolledPosition( cw, ch, &right, &bottom );
// avoid drawing grid lines past the last row and col
- //
- right = wxMin( right, GetColRight(GetColAt( m_numCols - 1 )) );
- bottom = wxMin( bottom, GetRowBottom(m_numRows - 1) );
+ if ( m_gridLinesClipHorz )
+ {
+ if ( !m_numCols )
+ return;
+
+ const int lastColRight = GetColRight(GetColAt(m_numCols - 1));
+ if ( right > lastColRight )
+ right = lastColRight;
+ }
+
+ if ( m_gridLinesClipVert )
+ {
+ if ( !m_numRows )
+ return;
+
+ const int lastRowBottom = GetRowBottom(m_numRows - 1);
+ if ( bottom > lastRowBottom )
+ bottom = lastRowBottom;
+ }
// no gridlines inside multicells, clip them out
int leftCol = GetColPos( internalXToCol(left) );
bool wxGrid::MovePageDown()
{
return DoMoveCursorByPage(
- wxGridForwardOperations(this, wxGridColumnOperations()));
+ wxGridForwardOperations(this, wxGridRowOperations()));
}
// helper of DoMoveCursorByBlock(): advance the cell coordinates using diroper
{
m_gridLineColour = colour;
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- DrawAllGridLines( dc, wxRegion() );
+ if ( GridLinesEnabled() )
+ RedrawGridLines();
}
}
}
}
+void wxGrid::RedrawGridLines()
+{
+ // the lines will be redrawn when the window is thawn
+ if ( GetBatchCount() )
+ return;
+
+ if ( GridLinesEnabled() )
+ {
+ wxClientDC dc( m_gridWin );
+ PrepareDC( dc );
+ DrawAllGridLines( dc, wxRegion() );
+ }
+ else // remove the grid lines
+ {
+ m_gridWin->Refresh();
+ }
+}
+
void wxGrid::EnableGridLines( bool enable )
{
if ( enable != m_gridLinesEnabled )
{
m_gridLinesEnabled = enable;
- if ( !GetBatchCount() )
- {
- if ( enable )
- {
- wxClientDC dc( m_gridWin );
- PrepareDC( dc );
- DrawAllGridLines( dc, wxRegion() );
- }
- else
- {
- m_gridWin->Refresh();
- }
- }
+ RedrawGridLines();
+ }
+}
+
+void wxGrid::DoClipGridLines(bool& var, bool clip)
+{
+ if ( clip != var )
+ {
+ var = clip;
+
+ if ( GridLinesEnabled() )
+ RedrawGridLines();
}
}