]> git.saurik.com Git - wxWidgets.git/blame - src/msw/accel.cpp
compilation fix for wxUniv
[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;
44};
45
46#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
47
48wxAcceleratorRefData::wxAcceleratorRefData()
49{
50 m_ok = FALSE;
51 m_hAccel = 0;
52}
53
54wxAcceleratorRefData::~wxAcceleratorRefData()
55{
56 if (m_hAccel)
57 {
1e6d9499 58 // This function not available in WIN16
57c208c5 59#if !defined(__WIN16__) && !defined(__TWIN32__)
110f3205 60 DestroyAcceleratorTable((HACCEL) m_hAccel);
1e6d9499 61#endif
110f3205
JS
62 }
63 m_hAccel = 0 ;
64}
65
66wxAcceleratorTable::wxAcceleratorTable()
67{
68 m_refData = NULL;
69}
70
71wxAcceleratorTable::~wxAcceleratorTable()
72{
73}
74
75// Load from .rc resource
76wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
77{
78 m_refData = new wxAcceleratorRefData;
79
80 HACCEL hAccel =
57c208c5 81#if defined(__WIN32__) && !defined(__TWIN32__)
110f3205 82#ifdef UNICODE
837e5743 83 ::LoadAcceleratorsW(wxGetInstance(), (const wxChar *)resource);
110f3205
JS
84#else
85 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource);
86#endif
87#else
837e5743 88 ::LoadAccelerators(wxGetInstance(), (const wxChar *)resource);
110f3205
JS
89#endif
90 M_ACCELDATA->m_hAccel = hAccel;
91 M_ACCELDATA->m_ok = (hAccel != 0);
92}
93
94extern int wxCharCodeWXToMSW(int id, bool *isVirtual);
95
96// Create from an array
5ea105e0 97#if !defined(__WIN16__) && !defined(__TWIN32__) && !defined(__WXWINE__)
252eb8fd 98wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
110f3205 99{
1e6d9499 100 // Not available in WIN16
110f3205
JS
101 m_refData = new wxAcceleratorRefData;
102
103 ACCEL* arr = new ACCEL[n];
1e6feb95 104 for ( int i = 0; i < n; i++ )
110f3205 105 {
1e6feb95
VZ
106 int flags = entries[i].GetFlags();
107
110f3205 108 BYTE fVirt = 0;
1e6feb95
VZ
109 if ( flags & wxACCEL_ALT )
110 fVirt |= FALT | FVIRTKEY;
111 if ( flags & wxACCEL_SHIFT )
112 fVirt |= FSHIFT | FVIRTKEY;
113 if ( flags & wxACCEL_CTRL )
114 fVirt |= FCONTROL | FVIRTKEY;
110f3205
JS
115
116 bool isVirtual;
1e6feb95
VZ
117
118 WORD key = wxCharCodeWXToMSW(entries[i].GetKeyCode(), &isVirtual);
2317bff2
JS
119 if (isVirtual)
120 fVirt |= FVIRTKEY;
110f3205 121
110f3205
JS
122 arr[i].fVirt = fVirt;
123 arr[i].key = key;
1e6feb95 124 arr[i].cmd = entries[i].GetCommand();
110f3205
JS
125 }
126
127 M_ACCELDATA->m_hAccel = ::CreateAcceleratorTable(arr, n);
128 delete[] arr;
129
130 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
131}
c50f1fb9 132#else // Win16
8870c26e
JS
133wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n), const wxAcceleratorEntry WXUNUSED(entries)[])
134{
1044a386
JS
135 // No, we simply gracefully degrade; we don't expect the
136 // developer to pepper their code with #ifdefs just for this.
137 // wxFAIL_MSG("not implemented");
8870c26e 138}
c50f1fb9 139#endif // Win32/16
110f3205 140
c50f1fb9 141bool wxAcceleratorTable::Ok() const
110f3205
JS
142{
143 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
144}
145
146void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
147{
148 if (!M_ACCELDATA)
149 m_refData = new wxAcceleratorRefData;
150
151 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
152}
153
154WXHACCEL wxAcceleratorTable::GetHACCEL() const
155{
156 if (!M_ACCELDATA)
157 return 0;
158 return (WXHACCEL) M_ACCELDATA->m_hAccel;
159}
160
c50f1fb9
VZ
161bool wxAcceleratorTable::Translate(wxWindow *window, WXMSG *wxmsg) const
162{
163 MSG *msg = (MSG *)wxmsg;
01dba85a
JS
164 return Ok() && ::TranslateAccelerator(GetHwndOf(window), GetHaccel(), msg);
165}
166