]> git.saurik.com Git - wxWidgets.git/blob - src/msw/accel.cpp
Implement support for gradient stops for OS X.
[wxWidgets.git] / src / msw / accel.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/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 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_ACCEL
28
29 #ifndef WX_PRECOMP
30 #include "wx/window.h"
31 #endif
32
33 #include "wx/accel.h"
34
35 #include "wx/msw/private.h"
36
37 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
38
39 // ----------------------------------------------------------------------------
40 // data defining wxAcceleratorTable
41 // ----------------------------------------------------------------------------
42
43 class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
44 {
45 friend class WXDLLIMPEXP_FWD_CORE wxAcceleratorTable;
46 public:
47 wxAcceleratorRefData();
48 virtual ~wxAcceleratorRefData();
49
50 inline HACCEL GetHACCEL() const { return m_hAccel; }
51 protected:
52 HACCEL m_hAccel;
53 bool m_ok;
54
55 wxDECLARE_NO_COPY_CLASS(wxAcceleratorRefData);
56 };
57
58 // ============================================================================
59 // implementation
60 // ============================================================================
61
62 // ----------------------------------------------------------------------------
63 // wxAcceleratorRefData
64 // ----------------------------------------------------------------------------
65
66 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
67
68 wxAcceleratorRefData::wxAcceleratorRefData()
69 {
70 m_ok = false;
71 m_hAccel = 0;
72 }
73
74 wxAcceleratorRefData::~wxAcceleratorRefData()
75 {
76 if (m_hAccel)
77 {
78 DestroyAcceleratorTable((HACCEL) m_hAccel);
79 }
80 }
81
82 // ----------------------------------------------------------------------------
83 // wxAcceleratorTable
84 // ----------------------------------------------------------------------------
85
86 // Load from .rc resource
87 wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
88 {
89 m_refData = new wxAcceleratorRefData;
90
91 HACCEL hAccel = ::LoadAccelerators(wxGetInstance(), resource.wx_str());
92 M_ACCELDATA->m_hAccel = hAccel;
93 M_ACCELDATA->m_ok = hAccel != 0;
94 }
95
96 // Create from an array
97 wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
98 {
99 m_refData = new wxAcceleratorRefData;
100
101 ACCEL* arr = new ACCEL[n];
102 for ( int i = 0; i < n; i++ )
103 {
104 int flags = entries[i].GetFlags();
105
106 BYTE fVirt = FVIRTKEY;
107 if ( flags & wxACCEL_ALT )
108 fVirt |= FALT;
109 if ( flags & wxACCEL_SHIFT )
110 fVirt |= FSHIFT;
111 if ( flags & wxACCEL_CTRL )
112 fVirt |= FCONTROL;
113
114 WORD key = wxCharCodeWXToMSW(entries[i].GetKeyCode());
115
116 arr[i].fVirt = fVirt;
117 arr[i].key = key;
118 arr[i].cmd = (WORD)entries[i].GetCommand();
119 }
120
121 M_ACCELDATA->m_hAccel = ::CreateAcceleratorTable(arr, n);
122 delete[] arr;
123
124 M_ACCELDATA->m_ok = (M_ACCELDATA->m_hAccel != 0);
125 }
126
127 bool wxAcceleratorTable::IsOk() const
128 {
129 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
130 }
131
132 void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
133 {
134 if (!M_ACCELDATA)
135 m_refData = new wxAcceleratorRefData;
136
137 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
138 }
139
140 WXHACCEL wxAcceleratorTable::GetHACCEL() const
141 {
142 if (!M_ACCELDATA)
143 return 0;
144 return (WXHACCEL) M_ACCELDATA->m_hAccel;
145 }
146
147 bool wxAcceleratorTable::Translate(wxWindow *window, WXMSG *wxmsg) const
148 {
149 MSG *msg = (MSG *)wxmsg;
150 return Ok() && ::TranslateAccelerator(GetHwndOf(window), GetHaccel(), msg);
151 }
152
153 #endif // wxUSE_ACCEL
154