X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b7540dc1ecf6de3a9f771c3cd24c688a0122c248..90f9b8ef0c83c09f80c2f60ad65407ba16f11a3c:/src/common/combocmn.cpp diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index e78ccaaa1a..bca191234f 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -716,6 +716,16 @@ bool wxComboCtrlBase::Create(wxWindow *parent, OnThemeChange(); m_absIndent = GetNativeTextIndent(); + m_iFlags |= wxCC_IFLAG_CREATED; + + // If x and y indicate valid size, wxSizeEvent won't be + // emitted automatically, so we need to add artifical one. + if ( size.x > 0 && size.y > 0 ) + { + wxSizeEvent evt(size,GetId()); + GetEventHandler()->AddPendingEvent(evt); + } + return true; } @@ -774,15 +784,7 @@ wxComboCtrlBase::~wxComboCtrlBase() m_toplevEvtHandler = (wxEvtHandler*) NULL; #endif - if ( m_popup ) - m_popup->RemoveEventHandler(m_popupExtraHandler); - - delete m_popupExtraHandler; - - HidePopup(); - - delete m_popupInterface; - delete m_winPopup; + DestroyPopup(); RemoveEventHandler(m_extraEvtHandler); @@ -803,7 +805,6 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth ) { wxSize sz = GetClientSize(); int customBorder = m_widthCustomBorder; - bool buttonOutside; int btnBorder; // border for button only // check if button should really be outside the border: we'll do it it if @@ -814,13 +815,11 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth ) m_btnSpacingX == 0 && m_btnHei == 0 ) { - buttonOutside = true; m_iFlags |= wxCC_IFLAG_BUTTON_OUTSIDE; btnBorder = 0; } else { - buttonOutside = false; m_iFlags &= ~(wxCC_IFLAG_BUTTON_OUTSIDE); btnBorder = customBorder; } @@ -839,15 +838,31 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth ) if ( butWidth <= 0 ) return; + int butHeight = sz.y - btnBorder*2; + // Adjust button width if ( m_btnWid < 0 ) butWidth += m_btnWid; else if ( m_btnWid > 0 ) butWidth = m_btnWid; + else + { + // Adjust button width to match aspect ratio + // (but only if control is smaller than best size). + int bestHeight = GetBestSize().y; + int height = GetSize().y; - int butHeight = sz.y; - - butHeight -= btnBorder*2; + if ( height < bestHeight ) + { + // Make very small buttons square, as it makes + // them accommodate arrow image better and still + // looks decent. + if ( height > 18 ) + butWidth = (height*butWidth)/bestHeight; + else + butWidth = butHeight; + } + } // Adjust button height if ( m_btnHei < 0 ) @@ -998,14 +1013,6 @@ wxSize wxComboCtrlBase::DoGetBestSize() const return ret; } -void wxComboCtrlBase::DoMoveWindow(int x, int y, int width, int height) -{ - // SetSize is called last in create, so it marks the end of creation - m_iFlags |= wxCC_IFLAG_CREATED; - - wxControl::DoMoveWindow(x, y, width, height); -} - void wxComboCtrlBase::OnSizeEvent( wxSizeEvent& event ) { if ( !IsCreated() ) @@ -1531,19 +1538,38 @@ void wxComboCtrlBase::CreatePopup() popupInterface->m_iFlags |= wxCP_IFLAG_CREATED; } +// Destroy popup window and the child control +void wxComboCtrlBase::DestroyPopup() +{ + if ( m_popup ) + m_popup->RemoveEventHandler(m_popupExtraHandler); + + delete m_popupExtraHandler; + + HidePopup(); + + delete m_popupInterface; + + if ( m_winPopup ) + m_winPopup->Destroy(); + + m_popupInterface = (wxComboPopup*) NULL; + m_winPopup = (wxWindow*) NULL; + m_popup = (wxWindow*) NULL; +} + void wxComboCtrlBase::SetPopupControl( wxComboPopup* iface ) { wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") ); - delete m_popupInterface; - delete m_winPopup; + DestroyPopup(); iface->InitBase(this); iface->Init(); m_popupInterface = iface; - if ( !iface->LazyCreate() || m_winPopup ) + if ( !iface->LazyCreate() ) { CreatePopup(); }