X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/40dc2ae656521edfa1bd4ece65003c9956120491..b5e9cbb92d56a2bccf5ef65986727f1bdcd96328:/src/generic/headerctrlg.cpp diff --git a/src/generic/headerctrlg.cpp b/src/generic/headerctrlg.cpp index f55b7e1f6f..8d8adc9fc4 100644 --- a/src/generic/headerctrlg.cpp +++ b/src/generic/headerctrlg.cpp @@ -134,7 +134,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const { wxHeaderCtrl * const self = const_cast(this); - int pos = 0; + int pos = m_scrollOffset; for ( unsigned n = 0; n < idx; n++ ) { const wxHeaderColumnBase& col = self->GetColumn(n); @@ -145,6 +145,41 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const return pos; } +int wxHeaderCtrl::FindColumnAtPos(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 wxHeaderColumnBase& col = self->GetColumn(n); + if ( col.IsHidden() ) + continue; + + pos += col.GetWidth(); + + // if the column is resizeable, check if we're approximatively over the + // line separating it from the next column + // + // TODO: don't hardcode sensitivity + if ( col.IsResizeable() && abs(x - pos) < 8 ) + { + onSeparator = true; + return n; + } + + // inside this column? + if ( x < pos ) + { + onSeparator = false; + return n; + } + } + + return COL_NONE; +} + // ---------------------------------------------------------------------------- // wxHeaderCtrl repainting // ---------------------------------------------------------------------------- @@ -158,6 +193,12 @@ void wxHeaderCtrl::RefreshCol(unsigned int idx) RefreshRect(rect); } +void wxHeaderCtrl::RefreshColIfNotNone(unsigned int idx) +{ + if ( idx != COL_NONE ) + RefreshCol(idx); +} + void wxHeaderCtrl::RefreshColsAfter(unsigned int idx) { wxRect rect = GetClientRect(); @@ -172,7 +213,7 @@ void wxHeaderCtrl::RefreshColsAfter(unsigned int idx) // wxHeaderCtrl event handlers // ---------------------------------------------------------------------------- -BEGIN_EVENT_TABLE(wxHeaderCtrl, wxControl) +BEGIN_EVENT_TABLE(wxHeaderCtrl, wxHeaderCtrlBase) EVT_PAINT(wxHeaderCtrl::OnPaint) EVT_MOUSE_EVENTS(wxHeaderCtrl::OnMouse) @@ -242,9 +283,98 @@ void wxHeaderCtrl::OnPaint(wxPaintEvent& WXUNUSED(event)) } } -void wxHeaderCtrl::OnMouse(wxMouseEvent& event) +void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent) { - event.Skip(); + mevent.Skip(); + + // account for the control displacement + const int x = mevent.GetX() - m_scrollOffset; + + // find if the event is over a column at all + bool onSeparator; + const unsigned col = mevent.Leaving() + ? (onSeparator = false, COL_NONE) + : FindColumnAtPos(x, onSeparator); + + // update the highlighted column if it changed + if ( col != m_hover ) + { + const unsigned hoverOld = m_hover; + m_hover = col; + + RefreshColIfNotNone(hoverOld); + RefreshColIfNotNone(m_hover); + } + + if ( col == COL_NONE ) + return; + + // update mouse cursor as it moves around + if ( mevent.Moving() ) + { + SetCursor(onSeparator ? wxCursor(wxCURSOR_SIZEWE) : wxNullCursor); + return; + } + + if ( mevent.LeftDown() ) + { + // TODO + if ( onSeparator ) + // resize column + ; + else + // drag column + ; + + return; + } + + // determine the type of header event corresponding to this mouse event + wxEventType evtType = wxEVT_NULL; + const bool click = mevent.ButtonUp(), + dblclk = mevent.ButtonDClick(); + if ( click || dblclk ) + { + switch ( mevent.GetButton() ) + { + case wxMOUSE_BTN_LEFT: + // treat left double clicks on separator specially + if ( onSeparator && dblclk ) + { + evtType = wxEVT_COMMAND_HEADER_SEPARATOR_DCLICK; + } + else // not double click on separator + { + evtType = click ? wxEVT_COMMAND_HEADER_CLICK + : wxEVT_COMMAND_HEADER_DCLICK; + } + break; + + case wxMOUSE_BTN_RIGHT: + evtType = click ? wxEVT_COMMAND_HEADER_RIGHT_CLICK + : wxEVT_COMMAND_HEADER_RIGHT_DCLICK; + break; + + case wxMOUSE_BTN_MIDDLE: + evtType = click ? wxEVT_COMMAND_HEADER_MIDDLE_CLICK + : wxEVT_COMMAND_HEADER_MIDDLE_DCLICK; + break; + + default: + // ignore clicks from other mouse buttons + ; + } + } + + if ( evtType == wxEVT_NULL ) + return; + + wxHeaderCtrlEvent event(evtType, GetId()); + event.SetEventObject(this); + event.SetColumn(col); + + if ( GetEventHandler()->ProcessEvent(event) ) + mevent.Skip(false); } #endif // wxHAS_GENERIC_HEADERCTRL