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