]> git.saurik.com Git - wxWidgets.git/blame - src/msw/accel.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / msw / accel.cpp
CommitLineData
110f3205 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/msw/accel.cpp
110f3205
JS
3// Purpose: wxAcceleratorTable
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
110f3205 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
110f3205
JS
9/////////////////////////////////////////////////////////////////////////////
10
a21d4ad1
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
a21d4ad1
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
110f3205
JS
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
22#ifdef __BORLANDC__
a21d4ad1 23 #pragma hdrstop
110f3205
JS
24#endif
25
a21d4ad1
VZ
26#if wxUSE_ACCEL
27
110f3205 28#ifndef WX_PRECOMP
1e6feb95 29 #include "wx/window.h"
110f3205
JS
30#endif
31
1e6feb95 32#include "wx/accel.h"
110f3205 33
48d1144b 34#include "wx/msw/private.h"
0c03f52d 35#include "wx/msw/private/keyboard.h"
48d1144b 36
110f3205 37IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
110f3205 38
a21d4ad1
VZ
39// ----------------------------------------------------------------------------
40// data defining wxAcceleratorTable
41// ----------------------------------------------------------------------------
42
110f3205
JS
43class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
44{
f5851311 45 friend class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable;
110f3205 46public:
c50f1fb9 47 wxAcceleratorRefData();
d3c7fc99 48 virtual ~wxAcceleratorRefData();
110f3205
JS
49
50 inline HACCEL GetHACCEL() const { return m_hAccel; }
51protected:
52 HACCEL m_hAccel;
53 bool m_ok;
22f3361e 54
c0c133e1 55 wxDECLARE_NO_COPY_CLASS(wxAcceleratorRefData);
110f3205
JS
56};
57
a21d4ad1
VZ
58// ============================================================================
59// implementation
60// ============================================================================
61
62// ----------------------------------------------------------------------------
63// wxAcceleratorRefData
64// ----------------------------------------------------------------------------
65
110f3205
JS
66#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
67
68wxAcceleratorRefData::wxAcceleratorRefData()
69{
a21d4ad1
VZ
70 m_ok = false;
71 m_hAccel = 0;
110f3205
JS
72}
73
74wxAcceleratorRefData::~wxAcceleratorRefData()
75{
a21d4ad1
VZ
76 if (m_hAccel)
77 {
78 DestroyAcceleratorTable((HACCEL) m_hAccel);
79 }
110f3205
JS
80}
81
a21d4ad1
VZ
82// ----------------------------------------------------------------------------
83// wxAcceleratorTable
84// ----------------------------------------------------------------------------
110f3205
JS
85
86// Load from .rc resource
87wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
88{
89 m_refData = new wxAcceleratorRefData;
90
017dc06b 91 HACCEL hAccel = ::LoadAccelerators(wxGetInstance(), resource.t_str());
110f3205 92 M_ACCELDATA->m_hAccel = hAccel;
a21d4ad1 93 M_ACCELDATA->m_ok = hAccel != 0;
110f3205
JS
94}
95
110f3205 96// Create from an array
252eb8fd 97wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
110f3205
JS
98{
99 m_refData = new wxAcceleratorRefData;
100
101 ACCEL* arr = new ACCEL[n];
1e6feb95 102 for ( int i = 0; i < n; i++ )
110f3205 103 {
1e6feb95
VZ
104 int flags = entries[i].GetFlags();
105
4f04a4fd 106 BYTE fVirt = FVIRTKEY;
1e6feb95 107 if ( flags & wxACCEL_ALT )
4f04a4fd 108 fVirt |= FALT;
1e6feb95 109 if ( flags & wxACCEL_SHIFT )
4f04a4fd 110 fVirt |= FSHIFT;
1e6feb95 111 if ( flags & wxACCEL_CTRL )
4f04a4fd 112 fVirt |= FCONTROL;
1e6feb95 113
0c03f52d 114 WORD key = wxMSWKeyboard::WXToVK(entries[i].GetKeyCode());
110f3205 115
110f3205
JS
116 arr[i].fVirt = fVirt;
117 arr[i].key = key;
373a5fb3 118 arr[i].cmd = (WORD)entries[i].GetCommand();
110f3205
JS
119 }
120
121 M_ACCELDATA->m_hAccel = ::CreateAcceleratorTable(arr, n);
122 delete[] arr;
123
124 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
125}
126
b7cacb43 127bool wxAcceleratorTable::IsOk() const
110f3205
JS
128{
129 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
130}
131
132void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
133{
134 if (!M_ACCELDATA)
135 m_refData = new wxAcceleratorRefData;
136
137 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
138}
139
140WXHACCEL wxAcceleratorTable::GetHACCEL() const
141{
142 if (!M_ACCELDATA)
143 return 0;
144 return (WXHACCEL) M_ACCELDATA->m_hAccel;
145}
146
c50f1fb9
VZ
147bool wxAcceleratorTable::Translate(wxWindow *window, WXMSG *wxmsg) const
148{
149 MSG *msg = (MSG *)wxmsg;
a1b806b9 150 return IsOk() && ::TranslateAccelerator(GetHwndOf(window), GetHaccel(), msg);
01dba85a
JS
151}
152
a21d4ad1
VZ
153#endif // wxUSE_ACCEL
154