]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/accel.cpp
fixed compilation bug in prior checkin
[wxWidgets.git] / src / mac / classic / accel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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/setup.h"
13 #include "wx/accel.h"
14 #include "wx/string.h"
15
16 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
17
18 // ----------------------------------------------------------------------------
19 // wxAccelList: a list of wxAcceleratorEntries
20 // ----------------------------------------------------------------------------
21
22 WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
23 #include "wx/listimpl.cpp"
24 WX_DEFINE_LIST(wxAccelList)
25
26 // ----------------------------------------------------------------------------
27 // wxAccelRefData: the data used by wxAcceleratorTable
28 // ----------------------------------------------------------------------------
29
30 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
31 {
32 friend class WXDLLEXPORT wxAcceleratorTable;
33 public:
34 wxAcceleratorRefData();
35 ~wxAcceleratorRefData();
36
37 wxAccelList m_accels;
38 };
39
40 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
41
42 wxAcceleratorRefData::wxAcceleratorRefData()
43 : m_accels()
44 {
45 }
46
47 wxAcceleratorRefData::~wxAcceleratorRefData()
48 {
49 m_accels.DeleteContents( TRUE );
50 }
51
52 wxAcceleratorTable::wxAcceleratorTable()
53 {
54 m_refData = NULL;
55 }
56
57 wxAcceleratorTable::~wxAcceleratorTable()
58 {
59 }
60
61 // Create from an array
62 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
63 {
64 m_refData = new wxAcceleratorRefData;
65
66 for (int i = 0; i < n; i++)
67 {
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 ) );
73 }
74 }
75
76 bool wxAcceleratorTable::Ok() const
77 {
78 return (m_refData != NULL);
79 }
80
81 int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
82 {
83 if (!Ok()) return -1;
84
85 wxAccelList::Node *node = M_ACCELDATA->m_accels.GetFirst();
86 while (node)
87 {
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()))
93 {
94 return entry->GetCommand();
95 }
96 node = node->GetNext();
97 }
98
99 return -1;
100 }
101
102