X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f0c8f31f407ecfce909060464c0ea655221cdab..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/osx/carbon/combobox.cpp diff --git a/src/osx/carbon/combobox.cpp b/src/osx/carbon/combobox.cpp index 1174358e29..387f7402a5 100644 --- a/src/osx/carbon/combobox.cpp +++ b/src/osx/carbon/combobox.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/carbon/combobox.cpp +// Name: src/osx/carbon/combobox.cpp // Purpose: wxComboBox class // Author: Stefan Csomor, Dan "Bud" Keith (composite combobox) // Modified by: @@ -11,7 +11,7 @@ #include "wx/wxprec.h" -#if wxUSE_COMBOBOX +#if wxUSE_COMBOBOX && wxOSX_USE_CARBON #include "wx/combobox.h" @@ -23,27 +23,7 @@ #include "wx/textctrl.h" #endif -#include "wx/osx/uma.h" - -IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) - -WX_DELEGATE_TO_CONTROL_CONTAINER(wxComboBox, wxControl) - -BEGIN_EVENT_TABLE(wxComboBox, wxControl) - WX_EVENT_TABLE_CONTROL_CONTAINER(wxComboBox) -END_EVENT_TABLE() - - -static int nextPopUpMenuId = 1000 ; - -MenuHandle NewUniqueMenu() -{ - MenuHandle handle = UMANewMenu(nextPopUpMenuId, wxString(wxT("Menu")), wxFont::GetDefaultEncoding() ); - nextPopUpMenuId++ ; - - return handle ; -} - +#include "wx/osx/private.h" // ---------------------------------------------------------------------------- // constants @@ -68,7 +48,6 @@ public: : wxTextCtrl( cb , 1 ) { m_cb = cb; - SetTriggerOnSetValue( false ); } protected: @@ -148,6 +127,17 @@ protected: event.Skip(); } + void OnFocus( wxFocusEvent& event ) + { + // in case the textcontrol gets the focus we propagate + // it to the parent's handlers. + wxFocusEvent evt2(event.GetEventType(),m_cb->GetId()); + evt2.SetEventObject(m_cb); + m_cb->GetEventHandler()->ProcessEvent(evt2); + + event.Skip(); + } + private: wxComboBox *m_cb; @@ -158,6 +148,8 @@ BEGIN_EVENT_TABLE(wxComboBoxText, wxTextCtrl) EVT_KEY_DOWN(wxComboBoxText::OnKeyDown) EVT_CHAR(wxComboBoxText::OnChar) EVT_KEY_UP(wxComboBoxText::OnKeyUp) + EVT_SET_FOCUS(wxComboBoxText::OnFocus) + EVT_KILL_FOCUS(wxComboBoxText::OnFocus) EVT_TEXT(wxID_ANY, wxComboBoxText::OnText) END_EVENT_TABLE() @@ -229,17 +221,8 @@ wxComboBox::~wxComboBox() // 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 - if (m_text != NULL) - { - delete m_text; - m_text = NULL; - } - - if (m_choice != NULL) - { - delete m_choice; - m_choice = NULL; - } + wxDELETE(m_text); + wxDELETE(m_choice); } // ---------------------------------------------------------------------------- @@ -256,12 +239,11 @@ wxSize wxComboBox::DoGetBestSize() const if ( m_text != NULL ) { wxSize sizeText = m_text->GetBestSize(); - if (sizeText.y > size.y) - size.y = sizeText.y; + if (sizeText.y + 2 * TEXTFOCUSBORDER > size.y) + size.y = sizeText.y + 2 * TEXTFOCUSBORDER; size.x = m_choice->GetPopupWidth() + sizeText.x + MARGIN; size.x += TEXTFOCUSBORDER ; - size.y += 2 * TEXTFOCUSBORDER ; } else { @@ -286,9 +268,13 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { wxCoord wText = width - m_choice->GetPopupWidth() - MARGIN; m_text->SetSize(TEXTFOCUSBORDER, TEXTFOCUSBORDER, wText, -1); + wxSize tSize = m_text->GetSize(); + wxSize cSize = m_choice->GetSize(); + + int yOffset = ( tSize.y + 2 * TEXTFOCUSBORDER - cSize.y ) / 2; // put it at an inset of 1 to have outer area shadows drawn as well - m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , TEXTFOCUSBORDER, m_choice->GetPopupWidth() , -1); + m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , yOffset, m_choice->GetPopupWidth() , -1); } } @@ -325,11 +311,6 @@ void wxComboBox::DelegateChoice( const wxString& value ) SetStringSelection( value ); } -void wxComboBox::Init() -{ - WX_INIT_CONTROL_CONTAINER(); -} - bool wxComboBox::Create(wxWindow *parent, wxWindowID id, const wxString& value, @@ -393,6 +374,19 @@ bool wxComboBox::Create(wxWindow *parent, return true; } +void wxComboBox::EnableTextChangedEvents(bool enable) +{ + if ( m_text ) + m_text->ForwardEnableTextChangedEvents(enable); +} + +wxString wxComboBox::DoGetValue() const +{ + wxCHECK_MSG( m_text, wxString(), "can't be called for read-only combobox" ); + + return m_text->GetValue(); +} + wxString wxComboBox::GetValue() const { wxString result; @@ -454,10 +448,9 @@ void wxComboBox::SetEditable(bool editable) { m_text = new wxComboBoxText( this ); } - else if ( ( m_text != NULL ) && !editable ) + else if ( !editable ) { - delete m_text; - m_text = NULL; + wxDELETE(m_text); } int currentX, currentY; @@ -651,7 +644,7 @@ bool wxComboBox::CanRedo() const return false; } -wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +bool wxComboBox::OSXHandleClicked( double WXUNUSED(timestampsec) ) { /* For consistency with other platforms, clicking in the text area does not constitute a selection @@ -662,7 +655,15 @@ wxInt32 wxComboBox::MacControlHit( WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENT ProcessCommand(event); */ - return noErr ; + return true ; +} + +wxTextWidgetImpl* wxComboBox::GetTextPeer() const +{ + if (m_text) + return m_text->GetTextPeer(); + + return NULL; } -#endif // wxUSE_COMBOBOX +#endif // wxUSE_COMBOBOX && wxOSX_USE_CARBON