]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/accel.cpp
Add wx.ListBox.HitTest
[wxWidgets.git] / src / mac / classic / accel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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
17 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
18
19 // ----------------------------------------------------------------------------
20 // wxAccelList: a list of wxAcceleratorEntries
21 // ----------------------------------------------------------------------------
22
23 WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
24 #include "wx/listimpl.cpp"
25 WX_DEFINE_LIST(wxAccelList)
26
27 // ----------------------------------------------------------------------------
28 // wxAccelRefData: the data used by wxAcceleratorTable
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
32 {
33 friend class WXDLLEXPORT wxAcceleratorTable;
34 public:
35 wxAcceleratorRefData();
36 ~wxAcceleratorRefData();
37
38 wxAccelList m_accels;
39 };
40
41 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
42
43 wxAcceleratorRefData::wxAcceleratorRefData()
44 : m_accels()
45 {
46 }
47
48 wxAcceleratorRefData::~wxAcceleratorRefData()
49 {
50 m_accels.DeleteContents( TRUE );
51 }
52
53 wxAcceleratorTable::wxAcceleratorTable()
54 {
55 m_refData = NULL;
56 }
57
58 wxAcceleratorTable::~wxAcceleratorTable()
59 {
60 }
61
62 // Create from an array
63 wxAcceleratorTable::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
77 bool wxAcceleratorTable::Ok() const
78 {
79 return (m_refData != NULL);
80 }
81
82 int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
83 {
84 if (!Ok()) return -1;
85
86 wxAccelList::Node *node = M_ACCELDATA->m_accels.GetFirst();
87 while (node)
88 {
89 wxAcceleratorEntry *entry = (wxAcceleratorEntry*)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 }