]>
Commit | Line | Data |
---|---|---|
bcf1fa6b RR |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: accel.cpp | |
3 | // Purpose: | |
4 | // Author: Robert Roebling | |
32e9da8b | 5 | // Id: $id$ |
bcf1fa6b RR |
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 | ||
22 | class wxAccelRefData: public wxObjectRefData | |
23 | { | |
ec758a20 | 24 | public: |
bcf1fa6b | 25 | |
ec758a20 | 26 | wxAccelRefData(void); |
bcf1fa6b | 27 | |
ec758a20 | 28 | wxList m_accels; |
bcf1fa6b RR |
29 | }; |
30 | ||
31 | wxAccelRefData::wxAccelRefData(void) | |
32 | { | |
ec758a20 | 33 | m_accels.DeleteContents( TRUE ); |
bcf1fa6b RR |
34 | } |
35 | ||
36 | //----------------------------------------------------------------------------- | |
37 | ||
38 | #define M_ACCELDATA ((wxAccelRefData *)m_refData) | |
39 | ||
40 | IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable,wxObject) | |
41 | ||
42 | wxAcceleratorTable::wxAcceleratorTable() | |
43 | { | |
bcf1fa6b RR |
44 | } |
45 | ||
46 | wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] ) | |
47 | { | |
ec758a20 RR |
48 | m_refData = new wxAccelRefData(); |
49 | ||
50 | for (int i = 0; i < n; i++) | |
51 | { | |
52 | int flag = entries[i].GetFlags(); | |
53 | int keycode = entries[i].GetKeyCode(); | |
54 | int command = entries[i].GetCommand(); | |
55 | if ((keycode >= (int)'A') && (keycode <= (int)'Z')) keycode = (int)tolower( (char)keycode ); | |
56 | M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) ); | |
57 | } | |
bcf1fa6b RR |
58 | } |
59 | ||
60 | wxAcceleratorTable::~wxAcceleratorTable() | |
61 | { | |
62 | } | |
63 | ||
64 | bool wxAcceleratorTable::Ok() const | |
65 | { | |
ec758a20 | 66 | return (m_refData != NULL); |
bcf1fa6b RR |
67 | } |
68 | ||
69 | int wxAcceleratorTable::GetCommand( wxKeyEvent &event ) | |
70 | { | |
ec758a20 | 71 | if (!Ok()) return -1; |
e55ad60e | 72 | |
ec758a20 RR |
73 | wxNode *node = M_ACCELDATA->m_accels.First(); |
74 | while (node) | |
75 | { | |
76 | wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->Data(); | |
77 | if ((event.m_keyCode == entry->GetKeyCode()) && | |
78 | (((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) && | |
79 | (((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) && | |
80 | (((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown())) | |
81 | { | |
82 | return entry->GetCommand(); | |
83 | } | |
84 | node = node->Next(); | |
85 | } | |
bcf1fa6b | 86 | |
ec758a20 | 87 | return -1; |
bcf1fa6b RR |
88 | } |
89 |