X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7ca4ac63835adef8226b655013a8a84b416c8171..1a8e309166de13278b719b3dd8b9db73d4750bb2:/src/common/combocmn.cpp diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index 356689bf70..b9792d8df8 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -25,9 +25,10 @@ #if wxUSE_COMBOCTRL +#include "wx/combobox.h" + #ifndef WX_PRECOMP #include "wx/log.h" - #include "wx/combobox.h" #include "wx/dcclient.h" #include "wx/settings.h" #include "wx/dialog.h" @@ -460,7 +461,7 @@ void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event) { int keycode = event.GetKeyCode(); - if ( keycode == WXK_TAB ) + if ( keycode == WXK_TAB && !m_combo->IsPopupShown() ) { wxNavigationKeyEvent evt; evt.SetFlags(wxNavigationKeyEvent::FromTab| @@ -491,19 +492,7 @@ void wxComboBoxExtraInputHandler::OnKey(wxKeyEvent& event) ( keycode != WXK_RIGHT && keycode != WXK_LEFT ) ) { - // Alternate keys: UP and DOWN show the popup instead of cycling - if ( (comboStyle & wxCC_ALT_KEYS) ) - { - if ( keycode == WXK_UP || keycode == WXK_DOWN ) - { - m_combo->OnButtonClick(); - return; - } - else - event.Skip(); - } - else - popupInterface->OnComboKeyEvent(event); + popupInterface->OnComboKeyEvent(event); } else event.Skip(); @@ -680,7 +669,7 @@ void wxComboCtrlBase::Init() m_btnState = 0; m_btnWidDefault = 0; m_blankButtonBg = false; - m_btnWid = m_btnHei = 0; + m_btnWid = m_btnHei = -1; m_btnSide = wxRIGHT; m_btnSpacingX = 0; @@ -716,6 +705,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; } @@ -732,24 +731,23 @@ void wxComboCtrlBase::InstallInputHandlers( bool alsoTextCtrl ) m_extraEvtHandler = inputHandler; } -void wxComboCtrlBase::CreateTextCtrl( int extraStyle, const wxValidator& validator ) +void +wxComboCtrlBase::CreateTextCtrl(int style, const wxValidator& validator) { if ( !(m_windowStyle & wxCB_READONLY) ) { - m_text = new wxTextCtrl(this, - wxID_ANY, - m_valueString, - wxDefaultPosition, - wxDefaultSize, - // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is - // not used by the wxPropertyGrid and therefore the tab is - // processed by looking at ancestors to see if they have - // wxTAB_TRAVERSAL. The navigation event is then sent to - // the wrong window. - wxTE_PROCESS_TAB | - wxTE_PROCESS_ENTER | - extraStyle, - validator); + // wxTE_PROCESS_TAB is needed because on Windows, wxTAB_TRAVERSAL is + // not used by the wxPropertyGrid and therefore the tab is processed by + // looking at ancestors to see if they have wxTAB_TRAVERSAL. The + // navigation event is then sent to the wrong window. + style |= wxTE_PROCESS_TAB; + + if ( HasFlag(wxTE_PROCESS_ENTER) ) + style |= wxTE_PROCESS_ENTER; + + m_text = new wxTextCtrl(this, wxID_ANY, m_valueString, + wxDefaultPosition, wxDefaultSize, + style, validator); // This is required for some platforms (GTK+ atleast) m_text->SetSizeHints(2,4); @@ -795,7 +793,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 @@ -804,15 +801,13 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth ) if ( ( (m_iFlags & wxCC_BUTTON_OUTSIDE_BORDER) || (m_bmpNormal.Ok() && m_blankButtonBg) ) && m_btnSpacingX == 0 && - m_btnHei == 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; } @@ -831,20 +826,32 @@ 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 ) + 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 ) - butHeight += m_btnHei; - else if ( m_btnHei > 0 ) + if ( m_btnHei > 0 ) butHeight = m_btnHei; // Use size of normal bitmap if... @@ -872,7 +879,7 @@ void wxComboCtrlBase::CalculateAreas( int btnWidth ) if ( (sz.y-(customBorder*2)) < butHeight && btnWidth == 0 ) { int newY = butHeight+(customBorder*2); - SetClientSize(-1,newY); + SetClientSize(wxDefaultCoord,newY); sz.y = newY; } } @@ -990,14 +997,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() ) @@ -1076,7 +1075,7 @@ void wxComboCtrlBase::DoSetToolTip(wxToolTip *tooltip) // ---------------------------------------------------------------------------- // draw focus background on area in a way typical on platform -void wxComboCtrlBase::DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) +void wxComboCtrlBase::DrawFocusBackground( wxDC& dc, const wxRect& rect, int flags ) const { wxSize sz = GetClientSize(); bool isEnabled; @@ -1110,8 +1109,14 @@ void wxComboCtrlBase::DrawFocusBackground( wxDC& dc, const wxRect& rect, int fla wxRect selRect(rect); selRect.y += focusSpacingY; selRect.height -= (focusSpacingY*2); - selRect.x += m_widthCustomPaint + focusSpacingX; - selRect.width -= m_widthCustomPaint + (focusSpacingX*2); + + int wcp = 0; + + if ( !(flags & wxCONTROL_ISSUBMENU) ) + wcp += m_widthCustomPaint; + + selRect.x += wcp + focusSpacingX; + selRect.width -= wcp + (focusSpacingX*2); wxColour bgCol; @@ -1269,8 +1274,11 @@ wxBitmap& wxComboCtrlBase::GetBufferBitmap( const wxSize& sz ) const void wxComboCtrlBase::OnTextCtrlEvent(wxCommandEvent& event) { - // Change event id and relay it forward + // Change event id, object and string before relaying it forward event.SetId(GetId()); + wxString s = event.GetString(); + event.SetEventObject(this); + event.SetString(s); event.Skip(); } @@ -1538,12 +1546,13 @@ void wxComboCtrlBase::DestroyPopup() if ( m_winPopup ) m_winPopup->Destroy(); + m_popupExtraHandler = (wxEvtHandler*) NULL; m_popupInterface = (wxComboPopup*) NULL; m_winPopup = (wxWindow*) NULL; m_popup = (wxWindow*) NULL; } -void wxComboCtrlBase::SetPopupControl( wxComboPopup* iface ) +void wxComboCtrlBase::DoSetPopupControl(wxComboPopup* iface) { wxCHECK_RET( iface, wxT("no popup interface set for wxComboCtrl") ); @@ -1832,7 +1841,7 @@ void wxComboCtrlBase::HidePopup() // ---------------------------------------------------------------------------- void wxComboCtrlBase::SetButtonPosition( int width, int height, - int side, int spacingX ) + int side, int spacingX ) { m_btnWid = width; m_btnHei = height; @@ -1842,6 +1851,25 @@ void wxComboCtrlBase::SetButtonPosition( int width, int height, RecalcAndRefresh(); } +wxSize wxComboCtrlBase::GetButtonSize() +{ + if ( m_btnSize.x > 0 ) + return m_btnSize; + + wxSize retSize(m_btnWid,m_btnHei); + + // Need to call CalculateAreas now if button size is + // is not explicitly specified. + if ( retSize.x <= 0 || retSize.y <= 0) + { + OnResize(); + + retSize = m_btnSize; + } + + return retSize; +} + void wxComboCtrlBase::SetButtonBitmaps( const wxBitmap& bmpNormal, bool blankButtonBg, const wxBitmap& bmpPressed,