1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/string.h"
17 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
19 // ----------------------------------------------------------------------------
20 // wxAccelList: a list of wxAcceleratorEntries
21 // ----------------------------------------------------------------------------
23 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
24 #include "wx/listimpl.cpp"
25 WX_DEFINE_LIST(wxAccelList
)
27 // ----------------------------------------------------------------------------
28 // wxAccelRefData: the data used by wxAcceleratorTable
29 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
33 friend class WXDLLEXPORT wxAcceleratorTable
;
35 wxAcceleratorRefData();
36 ~wxAcceleratorRefData();
41 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
43 wxAcceleratorRefData::wxAcceleratorRefData()
48 wxAcceleratorRefData::~wxAcceleratorRefData()
50 WX_CLEAR_LIST( wxAccelList
, m_accels
);
53 wxAcceleratorTable::wxAcceleratorTable()
58 wxAcceleratorTable::~wxAcceleratorTable()
62 // Create from an array
63 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
65 m_refData
= new wxAcceleratorRefData
;
67 for (int i
= 0; i
< n
; i
++)
69 int flag
= entries
[i
].GetFlags();
70 int keycode
= entries
[i
].GetKeyCode();
71 int command
= entries
[i
].GetCommand();
72 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
73 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
77 bool wxAcceleratorTable::Ok() const
79 return (m_refData
!= NULL
);
82 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
86 wxAccelList::compatibility_iterator node
= M_ACCELDATA
->m_accels
.GetFirst();
89 wxAcceleratorEntry
*entry
= node
->GetData();
90 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
91 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
92 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
93 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
95 return entry
->GetCommand();
97 node
= node
->GetNext();