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