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"
24 #include "wx/window.h"
29 #include "wx/msw/private.h"
31 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
33 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
35 friend class WXDLLEXPORT wxAcceleratorTable
;
37 wxAcceleratorRefData();
38 ~wxAcceleratorRefData();
40 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
46 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
48 wxAcceleratorRefData::wxAcceleratorRefData()
54 wxAcceleratorRefData::~wxAcceleratorRefData()
58 // This function not available in WIN16
59 #if !defined(__WIN16__) && !defined(__TWIN32__)
60 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
66 wxAcceleratorTable::wxAcceleratorTable()
71 wxAcceleratorTable::~wxAcceleratorTable()
75 // Load from .rc resource
76 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
78 m_refData
= new wxAcceleratorRefData
;
81 #if defined(__WIN32__) && !defined(__TWIN32__)
83 ::LoadAcceleratorsW(wxGetInstance(), (const wxChar
*)resource
);
85 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
88 ::LoadAccelerators(wxGetInstance(), (const wxChar
*)resource
);
90 M_ACCELDATA
->m_hAccel
= hAccel
;
91 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
94 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
96 // Create from an array
97 #if !defined(__WIN16__) && !defined(__TWIN32__) && !defined(__WXWINE__)
98 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
100 // Not available in WIN16
101 m_refData
= new wxAcceleratorRefData
;
103 ACCEL
* arr
= new ACCEL
[n
];
104 for ( int i
= 0; i
< n
; i
++ )
106 int flags
= entries
[i
].GetFlags();
109 if ( flags
& wxACCEL_ALT
)
110 fVirt
|= FALT
| FVIRTKEY
;
111 if ( flags
& wxACCEL_SHIFT
)
112 fVirt
|= FSHIFT
| FVIRTKEY
;
113 if ( flags
& wxACCEL_CTRL
)
114 fVirt
|= FCONTROL
| FVIRTKEY
;
118 WORD key
= wxCharCodeWXToMSW(entries
[i
].GetKeyCode(), &isVirtual
);
122 arr
[i
].fVirt
= fVirt
;
124 arr
[i
].cmd
= entries
[i
].GetCommand();
127 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
130 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
133 wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n
), const wxAcceleratorEntry
WXUNUSED(entries
)[])
135 // No, we simply gracefully degrade; we don't expect the
136 // developer to pepper their code with #ifdefs just for this.
137 // wxFAIL_MSG("not implemented");
141 bool wxAcceleratorTable::Ok() 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
;
161 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
163 MSG
*msg
= (MSG
*)wxmsg
;
164 return Ok() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
);