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