]> git.saurik.com Git - wxWidgets.git/blame - src/motif/accel.cpp
fixing osx_carbon
[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 15#include "wx/accel.h"
df91131c
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/string.h"
de6185e2 19 #include "wx/utils.h"
df91131c
WS
20#endif
21
8aa04e8b 22#include <ctype.h>
4bb6408c 23
4bb6408c 24IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
4bb6408c
JS
25
26class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
27{
6991087b 28 friend class wxAcceleratorTable;
4bb6408c
JS
29public:
30 wxAcceleratorRefData();
d3c7fc99 31 virtual ~wxAcceleratorRefData();
0fb67cd1 32
8aa04e8b
JS
33public:
34 int m_count;
35 wxAcceleratorEntry* m_entries;
4bb6408c
JS
36};
37
38#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
39
40wxAcceleratorRefData::wxAcceleratorRefData()
41{
8aa04e8b 42 m_count = 0;
d3b9f782 43 m_entries = NULL;
4bb6408c
JS
44}
45
46wxAcceleratorRefData::~wxAcceleratorRefData()
47{
5276b0a5 48 wxDELETEA(m_entries);
8aa04e8b 49 m_count = 0;
4bb6408c
JS
50}
51
52wxAcceleratorTable::wxAcceleratorTable()
53{
d3b9f782 54 m_refData = NULL;
4bb6408c
JS
55}
56
57wxAcceleratorTable::~wxAcceleratorTable()
58{
8aa04e8b 59 // Data deleted in ~wxObject
4bb6408c
JS
60}
61
62// Load from .rc resource
af111fc3 63wxAcceleratorTable::wxAcceleratorTable(const wxString& WXUNUSED(resource))
4bb6408c
JS
64{
65 m_refData = new wxAcceleratorRefData;
4bb6408c
JS
66}
67
68// Create from an array
3c674514 69wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
4bb6408c 70{
8aa04e8b
JS
71 wxAcceleratorRefData* data = new wxAcceleratorRefData;
72 m_refData = data;
0fb67cd1 73
8aa04e8b
JS
74 data->m_count = n;
75 data->m_entries = new wxAcceleratorEntry[n];
76 int i;
77 for (i = 0; i < n; i++)
78 data->m_entries[i] = entries[i];
0fb67cd1 79
4bb6408c
JS
80}
81
b7cacb43 82bool wxAcceleratorTable::IsOk() const
4bb6408c 83{
d3b9f782 84 return (m_refData != NULL);
8aa04e8b
JS
85}
86
87int wxAcceleratorTable::GetCount() const
88{
89 return M_ACCELDATA->m_count;
90}
91
92wxAcceleratorEntry* wxAcceleratorTable::GetEntries() const
93{
94 return M_ACCELDATA->m_entries;
95}
96
97// Implementation use only
98bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const
99{
100 bool eventAltDown = event.AltDown();
101 bool eventCtrlDown = event.ControlDown();
102 bool eventShiftDown = event.ShiftDown();
0ec6fd04 103 int eventKeyCode = event.GetKeyCode();
0fb67cd1 104
8aa04e8b
JS
105 bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT);
106 bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL);
107 bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT);
108 int accKeyCode = GetKeyCode();
109 int accKeyCode2 = GetKeyCode();
7a0079d5
VZ
110 if (wxIsascii(accKeyCode2))
111 accKeyCode2 = wxTolower(accKeyCode2);
0fb67cd1 112
8aa04e8b 113 return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
2d120f83
JS
114 (eventShiftDown == accShiftDown) &&
115 ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ;
4bb6408c 116}