]> git.saurik.com Git - wxWidgets.git/blame - src/motif/accel.cpp
added a cast to wxDecodeSurrogate() to fix wxMSW cross-compilation
[wxWidgets.git] / src / motif / accel.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
55034339 2// Name: src/motif/accel.cpp
4bb6408c
JS
3// Purpose: wxAcceleratorTable
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
1248b41f
MB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
4bb6408c
JS
15#include "wx/accel.h"
16#include "wx/string.h"
8aa04e8b
JS
17#include "wx/utils.h"
18#include <ctype.h>
4bb6408c 19
4bb6408c 20IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
4bb6408c
JS
21
22class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
23{
24 friend class WXDLLEXPORT wxAcceleratorTable;
25public:
26 wxAcceleratorRefData();
27 ~wxAcceleratorRefData();
0fb67cd1 28
8aa04e8b
JS
29public:
30 int m_count;
31 wxAcceleratorEntry* m_entries;
4bb6408c
JS
32};
33
34#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
35
36wxAcceleratorRefData::wxAcceleratorRefData()
37{
8aa04e8b
JS
38 m_count = 0;
39 m_entries = (wxAcceleratorEntry*) NULL;
4bb6408c
JS
40}
41
42wxAcceleratorRefData::~wxAcceleratorRefData()
43{
8aa04e8b
JS
44 delete[] m_entries;
45 m_entries = (wxAcceleratorEntry*) NULL;
46 m_count = 0;
4bb6408c
JS
47}
48
49wxAcceleratorTable::wxAcceleratorTable()
50{
8aa04e8b 51 m_refData = (wxAcceleratorRefData*) NULL;
4bb6408c
JS
52}
53
54wxAcceleratorTable::~wxAcceleratorTable()
55{
8aa04e8b 56 // Data deleted in ~wxObject
4bb6408c
JS
57}
58
59// Load from .rc resource
af111fc3 60wxAcceleratorTable::wxAcceleratorTable(const wxString& WXUNUSED(resource))
4bb6408c
JS
61{
62 m_refData = new wxAcceleratorRefData;
4bb6408c
JS
63}
64
65// Create from an array
3c674514 66wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
4bb6408c 67{
8aa04e8b
JS
68 wxAcceleratorRefData* data = new wxAcceleratorRefData;
69 m_refData = data;
0fb67cd1 70
8aa04e8b
JS
71 data->m_count = n;
72 data->m_entries = new wxAcceleratorEntry[n];
73 int i;
74 for (i = 0; i < n; i++)
75 data->m_entries[i] = entries[i];
0fb67cd1 76
4bb6408c
JS
77}
78
79bool wxAcceleratorTable::Ok() const
80{
8aa04e8b
JS
81 return (m_refData != (wxAcceleratorRefData*) NULL);
82}
83
84int wxAcceleratorTable::GetCount() const
85{
86 return M_ACCELDATA->m_count;
87}
88
89wxAcceleratorEntry* wxAcceleratorTable::GetEntries() const
90{
91 return M_ACCELDATA->m_entries;
92}
93
94// Implementation use only
95bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const
96{
97 bool eventAltDown = event.AltDown();
98 bool eventCtrlDown = event.ControlDown();
99 bool eventShiftDown = event.ShiftDown();
0ec6fd04 100 int eventKeyCode = event.GetKeyCode();
0fb67cd1 101
8aa04e8b
JS
102 bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT);
103 bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL);
104 bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT);
105 int accKeyCode = GetKeyCode();
106 int accKeyCode2 = GetKeyCode();
107 if (isascii(accKeyCode2))
0fb67cd1
VZ
108 accKeyCode2 = tolower(accKeyCode2);
109
8aa04e8b 110 return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
2d120f83
JS
111 (eventShiftDown == accShiftDown) &&
112 ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ;
4bb6408c 113}