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