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