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