]> git.saurik.com Git - wxWidgets.git/blame - src/msw/accel.cpp
fixed an unused parameter warning
[wxWidgets.git] / src / msw / accel.cpp
CommitLineData
110f3205
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: accel.cpp
3// Purpose: wxAcceleratorTable
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "accel.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20#pragma hdrstop
21#endif
22
23#ifndef WX_PRECOMP
1e6feb95 24 #include "wx/window.h"
110f3205
JS
25#endif
26
1e6feb95 27#include "wx/accel.h"
110f3205 28
48d1144b
JS
29#include "wx/msw/private.h"
30
110f3205 31IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
110f3205
JS
32
33class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
34{
35 friend class WXDLLEXPORT wxAcceleratorTable;
36public:
c50f1fb9
VZ
37 wxAcceleratorRefData();
38 ~wxAcceleratorRefData();
110f3205
JS
39
40 inline HACCEL GetHACCEL() const { return m_hAccel; }
41protected:
42 HACCEL m_hAccel;
43 bool m_ok;
22f3361e
VZ
44
45 DECLARE_NO_COPY_CLASS(wxAcceleratorRefData)
110f3205
JS
46};
47
48#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
49
50wxAcceleratorRefData::wxAcceleratorRefData()
51{
52 m_ok = FALSE;
53 m_hAccel = 0;
54}
55
56wxAcceleratorRefData::~wxAcceleratorRefData()
57{
58 if (m_hAccel)
59 {
1e6d9499 60 // This function not available in WIN16
57c208c5 61#if !defined(__WIN16__) && !defined(__TWIN32__)
110f3205 62 DestroyAcceleratorTable((HACCEL) m_hAccel);
1e6d9499 63#endif
110f3205
JS
64 }
65 m_hAccel = 0 ;
66}
67
68wxAcceleratorTable::wxAcceleratorTable()
69{
70 m_refData = NULL;
71}
72
73wxAcceleratorTable::~wxAcceleratorTable()
74{
75}
76
77// Load from .rc resource
78wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
79{
80 m_refData = new wxAcceleratorRefData;
81
82 HACCEL hAccel =
57c208c5 83#if defined(__WIN32__) && !defined(__TWIN32__)
110f3205 84#ifdef UNICODE
837e5743 85 ::LoadAcceleratorsW(wxGetInstance(), (const wxChar *)resource);
110f3205
JS
86#else
87 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource);
88#endif
89#else
837e5743 90 ::LoadAccelerators(wxGetInstance(), (const wxChar *)resource);
110f3205
JS
91#endif
92 M_ACCELDATA->m_hAccel = hAccel;
93 M_ACCELDATA->m_ok = (hAccel != 0);
94}
95
96extern int wxCharCodeWXToMSW(int id, bool *isVirtual);
97
98// Create from an array
b4da152e 99#if !defined(__WIN16__) && !defined(__TWIN32__)
252eb8fd 100wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
110f3205 101{
1e6d9499 102 // Not available in WIN16
110f3205
JS
103 m_refData = new wxAcceleratorRefData;
104
105 ACCEL* arr = new ACCEL[n];
1e6feb95 106 for ( int i = 0; i < n; i++ )
110f3205 107 {
1e6feb95
VZ
108 int flags = entries[i].GetFlags();
109
110f3205 110 BYTE fVirt = 0;
1e6feb95
VZ
111 if ( flags & wxACCEL_ALT )
112 fVirt |= FALT | FVIRTKEY;
113 if ( flags & wxACCEL_SHIFT )
114 fVirt |= FSHIFT | FVIRTKEY;
115 if ( flags & wxACCEL_CTRL )
116 fVirt |= FCONTROL | FVIRTKEY;
110f3205
JS
117
118 bool isVirtual;
1e6feb95
VZ
119
120 WORD key = wxCharCodeWXToMSW(entries[i].GetKeyCode(), &isVirtual);
2317bff2
JS
121 if (isVirtual)
122 fVirt |= FVIRTKEY;
110f3205 123
110f3205
JS
124 arr[i].fVirt = fVirt;
125 arr[i].key = key;
1e6feb95 126 arr[i].cmd = entries[i].GetCommand();
110f3205
JS
127 }
128
129 M_ACCELDATA->m_hAccel = ::CreateAcceleratorTable(arr, n);
130 delete[] arr;
131
132 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
133}
c50f1fb9 134#else // Win16
8870c26e
JS
135wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n), const wxAcceleratorEntry WXUNUSED(entries)[])
136{
1044a386
JS
137 // No, we simply gracefully degrade; we don't expect the
138 // developer to pepper their code with #ifdefs just for this.
139 // wxFAIL_MSG("not implemented");
8870c26e 140}
c50f1fb9 141#endif // Win32/16
110f3205 142
c50f1fb9 143bool wxAcceleratorTable::Ok() const
110f3205
JS
144{
145 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
146}
147
148void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
149{
150 if (!M_ACCELDATA)
151 m_refData = new wxAcceleratorRefData;
152
153 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
154}
155
156WXHACCEL wxAcceleratorTable::GetHACCEL() const
157{
158 if (!M_ACCELDATA)
159 return 0;
160 return (WXHACCEL) M_ACCELDATA->m_hAccel;
161}
162
c50f1fb9
VZ
163bool wxAcceleratorTable::Translate(wxWindow *window, WXMSG *wxmsg) const
164{
165 MSG *msg = (MSG *)wxmsg;
01dba85a
JS
166 return Ok() && ::TranslateAccelerator(GetHwndOf(window), GetHaccel(), msg);
167}
168