X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/92d9d10f80420429c4291394c80b3814999074e4..424da8bdb9f05243d8888d78a56ab0cc3f615a6c:/src/generic/listctrl.cpp diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 4ce0960f73..5a3ef5ac90 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -804,7 +804,8 @@ void wxListLineData::DrawInReportMode( wxDC *dc, int xOld = x; x += width; - const int wText = width - 8; + width -= 8; + const int wText = width; wxDCClipper clipper(*dc, xOld, rect.y, wText, rect.height); if ( item->HasImage() ) @@ -820,7 +821,7 @@ void wxListLineData::DrawInReportMode( wxDC *dc, } if ( item->HasText() ) - DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, wText); + DrawTextFormatted(dc, item->GetText(), col, xOld, yMid, width); } } @@ -1407,23 +1408,31 @@ wxListTextCtrlWrapper::wxListTextCtrlWrapper(wxListMainWindow *owner, m_text->PushEventHandler(this); } -void wxListTextCtrlWrapper::EndEdit(bool discardChanges) +void wxListTextCtrlWrapper::EndEdit(EndReason reason) { m_aboutToFinish = true; - if ( discardChanges ) + switch ( reason ) { - m_owner->OnRenameCancelled(m_itemEdited); + case End_Accept: + // Notify the owner about the changes + AcceptChanges(); - Finish( true ); - } - else - { - // Notify the owner about the changes - AcceptChanges(); + // Even if vetoed, close the control (consistent with MSW) + Finish( true ); + break; + + case End_Discard: + m_owner->OnRenameCancelled(m_itemEdited); + + Finish( true ); + break; - // Even if vetoed, close the control (consistent with MSW) - Finish( true ); + case End_Destroy: + // Don't generate any notifications for the control being destroyed + // and don't set focus to it neither. + Finish(false); + break; } } @@ -1462,11 +1471,11 @@ void wxListTextCtrlWrapper::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: - EndEdit( false ); + EndEdit( End_Accept ); break; case WXK_ESCAPE: - EndEdit( true ); + EndEdit( End_Discard ); break; default: @@ -1600,6 +1609,9 @@ wxListMainWindow::wxListMainWindow( wxWindow *parent, wxListMainWindow::~wxListMainWindow() { + if ( m_textctrlWrapper ) + m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Destroy); + DoDeleteAllItems(); WX_CLEAR_LIST(wxListHeaderDataList, m_columns); WX_CLEAR_ARRAY(m_aColWidths); @@ -2273,7 +2285,7 @@ void wxListMainWindow::OnMouse( wxMouseEvent &event ) // 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_textctrlWrapper ) - m_textctrlWrapper->EndEdit( false ); + m_textctrlWrapper->EndEdit(wxListTextCtrlWrapper::End_Accept); #endif // __WXMAC__ if ( event.LeftDown() ) @@ -5049,12 +5061,22 @@ bool wxGenericListCtrl::DoPopupMenu( wxMenu *menu, int x, int y ) void wxGenericListCtrl::DoClientToScreen( int *x, int *y ) const { - m_mainWin->DoClientToScreen(x, y); + // It's not clear whether this can be called before m_mainWin is created + // but it seems better to be on the safe side and check. + if ( m_mainWin ) + m_mainWin->DoClientToScreen(x, y); + else + wxControl::DoClientToScreen(x, y); } void wxGenericListCtrl::DoScreenToClient( int *x, int *y ) const { - m_mainWin->DoScreenToClient(x, y); + // At least in wxGTK/Univ build this method can be called before m_mainWin + // is created so avoid crashes in this case. + if ( m_mainWin ) + m_mainWin->DoScreenToClient(x, y); + else + wxControl::DoScreenToClient(x, y); } void wxGenericListCtrl::SetFocus()