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 wxAcceleratorTable
;
30 wxAcceleratorRefData();
31 virtual ~wxAcceleratorRefData();
35 wxAcceleratorEntry
* m_entries
;
38 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
40 wxAcceleratorRefData::wxAcceleratorRefData()
46 wxAcceleratorRefData::~wxAcceleratorRefData()
52 wxAcceleratorTable::wxAcceleratorTable()
57 wxAcceleratorTable::~wxAcceleratorTable()
59 // Data deleted in ~wxObject
62 // Load from .rc resource
63 wxAcceleratorTable::wxAcceleratorTable(const wxString
& WXUNUSED(resource
))
65 m_refData
= new wxAcceleratorRefData
;
68 // Create from an array
69 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
71 wxAcceleratorRefData
* data
= new wxAcceleratorRefData
;
75 data
->m_entries
= new wxAcceleratorEntry
[n
];
77 for (i
= 0; i
< n
; i
++)
78 data
->m_entries
[i
] = entries
[i
];
82 bool wxAcceleratorTable::IsOk() const
84 return (m_refData
!= NULL
);
87 int wxAcceleratorTable::GetCount() const
89 return M_ACCELDATA
->m_count
;
92 wxAcceleratorEntry
* wxAcceleratorTable::GetEntries() const
94 return M_ACCELDATA
->m_entries
;
97 // Implementation use only
98 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent
& event
) const
100 bool eventAltDown
= event
.AltDown();
101 bool eventCtrlDown
= event
.ControlDown();
102 bool eventShiftDown
= event
.ShiftDown();
103 int eventKeyCode
= event
.GetKeyCode();
105 bool accAltDown
= ((GetFlags() & wxACCEL_ALT
) == wxACCEL_ALT
);
106 bool accCtrlDown
= ((GetFlags() & wxACCEL_CTRL
) == wxACCEL_CTRL
);
107 bool accShiftDown
= ((GetFlags() & wxACCEL_SHIFT
) == wxACCEL_SHIFT
);
108 int accKeyCode
= GetKeyCode();
109 int accKeyCode2
= GetKeyCode();
110 if (wxIsascii(accKeyCode2
))
111 accKeyCode2
= wxTolower(accKeyCode2
);
113 return ((eventAltDown
== accAltDown
) && (eventCtrlDown
== accCtrlDown
) &&
114 (eventShiftDown
== accShiftDown
) &&
115 ((eventKeyCode
== accKeyCode
|| eventKeyCode
== accKeyCode2
))) ;