]>
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 | { | |
64 | DestroyAcceleratorTable((HACCEL) m_hAccel); | |
65 | } | |
66 | m_hAccel = 0 ; | |
67 | } | |
68 | ||
69 | wxAcceleratorTable::wxAcceleratorTable() | |
70 | { | |
71 | m_refData = NULL; | |
72 | } | |
73 | ||
74 | wxAcceleratorTable::~wxAcceleratorTable() | |
75 | { | |
76 | } | |
77 | ||
78 | // Load from .rc resource | |
79 | wxAcceleratorTable::wxAcceleratorTable(const wxString& resource) | |
80 | { | |
81 | m_refData = new wxAcceleratorRefData; | |
82 | ||
83 | HACCEL hAccel = | |
84 | #ifdef __WIN32__ | |
85 | #ifdef UNICODE | |
86 | ::LoadAcceleratorsW(wxGetInstance(), (const char *)resource); | |
87 | #else | |
88 | ::LoadAcceleratorsA(wxGetInstance(), (const char *)resource); | |
89 | #endif | |
90 | #else | |
91 | ::LoadAccelerators(wxGetInstance(), (const char *)resource); | |
92 | #endif | |
93 | M_ACCELDATA->m_hAccel = hAccel; | |
94 | M_ACCELDATA->m_ok = (hAccel != 0); | |
95 | } | |
96 | ||
97 | extern int wxCharCodeWXToMSW(int id, bool *isVirtual); | |
98 | ||
99 | // Create from an array | |
100 | wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) | |
101 | { | |
102 | m_refData = new wxAcceleratorRefData; | |
103 | ||
104 | ACCEL* arr = new ACCEL[n]; | |
105 | int i; | |
106 | for (i = 0; i < n; i++) | |
107 | { | |
108 | BYTE fVirt = 0; | |
109 | if (entries[i].m_flags & wxACCEL_ALT) | |
110 | fVirt |= FALT; | |
111 | if (entries[i].m_flags & wxACCEL_SHIFT) | |
112 | fVirt |= FSHIFT; | |
113 | if (entries[i].m_flags & wxACCEL_CTRL) | |
114 | fVirt |= FCONTROL; | |
115 | ||
116 | bool isVirtual; | |
117 | WORD key = wxCharCodeWXToMSW(entries[i].m_keyCode, & isVirtual); | |
118 | fVirt |= FVIRTKEY; | |
119 | ||
120 | WORD cmd = entries[i].m_command; | |
121 | ||
122 | arr[i].fVirt = fVirt; | |
123 | arr[i].key = key; | |
124 | arr[i].cmd = cmd; | |
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 | } | |
132 | ||
133 | bool wxAcceleratorTable::Ok(void) const | |
134 | { | |
135 | return (M_ACCELDATA && (M_ACCELDATA->m_ok)); | |
136 | } | |
137 | ||
138 | void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel) | |
139 | { | |
140 | if (!M_ACCELDATA) | |
141 | m_refData = new wxAcceleratorRefData; | |
142 | ||
143 | M_ACCELDATA->m_hAccel = (HACCEL) hAccel; | |
144 | } | |
145 | ||
146 | WXHACCEL wxAcceleratorTable::GetHACCEL() const | |
147 | { | |
148 | if (!M_ACCELDATA) | |
149 | return 0; | |
150 | return (WXHACCEL) M_ACCELDATA->m_hAccel; | |
151 | } | |
152 |