]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: accel.cpp | |
3 | // Purpose: wxAcceleratorTable | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
a8e9860d SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 SC |
14 | #include "wx/accel.h" |
15 | #include "wx/string.h" | |
16 | ||
e9576ca5 | 17 | IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) |
e9576ca5 | 18 | |
ffc93a32 SC |
19 | // ---------------------------------------------------------------------------- |
20 | // wxAccelList: a list of wxAcceleratorEntries | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList); | |
24 | #include "wx/listimpl.cpp" | |
25 | WX_DEFINE_LIST(wxAccelList); | |
26 | ||
27 | // ---------------------------------------------------------------------------- | |
28 | // wxAccelRefData: the data used by wxAcceleratorTable | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
e9576ca5 SC |
31 | class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData |
32 | { | |
33 | friend class WXDLLEXPORT wxAcceleratorTable; | |
34 | public: | |
35 | wxAcceleratorRefData(); | |
36 | ~wxAcceleratorRefData(); | |
37 | ||
ffc93a32 | 38 | wxAccelList m_accels; |
e9576ca5 SC |
39 | }; |
40 | ||
41 | #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) | |
42 | ||
43 | wxAcceleratorRefData::wxAcceleratorRefData() | |
d84afea9 | 44 | : m_accels() |
e9576ca5 | 45 | { |
e9576ca5 SC |
46 | } |
47 | ||
48 | wxAcceleratorRefData::~wxAcceleratorRefData() | |
49 | { | |
affd2611 | 50 | WX_CLEAR_LIST( wxAccelList, m_accels ); |
e9576ca5 SC |
51 | } |
52 | ||
53 | wxAcceleratorTable::wxAcceleratorTable() | |
54 | { | |
d84afea9 | 55 | m_refData = NULL; |
e9576ca5 SC |
56 | } |
57 | ||
58 | wxAcceleratorTable::~wxAcceleratorTable() | |
59 | { | |
60 | } | |
61 | ||
e9576ca5 | 62 | // Create from an array |
3c674514 | 63 | wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) |
e9576ca5 SC |
64 | { |
65 | m_refData = new wxAcceleratorRefData; | |
66 | ||
ffc93a32 SC |
67 | for (int i = 0; i < n; i++) |
68 | { | |
69 | int flag = entries[i].GetFlags(); | |
70 | int keycode = entries[i].GetKeyCode(); | |
71 | int command = entries[i].GetCommand(); | |
72 | if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode ); | |
73 | M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) ); | |
74 | } | |
e9576ca5 SC |
75 | } |
76 | ||
77 | bool wxAcceleratorTable::Ok() const | |
78 | { | |
ffc93a32 SC |
79 | return (m_refData != NULL); |
80 | } | |
81 | ||
82 | int wxAcceleratorTable::GetCommand( wxKeyEvent &event ) | |
83 | { | |
84 | if (!Ok()) return -1; | |
85 | ||
affd2611 | 86 | wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst(); |
ffc93a32 SC |
87 | while (node) |
88 | { | |
affd2611 | 89 | wxAcceleratorEntry *entry = node->GetData(); |
ffc93a32 SC |
90 | if ((event.m_keyCode == entry->GetKeyCode()) && |
91 | (((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) && | |
92 | (((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) && | |
93 | (((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown())) | |
94 | { | |
95 | return entry->GetCommand(); | |
96 | } | |
eb22f2a6 | 97 | node = node->GetNext(); |
ffc93a32 SC |
98 | } |
99 | ||
100 | return -1; | |
e9576ca5 SC |
101 | } |
102 | ||
ffc93a32 | 103 |