X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e9576ca53db96b462ed4c0b4bdf47d64c40203e4..7f65743f005572f1de2754ba8c5e7cf1eed1847e:/src/mac/carbon/accel.cpp diff --git a/src/mac/carbon/accel.cpp b/src/mac/carbon/accel.cpp index b0b8734d55..f33bbe28e0 100644 --- a/src/mac/carbon/accel.cpp +++ b/src/mac/carbon/accel.cpp @@ -1,93 +1,109 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: accel.cpp +// Name: src/mac/carbon/accel.cpp // Purpose: wxAcceleratorTable -// Author: AUTHOR +// Author: Stefan Csomor // Modified by: -// Created: ??/??/98 +// Created: 1998-01-01 // RCS-ID: $Id$ -// Copyright: (c) AUTHOR +// Copyright: (c) Stefan Csomor // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "accel.h" -#endif +#include "wx/wxprec.h" -#include "wx/setup.h" #include "wx/accel.h" -#include "wx/string.h" -#if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) +#ifndef WX_PRECOMP + #include "wx/string.h" #endif +#ifndef __WXUNIVERSAL__ + +IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) + +// ---------------------------------------------------------------------------- +// wxAccelList: a list of wxAcceleratorEntries +// ---------------------------------------------------------------------------- + +WX_DECLARE_LIST(wxAcceleratorEntry, wxAccelList); +#include "wx/listimpl.cpp" +WX_DEFINE_LIST(wxAccelList) + +// ---------------------------------------------------------------------------- +// wxAccelRefData: the data used by wxAcceleratorTable +// ---------------------------------------------------------------------------- + class WXDLLEXPORT wxAcceleratorRefData: public wxObjectRefData { - friend class WXDLLEXPORT wxAcceleratorTable; + friend class wxAcceleratorTable; public: wxAcceleratorRefData(); - ~wxAcceleratorRefData(); + virtual ~wxAcceleratorRefData(); -/* TODO: implementation - inline HACCEL GetHACCEL() const { return m_hAccel; } -protected: - HACCEL m_hAccel; -*/ + wxAccelList m_accels; }; #define M_ACCELDATA ((wxAcceleratorRefData *)m_refData) wxAcceleratorRefData::wxAcceleratorRefData() + : m_accels() { - // TODO -/* - HACCEL m_hAccel; -*/ } wxAcceleratorRefData::~wxAcceleratorRefData() { -/* - if (m_hAccel) - { - DestroyAcceleratorTable((HACCEL) m_hAccel); - } - m_hAccel = 0 ; -*/ + WX_CLEAR_LIST( wxAccelList, m_accels ); } wxAcceleratorTable::wxAcceleratorTable() { - m_refData = NULL; + m_refData = NULL; } wxAcceleratorTable::~wxAcceleratorTable() { } -// Load from .rc resource -wxAcceleratorTable::wxAcceleratorTable(const wxString& resource) +// Create from an array +wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[]) { m_refData = new wxAcceleratorRefData; -/* TODO: load acelerator from resource, if appropriate for your platform - M_ACCELDATA->m_hAccel = hAccel; - M_ACCELDATA->m_ok = (hAccel != 0); -*/ + for (int i = 0; i < n; i++) + { + int flag = entries[i].GetFlags(); + int keycode = entries[i].GetKeyCode(); + int command = entries[i].GetCommand(); + if ((keycode >= (int)'a') && (keycode <= (int)'z')) keycode = (int)toupper( (char)keycode ); + M_ACCELDATA->m_accels.Append( new wxAcceleratorEntry( flag, keycode, command ) ); + } } -// Create from an array -wxAcceleratorTable::wxAcceleratorTable(int n, wxAcceleratorEntry entries[]) +bool wxAcceleratorTable::IsOk() const { - m_refData = new wxAcceleratorRefData; - -/* TODO: create table from entries - */ + return (m_refData != NULL); } -bool wxAcceleratorTable::Ok() const +int wxAcceleratorTable::GetCommand( wxKeyEvent &event ) { - // TODO - return FALSE; + if (!Ok()) return -1; + + wxAccelList::compatibility_iterator node = M_ACCELDATA->m_accels.GetFirst(); + while (node) + { + wxAcceleratorEntry *entry = node->GetData(); + if ((event.m_keyCode == entry->GetKeyCode()) && + (((entry->GetFlags() & wxACCEL_CTRL) != 0) == event.ControlDown()) && + (((entry->GetFlags() & wxACCEL_SHIFT) != 0) == event.ShiftDown()) && + (((entry->GetFlags() & wxACCEL_ALT) != 0) == event.AltDown()) && + (((entry->GetFlags() & wxACCEL_CMD) != 0) == event.CmdDown())) + { + return entry->GetCommand(); + } + node = node->GetNext(); + } + + return -1; } +#endif \ No newline at end of file