Workaround for wxMac since it is unable to dismiss the edit control

when the listctrl is clicked on.  It has to do with a dependency on
the order of focus events so on wxMac we'll just explicitly dismiss
the edit control if it's active when the listctrl is clicked on.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@36720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2006-01-05 23:55:55 +00:00
parent a6956d86c7
commit b6bc47efde

View File

@@ -494,6 +494,8 @@ class WXDLLEXPORT wxListTextCtrl: public wxTextCtrl
public: public:
wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit); wxListTextCtrl(wxListMainWindow *owner, size_t itemEdit);
void AcceptChangesAndFinish();
protected: protected:
void OnChar( wxKeyEvent &event ); void OnChar( wxKeyEvent &event );
void OnKeyUp( wxKeyEvent &event ); void OnKeyUp( wxKeyEvent &event );
@@ -790,6 +792,8 @@ public:
m_lineBeforeLastClicked, m_lineBeforeLastClicked,
m_lineSelectSingleOnUp; m_lineSelectSingleOnUp;
wxListTextCtrl* m_textctrl;
protected: protected:
// the total count of items in a virtual list control // the total count of items in a virtual list control
size_t m_countVirt; size_t m_countVirt;
@@ -2068,6 +2072,7 @@ void wxListTextCtrl::Finish()
if ( !m_finished ) if ( !m_finished )
{ {
wxPendingDelete.Append(this); wxPendingDelete.Append(this);
m_owner->m_textctrl = NULL;
m_finished = true; m_finished = true;
@@ -2097,16 +2102,21 @@ bool wxListTextCtrl::AcceptChanges()
return true; return true;
} }
void wxListTextCtrl::OnChar( wxKeyEvent &event ) void wxListTextCtrl::AcceptChangesAndFinish()
{ {
switch ( event.m_keyCode )
{
case WXK_RETURN:
m_aboutToFinish = true; m_aboutToFinish = true;
// Notify the owner about the changes // Notify the owner about the changes
AcceptChanges(); AcceptChanges();
// Even if vetoed, close the control (consistent with MSW) // Even if vetoed, close the control (consistent with MSW)
Finish(); Finish();
}
void wxListTextCtrl::OnChar( wxKeyEvent &event )
{
switch ( event.m_keyCode )
{
case WXK_RETURN:
AcceptChangesAndFinish();
break; break;
case WXK_ESCAPE: case WXK_ESCAPE:
@@ -2198,6 +2208,7 @@ void wxListMainWindow::Init()
m_lastOnSame = false; m_lastOnSame = false;
m_renameTimer = new wxListRenameTimer( this ); m_renameTimer = new wxListRenameTimer( this );
m_textctrl = NULL;
m_current = m_current =
m_lineLastClicked = m_lineLastClicked =
@@ -2847,9 +2858,8 @@ void wxListMainWindow::EditLabel( long item )
if ( m_dirty ) if ( m_dirty )
wxSafeYield(); wxSafeYield();
wxListTextCtrl *text = new wxListTextCtrl(this, itemEdit); m_textctrl = new wxListTextCtrl(this, itemEdit);
m_textctrl->SetFocus();
text->SetFocus();
} }
void wxListMainWindow::OnRenameTimer() void wxListMainWindow::OnRenameTimer()
@@ -2894,6 +2904,17 @@ void wxListMainWindow::OnRenameCancelled(size_t itemEdit)
void wxListMainWindow::OnMouse( wxMouseEvent &event ) void wxListMainWindow::OnMouse( wxMouseEvent &event )
{ {
#ifdef __WXMAC__
// On wxMac we can't depend on the EVT_KILL_FOCUS event to properly
// shutdown the edit control when the mouse is clicked elsewhere on the
// listctrl because the order of events is different (or something like
// that,) so explicitly end the edit if it is active.
if ( event.LeftDown() && m_textctrl)
{
m_textctrl->AcceptChangesAndFinish();
}
#endif
event.SetEventObject( GetParent() ); event.SetEventObject( GetParent() );
if ( GetParent()->GetEventHandler()->ProcessEvent( event) ) if ( GetParent()->GetEventHandler()->ProcessEvent( event) )
return; return;