1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/string.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
22 // ----------------------------------------------------------------------------
23 // wxAccelList: a list of wxAcceleratorEntries
24 // ----------------------------------------------------------------------------
26 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
27 #include "wx/listimpl.cpp"
28 WX_DEFINE_LIST(wxAccelList
)
30 // ----------------------------------------------------------------------------
31 // wxAccelRefData: the data used by wxAcceleratorTable
32 // ----------------------------------------------------------------------------
34 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
36 friend class WXDLLEXPORT wxAcceleratorTable
;
38 wxAcceleratorRefData();
39 virtual ~wxAcceleratorRefData();
44 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
46 wxAcceleratorRefData::wxAcceleratorRefData()
51 wxAcceleratorRefData::~wxAcceleratorRefData()
53 WX_CLEAR_LIST( wxAccelList
, m_accels
);
56 wxAcceleratorTable::wxAcceleratorTable()
61 wxAcceleratorTable::~wxAcceleratorTable()
65 // Create from an array
66 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
68 m_refData
= new wxAcceleratorRefData
;
70 for (int i
= 0; i
< n
; i
++)
72 int flag
= entries
[i
].GetFlags();
73 int keycode
= entries
[i
].GetKeyCode();
74 int command
= entries
[i
].GetCommand();
75 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
76 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
80 bool wxAcceleratorTable::Ok() const
82 return (m_refData
!= NULL
);
85 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
89 wxAccelList::compatibility_iterator node
= M_ACCELDATA
->m_accels
.GetFirst();
92 wxAcceleratorEntry
*entry
= node
->GetData();
93 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
94 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
95 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
96 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown()) &&
97 (((entry
->GetFlags() & wxACCEL_CMD
) == 0) || event
.CmdDown()))
99 return entry
->GetCommand();
101 node
= node
->GetNext();