]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: accel.cpp | |
3 | // Purpose: wxAcceleratorTable | |
d88de032 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
d88de032 | 6 | // Created: 10/13/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
d88de032 | 8 | // Copyright: (c) David Webster |
0e320a79 DW |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
75f11ad7 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
0e320a79 | 14 | |
75f11ad7 DW |
15 | #ifndef WX_PRECOMP |
16 | #include <stdio.h> | |
0e320a79 | 17 | #include "wx/setup.h" |
75f11ad7 | 18 | #include "wx/window.h" |
f6bcfd97 BP |
19 | #include "wx/app.h" |
20 | #include "wx/frame.h" | |
75f11ad7 DW |
21 | #endif |
22 | ||
23 | #include "wx/os2/accel.h" | |
24 | ||
25 | #include "wx/os2/private.h" | |
26 | ||
0e320a79 | 27 | |
0e320a79 | 28 | IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) |
0e320a79 DW |
29 | |
30 | class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData | |
31 | { | |
32 | friend class WXDLLEXPORT wxAcceleratorTable; | |
33 | public: | |
34 | wxAcceleratorRefData(); | |
35 | ~wxAcceleratorRefData(); | |
36 | ||
0e320a79 DW |
37 | inline HACCEL GetHACCEL() const { return m_hAccel; } |
38 | protected: | |
39 | HACCEL m_hAccel; | |
d88de032 | 40 | bool m_ok; |
0e320a79 DW |
41 | }; |
42 | ||
43 | #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) | |
44 | ||
45 | wxAcceleratorRefData::wxAcceleratorRefData() | |
46 | { | |
f6bcfd97 BP |
47 | m_ok = FALSE; |
48 | m_hAccel = 0; | |
49 | } // end of wxAcceleratorRefData::wxAcceleratorRefData | |
0e320a79 DW |
50 | |
51 | wxAcceleratorRefData::~wxAcceleratorRefData() | |
52 | { | |
f6bcfd97 BP |
53 | if (m_hAccel) |
54 | { | |
55 | WinDestroyAccelTable((HACCEL) m_hAccel); | |
56 | } | |
57 | m_hAccel = 0 ; | |
58 | } // end of wxAcceleratorRefData::~wxAcceleratorRefData | |
0e320a79 DW |
59 | |
60 | wxAcceleratorTable::wxAcceleratorTable() | |
61 | { | |
f6bcfd97 BP |
62 | m_refData = NULL; |
63 | } // end of wxAcceleratorTable::wxAcceleratorTable | |
0e320a79 DW |
64 | |
65 | wxAcceleratorTable::~wxAcceleratorTable() | |
66 | { | |
f6bcfd97 | 67 | } // end of wxAcceleratorTable::~wxAcceleratorTable |
0e320a79 DW |
68 | |
69 | // Load from .rc resource | |
f6bcfd97 BP |
70 | wxAcceleratorTable::wxAcceleratorTable( |
71 | const wxString& rResource | |
72 | ) | |
0e320a79 | 73 | { |
f6bcfd97 BP |
74 | HACCEL hAccel; |
75 | ULONG ulId; | |
76 | ||
0e320a79 DW |
77 | m_refData = new wxAcceleratorRefData; |
78 | ||
f6bcfd97 BP |
79 | ulId = atol((char*)rResource.c_str()); |
80 | hAccel = ::WinLoadAccelTable( vHabmain | |
81 | ,NULL // resources always in .exe | |
82 | ,(ULONG)ulId | |
83 | ); | |
84 | if (wxTheApp->GetTopWindow() != NULL) | |
85 | { | |
86 | // | |
87 | // If we have accelerators the top window is the frame | |
88 | // | |
89 | wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow(); | |
90 | ||
91 | ::WinSetAccelTable( vHabmain | |
f6bcfd97 | 92 | ,hAccel |
f09d8a3b | 93 | ,(HWND)pFrame->GetFrame() |
f6bcfd97 BP |
94 | ); |
95 | } | |
0e320a79 DW |
96 | M_ACCELDATA->m_hAccel = hAccel; |
97 | M_ACCELDATA->m_ok = (hAccel != 0); | |
0e320a79 DW |
98 | } |
99 | ||
f6bcfd97 BP |
100 | extern int wxCharCodeWXToOS2( |
101 | int nId | |
102 | , bool* pbIsVirtual | |
103 | ); | |
d88de032 | 104 | |
0e320a79 | 105 | // Create from an array |
f6bcfd97 BP |
106 | wxAcceleratorTable::wxAcceleratorTable( |
107 | int n | |
108 | , wxAcceleratorEntry vaEntries[] | |
109 | ) | |
0e320a79 | 110 | { |
f6bcfd97 BP |
111 | int nAccelLength = ((sizeof(ACCEL) * n) + sizeof(ACCELTABLE)); |
112 | PACCELTABLE pArr; | |
113 | int i; | |
0e320a79 | 114 | |
f6bcfd97 BP |
115 | m_refData = new wxAcceleratorRefData; |
116 | pArr = (PACCELTABLE) new BYTE[nAccelLength]; | |
117 | ||
118 | for (i = 0; i < n; i++) | |
119 | { | |
120 | USHORT uVirt = AF_CHAR; | |
121 | ||
122 | if (vaEntries[i].GetFlags() & wxACCEL_ALT) | |
123 | uVirt |= AF_ALT; | |
124 | if (vaEntries[i].GetFlags() & wxACCEL_SHIFT) | |
125 | uVirt |= AF_SHIFT; | |
126 | if (vaEntries[i].GetFlags() & wxACCEL_CTRL) | |
127 | uVirt |= AF_CONTROL; | |
128 | ||
129 | bool bIsVirtual; | |
130 | USHORT uKey = wxCharCodeWXToOS2( vaEntries[i].GetKeyCode() | |
131 | ,&bIsVirtual | |
132 | ); | |
133 | if (bIsVirtual) | |
134 | uVirt = AF_CHAR | AF_VIRTUALKEY; | |
135 | ||
136 | USHORT uCmd = vaEntries[i].GetCommand(); | |
137 | ||
138 | pArr->aaccel[i].fs = uVirt; | |
139 | pArr->aaccel[i].key = uKey; | |
140 | pArr->aaccel[i].cmd = uCmd; | |
141 | } | |
142 | pArr->codepage = 437; // default to english Fix??? | |
143 | pArr->cAccel = (USHORT)n; | |
144 | M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain | |
145 | ,pArr | |
146 | ); | |
147 | if (wxTheApp->GetTopWindow() != NULL) | |
148 | { | |
149 | // | |
150 | // If we have accelerators the top window is the frame | |
151 | // | |
152 | wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow(); | |
153 | ||
154 | ::WinSetAccelTable( vHabmain | |
f6bcfd97 | 155 | ,M_ACCELDATA->m_hAccel |
f09d8a3b | 156 | ,(HWND)pFrame->GetFrame() |
f6bcfd97 BP |
157 | ); |
158 | } | |
159 | ||
160 | delete[] pArr; | |
161 | M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0); | |
162 | } // end of wxAcceleratorTable::wxAcceleratorTable | |
0e320a79 DW |
163 | |
164 | bool wxAcceleratorTable::Ok() const | |
165 | { | |
f6bcfd97 BP |
166 | return(M_ACCELDATA && (M_ACCELDATA->m_ok)); |
167 | } // end of wxAcceleratorTable::Ok | |
0e320a79 | 168 | |
75f11ad7 DW |
169 | void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel) |
170 | { | |
171 | if (!M_ACCELDATA) | |
172 | m_refData = new wxAcceleratorRefData; | |
173 | ||
174 | M_ACCELDATA->m_hAccel = (HACCEL) hAccel; | |
175 | } | |
176 | ||
177 | WXHACCEL wxAcceleratorTable::GetHACCEL() const | |
178 | { | |
179 | if (!M_ACCELDATA) | |
180 | return 0; | |
181 | return (WXHACCEL) M_ACCELDATA->m_hAccel; | |
182 | } | |
183 | ||
f6bcfd97 BP |
184 | bool wxAcceleratorTable::Translate( |
185 | WXHWND hWnd | |
186 | , WXMSG* pWxmsg | |
187 | ) const | |
75f11ad7 | 188 | { |
f6bcfd97 BP |
189 | PQMSG pMsg = (PQMSG)pWxmsg; |
190 | ||
191 | return Ok() && ::WinTranslateAccel( vHabmain | |
192 | ,(HWND)hWnd | |
193 | ,GetHaccel() | |
194 | ,pMsg | |
195 | ); | |
196 | } // end of wxAcceleratorTable::Translate | |
75f11ad7 | 197 |