fixed wxColourDialog crash

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7698 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2000-07-05 19:27:30 +00:00
parent 05c7d17691
commit 3450f21ccf
7 changed files with 43 additions and 20 deletions

View File

@@ -103,6 +103,9 @@ protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
// common part of Destroy() and ~wxDialog
void CleanUp();
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO); int sizeFlags = wxSIZE_AUTO);

View File

@@ -103,6 +103,9 @@ protected:
// common part of all ctors // common part of all ctors
void Init(); void Init();
// common part of Destroy() and ~wxDialog
void CleanUp();
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO); int sizeFlags = wxSIZE_AUTO);

View File

@@ -504,6 +504,11 @@ void wxWindowBase::AddChild(wxWindowBase *child)
{ {
wxCHECK_RET( child, wxT("can't add a NULL child") ); wxCHECK_RET( child, wxT("can't add a NULL child") );
// this should never happen and it will lead to a crash later if it does
// because RemoveChild() will remove only one node from the children list
// and the other(s) one(s) will be left with dangling pointers in them
wxASSERT_MSG( !GetChildren().Find(child), _T("AddChild() called twice") );
GetChildren().Append(child); GetChildren().Append(child);
child->SetParent(this); child->SetParent(this);
} }

View File

@@ -85,7 +85,7 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size)
while (m_inflate->avail_out > 0) { while (m_inflate->avail_out > 0) {
if (m_inflate->avail_in == 0) { if (m_inflate->avail_in == 0) {
m_parent_i_stream->Read(m_z_buffer, m_z_size); m_parent_i_stream->Read(m_z_buffer, wxMin(m_z_size, size));
m_inflate->next_in = m_z_buffer; m_inflate->next_in = m_z_buffer;
m_inflate->avail_in = m_parent_i_stream->LastRead(); m_inflate->avail_in = m_parent_i_stream->LastRead();
@@ -95,6 +95,13 @@ size_t wxZlibInputStream::OnSysRead(void *buffer, size_t size)
m_lasterror = m_parent_i_stream->LastError(); m_lasterror = m_parent_i_stream->LastError();
return 0; // failed to read anything return 0; // failed to read anything
} }
if ( m_inflate->avail_in == 0 )
{
// EOF
m_lasterror = wxStream_EOF;
break;
}
} }
err = inflate(m_inflate, Z_FINISH); err = inflate(m_inflate, Z_FINISH);
if (err == Z_STREAM_END) if (err == Z_STREAM_END)

View File

@@ -123,9 +123,6 @@ wxGenericColourDialog::wxGenericColourDialog()
wxGenericColourDialog::wxGenericColourDialog(wxWindow *parent, wxGenericColourDialog::wxGenericColourDialog(wxWindow *parent,
wxColourData *data) wxColourData *data)
: wxDialog(parent, -1, wxT("Colour"),
wxPoint(0, 0), wxSize(900, 900),
wxDEFAULT_DIALOG_STYLE | wxDIALOG_MODAL)
{ {
whichKind = 1; whichKind = 1;
colourSelection = 0; colourSelection = 0;

View File

@@ -314,9 +314,7 @@ bool wxDialog::Create( wxWindow *parent,
wxDialog::~wxDialog() wxDialog::~wxDialog()
{ {
Destroy(); CleanUp();
m_isBeingDeleted = TRUE;
if ((wxTopLevelWindows.Number() == 0) && if ((wxTopLevelWindows.Number() == 0) &&
(wxTheApp->GetExitOnFrameDelete())) (wxTheApp->GetExitOnFrameDelete()))
@@ -328,13 +326,12 @@ wxDialog::~wxDialog()
void wxDialog::SetTitle( const wxString& title ) void wxDialog::SetTitle( const wxString& title )
{ {
m_title = title; m_title = title;
if (m_title.IsNull()) m_title = wxT("");
gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() );
} }
wxString wxDialog::GetTitle() const wxString wxDialog::GetTitle() const
{ {
return (wxString&)m_title; return m_title;
} }
void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
@@ -366,7 +363,7 @@ void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
else else
{ {
SetReturnCode(wxID_OK); SetReturnCode(wxID_OK);
this->Show(FALSE); Show(FALSE);
} }
} }
} }
@@ -415,14 +412,21 @@ bool wxDialog::Destroy()
// don't leave a dangling pointer as the app top window, we can be deleted // don't leave a dangling pointer as the app top window, we can be deleted
// any moment at all now! // any moment at all now!
CleanUp();
return TRUE;
}
void wxDialog::CleanUp()
{
m_isBeingDeleted = TRUE;
if ( wxTheApp->GetTopWindow() == this ) if ( wxTheApp->GetTopWindow() == this )
{ {
wxTheApp->SetTopWindow( (wxWindow*) NULL ); wxTheApp->SetTopWindow( (wxWindow*) NULL );
} }
wxTopLevelWindows.DeleteObject( this ); wxTopLevelWindows.DeleteObject( this );
return TRUE;
} }
void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) )

View File

@@ -314,9 +314,7 @@ bool wxDialog::Create( wxWindow *parent,
wxDialog::~wxDialog() wxDialog::~wxDialog()
{ {
Destroy(); CleanUp();
m_isBeingDeleted = TRUE;
if ((wxTopLevelWindows.Number() == 0) && if ((wxTopLevelWindows.Number() == 0) &&
(wxTheApp->GetExitOnFrameDelete())) (wxTheApp->GetExitOnFrameDelete()))
@@ -328,13 +326,12 @@ wxDialog::~wxDialog()
void wxDialog::SetTitle( const wxString& title ) void wxDialog::SetTitle( const wxString& title )
{ {
m_title = title; m_title = title;
if (m_title.IsNull()) m_title = wxT("");
gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() ); gtk_window_set_title( GTK_WINDOW(m_widget), m_title.mbc_str() );
} }
wxString wxDialog::GetTitle() const wxString wxDialog::GetTitle() const
{ {
return (wxString&)m_title; return m_title;
} }
void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) ) void wxDialog::OnApply( wxCommandEvent &WXUNUSED(event) )
@@ -366,7 +363,7 @@ void wxDialog::OnOK( wxCommandEvent &WXUNUSED(event) )
else else
{ {
SetReturnCode(wxID_OK); SetReturnCode(wxID_OK);
this->Show(FALSE); Show(FALSE);
} }
} }
} }
@@ -415,14 +412,21 @@ bool wxDialog::Destroy()
// don't leave a dangling pointer as the app top window, we can be deleted // don't leave a dangling pointer as the app top window, we can be deleted
// any moment at all now! // any moment at all now!
CleanUp();
return TRUE;
}
void wxDialog::CleanUp()
{
m_isBeingDeleted = TRUE;
if ( wxTheApp->GetTopWindow() == this ) if ( wxTheApp->GetTopWindow() == this )
{ {
wxTheApp->SetTopWindow( (wxWindow*) NULL ); wxTheApp->SetTopWindow( (wxWindow*) NULL );
} }
wxTopLevelWindows.DeleteObject( this ); wxTopLevelWindows.DeleteObject( this );
return TRUE;
} }
void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) ) void wxDialog::OnSize( wxSizeEvent &WXUNUSED(event) )