]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/listctrl.cpp
remove duplicated HitTest implementation from wxCheckListBox, it already inherits...
[wxWidgets.git] / src / generic / listctrl.cpp
index eb553e13284246cc89ac8fee169697e7ff3453a5..f33e2b1437adc2b1757254fee60d8a0dd947126b 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "wx/listctrl.h"
 
-#if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__)
+#if ((!defined(__WXMSW__) && !(defined(__WXMAC__) && wxOSX_USE_CARBON)) || defined(__WXUNIVERSAL__))
     // if we have a native version, its implementation file does all this
     IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject)
     IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl)
@@ -43,6 +43,7 @@
     #include "wx/dcscreen.h"
     #include "wx/math.h"
     #include "wx/settings.h"
+    #include "wx/sizer.h"
 #endif
 
 #include "wx/imaglist.h"
@@ -50,7 +51,9 @@
 #include "wx/renderer.h"
 
 #ifdef __WXMAC__
-    #include "wx/mac/private.h"
+    #include "wx/osx/private.h"
+    // for themeing support
+    #include <Carbon/Carbon.h>
 #endif
 
 
@@ -77,7 +80,12 @@ static const int EXTRA_WIDTH = 6;
 #else
 static const int EXTRA_WIDTH = 4;
 #endif
+
+#ifdef __WXGTK__
+static const int EXTRA_HEIGHT = 6;
+#else
 static const int EXTRA_HEIGHT = 4;
+#endif
 
 // margin between the window and the items
 static const int EXTRA_BORDER_X = 2;
@@ -424,6 +432,13 @@ public:
     // needs refresh
     bool m_dirty;
 
+    // Update main window's column later
+    bool m_sendSetColumnWidth;
+    int m_colToSend;
+    int m_widthToSend;
+
+    virtual void OnInternalIdle();
+
 private:
     // common part of all ctors
     void Init();
@@ -491,7 +506,7 @@ WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList);
 #include "wx/listimpl.cpp"
 WX_DEFINE_LIST(wxListHeaderDataList)
 
-class wxListMainWindow : public wxScrolledCanvas
+class wxListMainWindow : public wxWindow
 {
 public:
     wxListMainWindow();
@@ -615,6 +630,8 @@ public:
 
     void OnPaint( wxPaintEvent &event );
 
+    void OnChildFocus(wxChildFocusEvent& event);
+
     void DrawImage( int index, wxDC *dc, int x, int y );
     void GetImageSize( int index, int &width, int &height ) const;
     int GetTextLength( const wxString &s ) const;
@@ -639,7 +656,11 @@ public:
     void SetItemState( long item, long state, long stateMask );
     void SetItemStateAll( long state, long stateMask );
     int GetItemState( long item, long stateMask ) const;
-    void GetItemRect( long index, wxRect &rect ) const;
+    bool GetItemRect( long item, wxRect &rect ) const
+    {
+        return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect);
+    }
+    bool GetSubItemRect( long item, long subItem, wxRect& rect ) const;
     wxRect GetViewRect() const;
     bool GetItemPosition( long item, wxPoint& pos ) const;
     int GetSelectedItemCount() const;
@@ -700,7 +721,7 @@ public:
     // override base class virtual to reset m_lineHeight when the font changes
     virtual bool SetFont(const wxFont& font)
     {
-        if ( !wxScrolledCanvas::SetFont(font) )
+        if ( !wxWindow::SetFont(font) )
             return false;
 
         m_lineHeight = 0;
@@ -1406,7 +1427,7 @@ bool wxListLineData::SetAttributes(wxDC *dc,
 #ifdef __WXMAC__
     {
         if (m_owner->HasFocus()
-#if !defined(__WXUNIVERSAL__)
+#if !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
                 && IsControlActive( (ControlRef)m_owner->GetHandle() )
 #endif
         )
@@ -1470,7 +1491,7 @@ void wxListLineData::Draw( wxDC *dc )
         {
             int flags = wxCONTROL_SELECTED;
             if (m_owner->HasFocus()
-#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
+#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
                 && IsControlActive( (ControlRef)m_owner->GetHandle() )
 #endif
             )
@@ -1692,17 +1713,18 @@ END_EVENT_TABLE()
 
 void wxListHeaderWindow::Init()
 {
-    m_currentCursor = (wxCursor *) NULL;
+    m_currentCursor = NULL;
     m_isDragging = false;
     m_dirty = false;
+    m_sendSetColumnWidth = false;
 }
 
 wxListHeaderWindow::wxListHeaderWindow()
 {
     Init();
 
-    m_owner = (wxListMainWindow *) NULL;
-    m_resizeCursor = (wxCursor *) NULL;
+    m_owner = NULL;
+    m_resizeCursor = NULL;
 }
 
 wxListHeaderWindow::wxListHeaderWindow( wxWindow *win,
@@ -1747,11 +1769,13 @@ wxListHeaderWindow::~wxListHeaderWindow()
 // scrollbar: this allows us to always use logical coords
 void wxListHeaderWindow::AdjustDC(wxDC& dc)
 {
+    wxGenericListCtrl *parent = m_owner->GetListCtrl();
+
     int xpix;
-    m_owner->GetScrollPixelsPerUnit( &xpix, NULL );
+    parent->GetScrollPixelsPerUnit( &xpix, NULL );
 
     int view_start;
-    m_owner->GetViewStart( &view_start, NULL );
+    parent->GetViewStart( &view_start, NULL );
 
 
     int org_x = 0;
@@ -1774,9 +1798,10 @@ void wxListHeaderWindow::AdjustDC(wxDC& dc)
 
 void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 {
+    wxGenericListCtrl *parent = m_owner->GetListCtrl();
+
     wxPaintDC dc( this );
 
-    PrepareDC( dc );
     AdjustDC( dc );
 
     dc.SetFont( GetFont() );
@@ -1784,7 +1809,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
     // width and height of the entire header window
     int w, h;
     GetClientSize( &w, &h );
-    m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
+    parent->CalcUnscrolledPosition(w, 0, &w, NULL);
 
     dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
     dc.SetTextForeground(GetForegroundColour());
@@ -1814,6 +1839,9 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
             flags |= wxCONTROL_SELECTED;
 #endif
 
+        if (i == 0)
+           flags |= wxCONTROL_SPECIAL; // mark as first column
+
         wxRendererNative::Get().DrawHeaderButton
                                 (
                                     this,
@@ -1891,12 +1919,39 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
 
         x += wCol;
     }
+
+    // Fill in what's missing to the right of the columns, otherwise we will
+    // leave an unpainted area when columns are removed (and it looks better)
+    if ( x < w )
+    {
+        wxRendererNative::Get().DrawHeaderButton
+                                (
+                                    this,
+                                    dc,
+                                    wxRect(x, HEADER_OFFSET_Y, w - x, h),
+                                    wxCONTROL_DIRTY // mark as last column
+                                );
+    }
+}
+
+void wxListHeaderWindow::OnInternalIdle()
+{
+    wxWindow::OnInternalIdle();
+
+    if (m_sendSetColumnWidth)
+    {
+        m_owner->SetColumnWidth( m_colToSend, m_widthToSend );
+        m_sendSetColumnWidth = false;
+    }
 }
 
 void wxListHeaderWindow::DrawCurrent()
 {
 #if 1
-    m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
+    // m_owner->SetColumnWidth( m_column, m_currentX - m_minX );
+    m_sendSetColumnWidth = true;
+    m_colToSend = m_column;
+    m_widthToSend = m_currentX - m_minX;
 #else
     int x1 = m_currentX;
     int y1 = 0;
@@ -1925,9 +1980,11 @@ void wxListHeaderWindow::DrawCurrent()
 
 void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
 {
+    wxGenericListCtrl *parent = m_owner->GetListCtrl();
+
     // we want to work with logical coords
     int x;
-    m_owner->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
+    parent->CalcUnscrolledPosition(event.GetX(), 0, &x, NULL);
     int y = event.GetY();
 
     if (m_isDragging)
@@ -1938,7 +1995,7 @@ void wxListHeaderWindow::OnMouse( wxMouseEvent &event )
         // there
         int w = 0;
         GetClientSize( &w, NULL );
-        m_owner->CalcUnscrolledPosition(w, 0, &w, NULL);
+        parent->CalcUnscrolledPosition(w, 0, &w, NULL);
         w -= 6;
 
         // erase the line if it was drawn
@@ -2115,9 +2172,11 @@ wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner,
     m_text = text;
     m_aboutToFinish = false;
 
+    wxGenericListCtrl *parent = m_owner->GetListCtrl();
+
     wxRect rectLabel = owner->GetLineLabelRect(itemEdit);
 
-    m_owner->CalcScrolledPosition(rectLabel.x, rectLabel.y,
+    parent->CalcScrolledPosition(rectLabel.x, rectLabel.y,
                                   &rectLabel.x, &rectLabel.y);
 
     m_text->Create(owner, wxID_ANY, m_startValue,
@@ -2242,6 +2301,7 @@ BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledCanvas)
   EVT_SET_FOCUS      (wxListMainWindow::OnSetFocus)
   EVT_KILL_FOCUS     (wxListMainWindow::OnKillFocus)
   EVT_SCROLLWIN      (wxListMainWindow::OnScroll)
+  EVT_CHILD_FOCUS    (wxListMainWindow::OnChildFocus)
 END_EVENT_TABLE()
 
 void wxListMainWindow::Init()
@@ -2255,8 +2315,8 @@ void wxListMainWindow::Init()
     m_headerWidth =
     m_lineHeight = 0;
 
-    m_small_image_list = (wxImageList *) NULL;
-    m_normal_image_list = (wxImageList *) NULL;
+    m_small_image_list = NULL;
+    m_normal_image_list = NULL;
 
     m_small_spacing = 30;
     m_normal_spacing = 40;
@@ -2280,7 +2340,7 @@ wxListMainWindow::wxListMainWindow()
     Init();
 
     m_highlightBrush =
-    m_highlightUnfocusedBrush = (wxBrush *) NULL;
+    m_highlightUnfocusedBrush = NULL;
 }
 
 wxListMainWindow::wxListMainWindow( wxWindow *parent,
@@ -2289,8 +2349,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent,
                                     const wxSize& size,
                                     long style,
                                     const wxString &name )
-                : wxScrolledCanvas( parent, id, pos, size,
-                                    style | wxHSCROLL | wxVSCROLL, name )
+                : wxWindow( parent, id, pos, size, style, name )
 {
     Init();
 
@@ -2312,8 +2371,6 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent,
                                  wxBRUSHSTYLE_SOLID
                               );
 
-    SetScrollbars( 0, 0, 0, 0, 0, 0 );
-
     wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes();
     SetOwnForegroundColour( attr.colFg );
     SetOwnBackgroundColour( attr.colBg );
@@ -2592,7 +2649,7 @@ void wxListMainWindow::RefreshLine( size_t line )
 
     wxRect rect = GetLineRect(line);
 
-    CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+    GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
     RefreshRect( rect );
 }
 
@@ -2619,7 +2676,7 @@ void wxListMainWindow::RefreshLines( size_t lineFrom, size_t lineTo )
         rect.width = GetClientSize().x;
         rect.height = GetLineY(lineTo) - rect.y + GetLineHeight();
 
-        CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+        GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
         RefreshRect( rect );
     }
     else // !report
@@ -2647,7 +2704,7 @@ void wxListMainWindow::RefreshAfter( size_t lineFrom )
         wxRect rect;
         rect.x = 0;
         rect.y = GetLineY(lineFrom);
-        CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
+        GetListCtrl()->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
 
         wxSize size = GetClientSize();
         rect.width = size.x;
@@ -2704,15 +2761,12 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
     }
 
     if ( m_dirty )
-    {
-        // delay the repainting until we calculate all the items positions
-        return;
-    }
+        RecalculatePositions( false );
 
-    PrepareDC( dc );
+    GetListCtrl()->PrepareDC( dc );
 
     int dev_x, dev_y;
-    CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
+    GetListCtrl()->CalcScrolledPosition( 0, 0, &dev_x, &dev_y );
 
     dc.SetFont( GetFont() );
 
@@ -2853,6 +2907,13 @@ void wxListMainWindow::HighlightAll( bool on )
     }
 }
 
+void wxListMainWindow::OnChildFocus(wxChildFocusEvent& WXUNUSED(event))
+{
+    // Do nothing here.  This prevents the default handler in wxScrolledWindow
+    // from needlessly scrolling the window when the edit control is
+    // dismissed.  See ticket #9563.
+}
+
 void wxListMainWindow::SendNotify( size_t line,
                                    wxEventType command,
                                    const wxPoint& point )
@@ -3026,7 +3087,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event )
 
     int x = event.GetX();
     int y = event.GetY();
-    CalcUnscrolledPosition( x, y, &x, &y );
+    GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
 
     // where did we hit it (if we did)?
     long hitResult = 0;
@@ -3271,9 +3332,9 @@ void wxListMainWindow::MoveToItem(size_t item)
         ResetVisibleLinesRange();
 
         if (rect.y < view_y)
-            Scroll( -1, rect.y / hLine );
+            GetListCtrl()->Scroll( -1, rect.y / hLine );
         if (rect.y + rect.height + 5 > view_y + client_h)
-            Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
+            GetListCtrl()->Scroll( -1, (rect.y + rect.height - client_h + hLine) / hLine );
 
 #ifdef __WXMAC__
         // At least on Mac the visible lines value will get reset inside of
@@ -3301,7 +3362,7 @@ void wxListMainWindow::MoveToItem(size_t item)
         if (rect.y + rect.height - 5 > view_y + client_h)
             sy = (rect.y + rect.height - client_h + hLine) / hLine;
 
-        Scroll(sx, sy);
+        GetListCtrl()->Scroll(sx, sy);
     }
 }
 
@@ -3323,7 +3384,7 @@ bool wxListMainWindow::ScrollList(int WXUNUSED(dx), int dy)
 
     int hLine = GetLineHeight();
 
-    Scroll(-1, top + dy / hLine);
+    GetListCtrl()->Scroll(-1, top + dy / hLine);
 
 #ifdef __WXMAC__
     // see comment in MoveToItem() for why we do this
@@ -3389,16 +3450,10 @@ void wxListMainWindow::OnKeyDown( wxKeyEvent &event )
     wxWindow *parent = GetParent();
 
     // propagate the key event upwards
-    wxKeyEvent ke( wxEVT_KEY_DOWN );
-    ke.m_shiftDown = event.m_shiftDown;
-    ke.m_controlDown = event.m_controlDown;
-    ke.m_altDown = event.m_altDown;
-    ke.m_metaDown = event.m_metaDown;
-    ke.m_keyCode = event.m_keyCode;
-    ke.m_x = event.m_x;
-    ke.m_y = event.m_y;
+    wxKeyEvent ke(event);
     ke.SetEventObject( parent );
-    if (parent->GetEventHandler()->ProcessEvent( ke )) return;
+    if (parent->GetEventHandler()->ProcessEvent( ke ))
+        return;
 
     event.Skip();
 }
@@ -3408,16 +3463,9 @@ void wxListMainWindow::OnKeyUp( wxKeyEvent &event )
     wxWindow *parent = GetParent();
 
     // propagate the key event upwards
-    wxKeyEvent ke( wxEVT_KEY_UP );
-    ke.m_shiftDown = event.m_shiftDown;
-    ke.m_controlDown = event.m_controlDown;
-    ke.m_altDown = event.m_altDown;
-    ke.m_metaDown = event.m_metaDown;
-    ke.m_keyCode = event.m_keyCode;
-    ke.m_x = event.m_x;
-    ke.m_y = event.m_y;
-    ke.SetEventObject( parent );
-    if (parent->GetEventHandler()->ProcessEvent( ke )) return;
+    wxKeyEvent ke(event);
+    if (parent->GetEventHandler()->ProcessEvent( ke ))
+        return;
 
     event.Skip();
 }
@@ -3437,17 +3485,21 @@ void wxListMainWindow::OnChar( wxKeyEvent &event )
         parent->GetEventHandler()->ProcessEvent( le );
     }
 
-    // propagate the char event upwards
-    wxKeyEvent ke( wxEVT_CHAR );
-    ke.m_shiftDown = event.m_shiftDown;
-    ke.m_controlDown = event.m_controlDown;
-    ke.m_altDown = event.m_altDown;
-    ke.m_metaDown = event.m_metaDown;
-    ke.m_keyCode = event.m_keyCode;
-    ke.m_x = event.m_x;
-    ke.m_y = event.m_y;
-    ke.SetEventObject( parent );
-    if (parent->GetEventHandler()->ProcessEvent( ke )) return;
+    if ( (event.GetKeyCode() != WXK_UP) &&
+         (event.GetKeyCode() != WXK_DOWN) &&
+         (event.GetKeyCode() != WXK_RIGHT) &&
+         (event.GetKeyCode() != WXK_LEFT) &&
+         (event.GetKeyCode() != WXK_PAGEUP) &&
+         (event.GetKeyCode() != WXK_PAGEDOWN) &&
+         (event.GetKeyCode() != WXK_END) &&
+         (event.GetKeyCode() != WXK_HOME) )
+    {
+        // propagate the char event upwards
+        wxKeyEvent ke(event);
+        ke.SetEventObject( parent );
+        if (parent->GetEventHandler()->ProcessEvent( ke ))
+            return;
+    }
 
     if ( HandleAsNavigationKey(event) )
         return;
@@ -3742,6 +3794,7 @@ void wxListMainWindow::SetColumnWidth( int col, int width )
                  _T("SetColumnWidth() can only be called in report mode.") );
 
     m_dirty = true;
+
     wxListHeaderWindow *headerWin = GetListCtrl()->m_headerWin;
     if ( headerWin )
         headerWin->m_dirty = true;
@@ -4110,8 +4163,7 @@ int wxListMainWindow::GetSelectedItemCount() const
 
 wxRect wxListMainWindow::GetViewRect() const
 {
-    wxASSERT_MSG( !HasFlag(wxLC_REPORT | wxLC_LIST),
-                    _T("wxListCtrl::GetViewRect() only works in icon mode") );
+    wxASSERT_MSG( !HasFlag(wxLC_LIST), "not implemented for list view" );
 
     // we need to find the longest/tallest label
     wxCoord xMax = 0, yMax = 0;
@@ -4120,8 +4172,9 @@ wxRect wxListMainWindow::GetViewRect() const
     {
         for ( int i = 0; i < count; i++ )
         {
-            wxRect r;
-            GetItemRect(i, r);
+            // we need logical, not physical, coordinates here, so use
+            // GetLineRect() instead of GetItemRect()
+            wxRect r = GetLineRect(i);
 
             wxCoord x = r.GetRight(),
                     y = r.GetBottom();
@@ -4147,10 +4200,14 @@ wxRect wxListMainWindow::GetViewRect() const
     return wxRect(0, 0, xMax, yMax);
 }
 
-void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
+bool
+wxListMainWindow::GetSubItemRect(long item, long subItem, wxRect& rect) const
 {
-    wxCHECK_RET( index >= 0 && (size_t)index < GetItemCount(),
-                 _T("invalid index in GetItemRect") );
+    wxCHECK_MSG( subItem == wxLIST_GETSUBITEMRECT_WHOLEITEM || InReportView(),
+                 false,
+                 _T("GetSubItemRect only meaningful in report view") );
+    wxCHECK_MSG( item >= 0 && (size_t)item < GetItemCount(), false,
+                 _T("invalid item in GetSubItemRect") );
 
     // ensure that we're laid out, otherwise we could return nonsense
     if ( m_dirty )
@@ -4159,9 +4216,24 @@ void wxListMainWindow::GetItemRect( long index, wxRect &rect ) const
             RecalculatePositions(true /* no refresh */);
     }
 
-    rect = GetLineRect((size_t)index);
+    rect = GetLineRect((size_t)item);
+
+    // Adjust rect to specified column
+    if ( subItem != wxLIST_GETSUBITEMRECT_WHOLEITEM )
+    {
+        wxCHECK_MSG( subItem >= 0 && subItem < GetColumnCount(), false,
+                     _T("invalid subItem in GetSubItemRect") );
+
+        for (int i = 0; i < subItem; i++)
+        {
+            rect.x += GetColumnWidth(i);
+        }
+        rect.width = GetColumnWidth(subItem);
+    }
+
+    GetListCtrl()->CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
 
-    CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y);
+    return true;
 }
 
 bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const
@@ -4189,9 +4261,9 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
     const size_t count = GetItemCount();
 
     int iconSpacing;
-    if ( HasFlag(wxLC_ICON) )
+    if ( HasFlag(wxLC_ICON) && m_normal_image_list )
         iconSpacing = m_normal_spacing;
-    else if ( HasFlag(wxLC_SMALL_ICON) )
+    else if ( HasFlag(wxLC_SMALL_ICON) && m_small_image_list )
         iconSpacing = m_small_spacing;
     else
         iconSpacing = 0;
@@ -4225,11 +4297,11 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
 
         ResetVisibleLinesRange();
 
-        SetScrollbars( SCROLL_UNIT_X, lineHeight,
+        GetListCtrl()->SetScrollbars( SCROLL_UNIT_X, lineHeight,
                        GetHeaderWidth() / SCROLL_UNIT_X,
                        (entireHeight + lineHeight - 1) / lineHeight,
-                       GetScrollPos(wxHORIZONTAL),
-                       GetScrollPos(wxVERTICAL),
+                       GetListCtrl()->GetScrollPos(wxHORIZONTAL),
+                       GetListCtrl()->GetScrollPos(wxVERTICAL),
                        true );
     }
     else // !report
@@ -4278,14 +4350,14 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
                 }
             }
 
-            SetScrollbars
+            GetListCtrl()->SetScrollbars
             (
                 SCROLL_UNIT_X,
                 lineHeight,
                 (x + SCROLL_UNIT_X) / SCROLL_UNIT_X,
                 (y + lineHeight) / lineHeight,
-                GetScrollPos( wxHORIZONTAL ),
-                GetScrollPos( wxVERTICAL ),
+                GetListCtrl()->GetScrollPos( wxHORIZONTAL ),
+                GetListCtrl()->GetScrollPos( wxVERTICAL ),
                 true
             );
         }
@@ -4359,13 +4431,13 @@ void wxListMainWindow::RecalculatePositions(bool noRefresh)
                 }
             }
 
-            SetScrollbars
+            GetListCtrl()->SetScrollbars
             (
                 SCROLL_UNIT_X,
                 lineHeight,
                 (entireWidth + SCROLL_UNIT_X) / SCROLL_UNIT_X,
                 0,
-                GetScrollPos( wxHORIZONTAL ),
+                GetListCtrl()->GetScrollPos( wxHORIZONTAL ),
                 0,
                 true
             );
@@ -4668,7 +4740,7 @@ long wxListMainWindow::FindItem( const wxPoint& pt )
 
 long wxListMainWindow::HitTest( int x, int y, int &flags ) const
 {
-    CalcUnscrolledPosition( x, y, &x, &y );
+    GetListCtrl()->CalcUnscrolledPosition( x, y, &x, &y );
 
     size_t count = GetItemCount();
 
@@ -4818,8 +4890,8 @@ int wxListMainWindow::GetItemWidthWithImage(wxListItem * item)
 // sorting
 // ----------------------------------------------------------------------------
 
-wxListCtrlCompare list_ctrl_compare_func_2;
-long              list_ctrl_compare_data;
+static wxListCtrlCompare list_ctrl_compare_func_2;
+static long              list_ctrl_compare_data;
 
 int LINKAGEMODE list_ctrl_compare_func_1( wxListLineData **arg1, wxListLineData **arg2 )
 {
@@ -4852,13 +4924,6 @@ void wxListMainWindow::SortItems( wxListCtrlCompare fn, long data )
 
 void wxListMainWindow::OnScroll(wxScrollWinEvent& event)
 {
-    // FIXME
-#if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__)
-    wxScrolledCanvas::OnScroll(event);
-#else
-    HandleOnScroll( event );
-#endif
-
     // update our idea of which lines are shown when we redraw the window the
     // next time
     ResetVisibleLinesRange();
@@ -4930,21 +4995,22 @@ IMPLEMENT_DYNAMIC_CLASS(wxGenericListCtrl, wxControl)
 
 BEGIN_EVENT_TABLE(wxGenericListCtrl,wxControl)
   EVT_SIZE(wxGenericListCtrl::OnSize)
+  EVT_SCROLLWIN(wxGenericListCtrl::OnScroll)
 END_EVENT_TABLE()
 
-wxGenericListCtrl::wxGenericListCtrl()
+void wxGenericListCtrl::Init()
 {
-    m_imageListNormal = (wxImageList *) NULL;
-    m_imageListSmall = (wxImageList *) NULL;
-    m_imageListState = (wxImageList *) NULL;
+    m_imageListNormal = NULL;
+    m_imageListSmall = NULL;
+    m_imageListState = NULL;
 
     m_ownsImageListNormal =
     m_ownsImageListSmall =
     m_ownsImageListState = false;
 
-    m_mainWin = (wxListMainWindow*) NULL;
-    m_headerWin = (wxListHeaderWindow*) NULL;
-    m_headerHeight = 0;
+    m_mainWin = NULL;
+    m_headerWin = NULL;
+    m_headerHeight = wxRendererNative::Get().GetHeaderButtonHeight(this);
 }
 
 wxGenericListCtrl::~wxGenericListCtrl()
@@ -4957,43 +5023,44 @@ wxGenericListCtrl::~wxGenericListCtrl()
         delete m_imageListState;
 }
 
-void wxGenericListCtrl::CalculateAndSetHeaderHeight()
+void wxGenericListCtrl::CreateOrDestroyHeaderWindowAsNeeded()
 {
-    if ( m_headerWin )
-    {
-#ifdef __WXMAC__
-        SInt32 h;
-        GetThemeMetric( kThemeMetricListHeaderHeight, &h );
-#else
-        // we use 'g' to get the descent, too
-        int w, h, d;
-        m_headerWin->GetTextExtent(wxT("Hg"), &w, &h, &d);
-        h += d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
-#endif
-
-        // only update if changed
-        if ( h != m_headerHeight )
-        {
-            m_headerHeight = h;
+    bool needs_header = HasHeader();
+    bool has_header = (m_headerWin != NULL);
 
-            if ( HasHeader() )
-                ResizeReportView(true);
-            else    //why is this needed if it doesn't have a header?
-                m_headerWin->SetSize(m_headerWin->GetSize().x, m_headerHeight);
-        }
-    }
-}
+    if (needs_header == has_header)
+        return;
 
-void wxGenericListCtrl::CreateHeaderWindow()
-{
-    m_headerWin = new wxListHeaderWindow
+    if (needs_header)
+    {
+        m_headerWin = new wxListHeaderWindow
                       (
                         this, wxID_ANY, m_mainWin,
                         wxPoint(0,0),
                         wxSize(GetClientSize().x, m_headerHeight),
                         wxTAB_TRAVERSAL
                       );
-    CalculateAndSetHeaderHeight();
+
+#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON
+        wxFont font;
+#if wxOSX_USE_ATSU_TEXT
+        font.MacCreateFromThemeFont( kThemeSmallSystemFont );
+#else
+        font.MacCreateFromUIFont( kCTFontSystemFontType );
+#endif
+        m_headerWin->SetFont( font );
+#endif
+
+        GetSizer()->Prepend( m_headerWin, 0, wxGROW );
+    }
+    else
+    {
+        GetSizer()->Detach( m_headerWin );
+
+        delete m_headerWin;
+
+        m_headerWin = NULL;
+    }
 }
 
 bool wxGenericListCtrl::Create(wxWindow *parent,
@@ -5004,66 +5071,81 @@ bool wxGenericListCtrl::Create(wxWindow *parent,
                         const wxValidator &validator,
                         const wxString &name)
 {
-    m_imageListNormal =
-    m_imageListSmall =
-    m_imageListState = (wxImageList *) NULL;
-    m_ownsImageListNormal =
-    m_ownsImageListSmall =
-    m_ownsImageListState = false;
-
-    m_mainWin = (wxListMainWindow*) NULL;
-    m_headerWin = (wxListHeaderWindow*) NULL;
-
-    m_headerHeight = 0;
+    Init();
 
-    if ( !(style & wxLC_MASK_TYPE) )
-    {
-        style = style | wxLC_LIST;
-    }
+    // just like in other ports, an assert will fail if the user doesn't give any type style:
+    wxASSERT_MSG( (style & wxLC_MASK_TYPE),
+                  _T("wxListCtrl style should have exactly one mode bit set") );
 
-    if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
+    if ( !wxControl::Create( parent, id, pos, size, style|wxVSCROLL|wxHSCROLL, validator, name ) )
         return false;
 
-    // this window itself shouldn't get the focus, only m_mainWin should
-    SetCanFocus(false);
-
-    // don't create the inner window with the border
+#ifdef __WXGTK__
     style &= ~wxBORDER_MASK;
+    style |= wxBORDER_THEME;
+#endif
 
     m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style );
 
-#ifdef __WXMAC__
-    // Human Interface Guidelines ask us for a special font in this case
-    if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL )
+    SetTargetWindow( m_mainWin );
+
+    wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );
+    sizer->Add( m_mainWin, 1, wxGROW );
+    SetSizer( sizer );
+
+    CreateOrDestroyHeaderWindowAsNeeded();
+
+    SetInitialSize(size);
+
+    return true;
+}
+
+wxBorder wxGenericListCtrl::GetDefaultBorder() const
+{
+    return wxBORDER_THEME;
+}
+
+#ifdef __WXMSW__
+WXLRESULT wxGenericListCtrl::MSWWindowProc(WXUINT nMsg,
+                                       WXWPARAM wParam,
+                                       WXLPARAM lParam)
+{
+    WXLRESULT rc = wxControl::MSWWindowProc(nMsg, wParam, lParam);
+
+#ifndef __WXWINCE__
+    // we need to process arrows ourselves for scrolling
+    if ( nMsg == WM_GETDLGCODE )
     {
-        wxFont font;
-        font.MacCreateFromThemeFont( kThemeViewsFont );
-        SetFont( font );
+        rc |= DLGC_WANTARROWS;
     }
 #endif
 
-    if ( InReportView() )
-    {
-        CreateHeaderWindow();
-
-#ifdef __WXMAC__
-        if (m_headerWin)
-        {
-            wxFont font;
-            font.MacCreateFromThemeFont( kThemeSmallSystemFont );
-            m_headerWin->SetFont( font );
-            CalculateAndSetHeaderHeight();
-        }
+    return rc;
+}
 #endif
 
-        if ( HasFlag(wxLC_NO_HEADER) )
-            // VZ: why do we create it at all then?
-            m_headerWin->Show( false );
-    }
+wxSize wxGenericListCtrl::GetSizeAvailableForScrollTarget(const wxSize& size)
+{
+    wxSize newsize = size;
+    if (m_headerWin)
+       newsize.y -= m_headerWin->GetSize().y;
 
-    SetInitialSize(size);
+    return newsize;
+}
 
-    return true;
+void wxGenericListCtrl::OnScroll(wxScrollWinEvent& event)
+{
+    // update our idea of which lines are shown when we redraw
+    // the window the next time
+    m_mainWin->ResetVisibleLinesRange();
+
+    HandleOnScroll( event );
+
+    if ( event.GetOrientation() == wxHORIZONTAL && HasHeader() )
+    {
+        m_headerWin->Refresh();
+        m_headerWin->Update();
+    }
 }
 
 void wxGenericListCtrl::SetSingleStyle( long style, bool add )
@@ -5088,45 +5170,28 @@ void wxGenericListCtrl::SetSingleStyle( long style, bool add )
     else
         flag &= ~style;
 
-    SetWindowStyleFlag( flag );
+    // some styles can be set without recreating everything (as happens in
+    // SetWindowStyleFlag() which calls wxListMainWindow::DeleteEverything())
+    if ( !(style & ~(wxLC_HRULES | wxLC_VRULES)) )
+    {
+        Refresh();
+        wxWindow::SetWindowStyleFlag(flag);
+    }
+    else
+    {
+        SetWindowStyleFlag( flag );
+    }
 }
 
 void wxGenericListCtrl::SetWindowStyleFlag( long flag )
 {
     if (m_mainWin)
     {
-        m_mainWin->DeleteEverything();
+        // m_mainWin->DeleteEverything();  wxMSW doesn't do that
 
-        // has the header visibility changed?
-        bool hasHeader = HasHeader();
-        bool willHaveHeader = (flag & wxLC_REPORT) && !(flag & wxLC_NO_HEADER);
+        CreateOrDestroyHeaderWindowAsNeeded();
 
-        if ( hasHeader != willHaveHeader )
-        {
-            // toggle it
-            if ( hasHeader )
-            {
-                if ( m_headerWin )
-                {
-                    // don't delete, just hide, as we can reuse it later
-                    m_headerWin->Show(false);
-                }
-                //else: nothing to do
-            }
-            else // must show header
-            {
-                if (!m_headerWin)
-                {
-                    CreateHeaderWindow();
-                }
-                else // already have it, just show
-                {
-                    m_headerWin->Show( true );
-                }
-            }
-
-            ResizeReportView(willHaveHeader);
-        }
+        GetSizer()->Layout();
     }
 
     wxWindow::SetWindowStyleFlag( flag );
@@ -5252,11 +5317,22 @@ wxRect wxGenericListCtrl::GetViewRect() const
     return m_mainWin->GetViewRect();
 }
 
-bool wxGenericListCtrl::GetItemRect( long item, wxRect &rect, int WXUNUSED(code) ) const
+bool wxGenericListCtrl::GetItemRect(long item, wxRect& rect, int code) const
+{
+    return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect, code);
+}
+
+bool wxGenericListCtrl::GetSubItemRect(long item,
+                                       long subItem,
+                                       wxRect& rect,
+                                       int WXUNUSED(code)) const
 {
-    m_mainWin->GetItemRect( item, rect );
+    if ( !m_mainWin->GetSubItemRect( item, subItem, rect ) )
+        return false;
+
     if ( m_mainWin->HasHeader() )
         rect.y += m_headerHeight + 1;
+
     return true;
 }
 
@@ -5268,7 +5344,7 @@ bool wxGenericListCtrl::GetItemPosition( long item, wxPoint& pos ) const
 
 bool wxGenericListCtrl::SetItemPosition( long WXUNUSED(item), const wxPoint& WXUNUSED(pos) )
 {
-    return 0;
+    return false;
 }
 
 int wxGenericListCtrl::GetItemCount() const
@@ -5332,16 +5408,6 @@ wxColour wxGenericListCtrl::GetItemBackgroundColour( long item ) const
     return info.GetBackgroundColour();
 }
 
-int wxGenericListCtrl::GetScrollPos( int orient ) const
-{
-    return m_mainWin->GetScrollPos( orient );
-}
-
-void wxGenericListCtrl::SetScrollPos( int orient, int pos, bool refresh )
-{
-    m_mainWin->SetScrollPos( orient, pos, refresh );
-}
-
 void wxGenericListCtrl::SetItemFont( long item, const wxFont &f )
 {
     wxListItem info;
@@ -5394,7 +5460,7 @@ wxImageList *wxGenericListCtrl::GetImageList(int which) const
     else if (which == wxIMAGE_LIST_STATE)
         return m_imageListState;
 
-    return (wxImageList *) NULL;
+    return NULL;
 }
 
 void wxGenericListCtrl::SetImageList( wxImageList *imageList, int which )
@@ -5470,8 +5536,8 @@ bool wxGenericListCtrl::DeleteColumn( int col )
     m_mainWin->DeleteColumn( col );
 
     // if we don't have the header any longer, we need to relayout the window
-    if ( !GetColumnCount() )
-        ResizeReportView(false /* no header */);
+    // if ( !GetColumnCount() )
+
     return true;
 }
 
@@ -5556,8 +5622,7 @@ long wxGenericListCtrl::InsertColumn( long col, wxListItem &item )
 
     // if we hadn't had a header before but have one now
     // then we need to relayout the window
-    if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
-        ResizeReportView(true /* have header */);
+    // if ( GetColumnCount() == 1 && m_mainWin->HasHeader() )
 
     m_headerWin->Refresh();
 
@@ -5608,43 +5673,28 @@ bool wxGenericListCtrl::SortItems( wxListCtrlCompare fn, long data )
 
 void wxGenericListCtrl::OnSize(wxSizeEvent& WXUNUSED(event))
 {
-    if ( !m_mainWin )
-        return;
+    if (!m_mainWin) return;
 
-    ResizeReportView(m_mainWin->HasHeader());
-    m_mainWin->RecalculatePositions();
-}
+    // We need to override OnSize so that our scrolled
+    // window a) does call Layout() to use sizers for
+    // positioning the controls but b) does not query
+    // the sizer for their size and use that for setting
+    // the scrollable area as set that ourselves by
+    // calling SetScrollbar() further down.
 
-void wxGenericListCtrl::ResizeReportView(bool showHeader)
-{
-    int cw, ch;
-    GetClientSize( &cw, &ch );
+    Layout();
 
-    if ( showHeader )
-    {
-        m_headerWin->SetSize( 0, 0, cw, m_headerHeight );
-        if(ch > m_headerHeight)
-            m_mainWin->SetSize( 0, m_headerHeight + 1,
-                                   cw, ch - m_headerHeight - 1 );
-        else
-            m_mainWin->SetSize( 0, m_headerHeight + 1,
-                                   cw, 0);
-    }
-    else // no header window
-    {
-        m_mainWin->SetSize( 0, 0, cw, ch );
-    }
+    m_mainWin->RecalculatePositions();
+
+    AdjustScrollbars();
 }
 
 void wxGenericListCtrl::OnInternalIdle()
 {
     wxWindow::OnInternalIdle();
 
-    // do it only if needed
-    if ( !m_mainWin->m_dirty )
-        return;
-
-    m_mainWin->RecalculatePositions();
+    if (m_mainWin->m_dirty)
+        m_mainWin->RecalculatePositions();
 }
 
 // ----------------------------------------------------------------------------
@@ -5693,7 +5743,7 @@ bool wxGenericListCtrl::SetFont( const wxFont &font )
     if (m_headerWin)
     {
         m_headerWin->SetFont( font );
-        CalculateAndSetHeaderHeight();
+        // CalculateAndSetHeaderHeight();
     }
 
     Refresh();
@@ -5711,7 +5761,7 @@ wxGenericListCtrl::GetClassDefaultAttributes(wxWindowVariant variant)
 #else
     wxUnusedVar(variant);
     wxVisualAttributes attr;
-    attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
+    attr.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOXTEXT);
     attr.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_LISTBOX);
     attr.font  = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
     return attr;