1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/window.h"
24 #include "wx/os2/private.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
29 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
31 friend class WXDLLEXPORT wxAcceleratorTable;
33 wxAcceleratorRefData();
34 virtual ~wxAcceleratorRefData();
36 inline HACCEL GetHACCEL() const { return m_hAccel; }
42 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
44 wxAcceleratorRefData::wxAcceleratorRefData()
48 } // end of wxAcceleratorRefData::wxAcceleratorRefData
50 wxAcceleratorRefData::~wxAcceleratorRefData()
54 WinDestroyAccelTable((HACCEL) m_hAccel);
57 } // end of wxAcceleratorRefData::~wxAcceleratorRefData
59 wxAcceleratorTable::wxAcceleratorTable()
62 } // end of wxAcceleratorTable::wxAcceleratorTable
64 wxAcceleratorTable::~wxAcceleratorTable()
66 } // end of wxAcceleratorTable::~wxAcceleratorTable
68 // Load from .rc resource
69 wxAcceleratorTable::wxAcceleratorTable(
70 const wxString& rResource
76 m_refData = new wxAcceleratorRefData;
78 ulId = atol(rResource.c_str());
79 hAccel = ::WinLoadAccelTable( vHabmain
80 ,NULL // resources always in .exe
83 if (wxTheApp->GetTopWindow() != NULL)
86 // If we have accelerators the top window is the frame
88 wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow();
90 ::WinSetAccelTable( vHabmain
92 ,(HWND)pFrame->GetFrame()
95 M_ACCELDATA->m_hAccel = hAccel;
96 M_ACCELDATA->m_ok = (hAccel != 0);
99 extern int wxCharCodeWXToOS2(
104 // Create from an array
105 wxAcceleratorTable::wxAcceleratorTable(
107 , const wxAcceleratorEntry vaEntries[]
110 int nAccelLength = ((sizeof(ACCEL) * n) + sizeof(ACCELTABLE));
114 m_refData = new wxAcceleratorRefData;
115 pArr = (PACCELTABLE) new BYTE[nAccelLength];
117 for (i = 0; i < n; i++)
119 USHORT uVirt = AF_CHAR;
121 if (vaEntries[i].GetFlags() & wxACCEL_ALT)
124 uVirt |= AF_VIRTUALKEY;
126 if (vaEntries[i].GetFlags() & wxACCEL_SHIFT)
129 uVirt |= AF_VIRTUALKEY;
131 if (vaEntries[i].GetFlags() & wxACCEL_CTRL)
134 uVirt |= AF_VIRTUALKEY;
138 USHORT uKey = (USHORT)wxCharCodeWXToOS2( vaEntries[i].GetKeyCode(),
141 uVirt = AF_CHAR | AF_VIRTUALKEY;
143 USHORT uCmd = (USHORT)vaEntries[i].GetCommand();
145 pArr->aaccel[i].fs = uVirt;
146 pArr->aaccel[i].key = uKey;
147 pArr->aaccel[i].cmd = uCmd;
149 pArr->codepage = (USHORT)::WinQueryCp(wxTheApp->m_hMq);
150 pArr->cAccel = (USHORT)n;
151 M_ACCELDATA->m_hAccel = ::WinCreateAccelTable( vHabmain
154 if (wxTheApp->GetTopWindow() != NULL)
157 // If we have accelerators the top window is the frame
159 wxFrame* pFrame = (wxFrame*)wxTheApp->GetTopWindow();
161 ::WinSetAccelTable( vHabmain
162 ,M_ACCELDATA->m_hAccel
163 ,(HWND)pFrame->GetFrame()
168 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
169 } // end of wxAcceleratorTable::wxAcceleratorTable
171 bool wxAcceleratorTable::IsOk() const
173 return(M_ACCELDATA && (M_ACCELDATA->m_ok));
174 } // end of wxAcceleratorTable::IsOk
176 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
179 m_refData = new wxAcceleratorRefData;
181 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
184 WXHACCEL wxAcceleratorTable::GetHACCEL() const
188 return (WXHACCEL) M_ACCELDATA->m_hAccel;
191 bool wxAcceleratorTable::Translate( WXHWND hWnd,
192 WXMSG* pWxmsg ) const
194 PQMSG pMsg = (PQMSG)pWxmsg;
197 rc = ::WinTranslateAccel( vHabmain
203 } // end of wxAcceleratorTable::Translate
205 // ---------------------------------------------------------------------------
206 // function for translating labels
207 // ---------------------------------------------------------------------------
209 wxString wxPMTextToLabel( const wxString& rsTitle )
217 for (zPc = rsTitle.c_str(); *zPc != wxT('\0'); zPc++)
219 if (*zPc == wxT('&'))
221 if (*(zPc + 1) == wxT('&'))
231 if ( *zPc == wxT('~'))
234 // Tildes must be doubled to prevent them from being
235 // interpreted as accelerator character prefix by PM ???
243 } // end of wxPMTextToLabel