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