]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/accel.cpp
switching to autorelease
[wxWidgets.git] / src / mac / carbon / accel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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 #include "wx/accel.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/string.h"
18 #endif
19
20 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
21
22 // ----------------------------------------------------------------------------
23 // wxAccelList: a list of wxAcceleratorEntries
24 // ----------------------------------------------------------------------------
25
26 WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
27 #include "wx/listimpl.cpp"
28 WX_DEFINE_LIST(wxAccelList)
29
30 // ----------------------------------------------------------------------------
31 // wxAccelRefData: the data used by wxAcceleratorTable
32 // ----------------------------------------------------------------------------
33
34 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
35 {
36 friend class WXDLLEXPORT wxAcceleratorTable;
37 public:
38 wxAcceleratorRefData();
39 virtual ~wxAcceleratorRefData();
40
41 wxAccelList m_accels;
42 };
43
44 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
45
46 wxAcceleratorRefData::wxAcceleratorRefData()
47 : m_accels()
48 {
49 }
50
51 wxAcceleratorRefData::~wxAcceleratorRefData()
52 {
53 WX_CLEAR_LIST( wxAccelList, m_accels );
54 }
55
56 wxAcceleratorTable::wxAcceleratorTable()
57 {
58 m_refData = NULL;
59 }
60
61 wxAcceleratorTable::~wxAcceleratorTable()
62 {
63 }
64
65 // Create from an array
66 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
67 {
68 m_refData = new wxAcceleratorRefData;
69
70 for (int i = 0; i < n; i++)
71 {
72 int flag = entries[i].GetFlags();
73 int keycode = entries[i].GetKeyCode();
74 int command = entries[i].GetCommand();
75 if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode );
76 M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
77 }
78 }
79
80 bool wxAcceleratorTable::IsOk() const
81 {
82 return (m_refData != NULL);
83 }
84
85 int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
86 {
87 if (!Ok()) return -1;
88
89 wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst();
90 while (node)
91 {
92 wxAcceleratorEntry *entry = node->GetData();
93 if ((event.m_keyCode == entry->GetKeyCode()) &&
94 (((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
95 (((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
96 (((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown()) &&
97 (((entry->GetFlags() & wxACCEL_CMD) == 0) || event.CmdDown()))
98 {
99 return entry->GetCommand();
100 }
101 node = node->GetNext();
102 }
103
104 return -1;
105 }