X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0847e36eff0512bf3c50c01e8d9dcff5e693ada5..af7e24c33e1e6e00a7687ee965b921dbe60cdb36:/src/common/combocmn.cpp?ds=sidebyside diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index e51c47e9fc..fafd36425e 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -32,7 +32,6 @@ #include "wx/log.h" #include "wx/dcclient.h" #include "wx/settings.h" - #include "wx/dialog.h" #include "wx/timer.h" #include "wx/textctrl.h" #endif @@ -59,6 +58,11 @@ #if defined(__WXMSW__) +// Let's use wxFrame as a fall-back solution until wxMSW gets wxNonOwnedWindow +#include "wx/frame.h" +#define wxCC_GENERIC_TLW_IS_FRAME +#define wxComboCtrlGenericTLW wxFrame + #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common // native controls work on it like normal. @@ -66,26 +70,23 @@ #define TEXTCTRL_TEXT_CENTERED 0 // 1 if text in textctrl is vertically centered #define FOCUS_RING 0 // No focus ring on wxMSW -#if !defined(__WXWINCE__) - // 1 if wxTextEntry::SetMargins() can be used to set the left margin - #define LEFT_MARGIN_CAN_BE_SET 1 -#else - #define LEFT_MARGIN_CAN_BE_SET 0 -#endif - //#undef wxUSE_POPUPWIN //#define wxUSE_POPUPWIN 0 #elif defined(__WXGTK__) -#include "wx/gtk/private.h" - // NB: It is not recommended to use wxDialog as popup on wxGTK, because of // this bug: If wxDialog is hidden, its position becomes corrupt // between hide and next show, but without internal coordinates being // reflected (or something like that - atleast commenting out ->Hide() // seemed to eliminate the position change). +#include "wx/dialog.h" +#define wxCC_GENERIC_TLW_IS_DIALOG +#define wxComboCtrlGenericTLW wxDialog + +#include "wx/gtk/private.h" + // NB: Let's not be afraid to use wxGTK's wxPopupTransientWindow as a // 'perfect' popup, as it can succesfully host child controls even in // popups that are shown in modal dialogs. @@ -97,15 +98,12 @@ #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered #define FOCUS_RING 0 // No focus ring on wxGTK -#if GTK_CHECK_VERSION(2,10,0) - // 1 if wxTextEntry::SetMargins() can be used to set the left margin - #define LEFT_MARGIN_CAN_BE_SET 1 -#else - #define LEFT_MARGIN_CAN_BE_SET 0 -#endif - #elif defined(__WXMAC__) +#include "wx/nonownedwnd.h" +#define wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW +#define wxComboCtrlGenericTLW wxNonOwnedWindow + #define USE_TRANSIENT_POPUP 1 // Use wxPopupWindowTransient (preferred, if it works properly on platform) #define TRANSIENT_POPUPWIN_IS_PERFECT 1 // wxPopupTransientWindow works, its child can have focus, and common // native controls work on it like normal. @@ -118,11 +116,12 @@ #undef COMBO_MARGIN #define COMBO_MARGIN FOCUS_RING -// 1 if wxTextEntry::SetMargins() can be used to set the left margin -#define LEFT_MARGIN_CAN_BE_SET 0 - #else +#include "wx/dialog.h" +#define wxCC_GENERIC_TLW_IS_DIALOG +#define wxComboCtrlGenericTLW wxDialog + #define USE_TRANSIENT_POPUP 0 // Use wxPopupWindowTransient (preferred, if it works properly on platform) #define TRANSIENT_POPUPWIN_IS_PERFECT 0 // wxPopupTransientWindow works, its child can have focus, and common // native controls work on it like normal. @@ -130,9 +129,6 @@ #define TEXTCTRL_TEXT_CENTERED 1 // 1 if text in textctrl is vertically centered #define FOCUS_RING 0 -// 1 if wxTextEntry::SetMargins() can be used to set the left margin -#define LEFT_MARGIN_CAN_BE_SET 0 - #endif @@ -159,7 +155,7 @@ enum POPUPWIN_NONE = 0, POPUPWIN_WXPOPUPTRANSIENTWINDOW = 1, POPUPWIN_WXPOPUPWINDOW = 2, - POPUPWIN_WXDIALOG = 3 + POPUPWIN_GENERICTLW = 3 }; @@ -177,9 +173,9 @@ enum #define SECONDARY_POPUP_TYPE POPUPWIN_WXPOPUPWINDOW #define USES_WXPOPUPWINDOW 1 #else - #define wxComboPopupWindowBase2 wxDialog - #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG - #define USES_WXDIALOG 1 + #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW + #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW + #define USES_GENERICTLW 1 #endif #elif wxUSE_POPUPWIN @@ -190,17 +186,17 @@ enum #define USES_WXPOPUPWINDOW 1 #if !POPUPWIN_IS_PERFECT - #define wxComboPopupWindowBase2 wxDialog - #define SECONDARY_POPUP_TYPE POPUPWIN_WXDIALOG - #define USES_WXDIALOG 1 + #define wxComboPopupWindowBase2 wxComboCtrlGenericTLW + #define SECONDARY_POPUP_TYPE POPUPWIN_GENERICTLW + #define USES_GENERICTLW 1 #endif #else // wxPopupWindow is not implemented - #define wxComboPopupWindowBase wxDialog - #define PRIMARY_POPUP_TYPE POPUPWIN_WXDIALOG - #define USES_WXDIALOG 1 + #define wxComboPopupWindowBase wxComboCtrlGenericTLW + #define PRIMARY_POPUP_TYPE POPUPWIN_GENERICTLW + #define USES_GENERICTLW 1 #endif @@ -213,8 +209,8 @@ enum #define USES_WXPOPUPWINDOW 0 #endif -#ifndef USES_WXDIALOG - #define USES_WXDIALOG 0 +#ifndef USES_GENERICTLW + #define USES_GENERICTLW 0 #endif @@ -311,7 +307,7 @@ void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event ) winFocused != m_combo->GetButton() // GTK (atleast) requires this ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); } event.Skip(); @@ -319,37 +315,37 @@ void wxComboFrameEventHandler::OnIdle( wxIdleEvent& event ) void wxComboFrameEventHandler::OnMenuEvent( wxMenuEvent& event ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } void wxComboFrameEventHandler::OnMouseEvent( wxMouseEvent& event ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } void wxComboFrameEventHandler::OnClose( wxCloseEvent& event ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } void wxComboFrameEventHandler::OnActivate( wxActivateEvent& event ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } void wxComboFrameEventHandler::OnResize( wxSizeEvent& event ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } void wxComboFrameEventHandler::OnMove( wxMoveEvent& event ) { - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } @@ -433,7 +429,7 @@ void wxComboPopupWindow::OnDismiss() wxASSERT_MSG( combo->IsKindOf(CLASSINFO(wxComboCtrlBase)), wxT("parent might not be wxComboCtrl, but check IMPLEMENT_DYNAMIC_CLASS(2) macro for correctness") ); - combo->OnPopupDismiss(); + combo->OnPopupDismiss(true); } #endif // USES_WXPOPUPTRANSIENTWINDOW @@ -455,7 +451,7 @@ public: void OnSizeEvent( wxSizeEvent& event ); void OnKeyEvent(wxKeyEvent& event); -#if USES_WXDIALOG +#if USES_GENERICTLW void OnActivate( wxActivateEvent& event ); #endif @@ -469,7 +465,7 @@ private: BEGIN_EVENT_TABLE(wxComboPopupWindowEvtHandler, wxEvtHandler) EVT_KEY_DOWN(wxComboPopupWindowEvtHandler::OnKeyEvent) EVT_KEY_UP(wxComboPopupWindowEvtHandler::OnKeyEvent) -#if USES_WXDIALOG +#if USES_GENERICTLW EVT_ACTIVATE(wxComboPopupWindowEvtHandler::OnActivate) #endif EVT_SIZE(wxComboPopupWindowEvtHandler::OnSizeEvent) @@ -490,13 +486,13 @@ void wxComboPopupWindowEvtHandler::OnKeyEvent( wxKeyEvent& event ) child->GetEventHandler()->AddPendingEvent(event); } -#if USES_WXDIALOG +#if USES_GENERICTLW void wxComboPopupWindowEvtHandler::OnActivate( wxActivateEvent& event ) { if ( !event.GetActive() ) { // Tell combo control that we are dismissed. - m_combo->HidePopup(); + m_combo->HidePopup(true); event.Skip(); } @@ -571,7 +567,7 @@ bool wxComboPopup::LazyCreate() void wxComboPopup::Dismiss() { - m_combo->HidePopup(); + m_combo->HidePopup(true); } // ---------------------------------------------------------------------------- @@ -1085,14 +1081,26 @@ void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust int customBorder = m_widthCustomBorder; if ( (m_text->GetWindowStyleFlag() & wxBORDER_MASK) == wxNO_BORDER ) { -#if LEFT_MARGIN_CAN_BE_SET - // Call SetMargins() on textctrl if LEFT_MARGIN_CAN_BE_SET == 1 - wxUnusedVar(textCtrlXAdjust); - m_text->SetMargins(0); - textCtrlXAdjust = 0; -#endif + int x; + + if ( !m_widthCustomPaint ) + { + // No special custom paint area - we can use 0 left margin + // with wxTextCtrl. + if ( m_text->SetMargins(0) ) + textCtrlXAdjust = 0; + x = m_tcArea.x + m_marginLeft + textCtrlXAdjust; + } + else + { + // There is special custom paint area - it is better to + // use some margin with the wxTextCtrl. + m_text->SetMargins(m_marginLeft); + x = m_tcArea.x + m_widthCustomPaint + + m_marginLeft + textCtrlXAdjust; + } - // Centre textctrl + // Centre textctrl vertically, if needed #if !TEXTCTRL_TEXT_CENTERED int tcSizeY = m_text->GetBestSize().y; int diff0 = sz.y - tcSizeY; @@ -1105,15 +1113,9 @@ void wxComboCtrlBase::PositionTextCtrl( int textCtrlXAdjust, int textCtrlYAdjust if ( y < customBorder ) y = customBorder; - int x = m_tcArea.x + m_widthCustomPaint + - m_marginLeft + textCtrlXAdjust; - m_text->SetSize(x, y, m_tcArea.width - m_tcArea.x - x, - /*m_tcArea.width - COMBO_MARGIN - - (textCtrlXAdjust + m_widthCustomPaint + - m_marginLeft),*/ -1 ); // Make sure textctrl doesn't exceed the bottom custom border @@ -1249,8 +1251,15 @@ bool wxComboCtrlBase::SetFont ( const wxFont& font ) if ( !wxControl::SetFont(font) ) return false; - if (m_text) + if ( m_text ) + { + // Without hiding the wxTextCtrl there would be some + // visible 'flicker' (at least on Windows XP). + m_text->Hide(); m_text->SetFont(font); + OnResize(); + m_text->Show(); + } return true; } @@ -1625,13 +1634,13 @@ bool wxComboCtrlBase::PreprocessMouseEvent( wxMouseEvent& event, wxLongLong t = ::wxGetLocalTimeMillis(); int evtType = event.GetEventType(); -#if USES_WXPOPUPWINDOW || USES_WXDIALOG +#if USES_WXPOPUPWINDOW || USES_GENERICTLW if ( m_popupWinType != POPUPWIN_WXPOPUPTRANSIENTWINDOW ) { if ( IsPopupWindowState(Visible) && ( evtType == wxEVT_LEFT_DOWN || evtType == wxEVT_RIGHT_DOWN ) ) { - HidePopup(); + HidePopup(true); return true; } } @@ -1659,7 +1668,7 @@ void wxComboCtrlBase::HandleNormalMouseEvent( wxMouseEvent& event ) #if USES_WXPOPUPWINDOW // Click here always hides the popup. if ( m_popupWinType == POPUPWIN_WXPOPUPWINDOW ) - HidePopup(); + HidePopup(true); #endif } else @@ -1736,13 +1745,9 @@ void wxComboCtrlBase::OnFocusEvent( wxFocusEvent& event ) { wxWindow* tc = GetTextCtrl(); if ( tc && tc != DoFindFocus() ) -#ifdef __WXMAC__ - m_resetFocus = true; -#else { tc->SetFocus(); } -#endif } Refresh(); @@ -1783,12 +1788,23 @@ void wxComboCtrlBase::CreatePopup() #ifdef wxComboPopupWindowBase2 if ( m_iFlags & wxCC_IFLAG_USE_ALT_POPUP ) { - #if !USES_WXDIALOG + #if !USES_GENERICTLW m_winPopup = new wxComboPopupWindowBase2( this, wxNO_BORDER ); #else + int tlwFlags = wxNO_BORDER; + #ifdef wxCC_GENERIC_TLW_IS_FRAME + tlwFlags |= wxFRAME_NO_TASKBAR; + #endif + + #ifdef wxCC_GENERIC_TLW_IS_NONOWNEDWINDOW + m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, + wxPoint(-21,-21), wxSize(20, 20), + tlwFlags ); + #else m_winPopup = new wxComboPopupWindowBase2( this, wxID_ANY, wxEmptyString, wxPoint(-21,-21), wxSize(20, 20), - wxNO_BORDER ); + tlwFlags ); + #endif #endif m_popupWinType = SECONDARY_POPUP_TYPE; } @@ -1819,7 +1835,7 @@ void wxComboCtrlBase::CreatePopup() // Destroy popup window and the child control void wxComboCtrlBase::DestroyPopup() { - HidePopup(); + HidePopup(true); if ( m_popup ) m_popup->RemoveEventHandler(m_popupExtraHandler); @@ -1882,9 +1898,17 @@ void wxComboCtrlBase::OnButtonClick() // Derived classes can override this method for totally custom // popup action if ( !IsPopupWindowState(Visible) ) + { + wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_DROPDOWN, GetId()); + event.SetEventObject(this); + HandleWindowEvent(event); + ShowPopup(); + } else - HidePopup(); + { + HidePopup(true); + } } void wxComboCtrlBase::ShowPopup() @@ -2103,7 +2127,7 @@ void wxComboCtrlBase::DoShowPopup( const wxRect& rect, int WXUNUSED(flags) ) Refresh(); } -void wxComboCtrlBase::OnPopupDismiss() +void wxComboCtrlBase::OnPopupDismiss(bool generateEvent) { // Just in case, avoid double dismiss if ( IsPopupWindowState(Hidden) ) @@ -2155,9 +2179,16 @@ void wxComboCtrlBase::OnPopupDismiss() Refresh(); SetFocus(); + + if ( generateEvent ) + { + wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_CLOSEUP, GetId()); + event.SetEventObject(this); + HandleWindowEvent(event); + } } -void wxComboCtrlBase::HidePopup() +void wxComboCtrlBase::HidePopup(bool generateEvent) { // Should be able to call this without popup interface if ( IsPopupWindowState(Hidden) ) @@ -2169,7 +2200,7 @@ void wxComboCtrlBase::HidePopup() m_winPopup->Hide(); - OnPopupDismiss(); + OnPopupDismiss(generateEvent); } // ---------------------------------------------------------------------------- @@ -2282,7 +2313,7 @@ wxPoint wxComboCtrlBase::DoGetMargins() const return wxPoint(m_marginLeft, -1); } -#if WXWIN_COMPATIBILITY_2_6 +#if WXWIN_COMPATIBILITY_2_8 void wxComboCtrlBase::SetTextIndent( int indent ) { if ( indent < 0 ) @@ -2299,7 +2330,7 @@ void wxComboCtrlBase::SetTextIndent( int indent ) RecalcAndRefresh(); } -wxCoord wxComboCtrlBase::GetTextIndent() const; +wxCoord wxComboCtrlBase::GetTextIndent() const { return m_marginLeft; }