1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
; }
45 DECLARE_NO_COPY_CLASS(wxAcceleratorRefData
)
48 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
50 wxAcceleratorRefData::wxAcceleratorRefData()
56 wxAcceleratorRefData::~wxAcceleratorRefData()
60 // This function not available in WIN16
61 #if !defined(__WIN16__)
62 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
68 wxAcceleratorTable::wxAcceleratorTable()
73 wxAcceleratorTable::~wxAcceleratorTable()
77 // Load from .rc resource
78 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
80 m_refData
= new wxAcceleratorRefData
;
83 #if defined(__WIN32__)
85 ::LoadAcceleratorsW(wxGetInstance(), (const wxChar
*)resource
);
87 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
90 ::LoadAccelerators(wxGetInstance(), (const wxChar
*)resource
);
92 M_ACCELDATA
->m_hAccel
= hAccel
;
93 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
96 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
98 // Create from an array
99 #if !defined(__WIN16__)
100 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
102 // Not available in WIN16
103 m_refData
= new wxAcceleratorRefData
;
105 ACCEL
* arr
= new ACCEL
[n
];
106 for ( int i
= 0; i
< n
; i
++ )
108 int flags
= entries
[i
].GetFlags();
111 if ( flags
& wxACCEL_ALT
)
112 fVirt
|= FALT
| FVIRTKEY
;
113 if ( flags
& wxACCEL_SHIFT
)
114 fVirt
|= FSHIFT
| FVIRTKEY
;
115 if ( flags
& wxACCEL_CTRL
)
116 fVirt
|= FCONTROL
| FVIRTKEY
;
120 WORD key
= wxCharCodeWXToMSW(entries
[i
].GetKeyCode(), &isVirtual
);
124 arr
[i
].fVirt
= fVirt
;
126 arr
[i
].cmd
= entries
[i
].GetCommand();
129 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
132 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
135 wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n
), const wxAcceleratorEntry
WXUNUSED(entries
)[])
137 // No, we simply gracefully degrade; we don't expect the
138 // developer to pepper their code with #ifdefs just for this.
139 // wxFAIL_MSG("not implemented");
143 bool wxAcceleratorTable::Ok() const
145 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
148 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
151 m_refData
= new wxAcceleratorRefData
;
153 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
156 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
160 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
163 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
165 MSG
*msg
= (MSG
*)wxmsg
;
166 return Ok() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
);