]> git.saurik.com Git - wxWidgets.git/blob - src/motif/accel.cpp
Try to display '...' text on editor buttons more consistently on wxGTK. This is done...
[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 = (wxAcceleratorEntry*) NULL;
44 }
45
46 wxAcceleratorRefData::~wxAcceleratorRefData()
47 {
48 delete[] m_entries;
49 m_entries = (wxAcceleratorEntry*) NULL;
50 m_count = 0;
51 }
52
53 wxAcceleratorTable::wxAcceleratorTable()
54 {
55 m_refData = (wxAcceleratorRefData*) NULL;
56 }
57
58 wxAcceleratorTable::~wxAcceleratorTable()
59 {
60 // Data deleted in ~wxObject
61 }
62
63 // Load from .rc resource
64 wxAcceleratorTable::wxAcceleratorTable(const wxString& WXUNUSED(resource))
65 {
66 m_refData = new wxAcceleratorRefData;
67 }
68
69 // Create from an array
70 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
71 {
72 wxAcceleratorRefData* data = new wxAcceleratorRefData;
73 m_refData = data;
74
75 data->m_count = n;
76 data->m_entries = new wxAcceleratorEntry[n];
77 int i;
78 for (i = 0; i < n; i++)
79 data->m_entries[i] = entries[i];
80
81 }
82
83 bool wxAcceleratorTable::IsOk() const
84 {
85 return (m_refData != (wxAcceleratorRefData*) NULL);
86 }
87
88 int wxAcceleratorTable::GetCount() const
89 {
90 return M_ACCELDATA->m_count;
91 }
92
93 wxAcceleratorEntry* wxAcceleratorTable::GetEntries() const
94 {
95 return M_ACCELDATA->m_entries;
96 }
97
98 // Implementation use only
99 bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const
100 {
101 bool eventAltDown = event.AltDown();
102 bool eventCtrlDown = event.ControlDown();
103 bool eventShiftDown = event.ShiftDown();
104 int eventKeyCode = event.GetKeyCode();
105
106 bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT);
107 bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL);
108 bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT);
109 int accKeyCode = GetKeyCode();
110 int accKeyCode2 = GetKeyCode();
111 if (isascii(accKeyCode2))
112 accKeyCode2 = tolower(accKeyCode2);
113
114 return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
115 (eventShiftDown == accShiftDown) &&
116 ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ;
117 }