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