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