]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/accel.cpp
Added lots of files. Enough now so that all wxHTML samples link.
[wxWidgets.git] / src / motif / accel.cpp
... / ...
CommitLineData
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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "accel.h"
14#endif
15
16#include "wx/setup.h"
17#include "wx/accel.h"
18#include "wx/string.h"
19#include "wx/utils.h"
20#include <ctype.h>
21
22#if !USE_SHARED_LIBRARIES
23IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
24#endif
25
26class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
27{
28 friend class WXDLLEXPORT wxAcceleratorTable;
29public:
30 wxAcceleratorRefData();
31 ~wxAcceleratorRefData();
32
33public:
34 int m_count;
35 wxAcceleratorEntry* m_entries;
36};
37
38#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
39
40wxAcceleratorRefData::wxAcceleratorRefData()
41{
42 m_count = 0;
43 m_entries = (wxAcceleratorEntry*) NULL;
44}
45
46wxAcceleratorRefData::~wxAcceleratorRefData()
47{
48 delete[] m_entries;
49 m_entries = (wxAcceleratorEntry*) NULL;
50 m_count = 0;
51}
52
53wxAcceleratorTable::wxAcceleratorTable()
54{
55 m_refData = (wxAcceleratorRefData*) NULL;
56}
57
58wxAcceleratorTable::~wxAcceleratorTable()
59{
60 // Data deleted in ~wxObject
61}
62
63// Load from .rc resource
64wxAcceleratorTable::wxAcceleratorTable(const wxString& resource)
65{
66 m_refData = new wxAcceleratorRefData;
67}
68
69// Create from an array
70wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[])
71{
72 wxAcceleratorRefData* data = new wxAcceleratorRefData;
73 m_refData = data;
74
75 data->m_count = n;
76 data->m_entries = new wxAcceleratorEntry[n];
77 int i;
78 for (i = 0; i < n; i++)
79 data->m_entries[i] = entries[i];
80
81}
82
83bool wxAcceleratorTable::Ok() const
84{
85 return (m_refData != (wxAcceleratorRefData*) NULL);
86}
87
88int wxAcceleratorTable::GetCount() const
89{
90 return M_ACCELDATA->m_count;
91}
92
93wxAcceleratorEntry* wxAcceleratorTable::GetEntries() const
94{
95 return M_ACCELDATA->m_entries;
96}
97
98// Implementation use only
99bool wxAcceleratorEntry::MatchesEvent(const wxKeyEvent& event) const
100{
101 bool eventAltDown = event.AltDown();
102 bool eventCtrlDown = event.ControlDown();
103 bool eventShiftDown = event.ShiftDown();
104 int eventKeyCode = event.KeyCode();
105
106 bool accAltDown = ((GetFlags() & wxACCEL_ALT) == wxACCEL_ALT);
107 bool accCtrlDown = ((GetFlags() & wxACCEL_CTRL) == wxACCEL_CTRL);
108 bool accShiftDown = ((GetFlags() & wxACCEL_SHIFT) == wxACCEL_SHIFT);
109 int accKeyCode = GetKeyCode();
110 int accKeyCode2 = GetKeyCode();
111 if (isascii(accKeyCode2))
112 accKeyCode2 = tolower(accKeyCode2);
113
114 return ((eventAltDown == accAltDown) && (eventCtrlDown == accCtrlDown) &&
115 (eventShiftDown == accShiftDown) &&
116 ((eventKeyCode == accKeyCode || eventKeyCode == accKeyCode2))) ;
117}
118