1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "accel.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/window.h"
29 #include "wx/msw/accel.h"
31 #include "wx/msw/private.h"
33 #ifdef LoadAccelerators
34 #undef LoadAccelerators
37 #if !USE_SHARED_LIBRARIES
38 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
41 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
43 friend class WXDLLEXPORT wxAcceleratorTable
;
45 wxAcceleratorRefData(void);
46 ~wxAcceleratorRefData(void);
48 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
54 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
56 wxAcceleratorRefData::wxAcceleratorRefData()
62 wxAcceleratorRefData::~wxAcceleratorRefData()
66 // This function not available in WIN16
67 #if !defined(__WIN16__) && !defined(__TWIN32__)
68 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
74 wxAcceleratorTable::wxAcceleratorTable()
79 wxAcceleratorTable::~wxAcceleratorTable()
83 // Load from .rc resource
84 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
86 m_refData
= new wxAcceleratorRefData
;
89 #if defined(__WIN32__) && !defined(__TWIN32__)
91 ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource
);
93 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
96 ::LoadAccelerators(wxGetInstance(), (const char *)resource
);
98 M_ACCELDATA
->m_hAccel
= hAccel
;
99 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
102 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
104 // Create from an array
105 #if !defined(__WIN16__) && !defined(__TWIN32__)
106 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
108 // Not available in WIN16
109 m_refData
= new wxAcceleratorRefData
;
111 ACCEL
* arr
= new ACCEL
[n
];
113 for (i
= 0; i
< n
; i
++)
116 if (entries
[i
].m_flags
& wxACCEL_ALT
)
118 if (entries
[i
].m_flags
& wxACCEL_SHIFT
)
120 if (entries
[i
].m_flags
& wxACCEL_CTRL
)
124 WORD key
= wxCharCodeWXToMSW(entries
[i
].m_keyCode
, & isVirtual
);
127 WORD cmd
= entries
[i
].m_command
;
129 arr
[i
].fVirt
= fVirt
;
134 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
137 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
140 wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n
), const wxAcceleratorEntry
WXUNUSED(entries
)[])
145 bool wxAcceleratorTable::Ok(void) const
147 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
150 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
153 m_refData
= new wxAcceleratorRefData
;
155 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
158 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
162 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;