1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "accel.h"
16 #include "wx/wxprec.h"
19 #include "wx/string.h"
21 #if !USE_SHARED_LIBRARIES
22 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
25 // ----------------------------------------------------------------------------
26 // wxAccelList: a list of wxAcceleratorEntries
27 // ----------------------------------------------------------------------------
29 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
30 #include "wx/listimpl.cpp"
31 WX_DEFINE_LIST(wxAccelList
);
33 // ----------------------------------------------------------------------------
34 // wxAccelRefData: the data used by wxAcceleratorTable
35 // ----------------------------------------------------------------------------
37 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
39 friend class WXDLLEXPORT wxAcceleratorTable
;
41 wxAcceleratorRefData();
42 ~wxAcceleratorRefData();
47 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
49 wxAcceleratorRefData::wxAcceleratorRefData()
54 wxAcceleratorRefData::~wxAcceleratorRefData()
56 WX_CLEAR_LIST( wxAccelList
, m_accels
);
59 wxAcceleratorTable::wxAcceleratorTable()
64 wxAcceleratorTable::~wxAcceleratorTable()
68 // Create from an array
69 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
71 m_refData
= new wxAcceleratorRefData
;
73 for (int i
= 0; i
< n
; i
++)
75 int flag
= entries
[i
].GetFlags();
76 int keycode
= entries
[i
].GetKeyCode();
77 int command
= entries
[i
].GetCommand();
78 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
79 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
83 bool wxAcceleratorTable::Ok() const
85 return (m_refData
!= NULL
);
88 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
92 wxAccelList::compatibility_iterator node
= M_ACCELDATA
->m_accels
.GetFirst();
95 wxAcceleratorEntry
*entry
= node
->GetData();
96 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
97 (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) &&
98 (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) &&
99 (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown()))
101 return entry
->GetCommand();
103 node
= node
->GetNext();