Remove manual memory management code for tooltips in wxStatusBar
Use a vector of unique_ptr<> to manage memory automatically instead. No real changes, this just simplifies the code and makes it more robust by making it impossible to forget to delete a tooltip.
This commit is contained in:
parent
8d8f94da64
commit
81ac38cf65
2 changed files with 12 additions and 21 deletions
|
|
@ -13,9 +13,11 @@
|
|||
|
||||
#if wxUSE_NATIVE_STATUSBAR
|
||||
|
||||
#include "wx/vector.h"
|
||||
#include "wx/tooltip.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class WXDLLIMPEXP_FWD_CORE wxClientDC;
|
||||
|
||||
class WXDLLIMPEXP_CORE wxStatusBar : public wxStatusBarBase
|
||||
|
|
@ -79,11 +81,6 @@ protected:
|
|||
// used by DoUpdateStatusText()
|
||||
wxClientDC *m_pDC;
|
||||
|
||||
#if wxUSE_TOOLTIPS
|
||||
// the tooltips used when wxSTB_SHOW_TIPS is given
|
||||
wxVector<wxToolTip*> m_tooltips;
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct MSWBorders
|
||||
{
|
||||
|
|
@ -107,6 +104,11 @@ private:
|
|||
// return the various status bar metrics
|
||||
static const MSWMetrics& MSWGetMetrics();
|
||||
|
||||
#if wxUSE_TOOLTIPS
|
||||
// the tooltips used when wxSTB_SHOW_TIPS is given
|
||||
std::vector<std::unique_ptr<wxToolTip>> m_tooltips;
|
||||
#endif
|
||||
|
||||
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxStatusBar);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -147,14 +147,6 @@ wxStatusBar::~wxStatusBar()
|
|||
// occupy
|
||||
PostSizeEventToParent();
|
||||
|
||||
#if wxUSE_TOOLTIPS
|
||||
// delete existing tooltips
|
||||
for (size_t i=0; i<m_tooltips.size(); i++)
|
||||
{
|
||||
wxDELETE(m_tooltips[i]);
|
||||
}
|
||||
#endif // wxUSE_TOOLTIPS
|
||||
|
||||
wxDELETE(m_pDC);
|
||||
}
|
||||
|
||||
|
|
@ -177,13 +169,10 @@ void wxStatusBar::SetFieldsCount(int nFields, const int *widths)
|
|||
|
||||
#if wxUSE_TOOLTIPS
|
||||
// reset all current tooltips
|
||||
for (size_t i=0; i<m_tooltips.size(); i++)
|
||||
{
|
||||
wxDELETE(m_tooltips[i]);
|
||||
}
|
||||
m_tooltips.clear();
|
||||
|
||||
// shrink/expand the array:
|
||||
m_tooltips.resize(nFields, nullptr);
|
||||
m_tooltips.resize(nFields);
|
||||
#endif // wxUSE_TOOLTIPS
|
||||
|
||||
wxStatusBarBase::SetFieldsCount(nFields, widths);
|
||||
|
|
@ -344,14 +333,14 @@ void wxStatusBar::DoUpdateStatusText(int nField)
|
|||
else
|
||||
{
|
||||
// delete the tooltip associated with this pane; it's not needed anymore
|
||||
wxDELETE(m_tooltips[nField]);
|
||||
m_tooltips[nField].reset();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// create a new tooltip for this pane if needed
|
||||
if (GetField(nField).IsEllipsized())
|
||||
m_tooltips[nField] = new wxToolTip(this, nField, GetStatusText(nField), rc);
|
||||
m_tooltips[nField].reset(new wxToolTip(this, nField, GetStatusText(nField), rc));
|
||||
//else: leave m_tooltips[nField]==nullptr
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue