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