From fc8c1a15b2154214ac744516b15a283b32990f39 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Fri, 28 Dec 2007 23:07:30 +0000 Subject: [PATCH] Implement rest of MSW's wxDataViewCtrl's native column reordering git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50940 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/dataview.h | 3 +++ src/generic/datavgen.cpp | 33 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 7bf0e396d8..51faf5f7c2 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -469,6 +469,9 @@ public: // utility functions not part of the API return GetClientSize().GetWidth() / GetColumnCount(); } + // called by header window after reorder + void ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ); + // updates the header window after a change in a column setting void OnColumnChange(); diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 6fafd57a25..602b4cb551 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -137,6 +137,8 @@ public: // called when any column setting is changed and/or changed // the column count virtual void UpdateDisplay(); + + virtual void OnInternalIdle(); // called Refresh afterwards virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL); @@ -155,8 +157,9 @@ protected: wxDataViewColumn *GetColumnFromHeader(NMHEADER *nmHDR) { return GetColumn(GetColumnIdxFromHeader(nmHDR)); } - int m_scrollOffsetX; - int m_buttonHeight; + int m_scrollOffsetX; + int m_buttonHeight; + bool m_delayedUpdate; private: DECLARE_DYNAMIC_CLASS(wxDataViewHeaderWindowMSW) @@ -1281,6 +1284,7 @@ bool wxDataViewHeaderWindowMSW::Create( wxDataViewCtrl *parent, wxWindowID id, m_owner = parent; m_scrollOffsetX = 0; + m_delayedUpdate = false; m_buttonHeight = wxRendererNative::Get().GetHeaderButtonHeight( this ); int x = pos.x == wxDefaultCoord ? 0 : pos.x, @@ -1333,7 +1337,16 @@ wxDataViewHeaderWindowMSW::~wxDataViewHeaderWindow() wxSize wxDataViewHeaderWindowMSW::DoGetBestSize() const { - return wxSize(80, m_buttonHeight ); + return wxSize( 80, m_buttonHeight+2 ); +} + +void wxDataViewHeaderWindowMSW::OnInternalIdle() +{ + if (m_delayedUpdate) + { + m_delayedUpdate = false; + UpdateDisplay(); + } } void wxDataViewHeaderWindowMSW::UpdateDisplay() @@ -1456,7 +1469,10 @@ bool wxDataViewHeaderWindowMSW::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARA case HDN_ENDDRAG: // user has finished reordering a column { - // TODO: How to query the new position here? + wxDataViewColumn *col = GetColumn(nmHDR->iItem); + unsigned int new_pos = nmHDR->pitem->iOrder; + m_owner->ColumnMoved( col, new_pos ); + m_delayedUpdate = true; } break; @@ -3965,6 +3981,15 @@ wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const return NULL; } +void wxDataViewCtrl::ColumnMoved( wxDataViewColumn* col, unsigned int new_pos ) +{ + if (new_pos > m_cols.GetCount()) return; + m_cols.DeleteObject( col ); + m_cols.Insert( new_pos, col ); + + m_clientArea->UpdateDisplay(); +} + bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column ) { wxDataViewColumnList::compatibility_iterator ret = m_cols.Find( column );