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"
28 #include "wx/msw/private.h"
29 #include "wx/msw/accel.h"
31 #ifdef LoadAccelerators
32 #undef LoadAccelerators
35 #if !USE_SHARED_LIBRARIES
36 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
39 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
41 friend class WXDLLEXPORT wxAcceleratorTable
;
43 wxAcceleratorRefData(void);
44 ~wxAcceleratorRefData(void);
46 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
52 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
54 wxAcceleratorRefData::wxAcceleratorRefData()
60 wxAcceleratorRefData::~wxAcceleratorRefData()
64 // This function not available in WIN16
66 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
72 wxAcceleratorTable::wxAcceleratorTable()
77 wxAcceleratorTable::~wxAcceleratorTable()
81 // Load from .rc resource
82 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
84 m_refData
= new wxAcceleratorRefData
;
89 ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource
);
91 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
94 ::LoadAccelerators(wxGetInstance(), (const char *)resource
);
96 M_ACCELDATA
->m_hAccel
= hAccel
;
97 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
100 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
102 // Create from an array
103 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
105 // Not available in WIN16
107 m_refData
= new wxAcceleratorRefData
;
109 ACCEL
* arr
= new ACCEL
[n
];
111 for (i
= 0; i
< n
; i
++)
114 if (entries
[i
].m_flags
& wxACCEL_ALT
)
116 if (entries
[i
].m_flags
& wxACCEL_SHIFT
)
118 if (entries
[i
].m_flags
& wxACCEL_CTRL
)
122 WORD key
= wxCharCodeWXToMSW(entries
[i
].m_keyCode
, & isVirtual
);
125 WORD cmd
= entries
[i
].m_command
;
127 arr
[i
].fVirt
= fVirt
;
132 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
135 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
139 bool wxAcceleratorTable::Ok(void) const
141 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
144 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
147 m_refData
= new wxAcceleratorRefData
;
149 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
152 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
156 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;