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