#include "wx/listbox.h"
#ifndef WX_PRECOMP
- #include "wx/dynarray.h"
#include "wx/log.h"
#include "wx/intl.h"
- #include "wx/app.h"
#include "wx/utils.h"
- #include "wx/button.h"
#include "wx/settings.h"
#include "wx/arrstr.h"
- #include "wx/toplevel.h"
+ #include "wx/dcclient.h"
#endif
-IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems)
BEGIN_EVENT_TABLE(wxListBox, wxControl)
END_EVENT_TABLE()
#include "wx/mac/uma.h"
-#include "wx/dynarray.h"
// ============================================================================
// list box control implementation
wxMacListControl* wxListBox::GetPeer() const
{
- return dynamic_cast<wxMacListControl*>(m_peer);
+ wxMacDataBrowserListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListControl);
+ return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ;
}
bool wxListBox::Create(
return false;
wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( this, pos, size, style );
- control->SetClientDataType( m_clientDataItemsType );
m_peer = control;
MacPostControlCreate( pos, size );
- InsertItems( n, choices, 0 );
+ Append(n, choices);
// Needed because it is a wxControlWithItems
- SetBestSize( size );
+ SetInitialSize( size );
return true;
}
GetPeer()->MacScrollTo( n );
}
-void wxListBox::Delete(unsigned int n)
+void wxListBox::DoDeleteOneItem(unsigned int n)
{
wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::Delete") );
GetPeer()->MacDelete( n );
}
-int wxListBox::DoAppend(const wxString& item)
+int wxListBox::DoInsertItems(const wxArrayStringsAdapter& items,
+ unsigned int pos,
+ void **clientData,
+ wxClientDataType type)
{
InvalidateBestSize();
- return GetPeer()->MacAppend( item );
-}
-
-void wxListBox::DoSetItems(const wxArrayString& choices, void** clientData)
-{
- Clear();
-
- unsigned int n = choices.GetCount();
-
- for ( size_t i = 0; i < n; ++i )
+ GetPeer()->MacInsert( pos, items );
+ const unsigned int count = items.GetCount();
+ if ( clientData )
{
- if ( clientData )
- {
- Append( choices[i], clientData[i] );
- }
- else
- Append( choices[i] );
+ for (unsigned int i = 0; i < count; ++i)
+ AssignNewItemClientData( pos + i, clientData, i, type );
}
+ return pos + count - 1;
}
int wxListBox::FindString(const wxString& s, bool bCase) const
return wxNOT_FOUND;
}
-void wxListBox::Clear()
+void wxListBox::DoClear()
{
FreeData();
}
return GetPeer()->MacGetClientData( n );
}
-wxClientData *wxListBox::DoGetItemClientObject(unsigned int n) const
-{
- return (wxClientData*)DoGetItemClientData( n );
-}
-
void wxListBox::DoSetItemClientData(unsigned int n, void *clientData)
{
wxCHECK_RET( IsValid(n), wxT("invalid index in wxListBox::SetClientData") );
GetPeer()->MacSetClientData( n , clientData);
}
-void wxListBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData)
-{
- DoSetItemClientData(n, clientData);
-}
-
// Return number of selections and an array of selected integers
int wxListBox::GetSelections(wxArrayInt& aSelections) const
{
return GetPeer()->MacGetString(n);
}
-void wxListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
-{
- wxCHECK_RET( IsValidInsert(pos), wxT("invalid index in wxListBox::InsertItems") );
-
- InvalidateBestSize();
-
- GetPeer()->MacInsert( pos, items );
-}
-
void wxListBox::SetString(unsigned int n, const wxString& s)
{
GetPeer()->MacSetString( n, s );
int wLine;
{
+#if wxMAC_USE_CORE_GRAPHICS
+ wxClientDC dc(const_cast<wxListBox*>(this));
+ dc.SetFont(GetFont());
+#else
wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef)MacGetTopLevelWindowRef() ) );
// TODO: clean this up
::TextSize( 9 );
::TextFace( 0 );
}
-
+#endif
// Find the widest line
for (unsigned int i = 0; i < GetCount(); i++)
{
wxString str( GetString( i ) );
-
+#if wxMAC_USE_CORE_GRAPHICS
+ wxCoord width, height ;
+ dc.GetTextExtent( str , &width, &height);
+ wLine = width ;
+#else
#if wxUSE_UNICODE
Point bounds = {0, 0};
SInt16 baseline;
#else
wLine = ::TextWidth( str.c_str(), 0, str.length() );
#endif
-
+#endif
lbWidth = wxMax( lbWidth, wLine );
}
// And just a bit more
int cy = 12;
- int cx = ::TextWidth( "X", 0, 1 );
+#if wxMAC_USE_CORE_GRAPHICS
+ wxCoord width, height ;
+ dc.GetTextExtent( wxT("XX") , &width, &height);
+ int cx = width ;
+#else
+ int cx = ::TextWidth( "XX", 0, 1 );
+#endif
lbWidth += cx;
// don't make the listbox too tall (limit height to around 10 items)
DataBrowserItemNotification message,
DataBrowserItemDataRef itemData ) const
{
- wxMacDataBrowserListControl *lb = dynamic_cast<wxMacDataBrowserListControl*>(owner);
+ wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl);
// we want to depend on as little as possible to make sure tear-down of controls is safe
}
}
+IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl )
+
wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style)
: wxMacDataItemBrowserControl( peer, pos, size, style )
{
}
else if ( style & wxLB_EXTENDED )
{
- // default behaviour
+ options |= kDataBrowserCmdTogglesSelection;
}
else
{