X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b1944ebcd065d61011e2a9187064089c3aef16aa..c989314692827562d3d2147ae880886b5eaa530e:/src/generic/grid.cpp?ds=sidebyside diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index d643c0ff7c..4957e2a461 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -96,6 +96,26 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxGridCellWithAttr, wxGridCellWithAttrArray); WX_DEFINE_OBJARRAY(wxGridCellCoordsArray) WX_DEFINE_OBJARRAY(wxGridCellWithAttrArray) +// ---------------------------------------------------------------------------- +// events +// ---------------------------------------------------------------------------- + +DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_CLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_CLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_LEFT_DCLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_RIGHT_DCLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_CLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_CLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_LEFT_DCLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_LABEL_RIGHT_DCLICK) +DEFINE_EVENT_TYPE(wxEVT_GRID_ROW_SIZE) +DEFINE_EVENT_TYPE(wxEVT_GRID_COL_SIZE) +DEFINE_EVENT_TYPE(wxEVT_GRID_RANGE_SELECT) +DEFINE_EVENT_TYPE(wxEVT_GRID_CELL_CHANGE) +DEFINE_EVENT_TYPE(wxEVT_GRID_SELECT_CELL) +DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_SHOWN) +DEFINE_EVENT_TYPE(wxEVT_GRID_EDITOR_HIDDEN) + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -112,6 +132,7 @@ private: void OnPaint( wxPaintEvent& event ); void OnMouseEvent( wxMouseEvent& event ); + void OnMouseWheel( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& event ); void OnKeyUp( wxKeyEvent& ); @@ -132,6 +153,7 @@ private: void OnPaint( wxPaintEvent &event ); void OnMouseEvent( wxMouseEvent& event ); + void OnMouseWheel( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& event ); void OnKeyUp( wxKeyEvent& ); @@ -151,6 +173,7 @@ private: wxGrid *m_owner; void OnMouseEvent( wxMouseEvent& event ); + void OnMouseWheel( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& event ); void OnKeyUp( wxKeyEvent& ); void OnPaint( wxPaintEvent& event ); @@ -183,6 +206,7 @@ private: wxGridColLabelWindow *m_colLabelWin; void OnPaint( wxPaintEvent &event ); + void OnMouseWheel( wxMouseEvent& event ); void OnMouseEvent( wxMouseEvent& event ); void OnKeyDown( wxKeyEvent& ); void OnKeyUp( wxKeyEvent& ); @@ -354,8 +378,15 @@ wxGridCellCoords wxGridNoCellCoords( -1, -1 ); wxRect wxGridNoCellRect( -1, -1, -1, -1 ); // scroll line size -// TODO: fixed so far - make configurable later (and also different for x/y) -static const size_t GRID_SCROLL_LINE = 10; +// TODO: this doesn't work at all, grid cells have different sizes and approx +// calculations don't work as because of the size mismatch scrollbars +// sometimes fail to be shown when they should be or vice versa +// +// The scroll bars may be a little flakey once in a while, but that is +// surely much less horrible than having scroll lines of only 1!!! +// -- Robin +static const size_t GRID_SCROLL_LINE = 15; // 1; + // the size of hash tables used a bit everywhere (the max number of elements // in these hash tables is the number of rows/columns) @@ -474,7 +505,7 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event) bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) { // accept the simple key presses, not anything with Ctrl/Alt/Meta - return !event.HasModifiers(); + return !(event.ControlDown() || event.AltDown()); } void wxGridCellEditor::StartingKey(wxKeyEvent& event) @@ -502,7 +533,8 @@ void wxGridCellTextEditor::Create(wxWindow* parent, m_control = new wxTextCtrl(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize #if defined(__WXMSW__) - , wxTE_MULTILINE | wxTE_NO_VSCROLL | wxTE_AUTO_SCROLL + , wxTE_PROCESS_TAB | wxTE_MULTILINE | + wxTE_NO_VSCROLL | wxTE_AUTO_SCROLL #endif ); @@ -538,9 +570,9 @@ void wxGridCellTextEditor::SetSize(const wxRect& rectOrig) } #else // !GTK int extra_x = ( rect.x > 2 )? 2 : 1; - -// MB: treat MSW separately here otherwise the caret doesn't show -// when the editor is in the first row. + +// MB: treat MSW separately here otherwise the caret doesn't show +// when the editor is in the first row. #if defined(__WXMSW__) int extra_y = 2; #else @@ -1189,7 +1221,10 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid) if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) m_startValue = grid->GetTable()->GetValueAsBool(row, col); else - m_startValue = !!grid->GetTable()->GetValue(row, col); + { + wxString cellval( grid->GetTable()->GetValue(row, col) ); + m_startValue = !( !cellval || (cellval == "0") ); + } CBox()->SetValue(m_startValue); CBox()->SetFocus(); } @@ -1386,11 +1421,12 @@ void wxGridCellEditorEvtHandler::OnKeyDown(wxKeyEvent& event) break; case WXK_TAB: - event.Skip( m_grid->ProcessEvent( event ) ); + m_grid->GetEventHandler()->ProcessEvent( event ); break; case WXK_RETURN: - if (!m_grid->ProcessEvent(event)) + case WXK_NUMPAD_ENTER: + if (!m_grid->GetEventHandler()->ProcessEvent(event)) m_editor->HandleReturn(event); break; @@ -1407,6 +1443,7 @@ void wxGridCellEditorEvtHandler::OnChar(wxKeyEvent& event) case WXK_ESCAPE: case WXK_TAB: case WXK_RETURN: + case WXK_NUMPAD_ENTER: break; default: @@ -1627,8 +1664,15 @@ wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) { if ( m_width == -1 ) { + if ( m_precision == -1 ) + { // default width/precision m_format = _T("%f"); + } + else + { + m_format.Printf(_T("%%.%df"), m_precision); + } } else if ( m_precision == -1 ) { @@ -1642,6 +1686,7 @@ wxString wxGridCellFloatRenderer::GetString(wxGrid& grid, int row, int col) } text.Printf(m_format, val); + } //else: text already contains the string @@ -1680,8 +1725,6 @@ wxSize wxGridCellFloatRenderer::GetBestSize(wxGrid& grid, void wxGridCellFloatRenderer::SetParameters(const wxString& params) { - bool ok = TRUE; - if ( !params ) { // reset to defaults @@ -1694,37 +1737,34 @@ void wxGridCellFloatRenderer::SetParameters(const wxString& params) if ( !!tmp ) { long width; - if ( !tmp.ToLong(&width) ) + if ( tmp.ToLong(&width) ) { - ok = FALSE; + SetWidth((int)width); } else { - SetWidth((int)width); + wxLogDebug(_T("Invalid wxGridCellFloatRenderer width parameter string '%s ignored"), params.c_str()); + } + } tmp = params.AfterFirst(_T(',')); if ( !!tmp ) { long precision; - if ( !tmp.ToLong(&precision) ) + if ( tmp.ToLong(&precision) ) { - ok = FALSE; + SetPrecision((int)precision); } else { - SetPrecision((int)precision); - } - } - } + wxLogDebug(_T("Invalid wxGridCellFloatRenderer precision parameter string '%s ignored"), params.c_str()); } - if ( !ok ) - { - wxLogDebug(_T("Invalid wxGridCellFloatRenderer parameter string '%s ignored"), params.c_str()); } } } + // ---------------------------------------------------------------------------- // wxGridCellBoolRenderer // ---------------------------------------------------------------------------- @@ -1795,7 +1835,10 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) value = grid.GetTable()->GetValueAsBool(row, col); else - value = !!grid.GetTable()->GetValue(row, col); + { + wxString cellval( grid.GetTable()->GetValue(row, col) ); + value = !( !cellval || (cellval == "0") ); + } if ( value ) { @@ -1848,11 +1891,47 @@ wxGridCellAttr *wxGridCellAttr::Clone() const if ( IsReadOnly() ) attr->SetReadOnly(); + attr->SetKind( m_attrkind ); + attr->SetDefAttr(m_defGridAttr); return attr; } +void wxGridCellAttr::MergeWith(wxGridCellAttr *mergefrom) +{ + if ( !HasTextColour() && mergefrom->HasTextColour() ) + SetTextColour(mergefrom->GetTextColour()); + if ( !HasBackgroundColour() && mergefrom->HasBackgroundColour() ) + SetBackgroundColour(mergefrom->GetBackgroundColour()); + if ( !HasFont() && mergefrom->HasFont() ) + SetFont(mergefrom->GetFont()); + if ( !!HasAlignment() && mergefrom->HasAlignment() ){ + int hAlign, vAlign; + mergefrom->GetAlignment( &hAlign, &vAlign); + SetAlignment(hAlign, vAlign); + } + + // Directly access member functions as GetRender/Editor don't just return + // m_renderer/m_editor + // + // Maybe add support for merge of Render and Editor? + if (!HasRenderer() && mergefrom->HasRenderer() ) + { + m_renderer = mergefrom->m_renderer; + m_renderer->IncRef(); + } + if ( !HasEditor() && mergefrom->HasEditor() ) + { + m_editor = mergefrom->m_editor; + m_editor->IncRef(); + } + if ( !HasReadWriteMode() && mergefrom->HasReadWriteMode() ) + SetReadOnly(mergefrom->IsReadOnly()); + + SetDefAttr(mergefrom->m_defGridAttr); +} + const wxColour& wxGridCellAttr::GetTextColour() const { if (HasTextColour()) @@ -2205,28 +2284,77 @@ void wxGridCellAttrProvider::InitData() m_data = new wxGridCellAttrProviderData; } -wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col) const +wxGridCellAttr *wxGridCellAttrProvider::GetAttr(int row, int col, + wxGridCellAttr::wxAttrKind kind ) const { wxGridCellAttr *attr = (wxGridCellAttr *)NULL; if ( m_data ) { - // first look for the attribute of this specific cell - attr = m_data->m_cellAttrs.GetAttr(row, col); - - if ( !attr ) + switch(kind) { - // then look for the col attr (col attributes are more common than - // the row ones, hence they have priority) - attr = m_data->m_colAttrs.GetAttr(col); - } - - if ( !attr ) + case (wxGridCellAttr::Any): + //Get cached merge attributes. + // Currenlty not used as no cache implemented as not mutiable + // attr = m_data->m_mergeAttr.GetAttr(row, col); + if(!attr) + { + //Basicaly implement old version. + //Also check merge cache, so we don't have to re-merge every time.. + wxGridCellAttr *attrcell = (wxGridCellAttr *)NULL, + *attrrow = (wxGridCellAttr *)NULL, + *attrcol = (wxGridCellAttr *)NULL; + + attrcell = m_data->m_cellAttrs.GetAttr(row, col); + attrcol = m_data->m_colAttrs.GetAttr(col); + attrrow = m_data->m_rowAttrs.GetAttr(row); + + if((attrcell != attrrow) && (attrrow !=attrcol) && (attrcell != attrcol)){ + // Two or move are non NULL + attr = new wxGridCellAttr; + attr->SetKind(wxGridCellAttr::Merged); + + //Order important.. + if(attrcell){ + attr->MergeWith(attrcell); + attrcell->DecRef(); + } + if(attrcol){ + attr->MergeWith(attrcol); + attrcol->DecRef(); + } + if(attrrow){ + attr->MergeWith(attrrow); + attrrow->DecRef(); + } + //store merge attr if cache implemented + //attr->IncRef(); + //m_data->m_mergeAttr.SetAttr(attr, row, col); + } + else { - // finally try the row attributes + // one or none is non null return it or null. + if(attrrow) attr = attrrow; + if(attrcol) attr = attrcol; + if(attrcell) attr = attrcell; + } + } + break; + case (wxGridCellAttr::Cell): + attr = m_data->m_cellAttrs.GetAttr(row, col); + break; + case (wxGridCellAttr::Col): + attr = m_data->m_colAttrs.GetAttr(col); + break; + case (wxGridCellAttr::Row): attr = m_data->m_rowAttrs.GetAttr(row); + break; + default: + // unused as yet... + // (wxGridCellAttr::Default): + // (wxGridCellAttr::Merged): + break; } } - return attr; } @@ -2411,14 +2539,16 @@ int wxGridTypeRegistry::FindOrCloneDataType(const wxString& typeName) wxGridCellRenderer* wxGridTypeRegistry::GetRenderer(int index) { wxGridCellRenderer* renderer = m_typeinfo[index]->m_renderer; - renderer->IncRef(); + if (renderer) + renderer->IncRef(); return renderer; } wxGridCellEditor* wxGridTypeRegistry::GetEditor(int index) { wxGridCellEditor* editor = m_typeinfo[index]->m_editor; - editor->IncRef(); + if (editor) + editor->IncRef(); return editor; } @@ -2456,10 +2586,10 @@ bool wxGridTableBase::CanHaveAttributes() return TRUE; } -wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col) +wxGridCellAttr *wxGridTableBase::GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) { if ( m_attrProvider ) - return m_attrProvider->GetAttr(row, col); + return m_attrProvider->GetAttr(row, col, kind); else return (wxGridCellAttr *)NULL; } @@ -2468,6 +2598,7 @@ void wxGridTableBase::SetAttr(wxGridCellAttr* attr, int row, int col) { if ( m_attrProvider ) { + attr->SetKind(wxGridCellAttr::Cell); m_attrProvider->SetAttr(attr, row, col); } else @@ -2482,6 +2613,7 @@ void wxGridTableBase::SetRowAttr(wxGridCellAttr *attr, int row) { if ( m_attrProvider ) { + attr->SetKind(wxGridCellAttr::Row); m_attrProvider->SetRowAttr(attr, row); } else @@ -2496,6 +2628,7 @@ void wxGridTableBase::SetColAttr(wxGridCellAttr *attr, int col) { if ( m_attrProvider ) { + attr->SetKind(wxGridCellAttr::Col); m_attrProvider->SetColAttr(attr, col); } else @@ -3069,6 +3202,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridRowLabelWindow, wxWindow ) BEGIN_EVENT_TABLE( wxGridRowLabelWindow, wxWindow ) EVT_PAINT( wxGridRowLabelWindow::OnPaint ) + EVT_MOUSEWHEEL( wxGridRowLabelWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridRowLabelWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridRowLabelWindow::OnKeyDown ) EVT_KEY_UP( wxGridRowLabelWindow::OnKeyUp ) @@ -3107,17 +3241,23 @@ void wxGridRowLabelWindow::OnMouseEvent( wxMouseEvent& event ) } +void wxGridRowLabelWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} + + // This seems to be required for wxMotif otherwise the mouse // cursor must be in the cell edit control to get key events // void wxGridRowLabelWindow::OnKeyDown( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } void wxGridRowLabelWindow::OnKeyUp( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } @@ -3128,6 +3268,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridColLabelWindow, wxWindow ) BEGIN_EVENT_TABLE( wxGridColLabelWindow, wxWindow ) EVT_PAINT( wxGridColLabelWindow::OnPaint ) + EVT_MOUSEWHEEL( wxGridColLabelWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridColLabelWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridColLabelWindow::OnKeyDown ) EVT_KEY_UP( wxGridColLabelWindow::OnKeyUp ) @@ -3165,18 +3306,23 @@ void wxGridColLabelWindow::OnMouseEvent( wxMouseEvent& event ) m_owner->ProcessColLabelMouseEvent( event ); } +void wxGridColLabelWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} + // This seems to be required for wxMotif otherwise the mouse // cursor must be in the cell edit control to get key events // void wxGridColLabelWindow::OnKeyDown( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } void wxGridColLabelWindow::OnKeyUp( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } @@ -3186,6 +3332,7 @@ void wxGridColLabelWindow::OnKeyUp( wxKeyEvent& event ) IMPLEMENT_DYNAMIC_CLASS( wxGridCornerLabelWindow, wxWindow ) BEGIN_EVENT_TABLE( wxGridCornerLabelWindow, wxWindow ) + EVT_MOUSEWHEEL( wxGridCornerLabelWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridCornerLabelWindow::OnMouseEvent ) EVT_PAINT( wxGridCornerLabelWindow::OnPaint) EVT_KEY_DOWN( wxGridCornerLabelWindow::OnKeyDown ) @@ -3224,17 +3371,22 @@ void wxGridCornerLabelWindow::OnMouseEvent( wxMouseEvent& event ) } +void wxGridCornerLabelWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} + // This seems to be required for wxMotif otherwise the mouse // cursor must be in the cell edit control to get key events // void wxGridCornerLabelWindow::OnKeyDown( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } void wxGridCornerLabelWindow::OnKeyUp( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } @@ -3245,6 +3397,7 @@ IMPLEMENT_DYNAMIC_CLASS( wxGridWindow, wxPanel ) BEGIN_EVENT_TABLE( wxGridWindow, wxPanel ) EVT_PAINT( wxGridWindow::OnPaint ) + EVT_MOUSEWHEEL( wxGridWindow::OnMouseWheel) EVT_MOUSE_EVENTS( wxGridWindow::OnMouseEvent ) EVT_KEY_DOWN( wxGridWindow::OnKeyDown ) EVT_KEY_UP( wxGridWindow::OnKeyUp ) @@ -3297,18 +3450,22 @@ void wxGridWindow::OnMouseEvent( wxMouseEvent& event ) m_owner->ProcessGridCellMouseEvent( event ); } +void wxGridWindow::OnMouseWheel( wxMouseEvent& event ) +{ + m_owner->GetEventHandler()->ProcessEvent(event); +} // This seems to be required for wxMotif/wxGTK otherwise the mouse // cursor must be in the cell edit control to get key events // void wxGridWindow::OnKeyDown( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } void wxGridWindow::OnKeyUp( wxKeyEvent& event ) { - if ( !m_owner->ProcessEvent( event ) ) event.Skip(); + if ( !m_owner->GetEventHandler()->ProcessEvent( event ) ) event.Skip(); } void wxGridWindow::OnEraseBackground( wxEraseEvent& WXUNUSED(event) ) @@ -3381,6 +3538,7 @@ void wxGrid::Create() m_defaultCellAttr->SetDefAttr(m_defaultCellAttr); // Set default cell attributes + m_defaultCellAttr->SetKind(wxGridCellAttr::Default); m_defaultCellAttr->SetFont(GetFont()); m_defaultCellAttr->SetAlignment(wxALIGN_LEFT, wxALIGN_TOP); m_defaultCellAttr->SetTextColour( @@ -3532,6 +3690,8 @@ void wxGrid::Init() m_gridLineColour = wxColour( 128, 128, 255 ); m_gridLinesEnabled = TRUE; m_cellHighlightColour = m_gridLineColour; + m_cellHighlightPenWidth = 3; + m_cellHighlightROPenWidth = 1; m_cursorMode = WXGRID_CURSOR_SELECT_CELL; m_winCapture = (wxWindow *)NULL; @@ -3648,19 +3808,44 @@ void wxGrid::CalcDimensions() int cw, ch; GetClientSize( &cw, &ch ); - if ( m_numRows > 0 || m_numCols > 0 ) - { - int right = m_numCols > 0 ? GetColRight( m_numCols-1 ) + m_extraWidth : 0; - int bottom = m_numRows > 0 ? GetRowBottom( m_numRows-1 ) + m_extraHeight : 0; + if ( m_colLabelWin->IsShown() ) + cw -= m_rowLabelWidth; + if ( m_rowLabelWin->IsShown() ) + ch -= m_colLabelHeight; - // TODO: restore the scroll position that we had before sizing - // - int x, y; - GetViewStart( &x, &y ); - SetScrollbars( GRID_SCROLL_LINE, GRID_SCROLL_LINE, - right/GRID_SCROLL_LINE, bottom/GRID_SCROLL_LINE, - x, y ); + // grid total size + int w = m_numCols > 0 ? GetColRight(m_numCols - 1) + m_extraWidth + 1 : 0; + int h = m_numRows > 0 ? GetRowBottom(m_numRows - 1) + m_extraHeight + 1 : 0; + + // preserve (more or less) the previous position + int x, y; + GetViewStart( &x, &y ); + // maybe we don't need scrollbars at all? and if we do, transform w and h + // from pixels into logical units + if ( w <= cw ) + { + w = 0; x= 0; + } + else + { + w = (w + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE; + if ( x >= w ) + x = w - 1; + } + if ( h <= ch ) + { + h = 0; y = 0; + } + else + { + h = (h + GRID_SCROLL_LINE - 1)/GRID_SCROLL_LINE; + if ( y >= h ) + y = h - 1; } + + // do set scrollbar parameters + SetScrollbars( GRID_SCROLL_LINE, GRID_SCROLL_LINE, + w, h, x, y, (GetBatchCount() != 0)); } @@ -3827,13 +4012,14 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) attrProvider->UpdateAttrRows( pos, -((int)numRows) ); // ifdef'd out following patch from Paul Gammans #if 0 + // No need to touch column attributes, unless we // removed _all_ rows, in this case, we remove // all column attributes. // I hate to do this here, but the // needed data is not available inside UpdateAttrRows. if ( !GetNumberRows() ) attrProvider->UpdateAttrCols( 0, -GetNumberCols() ); -#endif +#endif } if ( !GetBatchCount() ) { @@ -3960,7 +4146,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) wxGridCellAttrProvider * attrProvider = m_table->GetAttrProvider(); if (attrProvider) { attrProvider->UpdateAttrCols( pos, -((int)numCols) ); -// ifdef'd out following patch from Paul Gammans +// ifdef'd out following patch from Paul Gammans #if 0 // No need to touch row attributes, unless we // removed _all_ columns, in this case, we remove @@ -3969,20 +4155,16 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) // needed data is not available inside UpdateAttrCols. if ( !GetNumberCols() ) attrProvider->UpdateAttrRows( 0, -GetNumberRows() ); -#endif +#endif } if ( !GetBatchCount() ) { CalcDimensions(); m_colLabelWin->Refresh(); } - return TRUE; } -#if 0 -// There is no path to this code !!!!!! - result = TRUE; + result = TRUE; break; -#endif } if (result && !GetBatchCount() ) @@ -4582,7 +4764,9 @@ void wxGrid::ChangeCursorMode(CursorMode mode, cursorModes[m_cursorMode], cursorModes[mode]); #endif // __WXDEBUG__ - if ( mode == m_cursorMode ) + if ( mode == m_cursorMode && + win == m_winCapture && + captureMouse == (m_winCapture != NULL)) return; if ( !win ) @@ -5253,13 +5437,12 @@ bool wxGrid::SendEvent( const wxEventType type, type, this, rowOrCol, - mouseEv.GetX() + GetColLabelSize(), - mouseEv.GetY() + GetRowLabelSize(), + mouseEv.GetX() + GetRowLabelSize(), + mouseEv.GetY() + GetColLabelSize(), mouseEv.ControlDown(), mouseEv.ShiftDown(), mouseEv.AltDown(), mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); } else if ( type == wxEVT_GRID_RANGE_SELECT ) @@ -5284,14 +5467,13 @@ bool wxGrid::SendEvent( const wxEventType type, type, this, row, col, - mouseEv.GetX() + GetColLabelSize(), - mouseEv.GetY() + GetRowLabelSize(), + mouseEv.GetX() + GetRowLabelSize(), + mouseEv.GetY() + GetColLabelSize(), FALSE, mouseEv.ControlDown(), mouseEv.ShiftDown(), mouseEv.AltDown(), mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); } } @@ -5412,6 +5594,7 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) break; case WXK_RETURN: + case WXK_NUMPAD_ENTER: if ( event.ControlDown() ) { event.Skip(); // to let the edit control have the return @@ -5595,7 +5778,7 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) HideCellEditControl(); DisableCellEditControl(); - if ( IsVisible( m_currentCellCoords, FALSE ) ) // zzz + if ( IsVisible( m_currentCellCoords, FALSE ) ) { wxRect r; r = BlockToDeviceRect(m_currentCellCoords, m_currentCellCoords); @@ -5608,7 +5791,7 @@ void wxGrid::SetCurrentCell( const wxGridCellCoords& coords ) } CalcCellsExposed( r ); - + // Otherwise refresh redraws the highlight! m_currentCellCoords = coords; @@ -5759,7 +5942,6 @@ void wxGrid::HighlightBlock( int topRow, int leftCol, int bottomRow, int rightCo // (old comment from when this was the body of SelectBlock) } - // // ------ functions to get/send data (see also public functions) // @@ -5903,10 +6085,27 @@ void wxGrid::DrawCellHighlight( wxDC& dc, const wxGridCellAttr *attr ) // hmmm... what could we do here to show that the cell is disabled? // for now, I just draw a thinner border than for the other ones, but // it doesn't look really good - dc.SetPen(wxPen(m_cellHighlightColour, attr->IsReadOnly() ? 1 : 3, wxSOLID)); - dc.SetBrush(*wxTRANSPARENT_BRUSH); - dc.DrawRectangle(rect); + int penWidth = attr->IsReadOnly() ? m_cellHighlightROPenWidth : m_cellHighlightPenWidth; + + if (penWidth > 0) { + + // The center of th drawn line is where the position/width/height of + // the rectangle is actually at, (on wxMSW atr least,) so we will + // reduce the size of the rectangle to compensate for the thickness of + // the line. If this is too strange on non wxMSW platforms then + // please #ifdef this appropriately. + rect.x += penWidth/2; + rect.y += penWidth/2; + rect.width -= penWidth-1; + rect.height -= penWidth-1; + + + // Now draw the rectangle + dc.SetPen(wxPen(m_cellHighlightColour, penWidth, wxSOLID)); + dc.SetBrush(*wxTRANSPARENT_BRUSH); + dc.DrawRectangle(rect); + } #if 0 // VZ: my experiments with 3d borders... @@ -5988,7 +6187,7 @@ void wxGrid::DrawHighlight(wxDC& dc) // This is used to redraw all grid lines e.g. when the grid line colour // has been changed // -void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED_GTK(reg) ) +void wxGrid::DrawAllGridLines( wxDC& dc, const wxRegion & WXUNUSED(reg) ) { if ( !m_gridLinesEnabled || !m_numRows || @@ -6417,7 +6616,7 @@ void wxGrid::ShowCellEditControl() { if ( !IsVisible( m_currentCellCoords ) ) { - m_cellEditCtrlEnabled = false; + m_cellEditCtrlEnabled = FALSE; return; } else @@ -7337,14 +7536,14 @@ void wxGrid::SetRowLabelAlignment( int horiz, int vert ) case wxRIGHT: horiz = wxALIGN_RIGHT; break; case wxCENTRE: horiz = wxALIGN_CENTRE; break; } - + switch ( vert ) { case wxTOP: vert = wxALIGN_TOP; break; case wxBOTTOM: vert = wxALIGN_BOTTOM; break; case wxCENTRE: vert = wxALIGN_CENTRE; break; } - + if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) { m_rowLabelHorizAlign = horiz; @@ -7370,14 +7569,14 @@ void wxGrid::SetColLabelAlignment( int horiz, int vert ) case wxRIGHT: horiz = wxALIGN_RIGHT; break; case wxCENTRE: horiz = wxALIGN_CENTRE; break; } - + switch ( vert ) { case wxTOP: vert = wxALIGN_TOP; break; case wxBOTTOM: vert = wxALIGN_BOTTOM; break; case wxCENTRE: vert = wxALIGN_CENTRE; break; } - + if ( horiz == wxALIGN_LEFT || horiz == wxALIGN_CENTRE || horiz == wxALIGN_RIGHT ) { m_colLabelHorizAlign = horiz; @@ -7459,6 +7658,38 @@ void wxGrid::SetCellHighlightColour( const wxColour& colour ) } } +void wxGrid::SetCellHighlightPenWidth(int width) +{ + if (m_cellHighlightPenWidth != width) { + m_cellHighlightPenWidth = width; + + // Just redrawing the cell highlight is not enough since that won't + // make any visible change if the the thickness is getting smaller. + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) + return; + wxRect rect = CellToRect(row, col); + m_gridWin->Refresh(TRUE, &rect); + } +} + +void wxGrid::SetCellHighlightROPenWidth(int width) +{ + if (m_cellHighlightROPenWidth != width) { + m_cellHighlightROPenWidth = width; + + // Just redrawing the cell highlight is not enough since that won't + // make any visible change if the the thickness is getting smaller. + int row = m_currentCellCoords.GetRow(); + int col = m_currentCellCoords.GetCol(); + if ( GetColWidth(col) <= 0 || GetRowHeight(row) <= 0 ) + return; + wxRect rect = CellToRect(row, col); + m_gridWin->Refresh(TRUE, &rect); + } +} + void wxGrid::EnableGridLines( bool enable ) { if ( enable != m_gridLinesEnabled ) @@ -7662,6 +7893,7 @@ void wxGrid::ClearAttrCache() if ( m_attrCache.row != -1 ) { wxSafeDecRef(m_attrCache.attr); + m_attrCache.attr = NULL; m_attrCache.row = -1; } } @@ -7704,7 +7936,7 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const wxGridCellAttr *attr; if ( !LookupAttr(row, col, &attr) ) { - attr = m_table ? m_table->GetAttr(row, col) : (wxGridCellAttr *)NULL; + attr = m_table ? m_table->GetAttr(row, col , wxGridCellAttr::Any) : (wxGridCellAttr *)NULL; CacheAttr(row, col, attr); } if (attr) @@ -7722,25 +7954,19 @@ wxGridCellAttr *wxGrid::GetCellAttr(int row, int col) const wxGridCellAttr *wxGrid::GetOrCreateCellAttr(int row, int col) const { - wxGridCellAttr *attr; - if ( !LookupAttr(row, col, &attr) || !attr ) - { + wxGridCellAttr *attr = (wxGridCellAttr *)NULL; wxASSERT_MSG( m_table, _T("we may only be called if CanHaveAttributes() returned TRUE and then m_table should be !NULL") ); - attr = m_table->GetAttr(row, col); + attr = m_table->GetAttr(row, col, wxGridCellAttr::Cell ); if ( !attr ) { attr = new wxGridCellAttr; // artificially inc the ref count to match DecRef() in caller attr->IncRef(); - m_table->SetAttr(attr, row, col); } - - CacheAttr(row, col, attr); - } attr->SetDefAttr(m_defaultCellAttr); return attr; } @@ -7772,11 +7998,16 @@ void wxGrid::SetColFormatFloat(int col, int width, int precision) void wxGrid::SetColFormatCustom(int col, const wxString& typeName) { - wxGridCellAttr *attr = new wxGridCellAttr; + wxGridCellAttr *attr = (wxGridCellAttr *)NULL; + + attr = m_table->GetAttr(-1, col, wxGridCellAttr::Col ); + if(!attr) + attr = new wxGridCellAttr; wxGridCellRenderer *renderer = GetDefaultRendererForType(typeName); attr->SetRenderer(renderer); SetColAttr(col, attr); + } // ---------------------------------------------------------------------------- @@ -7788,6 +8019,7 @@ void wxGrid::SetRowAttr(int row, wxGridCellAttr *attr) if ( CanHaveAttributes() ) { m_table->SetRowAttr(attr, row); + ClearAttrCache(); } else { @@ -7800,6 +8032,7 @@ void wxGrid::SetColAttr(int col, wxGridCellAttr *attr) if ( CanHaveAttributes() ) { m_table->SetColAttr(attr, col); + ClearAttrCache(); } else { @@ -7958,8 +8191,8 @@ void wxGrid::SetDefaultRowSize( int height, bool resizeExistingRows ) if ( resizeExistingRows ) { InitRowHeights(); - - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } } @@ -7982,7 +8215,8 @@ void wxGrid::SetRowSize( int row, int height ) { m_rowBottoms[i] += diff; } - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) @@ -7992,8 +8226,8 @@ void wxGrid::SetDefaultColSize( int width, bool resizeExistingCols ) if ( resizeExistingCols ) { InitColWidths(); - - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } } @@ -8018,7 +8252,8 @@ void wxGrid::SetColSize( int col, int width ) { m_colRights[i] += diff; } - CalcDimensions(); + if ( !GetBatchCount() ) + CalcDimensions(); } @@ -8093,7 +8328,7 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) if ( column ) dc.GetTextExtent( GetColLabelValue(col), &w, &h ); else - dc.GetTextExtent( GetRowLabelValue(col), &w, &h ); + dc.GetTextExtent( GetRowLabelValue(row), &w, &h ); extent = column ? w : h; if ( extent > extentMax ) @@ -8120,11 +8355,34 @@ void wxGrid::AutoSizeColOrRow( int colOrRow, bool setAsMin, bool column ) } } - if ( column ) + if ( column ){ SetColSize(col, extentMax); - else + if ( !GetBatchCount() ) + { + int cw, ch, dummy; + m_gridWin->GetClientSize( &cw, &ch ); + wxRect rect ( CellToRect( 0, col ) ); + rect.y = 0; + CalcScrolledPosition(rect.x, 0, &rect.x, &dummy); + rect.width = cw - rect.x; + rect.height = m_colLabelHeight; + m_colLabelWin->Refresh( TRUE, &rect ); + } + } + else{ SetRowSize(row, extentMax); - + if ( !GetBatchCount() ) + { + int cw, ch, dummy; + m_gridWin->GetClientSize( &cw, &ch ); + wxRect rect ( CellToRect( row, 0 ) ); + rect.x = 0; + CalcScrolledPosition(0, rect.y, &dummy, &rect.y); + rect.width = m_rowLabelWidth; + rect.height = ch - rect.y; + m_rowLabelWin->Refresh( TRUE, &rect ); + } + } if ( setAsMin ) { if ( column ) @@ -8138,6 +8396,8 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin) { int width = m_rowLabelWidth; + if ( !calcOnly ) + BeginBatch(); for ( int col = 0; col < m_numCols; col++ ) { if ( !calcOnly ) @@ -8147,7 +8407,8 @@ int wxGrid::SetOrCalcColumnSizes(bool calcOnly, bool setAsMin) width += GetColWidth(col); } - + if ( !calcOnly ) + EndBatch(); return width; } @@ -8155,6 +8416,8 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin) { int height = m_colLabelHeight; + if ( !calcOnly ) + BeginBatch(); for ( int row = 0; row < m_numRows; row++ ) { if ( !calcOnly ) @@ -8164,14 +8427,15 @@ int wxGrid::SetOrCalcRowSizes(bool calcOnly, bool setAsMin) height += GetRowHeight(row); } - + if ( !calcOnly ) + EndBatch(); return height; } void wxGrid::AutoSize() { // set the size too - SetSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE)); + SetClientSize(SetOrCalcColumnSizes(FALSE), SetOrCalcRowSizes(FALSE)); } wxSize wxGrid::DoGetBestSize() const @@ -8246,20 +8510,67 @@ void wxGrid::SelectCol( int col, bool addToSelected ) } -void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, +void wxGrid::SelectBlock( int topRow, int leftCol, int bottomRow, int rightCol, bool addToSelected ) { if ( IsSelection() && !addToSelected ) ClearSelection(); - m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol, - FALSE, addToSelected ); + m_selection->SelectBlock( topRow, leftCol, bottomRow, rightCol, + FALSE, addToSelected ); } void wxGrid::SelectAll() { - m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 ); + if ( m_numRows > 0 && m_numCols > 0 ) + m_selection->SelectBlock( 0, 0, m_numRows-1, m_numCols-1 ); +} + +// +// ------ Cell, row and col deselection +// + +void wxGrid::DeselectRow( int row ) +{ + if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectRows ) + { + if ( m_selection->IsInSelection(row, 0 ) ) + m_selection->ToggleCellSelection( row, 0); + } + else + { + int nCols = GetNumberCols(); + for ( int i = 0; i < nCols ; i++ ) + { + if ( m_selection->IsInSelection(row, i ) ) + m_selection->ToggleCellSelection( row, i); + } + } +} + +void wxGrid::DeselectCol( int col ) +{ + if ( m_selection->GetSelectionMode() == wxGrid::wxGridSelectColumns ) + { + if ( m_selection->IsInSelection(0, col ) ) + m_selection->ToggleCellSelection( 0, col); + } + else + { + int nRows = GetNumberRows(); + for ( int i = 0; i < nRows ; i++ ) + { + if ( m_selection->IsInSelection(i, col ) ) + m_selection->ToggleCellSelection(i, col); + } + } +} + +void wxGrid::DeselectCell( int row, int col ) +{ + if ( m_selection->IsInSelection(row, col) ) + m_selection->ToggleCellSelection(row, col); } bool wxGrid::IsSelection()