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
27 ~wxAccelRefData(void);
32 wxAccelRefData::wxAccelRefData(void)
36 wxAccelRefData::~wxAccelRefData(void)
38 wxNode
*node
= m_accels
.First();
41 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->Data();
47 //-----------------------------------------------------------------------------
49 #define M_ACCELDATA ((wxAccelRefData *)m_refData)
51 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
,wxObject
)
53 wxAcceleratorTable::wxAcceleratorTable()
55 m_refData
= new wxAccelRefData();
58 wxAcceleratorTable::wxAcceleratorTable( int n
, wxAcceleratorEntry entries
[] )
60 m_refData
= new wxAccelRefData();
61 for (int i
= 0; i
< n
; i
++)
63 int flag
= entries
[i
].GetFlags();
64 int keycode
= entries
[i
].GetKeyCode();
65 int command
= entries
[i
].GetCommand();
66 if ((keycode
>= (int)'A') && (keycode
<= (int)'Z')) keycode
= (int)tolower( (char)keycode
);
67 M_ACCELDATA
->m_accels
.Append( (wxObject
*) new wxAcceleratorEntry( flag
, keycode
, command
) );
71 wxAcceleratorTable::~wxAcceleratorTable()
75 bool wxAcceleratorTable::Ok() const
77 return (m_refData
!= NULL
);
80 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
82 wxNode
*node
= M_ACCELDATA
->m_accels
.First();
85 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->Data();
86 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
87 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
88 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
89 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
90 return entry
->GetCommand();