1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/string.h"
16 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
18 // ----------------------------------------------------------------------------
19 // wxAccelList: a list of wxAcceleratorEntries
20 // ----------------------------------------------------------------------------
22 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
23 #include "wx/listimpl.cpp"
24 WX_DEFINE_LIST(wxAccelList
)
26 // ----------------------------------------------------------------------------
27 // wxAccelRefData: the data used by wxAcceleratorTable
28 // ----------------------------------------------------------------------------
30 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
32 friend class WXDLLEXPORT wxAcceleratorTable
;
34 wxAcceleratorRefData();
35 ~wxAcceleratorRefData();
40 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
42 wxAcceleratorRefData::wxAcceleratorRefData()
47 wxAcceleratorRefData::~wxAcceleratorRefData()
49 m_accels
.DeleteContents( TRUE
);
52 wxAcceleratorTable::wxAcceleratorTable()
57 wxAcceleratorTable::~wxAcceleratorTable()
61 // Create from an array
62 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
64 m_refData
= new wxAcceleratorRefData
;
66 for (int i
= 0; i
< n
; i
++)
68 int flag
= entries
[i
].GetFlags();
69 int keycode
= entries
[i
].GetKeyCode();
70 int command
= entries
[i
].GetCommand();
71 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
72 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
76 bool wxAcceleratorTable::Ok() const
78 return (m_refData
!= NULL
);
81 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
85 wxAccelList::Node
*node
= M_ACCELDATA
->m_accels
.GetFirst();
88 wxAcceleratorEntry
*entry
= (wxAcceleratorEntry
*)node
->GetData();
89 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
90 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
91 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
92 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
94 return entry
->GetCommand();
96 node
= node
->GetNext();