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