]> git.saurik.com Git - wxWidgets.git/blame - src/msw/accel.cpp
Fixed some bugs in new code (CanPaste, GetSelection)
[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
8870c26e 105#if !defined(__WIN16__) && !defined(__TWIN32__)
252eb8fd 106wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
110f3205 107{
1e6d9499 108 // Not available in WIN16
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);
138}
8870c26e
JS
139#else
140wxAcceleratorTable::wxAcceleratorTable(int WXUNUSED(n), const wxAcceleratorEntry WXUNUSED(entries)[])
141{
142}
143#endif
110f3205
JS
144
145bool wxAcceleratorTable::Ok(void) const
146{
147 return (M_ACCELDATA && (M_ACCELDATA->m_ok));
148}
149
150void wxAcceleratorTable::SetHACCEL(WXHACCEL hAccel)
151{
152 if (!M_ACCELDATA)
153 m_refData = new wxAcceleratorRefData;
154
155 M_ACCELDATA->m_hAccel = (HACCEL) hAccel;
156}
157
158WXHACCEL wxAcceleratorTable::GetHACCEL() const
159{
160 if (!M_ACCELDATA)
161 return 0;
162 return (WXHACCEL) M_ACCELDATA->m_hAccel;
163}
164