X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c3422e90992d1330a8b412206d3381f63d2d29e..f138704e73645d58c647213bd8fbed0cb2c889fb:/src/common/popupcmn.cpp?ds=sidebyside diff --git a/src/common/popupcmn.cpp b/src/common/popupcmn.cpp index c78d74bcc4..0a79fdd679 100644 --- a/src/common/popupcmn.cpp +++ b/src/common/popupcmn.cpp @@ -40,14 +40,17 @@ #include "wx/univ/renderer.h" #endif // __WXUNIVERSAL__ -// there is no src/msw/popupwin.cpp to put this in, so we do it here - BTW we +// there is no src/{msw,mgl}/popupwin.cpp to put this in, so we do it here - BTW we // probably could do it for all ports here just as well -#ifdef __WXMSW__ +#if defined(__WXMSW__) || defined(__WXMGL__) IMPLEMENT_DYNAMIC_CLASS(wxPopupWindow, wxWindow) #endif // __WXMSW__ IMPLEMENT_DYNAMIC_CLASS(wxPopupTransientWindow, wxPopupWindow) -IMPLEMENT_DYNAMIC_CLASS(wxPopupComboWindow, wxPopupTransientWindow) + +#if wxUSE_COMBOBOX && defined(__WXUNIVERSAL__) + IMPLEMENT_DYNAMIC_CLASS(wxPopupComboWindow, wxPopupTransientWindow) +#endif // ---------------------------------------------------------------------------- // private classes @@ -73,15 +76,30 @@ private: class wxPopupFocusHandler : public wxEvtHandler { public: - wxPopupFocusHandler(wxPopupTransientWindow *popup) { m_popup = popup; } + wxPopupFocusHandler(wxPopupTransientWindow *popup) + { + m_popup = popup; + +#ifdef __WXGTK__ + // ignore the next few OnKillFocus() calls + m_creationTime = time(NULL); +#endif // __WXGTK__ + } protected: // event handlers void OnKillFocus(wxFocusEvent& event); + void OnKeyUp(wxKeyEvent& event); private: wxPopupTransientWindow *m_popup; + // hack around wxGTK bug: we always get several kill focus events + // immediately after creation! +#ifdef __WXGTK__ + time_t m_creationTime; +#endif // __WXGTK__ + DECLARE_EVENT_TABLE() }; @@ -95,6 +113,7 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxPopupFocusHandler, wxEvtHandler) EVT_KILL_FOCUS(wxPopupFocusHandler::OnKillFocus) + EVT_KEY_UP(wxPopupFocusHandler::OnKeyUp) END_EVENT_TABLE() // ============================================================================ @@ -105,6 +124,11 @@ END_EVENT_TABLE() // wxPopupWindowBase // ---------------------------------------------------------------------------- +wxPopupWindowBase::~wxPopupWindowBase() +{ + // this destructor is required for Darwin +} + bool wxPopupWindowBase::Create(wxWindow* WXUNUSED(parent), int WXUNUSED(flags)) { return TRUE; @@ -196,21 +220,30 @@ void wxPopupTransientWindow::Popup(wxWindow *winFocus) m_child = this; } - // we can't capture mouse before the window is shown in wxGTL -#ifdef __WXGTK__ + // we can't capture mouse before the window is shown in wxGTK, so do it + // first Show(); -#endif m_child->CaptureMouse(); m_child->PushEventHandler(new wxPopupWindowHandler(this)); -#ifndef __WXGTK__ - Show(); -#endif - m_focus = winFocus ? winFocus : this; - m_focus->PushEventHandler(new wxPopupFocusHandler(this)); m_focus->SetFocus(); + +#ifdef __WXMSW__ + // FIXME: I don't know why does this happen but sometimes SetFocus() simply + // refuses to work under MSW - no error happens but the focus is not + // given to the window, i.e. the assert below is triggered + // + // Try work around this as we can... + + //wxASSERT_MSG( FindFocus() == m_focus, _T("setting focus failed") ); + m_focus = FindFocus(); + if ( m_focus ) +#endif // __WXMSW__ + { + m_focus->PushEventHandler(new wxPopupFocusHandler(this)); + } } void wxPopupTransientWindow::Dismiss() @@ -354,12 +387,30 @@ void wxPopupWindowHandler::OnLeftDown(wxMouseEvent& event) void wxPopupFocusHandler::OnKillFocus(wxFocusEvent& event) { - // when we lose focus we always disappear +#ifdef __WXGTK__ + // ignore the next OnKillFocus() call + if ( time(NULL) < m_creationTime + 1 ) + { + event.Skip(); - // But if m_popup was about to get the focus, - // don't disappear. - if (event.GetWindow() != m_popup) + return; + } +#endif // __WXGTK__ + + // when we lose focus we always disappear - unless it goes to the popup (in + // which case we don't really lose it) + if ( event.GetWindow() != m_popup ) + m_popup->DismissAndNotify(); +} + +void wxPopupFocusHandler::OnKeyUp(wxKeyEvent& event) +{ + // let the window have it first, it might process the keys + if ( !m_popup->ProcessEvent(event) ) + { + // by default, dismiss the popup m_popup->DismissAndNotify(); + } } #endif // wxUSE_POPUPWIN