]> git.saurik.com Git - wxWidgets.git/blame - src/osx/accel.cpp
Add wxX11EventLoopSourcesManager stub implementation to fix wxX11 linking.
[wxWidgets.git] / src / osx / accel.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
96dabe43 2// Name: src/osx/accel.cpp
489468fe
SC
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
666db5d1
VZ
14#if wxUSE_ACCEL
15
489468fe
SC
16#include "wx/accel.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/string.h"
20#endif
21
489468fe
SC
22IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
23
24// ----------------------------------------------------------------------------
25// wxAccelList: a list of wxAcceleratorEntries
26// ----------------------------------------------------------------------------
27
28WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
29#include "wx/listimpl.cpp"
30WX_DEFINE_LIST(wxAccelList)
31
32// ----------------------------------------------------------------------------
33// wxAccelRefData: the data used by wxAcceleratorTable
34// ----------------------------------------------------------------------------
35
36class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
37{
38 friend class wxAcceleratorTable;
39public:
40 wxAcceleratorRefData();
41 virtual ~wxAcceleratorRefData();
42
43 wxAccelList m_accels;
44};
45
46#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
47
48wxAcceleratorRefData::wxAcceleratorRefData()
49 : m_accels()
50{
51}
52
53wxAcceleratorRefData::~wxAcceleratorRefData()
54{
55 WX_CLEAR_LIST( wxAccelList, m_accels );
56}
57
58wxAcceleratorTable::wxAcceleratorTable()
59{
60 m_refData = NULL;
61}
62
63wxAcceleratorTable::~wxAcceleratorTable()
64{
65}
66
67// Create from an array
68wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
69{
70 m_refData = new wxAcceleratorRefData;
71
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 }
80}
81
82bool wxAcceleratorTable::IsOk() const
83{
84 return (m_refData != NULL);
85}
86
87int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
88{
a1b806b9 89 if (!IsOk()) return -1;
489468fe
SC
90
91 wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst();
92 while (node)
93 {
94 wxAcceleratorEntry *entry = node->GetData();
95 if ((event.m_keyCode == entry->GetKeyCode()) &&
df856ba9 96 (((entry->GetFlags() & wxACCEL_RAW_CTRL) != 0) == event.RawControlDown()) &&
489468fe 97 (((entry->GetFlags() & wxACCEL_SHIFT) != 0) == event.ShiftDown()) &&
03647350 98 (((entry->GetFlags() & wxACCEL_ALT) != 0) == event.AltDown()) &&
df856ba9 99 (((entry->GetFlags() & wxACCEL_CTRL) != 0) == event.ControlDown()))
489468fe
SC
100 {
101 return entry->GetCommand();
102 }
103 node = node->GetNext();
104 }
105
106 return -1;
107}
108
666db5d1 109#endif // wxUSE_ACCEL