X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c24dad6f7aa0797afa0a91861a0124a1099ea91..3e1924dd5f5744c3e2a8973de9b3e4f372b7fd85:/src/mac/carbon/combobxc.cpp diff --git a/src/mac/carbon/combobxc.cpp b/src/mac/carbon/combobxc.cpp index f5ba7c6f31..c494f9fada 100644 --- a/src/mac/carbon/combobxc.cpp +++ b/src/mac/carbon/combobxc.cpp @@ -12,8 +12,12 @@ #include "wx/wxprec.h" #include "wx/combobox.h" -#include "wx/button.h" -#include "wx/menu.h" + +#ifndef WX_PRECOMP + #include "wx/button.h" + #include "wx/menu.h" +#endif + #include "wx/mac/uma.h" #if TARGET_API_MAC_OSX #ifndef __HIVIEW__ @@ -61,7 +65,7 @@ static pascal OSStatus wxMacComboBoxEventHandler( EventHandlerCallRef handler , event.SetInt( cb->GetSelection() ); event.SetString( cb->GetStringSelection() ); event.SetEventObject( cb ); - cb->GetEventHandler()->ProcessEvent( event ); + cb->HandleWindowEvent( event ); } break; default : @@ -122,7 +126,7 @@ protected: event.SetInt( 0 ); event.SetString( value ); event.SetEventObject( m_cb ); - m_cb->GetEventHandler()->ProcessEvent( event ); + m_cb->HandleWindowEvent( event ); } else { @@ -137,20 +141,16 @@ protected: event.SetInt( m_cb->GetCount() - 1 ); event.SetString( value ); event.SetEventObject( m_cb ); - m_cb->GetEventHandler()->ProcessEvent( event ); + m_cb->HandleWindowEvent( event ); } // This will invoke the dialog default action, such // as the clicking the default button. - wxWindow *parent = GetParent(); - while( parent && !parent->IsTopLevel() && parent->GetDefaultItem() == NULL ) { - parent = parent->GetParent(); - } - if ( parent && parent->GetDefaultItem() ) + wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); + if ( tlw && tlw->GetDefaultItem() ) { - wxButton *def = wxDynamicCast(parent->GetDefaultItem(), - wxButton); + wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton); if ( def && def->IsEnabled() ) { wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); @@ -216,9 +216,6 @@ END_EVENT_TABLE() wxComboBox::~wxComboBox() { - // delete client objects - FreeData(); - // delete the controls now, don't leave them alive even though they would // still be eventually deleted by our parent - but it will be too late, the // user code expects them to be gone now @@ -386,10 +383,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, MacPostControlCreate(pos,size); - for ( int i = 0; i < n; i++ ) - { - DoAppend( choices[ i ] ); - } + Append( choices[ i ] ); HIViewSetVisible( m_peer->GetControlRef(), true ); SetSelection(0); @@ -399,9 +393,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, (EventHandlerRef *)&comboEventHandler); #else m_choice = new wxComboBoxChoice(this, style ); - - m_choice = new wxComboBoxChoice(this, style ); - m_choice->SetSizeHints( wxSize( POPUPWIDTH , POPUPHEIGHT ) ); + m_choice->SetMinSize( wxSize( POPUPWIDTH , POPUPHEIGHT ) ); wxSize csize = size; if ( style & wxCB_READONLY ) @@ -418,11 +410,8 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, DoSetSize(pos.x, pos.y, csize.x, csize.y); - for ( int i = 0; i < n; i++ ) - { - m_choice->DoAppend( choices[ i ] ); - } - SetBestSize(csize); // Needed because it is a wxControlWithItems + m_choice->Append( n, choices ); + SetInitialSize(csize); // Needed because it is a wxControlWithItems #endif return true; @@ -433,7 +422,7 @@ wxString wxComboBox::GetValue() const #if USE_HICOMBOBOX CFStringRef myString; HIComboBoxCopyTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)GetSelection(), &myString ); - return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString(); + return wxMacCFStringHolder( myString, GetFont().GetEncoding() ).AsString(); #else wxString result; @@ -547,28 +536,26 @@ void wxComboBox::SetSelection(long from, long to) // TODO } -int wxComboBox::DoAppend(const wxString& item) -{ -#if USE_HICOMBOBOX - CFIndex outIndex; - HIComboBoxAppendTextItem( m_peer->GetControlRef(), wxMacCFStringHolder( item, m_font.GetEncoding() ), &outIndex ); - //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() ); - return (int) outIndex; -#else - return m_choice->DoAppend( item ); -#endif -} - -int wxComboBox::DoInsert(const wxString& item, unsigned int pos) +int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items, + unsigned int pos, + void **clientData, wxClientDataType type) { #if USE_HICOMBOBOX - HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) ); + const unsigned int count = items.GetCount(); + for ( unsigned int i = 0; i < count; ++i, ++pos ) + { + HIComboBoxInsertTextItemAtIndex(m_peer->GetControlRef(), + (CFIndex)pos, + wxMacCFStringHolder(items[i], + GetFont().GetEncoding())); + AssignNewItemClientData(pos, clientData, i, type); + } //SetControl32BitMaximum( m_peer->GetControlRef(), GetCount() ); - return pos; + return pos - 1; #else - return m_choice->DoInsert( item , pos ); + return m_choice->DoInsertItems( items, pos, clientData, type ); #endif } @@ -590,36 +577,6 @@ void* wxComboBox::DoGetItemClientData(unsigned int n) const #endif } -void wxComboBox::DoSetItemClientObject(unsigned int n, wxClientData* clientData) -{ -#if USE_HICOMBOBOX - return; //TODO -#else - return m_choice->DoSetItemClientObject( n , clientData ); -#endif -} - -wxClientData* wxComboBox::DoGetItemClientObject(unsigned int n) const -{ -#if USE_HICOMBOBOX - return NULL; -#else - return m_choice->DoGetItemClientObject( n ); -#endif -} - -void wxComboBox::FreeData() -{ - if (HasClientObjectData()) - { - unsigned int count = GetCount(); - for ( unsigned int n = 0; n < count; n++ ) - { - SetClientObject( n, NULL ); - } - } -} - unsigned int wxComboBox::GetCount() const { #if USE_HICOMBOBOX return (unsigned int) HIComboBoxGetItemCount( m_peer->GetControlRef() ); @@ -628,21 +585,17 @@ unsigned int wxComboBox::GetCount() const { #endif } -void wxComboBox::Delete(unsigned int n) +void wxComboBox::DoDeleteOneItem(unsigned int n) { #if USE_HICOMBOBOX HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex)n ); #else - // force client object deletion - if( HasClientObjectData() ) - SetClientObject( n, NULL ); m_choice->Delete( n ); #endif } -void wxComboBox::Clear() +void wxComboBox::DoClear() { - FreeData(); #if USE_HICOMBOBOX for ( CFIndex i = GetCount() - 1; i >= 0; ++ i ) verify_noerr( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), i ) ); @@ -717,7 +670,7 @@ void wxComboBox::SetString(unsigned int n, const wxString& s) { #if USE_HICOMBOBOX verify_noerr ( HIComboBoxInsertTextItemAtIndex( m_peer->GetControlRef(), (CFIndex) n, - wxMacCFStringHolder(s, m_font.GetEncoding()) ) ); + wxMacCFStringHolder(s, GetFont().GetEncoding()) ) ); verify_noerr ( HIComboBoxRemoveItemAtIndex( m_peer->GetControlRef(), (CFIndex) n + 1 ) ); #else m_choice->SetString( n , s );