Added wxUSE_ACCEL guard.
[wxWidgets.git] / src / osx / accel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_ACCEL
15
16 #include "wx/accel.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/string.h"
20 #endif
21
22 #ifndef __WXUNIVERSAL__
23
24 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
25
26 // ----------------------------------------------------------------------------
27 // wxAccelList: a list of wxAcceleratorEntries
28 // ----------------------------------------------------------------------------
29
30 WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
31 #include "wx/listimpl.cpp"
32 WX_DEFINE_LIST(wxAccelList)
33
34 // ----------------------------------------------------------------------------
35 // wxAccelRefData: the data used by wxAcceleratorTable
36 // ----------------------------------------------------------------------------
37
38 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
39 {
40 friend class wxAcceleratorTable;
41 public:
42 wxAcceleratorRefData();
43 virtual ~wxAcceleratorRefData();
44
45 wxAccelList m_accels;
46 };
47
48 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
49
50 wxAcceleratorRefData::wxAcceleratorRefData()
51 : m_accels()
52 {
53 }
54
55 wxAcceleratorRefData::~wxAcceleratorRefData()
56 {
57 WX_CLEAR_LIST( wxAccelList, m_accels );
58 }
59
60 wxAcceleratorTable::wxAcceleratorTable()
61 {
62 m_refData = NULL;
63 }
64
65 wxAcceleratorTable::~wxAcceleratorTable()
66 {
67 }
68
69 // Create from an array
70 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
71 {
72 m_refData = new wxAcceleratorRefData;
73
74 for (int i = 0; i < n; i++)
75 {
76 int flag = entries[i].GetFlags();
77 int keycode = entries[i].GetKeyCode();
78 int command = entries[i].GetCommand();
79 if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode );
80 M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
81 }
82 }
83
84 bool wxAcceleratorTable::IsOk() const
85 {
86 return (m_refData != NULL);
87 }
88
89 int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
90 {
91 if (!Ok()) return -1;
92
93 wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst();
94 while (node)
95 {
96 wxAcceleratorEntry *entry = node->GetData();
97 if ((event.m_keyCode == entry->GetKeyCode()) &&
98 (((entry->GetFlags() & wxACCEL_CTRL) != 0) == event.ControlDown()) &&
99 (((entry->GetFlags() & wxACCEL_SHIFT) != 0) == event.ShiftDown()) &&
100 (((entry->GetFlags() & wxACCEL_ALT) != 0) == event.AltDown()) &&
101 (((entry->GetFlags() & wxACCEL_CMD) != 0) == event.CmdDown()))
102 {
103 return entry->GetCommand();
104 }
105 node = node->GetNext();
106 }
107
108 return -1;
109 }
110
111 #endif
112
113 #endif // wxUSE_ACCEL