X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a8a89154531d94c2ff30990a0463a366242703b2..e36dcd10d0528529a055c63111b3aa64538d4313:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 46cf4f3638..c42fded26c 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__) && 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) @@ -50,7 +50,9 @@ #include "wx/renderer.h" #ifdef __WXMAC__ - #include "wx/mac/private.h" + #include "wx/osx/private.h" + // for themeing support + #include #endif @@ -243,7 +245,7 @@ private: // wxListLineData (internal) //----------------------------------------------------------------------------- -WX_DECLARE_EXPORTED_LIST(wxListItemData, wxListItemDataList); +WX_DECLARE_LIST(wxListItemData, wxListItemDataList); #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxListItemDataList) @@ -375,7 +377,7 @@ private: int width); }; -WX_DECLARE_EXPORTED_OBJARRAY(wxListLineData, wxListLineDataArray); +WX_DECLARE_OBJARRAY(wxListLineData, wxListLineDataArray); #include "wx/arrimpl.cpp" WX_DEFINE_OBJARRAY(wxListLineDataArray) @@ -432,7 +434,6 @@ private: // it wasn't vetoed, i.e. if we should proceed bool SendListEvent(wxEventType type, const wxPoint& pos); - DECLARE_DYNAMIC_CLASS(wxListHeaderWindow) DECLARE_EVENT_TABLE() }; @@ -488,11 +489,11 @@ private: // wxListMainWindow (internal) //----------------------------------------------------------------------------- -WX_DECLARE_EXPORTED_LIST(wxListHeaderData, wxListHeaderDataList); +WX_DECLARE_LIST(wxListHeaderData, wxListHeaderDataList); #include "wx/listimpl.cpp" WX_DEFINE_LIST(wxListHeaderDataList) -class wxListMainWindow : public wxScrolledWindow +class wxListMainWindow : public wxScrolledCanvas { public: wxListMainWindow(); @@ -598,10 +599,6 @@ public: m_textctrlWrapper = NULL; } - // we don't draw anything while we're frozen so we must refresh ourselves - // when we're thawed to make sure the changes are displayed correctly - virtual void DoThaw() { Refresh(); } - void OnRenameTimer(); bool OnRenameAccept(size_t itemEdit, const wxString& value); void OnRenameCancelled(size_t itemEdit); @@ -620,6 +617,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; @@ -644,7 +643,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; @@ -705,7 +708,7 @@ public: // override base class virtual to reset m_lineHeight when the font changes virtual bool SetFont(const wxFont& font) { - if ( !wxScrolledWindow::SetFont(font) ) + if ( !wxScrolledCanvas::SetFont(font) ) return false; m_lineHeight = 0; @@ -853,7 +856,6 @@ private: wxListTextCtrlWrapper *m_textctrlWrapper; - DECLARE_DYNAMIC_CLASS(wxListMainWindow) DECLARE_EVENT_TABLE() friend class wxGenericListCtrl; @@ -1412,7 +1414,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 ) @@ -1446,7 +1448,7 @@ bool wxListLineData::SetAttributes(wxDC *dc, if ( highlighted ) dc->SetBrush( *m_owner->GetHighlightBrush() ); else - dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxSOLID)); + dc->SetBrush(wxBrush(attr->GetBackgroundColour(), wxBRUSHSTYLE_SOLID)); dc->SetPen( *wxTRANSPARENT_PEN ); @@ -1476,7 +1478,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 ) @@ -1569,6 +1571,9 @@ void wxListLineData::DrawInReportMode( wxDC *dc, int xOld = x; x += width; + const int wText = width - 8; + wxDCClipper clipper(*dc, xOld, rect.y, wText, rect.height); + if ( item->HasImage() ) { int ix, iy; @@ -1582,7 +1587,7 @@ void wxListLineData::DrawInReportMode( wxDC *dc, } if ( item->HasText() ) - DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width - 8); + DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, wText); } } @@ -1687,8 +1692,6 @@ void wxListLineData::ReverseHighlight( void ) // wxListHeaderWindow //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxListHeaderWindow,wxWindow) - BEGIN_EVENT_TABLE(wxListHeaderWindow,wxWindow) EVT_PAINT (wxListHeaderWindow::OnPaint) EVT_MOUSE_EVENTS (wxListHeaderWindow::OnMouse) @@ -1791,7 +1794,7 @@ void wxListHeaderWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) GetClientSize( &w, &h ); m_owner->CalcUnscrolledPosition(w, 0, &w, NULL); - dc.SetBackgroundMode(wxTRANSPARENT); + dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); dc.SetTextForeground(GetForegroundColour()); int x = HEADER_OFFSET_X; @@ -1896,6 +1899,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() @@ -2136,11 +2152,11 @@ wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner, void wxListTextCtrlWrapper::EndEdit(bool discardChanges) { m_aboutToFinish = true; - + if ( discardChanges ) { m_owner->OnRenameCancelled(m_itemEdited); - + Finish( true ); } else @@ -2159,7 +2175,7 @@ void wxListTextCtrlWrapper::Finish( bool setfocus ) m_owner->ResetTextControl( m_text ); wxPendingDelete.Append( this ); - + if (setfocus) m_owner->SetFocus(); } @@ -2216,7 +2232,7 @@ void wxListTextCtrlWrapper::OnKeyUp( wxKeyEvent &event ) sx = mySize.x; m_text->SetSize(sx, wxDefaultCoord); } - + event.Skip(); } @@ -2238,9 +2254,7 @@ void wxListTextCtrlWrapper::OnKillFocus( wxFocusEvent &event ) // wxListMainWindow //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxListMainWindow,wxScrolledWindow) - -BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) +BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledCanvas) EVT_PAINT (wxListMainWindow::OnPaint) EVT_MOUSE_EVENTS (wxListMainWindow::OnMouse) EVT_CHAR (wxListMainWindow::OnChar) @@ -2249,6 +2263,7 @@ BEGIN_EVENT_TABLE(wxListMainWindow,wxScrolledWindow) 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() @@ -2296,7 +2311,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, const wxSize& size, long style, const wxString &name ) - : wxScrolledWindow( parent, id, pos, size, + : wxScrolledCanvas( parent, id, pos, size, style | wxHSCROLL | wxVSCROLL, name ) { Init(); @@ -2307,7 +2322,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, ( wxSYS_COLOUR_HIGHLIGHT ), - wxSOLID + wxBRUSHSTYLE_SOLID ); m_highlightUnfocusedBrush = new wxBrush @@ -2316,7 +2331,7 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, ( wxSYS_COLOUR_BTNSHADOW ), - wxSOLID + wxBRUSHSTYLE_SOLID ); SetScrollbars( 0, 0, 0, 0, 0, 0 ); @@ -2704,7 +2719,7 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // done (a Windows requirement). wxPaintDC dc( this ); - if ( IsEmpty() || IsFrozen() ) + if ( IsEmpty() ) { // nothing to draw or not the moment to draw it return; @@ -2765,7 +2780,7 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) if ( HasFlag(wxLC_HRULES) ) { - wxPen pen(GetRuleColour(), 1, wxSOLID); + wxPen pen(GetRuleColour(), 1, wxPENSTYLE_SOLID); wxSize clientSize = GetClientSize(); size_t i = visibleFrom; @@ -2791,7 +2806,7 @@ void wxListMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) // Draw vertical rules if required if ( HasFlag(wxLC_VRULES) && !IsEmpty() ) { - wxPen pen(GetRuleColour(), 1, wxSOLID); + wxPen pen(GetRuleColour(), 1, wxPENSTYLE_SOLID); wxRect firstItemRect, lastItemRect; GetItemRect(visibleFrom, firstItemRect); @@ -2860,6 +2875,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 ) @@ -2995,7 +3017,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) #endif // __WXMAC__ if ( event.LeftDown() ) - SetFocusIgnoringChildren(); + SetFocus(); event.SetEventObject( GetParent() ); if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) @@ -3396,16 +3418,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(); } @@ -3415,16 +3431,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(); } @@ -3445,27 +3454,13 @@ 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 (event.GetKeyCode() == WXK_TAB) - { - wxNavigationKeyEvent nevent; - nevent.SetWindowChange( event.ControlDown() ); - nevent.SetDirection( !event.ShiftDown() ); - nevent.SetEventObject( GetParent()->GetParent() ); - nevent.SetCurrentFocus( m_parent ); - if (GetParent()->GetParent()->GetEventHandler()->ProcessEvent( nevent )) - return; - } + if ( HandleAsNavigationKey(event) ) + return; // no item -> nothing to do if (!HasCurrent()) @@ -4125,8 +4120,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; @@ -4135,8 +4129,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(); @@ -4162,10 +4157,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 ) @@ -4174,9 +4173,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 @@ -4204,9 +4218,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; @@ -4869,7 +4883,7 @@ void wxListMainWindow::OnScroll(wxScrollWinEvent& event) { // FIXME #if ( defined(__WXGTK__) || defined(__WXMAC__) ) && !defined(__WXUNIVERSAL__) - wxScrolledWindow::OnScroll(event); + wxScrolledCanvas::OnScroll(event); #else HandleOnScroll( event ); #endif @@ -4976,7 +4990,7 @@ void wxGenericListCtrl::CalculateAndSetHeaderHeight() { if ( m_headerWin ) { -#ifdef __WXMAC__ +#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON SInt32 h; GetThemeMetric( kThemeMetricListHeaderHeight, &h ); #else @@ -5031,10 +5045,9 @@ bool wxGenericListCtrl::Create(wxWindow *parent, m_headerHeight = 0; - 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 ) ) return false; @@ -5047,12 +5060,16 @@ 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 ) { wxFont font; +#if wxOSX_USE_CARBON font.MacCreateFromThemeFont( kThemeViewsFont ); +#else + font.MacCreateFromUIFont( kCTFontViewsFontType ); +#endif SetFont( font ); } #endif @@ -5061,11 +5078,15 @@ bool wxGenericListCtrl::Create(wxWindow *parent, { CreateHeaderWindow(); -#ifdef __WXMAC__ +#if defined( __WXMAC__ ) && wxOSX_USE_COCOA_OR_CARBON if (m_headerWin) { wxFont font; +#if wxOSX_USE_CARBON font.MacCreateFromThemeFont( kThemeSmallSystemFont ); +#else + font.MacCreateFromUIFont( kCTFontSystemFontType ); +#endif m_headerWin->SetFont( font ); CalculateAndSetHeaderHeight(); } @@ -5103,7 +5124,17 @@ 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 ) @@ -5267,11 +5298,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; } @@ -5283,7 +5325,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 @@ -5906,14 +5948,4 @@ void wxGenericListCtrl::Refresh(bool eraseBackground, const wxRect *rect) } } -void wxGenericListCtrl::DoFreeze() -{ - m_mainWin->Freeze(); -} - -void wxGenericListCtrl::DoThaw() -{ - m_mainWin->Thaw(); -} - #endif // wxUSE_LISTCTRL