]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/accel.cpp
New event locking.
[wxWidgets.git] / src / gtk1 / accel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: accel.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $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
16 #if wxUSE_ACCEL
17
18 #include <ctype.h>
19
20 //-----------------------------------------------------------------------------
21 // wxAcceleratorTable
22 //-----------------------------------------------------------------------------
23
24 class wxAccelRefData: public wxObjectRefData
25 {
26 public:
27 wxAccelRefData();
28
29 wxList m_accels;
30 };
31
32 wxAccelRefData::wxAccelRefData()
33 {
34 m_accels.DeleteContents( TRUE );
35 }
36
37 //-----------------------------------------------------------------------------
38
39 #define M_ACCELDATA ((wxAccelRefData *)m_refData)
40
41 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable,wxObject)
42
43 wxAcceleratorTable::wxAcceleratorTable()
44 {
45 }
46
47 wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] )
48 {
49 m_refData = new wxAccelRefData();
50
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 }
59 }
60
61 wxAcceleratorTable::~wxAcceleratorTable()
62 {
63 }
64
65 bool wxAcceleratorTable::Ok() const
66 {
67 return (m_refData != NULL);
68 }
69
70 int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
71 {
72 if (!Ok()) return -1;
73
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()))
82 {
83 return entry->GetCommand();
84 }
85 node = node->Next();
86 }
87
88 return -1;
89 }
90
91 #endif