1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/motif/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
17 #include "wx/string.h"
23 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
25 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
27 friend class wxAcceleratorTable
;
29 wxAcceleratorRefData();
30 virtual ~wxAcceleratorRefData();
34 wxAcceleratorEntry
* m_entries
;
37 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
39 wxAcceleratorRefData::wxAcceleratorRefData()
45 wxAcceleratorRefData::~wxAcceleratorRefData()
51 wxAcceleratorTable::wxAcceleratorTable()
56 wxAcceleratorTable::~wxAcceleratorTable()
58 // Data deleted in ~wxObject
61 // Load from .rc resource
62 wxAcceleratorTable::wxAcceleratorTable(const wxString
& WXUNUSED(resource
))
64 m_refData
= new wxAcceleratorRefData
;
67 // Create from an array
68 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
70 wxAcceleratorRefData
* data
= new wxAcceleratorRefData
;
74 data
->m_entries
= new wxAcceleratorEntry
[n
];
76 for (i
= 0; i
< n
; i
++)
77 data
->m_entries
[i
] = entries
[i
];
81 bool wxAcceleratorTable::IsOk() const
83 return (m_refData
!= NULL
);
86 int wxAcceleratorTable::GetCount() const
88 return M_ACCELDATA
->m_count
;
91 wxAcceleratorEntry
* wxAcceleratorTable::GetEntries() const
93 return M_ACCELDATA
->m_entries
;
96 // Implementation use only
97 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent
& event
) const
99 bool eventAltDown
= event
.AltDown();
100 bool eventCtrlDown
= event
.ControlDown();
101 bool eventShiftDown
= event
.ShiftDown();
102 int eventKeyCode
= event
.GetKeyCode();
104 bool accAltDown
= ((GetFlags() & wxACCEL_ALT
) == wxACCEL_ALT
);
105 bool accCtrlDown
= ((GetFlags() & wxACCEL_CTRL
) == wxACCEL_CTRL
);
106 bool accShiftDown
= ((GetFlags() & wxACCEL_SHIFT
) == wxACCEL_SHIFT
);
107 int accKeyCode
= GetKeyCode();
108 int accKeyCode2
= GetKeyCode();
109 if (wxIsascii(accKeyCode2
))
110 accKeyCode2
= wxTolower(accKeyCode2
);
112 return ((eventAltDown
== accAltDown
) && (eventCtrlDown
== accCtrlDown
) &&
113 (eventShiftDown
== accShiftDown
) &&
114 ((eventKeyCode
== accKeyCode
|| eventKeyCode
== accKeyCode2
))) ;