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();
42 ~wxAcceleratorRefData();
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 wxChar
*)resource
);
89 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
92 ::LoadAccelerators(wxGetInstance(), (const wxChar
*)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__) && !defined(__WXWINE__)
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
)[])
138 // No, we simply gracefully degrade; we don't expect the
139 // developer to pepper their code with #ifdefs just for this.
140 // wxFAIL_MSG("not implemented");
144 bool wxAcceleratorTable::Ok() const
146 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
149 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
152 m_refData
= new wxAcceleratorRefData
;
154 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
157 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
161 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
164 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
166 MSG
*msg
= (MSG
*)wxmsg
;
168 return Ok() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
); }