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