]> git.saurik.com Git - wxWidgets.git/blame - src/os2/accel.cpp
replace apple extended code
[wxWidgets.git] / src / os2 / accel.cpp
CommitLineData
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
65571936 9// Licence: wxWindows licence
0e320a79
DW
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 28IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
0e320a79
DW
29
30class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
31{
32 friend class WXDLLEXPORT wxAcceleratorTable;
33public:
34 wxAcceleratorRefData();
35 ~wxAcceleratorRefData();
36
0e320a79
DW
37 inline HACCEL GetHACCEL() const { return m_hAccel; }
38protected:
39 HACCEL m_hAccel;
d88de032 40 bool m_ok;
0e320a79
DW
41};
42
43#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
44
45wxAcceleratorRefData::wxAcceleratorRefData()
46{
f6bcfd97
BP
47 m_ok = FALSE;
48 m_hAccel = 0;
49} // end of wxAcceleratorRefData::wxAcceleratorRefData
0e320a79
DW
50
51wxAcceleratorRefData::~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
60wxAcceleratorTable::wxAcceleratorTable()
61{
f6bcfd97
BP
62 m_refData = NULL;
63} // end of wxAcceleratorTable::wxAcceleratorTable
0e320a79
DW
64
65wxAcceleratorTable::~wxAcceleratorTable()
66{
f6bcfd97 67} // end of wxAcceleratorTable::~wxAcceleratorTable
0e320a79
DW
68
69// Load from .rc resource
f6bcfd97
BP
70wxAcceleratorTable::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
598d8cac 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
100extern int wxCharCodeWXToOS2(
101 int nId
102, bool* pbIsVirtual
103);
d88de032 104
0e320a79 105// Create from an array
f6bcfd97
BP
106wxAcceleratorTable::wxAcceleratorTable(
107 int n
3c674514 108, const wxAcceleratorEntry vaEntries[]
f6bcfd97 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)
3febf684 123 {
f6bcfd97 124 uVirt |= AF_ALT;
3febf684
DW
125 uVirt |= AF_VIRTUALKEY;
126 }
f6bcfd97 127 if (vaEntries[i].GetFlags() & wxACCEL_SHIFT)
3febf684 128 {
f6bcfd97 129 uVirt |= AF_SHIFT;
3febf684
DW
130 uVirt |= AF_VIRTUALKEY;
131 }
f6bcfd97 132 if (vaEntries[i].GetFlags() & wxACCEL_CTRL)
3febf684 133 {
f6bcfd97 134 uVirt |= AF_CONTROL;
3febf684
DW
135 uVirt |= AF_VIRTUALKEY;
136 }
f6bcfd97
BP
137
138 bool bIsVirtual;
139 USHORT uKey = wxCharCodeWXToOS2( vaEntries[i].GetKeyCode()
140 ,&bIsVirtual
141 );
142 if (bIsVirtual)
143 uVirt = AF_CHAR | AF_VIRTUALKEY;
144
145 USHORT uCmd = vaEntries[i].GetCommand();
146
147 pArr->aaccel[i].fs = uVirt;
148 pArr->aaccel[i].key = uKey;
149 pArr->aaccel[i].cmd = uCmd;
150 }
2ebb116d 151 pArr->codepage = ::WinQueryCp(wxTheApp->m_hMq);
f6bcfd97
BP
152 pArr->cAccel = (USHORT)n;
153 M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain
154 ,pArr
155 );
156 if (wxTheApp->GetTopWindow() != NULL)
157 {
158 //
159 // If we have accelerators the top window is the frame
160 //
161 wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow();
162
163 ::WinSetAccelTable( vHabmain
f6bcfd97 164 ,M_ACCELDATA->m_hAccel
598d8cac 165 ,(HWND)pFrame->GetFrame()
f6bcfd97
BP
166 );
167 }
168
169 delete[] pArr;
170 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
171} // end of wxAcceleratorTable::wxAcceleratorTable
0e320a79
DW
172
173bool wxAcceleratorTable::Ok() const
174{
f6bcfd97
BP
175 return(M_ACCELDATA && (M_ACCELDATA->m_ok));
176} // end of wxAcceleratorTable::Ok
0e320a79 177
75f11ad7
DW
178void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
179{
180 if (!M_ACCELDATA)
181 m_refData = new wxAcceleratorRefData;
182
183 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
184}
185
186WXHACCEL wxAcceleratorTable::GetHACCEL() const
187{
188 if (!M_ACCELDATA)
189 return 0;
190 return (WXHACCEL) M_ACCELDATA->m_hAccel;
191}
192
f6bcfd97
BP
193bool wxAcceleratorTable::Translate(
194 WXHWND hWnd
195, WXMSG* pWxmsg
196) const
75f11ad7 197{
f6bcfd97 198 PQMSG pMsg = (PQMSG)pWxmsg;
e15bbde0
DW
199 BOOL rc = FALSE;
200
201 rc = ::WinTranslateAccel( vHabmain
202 ,(HWND)hWnd
203 ,GetHaccel()
204 ,pMsg
205 );
206 if (rc)
207 {
208 int x = 1;
209 }
210 return (Ok() && rc);
f6bcfd97 211} // end of wxAcceleratorTable::Translate
75f11ad7 212
3a7c1253
SN
213// ---------------------------------------------------------------------------
214// function for translating labels
215// ---------------------------------------------------------------------------
216
217wxString wxPMTextToLabel(
218 const wxString& rsTitle
219)
220{
221 wxString sTitle;
222 const wxChar* zPc;
223
224 if (rsTitle.IsEmpty())
225 return(sTitle);
226
227 for (zPc = rsTitle.c_str(); *zPc != wxT('\0'); zPc++)
228 {
229 if (*zPc == wxT('&'))
230 {
231 if (*(zPc + 1) == wxT('&'))
232 {
233 zPc++;
234 sTitle << wxT('&');
235 }
236 else
237 sTitle << wxT('~');
238 }
239 else
240 {
241 if ( *zPc == wxT('~'))
242 {
243 //
244 // Tildes must be doubled to prevent them from being
245 // interpreted as accelerator character prefix by PM ???
246 //
247 sTitle << *zPc;
248 }
249 sTitle << *zPc;
250 }
251 }
252 return(sTitle);
253} // end of wxPMTextToLabel
254