1 /////////////////////////////////////////////////////////////////////////////
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"
18 #include "wx/window.h"
23 #include "wx/os2/accel.h"
25 #include "wx/os2/private.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
30 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
32 friend class WXDLLEXPORT wxAcceleratorTable
;
34 wxAcceleratorRefData();
35 ~wxAcceleratorRefData();
37 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
43 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
45 wxAcceleratorRefData::wxAcceleratorRefData()
49 } // end of wxAcceleratorRefData::wxAcceleratorRefData
51 wxAcceleratorRefData::~wxAcceleratorRefData()
55 WinDestroyAccelTable((HACCEL
) m_hAccel
);
58 } // end of wxAcceleratorRefData::~wxAcceleratorRefData
60 wxAcceleratorTable::wxAcceleratorTable()
63 } // end of wxAcceleratorTable::wxAcceleratorTable
65 wxAcceleratorTable::~wxAcceleratorTable()
67 } // end of wxAcceleratorTable::~wxAcceleratorTable
69 // Load from .rc resource
70 wxAcceleratorTable::wxAcceleratorTable(
71 const wxString
& rResource
77 m_refData
= new wxAcceleratorRefData
;
79 ulId
= atol((char*)rResource
.c_str());
80 hAccel
= ::WinLoadAccelTable( vHabmain
81 ,NULL
// resources always in .exe
84 if (wxTheApp
->GetTopWindow() != NULL
)
87 // If we have accelerators the top window is the frame
89 wxFrame
* pFrame
= (wxFrame
*)wxTheApp
->GetTopWindow();
91 ::WinSetAccelTable( vHabmain
93 ,(HWND
)pFrame
->GetFrame()
96 M_ACCELDATA
->m_hAccel
= hAccel
;
97 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
100 extern int wxCharCodeWXToOS2(
105 // Create from an array
106 wxAcceleratorTable::wxAcceleratorTable(
108 , const wxAcceleratorEntry vaEntries
[]
111 int nAccelLength
= ((sizeof(ACCEL
) * n
) + sizeof(ACCELTABLE
));
115 m_refData
= new wxAcceleratorRefData
;
116 pArr
= (PACCELTABLE
) new BYTE
[nAccelLength
];
118 for (i
= 0; i
< n
; i
++)
120 USHORT uVirt
= AF_CHAR
;
122 if (vaEntries
[i
].GetFlags() & wxACCEL_ALT
)
125 uVirt
|= AF_VIRTUALKEY
;
127 if (vaEntries
[i
].GetFlags() & wxACCEL_SHIFT
)
130 uVirt
|= AF_VIRTUALKEY
;
132 if (vaEntries
[i
].GetFlags() & wxACCEL_CTRL
)
135 uVirt
|= AF_VIRTUALKEY
;
139 USHORT uKey
= wxCharCodeWXToOS2( vaEntries
[i
].GetKeyCode()
143 uVirt
= AF_CHAR
| AF_VIRTUALKEY
;
145 USHORT uCmd
= vaEntries
[i
].GetCommand();
147 pArr
->aaccel
[i
].fs
= uVirt
;
148 pArr
->aaccel
[i
].key
= uKey
;
149 pArr
->aaccel
[i
].cmd
= uCmd
;
151 pArr
->codepage
= ::WinQueryCp(wxTheApp
->m_hMq
);
152 pArr
->cAccel
= (USHORT
)n
;
153 M_ACCELDATA
->m_hAccel
= ::WinCreateAccelTable( vHabmain
156 if (wxTheApp
->GetTopWindow() != NULL
)
159 // If we have accelerators the top window is the frame
161 wxFrame
* pFrame
= (wxFrame
*)wxTheApp
->GetTopWindow();
163 ::WinSetAccelTable( vHabmain
164 ,M_ACCELDATA
->m_hAccel
165 ,(HWND
)pFrame
->GetFrame()
170 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
171 } // end of wxAcceleratorTable::wxAcceleratorTable
173 bool wxAcceleratorTable::Ok() const
175 return(M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
176 } // end of wxAcceleratorTable::Ok
178 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
181 m_refData
= new wxAcceleratorRefData
;
183 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
186 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
190 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
193 bool wxAcceleratorTable::Translate(
198 PQMSG pMsg
= (PQMSG
)pWxmsg
;
201 rc
= ::WinTranslateAccel( vHabmain
211 } // end of wxAcceleratorTable::Translate