X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/464b15e17d983e96152a126708cc60b36eb9914a..6cef0db28018fd2644ee4e38af715872e5242459:/src/mac/carbon/listbox.cpp?ds=inline diff --git a/src/mac/carbon/listbox.cpp b/src/mac/carbon/listbox.cpp index a837c5f17d..7a21c3bc8f 100644 --- a/src/mac/carbon/listbox.cpp +++ b/src/mac/carbon/listbox.cpp @@ -24,7 +24,7 @@ #include "wx/dcclient.h" #endif -IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControl) +IMPLEMENT_DYNAMIC_CLASS(wxListBox, wxControlWithItems) BEGIN_EVENT_TABLE(wxListBox, wxControl) END_EVENT_TABLE() @@ -58,7 +58,8 @@ bool wxListBox::Create( wxMacListControl* wxListBox::GetPeer() const { - return dynamic_cast(m_peer); + wxMacDataBrowserListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserListControl); + return lb ? wx_static_cast(wxMacListControl*,lb) : 0 ; } bool wxListBox::Create( @@ -81,12 +82,12 @@ bool wxListBox::Create( return false; wxMacDataBrowserListControl* control = new wxMacDataBrowserListControl( this, pos, size, style ); - control->SetClientDataType( m_clientDataItemsType ); + // TODO CHECK control->SetClientDataType( m_clientDataItemsType ); m_peer = control; MacPostControlCreate( pos, size ); - InsertItems( n, choices, 0 ); + Append(n, choices); // Needed because it is a wxControlWithItems SetInitialSize( size ); @@ -115,36 +116,29 @@ void wxListBox::EnsureVisible(int n) 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 @@ -158,7 +152,7 @@ int wxListBox::FindString(const wxString& s, bool bCase) const return wxNOT_FOUND; } -void wxListBox::Clear() +void wxListBox::DoClear() { FreeData(); } @@ -187,22 +181,12 @@ void *wxListBox::DoGetItemClientData(unsigned int n) const 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 { @@ -222,15 +206,6 @@ wxString wxListBox::GetString(unsigned int n) 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 ); @@ -243,53 +218,18 @@ wxSize wxListBox::DoGetBestSize() const int wLine; { -#if wxMAC_USE_CORE_GRAPHICS wxClientDC dc(const_cast(this)); -#else - wxMacPortStateHelper st( UMAGetWindowPort( (WindowRef)MacGetTopLevelWindowRef() ) ); + dc.SetFont(GetFont()); - // TODO: clean this up - if ( m_font.Ok() ) - { - ::TextFont( m_font.MacGetFontNum() ); - ::TextSize( m_font.MacGetFontSize() ); - ::TextFace( m_font.MacGetFontStyle() ); - } - else - { - ::TextFont( kFontIDMonaco ); - ::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; - - // NB: what if m_font.Ok() == false ??? - ::GetThemeTextDimensions( - wxMacCFStringHolder( str, m_font.GetEncoding() ), - kThemeCurrentPortFont, - kThemeStateActive, - false, - &bounds, - &baseline ); - wLine = bounds.h; -#else - wLine = ::TextWidth( str.c_str(), 0, str.length() ); -#endif - lbWidth = wxMax( lbWidth, wLine ); -#endif } // Add room for the scrollbar @@ -297,13 +237,10 @@ wxSize wxListBox::DoGetBestSize() const // And just a bit more int cy = 12; -#if wxMAC_USE_CORE_GRAPHICS + wxCoord width, height ; - dc.GetTextExtent( wxT("X") , &width, &height); + dc.GetTextExtent( wxT("XX") , &width, &height); int cx = width ; -#else - int cx = ::TextWidth( "X", 0, 1 ); -#endif lbWidth += cx; // don't make the listbox too tall (limit height to around 10 items) @@ -332,7 +269,7 @@ wxListBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) attr.colFg = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ); attr.colBg = wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ); - attr.font = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ); + attr.font.MacCreateFromThemeFont(kThemeViewsFont); return attr; } @@ -351,12 +288,6 @@ int wxListBox::DoListHitTest(const wxPoint& inpoint) const wxPoint point = inpoint; - // interestingly enough 10.2 (and below?) have GetDataBrowserItemPartBounds - // giving root window coordinates but 10.3 and above give client coordinates - // so we only compare using root window coordinates on 10.3 and up - if ( UMAGetSystemVersion() < 0x1030 ) - MacClientToRootWindow(&point.x, &point.y); - // get column property ID (req. for call to itempartbounds) DataBrowserTableViewColumnID colId = 0; err = GetDataBrowserTableViewColumnProperty(m_peer->GetControlRef(), 0, &colId); @@ -461,9 +392,9 @@ wxMacListBoxItem::~wxMacListBoxItem() void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner , DataBrowserItemNotification message, - DataBrowserItemDataRef itemData ) const + DataBrowserItemDataRef WXUNUSED(itemData) ) const { - wxMacDataBrowserListControl *lb = dynamic_cast(owner); + wxMacDataBrowserListControl *lb = wxDynamicCast(owner,wxMacDataBrowserListControl); // we want to depend on as little as possible to make sure tear-down of controls is safe @@ -516,12 +447,14 @@ void wxMacListBoxItem::Notification(wxMacDataItemBrowserControl *owner , // direct notification is not always having the listbox GetSelection() // having in synch with event, so use wxPostEvent instead - // list->GetEventHandler()->ProcessEvent(event); + // list->HandleWindowEvent(event); wxPostEvent( list->GetEventHandler(), event ); } } +IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserListControl , wxMacDataItemBrowserControl ) + wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style) : wxMacDataItemBrowserControl( peer, pos, size, style ) { @@ -565,9 +498,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const columnDesc.propertyDesc.propertyID = kTextColumnId; columnDesc.propertyDesc.propertyType = kDataBrowserTextType; columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; -#endif verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); @@ -576,9 +507,7 @@ wxMacDataBrowserListControl::wxMacDataBrowserListControl( wxWindow *peer, const columnDesc.propertyDesc.propertyID = kNumericOrderColumnId; columnDesc.propertyDesc.propertyType = kDataBrowserPropertyRelevanceRankPart; columnDesc.propertyDesc.propertyFlags = kDataBrowserTableViewSelectionColumn; -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn; -#endif verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) ); @@ -646,8 +575,7 @@ static pascal void ListBoxDrawProc( // TODO: switch over to wxSystemSettingsNative::GetColour() when kThemeBrushSecondaryHighlightColor // is incorporated Panther DB starts using kThemeBrushSecondaryHighlightColor // for inactive browser highlighting - Gestalt( gestaltSystemVersion, &systemVersion ); - if ( (systemVersion >= 0x00001030) && !IsControlActive( browser ) ) + if ( !IsControlActive( browser ) ) colorBrushID = kThemeBrushSecondaryHighlightColor; else colorBrushID = kThemeBrushPrimaryHighlightColor;