fixed huge memory leak in wxFileDialog (closes patch 544060)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15214 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -201,8 +201,8 @@ wxGTK:
|
|||||||
- support for more SGI hardware (12-bit mode among others)
|
- support for more SGI hardware (12-bit mode among others)
|
||||||
- fixed wxDC::Blit() to honour source DC's logical coordinates
|
- fixed wxDC::Blit() to honour source DC's logical coordinates
|
||||||
- implemented wxIdleEvent::RequestMore() for simple background tasks
|
- implemented wxIdleEvent::RequestMore() for simple background tasks
|
||||||
(unlike thread work)
|
|
||||||
- implemented wxChoice::Delete()
|
- implemented wxChoice::Delete()
|
||||||
|
- fixed bad memory leak in wxFileDialog (Chris Elliott)
|
||||||
|
|
||||||
wxHTML:
|
wxHTML:
|
||||||
|
|
||||||
|
@@ -67,17 +67,16 @@
|
|||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxFileData
|
// wxFileData
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
class wxFileData : public wxObject
|
class wxFileData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
wxFileData() { }
|
|
||||||
wxFileData( const wxString &name, const wxString &fname );
|
wxFileData( const wxString &name, const wxString &fname );
|
||||||
wxString GetName() const;
|
wxString GetName() const;
|
||||||
wxString GetFullName() const;
|
wxString GetFullName() const;
|
||||||
@@ -103,8 +102,6 @@ private:
|
|||||||
bool m_isDir;
|
bool m_isDir;
|
||||||
bool m_isLink;
|
bool m_isLink;
|
||||||
bool m_isExe;
|
bool m_isExe;
|
||||||
|
|
||||||
DECLARE_DYNAMIC_CLASS(wxFileData);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@@ -124,6 +121,8 @@ public:
|
|||||||
long style = wxLC_LIST,
|
long style = wxLC_LIST,
|
||||||
const wxValidator &validator = wxDefaultValidator,
|
const wxValidator &validator = wxDefaultValidator,
|
||||||
const wxString &name = wxT("filelist") );
|
const wxString &name = wxT("filelist") );
|
||||||
|
virtual ~wxFileCtrl();
|
||||||
|
|
||||||
void ChangeToListMode();
|
void ChangeToListMode();
|
||||||
void ChangeToReportMode();
|
void ChangeToReportMode();
|
||||||
void ChangeToIconMode();
|
void ChangeToIconMode();
|
||||||
@@ -138,7 +137,6 @@ public:
|
|||||||
void SetWild( const wxString &wild );
|
void SetWild( const wxString &wild );
|
||||||
void GetDir( wxString &dir );
|
void GetDir( wxString &dir );
|
||||||
void OnListDeleteItem( wxListEvent &event );
|
void OnListDeleteItem( wxListEvent &event );
|
||||||
void OnListDeleteAllItems( wxListEvent &event );
|
|
||||||
void OnListEndLabelEdit( wxListEvent &event );
|
void OnListEndLabelEdit( wxListEvent &event );
|
||||||
|
|
||||||
// Associate commonly used UI controls with wxFileCtrl so that they can be
|
// Associate commonly used UI controls with wxFileCtrl so that they can be
|
||||||
@@ -148,6 +146,9 @@ public:
|
|||||||
void SetNewDirControl(wxWindow *ctrl) { m_newDirControl = ctrl; }
|
void SetNewDirControl(wxWindow *ctrl) { m_newDirControl = ctrl; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void FreeItemData(const wxListItem& item);
|
||||||
|
void FreeAllItemsData();
|
||||||
|
|
||||||
wxString m_dirName;
|
wxString m_dirName;
|
||||||
bool m_showHidden;
|
bool m_showHidden;
|
||||||
wxString m_wild;
|
wxString m_wild;
|
||||||
@@ -391,8 +392,6 @@ extern bool wxIsDriveAvailable(const wxString& dirName);
|
|||||||
// wxFileData
|
// wxFileData
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_DYNAMIC_CLASS(wxFileData,wxObject);
|
|
||||||
|
|
||||||
wxFileData::wxFileData( const wxString &name, const wxString &fname )
|
wxFileData::wxFileData( const wxString &name, const wxString &fname )
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = name;
|
||||||
@@ -584,7 +583,6 @@ IMPLEMENT_DYNAMIC_CLASS(wxFileCtrl,wxListCtrl);
|
|||||||
|
|
||||||
BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
|
BEGIN_EVENT_TABLE(wxFileCtrl,wxListCtrl)
|
||||||
EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
|
EVT_LIST_DELETE_ITEM(-1, wxFileCtrl::OnListDeleteItem)
|
||||||
EVT_LIST_DELETE_ALL_ITEMS(-1, wxFileCtrl::OnListDeleteAllItems)
|
|
||||||
EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
|
EVT_LIST_END_LABEL_EDIT(-1, wxFileCtrl::OnListEndLabelEdit)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
@@ -680,7 +678,9 @@ void wxFileCtrl::UpdateFiles()
|
|||||||
name_col_width = GetColumnWidth( 0 );
|
name_col_width = GetColumnWidth( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FreeAllItemsData();
|
||||||
ClearAll();
|
ClearAll();
|
||||||
|
|
||||||
if (my_style & wxLC_REPORT)
|
if (my_style & wxLC_REPORT)
|
||||||
{
|
{
|
||||||
if (name_col_width < 140) name_col_width = 140;
|
if (name_col_width < 140) name_col_width = 140;
|
||||||
@@ -884,13 +884,18 @@ void wxFileCtrl::GetDir( wxString &dir )
|
|||||||
dir = m_dirName;
|
dir = m_dirName;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
|
void wxFileCtrl::FreeItemData(const wxListItem& item)
|
||||||
{
|
{
|
||||||
wxFileData *fd = (wxFileData*)event.m_item.m_data;
|
wxFileData *fd = (wxFileData*)item.m_data;
|
||||||
delete fd;
|
delete fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileCtrl::OnListDeleteAllItems( wxListEvent &WXUNUSED(event) )
|
void wxFileCtrl::OnListDeleteItem( wxListEvent &event )
|
||||||
|
{
|
||||||
|
FreeItemData(event.m_item);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxFileCtrl::FreeAllItemsData()
|
||||||
{
|
{
|
||||||
wxListItem item;
|
wxListItem item;
|
||||||
item.m_mask = wxLIST_MASK_DATA;
|
item.m_mask = wxLIST_MASK_DATA;
|
||||||
@@ -899,10 +904,7 @@ void wxFileCtrl::OnListDeleteAllItems( wxListEvent &WXUNUSED(event) )
|
|||||||
while ( item.m_itemId != -1 )
|
while ( item.m_itemId != -1 )
|
||||||
{
|
{
|
||||||
GetItem( item );
|
GetItem( item );
|
||||||
wxFileData *fd = (wxFileData*)item.m_data;
|
FreeItemData(item);
|
||||||
delete fd;
|
|
||||||
item.m_data = 0;
|
|
||||||
SetItem( item );
|
|
||||||
item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL );
|
item.m_itemId = GetNextItem( item.m_itemId, wxLIST_NEXT_ALL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -950,6 +952,11 @@ void wxFileCtrl::OnListEndLabelEdit( wxListEvent &event )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxFileCtrl::~wxFileCtrl()
|
||||||
|
{
|
||||||
|
FreeAllItemsData();
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxFileDialog
|
// wxFileDialog
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user