wxZRColaCharGrid memory leak fixed

(fixes #23)
This commit is contained in:
Simon Rozman 2016-05-13 12:54:41 +02:00
parent 155fb03c5a
commit 5d732522fe
2 changed files with 12 additions and 12 deletions

View File

@ -61,6 +61,7 @@ wxZRColaCharGrid::~wxZRColaCharGrid()
void wxZRColaCharGrid::Init()
{
m_regenerate = false;
m_isResizing = false;
m_toolTipIdx = (size_t)-1;
}
@ -69,15 +70,12 @@ void wxZRColaCharGrid::Init()
void wxZRColaCharGrid::SetCharacters(const wxString &chars)
{
m_chars = chars;
m_regenerate = true;
// Build and set new grid data.
size_t char_len = m_chars.Length();
int rows = std::max<int>((char_len + m_numCols - 1) / m_numCols, 1);
wxGridStringTable *table = new wxGridStringTable(rows, m_numCols);
for (int r = 0, i = 0; r < rows; r++)
for (int c = 0; c < m_numCols; c++, i++)
table->SetValue(r, c, i < char_len ? wxString(1, m_chars[i]) : wxEmptyString);
SetTable(table, true);
// Invoke OnSize(), which will populate the grid.
wxSizeEvent e(GetSize(), m_windowId);
e.SetEventObject(this);
HandleWindowEvent(e);
}
@ -134,13 +132,14 @@ void wxZRColaCharGrid::OnSize(wxSizeEvent& event)
BeginBatch();
if (cols != m_numCols) {
if (m_regenerate || cols != m_numCols) {
// Build and set new grid data.
wxGridStringTable *table = new wxGridStringTable(rows, cols);
for (int r = 0, i = 0; r < rows; r++)
for (int c = 0; c < cols; c++, i++)
table->SetValue(r, c, i < char_len ? wxString(1, m_chars[i]) : wxEmptyString);
SetTable(table, true);
m_regenerate = false;
}
for (int c = 0; c < cols; c++)

View File

@ -84,6 +84,7 @@ protected:
wxString m_chars; ///< Array of Unicode characters to display in the grid
private:
bool m_regenerate; ///< Force regenerate grid table
bool m_isResizing; ///< Prevents nesting of OnSize() method.
wxTimer m_timerToolTip; ///< Timer for displaying tooltip
size_t m_toolTipIdx; ///< Index of cell for tooltip display