1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
18 #include "wx/string.h"
21 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
23 // ----------------------------------------------------------------------------
24 // wxAccelList: a list of wxAcceleratorEntries
25 // ----------------------------------------------------------------------------
27 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
);
28 #include "wx/listimpl.cpp"
29 WX_DEFINE_LIST(wxAccelList
)
31 // ----------------------------------------------------------------------------
32 // wxAccelRefData: the data used by wxAcceleratorTable
33 // ----------------------------------------------------------------------------
35 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
37 friend class wxAcceleratorTable
;
39 wxAcceleratorRefData();
40 virtual ~wxAcceleratorRefData();
45 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
47 wxAcceleratorRefData::wxAcceleratorRefData()
52 wxAcceleratorRefData::~wxAcceleratorRefData()
54 WX_CLEAR_LIST( wxAccelList
, m_accels
);
57 wxAcceleratorTable::wxAcceleratorTable()
62 wxAcceleratorTable::~wxAcceleratorTable()
66 // Create from an array
67 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
69 m_refData
= new wxAcceleratorRefData
;
71 for (int i
= 0; i
< n
; i
++)
73 int flag
= entries
[i
].GetFlags();
74 int keycode
= entries
[i
].GetKeyCode();
75 int command
= entries
[i
].GetCommand();
76 if ((keycode
>= (int)'a') && (keycode
<= (int)'z')) keycode
= (int)toupper( (char)keycode
);
77 M_ACCELDATA
->m_accels
.Append( new wxAcceleratorEntry( flag
, keycode
, command
) );
81 bool wxAcceleratorTable::IsOk() const
83 return (m_refData
!= NULL
);
86 int wxAcceleratorTable::GetCommand( wxKeyEvent
&event
)
88 if (!IsOk()) return -1;
90 wxAccelList::compatibility_iterator node
= M_ACCELDATA
->m_accels
.GetFirst();
93 wxAcceleratorEntry
*entry
= node
->GetData();
94 if ((event
.m_keyCode
== entry
->GetKeyCode()) &&
95 (((entry
->GetFlags() & wxACCEL_RAW_CTRL
) != 0) == event
.RawControlDown()) &&
96 (((entry
->GetFlags() & wxACCEL_SHIFT
) != 0) == event
.ShiftDown()) &&
97 (((entry
->GetFlags() & wxACCEL_ALT
) != 0) == event
.AltDown()) &&
98 (((entry
->GetFlags() & wxACCEL_CTRL
) != 0) == event
.ControlDown()))
100 return entry
->GetCommand();
102 node
= node
->GetNext();
108 #endif // wxUSE_ACCEL