1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/accel.cpp
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"
16 #include "wx/string.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
22 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
24 friend class WXDLLEXPORT wxAcceleratorTable
;
26 wxAcceleratorRefData();
27 ~wxAcceleratorRefData();
31 wxAcceleratorEntry
* m_entries
;
34 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
36 wxAcceleratorRefData::wxAcceleratorRefData()
39 m_entries
= (wxAcceleratorEntry
*) NULL
;
42 wxAcceleratorRefData::~wxAcceleratorRefData()
45 m_entries
= (wxAcceleratorEntry
*) NULL
;
49 wxAcceleratorTable::wxAcceleratorTable()
51 m_refData
= (wxAcceleratorRefData
*) NULL
;
54 wxAcceleratorTable::~wxAcceleratorTable()
56 // Data deleted in ~wxObject
59 // Load from .rc resource
60 wxAcceleratorTable::wxAcceleratorTable(const wxString
& WXUNUSED(resource
))
62 m_refData
= new wxAcceleratorRefData
;
65 // Create from an array
66 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
68 wxAcceleratorRefData
* data
= new wxAcceleratorRefData
;
72 data
->m_entries
= new wxAcceleratorEntry
[n
];
74 for (i
= 0; i
< n
; i
++)
75 data
->m_entries
[i
] = entries
[i
];
79 bool wxAcceleratorTable::Ok() const
81 return (m_refData
!= (wxAcceleratorRefData
*) NULL
);
84 int wxAcceleratorTable::GetCount() const
86 return M_ACCELDATA
->m_count
;
89 wxAcceleratorEntry
* wxAcceleratorTable::GetEntries() const
91 return M_ACCELDATA
->m_entries
;
94 // Implementation use only
95 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent
& event
) const
97 bool eventAltDown
= event
.AltDown();
98 bool eventCtrlDown
= event
.ControlDown();
99 bool eventShiftDown
= event
.ShiftDown();
100 int eventKeyCode
= event
.GetKeyCode();
102 bool accAltDown
= ((GetFlags() & wxACCEL_ALT
) == wxACCEL_ALT
);
103 bool accCtrlDown
= ((GetFlags() & wxACCEL_CTRL
) == wxACCEL_CTRL
);
104 bool accShiftDown
= ((GetFlags() & wxACCEL_SHIFT
) == wxACCEL_SHIFT
);
105 int accKeyCode
= GetKeyCode();
106 int accKeyCode2
= GetKeyCode();
107 if (isascii(accKeyCode2
))
108 accKeyCode2
= tolower(accKeyCode2
);
110 return ((eventAltDown
== accAltDown
) && (eventCtrlDown
== accCtrlDown
) &&
111 (eventShiftDown
== accShiftDown
) &&
112 ((eventKeyCode
== accKeyCode
|| eventKeyCode
== accKeyCode2
))) ;