]>
Commit | Line | Data |
---|---|---|
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 | |
670f9935 WS |
15 | #include "wx/accel.h" |
16 | ||
75f11ad7 | 17 | #ifndef WX_PRECOMP |
670f9935 WS |
18 | #include <stdio.h> |
19 | #include "wx/window.h" | |
20 | #include "wx/app.h" | |
21 | #include "wx/frame.h" | |
75f11ad7 DW |
22 | #endif |
23 | ||
75f11ad7 DW |
24 | #include "wx/os2/private.h" |
25 | ||
0e320a79 | 26 | |
0e320a79 | 27 | IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) |
0e320a79 DW |
28 | |
29 | class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData | |
30 | { | |
31 | friend class WXDLLEXPORT wxAcceleratorTable; | |
32 | public: | |
33 | wxAcceleratorRefData(); | |
d3c7fc99 | 34 | virtual ~wxAcceleratorRefData(); |
0e320a79 | 35 | |
0e320a79 DW |
36 | inline HACCEL GetHACCEL() const { return m_hAccel; } |
37 | protected: | |
38 | HACCEL m_hAccel; | |
d88de032 | 39 | bool m_ok; |
0e320a79 DW |
40 | }; |
41 | ||
42 | #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) | |
43 | ||
44 | wxAcceleratorRefData::wxAcceleratorRefData() | |
45 | { | |
670f9935 | 46 | m_ok = false; |
f6bcfd97 BP |
47 | m_hAccel = 0; |
48 | } // end of wxAcceleratorRefData::wxAcceleratorRefData | |
0e320a79 DW |
49 | |
50 | wxAcceleratorRefData::~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 | |
59 | wxAcceleratorTable::wxAcceleratorTable() | |
60 | { | |
f6bcfd97 BP |
61 | m_refData = NULL; |
62 | } // end of wxAcceleratorTable::wxAcceleratorTable | |
0e320a79 DW |
63 | |
64 | wxAcceleratorTable::~wxAcceleratorTable() | |
65 | { | |
f6bcfd97 | 66 | } // end of wxAcceleratorTable::~wxAcceleratorTable |
0e320a79 DW |
67 | |
68 | // Load from .rc resource | |
f6bcfd97 BP |
69 | wxAcceleratorTable::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 | ||
65f3f920 | 78 | ulId = atol(rResource.c_str()); |
f6bcfd97 BP |
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 |
99 | extern int wxCharCodeWXToOS2( |
100 | int nId | |
101 | , bool* pbIsVirtual | |
102 | ); | |
d88de032 | 103 | |
0e320a79 | 104 | // Create from an array |
f6bcfd97 BP |
105 | wxAcceleratorTable::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 | 170 | |
b7cacb43 | 171 | bool wxAcceleratorTable::IsOk() const |
0e320a79 | 172 | { |
f6bcfd97 | 173 | return(M_ACCELDATA && (M_ACCELDATA->m_ok)); |
b7cacb43 | 174 | } // end of wxAcceleratorTable::IsOk |
0e320a79 | 175 | |
75f11ad7 DW |
176 | void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel) |
177 | { | |
178 | if (!M_ACCELDATA) | |
179 | m_refData = new wxAcceleratorRefData; | |
180 | ||
181 | M_ACCELDATA->m_hAccel = (HACCEL) hAccel; | |
182 | } | |
183 | ||
184 | WXHACCEL wxAcceleratorTable::GetHACCEL() const | |
185 | { | |
186 | if (!M_ACCELDATA) | |
187 | return 0; | |
188 | return (WXHACCEL) M_ACCELDATA->m_hAccel; | |
189 | } | |
190 | ||
670f9935 WS |
191 | bool wxAcceleratorTable::Translate( WXHWND hWnd, |
192 | WXMSG* pWxmsg ) const | |
75f11ad7 | 193 | { |
670f9935 WS |
194 | PQMSG pMsg = (PQMSG)pWxmsg; |
195 | BOOL rc = FALSE; | |
e15bbde0 DW |
196 | |
197 | rc = ::WinTranslateAccel( vHabmain | |
198 | ,(HWND)hWnd | |
199 | ,GetHaccel() | |
200 | ,pMsg | |
201 | ); | |
e15bbde0 | 202 | return (Ok() && rc); |
f6bcfd97 | 203 | } // end of wxAcceleratorTable::Translate |
75f11ad7 | 204 | |
3a7c1253 SN |
205 | // --------------------------------------------------------------------------- |
206 | // function for translating labels | |
207 | // --------------------------------------------------------------------------- | |
208 | ||
6670f564 | 209 | wxString wxPMTextToLabel( const wxString& rsTitle ) |
3a7c1253 | 210 | { |
6670f564 WS |
211 | wxString sTitle; |
212 | const wxChar* zPc; | |
3a7c1253 | 213 | |
6670f564 | 214 | if (rsTitle.empty()) |
3a7c1253 SN |
215 | return(sTitle); |
216 | ||
217 | for (zPc = rsTitle.c_str(); *zPc != wxT('\0'); zPc++) | |
218 | { | |
219 | if (*zPc == wxT('&')) | |
220 | { | |
221 | if (*(zPc + 1) == wxT('&')) | |
222 | { | |
223 | zPc++; | |
224 | sTitle << wxT('&'); | |
225 | } | |
226 | else | |
227 | sTitle << wxT('~'); | |
228 | } | |
229 | else | |
230 | { | |
231 | if ( *zPc == wxT('~')) | |
232 | { | |
233 | // | |
234 | // Tildes must be doubled to prevent them from being | |
235 | // interpreted as accelerator character prefix by PM ??? | |
236 | // | |
237 | sTitle << *zPc; | |
238 | } | |
239 | sTitle << *zPc; | |
240 | } | |
241 | } | |
242 | return(sTitle); | |
243 | } // end of wxPMTextToLabel |