]>
Commit | Line | Data |
---|---|---|
4bb6408c | 1 | ///////////////////////////////////////////////////////////////////////////// |
55034339 | 2 | // Name: src/motif/accel.cpp |
4bb6408c JS |
3 | // Purpose: wxAcceleratorTable |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
65571936 | 9 | // Licence: wxWindows licence |
4bb6408c JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
1248b41f MB |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
4bb6408c | 15 | #include "wx/accel.h" |
df91131c WS |
16 | |
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/string.h" | |
de6185e2 | 19 | #include "wx/utils.h" |
df91131c WS |
20 | #endif |
21 | ||
8aa04e8b | 22 | #include <ctype.h> |
4bb6408c | 23 | |
4bb6408c | 24 | IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) |
4bb6408c JS |
25 | |
26 | class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData | |
27 | { | |
28 | friend class WXDLLEXPORT wxAcceleratorTable; | |
29 | public: | |
30 | wxAcceleratorRefData(); | |
d3c7fc99 | 31 | virtual ~wxAcceleratorRefData(); |
0fb67cd1 | 32 | |
8aa04e8b JS |
33 | public: |
34 | int m_count; | |
35 | wxAcceleratorEntry* m_entries; | |
4bb6408c JS |
36 | }; |
37 | ||
38 | #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) | |
39 | ||
40 | wxAcceleratorRefData::wxAcceleratorRefData() | |
41 | { | |
8aa04e8b JS |
42 | m_count = 0; |
43 | m_entries = (wxAcceleratorEntry*) NULL; | |
4bb6408c JS |
44 | } |
45 | ||
46 | wxAcceleratorRefData::~wxAcceleratorRefData() | |
47 | { | |
8aa04e8b JS |
48 | delete[] m_entries; |
49 | m_entries = (wxAcceleratorEntry*) NULL; | |
50 | m_count = 0; | |
4bb6408c JS |
51 | } |
52 | ||
53 | wxAcceleratorTable::wxAcceleratorTable() | |
54 | { | |
8aa04e8b | 55 | m_refData = (wxAcceleratorRefData*) NULL; |
4bb6408c JS |
56 | } |
57 | ||
58 | wxAcceleratorTable::~wxAcceleratorTable() | |
59 | { | |
8aa04e8b | 60 | // Data deleted in ~wxObject |
4bb6408c JS |
61 | } |
62 | ||
63 | // Load from .rc resource | |
af111fc3 | 64 | wxAcceleratorTable::wxAcceleratorTable(const wxString& WXUNUSED(resource)) |
4bb6408c JS |
65 | { |
66 | m_refData = new wxAcceleratorRefData; | |
4bb6408c JS |
67 | } |
68 | ||
69 | // Create from an array | |
3c674514 | 70 | wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) |
4bb6408c | 71 | { |
8aa04e8b JS |
72 | wxAcceleratorRefData* data = new wxAcceleratorRefData; |
73 | m_refData = data; | |
0fb67cd1 | 74 | |
8aa04e8b JS |
75 | data->m_count = n; |
76 | data->m_entries = new wxAcceleratorEntry[n]; | |
77 | int i; | |
78 | for (i = 0; i < n; i++) | |
79 | data->m_entries[i] = entries[i]; | |
0fb67cd1 | 80 | |
4bb6408c JS |
81 | } |
82 | ||
b7cacb43 | 83 | bool wxAcceleratorTable::IsOk() const |
4bb6408c | 84 | { |
8aa04e8b JS |
85 | return (m_refData != (wxAcceleratorRefData*) NULL); |
86 | } | |
87 | ||
88 | int wxAcceleratorTable::GetCount() const | |
89 | { | |
90 | return M_ACCELDATA->m_count; | |
91 | } | |
92 | ||
93 | wxAcceleratorEntry* wxAcceleratorTable::GetEntries() const | |
94 | { | |
95 | return M_ACCELDATA->m_entries; | |
96 | } | |
97 | ||
98 | // Implementation use only | |
99 | bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const | |
100 | { | |
101 | bool eventAltDown = event.AltDown(); | |
102 | bool eventCtrlDown = event.ControlDown(); | |
103 | bool eventShiftDown = event.ShiftDown(); | |
0ec6fd04 | 104 | int eventKeyCode = event.GetKeyCode(); |
0fb67cd1 | 105 | |
8aa04e8b JS |
106 | bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT); |
107 | bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL); | |
108 | bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT); | |
109 | int accKeyCode = GetKeyCode(); | |
110 | int accKeyCode2 = GetKeyCode(); | |
111 | if (isascii(accKeyCode2)) | |
0fb67cd1 VZ |
112 | accKeyCode2 = tolower(accKeyCode2); |
113 | ||
8aa04e8b | 114 | return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) && |
2d120f83 JS |
115 | (eventShiftDown == accShiftDown) && |
116 | ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ; | |
4bb6408c | 117 | } |