]> git.saurik.com Git - wxWidgets.git/blame - src/msw/accel.cpp
Compilation fixes for PCH-less build after ownerdraw-refactor branch merge.
[wxWidgets.git] / src / msw / accel.cpp
CommitLineData
110f3205 1/////////////////////////////////////////////////////////////////////////////
a21d4ad1 2// Name: msw/accel.cpp
110f3205
JS
3// Purpose: wxAcceleratorTable
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
110f3205
JS
10/////////////////////////////////////////////////////////////////////////////
11
a21d4ad1
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
a21d4ad1
VZ
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
110f3205
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
a21d4ad1 24 #pragma hdrstop
110f3205
JS
25#endif
26
a21d4ad1
VZ
27#if wxUSE_ACCEL
28
110f3205 29#ifndef WX_PRECOMP
1e6feb95 30 #include "wx/window.h"
110f3205
JS
31#endif
32
1e6feb95 33#include "wx/accel.h"
110f3205 34
48d1144b
JS
35#include "wx/msw/private.h"
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
e0a050e3 91 HACCEL hAccel = ::LoadAccelerators(wxGetInstance(), resource.wx_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
4f04a4fd 114 WORD key = wxCharCodeWXToMSW(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;
01dba85a
JS
150 return Ok() && ::TranslateAccelerator(GetHwndOf(window), GetHaccel(), msg);
151}
152
a21d4ad1
VZ
153#endif // wxUSE_ACCEL
154