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 #if !USE_SHARED_LIBRARIES
34 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
37 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
39 friend class WXDLLEXPORT wxAcceleratorTable
;
41 wxAcceleratorRefData(void);
42 ~wxAcceleratorRefData(void);
44 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
50 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
52 wxAcceleratorRefData::wxAcceleratorRefData()
58 wxAcceleratorRefData::~wxAcceleratorRefData()
62 // This function not available in WIN16
63 #if !defined(__WIN16__) && !defined(__TWIN32__)
64 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
70 wxAcceleratorTable::wxAcceleratorTable()
75 wxAcceleratorTable::~wxAcceleratorTable()
79 // Load from .rc resource
80 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
82 m_refData
= new wxAcceleratorRefData
;
85 #if defined(__WIN32__) && !defined(__TWIN32__)
87 ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource
);
89 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
92 ::LoadAccelerators(wxGetInstance(), (const char *)resource
);
94 M_ACCELDATA
->m_hAccel
= hAccel
;
95 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
98 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
100 // Create from an array
101 #if !defined(__WIN16__) && !defined(__TWIN32__)
102 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
104 // Not available in WIN16
105 m_refData
= new wxAcceleratorRefData
;
107 ACCEL
* arr
= new ACCEL
[n
];
109 for (i
= 0; i
< n
; i
++)
112 if (entries
[i
].m_flags
& wxACCEL_ALT
)
114 if (entries
[i
].m_flags
& wxACCEL_SHIFT
)
116 if (entries
[i
].m_flags
& wxACCEL_CTRL
)
120 WORD key
= wxCharCodeWXToMSW(entries
[i
].m_keyCode
, & isVirtual
);
123 WORD cmd
= entries
[i
].m_command
;
125 arr
[i
].fVirt
= fVirt
;
130 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
133 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
136 wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n
), const wxAcceleratorEntry
WXUNUSED(entries
)[])
141 bool wxAcceleratorTable::Ok(void) const
143 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
146 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
149 m_refData
= new wxAcceleratorRefData
;
151 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
154 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
158 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;