1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "accel.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 class wxAccelRefData
: public wxObjectRefData
31 wxAccelRefData::wxAccelRefData(void)
33 m_accels
.DeleteContents( TRUE
);
36 //-----------------------------------------------------------------------------
38 #define M_ACCELDATA ((wxAccelRefData *)m_refData)
40 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
,wxObject
)
42 wxAcceleratorTable::wxAcceleratorTable()
46 wxAcceleratorTable::wxAcceleratorTable( int n
, wxAcceleratorEntry entries
[] )
48 m_refData
= new wxAccelRefData();
50 for (int i
= 0; i
< n
; i
++)
52 int flag
= entries
[i
].GetFlags();
53 int keycode
= entries
[i
].GetKeyCode();
54 int command
= entries
[i
].GetCommand();
55 if ((keycode
>= (int)'A') && (keycode
<= (int)'Z')) keycode
= (int)tolower( (char)keycode
);
56 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
60 wxAcceleratorTable::~wxAcceleratorTable()
64 bool wxAcceleratorTable::Ok() const
66 return (m_refData
!= NULL
);
69 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
73 wxNode
*node
= M_ACCELDATA
->m_accels
.First();
76 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->Data();
77 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
78 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
79 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
80 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
82 return entry
->GetCommand();