X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/39e39d3944af7a7dd5958a25391b0e914a05e93c..359878c33e86222a2156e25705ec97ab630a8763:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index b7143eaa85..3a2774b15e 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -76,6 +76,9 @@ #include "wx/mac/private.h" #endif +#include + + // NOTE: If using the wxListBox visual attributes works everywhere then this can // be removed, as well as the #else case below. #define _USE_VISATTR 0 @@ -677,6 +680,7 @@ public: void EnsureVisible( long index ); long FindItem( long start, const wxString& str, bool partial = false ); long FindItem( long start, long data); + long FindItem( const wxPoint& pt ); long HitTest( int x, int y, int &flags ); void InsertItem( wxListItem &item ); void InsertColumn( long col, wxListItem &item ); @@ -1668,11 +1672,13 @@ wxListHeaderWindow::wxListHeaderWindow( wxWindow *win, wxVisualAttributes attr = wxPanel::GetClassDefaultAttributes(); SetOwnForegroundColour( attr.colFg ); SetOwnBackgroundColour( attr.colBg ); - SetOwnFont( attr.font ); + if (!m_hasFont) + SetOwnFont( attr.font ); #else SetOwnForegroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); SetOwnBackgroundColour( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); - SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); + if (!m_hasFont) + SetOwnFont( wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT )); #endif } @@ -2068,12 +2074,14 @@ void wxListTextCtrl::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: - if ( !AcceptChanges() ) + if ( AcceptChanges() ) { - // vetoed by the user code - break; + // Close the text control, changes were accepted + Finish(); } - //else: fall through + // else do nothing, do not accept and do not close + + break; case WXK_ESCAPE: Finish(); @@ -2103,7 +2111,7 @@ void wxListTextCtrl::OnKeyUp( wxKeyEvent &event ) sx = parentSize.x - myPos.x; if (mySize.x > sx) sx = mySize.x; - SetSize(sx, wxDefaultSize.y); + SetSize(sx, wxDefaultCoord); event.Skip(); } @@ -2112,13 +2120,16 @@ void wxListTextCtrl::OnKillFocus( wxFocusEvent &event ) { if ( !m_finished ) { - // We must finish regardless of success, otherwise we'll get focus problems + // We must finish regardless of success, otherwise we'll get + // focus problems: Finish(); if ( !AcceptChanges() ) m_owner->OnRenameCancelled( m_itemEdited ); } + // We must let the native text control handle focus, too, otherwise + // it could have problems with the cursor (e.g., in wxGTK): event.Skip(); } @@ -2214,7 +2225,8 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxVisualAttributes attr = wxGenericListCtrl::GetClassDefaultAttributes(); SetOwnForegroundColour( attr.colFg ); SetOwnBackgroundColour( attr.colBg ); - SetOwnFont( attr.font ); + if (!m_hasFont) + SetOwnFont( attr.font ); } wxListMainWindow::~wxListMainWindow() @@ -4278,6 +4290,22 @@ long wxListMainWindow::FindItem(long start, long data) return wxNOT_FOUND; } +long wxListMainWindow::FindItem( const wxPoint& pt ) +{ + size_t topItem; + GetVisibleLinesRange(&topItem, NULL); + + wxPoint p; + GetItemPosition( GetItemCount()-1, p ); + if( p.y == 0 ) + return topItem; + long id = (long) floor( pt.y*double(GetItemCount()-topItem-1)/p.y+topItem ); + if( id >= 0 && id < (long)GetItemCount() ) + return id; + + return wxNOT_FOUND; +} + long wxListMainWindow::HitTest( int x, int y, int &flags ) { CalcUnscrolledPosition( x, y, &x, &y ); @@ -4317,10 +4345,12 @@ void wxListMainWindow::InsertItem( wxListItem &item ) { wxASSERT_MSG( !IsVirtual(), _T("can't be used with virtual control") ); - size_t count = GetItemCount(); - wxCHECK_RET( item.m_itemId >= 0 && (size_t)item.m_itemId <= count, - _T("invalid item index") ); + int count = GetItemCount(); + wxCHECK_RET( item.m_itemId >= 0, _T("invalid item index") ); + if (item.m_itemId > count) + item.m_itemId = count; + size_t id = item.m_itemId; m_dirty = true; @@ -4629,9 +4659,13 @@ bool wxGenericListCtrl::Create(wxWindow *parent, m_mainWin = new wxListMainWindow( this, wxID_ANY, wxPoint(0,0), size, style ); #if defined( __WXMAC__ ) && __WXMAC_CARBON__ - wxFont font ; - font.MacCreateThemeFont( kThemeViewsFont ) ; - SetFont( font ) ; + // Human Interface Guidelines ask us for a special font in this case + if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL ) + { + wxFont font ; + font.MacCreateThemeFont( kThemeViewsFont ) ; + SetFont( font ) ; + } #endif if ( InReportView() ) { @@ -5051,10 +5085,10 @@ long wxGenericListCtrl::FindItem( long start, long data ) return m_mainWin->FindItem( start, data ); } -long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& WXUNUSED(pt), +long wxGenericListCtrl::FindItem( long WXUNUSED(start), const wxPoint& pt, int WXUNUSED(direction)) { - return 0; + return m_mainWin->FindItem( pt ); } long wxGenericListCtrl::HitTest( const wxPoint &point, int &flags ) @@ -5321,6 +5355,14 @@ void wxGenericListCtrl::SetFocus() m_mainWin->SetFocus(); } +wxSize wxGenericListCtrl::DoGetBestSize() const +{ + // Something is better than nothing... + // 100x80 is what the MSW version will get from the default + // wxControl::DoGetBestSize + return wxSize(100,80); +} + // ---------------------------------------------------------------------------- // virtual list control support // ----------------------------------------------------------------------------