1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
19 #include "wx/string.h"
22 #ifndef __WXUNIVERSAL__
24 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
26 // ----------------------------------------------------------------------------
27 // wxAccelList: a list of wxAcceleratorEntries
28 // ----------------------------------------------------------------------------
30 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
31 #include "wx/listimpl.cpp"
32 WX_DEFINE_LIST(wxAccelList
)
34 // ----------------------------------------------------------------------------
35 // wxAccelRefData: the data used by wxAcceleratorTable
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
40 friend class wxAcceleratorTable
;
42 wxAcceleratorRefData();
43 virtual ~wxAcceleratorRefData();
48 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
50 wxAcceleratorRefData
::wxAcceleratorRefData()
55 wxAcceleratorRefData
::~wxAcceleratorRefData()
57 WX_CLEAR_LIST( wxAccelList
, m_accels
);
60 wxAcceleratorTable
::wxAcceleratorTable()
65 wxAcceleratorTable
::~wxAcceleratorTable()
69 // Create from an array
70 wxAcceleratorTable
::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
72 m_refData
= new wxAcceleratorRefData
;
74 for (int i
= 0; i
< n
; i
++)
76 int flag
= entries
[i
].GetFlags();
77 int keycode
= entries
[i
].GetKeyCode();
78 int command
= entries
[i
].GetCommand();
79 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
80 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
84 bool wxAcceleratorTable
::IsOk() const
86 return (m_refData
!= NULL
);
89 int wxAcceleratorTable
::GetCommand( wxKeyEvent
&event
)
93 wxAccelList
::compatibility_iterator node
= M_ACCELDATA
->m_accels
.GetFirst();
96 wxAcceleratorEntry
*entry
= node
->GetData();
97 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
98 (((entry
->GetFlags() & wxACCEL_CTRL
) != 0) == event
.ControlDown()) &&
99 (((entry
->GetFlags() & wxACCEL_SHIFT
) != 0) == event
.ShiftDown()) &&
100 (((entry
->GetFlags() & wxACCEL_ALT
) != 0) == event
.AltDown()) &&
101 (((entry
->GetFlags() & wxACCEL_CMD
) != 0) == event
.CmdDown()))
103 return entry
->GetCommand();
105 node
= node
->GetNext();
113 #endif // wxUSE_ACCEL