]> git.saurik.com Git - wxWidgets.git/blame - src/msw/accel.cpp
wxEVT_COMMAND_CHOICE_SELECTED => wxEVT_COMMAND_COMBOBOX_SELECTED
[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#ifdef LoadAccelerators
34#undef LoadAccelerators
35#endif
36
37#if !USE_SHARED_LIBRARIES
38IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
39#endif
40
41class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
42{
43 friend class WXDLLEXPORT wxAcceleratorTable;
44public:
45 wxAcceleratorRefData(void);
46 ~wxAcceleratorRefData(void);
47
48 inline HACCEL GetHACCEL() const { return m_hAccel; }
49protected:
50 HACCEL m_hAccel;
51 bool m_ok;
52};
53
54#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
55
56wxAcceleratorRefData::wxAcceleratorRefData()
57{
58 m_ok = FALSE;
59 m_hAccel = 0;
60}
61
62wxAcceleratorRefData::~wxAcceleratorRefData()
63{
64 if (m_hAccel)
65 {
1e6d9499 66 // This function not available in WIN16
57c208c5 67#if !defined(__WIN16__) && !defined(__TWIN32__)
110f3205 68 DestroyAcceleratorTable((HACCEL) m_hAccel);
1e6d9499 69#endif
110f3205
JS
70 }
71 m_hAccel = 0 ;
72}
73
74wxAcceleratorTable::wxAcceleratorTable()
75{
76 m_refData = NULL;
77}
78
79wxAcceleratorTable::~wxAcceleratorTable()
80{
81}
82
83// Load from .rc resource
84wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
85{
86 m_refData = new wxAcceleratorRefData;
87
88 HACCEL hAccel =
57c208c5 89#if defined(__WIN32__) && !defined(__TWIN32__)
110f3205
JS
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
102extern int wxCharCodeWXToMSW(int id, bool *isVirtual);
103
104// Create from an array
252eb8fd 105wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
110f3205 106{
1e6d9499 107 // Not available in WIN16
57c208c5 108#if !defined(__WIN16__) && !defined(__TWIN32__)
110f3205
JS
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);
1e6d9499 138#endif
110f3205
JS
139}
140
141bool wxAcceleratorTable::Ok(void) const
142{
143 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
144}
145
146void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
147{
148 if (!M_ACCELDATA)
149 m_refData = new wxAcceleratorRefData;
150
151 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
152}
153
154WXHACCEL wxAcceleratorTable::GetHACCEL() const
155{
156 if (!M_ACCELDATA)
157 return 0;
158 return (WXHACCEL) M_ACCELDATA->m_hAccel;
159}
160