]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/accel.cpp
fixed (rare but fatal) bug in wxWindowDisabler
[wxWidgets.git] / src / gtk1 / accel.cpp
CommitLineData
bcf1fa6b
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: accel.cpp
3// Purpose:
4// Author: Robert Roebling
dcf924a3 5// Id: $id:$
bcf1fa6b 6// Copyright: (c) 1998 Robert Roebling
e90c1d2a 7// Licence: wxWindows licence
bcf1fa6b
RR
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "accel.h"
12#endif
13
14#include "wx/accel.h"
15
dcf924a3 16#if wxUSE_ACCEL
66c135f3 17
dcf924a3 18#include <ctype.h>
bbe0af5b 19
bcf1fa6b
RR
20//-----------------------------------------------------------------------------
21// wxAcceleratorTable
22//-----------------------------------------------------------------------------
23
24class wxAccelRefData: public wxObjectRefData
25{
ec758a20 26public:
f2593d0d 27 wxAccelRefData();
e90c1d2a 28
f2593d0d 29 wxList m_accels;
bcf1fa6b
RR
30};
31
e90c1d2a 32wxAccelRefData::wxAccelRefData()
bcf1fa6b 33{
ec758a20 34 m_accels.DeleteContents( TRUE );
bcf1fa6b
RR
35}
36
37//-----------------------------------------------------------------------------
38
39#define M_ACCELDATA ((wxAccelRefData *)m_refData)
40
41IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable,wxObject)
e90c1d2a 42
bcf1fa6b
RR
43wxAcceleratorTable::wxAcceleratorTable()
44{
bcf1fa6b
RR
45}
46
47wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] )
48{
ec758a20 49 m_refData = new wxAccelRefData();
e90c1d2a 50
ec758a20
RR
51 for (int i = 0; i < n; i++)
52 {
53 int flag = entries[i].GetFlags();
54 int keycode = entries[i].GetKeyCode();
55 int command = entries[i].GetCommand();
56 if ((keycode >= (int)'A') && (keycode <= (int)'Z')) keycode = (int)tolower( (char)keycode );
57 M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
58 }
bcf1fa6b
RR
59}
60
61wxAcceleratorTable::~wxAcceleratorTable()
62{
63}
64
65bool wxAcceleratorTable::Ok() const
66{
ec758a20 67 return (m_refData != NULL);
bcf1fa6b
RR
68}
69
70int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
71{
ec758a20 72 if (!Ok()) return -1;
e55ad60e 73
ec758a20
RR
74 wxNode *node = M_ACCELDATA->m_accels.First();
75 while (node)
76 {
77 wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->Data();
78 if ((event.m_keyCode == entry->GetKeyCode()) &&
79 (((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
80 (((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
81 (((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown()))
e90c1d2a 82 {
ec758a20 83 return entry->GetCommand();
e90c1d2a 84 }
ec758a20
RR
85 node = node->Next();
86 }
e90c1d2a 87
ec758a20 88 return -1;
bcf1fa6b
RR
89}
90
dcf924a3 91#endif