X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/519cb848a8f4c91c73421bb75314754284e593a4..e7300ec6d9ebbd1cfa2fcf12c0ce6e5aee85a152:/src/mac/combobox.cpp diff --git a/src/mac/combobox.cpp b/src/mac/combobox.cpp index 905f3180aa..d55e591e52 100644 --- a/src/mac/combobox.cpp +++ b/src/mac/combobox.cpp @@ -14,6 +14,7 @@ #endif #include "wx/combobox.h" +#include "wx/menu.h" #include "wx/mac/uma.h" #if !USE_SHARED_LIBRARY @@ -22,6 +23,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) // 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, @@ -39,18 +47,20 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, MacPreControlCreate( parent , id , "" , pos , size ,style, validator , name , &bounds , title ) ; - m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , -12345 , 0, + m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , -12345 , 0, kControlPopupButtonProc , (long) this ) ; - m_macPopUpMenuHandle = NewMenu( 1 , "\pPopUp Menu" ) ; - SetControlData( m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; + m_macPopUpMenuHandle = NewUniqueMenu() ; + SetControlData( (ControlHandle) m_macControl , kControlNoPart , kControlPopupButtonMenuHandleTag , sizeof( MenuHandle ) , (char*) &m_macPopUpMenuHandle) ; for ( int i = 0 ; i < n ; i++ ) { - appendmenu( m_macPopUpMenuHandle , choices[i] ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , choices[i] ,false); + AppendMenu( (MenuHandle) m_macPopUpMenuHandle , label ) ; } - SetControlMinimum( m_macControl , 0 ) ; - SetControlMaximum( m_macControl , m_noStrings) ; - SetControlValue( m_macControl , 1 ) ; + SetControlMinimum( (ControlHandle) m_macControl , 0 ) ; + SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ; + SetControlValue( (ControlHandle) m_macControl , 1 ) ; MacPostControlCreate() ; @@ -127,37 +137,39 @@ void wxComboBox::SetSelection(long from, long to) void wxComboBox::Append(const wxString& item) { - appendmenu( m_macPopUpMenuHandle , item ) ; + Str255 label; + wxMenuItem::MacBuildMenuString( label , NULL , NULL , item ,false); + AppendMenu( (MenuHandle) m_macPopUpMenuHandle , label ) ; m_noStrings ++; - SetControlMaximum( m_macControl , m_noStrings) ; + SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ; } void wxComboBox::Delete(int n) { wxASSERT( n < m_noStrings ) ; - ::DeleteMenuItem( m_macPopUpMenuHandle , n + 1) ; + ::DeleteMenuItem( (MenuHandle) m_macPopUpMenuHandle , n + 1) ; m_noStrings --; - SetControlMaximum( m_macControl , m_noStrings) ; + SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ; } void wxComboBox::Clear() { for ( int i = 0 ; i < m_noStrings ; i++ ) { - ::DeleteMenuItem( m_macPopUpMenuHandle , 1 ) ; + ::DeleteMenuItem((MenuHandle) m_macPopUpMenuHandle , 1 ) ; } m_noStrings = 0; - SetControlMaximum( m_macControl , m_noStrings) ; + SetControlMaximum( (ControlHandle) m_macControl , m_noStrings) ; } int wxComboBox::GetSelection() const { - return GetControlValue( m_macControl ) -1 ; + return GetControlValue( (ControlHandle) m_macControl ) -1 ; } void wxComboBox::SetSelection(int n) { - SetControlValue( m_macControl , n + 1 ) ; + SetControlValue( (ControlHandle) m_macControl , n + 1 ) ; } int wxComboBox::FindString(const wxString& s) const @@ -172,10 +184,16 @@ int wxComboBox::FindString(const wxString& s) const wxString wxComboBox::GetString(int n) const { - Str255 text ; - ::GetMenuItemText( m_macPopUpMenuHandle , n+1 , text ) ; - p2cstr( text ) ; - return wxString( text ); + Str255 p_text ; + char c_text[255]; + ::GetMenuItemText( (MenuHandle) 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 @@ -199,13 +217,12 @@ bool wxComboBox::SetStringSelection(const wxString& sel) return FALSE; } -void wxComboBox::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) +void wxComboBox::MacHandleControlClick( WXWidget control , wxInt16 controlpart ) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); event.SetEventObject(this); - event.SetString(copystring(GetStringSelection())); + event.SetString(GetStringSelection()); ProcessCommand(event); - delete[] event.GetString(); }