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 , 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
)
124 if (vaEntries
[i
].GetFlags() & wxACCEL_SHIFT
)
126 if (vaEntries
[i
].GetFlags() & wxACCEL_CTRL
)
130 USHORT uKey
= wxCharCodeWXToOS2( vaEntries
[i
].GetKeyCode()
134 uVirt
= AF_CHAR
| AF_VIRTUALKEY
;
136 USHORT uCmd
= vaEntries
[i
].GetCommand();
138 pArr
->aaccel
[i
].fs
= uVirt
;
139 pArr
->aaccel
[i
].key
= uKey
;
140 pArr
->aaccel
[i
].cmd
= uCmd
;
142 pArr
->codepage
= 437; // default to english Fix???
143 pArr
->cAccel
= (USHORT
)n
;
144 M_ACCELDATA
->m_hAccel
= ::WinCreateAccelTable( vHabmain
147 if (wxTheApp
->GetTopWindow() != NULL
)
150 // If we have accelerators the top window is the frame
152 wxFrame
* pFrame
= (wxFrame
*)wxTheApp
->GetTopWindow();
154 ::WinSetAccelTable( vHabmain
155 ,M_ACCELDATA
->m_hAccel
156 ,(HWND
)pFrame
->GetFrame()
161 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
162 } // end of wxAcceleratorTable::wxAcceleratorTable
164 bool wxAcceleratorTable::Ok() const
166 return(M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
167 } // end of wxAcceleratorTable::Ok
169 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
172 m_refData
= new wxAcceleratorRefData
;
174 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
177 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
181 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
184 bool wxAcceleratorTable::Translate(
189 PQMSG pMsg
= (PQMSG
)pWxmsg
;
191 return Ok() && ::WinTranslateAccel( vHabmain
196 } // end of wxAcceleratorTable::Translate