#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 ( (row = YToRow( y )) >= 0 )
{
if ( m_selection )
- {
- m_selection->SelectRow( row,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
- }
+ m_selection->SelectRow(row, event);
}
}
break;
{
if ( event.ShiftDown() )
{
- m_selection->SelectBlock( m_currentCellCoords.GetRow(),
- 0,
- row,
- GetNumberCols() - 1,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectBlock
+ (
+ m_currentCellCoords.GetRow(), 0,
+ row, GetNumberCols() - 1,
+ event
+ );
}
else
{
- m_selection->SelectRow( row,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectRow(row, event);
}
}
if ( (col = XToCol( x )) >= 0 )
{
if ( m_selection )
- {
- m_selection->SelectCol( col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
- }
+ m_selection->SelectCol(col, event);
}
}
break;
{
if ( event.ShiftDown() )
{
- m_selection->SelectBlock( 0,
- m_currentCellCoords.GetCol(),
- GetNumberRows() - 1, col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectBlock
+ (
+ 0, m_currentCellCoords.GetCol(),
+ GetNumberRows() - 1, col,
+ event
+ );
}
else
{
- m_selection->SelectCol( col,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectCol(col, event);
}
}
if ( m_winCapture )
{
- if (m_winCapture->HasCapture())
- m_winCapture->ReleaseMouse();
+ m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
{
if ( m_selection )
{
- m_selection->SelectBlock( m_currentCellCoords,
- coords,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->SelectBlock(m_currentCellCoords, coords, event);
m_selectedBlockCorner = coords;
}
}
{
if ( m_selection )
{
- m_selection->ToggleCellSelection( coords,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ m_selection->ToggleCellSelection(coords, event);
}
+
m_selectedBlockTopLeft = wxGridNoCellCoords;
m_selectedBlockBottomRight = wxGridNoCellCoords;
m_selectedBlockCorner = coords;
{
if (m_winCapture)
{
- if (m_winCapture->HasCapture())
- m_winCapture->ReleaseMouse();
+ m_winCapture->ReleaseMouse();
m_winCapture = NULL;
}
{
m_selection->SelectBlock( m_selectedBlockTopLeft,
m_selectedBlockBottomRight,
- event.ControlDown(),
- event.ShiftDown(),
- event.AltDown(),
- event.MetaDown() );
+ event );
}
m_selectedBlockTopLeft = wxGridNoCellCoords;
rowOrCol,
mouseEv.GetX() + GetRowLabelSize(),
mouseEv.GetY() + GetColLabelSize(),
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
m_selectedBlockTopLeft,
m_selectedBlockBottomRight,
true,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
pos.x,
pos.y,
false,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
mouseEv.GetX() + GetRowLabelSize(),
mouseEv.GetY() + GetColLabelSize(),
false,
- mouseEv.ControlDown(),
- mouseEv.ShiftDown(),
- mouseEv.AltDown(),
- mouseEv.MetaDown() );
+ mouseEv);
claimed = GetEventHandler()->ProcessEvent(gridEvt);
vetoed = !gridEvt.IsAllowed();
}
m_selection->SelectBlock(
m_selectedBlockTopLeft,
m_selectedBlockBottomRight,
- event.ControlDown(),
- true,
- event.AltDown(),
- event.MetaDown() );
+ event);
}
}
//
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();
}
}
void wxGrid::SelectRow( int row, bool addToSelected )
{
- if ( IsSelection() && !addToSelected )
+ if ( !m_selection )
+ return;
+
+ if ( !addToSelected )
ClearSelection();
- if ( m_selection )
- m_selection->SelectRow( row, false, addToSelected );
+ m_selection->SelectRow(row);
}
void wxGrid::SelectCol( int col, bool addToSelected )
{
- if ( IsSelection() && !addToSelected )
+ if ( !m_selection )
+ return;
+
+ if ( !addToSelected )
ClearSelection();
- if ( m_selection )
- m_selection->SelectCol( col, false, addToSelected );
+ m_selection->SelectCol(col);
}
-void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol,
- bool addToSelected )
+void wxGrid::SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol,
+ bool addToSelected)
{
- if ( IsSelection() && !addToSelected )
+ if ( !m_selection )
+ return;
+
+ if ( !addToSelected )
ClearSelection();
- if ( m_selection )
- m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol,
- false, addToSelected );
+ m_selection->SelectBlock(topRow, leftCol, bottomRow, rightCol);
}
void wxGrid::SelectAll()
wxGridEvent::wxGridEvent( int id, wxEventType type, wxObject* obj,
int row, int col, int x, int y, bool sel,
bool control, bool shift, bool alt, bool meta )
- : wxNotifyEvent( type, id )
+ : wxNotifyEvent( type, id ),
+ wxKeyboardState(control, shift, alt, meta)
{
- m_row = row;
- m_col = col;
- m_x = x;
- m_y = y;
- m_selecting = sel;
- m_control = control;
- m_shift = shift;
- m_alt = alt;
- m_meta = meta;
+ Init(row, col, x, y, sel);
SetEventObject(obj);
}
-
IMPLEMENT_DYNAMIC_CLASS( wxGridSizeEvent, wxNotifyEvent )
wxGridSizeEvent::wxGridSizeEvent( int id, wxEventType type, wxObject* obj,
int rowOrCol, int x, int y,
bool control, bool shift, bool alt, bool meta )
- : wxNotifyEvent( type, id )
+ : wxNotifyEvent( type, id ),
+ wxKeyboardState(control, shift, alt, meta)
{
- m_rowOrCol = rowOrCol;
- m_x = x;
- m_y = y;
- m_control = control;
- m_shift = shift;
- m_alt = alt;
- m_meta = meta;
+ Init(rowOrCol, x, y);
SetEventObject(obj);
}
const wxGridCellCoords& bottomRight,
bool sel, bool control,
bool shift, bool alt, bool meta )
- : wxNotifyEvent( type, id )
-{
- m_topLeft = topLeft;
- m_bottomRight = bottomRight;
- m_selecting = sel;
- m_control = control;
- m_shift = shift;
- m_alt = alt;
- m_meta = meta;
+ : wxNotifyEvent( type, id ),
+ wxKeyboardState(control, shift, alt, meta)
+{
+ Init(topLeft, bottomRight, sel);
SetEventObject(obj);
}