]> git.saurik.com Git - wxWidgets.git/blob - src/msw/accel.cpp
Some changes in a vain attempt to make Salford C++ work; added FAQ files;
[wxWidgets.git] / src / msw / accel.cpp
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
24 #include <stdio.h>
25 #include "wx/setup.h"
26 #include "wx/window.h"
27 #endif
28
29 #include "wx/msw/private.h"
30 #include "wx/msw/accel.h"
31
32 #ifdef LoadAccelerators
33 #undef LoadAccelerators
34 #endif
35
36 #if !USE_SHARED_LIBRARIES
37 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
38 #endif
39
40 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
41 {
42 friend class WXDLLEXPORT wxAcceleratorTable;
43 public:
44 wxAcceleratorRefData(void);
45 ~wxAcceleratorRefData(void);
46
47 inline HACCEL GetHACCEL() const { return m_hAccel; }
48 protected:
49 HACCEL m_hAccel;
50 bool m_ok;
51 };
52
53 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
54
55 wxAcceleratorRefData::wxAcceleratorRefData()
56 {
57 m_ok = FALSE;
58 m_hAccel = 0;
59 }
60
61 wxAcceleratorRefData::~wxAcceleratorRefData()
62 {
63 if (m_hAccel)
64 {
65 // This function not available in WIN16
66 #ifndef __WIN16__
67 DestroyAcceleratorTable((HACCEL) m_hAccel);
68 #endif
69 }
70 m_hAccel = 0 ;
71 }
72
73 wxAcceleratorTable::wxAcceleratorTable()
74 {
75 m_refData = NULL;
76 }
77
78 wxAcceleratorTable::~wxAcceleratorTable()
79 {
80 }
81
82 // Load from .rc resource
83 wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
84 {
85 m_refData = new wxAcceleratorRefData;
86
87 HACCEL hAccel =
88 #ifdef __WIN32__
89 #ifdef UNICODE
90 ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource);
91 #else
92 ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource);
93 #endif
94 #else
95 ::LoadAccelerators(wxGetInstance(), (const char *)resource);
96 #endif
97 M_ACCELDATA->m_hAccel = hAccel;
98 M_ACCELDATA->m_ok = (hAccel != 0);
99 }
100
101 extern int wxCharCodeWXToMSW(int id, bool *isVirtual);
102
103 // Create from an array
104 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
105 {
106 // Not available in WIN16
107 #ifndef __WIN16__
108 m_refData = new wxAcceleratorRefData;
109
110 ACCEL* arr = new ACCEL[n];
111 int i;
112 for (i = 0; i < n; i++)
113 {
114 BYTE fVirt = 0;
115 if (entries[i].m_flags & wxACCEL_ALT)
116 fVirt |= FALT;
117 if (entries[i].m_flags & wxACCEL_SHIFT)
118 fVirt |= FSHIFT;
119 if (entries[i].m_flags & wxACCEL_CTRL)
120 fVirt |= FCONTROL;
121
122 bool isVirtual;
123 WORD key = wxCharCodeWXToMSW(entries[i].m_keyCode, & isVirtual);
124 fVirt |= FVIRTKEY;
125
126 WORD cmd = entries[i].m_command;
127
128 arr[i].fVirt = fVirt;
129 arr[i].key = key;
130 arr[i].cmd = cmd;
131 }
132
133 M_ACCELDATA->m_hAccel = ::CreateAcceleratorTable(arr, n);
134 delete[] arr;
135
136 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
137 #endif
138 }
139
140 bool wxAcceleratorTable::Ok(void) const
141 {
142 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
143 }
144
145 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
146 {
147 if (!M_ACCELDATA)
148 m_refData = new wxAcceleratorRefData;
149
150 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
151 }
152
153 WXHACCEL wxAcceleratorTable::GetHACCEL() const
154 {
155 if (!M_ACCELDATA)
156 return 0;
157 return (WXHACCEL) M_ACCELDATA->m_hAccel;
158 }
159