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