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