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