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"
31 #include "wx/msw/private.h"
33 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
35 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
37 friend class WXDLLEXPORT wxAcceleratorTable
;
39 wxAcceleratorRefData();
40 ~wxAcceleratorRefData();
42 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
47 DECLARE_NO_COPY_CLASS(wxAcceleratorRefData
)
50 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
52 wxAcceleratorRefData::wxAcceleratorRefData()
58 wxAcceleratorRefData::~wxAcceleratorRefData()
62 // This function not available in WIN16
63 #if !defined(__WIN16__)
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__)
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__)
102 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
104 // Not available in WIN16
105 m_refData
= new wxAcceleratorRefData
;
107 ACCEL
* arr
= new ACCEL
[n
];
108 for ( int i
= 0; i
< n
; i
++ )
110 int flags
= entries
[i
].GetFlags();
113 if ( flags
& wxACCEL_ALT
)
114 fVirt
|= FALT
| FVIRTKEY
;
115 if ( flags
& wxACCEL_SHIFT
)
116 fVirt
|= FSHIFT
| FVIRTKEY
;
117 if ( flags
& wxACCEL_CTRL
)
118 fVirt
|= FCONTROL
| FVIRTKEY
;
122 WORD key
= wxCharCodeWXToMSW(entries
[i
].GetKeyCode(), &isVirtual
);
126 arr
[i
].fVirt
= fVirt
;
128 arr
[i
].cmd
= entries
[i
].GetCommand();
131 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
134 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
137 wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n
), const wxAcceleratorEntry
WXUNUSED(entries
)[])
139 // No, we simply gracefully degrade; we don't expect the
140 // developer to pepper their code with #ifdefs just for this.
141 // wxFAIL_MSG("not implemented");
145 bool wxAcceleratorTable::Ok() const
147 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
150 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
153 m_refData
= new wxAcceleratorRefData
;
155 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
158 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
162 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
165 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
167 MSG
*msg
= (MSG
*)wxmsg
;
168 return Ok() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
);