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