1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "accel.h"
22 #define NULL ((void*)0L)
25 //-----------------------------------------------------------------------------
27 //-----------------------------------------------------------------------------
29 class wxAccelRefData
: public wxObjectRefData
38 wxAccelRefData::wxAccelRefData(void)
40 m_accels
.DeleteContents( TRUE
);
43 //-----------------------------------------------------------------------------
45 #define M_ACCELDATA ((wxAccelRefData *)m_refData)
47 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
,wxObject
)
49 wxAcceleratorTable::wxAcceleratorTable()
53 wxAcceleratorTable::wxAcceleratorTable( int n
, wxAcceleratorEntry entries
[] )
55 m_refData
= new wxAccelRefData();
57 for (int i
= 0; i
< n
; i
++)
59 int flag
= entries
[i
].GetFlags();
60 int keycode
= entries
[i
].GetKeyCode();
61 int command
= entries
[i
].GetCommand();
62 if ((keycode
>= (int)'A') && (keycode
<= (int)'Z')) keycode
= (int)tolower( (char)keycode
);
63 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
67 wxAcceleratorTable::~wxAcceleratorTable()
71 bool wxAcceleratorTable::Ok() const
73 return (m_refData
!= NULL
);
76 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
80 wxNode
*node
= M_ACCELDATA
->m_accels
.First();
83 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->Data();
84 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
85 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
86 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
87 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
89 return entry
->GetCommand();