1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "accel.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
21 #include "wx/string.h"
25 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
27 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
29 friend class WXDLLEXPORT wxAcceleratorTable
;
31 wxAcceleratorRefData();
32 ~wxAcceleratorRefData();
36 wxAcceleratorEntry
* m_entries
;
39 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
41 wxAcceleratorRefData::wxAcceleratorRefData()
44 m_entries
= (wxAcceleratorEntry
*) NULL
;
47 wxAcceleratorRefData::~wxAcceleratorRefData()
50 m_entries
= (wxAcceleratorEntry
*) NULL
;
54 wxAcceleratorTable::wxAcceleratorTable()
56 m_refData
= (wxAcceleratorRefData
*) NULL
;
59 wxAcceleratorTable::~wxAcceleratorTable()
61 // Data deleted in ~wxObject
64 // Load from .rc resource
65 wxAcceleratorTable::wxAcceleratorTable(const wxString
& WXUNUSED(resource
))
67 m_refData
= new wxAcceleratorRefData
;
70 // Create from an array
71 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
73 wxAcceleratorRefData
* data
= new wxAcceleratorRefData
;
77 data
->m_entries
= new wxAcceleratorEntry
[n
];
79 for (i
= 0; i
< n
; i
++)
80 data
->m_entries
[i
] = entries
[i
];
84 bool wxAcceleratorTable::Ok() const
86 return (m_refData
!= (wxAcceleratorRefData
*) NULL
);
89 int wxAcceleratorTable::GetCount() const
91 return M_ACCELDATA
->m_count
;
94 wxAcceleratorEntry
* wxAcceleratorTable::GetEntries() const
96 return M_ACCELDATA
->m_entries
;
99 // Implementation use only
100 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent
& event
) const
102 bool eventAltDown
= event
.AltDown();
103 bool eventCtrlDown
= event
.ControlDown();
104 bool eventShiftDown
= event
.ShiftDown();
105 int eventKeyCode
= event
.GetKeyCode();
107 bool accAltDown
= ((GetFlags() & wxACCEL_ALT
) == wxACCEL_ALT
);
108 bool accCtrlDown
= ((GetFlags() & wxACCEL_CTRL
) == wxACCEL_CTRL
);
109 bool accShiftDown
= ((GetFlags() & wxACCEL_SHIFT
) == wxACCEL_SHIFT
);
110 int accKeyCode
= GetKeyCode();
111 int accKeyCode2
= GetKeyCode();
112 if (isascii(accKeyCode2
))
113 accKeyCode2
= tolower(accKeyCode2
);
115 return ((eventAltDown
== accAltDown
) && (eventCtrlDown
== accCtrlDown
) &&
116 (eventShiftDown
== accShiftDown
) &&
117 ((eventKeyCode
== accKeyCode
|| eventKeyCode
== accKeyCode2
))) ;