1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxAcceleratorTable 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) 
  13 #pragma implementation "accel.h" 
  16 #include "wx/wxprec.h" 
  19 #include "wx/string.h" 
  21 IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable
, wxObject
) 
  23 // ---------------------------------------------------------------------------- 
  24 // wxAccelList: a list of wxAcceleratorEntries 
  25 // ---------------------------------------------------------------------------- 
  27 WX_DECLARE_LIST(wxAcceleratorEntry
, wxAccelList
); 
  28 #include "wx/listimpl.cpp" 
  29 WX_DEFINE_LIST(wxAccelList
); 
  31 // ---------------------------------------------------------------------------- 
  32 // wxAccelRefData: the data used by wxAcceleratorTable 
  33 // ---------------------------------------------------------------------------- 
  35 class WXDLLEXPORT wxAcceleratorRefData
: public wxObjectRefData
 
  37     friend class WXDLLEXPORT wxAcceleratorTable
; 
  39     wxAcceleratorRefData(); 
  40     ~wxAcceleratorRefData(); 
  45 #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) 
  47 wxAcceleratorRefData::wxAcceleratorRefData() 
  52 wxAcceleratorRefData::~wxAcceleratorRefData() 
  54     WX_CLEAR_LIST( wxAccelList
, m_accels 
); 
  57 wxAcceleratorTable::wxAcceleratorTable() 
  62 wxAcceleratorTable::~wxAcceleratorTable() 
  66 // Create from an array 
  67 wxAcceleratorTable::wxAcceleratorTable(int n
, const wxAcceleratorEntry entries
[]) 
  69     m_refData 
= new wxAcceleratorRefData
; 
  71     for (int i 
= 0; i 
< n
; i
++) 
  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 
) ); 
  81 bool wxAcceleratorTable::Ok() const 
  83     return (m_refData 
!= NULL
); 
  86 int wxAcceleratorTable::GetCommand( wxKeyEvent 
&event 
) 
  90     wxAccelList::compatibility_iterator node 
= M_ACCELDATA
->m_accels
.GetFirst(); 
  93         wxAcceleratorEntry 
*entry 
= node
->GetData(); 
  94         if ((event
.m_keyCode 
== entry
->GetKeyCode()) && 
  95            (((entry
->GetFlags() & wxACCEL_CTRL
) == 0) || event
.ControlDown()) && 
  96            (((entry
->GetFlags() & wxACCEL_SHIFT
) == 0) || event
.ShiftDown()) && 
  97            (((entry
->GetFlags() & wxACCEL_ALT
) == 0) || event
.AltDown() || event
.MetaDown())) 
  99             return entry
->GetCommand(); 
 101         node 
= node
->GetNext();