X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b9293331c6e25901bd5f615c14950b5a75f2a27b..062dfc9a96dc9e796c53544f41ff92dc47f26e82:/src/generic/datavgen.cpp diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 68c7d4bd09..bdc389ad66 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -145,7 +145,6 @@ protected: return *(GetOwner()->GetColumn(idx)); } - // FIXME: currently unused virtual bool UpdateColumnWidthToFit(unsigned int idx, int widthTitle) { wxDataViewCtrl * const owner = GetOwner(); @@ -215,6 +214,8 @@ private: model->Resort(); owner->OnColumnChange(idx); + + SendEvent(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, idx); } void OnRClick(wxHeaderCtrlEvent& event) @@ -533,6 +534,8 @@ public: int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode + void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; } + // Some useful functions for row and item mapping wxDataViewItem GetItemByRow( unsigned int row ) const; int GetRowByItem( const wxDataViewItem & item ) const; @@ -733,7 +736,7 @@ bool wxDataViewTextRenderer::HasEditorCtrl() const return true; } -wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent, +wxWindow* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) { wxTextCtrl* ctrl = new wxTextCtrl( parent, wxID_ANY, value, @@ -747,7 +750,7 @@ wxControl* wxDataViewTextRenderer::CreateEditorCtrl( wxWindow *parent, return ctrl; } -bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant &value ) +bool wxDataViewTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant &value ) { wxTextCtrl *text = (wxTextCtrl*) editor; value = text->GetValue(); @@ -797,9 +800,9 @@ bool wxDataViewBitmapRenderer::GetValue( wxVariant& WXUNUSED(value) ) const bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) ) { - if (m_bitmap.Ok()) + if (m_bitmap.IsOk()) dc->DrawBitmap( m_bitmap, cell.x, cell.y ); - else if (m_icon.Ok()) + else if (m_icon.IsOk()) dc->DrawIcon( m_icon, cell.x, cell.y ); return true; @@ -807,9 +810,9 @@ bool wxDataViewBitmapRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state wxSize wxDataViewBitmapRenderer::GetSize() const { - if (m_bitmap.Ok()) + if (m_bitmap.IsOk()) return wxSize( m_bitmap.GetWidth(), m_bitmap.GetHeight() ); - else if (m_icon.Ok()) + else if (m_icon.IsOk()) return wxSize( m_icon.GetWidth(), m_icon.GetHeight() ); return wxSize(wxDVC_DEFAULT_RENDERER_SIZE,wxDVC_DEFAULT_RENDERER_SIZE); @@ -864,15 +867,23 @@ bool wxDataViewToggleRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state return true; } -void wxDataViewToggleRenderer::WXOnActivate(wxDataViewModel *model, - const wxVariant& valueOld, - const wxDataViewItem & item, - unsigned int col) +bool wxDataViewToggleRenderer::WXOnLeftClick(const wxPoint& cursor, + const wxRect& WXUNUSED(cell), + wxDataViewModel *model, + const wxDataViewItem& item, + unsigned int col) { + // only react to clicks directly on the checkbox, not elsewhere in the same cell: + if (!wxRect(GetSize()).Contains(cursor)) + return false; + if (model->IsEnabled(item, col)) { - model->ChangeValue(!valueOld.GetBool(), item, col); + model->ChangeValue(!m_toggle, item, col); + return true; } + + return false; } wxSize wxDataViewToggleRenderer::GetSize() const @@ -1024,12 +1035,12 @@ wxSize wxDataViewDateRenderer::GetSize() const return GetTextExtent(m_date.FormatDate()); } -void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model, - const wxVariant& valueOld, - const wxDataViewItem & item, - unsigned int col ) +bool wxDataViewDateRenderer::WXOnActivate(const wxRect& WXUNUSED(cell), + wxDataViewModel *model, + const wxDataViewItem& item, + unsigned int col) { - wxDateTime dtOld = valueOld.GetDateTime(); + wxDateTime dtOld = m_date; #if wxUSE_DATE_RENDERER_POPUP wxDataViewDateRendererPopupTransient *popup = new wxDataViewDateRendererPopupTransient( @@ -1041,6 +1052,8 @@ void wxDataViewDateRenderer::WXOnActivate(wxDataViewModel *model, #else // !wxUSE_DATE_RENDERER_POPUP wxMessageBox(dtOld.Format()); #endif // wxUSE_DATE_RENDERER_POPUP/!wxUSE_DATE_RENDERER_POPUP + + return true; } // --------------------------------------------------------- @@ -1097,7 +1110,7 @@ wxSize wxDataViewIconTextRenderer::GetSize() const return wxSize(80,20); } -wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value) +wxWindow* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect labelRect, const wxVariant& value) { wxDataViewIconText iconText; iconText << value; @@ -1123,7 +1136,7 @@ wxControl* wxDataViewIconTextRenderer::CreateEditorCtrl(wxWindow *parent, wxRect return ctrl; } -bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxControl *editor, wxVariant& value ) +bool wxDataViewIconTextRenderer::GetValueFromEditorCtrl( wxWindow *editor, wxVariant& value ) { wxTextCtrl *text = (wxTextCtrl*) editor; @@ -1588,6 +1601,12 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawRectangle(GetClientSize()); #endif + if ( IsEmpty() ) + { + // No items to draw. + return; + } + // prepare the DC GetOwner()->PrepareDC( dc ); dc.SetFont( GetFont() ); @@ -1601,10 +1620,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) wxMin( (int)( GetLineAt( wxMax(0,update.y+update.height) ) - item_start + 1), (int)(GetRowCount( ) - item_start)); unsigned int item_last = item_start + item_count; - // Get the parent of DataViewCtrl - wxWindow *parent = GetParent()->GetParent(); + + // Send the event to wxDataViewCtrl itself. + wxWindow * const parent = GetParent(); wxDataViewEvent cache_event(wxEVT_COMMAND_DATAVIEW_CACHE_HINT, parent->GetId()); - cache_event.SetEventObject(GetParent()); + cache_event.SetEventObject(parent); cache_event.SetCache(item_start, item_last - 1); parent->ProcessWindowEvent(cache_event); @@ -1665,22 +1685,23 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.SetPen(m_penRule); dc.SetBrush(*wxTRANSPARENT_BRUSH); - int x = x_start; + // NB: Vertical rules are drawn in the last pixel of a column so that + // they align perfectly with native MSW wxHeaderCtrl as well as for + // consistency with MSW native list control. There's no vertical + // rule at the most-left side of the control. + + int x = x_start - 1; for (unsigned int i = col_start; i < col_last; i++) { wxDataViewColumn *col = GetOwner()->GetColumnAt(i); if (col->IsHidden()) continue; // skip it + x += col->GetWidth(); + dc.DrawLine(x, GetLineStart( item_start ), x, GetLineStart( item_last ) ); - - x += col->GetWidth(); } - - // Draw last vertical rule - dc.DrawLine(x, GetLineStart( item_start ), - x, GetLineStart( item_last ) ); } // redraw the background for the items which are selected/current @@ -1752,8 +1773,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) dataitem = node->GetItem(); - if ((i > 0) && model->IsContainer(dataitem) && - !model->HasContainerColumns(dataitem)) + // Skip all columns of "container" rows except the expander + // column itself unless HasContainerColumns() overrides this. + if ( col != GetOwner()->GetExpanderColumn() && + model->IsContainer(dataitem) && + !model->HasContainerColumns(dataitem) ) continue; } else @@ -3010,7 +3034,7 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item // Find the item along the parent-chain. // This algorithm is designed to speed up the node-finding method wxDataViewTreeNode* node = m_root; - for( unsigned iter = parentChain.size()-1; iter>=0; --iter ) + for( unsigned iter = parentChain.size()-1; ; --iter ) { if( node->HasChildren() ) { @@ -3041,6 +3065,9 @@ wxDataViewTreeNode * wxDataViewMainWindow::FindNode( const wxDataViewItem & item } else return NULL; + + if ( !iter ) + break; } return NULL; } @@ -3352,7 +3379,7 @@ void wxDataViewMainWindow::OnChar( wxKeyEvent &event ) break; case WXK_DOWN: - if ( m_currentRow < GetRowCount() - 1 ) + if ( m_currentRow + 1 < GetRowCount() ) OnArrowChar( m_currentRow + 1, event ); break; // Add the process for tree expanding/collapsing @@ -3630,19 +3657,11 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) { const unsigned colIdx = col->GetModelColumn(); - wxVariant value; - model->GetValue( value, item, colIdx ); - - cell->WXOnActivate(model, value, item, colIdx); - - if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() ) - { - cell->SetValue( value ); + cell->PrepareForItem(model, item, colIdx); - wxRect cell_rect( xpos, GetLineStart( current ), - col->GetWidth(), GetLineHeight( current ) ); - custom->Activate( cell_rect, model, item, colIdx ); - } + wxRect cell_rect( xpos, GetLineStart( current ), + col->GetWidth(), GetLineHeight( current ) ); + cell->WXOnActivate( cell_rect, model, item, colIdx ); } else { @@ -3709,8 +3728,10 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) if (!IsRowSelected(current)) { SelectAllRows(false); + const unsigned oldCurrent = m_currentRow; ChangeCurrentRow(current); SelectRow(m_currentRow,true); + RefreshRow(oldCurrent); SendSelectionChangedEvent(GetItemByRow( m_currentRow ) ); } } @@ -3813,53 +3834,50 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event ) // Call LeftClick after everything else as under GTK+ if (cell->GetMode() & wxDATAVIEW_CELL_ACTIVATABLE) { - if ( wxDataViewCustomRenderer *custom = cell->WXGetAsCustom() ) - { - // notify cell about click - custom->PrepareForItem(model, item, col->GetModelColumn()); + // notify cell about click + cell->PrepareForItem(model, item, col->GetModelColumn()); - wxRect cell_rect( xpos, GetLineStart( current ), - col->GetWidth(), GetLineHeight( current ) ); + wxRect cell_rect( xpos, GetLineStart( current ), + col->GetWidth(), GetLineHeight( current ) ); - // Report position relative to the cell's custom area, i.e. - // no the entire space as given by the control but the one - // used by the renderer after calculation of alignment etc. + // Report position relative to the cell's custom area, i.e. + // no the entire space as given by the control but the one + // used by the renderer after calculation of alignment etc. - // adjust the rectangle ourselves to account for the alignment - wxRect rectItem = cell_rect; - const int align = custom->GetAlignment(); - if ( align != wxDVR_DEFAULT_ALIGNMENT ) - { - const wxSize size = custom->GetSize(); + // adjust the rectangle ourselves to account for the alignment + wxRect rectItem = cell_rect; + const int align = cell->GetAlignment(); + if ( align != wxDVR_DEFAULT_ALIGNMENT ) + { + const wxSize size = cell->GetSize(); - if ( size.x >= 0 && size.x < cell_rect.width ) - { - if ( align & wxALIGN_CENTER_HORIZONTAL ) - rectItem.x += (cell_rect.width - size.x)/2; - else if ( align & wxALIGN_RIGHT ) - rectItem.x += cell_rect.width - size.x; - // else: wxALIGN_LEFT is the default - } + if ( size.x >= 0 && size.x < cell_rect.width ) + { + if ( align & wxALIGN_CENTER_HORIZONTAL ) + rectItem.x += (cell_rect.width - size.x)/2; + else if ( align & wxALIGN_RIGHT ) + rectItem.x += cell_rect.width - size.x; + // else: wxALIGN_LEFT is the default + } - if ( size.y >= 0 && size.y < cell_rect.height ) - { - if ( align & wxALIGN_CENTER_VERTICAL ) - rectItem.y += (cell_rect.height - size.y)/2; - else if ( align & wxALIGN_BOTTOM ) - rectItem.y += cell_rect.height - size.y; - // else: wxALIGN_TOP is the default - } + if ( size.y >= 0 && size.y < cell_rect.height ) + { + if ( align & wxALIGN_CENTER_VERTICAL ) + rectItem.y += (cell_rect.height - size.y)/2; + else if ( align & wxALIGN_BOTTOM ) + rectItem.y += cell_rect.height - size.y; + // else: wxALIGN_TOP is the default } + } - wxPoint pos( event.GetPosition() ); - pos.x -= rectItem.x; - pos.y -= rectItem.y; + wxPoint pos( event.GetPosition() ); + pos.x -= rectItem.x; + pos.y -= rectItem.y; - m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y ); + m_owner->CalcUnscrolledPosition( pos.x, pos.y, &pos.x, &pos.y ); - /* ignore ret */ custom->LeftClick( pos, cell_rect, - model, item, col->GetModelColumn()); - } + /* ignore ret */ cell->WXOnLeftClick( pos, cell_rect, + model, item, col->GetModelColumn()); } } } @@ -4014,6 +4032,16 @@ void wxDataViewCtrl::OnSize( wxSizeEvent &WXUNUSED(event) ) Layout(); AdjustScrollbars(); + + // We must redraw the headers if their height changed. Normally this + // shouldn't happen as the control shouldn't let itself be resized beneath + // its minimal height but avoid the display artefacts that appear if it + // does happen, e.g. because there is really not enough vertical space. + if ( !HasFlag(wxDV_NO_HEADER) && m_headerArea && + m_headerArea->GetSize().y <= m_headerArea->GetBestSize(). y ) + { + m_headerArea->Refresh(); + } } void wxDataViewCtrl::SetFocus() @@ -4118,6 +4146,16 @@ unsigned int wxDataViewCtrl::GetColumnCount() const return m_cols.GetCount(); } +bool wxDataViewCtrl::SetRowHeight( int lineHeight ) +{ + if ( !m_clientArea ) + return false; + + m_clientArea->SetRowHeight(lineHeight); + + return true; +} + wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int idx ) const { return m_cols[idx]; @@ -4238,7 +4276,7 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const calculator.UpdateWithRow(row); } - // row is the first unmeasured item now; that's out value of N/2 + // row is the first unmeasured item now; that's our value of N/2 if ( row < count ) { @@ -4278,8 +4316,6 @@ unsigned int wxDataViewCtrl::GetBestColumnWidth(int idx) const const_cast(this)->m_colsBestWidths[idx] = max_width; return max_width; - - #undef MEASURE_ITEM } void wxDataViewCtrl::ColumnMoved(wxDataViewColumn * WXUNUSED(col), @@ -4327,8 +4363,9 @@ void wxDataViewCtrl::InvalidateColBestWidths() if ( m_headerArea ) { - // this updates visual appearance of columns 0 and up, not just 0 - m_headerArea->UpdateColumn(0); + const unsigned cols = m_headerArea->GetColumnCount(); + for ( unsigned i = 0; i < cols; i++ ) + m_headerArea->UpdateColumn(i); } }