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