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