1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/window.h"
34 #include "wx/msw/private.h"
35 #include "wx/msw/private/keyboard.h"
37 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
39 // ----------------------------------------------------------------------------
40 // data defining wxAcceleratorTable
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
45 friend class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable
;
47 wxAcceleratorRefData();
48 virtual ~wxAcceleratorRefData();
50 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
55 wxDECLARE_NO_COPY_CLASS(wxAcceleratorRefData
);
58 // ============================================================================
60 // ============================================================================
62 // ----------------------------------------------------------------------------
63 // wxAcceleratorRefData
64 // ----------------------------------------------------------------------------
66 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
68 wxAcceleratorRefData::wxAcceleratorRefData()
74 wxAcceleratorRefData::~wxAcceleratorRefData()
78 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 // Load from .rc resource
87 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
89 m_refData
= new wxAcceleratorRefData
;
91 HACCEL hAccel
= ::LoadAccelerators(wxGetInstance(), resource
.t_str());
92 M_ACCELDATA
->m_hAccel
= hAccel
;
93 M_ACCELDATA
->m_ok
= hAccel
!= 0;
96 // Create from an array
97 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[])
99 m_refData
= new wxAcceleratorRefData
;
101 ACCEL
* arr
= new ACCEL
[n
];
102 for ( int i
= 0; i
< n
; i
++ )
104 int flags
= entries
[i
].GetFlags();
106 BYTE fVirt
= FVIRTKEY
;
107 if ( flags
& wxACCEL_ALT
)
109 if ( flags
& wxACCEL_SHIFT
)
111 if ( flags
& wxACCEL_CTRL
)
114 WORD key
= wxMSWKeyboard::WXToVK(entries
[i
].GetKeyCode());
116 arr
[i
].fVirt
= fVirt
;
118 arr
[i
].cmd
= (WORD
)entries
[i
].GetCommand();
121 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
124 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
127 bool wxAcceleratorTable::IsOk() const
129 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
132 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
135 m_refData
= new wxAcceleratorRefData
;
137 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
140 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
144 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
147 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
149 MSG
*msg
= (MSG
*)wxmsg
;
150 return IsOk() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
);
153 #endif // wxUSE_ACCEL