1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/accel.cpp
3 // Purpose: wxAcceleratorTable
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/window.h"
35 #include "wx/msw/private.h"
36 #include "wx/msw/private/keyboard.h"
38 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
)
40 // ----------------------------------------------------------------------------
41 // data defining wxAcceleratorTable
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
46 friend class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable
;
48 wxAcceleratorRefData();
49 virtual ~wxAcceleratorRefData();
51 inline HACCEL
GetHACCEL() const { return m_hAccel
; }
56 wxDECLARE_NO_COPY_CLASS(wxAcceleratorRefData
);
59 // ============================================================================
61 // ============================================================================
63 // ----------------------------------------------------------------------------
64 // wxAcceleratorRefData
65 // ----------------------------------------------------------------------------
67 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
69 wxAcceleratorRefData::wxAcceleratorRefData()
75 wxAcceleratorRefData::~wxAcceleratorRefData()
79 DestroyAcceleratorTable((HACCEL
) m_hAccel
);
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 // Load from .rc resource
88 wxAcceleratorTable::wxAcceleratorTable(const wxString
& resource
)
90 m_refData
= new wxAcceleratorRefData
;
92 HACCEL hAccel
= ::LoadAccelerators(wxGetInstance(), resource
.wx_str());
93 M_ACCELDATA
->m_hAccel
= hAccel
;
94 M_ACCELDATA
->m_ok
= hAccel
!= 0;
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();
107 BYTE fVirt
= FVIRTKEY
;
108 if ( flags
& wxACCEL_ALT
)
110 if ( flags
& wxACCEL_SHIFT
)
112 if ( flags
& wxACCEL_CTRL
)
115 WORD key
= wxMSWKeyboard::WXToVK(entries
[i
].GetKeyCode());
117 arr
[i
].fVirt
= fVirt
;
119 arr
[i
].cmd
= (WORD
)entries
[i
].GetCommand();
122 M_ACCELDATA
->m_hAccel
= ::CreateAcceleratorTable(arr
, n
);
125 M_ACCELDATA
->m_ok
= (M_ACCELDATA
->m_hAccel
!= 0);
128 bool wxAcceleratorTable::IsOk() const
130 return (M_ACCELDATA
&& (M_ACCELDATA
->m_ok
));
133 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel
)
136 m_refData
= new wxAcceleratorRefData
;
138 M_ACCELDATA
->m_hAccel
= (HACCEL
) hAccel
;
141 WXHACCEL
wxAcceleratorTable::GetHACCEL() const
145 return (WXHACCEL
) M_ACCELDATA
->m_hAccel
;
148 bool wxAcceleratorTable::Translate(wxWindow
*window
, WXMSG
*wxmsg
) const
150 MSG
*msg
= (MSG
*)wxmsg
;
151 return Ok() && ::TranslateAccelerator(GetHwndOf(window
), GetHaccel(), msg
);
154 #endif // wxUSE_ACCEL