diff --git a/include/wx/generic/accel.h b/include/wx/generic/accel.h index 76e2f9369c..bdd4ff8a85 100644 --- a/include/wx/generic/accel.h +++ b/include/wx/generic/accel.h @@ -50,6 +50,11 @@ public: const wxAcceleratorEntry *GetEntry(const wxKeyEvent& event) const; +protected: + // ref counting code + virtual wxObjectRefData *CreateRefData() const; + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxAcceleratorTable) }; diff --git a/src/generic/accel.cpp b/src/generic/accel.cpp index d99b55cea6..21a745b598 100644 --- a/src/generic/accel.cpp +++ b/src/generic/accel.cpp @@ -53,7 +53,16 @@ WX_DEFINE_LIST(wxAccelList); class wxAccelRefData : public wxObjectRefData { public: - wxAccelRefData() { m_accels.DeleteContents(TRUE); } + wxAccelRefData() + { + m_accels.DeleteContents(TRUE); + } + + wxAccelRefData(const wxAccelRefData& data) + { + m_accels.DeleteContents(TRUE); + m_accels = data.m_accels; + } wxAccelList m_accels; }; @@ -61,6 +70,7 @@ public: // macro which can be used to access wxAccelRefData from wxAcceleratorTable #define M_ACCELDATA ((wxAccelRefData *)m_refData) + // ============================================================================ // implementation // ============================================================================ @@ -108,6 +118,8 @@ bool wxAcceleratorTable::Ok() const void wxAcceleratorTable::Add(const wxAcceleratorEntry& entry) { + AllocExclusive(); + if ( !m_refData ) { m_refData = new wxAccelRefData; @@ -118,6 +130,8 @@ void wxAcceleratorTable::Add(const wxAcceleratorEntry& entry) void wxAcceleratorTable::Remove(const wxAcceleratorEntry& entry) { + AllocExclusive(); + wxAccelList::Node *node = M_ACCELDATA->m_accels.GetFirst(); while ( node ) { @@ -189,5 +203,15 @@ int wxAcceleratorTable::GetCommand(const wxKeyEvent& event) const return entry ? entry->GetCommand() : -1; } +wxObjectRefData *wxAcceleratorTable::CreateRefData() const +{ + return new wxAccelRefData; +} + +wxObjectRefData *wxAcceleratorTable::CloneRefData(const wxObjectRefData *data) const +{ + return new wxAccelRefData(*(wxAccelRefData *)data); +} + #endif // wxUSE_ACCEL