X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7ac5e1c9088dedba495f5af5dbfb23ca89487a78..48e05747043db02c4e9d2e286eca4fdf5dee7881:/src/osx/listbox_osx.cpp diff --git a/src/osx/listbox_osx.cpp b/src/osx/listbox_osx.cpp index e138470cae..63a7bc9e4b 100644 --- a/src/osx/listbox_osx.cpp +++ b/src/osx/listbox_osx.cpp @@ -1,10 +1,10 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: src/osx/carbon/listbox.cpp +// Name: src/osx/listbox_osx.cpp // Purpose: wxListBox // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 -// RCS-ID: $Id: listbox.cpp 54820 2008-07-29 20:04:11Z SC $ +// RCS-ID: $Id$ // Copyright: (c) Stefan Csomor // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -24,8 +24,6 @@ #include "wx/dcclient.h" #endif -IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems) - BEGIN_EVENT_TABLE(wxListBox, wxControl) END_EVENT_TABLE() @@ -73,8 +71,11 @@ bool wxListBox::Create( const wxValidator& validator, const wxString& name ) { + DontCreatePeer(); m_blockEvents = false; - m_macIsUserPane = false; + + if ( ! (style & wxNO_BORDER) ) + style = (style & ~wxBORDER_MASK) | wxSUNKEN_BORDER ; wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), wxT("only a single listbox selection mode can be specified") ); @@ -87,8 +88,8 @@ bool wxListBox::Create( else m_strings.unsorted = new wxArrayString; - m_peer = wxWidgetImpl::CreateListBox( this, parent, id, pos, size, style, GetExtraStyle() ); - + SetPeer(wxWidgetImpl::CreateListBox( this, parent, id, pos, size, style, GetExtraStyle() )); + MacPostControlCreate( pos, size ); m_textColumn = GetListPeer()->InsertTextColumn(0,wxEmptyString); @@ -103,10 +104,12 @@ bool wxListBox::Create( wxListBox::~wxListBox() { + m_blockEvents = true; FreeData(); + m_blockEvents = false; + // make sure no native events get sent to a object in destruction - delete m_peer; - m_peer = NULL; + SetPeer(NULL); if ( IsSorted() ) delete m_strings.sorted; @@ -130,6 +133,11 @@ void wxListBox::FreeData() void wxListBox::DoSetFirstItem(int n) { + // osx actually only has an implementation for ensuring the visibility of a row, it does so + // by scrolling the minimal amount necessary from the current scrolling position. + // in order to get the same behaviour I'd have to make sure first that the last line is visible, + // followed by a scrollRowToVisible for the desired line + GetListPeer()->ListScrollTo( GetCount()-1 ); GetListPeer()->ListScrollTo( n ); } @@ -152,7 +160,7 @@ void wxListBox::DoDeleteOneItem(unsigned int n) GetListPeer()->ListDelete( n ); m_blockEvents = false; - + UpdateOldSelections(); } @@ -161,7 +169,7 @@ void wxListBox::DoClear() m_blockEvents = true; FreeData(); m_blockEvents = false; - + UpdateOldSelections(); } @@ -175,14 +183,14 @@ void wxListBox::DoSetSelection(int n, bool select) wxT("invalid index in wxListBox::SetSelection") ); m_blockEvents = true; - + if ( n == wxNOT_FOUND ) GetListPeer()->ListDeselectAll(); else GetListPeer()->ListSetSelection( n, select, HasMultipleSelection() ); - + m_blockEvents = false; - + UpdateOldSelections(); } @@ -205,6 +213,11 @@ int wxListBox::GetSelection() const return GetListPeer()->ListGetSelection(); } +int wxListBox::DoListHitTest(const wxPoint& inpoint) const +{ + return GetListPeer()->DoListHitTest( inpoint ); +} + // ---------------------------------------------------------------------------- // display // ---------------------------------------------------------------------------- @@ -215,14 +228,14 @@ void wxListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxLi value.Set( GetString( n ) ); } -void wxListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) +void wxListBox::SetValueCallback( unsigned int WXUNUSED(n), wxListWidgetColumn* WXUNUSED(col) , wxListWidgetCellValue& WXUNUSED(value) ) { } wxSize wxListBox::DoGetBestSize() const { int lbWidth = 100; // some defaults - int lbHeight = 110; + int lbHeight; int wLine; { @@ -272,11 +285,8 @@ wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); -#if wxOSX_USE_ATSU_TEXT - attr.font.MacCreateFromThemeFont(kThemeViewsFont); -#else - attr.font.MacCreateFromUIFont(kCTFontViewsFontType); -#endif + static wxFont font = wxFont(wxOSX_SYSTEM_FONT_VIEWS); + attr.font = font; return attr; } @@ -325,7 +335,6 @@ int wxListBox::FindString(const wxString& s, bool bCase) const void wxListBox::OnItemInserted(unsigned int WXUNUSED(pos)) { - } int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, @@ -353,6 +362,14 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, GetListPeer()->UpdateLineToEnd(startpos); + // Inserting the items may scroll the listbox down to show the last + // selected one but we don't want to do it as it could result in e.g. the + // first items of a listbox be hidden immediately after its creation so + // show the first selected item instead. Ideal would probably be to + // preserve the old selection unchanged, in fact, but I don't know how to + // get the first visible item so for now do at least this. + SetFirstItem(startpos); + UpdateOldSelections(); return idx; @@ -360,7 +377,7 @@ int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items, void wxListBox::SetString(unsigned int n, const wxString& s) { - wxCHECK_RET( !IsSorted(), _T("can't set string in sorted listbox") ); + wxCHECK_RET( !IsSorted(), wxT("can't set string in sorted listbox") ); if ( IsSorted() ) (*m_strings.sorted)[n] = s; @@ -370,4 +387,39 @@ void wxListBox::SetString(unsigned int n, const wxString& s) GetListPeer()->UpdateLine(n); } +// +// common event handling +// + +void wxListBox::HandleLineEvent( unsigned int n, bool doubleClick ) +{ + wxCommandEvent event( doubleClick ? wxEVT_LISTBOX_DCLICK : + wxEVT_LISTBOX, GetId() ); + event.SetEventObject( this ); + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + event.SetString( GetString(n) ); + event.SetInt( n ); + event.SetExtraLong( 1 ); + HandleWindowEvent(event); +} + +// +// common list cell value operations +// + +void wxListWidgetCellValue::Check( bool check ) +{ + Set( check ? 1 : 0 ); +} + +bool wxListWidgetCellValue::IsChecked() const +{ + return GetIntValue() != 0; +} + + + #endif // wxUSE_LISTBOX