1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "accel.h"
18 #include "wx/string.h"
20 #if !USE_SHARED_LIBRARIES
21 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
24 // ----------------------------------------------------------------------------
25 // wxAccelList: a list of wxAcceleratorEntries
26 // ----------------------------------------------------------------------------
28 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
29 #include "wx/listimpl.cpp"
30 WX_DEFINE_LIST(wxAccelList
);
32 // ----------------------------------------------------------------------------
33 // wxAccelRefData: the data used by wxAcceleratorTable
34 // ----------------------------------------------------------------------------
36 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
38 friend class WXDLLEXPORT wxAcceleratorTable
;
40 wxAcceleratorRefData();
41 ~wxAcceleratorRefData();
46 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
48 wxAcceleratorRefData::wxAcceleratorRefData()
53 wxAcceleratorRefData::~wxAcceleratorRefData()
55 m_accels
.DeleteContents( TRUE
);
58 wxAcceleratorTable::wxAcceleratorTable()
63 wxAcceleratorTable::~wxAcceleratorTable()
67 // Create from an array
68 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
70 m_refData
= new wxAcceleratorRefData
;
72 for (int i
= 0; i
< n
; i
++)
74 int flag
= entries
[i
].GetFlags();
75 int keycode
= entries
[i
].GetKeyCode();
76 int command
= entries
[i
].GetCommand();
77 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
78 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
82 bool wxAcceleratorTable::Ok() const
84 return (m_refData
!= NULL
);
87 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
91 wxNode
*node
= M_ACCELDATA
->m_accels
.First();
94 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->Data();
95 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
96 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
97 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
98 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
100 return entry
->GetCommand();