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