]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/accel.cpp
Added wxMenu::UpdateUI to wxMSW, wxGTK, wxMotif, wxStubs; rearranged/debugged
[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 #include <ctype.h>
17
18 #ifdef __WXDEBUG__
19 #ifdef NULL
20 #undef NULL
21 #endif
22 #define NULL ((void*)0L)
23 #endif
24
25 //-----------------------------------------------------------------------------
26 // wxAcceleratorTable
27 //-----------------------------------------------------------------------------
28
29 class wxAccelRefData: public wxObjectRefData
30 {
31 public:
32
33 wxAccelRefData(void);
34
35 wxList m_accels;
36 };
37
38 wxAccelRefData::wxAccelRefData(void)
39 {
40 m_accels.DeleteContents( TRUE );
41 }
42
43 //-----------------------------------------------------------------------------
44
45 #define M_ACCELDATA ((wxAccelRefData *)m_refData)
46
47 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable,wxObject)
48
49 wxAcceleratorTable::wxAcceleratorTable()
50 {
51 }
52
53 wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] )
54 {
55 m_refData = new wxAccelRefData();
56
57 for (int i = 0; i < n; i++)
58 {
59 int flag = entries[i].GetFlags();
60 int keycode = entries[i].GetKeyCode();
61 int command = entries[i].GetCommand();
62 if ((keycode >= (int)'A') && (keycode <= (int)'Z')) keycode = (int)tolower( (char)keycode );
63 M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
64 }
65 }
66
67 wxAcceleratorTable::~wxAcceleratorTable()
68 {
69 }
70
71 bool wxAcceleratorTable::Ok() const
72 {
73 return (m_refData != NULL);
74 }
75
76 int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
77 {
78 if (!Ok()) return -1;
79
80 wxNode *node = M_ACCELDATA->m_accels.First();
81 while (node)
82 {
83 wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->Data();
84 if ((event.m_keyCode == entry->GetKeyCode()) &&
85 (((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
86 (((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
87 (((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown()))
88 {
89 return entry->GetCommand();
90 }
91 node = node->Next();
92 }
93
94 return -1;
95 }
96