]> git.saurik.com Git - wxWidgets.git/blame - src/os2/accel.cpp
Fixed home and end accelerators.
[wxWidgets.git] / src / os2 / accel.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
521bf4ff 2// Name: src/os2/accel.cpp
0e320a79 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>
75f11ad7 17#include "wx/window.h"
f6bcfd97
BP
18#include "wx/app.h"
19#include "wx/frame.h"
75f11ad7
DW
20#endif
21
22#include "wx/os2/accel.h"
23
24#include "wx/os2/private.h"
25
0e320a79 26
0e320a79 27IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
0e320a79
DW
28
29class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
30{
31 friend class WXDLLEXPORT wxAcceleratorTable;
32public:
33 wxAcceleratorRefData();
34 ~wxAcceleratorRefData();
35
0e320a79
DW
36 inline HACCEL GetHACCEL() const { return m_hAccel; }
37protected:
38 HACCEL m_hAccel;
d88de032 39 bool m_ok;
0e320a79
DW
40};
41
42#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
43
44wxAcceleratorRefData::wxAcceleratorRefData()
45{
f6bcfd97
BP
46 m_ok = FALSE;
47 m_hAccel = 0;
48} // end of wxAcceleratorRefData::wxAcceleratorRefData
0e320a79
DW
49
50wxAcceleratorRefData::~wxAcceleratorRefData()
51{
f6bcfd97
BP
52 if (m_hAccel)
53 {
54 WinDestroyAccelTable((HACCEL) m_hAccel);
55 }
56 m_hAccel = 0 ;
57} // end of wxAcceleratorRefData::~wxAcceleratorRefData
0e320a79
DW
58
59wxAcceleratorTable::wxAcceleratorTable()
60{
f6bcfd97
BP
61 m_refData = NULL;
62} // end of wxAcceleratorTable::wxAcceleratorTable
0e320a79
DW
63
64wxAcceleratorTable::~wxAcceleratorTable()
65{
f6bcfd97 66} // end of wxAcceleratorTable::~wxAcceleratorTable
0e320a79
DW
67
68// Load from .rc resource
f6bcfd97
BP
69wxAcceleratorTable::wxAcceleratorTable(
70 const wxString& rResource
71)
0e320a79 72{
f6bcfd97
BP
73 HACCEL hAccel;
74 ULONG ulId;
75
0e320a79
DW
76 m_refData = new wxAcceleratorRefData;
77
f6bcfd97
BP
78 ulId = atol((char*)rResource.c_str());
79 hAccel = ::WinLoadAccelTable( vHabmain
80 ,NULL // resources always in .exe
81 ,(ULONG)ulId
82 );
83 if (wxTheApp->GetTopWindow() != NULL)
84 {
85 //
86 // If we have accelerators the top window is the frame
87 //
88 wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow();
89
90 ::WinSetAccelTable( vHabmain
f6bcfd97 91 ,hAccel
598d8cac 92 ,(HWND)pFrame->GetFrame()
f6bcfd97
BP
93 );
94 }
0e320a79
DW
95 M_ACCELDATA->m_hAccel = hAccel;
96 M_ACCELDATA->m_ok = (hAccel != 0);
0e320a79
DW
97}
98
f6bcfd97
BP
99extern int wxCharCodeWXToOS2(
100 int nId
101, bool* pbIsVirtual
102);
d88de032 103
0e320a79 104// Create from an array
f6bcfd97
BP
105wxAcceleratorTable::wxAcceleratorTable(
106 int n
3c674514 107, const wxAcceleratorEntry vaEntries[]
f6bcfd97 108)
0e320a79 109{
f6bcfd97
BP
110 int nAccelLength = ((sizeof(ACCEL) * n) + sizeof(ACCELTABLE));
111 PACCELTABLE pArr;
112 int i;
0e320a79 113
f6bcfd97
BP
114 m_refData = new wxAcceleratorRefData;
115 pArr = (PACCELTABLE) new BYTE[nAccelLength];
116
117 for (i = 0; i < n; i++)
118 {
119 USHORT uVirt = AF_CHAR;
120
121 if (vaEntries[i].GetFlags() & wxACCEL_ALT)
3febf684 122 {
f6bcfd97 123 uVirt |= AF_ALT;
3febf684
DW
124 uVirt |= AF_VIRTUALKEY;
125 }
f6bcfd97 126 if (vaEntries[i].GetFlags() & wxACCEL_SHIFT)
3febf684 127 {
f6bcfd97 128 uVirt |= AF_SHIFT;
3febf684
DW
129 uVirt |= AF_VIRTUALKEY;
130 }
f6bcfd97 131 if (vaEntries[i].GetFlags() & wxACCEL_CTRL)
3febf684 132 {
f6bcfd97 133 uVirt |= AF_CONTROL;
3febf684
DW
134 uVirt |= AF_VIRTUALKEY;
135 }
f6bcfd97 136
6670f564
WS
137 bool bIsVirtual;
138 USHORT uKey = (USHORT)wxCharCodeWXToOS2( vaEntries[i].GetKeyCode(),
139 &bIsVirtual);
f6bcfd97
BP
140 if (bIsVirtual)
141 uVirt = AF_CHAR | AF_VIRTUALKEY;
142
6670f564 143 USHORT uCmd = (USHORT)vaEntries[i].GetCommand();
f6bcfd97
BP
144
145 pArr->aaccel[i].fs = uVirt;
146 pArr->aaccel[i].key = uKey;
147 pArr->aaccel[i].cmd = uCmd;
148 }
6670f564 149 pArr->codepage = (USHORT)::WinQueryCp(wxTheApp->m_hMq);
f6bcfd97
BP
150 pArr->cAccel = (USHORT)n;
151 M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain
152 ,pArr
153 );
154 if (wxTheApp->GetTopWindow() != NULL)
155 {
156 //
157 // If we have accelerators the top window is the frame
158 //
6670f564 159 wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow();
f6bcfd97
BP
160
161 ::WinSetAccelTable( vHabmain
f6bcfd97 162 ,M_ACCELDATA->m_hAccel
598d8cac 163 ,(HWND)pFrame->GetFrame()
f6bcfd97
BP
164 );
165 }
166
167 delete[] pArr;
168 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
169} // end of wxAcceleratorTable::wxAcceleratorTable
0e320a79
DW
170
171bool wxAcceleratorTable::Ok() const
172{
f6bcfd97
BP
173 return(M_ACCELDATA && (M_ACCELDATA->m_ok));
174} // end of wxAcceleratorTable::Ok
0e320a79 175
75f11ad7
DW
176void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
177{
178 if (!M_ACCELDATA)
179 m_refData = new wxAcceleratorRefData;
180
181 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
182}
183
184WXHACCEL wxAcceleratorTable::GetHACCEL() const
185{
186 if (!M_ACCELDATA)
187 return 0;
188 return (WXHACCEL) M_ACCELDATA->m_hAccel;
189}
190
f6bcfd97
BP
191bool wxAcceleratorTable::Translate(
192 WXHWND hWnd
193, WXMSG* pWxmsg
194) const
75f11ad7 195{
f6bcfd97 196 PQMSG pMsg = (PQMSG)pWxmsg;
e15bbde0
DW
197 BOOL rc = FALSE;
198
199 rc = ::WinTranslateAccel( vHabmain
200 ,(HWND)hWnd
201 ,GetHaccel()
202 ,pMsg
203 );
e15bbde0 204 return (Ok() && rc);
f6bcfd97 205} // end of wxAcceleratorTable::Translate
75f11ad7 206
3a7c1253
SN
207// ---------------------------------------------------------------------------
208// function for translating labels
209// ---------------------------------------------------------------------------
210
6670f564 211wxString wxPMTextToLabel( const wxString& rsTitle )
3a7c1253 212{
6670f564
WS
213 wxString sTitle;
214 const wxChar* zPc;
3a7c1253 215
6670f564 216 if (rsTitle.empty())
3a7c1253
SN
217 return(sTitle);
218
219 for (zPc = rsTitle.c_str(); *zPc != wxT('\0'); zPc++)
220 {
221 if (*zPc == wxT('&'))
222 {
223 if (*(zPc + 1) == wxT('&'))
224 {
225 zPc++;
226 sTitle << wxT('&');
227 }
228 else
229 sTitle << wxT('~');
230 }
231 else
232 {
233 if ( *zPc == wxT('~'))
234 {
235 //
236 // Tildes must be doubled to prevent them from being
237 // interpreted as accelerator character prefix by PM ???
238 //
239 sTitle << *zPc;
240 }
241 sTitle << *zPc;
242 }
243 }
244 return(sTitle);
245} // end of wxPMTextToLabel