X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/673810eeb8e16599b599f3a851692c323bc20165..2debe2b120a2b376a57d3f8ec24eb418a23b2710:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index a66701b634..94ddc67dc2 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -69,6 +69,24 @@ private: } // anonymous namespace +// --------------------------------------------------------- +// wxDataViewItemAttr +// --------------------------------------------------------- + +wxFont wxDataViewItemAttr::GetEffectiveFont(const wxFont& font) const +{ + if ( !HasFont() ) + return font; + + wxFont f(font); + if ( GetBold() ) + f.MakeBold(); + if ( GetItalic() ) + f.MakeItalic(); + return f; +} + + // --------------------------------------------------------- // wxDataViewModelNotifier // --------------------------------------------------------- @@ -235,7 +253,7 @@ bool wxDataViewModel::Cleared() return ret; } -bool wxDataViewModel::BeforeReset( size_t old_size, size_t new_size ) +bool wxDataViewModel::BeforeReset() { bool ret = true; @@ -243,7 +261,7 @@ bool wxDataViewModel::BeforeReset( size_t old_size, size_t new_size ) for (iter = m_notifiers.begin(); iter != m_notifiers.end(); ++iter) { wxDataViewModelNotifier* notifier = *iter; - if (!notifier->BeforeReset(old_size,new_size)) + if (!notifier->BeforeReset()) ret = false; } @@ -375,6 +393,8 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) void wxDataViewIndexListModel::Reset( unsigned int new_size ) { + /* wxDataViewModel:: */ BeforeReset(); + m_hash.Clear(); // IDs are ordered until an item gets deleted or inserted @@ -387,7 +407,7 @@ void wxDataViewIndexListModel::Reset( unsigned int new_size ) m_nextFreeID = new_size + 1; - /* wxDataViewModel:: */ Cleared(); + /* wxDataViewModel:: */ AfterReset(); } void wxDataViewIndexListModel::RowPrepended() @@ -529,10 +549,10 @@ wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_siz void wxDataViewVirtualListModel::Reset( unsigned int new_size ) { - /* wxDataViewModel:: */ BeforeReset( m_size, new_size ); + /* wxDataViewModel:: */ BeforeReset(); m_size = new_size; - + /* wxDataViewModel:: */ AfterReset(); } @@ -759,6 +779,20 @@ bool wxDataViewRendererBase::FinishEditing() return true; } +void wxDataViewRendererBase::PrepareForItem(const wxDataViewModel *model, + const wxDataViewItem& item, + unsigned column) +{ + wxVariant value; + model->GetValue(value, item, column); + SetValue(value); + + wxDataViewItemAttr attr; + model->GetAttr(item, column, attr); + SetAttr(attr); +} + + // ---------------------------------------------------------------------------- // wxDataViewCustomRendererBase // ---------------------------------------------------------------------------- @@ -824,19 +858,28 @@ wxDataViewCustomRendererBase::WXCallRender(wxRect rectCell, wxDC *dc, int state) wxDCFontChanger changeFont(*dc); if ( m_attr.HasFont() ) - { - wxFont font(dc->GetFont()); - if ( m_attr.GetBold() ) - font.MakeBold(); - if ( m_attr.GetItalic() ) - font.MakeItalic(); - - changeFont.Set(font); - } + changeFont.Set(m_attr.GetEffectiveFont(dc->GetFont())); Render(rectItem, dc, state); } +wxSize wxDataViewCustomRendererBase::GetTextExtent(const wxString& str) const +{ + const wxDataViewCtrl *view = GetView(); + + if ( m_attr.HasFont() ) + { + wxFont font(m_attr.GetEffectiveFont(view->GetFont())); + wxSize size; + view->GetTextExtent(str, &size.x, &size.y, NULL, NULL, &font); + return size; + } + else + { + return view->GetTextExtent(str); + } +} + void wxDataViewCustomRendererBase::RenderText(const wxString& text, int xoffset, @@ -1485,11 +1528,11 @@ wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayS wxDataViewChoiceRenderer( choices, mode, alignment ) { } - + wxControl* wxDataViewChoiceByIndexRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) { wxVariant string_value = GetChoice( value.GetLong() ); - + return wxDataViewChoiceRenderer::CreateEditorCtrl( parent, labelRect, string_value ); } @@ -1508,13 +1551,13 @@ bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value ) wxVariant string_value = GetChoice( value.GetLong() ); return wxDataViewChoiceRenderer::SetValue( string_value ); } - + bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const { wxVariant string_value; if (!wxDataViewChoiceRenderer::GetValue( string_value )) return false; - + value = (long) GetChoices().Index( string_value.GetString() ); return true; }