]>
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 JS |
15 | #include "wx/setup.h" |
16 | #include "wx/accel.h" | |
17 | #include "wx/string.h" | |
8aa04e8b JS |
18 | #include "wx/utils.h" |
19 | #include <ctype.h> | |
4bb6408c | 20 | |
4bb6408c | 21 | IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) |
4bb6408c JS |
22 | |
23 | class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData | |
24 | { | |
25 | friend class WXDLLEXPORT wxAcceleratorTable; | |
26 | public: | |
27 | wxAcceleratorRefData(); | |
28 | ~wxAcceleratorRefData(); | |
0fb67cd1 | 29 | |
8aa04e8b JS |
30 | public: |
31 | int m_count; | |
32 | wxAcceleratorEntry* m_entries; | |
4bb6408c JS |
33 | }; |
34 | ||
35 | #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) | |
36 | ||
37 | wxAcceleratorRefData::wxAcceleratorRefData() | |
38 | { | |
8aa04e8b JS |
39 | m_count = 0; |
40 | m_entries = (wxAcceleratorEntry*) NULL; | |
4bb6408c JS |
41 | } |
42 | ||
43 | wxAcceleratorRefData::~wxAcceleratorRefData() | |
44 | { | |
8aa04e8b JS |
45 | delete[] m_entries; |
46 | m_entries = (wxAcceleratorEntry*) NULL; | |
47 | m_count = 0; | |
4bb6408c JS |
48 | } |
49 | ||
50 | wxAcceleratorTable::wxAcceleratorTable() | |
51 | { | |
8aa04e8b | 52 | m_refData = (wxAcceleratorRefData*) NULL; |
4bb6408c JS |
53 | } |
54 | ||
55 | wxAcceleratorTable::~wxAcceleratorTable() | |
56 | { | |
8aa04e8b | 57 | // Data deleted in ~wxObject |
4bb6408c JS |
58 | } |
59 | ||
60 | // Load from .rc resource | |
af111fc3 | 61 | wxAcceleratorTable::wxAcceleratorTable(const wxString& WXUNUSED(resource)) |
4bb6408c JS |
62 | { |
63 | m_refData = new wxAcceleratorRefData; | |
4bb6408c JS |
64 | } |
65 | ||
66 | // Create from an array | |
3c674514 | 67 | wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) |
4bb6408c | 68 | { |
8aa04e8b JS |
69 | wxAcceleratorRefData* data = new wxAcceleratorRefData; |
70 | m_refData = data; | |
0fb67cd1 | 71 | |
8aa04e8b JS |
72 | data->m_count = n; |
73 | data->m_entries = new wxAcceleratorEntry[n]; | |
74 | int i; | |
75 | for (i = 0; i < n; i++) | |
76 | data->m_entries[i] = entries[i]; | |
0fb67cd1 | 77 | |
4bb6408c JS |
78 | } |
79 | ||
80 | bool wxAcceleratorTable::Ok() const | |
81 | { | |
8aa04e8b JS |
82 | return (m_refData != (wxAcceleratorRefData*) NULL); |
83 | } | |
84 | ||
85 | int wxAcceleratorTable::GetCount() const | |
86 | { | |
87 | return M_ACCELDATA->m_count; | |
88 | } | |
89 | ||
90 | wxAcceleratorEntry* wxAcceleratorTable::GetEntries() const | |
91 | { | |
92 | return M_ACCELDATA->m_entries; | |
93 | } | |
94 | ||
95 | // Implementation use only | |
96 | bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const | |
97 | { | |
98 | bool eventAltDown = event.AltDown(); | |
99 | bool eventCtrlDown = event.ControlDown(); | |
100 | bool eventShiftDown = event.ShiftDown(); | |
0ec6fd04 | 101 | int eventKeyCode = event.GetKeyCode(); |
0fb67cd1 | 102 | |
8aa04e8b JS |
103 | bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT); |
104 | bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL); | |
105 | bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT); | |
106 | int accKeyCode = GetKeyCode(); | |
107 | int accKeyCode2 = GetKeyCode(); | |
108 | if (isascii(accKeyCode2)) | |
0fb67cd1 VZ |
109 | accKeyCode2 = tolower(accKeyCode2); |
110 | ||
8aa04e8b | 111 | return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) && |
2d120f83 JS |
112 | (eventShiftDown == accShiftDown) && |
113 | ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ; | |
4bb6408c | 114 | } |