]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/headerctrlg.cpp
enable wheel-scrolling under wxGTK by allowing GTK+ default processing to happen...
[wxWidgets.git] / src / generic / headerctrlg.cpp
index 823ea60aac8254025f8dbb4cefe74e27f4afa2d3..8d8adc9fc42c2a9bdae0ccdc98f82d47274c471a 100644 (file)
@@ -134,7 +134,7 @@ int wxHeaderCtrl::GetColStart(unsigned int idx) const
 {
     wxHeaderCtrl * const self = const_cast<wxHeaderCtrl *>(this);
 
-    int pos = 0;
+    int pos = m_scrollOffset;
     for ( unsigned n = 0; n < idx; n++ )
     {
         const wxHeaderColumnBase& col = self->GetColumn(n);
@@ -193,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();
@@ -207,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)
@@ -281,9 +287,25 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
 {
     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 = FindColumnAtPos(mevent.GetX(), 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;
 
@@ -308,15 +330,24 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
     }
 
     // determine the type of header event corresponding to this mouse event
-    wxEventType evtType;
-    const bool click = mevent.ButtonUp();
-    if ( click || mevent.ButtonDClick() )
+    wxEventType evtType = wxEVT_NULL;
+    const bool click = mevent.ButtonUp(),
+               dblclk = mevent.ButtonDClick();
+    if ( click || dblclk )
     {
         switch ( mevent.GetButton() )
         {
             case wxMOUSE_BTN_LEFT:
-                evtType = click ? wxEVT_COMMAND_HEADER_CLICK
-                                : wxEVT_COMMAND_HEADER_DCLICK;
+                // 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:
@@ -331,16 +362,19 @@ void wxHeaderCtrl::OnMouse(wxMouseEvent& mevent)
 
             default:
                 // ignore clicks from other mouse buttons
-                return;
+                ;
         }
+    }
 
-        wxHeaderCtrlEvent event(evtType, GetId());
-        event.SetEventObject(this);
-        event.SetColumn(col);
+    if ( evtType == wxEVT_NULL )
+        return;
 
-        if ( GetEventHandler()->ProcessEvent(event) )
-            mevent.Skip(false);
-    }
+    wxHeaderCtrlEvent event(evtType, GetId());
+    event.SetEventObject(this);
+    event.SetColumn(col);
+
+    if ( GetEventHandler()->ProcessEvent(event) )
+        mevent.Skip(false);
 }
 
 #endif // wxHAS_GENERIC_HEADERCTRL