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