X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f941a30bef665561d96d29c4cee07471dbbd497f..75a2c6a1ee034a5d866b4a121a97351603bce98b:/src/osx/combobox_osx.cpp diff --git a/src/osx/combobox_osx.cpp b/src/osx/combobox_osx.cpp index 3a0e884c7a..856a5b31e9 100644 --- a/src/osx/combobox_osx.cpp +++ b/src/osx/combobox_osx.cpp @@ -11,7 +11,7 @@ #include "wx/wxprec.h" -#if wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX) +#if wxUSE_COMBOBOX && wxOSX_USE_COCOA #include "wx/combobox.h" #include "wx/osx/private.h" @@ -62,7 +62,13 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) ) return false; - + + wxASSERT_MSG( !(style & wxCB_READONLY), + "wxCB_READONLY not supported, use wxChoice instead" ); + + wxASSERT_MSG( !(style & wxCB_SORT), + "wxCB_SORT not currently supported by wxOSX/Cocoa"); + m_peer = wxWidgetImpl::CreateComboBox( this, parent, id, NULL, pos, size, style, GetExtraStyle() ); MacPostControlCreate( pos, size ); @@ -89,197 +95,105 @@ void wxComboBox::DelegateChoice( const wxString& value ) SetStringSelection( value ); } -wxString wxComboBox::GetValue() const -{ - wxFAIL_MSG("Method Not Implemented."); - return wxEmptyString; -} - -void wxComboBox::SetValue(const wxString& value) -{ - wxFAIL_MSG("Method Not Implemented."); -} - -// Clipboard operations -void wxComboBox::Copy() -{ - wxFAIL_MSG("Method Not Implemented."); -} - -void wxComboBox::Cut() -{ - wxFAIL_MSG("Method Not Implemented."); -} - -void wxComboBox::Paste() -{ - wxFAIL_MSG("Method Not Implemented."); -} - -void wxComboBox::SetEditable(bool editable) -{ - wxFAIL_MSG("Method Not Implemented."); -} - -void wxComboBox::SetInsertionPoint(long pos) +int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items, + unsigned int pos, + void **clientData, wxClientDataType type) { - wxFAIL_MSG("Method Not Implemented."); -} + const unsigned int numItems = items.GetCount(); + for( unsigned int i = 0; i < numItems; ++i, ++pos ) + { + unsigned int idx; -void wxComboBox::SetInsertionPointEnd() -{ - wxFAIL_MSG("Method Not Implemented."); -} + idx = pos; + GetComboPeer()->InsertItem( idx, items[i] ); -long wxComboBox::GetInsertionPoint() const -{ - wxFAIL_MSG("Method Not Implemented."); - return 0; -} + if (idx > m_datas.GetCount()) + m_datas.SetCount(idx); + m_datas.Insert( NULL, idx ); + AssignNewItemClientData(idx, clientData, i, type); + } -wxTextPos wxComboBox::GetLastPosition() const -{ - wxFAIL_MSG("Method Not Implemented."); - return 0; -} + m_peer->SetMaximum( GetCount() ); -void wxComboBox::Replace(long from, long to, const wxString& value) -{ - wxFAIL_MSG("Method Not Implemented."); + return pos - 1; } -void wxComboBox::Remove(long from, long to) +// ---------------------------------------------------------------------------- +// client data +// ---------------------------------------------------------------------------- +void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) { - wxFAIL_MSG("Method Not Implemented."); -} + wxCHECK_RET( IsValid(n), "invalid index" ); -void wxComboBox::SetSelection(long from, long to) -{ - wxFAIL_MSG("Method Not Implemented."); + m_datas[n] = (char*)clientData ; } -int wxComboBox::DoInsertItems(const wxArrayStringsAdapter& items, - unsigned int pos, - void **clientData, wxClientDataType type) +void * wxComboBox::DoGetItemClientData(unsigned int n) const { - wxFAIL_MSG("Method Not Implemented."); - return 0; -} + wxCHECK_MSG( IsValid(n), NULL, "invalid index" ); -void wxComboBox::DoSetItemClientData(unsigned int n, void* clientData) -{ - wxFAIL_MSG("Method Not Implemented."); + return (void *)m_datas[n]; } -void* wxComboBox::DoGetItemClientData(unsigned int n) const +unsigned int wxComboBox::GetCount() const { - wxFAIL_MSG("Method Not Implemented."); - return NULL; + return GetComboPeer()->GetNumberOfItems(); } -unsigned int wxComboBox::GetCount() const +void wxComboBox::DoDeleteOneItem(unsigned int n) { - wxFAIL_MSG("Method Not Implemented."); - return 0; + GetComboPeer()->RemoveItem(n); } -void wxComboBox::DoDeleteOneItem(unsigned int n) +void wxComboBox::DoClear() { - wxFAIL_MSG("Method Not Implemented."); + GetComboPeer()->Clear(); + SetValue(wxEmptyString); } -void wxComboBox::DoClear() +void wxComboBox::GetSelection(long *from, long *to) const { - wxFAIL_MSG("Method Not Implemented."); + wxTextEntry::GetSelection(from, to); } int wxComboBox::GetSelection() const { - wxFAIL_MSG("Method Not Implemented."); - return 0; + return GetComboPeer()->GetSelectedItem(); } -void wxComboBox::GetSelection(long *from, long *to) const +void wxComboBox::SetSelection(int n) { - wxFAIL_MSG("Method Not Implemented."); + GetComboPeer()->SetSelectedItem(n); } -void wxComboBox::SetSelection(int n) +void wxComboBox::SetSelection(long from, long to) { - wxFAIL_MSG("Method Not Implemented."); + wxTextEntry::SetSelection(from, to); } int wxComboBox::FindString(const wxString& s, bool bCase) const { - wxFAIL_MSG("Method Not Implemented."); - return 0; + wxASSERT_MSG(bCase, "wxComboBox::FindString() doesn't currently support case " + "insensitive search in wxOSX/Cocoa"); + + return GetComboPeer()->FindString(s); } wxString wxComboBox::GetString(unsigned int n) const { - wxFAIL_MSG("Method Not Implemented."); - return wxEmptyString; + return GetComboPeer()->GetStringAtIndex(n); } wxString wxComboBox::GetStringSelection() const { - wxFAIL_MSG("Method Not Implemented."); - return wxEmptyString; + return GetString(GetSelection()); } void wxComboBox::SetString(unsigned int n, const wxString& s) { - wxFAIL_MSG("Method Not Implemented."); -} - -bool wxComboBox::IsEditable() const -{ - return !HasFlag(wxCB_READONLY); -} - -void wxComboBox::Undo() -{ - wxFAIL_MSG("Method Not Implemented."); -} - -void wxComboBox::Redo() -{ - wxFAIL_MSG("Method Not Implemented."); -} - -void wxComboBox::SelectAll() -{ - wxFAIL_MSG("Method Not Implemented."); -} - -bool wxComboBox::CanCopy() const -{ - wxFAIL_MSG("Method Not Implemented."); - return false; -} - -bool wxComboBox::CanCut() const -{ - wxFAIL_MSG("Method Not Implemented."); - return false; -} - -bool wxComboBox::CanPaste() const -{ - wxFAIL_MSG("Method Not Implemented."); - return false; -} - -bool wxComboBox::CanUndo() const -{ - wxFAIL_MSG("Method Not Implemented."); - return false; -} - -bool wxComboBox::CanRedo() const -{ - wxFAIL_MSG("Method Not Implemented."); - return false; + Delete(n); + Insert(s, n); + SetValue(s); // changing the item in the list won't update the display item } void wxComboBox::EnableTextChangedEvents(bool enable) @@ -287,28 +201,6 @@ void wxComboBox::EnableTextChangedEvents(bool enable) wxFAIL_MSG("Method Not Implemented."); } -void wxComboBox::WriteText(const wxString& text) -{ - wxFAIL_MSG("Method Not Implemented."); -} - -wxString wxComboBox::DoGetValue() const -{ - wxFAIL_MSG("Method Not Implemented."); - return wxEmptyString; -} - -wxClientDataType wxComboBox::GetClientDataType() const -{ - wxFAIL_MSG("Method Not Implemented."); - return wxClientData_None; -} - -void wxComboBox::SetClientDataType(wxClientDataType clientDataItemsType) -{ - wxFAIL_MSG("Method Not Implemented."); -} - bool wxComboBox::OSXHandleClicked( double timestampsec ) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); @@ -319,4 +211,14 @@ bool wxComboBox::OSXHandleClicked( double timestampsec ) return true; } -#endif // wxUSE_COMBOBOX && defined(wxOSX_USE_NATIVE_COMBOBOX) +wxTextWidgetImpl* wxComboBox::GetTextPeer() const +{ + return dynamic_cast (m_peer); +} + +wxComboWidgetImpl* wxComboBox::GetComboPeer() const +{ + return dynamic_cast (m_peer); +} + +#endif // wxUSE_COMBOBOX && wxOSX_USE_COCOA