]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/accel.cpp
compilation fixes
[wxWidgets.git] / src / gtk1 / accel.cpp
CommitLineData
bcf1fa6b
RR
1/////////////////////////////////////////////////////////////////////////////
2// Name: accel.cpp
3// Purpose:
4// Author: Robert Roebling
dcf924a3 5// Id: $id:$
bcf1fa6b
RR
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifdef __GNUG__
11#pragma implementation "accel.h"
12#endif
13
14#include "wx/accel.h"
15
dcf924a3 16#if wxUSE_ACCEL
66c135f3 17
dcf924a3 18#include <ctype.h>
bbe0af5b 19
bcf1fa6b
RR
20//-----------------------------------------------------------------------------
21// wxAcceleratorTable
22//-----------------------------------------------------------------------------
23
24class wxAccelRefData: public wxObjectRefData
25{
ec758a20 26public:
bcf1fa6b 27
ec758a20 28 wxAccelRefData(void);
bcf1fa6b 29
ec758a20 30 wxList m_accels;
bcf1fa6b
RR
31};
32
33wxAccelRefData::wxAccelRefData(void)
34{
ec758a20 35 m_accels.DeleteContents( TRUE );
bcf1fa6b
RR
36}
37
38//-----------------------------------------------------------------------------
39
40#define M_ACCELDATA ((wxAccelRefData *)m_refData)
41
42IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable,wxObject)
43
44wxAcceleratorTable::wxAcceleratorTable()
45{
bcf1fa6b
RR
46}
47
48wxAcceleratorTable::wxAcceleratorTable( int n, wxAcceleratorEntry entries[] )
49{
ec758a20
RR
50 m_refData = new wxAccelRefData();
51
52 for (int i = 0; i < n; i++)
53 {
54 int flag = entries[i].GetFlags();
55 int keycode = entries[i].GetKeyCode();
56 int command = entries[i].GetCommand();
57 if ((keycode >= (int)'A') && (keycode <= (int)'Z')) keycode = (int)tolower( (char)keycode );
58 M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) );
59 }
bcf1fa6b
RR
60}
61
62wxAcceleratorTable::~wxAcceleratorTable()
63{
64}
65
66bool wxAcceleratorTable::Ok() const
67{
ec758a20 68 return (m_refData != NULL);
bcf1fa6b
RR
69}
70
71int wxAcceleratorTable::GetCommand( wxKeyEvent &event )
72{
ec758a20 73 if (!Ok()) return -1;
e55ad60e 74
ec758a20
RR
75 wxNode *node = M_ACCELDATA->m_accels.First();
76 while (node)
77 {
78 wxAcceleratorEntry *entry = (wxAcceleratorEntry*)node->Data();
79 if ((event.m_keyCode == entry->GetKeyCode()) &&
80 (((entry->GetFlags() & wxACCEL_CTRL) == 0) || event.ControlDown()) &&
81 (((entry->GetFlags() & wxACCEL_SHIFT) == 0) || event.ShiftDown()) &&
82 (((entry->GetFlags() & wxACCEL_ALT) == 0) || event.AltDown() || event.MetaDown()))
83 {
84 return entry->GetCommand();
85 }
86 node = node->Next();
87 }
bcf1fa6b 88
ec758a20 89 return -1;
bcf1fa6b
RR
90}
91
dcf924a3 92#endif