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
32 wxAccelRefData::wxAccelRefData()
34 m_accels
.DeleteContents( TRUE
);
37 //-----------------------------------------------------------------------------
39 #define M_ACCELDATA ((wxAccelRefData *)m_refData)
41 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
,wxObject
)
43 wxAcceleratorTable::wxAcceleratorTable()
47 wxAcceleratorTable::wxAcceleratorTable( int n
, wxAcceleratorEntry entries
[] )
49 m_refData
= new wxAccelRefData();
51 for (int i
= 0; i
< n
; i
++)
53 int flag
= entries
[i
].GetFlags();
54 int keycode
= entries
[i
].GetKeyCode();
55 int command
= entries
[i
].GetCommand();
56 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
57 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
61 wxAcceleratorTable::~wxAcceleratorTable()
65 bool wxAcceleratorTable::Ok() const
67 return (m_refData
!= NULL
);
70 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
74 wxNode
*node
= M_ACCELDATA
->m_accels
.First();
77 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->Data();
78 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
79 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
80 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
81 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
83 return entry
->GetCommand();