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