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 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
69 wxAcceleratorTable::wxAcceleratorTable()
74 wxAcceleratorTable::~wxAcceleratorTable()
78 // Load from .rc resource
79 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
81 m_refData
= new wxAcceleratorRefData
;
86 ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource
);
88 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
91 ::LoadAccelerators(wxGetInstance(), (const char *)resource
);
93 M_ACCELDATA
->m_hAccel
= hAccel
;
94 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
97 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
99 // Create from an array
100 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
102 m_refData
= new wxAcceleratorRefData
;
104 ACCEL
* arr
= new ACCEL
[n
];
106 for (i
= 0; i
< n
; i
++)
109 if (entries
[i
].m_flags
& wxACCEL_ALT
)
111 if (entries
[i
].m_flags
& wxACCEL_SHIFT
)
113 if (entries
[i
].m_flags
& wxACCEL_CTRL
)
117 WORD key
= wxCharCodeWXToMSW(entries
[i
].m_keyCode
, & isVirtual
);
120 WORD cmd
= entries
[i
].m_command
;
122 arr
[i
].fVirt
= fVirt
;
127 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
130 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
133 bool wxAcceleratorTable::Ok(void) const
135 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
138 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
141 m_refData
= new wxAcceleratorRefData
;
143 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
146 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
150 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;