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