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"
18 #include "wx/string.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
26 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
28 friend class WXDLLEXPORT wxAcceleratorTable
;
30 wxAcceleratorRefData();
31 virtual ~wxAcceleratorRefData();
35 wxAcceleratorEntry
* m_entries
;
38 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
40 wxAcceleratorRefData::wxAcceleratorRefData()
43 m_entries
= (wxAcceleratorEntry
*) NULL
;
46 wxAcceleratorRefData::~wxAcceleratorRefData()
49 m_entries
= (wxAcceleratorEntry
*) NULL
;
53 wxAcceleratorTable::wxAcceleratorTable()
55 m_refData
= (wxAcceleratorRefData
*) NULL
;
58 wxAcceleratorTable::~wxAcceleratorTable()
60 // Data deleted in ~wxObject
63 // Load from .rc resource
64 wxAcceleratorTable::wxAcceleratorTable(const wxString
& WXUNUSED(resource
))
66 m_refData
= new wxAcceleratorRefData
;
69 // Create from an array
70 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
72 wxAcceleratorRefData
* data
= new wxAcceleratorRefData
;
76 data
->m_entries
= new wxAcceleratorEntry
[n
];
78 for (i
= 0; i
< n
; i
++)
79 data
->m_entries
[i
] = entries
[i
];
83 bool wxAcceleratorTable::Ok() const
85 return (m_refData
!= (wxAcceleratorRefData
*) NULL
);
88 int wxAcceleratorTable::GetCount() const
90 return M_ACCELDATA
->m_count
;
93 wxAcceleratorEntry
* wxAcceleratorTable::GetEntries() const
95 return M_ACCELDATA
->m_entries
;
98 // Implementation use only
99 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent
& event
) const
101 bool eventAltDown
= event
.AltDown();
102 bool eventCtrlDown
= event
.ControlDown();
103 bool eventShiftDown
= event
.ShiftDown();
104 int eventKeyCode
= event
.GetKeyCode();
106 bool accAltDown
= ((GetFlags() & wxACCEL_ALT
) == wxACCEL_ALT
);
107 bool accCtrlDown
= ((GetFlags() & wxACCEL_CTRL
) == wxACCEL_CTRL
);
108 bool accShiftDown
= ((GetFlags() & wxACCEL_SHIFT
) == wxACCEL_SHIFT
);
109 int accKeyCode
= GetKeyCode();
110 int accKeyCode2
= GetKeyCode();
111 if (isascii(accKeyCode2
))
112 accKeyCode2
= tolower(accKeyCode2
);
114 return ((eventAltDown
== accAltDown
) && (eventCtrlDown
== accCtrlDown
) &&
115 (eventShiftDown
== accShiftDown
) &&
116 ((eventKeyCode
== accKeyCode
|| eventKeyCode
== accKeyCode2
))) ;