]> git.saurik.com Git - wxWidgets.git/blame - src/osx/accel.cpp
avoid setting initial position if it was not specified, broken in r70734
[wxWidgets.git] / src / osx / accel.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
96dabe43 2// Name: src/osx/accel.cpp
489468fe
SC
3// Purpose: wxAcceleratorTable
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
489468fe
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
666db5d1
VZ
13#if wxUSE_ACCEL
14
489468fe
SC
15#include "wx/accel.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/string.h"
19#endif
20
489468fe
SC
21IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject)
22
23// ----------------------------------------------------------------------------
24// wxAccelList: a list of wxAcceleratorEntries
25// ----------------------------------------------------------------------------
26
27WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList);
28#include "wx/listimpl.cpp"
29WX_DEFINE_LIST(wxAccelList)
30
31// ----------------------------------------------------------------------------
32// wxAccelRefData: the data used by wxAcceleratorTable
33// ----------------------------------------------------------------------------
34
35class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData
36{
37 friend class wxAcceleratorTable;
38public:
39 wxAcceleratorRefData();
40 virtual ~wxAcceleratorRefData();
41
42 wxAccelList m_accels;
43};
44
45#define M_ACCELDATA ((wxAcceleratorRefData *)m_refData)
46
47wxAcceleratorRefData::wxAcceleratorRefData()
48 : m_accels()
49{
50}
51
52wxAcceleratorRefData::~wxAcceleratorRefData()
53{
54 WX_CLEAR_LIST( wxAccelList, m_accels );
55}
56
57wxAcceleratorTable::wxAcceleratorTable()
58{
59 m_refData = NULL;
60}
61
62wxAcceleratorTable::~wxAcceleratorTable()
63{
64}
65
66// Create from an array
67wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[])
68{
69 m_refData = new wxAcceleratorRefData;
70
71 for (int i = 0; i < n; i++)
72 {
73 int flag = entries[i].GetFlags();
74 int keycode = entries[i].GetKeyCode();
75 int command = entries[i].GetCommand();
76 if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode );
77 M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
78 }
79}
80
81bool wxAcceleratorTable::IsOk() const
82{
83 return (m_refData != NULL);
84}
85
86int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
87{
a1b806b9 88 if (!IsOk()) return -1;
489468fe
SC
89
90 wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst();
91 while (node)
92 {
93 wxAcceleratorEntry *entry = node->GetData();
94 if ((event.m_keyCode == entry->GetKeyCode()) &&
df856ba9 95 (((entry->GetFlags() & wxACCEL_RAW_CTRL) != 0) == event.RawControlDown()) &&
489468fe 96 (((entry->GetFlags() & wxACCEL_SHIFT) != 0) == event.ShiftDown()) &&
03647350 97 (((entry->GetFlags() & wxACCEL_ALT) != 0) == event.AltDown()) &&
df856ba9 98 (((entry->GetFlags() & wxACCEL_CTRL) != 0) == event.ControlDown()))
489468fe
SC
99 {
100 return entry->GetCommand();
101 }
102 node = node->GetNext();
103 }
104
105 return -1;
106}
107
666db5d1 108#endif // wxUSE_ACCEL