1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/string.h"
21 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
23 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
25 friend class WXDLLEXPORT wxAcceleratorTable
;
27 wxAcceleratorRefData();
28 ~wxAcceleratorRefData();
32 wxAcceleratorEntry
* m_entries
;
35 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
37 wxAcceleratorRefData::wxAcceleratorRefData()
40 m_entries
= (wxAcceleratorEntry
*) NULL
;
43 wxAcceleratorRefData::~wxAcceleratorRefData()
46 m_entries
= (wxAcceleratorEntry
*) NULL
;
50 wxAcceleratorTable::wxAcceleratorTable()
52 m_refData
= (wxAcceleratorRefData
*) NULL
;
55 wxAcceleratorTable::~wxAcceleratorTable()
57 // Data deleted in ~wxObject
60 // Load from .rc resource
61 wxAcceleratorTable::wxAcceleratorTable(const wxString
& WXUNUSED(resource
))
63 m_refData
= new wxAcceleratorRefData
;
66 // Create from an array
67 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
69 wxAcceleratorRefData
* data
= new wxAcceleratorRefData
;
73 data
->m_entries
= new wxAcceleratorEntry
[n
];
75 for (i
= 0; i
< n
; i
++)
76 data
->m_entries
[i
] = entries
[i
];
80 bool wxAcceleratorTable::Ok() const
82 return (m_refData
!= (wxAcceleratorRefData
*) NULL
);
85 int wxAcceleratorTable::GetCount() const
87 return M_ACCELDATA
->m_count
;
90 wxAcceleratorEntry
* wxAcceleratorTable::GetEntries() const
92 return M_ACCELDATA
->m_entries
;
95 // Implementation use only
96 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent
& event
) const
98 bool eventAltDown
= event
.AltDown();
99 bool eventCtrlDown
= event
.ControlDown();
100 bool eventShiftDown
= event
.ShiftDown();
101 int eventKeyCode
= event
.GetKeyCode();
103 bool accAltDown
= ((GetFlags() & wxACCEL_ALT
) == wxACCEL_ALT
);
104 bool accCtrlDown
= ((GetFlags() & wxACCEL_CTRL
) == wxACCEL_CTRL
);
105 bool accShiftDown
= ((GetFlags() & wxACCEL_SHIFT
) == wxACCEL_SHIFT
);
106 int accKeyCode
= GetKeyCode();
107 int accKeyCode2
= GetKeyCode();
108 if (isascii(accKeyCode2
))
109 accKeyCode2
= tolower(accKeyCode2
);
111 return ((eventAltDown
== accAltDown
) && (eventCtrlDown
== accCtrlDown
) &&
112 (eventShiftDown
== accShiftDown
) &&
113 ((eventKeyCode
== accKeyCode
|| eventKeyCode
== accKeyCode2
))) ;