X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da678e6c3911929406b8fc49e26c520ac2fd9444..ecdf28983ce7862b1a0f2a5fe4c3001a5e9df81b:/src/generic/headerctrlg.cpp diff --git a/src/generic/headerctrlg.cpp b/src/generic/headerctrlg.cpp index 85548d7b97..48e3117c39 100644 --- a/src/generic/headerctrlg.cpp +++ b/src/generic/headerctrlg.cpp @@ -23,8 +23,7 @@ #pragma hdrstop #endif -#ifndef WX_PRECOMP -#endif // WX_PRECOMP +#if wxUSE_HEADERCTRL #include "wx/headerctrl.h" @@ -92,32 +91,12 @@ wxHeaderCtrl::~wxHeaderCtrl() void wxHeaderCtrl::DoSetCount(unsigned int count) { - // update the column indices array if necessary - if ( count > m_numColumns ) - { - // all new columns have default positions equal to their indices - for ( unsigned n = m_numColumns; n < count; n++ ) - m_colIndices.push_back(n); - } - else if ( count < m_numColumns ) - { - // filter out all the positions which are invalid now while keeping the - // order of the remaining ones - wxArrayInt colIndices; - for ( unsigned n = 0; n < m_numColumns; n++ ) - { - const unsigned idx = m_colIndices[n]; - if ( idx < count ) - colIndices.push_back(idx); - } - - wxASSERT_MSG( colIndices.size() == count, "logic error" ); - - m_colIndices = colIndices; - } + // update the column indices order array before changing m_numColumns + DoResizeColumnIndices(m_colIndices, count); m_numColumns = count; + InvalidateBestSize(); Refresh(); } @@ -128,6 +107,8 @@ unsigned int wxHeaderCtrl::DoGetCount() const void wxHeaderCtrl::DoUpdate(unsigned int idx) { + InvalidateBestSize(); + // we need to refresh not only this column but also the ones after it in // case it was shown or hidden or its width changed -- it would be nice to // avoid doing this unnecessary by storing the old column width (TODO) @@ -152,17 +133,20 @@ void wxHeaderCtrl::DoScrollHorz(int dx) wxSize wxHeaderCtrl::DoGetBestSize() const { + wxWindow *win = GetParent(); + int height = wxRendererNative::Get().GetHeaderButtonHeight( win ); + // the vertical size is rather arbitrary but it looks better if we leave // some space around the text - return wxSize(IsEmpty() ? wxHeaderCtrlBase::DoGetBestSize().x - : GetColEnd(GetColumnCount() - 1), - (7*GetCharHeight())/4); + const wxSize size(IsEmpty() ? wxHeaderCtrlBase::DoGetBestSize().x + : GetColEnd(GetColumnCount() - 1), + height ); // (7*GetCharHeight())/4); + CacheBestSize(size); + return size; } int wxHeaderCtrl::GetColStart(unsigned int idx) const { - wxHeaderCtrl * const self = const_cast(this); - int pos = m_scrollOffset; for ( unsigned n = 0; ; n++ ) { @@ -170,7 +154,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const if ( i == idx ) break; - const wxHeaderColumnBase& col = self->GetColumn(i); + const wxHeaderColumn& col = GetColumn(i); if ( col.IsShown() ) pos += col.GetWidth(); } @@ -182,19 +166,17 @@ int wxHeaderCtrl::GetColEnd(unsigned int idx) const { int x = GetColStart(idx); - return x + const_cast(this)->GetColumn(idx).GetWidth(); + return x + GetColumn(idx).GetWidth(); } unsigned int wxHeaderCtrl::FindColumnAtPoint(int x, bool *onSeparator) const { - wxHeaderCtrl * const self = const_cast(this); - int pos = 0; const unsigned count = GetColumnCount(); for ( unsigned n = 0; n < count; n++ ) { const unsigned idx = m_colIndices[n]; - const wxHeaderColumnBase& col = self->GetColumn(idx); + const wxHeaderColumn& col = GetColumn(idx); if ( col.IsHidden() ) continue; @@ -220,6 +202,8 @@ unsigned int wxHeaderCtrl::FindColumnAtPoint(int x, bool *onSeparator) const } } + if ( onSeparator ) + *onSeparator = false; return COL_NONE; } @@ -429,10 +413,12 @@ void wxHeaderCtrl::StartReordering(unsigned int col, int xPhysical) SetCursor(wxCursor(wxCURSOR_HAND)); CaptureMouse(); - UpdateReorderingMarker(xPhysical); + // do not call UpdateReorderingMarker() here: we don't want to give + // feedback for reordering until the user starts to really move the mouse + // as he might want to just click on the column and not move it at all } -void wxHeaderCtrl::EndReordering(int xPhysical) +bool wxHeaderCtrl::EndReordering(int xPhysical) { wxASSERT_MSG( IsReordering(), "shouldn't be called if we're not reordering" ); @@ -440,20 +426,33 @@ void wxHeaderCtrl::EndReordering(int xPhysical) ReleaseMouse(); - wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId()); - event.SetEventObject(this); - event.SetColumn(m_colBeingReordered); + const int colOld = m_colBeingReordered, + colNew = FindColumnAtPoint(xPhysical); + + m_colBeingReordered = COL_NONE; - const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical)); - event.SetNewOrder(pos); + if ( xPhysical - GetColStart(colOld) == m_dragOffset ) + return false; - if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) + if ( colNew != colOld ) { - // do reorder the columns - DoMoveCol(m_colBeingReordered, pos); + wxHeaderCtrlEvent event(wxEVT_COMMAND_HEADER_END_REORDER, GetId()); + event.SetEventObject(this); + event.SetColumn(colOld); + + const unsigned pos = GetColumnPos(FindColumnAtPoint(xPhysical)); + event.SetNewOrder(pos); + + if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) + { + // do reorder the columns + DoMoveCol(colOld, pos); + } } - m_colBeingReordered = COL_NONE; + // whether we moved the column or not, the user did move the mouse and so + // did try to do it so return true + return true; } // ---------------------------------------------------------------------------- @@ -473,28 +472,7 @@ wxArrayInt wxHeaderCtrl::DoGetColumnsOrder() const void wxHeaderCtrl::DoMoveCol(unsigned int idx, unsigned int pos) { - const unsigned count = m_colIndices.size(); - - wxArrayInt colIndices; - colIndices.reserve(count); - for ( unsigned n = 0; n < count; n++ ) - { - // NB: order of checks is important for this to work when the new - // column position is the same as the old one - - // insert the column at its new position - if ( colIndices.size() == pos ) - colIndices.push_back(idx); - - // delete the column from its old position - const unsigned idxOld = m_colIndices[n]; - if ( idxOld == idx ) - continue; - - colIndices.push_back(idxOld); - } - - m_colIndices = colIndices; + MoveColumnInOrderArray(m_colIndices, idx, pos); Refresh(); } @@ -517,6 +495,11 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { int w, h; GetClientSize(&w, &h); + +#ifdef __WXGTK__ + int vw; + GetVirtualSize(&vw, NULL); +#endif wxAutoBufferedPaintDC dc(this); @@ -531,11 +514,11 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) for ( unsigned int i = 0; i < count; i++ ) { const unsigned idx = m_colIndices[i]; - const wxHeaderColumnBase& col = GetColumn(idx); + const wxHeaderColumn& col = GetColumn(idx); if ( col.IsHidden() ) continue; - const int colWidth = col.GetWidth(); + int colWidth = col.GetWidth(); wxHeaderSortIconType sortArrow; if ( col.IsSortKey() ) @@ -558,11 +541,22 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) { state = wxCONTROL_DISABLED; } + + if (i == 0) + state |= wxCONTROL_SPECIAL; wxHeaderButtonParams params; params.m_labelText = col.GetTitle(); params.m_labelBitmap = col.GetBitmap(); params.m_labelAlignment = col.GetAlignment(); + +#ifdef __WXGTK__ + if (i == count-1) + { + colWidth = wxMax( colWidth, vw - xpos ); + state |= wxCONTROL_EXPANDED; + } +#endif wxRendererNative::Get().DrawHeaderButton ( @@ -625,12 +619,18 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) if ( IsReordering() ) { - if ( mevent.LeftUp() ) - EndReordering(xPhysical); - else // update the column position + if ( !mevent.LeftUp() ) + { + // update the column position UpdateReorderingMarker(xPhysical); - return; + return; + } + + // finish reordering and continue to generate a click event below if we + // didn't really reorder anything + if ( EndReordering(xPhysical) ) + return; } @@ -732,3 +732,5 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) } #endif // wxHAS_GENERIC_HEADERCTRL + +#endif // wxUSE_HEADERCTRL