X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e9576ca53db96b462ed4c0b4bdf47d64c40203e4..e7ca6139d062c37cc7c056b6647097e999b714cd:/src/mac/combobox.cpp diff --git a/src/mac/combobox.cpp b/src/mac/combobox.cpp index 0be841bad4..5dabd2dd49 100644 --- a/src/mac/combobox.cpp +++ b/src/mac/combobox.cpp @@ -14,11 +14,23 @@ #endif #include "wx/combobox.h" +#include "wx/menu.h" +#include "wx/mac/uma.h" #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) #endif +// right now we don't support editable comboboxes + +static int nextPopUpMenuId = 1000 ; +MenuHandle NewUniqueMenu() +{ + MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ; + nextPopUpMenuId++ ; + return handle ; +} + bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value, const wxPoint& pos, @@ -28,32 +40,41 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxValidator& validator, const wxString& name) { - SetName(name); - SetValidator(validator); m_noStrings = n; - m_windowStyle = style; - - if (parent) parent->AddChild(this); - - if ( id == -1 ) - m_windowId = (int)NewControlId(); - else - m_windowId = id; - // TODO: create combobox control - - return TRUE; + Rect bounds ; + Str255 title ; + + MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; + + m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , -12345 , 0, + kControlPopupButtonProc , (long) this ) ; + + m_macPopUpMenuHandle = NewUniqueMenu() ; + SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; + for ( int i = 0 ; i < n ; i++ ) + { + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + } + SetControlMinimum( m_macControl , 0 ) ; + SetControlMaximum( m_macControl , m_noStrings) ; + SetControlValue( m_macControl , 1 ) ; + + MacPostControlCreate() ; + + return TRUE; } wxString wxComboBox::GetValue() const { - // TODO - return wxString(""); + return GetStringSelection() ; } void wxComboBox::SetValue(const wxString& value) { - // TODO + SetStringSelection( value ) ; } // Clipboard operations @@ -116,50 +137,92 @@ void wxComboBox::SetSelection(long from, long to) void wxComboBox::Append(const wxString& item) { - // TODO + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( m_macPopUpMenuHandle , label ) ; + m_noStrings ++; + SetControlMaximum( m_macControl , m_noStrings) ; } void wxComboBox::Delete(int n) { - // TODO + wxASSERT( n < m_noStrings ) ; + ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; + m_noStrings --; + SetControlMaximum( m_macControl , m_noStrings) ; } void wxComboBox::Clear() { - // TODO + for ( int i = 0 ; i < m_noStrings ; i++ ) + { + ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; + } + m_noStrings = 0; + SetControlMaximum( m_macControl , m_noStrings) ; } int wxComboBox::GetSelection() const { - // TODO - return -1; + return GetControlValue( m_macControl ) -1 ; } void wxComboBox::SetSelection(int n) { - // TODO + SetControlValue( m_macControl , n + 1 ) ; } int wxComboBox::FindString(const wxString& s) const { - // TODO + for( int i = 0 ; i < m_noStrings ; i++ ) + { + if ( GetString( i ) == s ) + return i ; + } return -1; } wxString wxComboBox::GetString(int n) const { - // TODO - return wxString(""); + Str255 p_text ; + char c_text[255]; + ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , p_text ) ; +#if TARGET_CARBON + p2cstrcpy( c_text, p_text ) ; +#else + p2cstr( p_text ) ; + strcpy( c_text, (char *) p_text ) ; +#endif + return wxString( c_text ); } wxString wxComboBox::GetStringSelection() const { - // TODO - return wxString(""); + int sel = GetSelection (); + if (sel > -1) + return wxString(this->GetString (sel)); + else + return wxString(""); } bool wxComboBox::SetStringSelection(const wxString& sel) { - // TODO - return FALSE; + int s = FindString (sel); + if (s > -1) + { + SetSelection (s); + return TRUE; + } + else + return FALSE; +} + +void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) +{ + wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); + event.SetInt(GetSelection()); + event.SetEventObject(this); + event.SetString(GetStringSelection()); + ProcessCommand(event); } +