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 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
67 wxAcceleratorTable::wxAcceleratorTable()
72 wxAcceleratorTable::~wxAcceleratorTable()
76 // Load from .rc resource
77 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
79 m_refData
= new wxAcceleratorRefData
;
82 #if defined(__WIN32__)
84 ::LoadAcceleratorsW(wxGetInstance(), (const wxChar
*)resource
);
86 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource
);
89 ::LoadAccelerators(wxGetInstance(), (const wxChar
*)resource
);
91 M_ACCELDATA
->m_hAccel
= hAccel
;
92 M_ACCELDATA
->m_ok
= (hAccel
!= 0);
95 extern int wxCharCodeWXToMSW(int id
, bool *isVirtual
);
97 // Create from an array
98 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
100 m_refData
= new wxAcceleratorRefData
;
102 ACCEL
* arr
= new ACCEL
[n
];
103 for ( int i
= 0; i
< n
; i
++ )
105 int flags
= entries
[i
].GetFlags();
108 if ( flags
& wxACCEL_ALT
)
109 fVirt
|= FALT
| FVIRTKEY
;
110 if ( flags
& wxACCEL_SHIFT
)
111 fVirt
|= FSHIFT
| FVIRTKEY
;
112 if ( flags
& wxACCEL_CTRL
)
113 fVirt
|= FCONTROL
| FVIRTKEY
;
117 WORD key
= wxCharCodeWXToMSW(entries
[i
].GetKeyCode(), &isVirtual
);
121 arr
[i
].fVirt
= fVirt
;
123 arr
[i
].cmd
= entries
[i
].GetCommand();
126 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
129 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
132 bool wxAcceleratorTable::Ok() const
134 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
137 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
140 m_refData
= new wxAcceleratorRefData
;
142 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
145 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
149 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
152 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
154 MSG
*msg
= (MSG
*)wxmsg
;
155 return Ok() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
);