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/private.h"
30 #include "wx/msw/accel.h"
32 #ifdef LoadAccelerators
33 #undef LoadAccelerators
36 #if !USE_SHARED_LIBRARIES
37 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
40 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
42 friend class WXDLLEXPORT wxAcceleratorTable
;
44 wxAcceleratorRefData(void);
45 ~wxAcceleratorRefData(void);
47 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
53 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
55 wxAcceleratorRefData::wxAcceleratorRefData()
61 wxAcceleratorRefData::~wxAcceleratorRefData()
65 // This function not available in WIN16
66 #if !defined(__WIN16__) && !defined(__TWIN32__)
67 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
73 wxAcceleratorTable::wxAcceleratorTable()
78 wxAcceleratorTable::~wxAcceleratorTable()
82 // Load from .rc resource
83 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
85 m_refData
= new wxAcceleratorRefData
;
88 #if defined(__WIN32__) && !defined(__TWIN32__)
90 ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource
);
92 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
95 ::LoadAccelerators(wxGetInstance(), (const char *)resource
);
97 M_ACCELDATA
->m_hAccel
= hAccel
;
98 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
101 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
103 // Create from an array
104 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
106 // Not available in WIN16
107 #if !defined(__WIN16__) && !defined(__TWIN32__)
108 m_refData
= new wxAcceleratorRefData
;
110 ACCEL
* arr
= new ACCEL
[n
];
112 for (i
= 0; i
< n
; i
++)
115 if (entries
[i
].m_flags
& wxACCEL_ALT
)
117 if (entries
[i
].m_flags
& wxACCEL_SHIFT
)
119 if (entries
[i
].m_flags
& wxACCEL_CTRL
)
123 WORD key
= wxCharCodeWXToMSW(entries
[i
].m_keyCode
, & isVirtual
);
126 WORD cmd
= entries
[i
].m_command
;
128 arr
[i
].fVirt
= fVirt
;
133 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
136 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
140 bool wxAcceleratorTable::Ok(void) const
142 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
145 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
148 m_refData
= new wxAcceleratorRefData
;
150 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
153 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
157 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;