X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a75124d0da255513e83d2e62f963dd849829466b..1a18f241bdb52052298892330d9baf8a4925726c:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 4d1c9dd89c..7303a0b119 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -40,7 +40,7 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) #ifdef __WXDEBUG__ void wxDataViewItem::Print(const wxString& text) const { - wxPrintf("item %s: %l\n", text, (long)m_id); + wxPrintf(wxT("item %s: %l\n"), text.GetData(), (long)m_id); } #endif @@ -326,6 +326,29 @@ wxDataViewIndexListModel::~wxDataViewIndexListModel() { } +void wxDataViewIndexListModel::Reset( unsigned int new_size ) +{ + if (m_useHash) + { + m_hash.Clear(); + + // IDs are ordered until an item gets deleted or inserted + m_ordered = true; + + // build initial index + unsigned int i; + for (i = 1; i < new_size+1; i++) + m_hash.Add( (void*) i ); + m_lastIndex = new_size + 1; + } + else + { + m_lastIndex = new_size-1; + } + + wxDataViewModel::Cleared(); +} + void wxDataViewIndexListModel::RowPrepended() { if (m_useHash) @@ -385,6 +408,8 @@ void wxDataViewIndexListModel::RowDeleted( unsigned int row ) { if (m_useHash) { + m_ordered = false; + wxDataViewItem item( m_hash[row] ); wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); m_hash.RemoveAt( row ); @@ -397,6 +422,47 @@ void wxDataViewIndexListModel::RowDeleted( unsigned int row ) } } +static int my_sort( int *v1, int *v2 ) +{ + return *v2-*v1; +} + +void wxDataViewIndexListModel::RowsDeleted( const wxArrayInt &rows ) +{ + wxArrayInt sorted = rows; + sorted.Sort( my_sort ); + + if (m_useHash) + { + m_ordered = false; + + wxDataViewItemArray array; + unsigned int i; + for (i = 0; i < rows.GetCount(); i++) + { + wxDataViewItem item( m_hash[rows[i]] ); + array.Add( item ); + } + wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array ); + + for (i = 0; i < sorted.GetCount(); i++) + m_hash.RemoveAt( sorted[i] ); + } + else + { + wxDataViewItemArray array; + unsigned int i; + for (i = 0; i < sorted.GetCount(); i++) + { + wxDataViewItem item( (void*) sorted[i] ); + array.Add( item ); + } + wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array ); + + m_lastIndex -= rows.GetCount(); + } +} + void wxDataViewIndexListModel::RowChanged( unsigned int row ) { wxDataViewModel::ItemChanged( GetItem(row) ); @@ -506,7 +572,7 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, return 0; children = m_hash; - + return m_hash.GetCount(); } @@ -735,6 +801,7 @@ void wxDataViewColumnBase::SetFlags(int flags) SetSortable((flags & wxDATAVIEW_COL_SORTABLE) != 0); SetResizeable((flags & wxDATAVIEW_COL_RESIZABLE) != 0); SetHidden((flags & wxDATAVIEW_COL_HIDDEN) != 0); + SetReorderable((flags & wxDATAVIEW_COL_REORDERABLE) != 0); } // --------------------------------------------------------- @@ -1083,9 +1150,12 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED) DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE) DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_VALUE_CHANGED) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_ITEM_CONTEXT_MENU) + DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK) DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) +DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_REORDERED) // ------------------------------------- @@ -1093,7 +1163,7 @@ DEFINE_EVENT_TYPE(wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED) // ------------------------------------- wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCellMode mode, int alignment ) : - wxDataViewCustomRenderer( "long", mode, alignment ) + wxDataViewCustomRenderer(wxT("long"), mode, alignment ) { m_min = min; m_max = max; @@ -1102,8 +1172,21 @@ wxDataViewSpinRenderer::wxDataViewSpinRenderer( int min, int max, wxDataViewCell wxControl* wxDataViewSpinRenderer::CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value ) { long l = value; - return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString, - labelRect.GetTopLeft(), labelRect.GetSize(), wxSP_ARROW_KEYS, m_min, m_max, l ); + wxSize size = labelRect.GetSize(); +#ifdef __WXMAC__ + size = wxSize( wxMax(70,labelRect.width ), -1 ); +#endif + wxString str; + str.Printf( wxT("%d\n"), (int) l ); + wxSpinCtrl *sc = new wxSpinCtrl( parent, wxID_ANY, str, + labelRect.GetTopLeft(), size, wxSP_ARROW_KEYS, m_min, m_max, l ); +#ifdef __WXMAC__ + size = sc->GetSize(); + wxPoint pt = sc->GetPosition(); + sc->SetSize( pt.x - 4, pt.y - 4, size.x, size.y ); +#endif + + return sc; } bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVariant &value ) @@ -1117,7 +1200,7 @@ bool wxDataViewSpinRenderer::GetValueFromEditorCtrl( wxControl* editor, wxVarian bool wxDataViewSpinRenderer::Render( wxRect rect, wxDC *dc, int state ) { wxString str; - str.Printf( "%d", (int) m_data ); + str.Printf(wxT("%d"), (int) m_data ); RenderText( str, 0, rect, dc, state ); return true; } @@ -1559,6 +1642,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxDataViewTreeCtrl,wxDataViewCtrl) BEGIN_EVENT_TABLE(wxDataViewTreeCtrl,wxDataViewCtrl) EVT_DATAVIEW_ITEM_EXPANDED(-1, wxDataViewTreeCtrl::OnExpanded) EVT_DATAVIEW_ITEM_COLLAPSED(-1, wxDataViewTreeCtrl::OnCollapsed) + EVT_SIZE( wxDataViewTreeCtrl::OnSize ) END_EVENT_TABLE() wxDataViewTreeCtrl::wxDataViewTreeCtrl() @@ -1575,7 +1659,8 @@ wxDataViewTreeCtrl::wxDataViewTreeCtrl( wxWindow *parent, wxWindowID id, wxDataViewTreeStore *store = new wxDataViewTreeStore; AssociateModel( store ); store->DecRef(); - AppendIconTextColumn( "", 0, wxDATAVIEW_CELL_INERT, 200 ); + + AppendIconTextColumn(wxString(),0,wxDATAVIEW_CELL_INERT,-1); } wxDataViewTreeCtrl::~wxDataViewTreeCtrl() @@ -1670,7 +1755,6 @@ wxDataViewItem wxDataViewTreeCtrl::InsertContainer( const wxDataViewItem& parent return GetStore()->InsertContainer( parent, previous, text, icon, expanded, data ); } - void wxDataViewTreeCtrl::OnExpanded( wxDataViewEvent &event ) { if (m_imageList) return; @@ -1693,6 +1777,16 @@ void wxDataViewTreeCtrl::OnCollapsed( wxDataViewEvent &event ) GetStore()->ItemChanged( event.GetItem() ); } +void wxDataViewTreeCtrl::OnSize( wxSizeEvent &event ) +{ +#if defined(wxUSE_GENERICDATAVIEWCTRL) + wxSize size = GetClientSize(); + wxDataViewColumn *col = GetColumn( 0 ); + if (col) + col->SetWidth( size.x ); +#endif + event.Skip( true ); +} #endif // wxUSE_DATAVIEWCTRL