]> git.saurik.com Git - wxWidgets.git/blob - src/motif/accel.cpp
mask fixes for non-core graphics case (this build uses CopyDeepMask for painting...
[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/setup.h"
16 #include "wx/accel.h"
17 #include "wx/string.h"
18 #include "wx/utils.h"
19 #include <ctype.h>
20
21 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
22
23 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
24 {
25 friend class WXDLLEXPORT wxAcceleratorTable;
26 public:
27 wxAcceleratorRefData();
28 ~wxAcceleratorRefData();
29
30 public:
31 int m_count;
32 wxAcceleratorEntry* m_entries;
33 };
34
35 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
36
37 wxAcceleratorRefData::wxAcceleratorRefData()
38 {
39 m_count = 0;
40 m_entries = (wxAcceleratorEntry*) NULL;
41 }
42
43 wxAcceleratorRefData::~wxAcceleratorRefData()
44 {
45 delete[] m_entries;
46 m_entries = (wxAcceleratorEntry*) NULL;
47 m_count = 0;
48 }
49
50 wxAcceleratorTable::wxAcceleratorTable()
51 {
52 m_refData = (wxAcceleratorRefData*) NULL;
53 }
54
55 wxAcceleratorTable::~wxAcceleratorTable()
56 {
57 // Data deleted in ~wxObject
58 }
59
60 // Load from .rc resource
61 wxAcceleratorTable::wxAcceleratorTable(const wxString& WXUNUSED(resource))
62 {
63 m_refData = new wxAcceleratorRefData;
64 }
65
66 // Create from an array
67 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
68 {
69 wxAcceleratorRefData* data = new wxAcceleratorRefData;
70 m_refData = data;
71
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];
77
78 }
79
80 bool wxAcceleratorTable::Ok() const
81 {
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();
101 int eventKeyCode = event.GetKeyCode();
102
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))
109 accKeyCode2 = tolower(accKeyCode2);
110
111 return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
112 (eventShiftDown == accShiftDown) &&
113 ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ;
114 }