X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b90c32b486407a69ed81e8991c2ec8a6e0602431..703e3c42d11a74be69cc1dee560e2c0f359ac13f:/src/generic/accel.cpp diff --git a/src/generic/accel.cpp b/src/generic/accel.cpp index d99b55cea6..15054cb158 100644 --- a/src/generic/accel.cpp +++ b/src/generic/accel.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: generic/accel.cpp +// Name: src/generic/accel.cpp // Purpose: generic implementation of wxAcceleratorTable class // Author: Robert Roebling // Modified: VZ pn 31.05.01: use typed lists, Unicode cleanup, Add/Remove @@ -16,10 +16,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "accel.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -30,8 +26,8 @@ #if wxUSE_ACCEL #ifndef WX_PRECOMP - #include "wx/event.h" #include "wx/list.h" + #include "wx/event.h" #endif // WX_PRECOMP #include "wx/accel.h" @@ -44,7 +40,7 @@ WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList); #include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxAccelList); +WX_DEFINE_LIST(wxAccelList) // ---------------------------------------------------------------------------- // wxAccelRefData: the data used by wxAcceleratorTable @@ -53,7 +49,20 @@ WX_DEFINE_LIST(wxAccelList); class wxAccelRefData : public wxObjectRefData { public: - wxAccelRefData() { m_accels.DeleteContents(TRUE); } + wxAccelRefData() + { + } + + wxAccelRefData(const wxAccelRefData& data) + : wxObjectRefData() + { + m_accels = data.m_accels; + } + + virtual ~wxAccelRefData() + { + WX_CLEAR_LIST(wxAccelList, 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 // ============================================================================ @@ -75,7 +85,7 @@ wxAcceleratorTable::wxAcceleratorTable() { } -wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) +wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) { m_refData = new wxAccelRefData; @@ -84,7 +94,7 @@ wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) const wxAcceleratorEntry& entry = entries[i]; int keycode = entry.GetKeyCode(); - if ( wxIslower(keycode) ) + if ( wxIsascii(keycode) ) keycode = wxToupper(keycode); M_ACCELDATA->m_accels.Append(new wxAcceleratorEntry(entry.GetFlags(), @@ -97,7 +107,7 @@ wxAcceleratorTable::~wxAcceleratorTable() { } -bool wxAcceleratorTable::Ok() const +bool wxAcceleratorTable::IsOk() const { return m_refData != NULL; } @@ -108,6 +118,8 @@ bool wxAcceleratorTable::Ok() const void wxAcceleratorTable::Add(const wxAcceleratorEntry& entry) { + AllocExclusive(); + if ( !m_refData ) { m_refData = new wxAccelRefData; @@ -118,14 +130,21 @@ void wxAcceleratorTable::Add(const wxAcceleratorEntry& entry) void wxAcceleratorTable::Remove(const wxAcceleratorEntry& entry) { - wxAccelList::Node *node = M_ACCELDATA->m_accels.GetFirst(); + AllocExclusive(); + + wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst(); while ( node ) { const wxAcceleratorEntry *entryCur = node->GetData(); - if ( *entryCur == entry ) + // given entry contains only the information of the accelerator key + // because it was set that way during creation so do not use the + // comparison operator which also checks the command field + if ((entryCur->GetKeyCode() == entry.GetKeyCode()) && + (entryCur->GetFlags() == entry.GetFlags())) { - M_ACCELDATA->m_accels.DeleteNode(node); + delete node->GetData(); + M_ACCELDATA->m_accels.Erase(node); return; } @@ -133,7 +152,7 @@ void wxAcceleratorTable::Remove(const wxAcceleratorEntry& entry) node = node->GetNext(); } - wxFAIL_MSG(_T("deleting inexistent accel from wxAcceleratorTable")); + wxFAIL_MSG(wxT("deleting inexistent accel from wxAcceleratorTable")); } // ---------------------------------------------------------------------------- @@ -149,7 +168,7 @@ wxAcceleratorTable::GetEntry(const wxKeyEvent& event) const return NULL; } - wxAccelList::Node *node = M_ACCELDATA->m_accels.GetFirst(); + wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst(); while ( node ) { const wxAcceleratorEntry *entry = node->GetData(); @@ -162,8 +181,7 @@ wxAcceleratorTable::GetEntry(const wxKeyEvent& event) const // now check flags if ( (((flags & wxACCEL_CTRL) != 0) == event.ControlDown()) && (((flags & wxACCEL_SHIFT) != 0) == event.ShiftDown()) && - (((flags & wxACCEL_ALT) != 0) == - (event.AltDown() || event.MetaDown())) ) + (((flags & wxACCEL_ALT) != 0) == event.AltDown()) ) { return entry; } @@ -189,5 +207,14 @@ int wxAcceleratorTable::GetCommand(const wxKeyEvent& event) const return entry ? entry->GetCommand() : -1; } -#endif // wxUSE_ACCEL +wxObjectRefData *wxAcceleratorTable::CreateRefData() const +{ + return new wxAccelRefData; +} +wxObjectRefData *wxAcceleratorTable::CloneRefData(const wxObjectRefData *data) const +{ + return new wxAccelRefData(*(wxAccelRefData *)data); +} + +#endif // wxUSE_ACCEL