X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/929b79014a38bc4d2b7fac4e25286c0f4a0b5ab7..05e0b047d879cdbfade7f2ab346c0acdf3e29f96:/src/generic/listctrl.cpp?ds=sidebyside diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 8c886803cc..ec924ef4c1 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -25,7 +25,7 @@ #include "wx/listctrl.h" -#if (!defined(__WXMSW__) || defined(__WXUNIVERSAL__)) && !defined(__WXMAC__) +#if ((!defined(__WXMSW__) && !defined(__WXMAC__)) || defined(__WXUNIVERSAL__)) // if we have a native version, its implementation file does all this IMPLEMENT_DYNAMIC_CLASS(wxListItem, wxObject) IMPLEMENT_DYNAMIC_CLASS(wxListView, wxListCtrl) @@ -615,6 +615,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 +641,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; @@ -1891,6 +1897,19 @@ 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), + 0 + ); + } } void wxListHeaderWindow::DrawCurrent() @@ -2242,6 +2261,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() @@ -2853,6 +2873,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 ) @@ -3389,16 +3416,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 +3429,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(); } @@ -3438,16 +3452,10 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) } // 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; + wxKeyEvent ke(event); ke.SetEventObject( parent ); - if (parent->GetEventHandler()->ProcessEvent( ke )) return; + if (parent->GetEventHandler()->ProcessEvent( ke )) + return; if ( HandleAsNavigationKey(event) ) return; @@ -4119,8 +4127,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(); @@ -4146,10 +4155,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 ) @@ -4158,9 +4171,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); + } CalcScrolledPosition(rect.x, rect.y, &rect.x, &rect.y); + + return true; } bool wxListMainWindow::GetItemPosition(long item, wxPoint& pos) const @@ -4960,7 +4988,7 @@ void wxGenericListCtrl::CalculateAndSetHeaderHeight() { if ( m_headerWin ) { -#ifdef __WXMAC__ +#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON SInt32 h; GetThemeMetric( kThemeMetricListHeaderHeight, &h ); #else @@ -5031,7 +5059,7 @@ bool wxGenericListCtrl::Create(wxWindow *parent, m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0, 0), size, style ); -#ifdef __WXMAC__ +#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON // Human Interface Guidelines ask us for a special font in this case if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ) { @@ -5045,7 +5073,7 @@ bool wxGenericListCtrl::Create(wxWindow *parent, { CreateHeaderWindow(); -#ifdef __WXMAC__ +#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON if (m_headerWin) { wxFont font; @@ -5261,11 +5289,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 { - m_mainWin->GetItemRect( item, rect ); + return GetSubItemRect(item, wxLIST_GETSUBITEMRECT_WHOLEITEM, rect, code); +} + +bool wxGenericListCtrl::GetSubItemRect(long item, + long subItem, + wxRect& rect, + int WXUNUSED(code)) const +{ + if ( !m_mainWin->GetSubItemRect( item, subItem, rect ) ) + return false; + if ( m_mainWin->HasHeader() ) rect.y += m_headerHeight + 1; + return true; } @@ -5277,7 +5316,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