X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c8ef3d5565e6f1c1a23baa3be7d6a7b42151c616..71a09c3579dd5cb4cd8fa7fdc143561cbff74e12:/src/osx/core/hid.cpp diff --git a/src/osx/core/hid.cpp b/src/osx/core/hid.cpp index e9f4cdbaca..10faa7d10e 100644 --- a/src/osx/core/hid.cpp +++ b/src/osx/core/hid.cpp @@ -1,10 +1,9 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/mac/corefoundation/hid.cpp +// Name: src/osx/core/hid.cpp // Purpose: DARWIN HID layer for WX Implementation // Author: Ryan Norton // Modified by: // Created: 11/11/2003 -// RCS-ID: $Id$ // Copyright: (c) Ryan Norton // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -24,8 +23,7 @@ #pragma hdrstop #endif -//DARWIN _ONLY_ -#ifdef __DARWIN__ +#if wxOSX_USE_COCOA_OR_CARBON #include "wx/osx/core/hid.h" @@ -37,7 +35,7 @@ #include "wx/module.h" #endif -#include "wx/osx/core/cfstring.h" +#include "wx/osx/private.h" // ============================================================================ // implementation @@ -78,7 +76,7 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev) CFMutableDictionaryRef pDictionary = IOServiceMatching(kIOHIDDeviceKey); if(pDictionary == NULL) { - wxLogSysError( _T("IOServiceMatching(kIOHIDDeviceKey) failed") ); + wxLogSysError( wxT("IOServiceMatching(kIOHIDDeviceKey) failed") ); return false; } @@ -98,12 +96,12 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev) CFRelease(pClass); } - //Now get the maching services + //Now get the matching services io_iterator_t pIterator; if( IOServiceGetMatchingServices(m_pPort, pDictionary, &pIterator) != kIOReturnSuccess ) { - wxLogSysError(_T("No Matching HID Services")); + wxLogSysError(wxT("No Matching HID Services")); return false; } @@ -129,7 +127,7 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev) kNilOptions ) != KERN_SUCCESS ) { - wxLogDebug(_T("IORegistryEntryCreateCFProperties failed")); + wxLogDebug(wxT("IORegistryEntryCreateCFProperties failed")); } // @@ -193,7 +191,9 @@ bool wxHIDDevice::Create (int nClass, int nType, int nDev) //open the HID interface... if ( (*m_ppDevice)->open(m_ppDevice, 0) != S_OK ) - wxLogDebug(_T("HID device: open failed")); + { + wxLogDebug(wxT("HID device: open failed")); + } // //Now the hard part - in order to scan things we need "cookies" @@ -240,7 +240,7 @@ size_t wxHIDDevice::GetCount (int nClass, int nType) CFMutableDictionaryRef pDictionary = IOServiceMatching(kIOHIDDeviceKey); if(pDictionary == NULL) { - wxLogSysError( _T("IOServiceMatching(kIOHIDDeviceKey) failed") ); + wxLogSysError( wxT("IOServiceMatching(kIOHIDDeviceKey) failed") ); return false; } @@ -260,12 +260,12 @@ size_t wxHIDDevice::GetCount (int nClass, int nType) CFRelease(pClass); } - //Now get the maching services + //Now get the matching services io_iterator_t pIterator; if( IOServiceGetMatchingServices(pPort, pDictionary, &pIterator) != kIOReturnSuccess ) { - wxLogSysError(_T("No Matching HID Services")); + wxLogSysError(wxT("No Matching HID Services")); return false; } @@ -316,7 +316,9 @@ void wxHIDDevice::AddCookieInQueue(CFTypeRef Data, int i) //3rd Param flags (none yet) AddCookie(Data, i); if ( (*m_ppQueue)->addElement(m_ppQueue, m_pCookies[i], 0) != S_OK ) - wxLogDebug(_T("HID device: adding element failed")); + { + wxLogDebug(wxT("HID device: adding element failed")); + } } // ---------------------------------------------------------------------------- @@ -333,14 +335,14 @@ void wxHIDDevice::InitCookies(size_t dwSize, bool bQueue) m_ppQueue = (*m_ppDevice)->allocQueue(m_ppDevice); if ( !m_ppQueue ) { - wxLogDebug(_T("HID device: allocQueue failed")); + wxLogDebug(wxT("HID device: allocQueue failed")); return; } //Param 2, flags, none yet if ( (*m_ppQueue)->create(m_ppQueue, 0, 512) != S_OK ) { - wxLogDebug(_T("HID device: create failed")); + wxLogDebug(wxT("HID device: create failed")); } } @@ -376,7 +378,7 @@ bool wxHIDDevice::IsActive(int nIndex) // ---------------------------------------------------------------------------- bool wxHIDDevice::HasElement(int nIndex) { - return m_pCookies[nIndex] != NULL; + return (void*) m_pCookies[nIndex] != NULL; } // ---------------------------------------------------------------------------- @@ -418,7 +420,7 @@ enum WXK_RSHIFT = 400, WXK_RALT, WXK_RCONTROL, - WXK_RMENU + WXK_RAW_RCONTROL, }; // ---------------------------------------------------------------------------- @@ -474,8 +476,8 @@ void wxHIDKeyboard::BuildCookies(CFArrayRef Array) void wxHIDKeyboard::DoBuildCookies(CFArrayRef Array) { //Now go through each possible cookie - int i, - nUsage; + int i; + long nUsage; // bool bEOTriggered = false; for (i = 0; i < CFArrayGetCount(Array); ++i) { @@ -598,7 +600,7 @@ void wxHIDKeyboard::DoBuildCookies(CFArrayRef Array) //Menu keys, Shift, other specials case kHIDUsage_KeyboardLeftControl: - AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_CONTROL); + AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RAW_CONTROL); break; case kHIDUsage_KeyboardLeftShift: AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_SHIFT); @@ -607,10 +609,10 @@ void wxHIDKeyboard::DoBuildCookies(CFArrayRef Array) AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_ALT); break; case kHIDUsage_KeyboardLeftGUI: - AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_MENU); + AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_CONTROL); break; case kHIDUsage_KeyboardRightControl: - AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RCONTROL); + AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RAW_RCONTROL); break; case kHIDUsage_KeyboardRightShift: AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RSHIFT); @@ -619,7 +621,7 @@ void wxHIDKeyboard::DoBuildCookies(CFArrayRef Array) AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RALT); break; case kHIDUsage_KeyboardRightGUI: - AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RMENU); + AddCookie(CFArrayGetValueAtIndex(Array, i),WXK_RCONTROL); break; //Default @@ -651,6 +653,7 @@ class wxHIDModule : public wxModule { for(size_t i = 0; i < sm_keyboards.GetCount(); ++i) delete (wxHIDKeyboard*) sm_keyboards[i]; + sm_keyboards.Clear(); } }; @@ -669,73 +672,8 @@ bool wxGetKeyState (wxKeyCode key) wxASSERT_MSG(key != WXK_LBUTTON && key != WXK_RBUTTON && key != WXK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons")); - if (wxHIDModule::sm_keyboards.GetCount() == 0) - { - int nKeyboards = wxHIDKeyboard::GetCount(); - - for(int i = 1; i <= nKeyboards; ++i) - { - wxHIDKeyboard* keyboard = new wxHIDKeyboard(); - if(keyboard->Create(i)) - { - wxHIDModule::sm_keyboards.Add(keyboard); - } - else - { - delete keyboard; - break; - } - } - - wxASSERT_MSG(wxHIDModule::sm_keyboards.GetCount() != 0, - wxT("No keyboards found!")); - } - - for(size_t i = 0; i < wxHIDModule::sm_keyboards.GetCount(); ++i) - { - wxHIDKeyboard* keyboard = (wxHIDKeyboard*) - wxHIDModule::sm_keyboards[i]; - - switch(key) - { - case WXK_SHIFT: - if( keyboard->IsActive(WXK_SHIFT) || - keyboard->IsActive(WXK_RSHIFT) ) - { - return true; - } - break; - case WXK_ALT: - if( keyboard->IsActive(WXK_ALT) || - keyboard->IsActive(WXK_RALT) ) - { - return true; - } - break; - case WXK_CONTROL: - if( keyboard->IsActive(WXK_CONTROL) || - keyboard->IsActive(WXK_RCONTROL) ) - { - return true; - } - break; - case WXK_MENU: - if( keyboard->IsActive(WXK_MENU) || - keyboard->IsActive(WXK_RMENU) ) - { - return true; - } - break; - default: - if( keyboard->IsActive(key) ) - { - return true; - } - break; - } - } - - return false; //not down/error + CGKeyCode cgcode = wxCharCodeWXToOSX((wxKeyCode)key); + return CGEventSourceKeyState(kCGEventSourceStateCombinedSessionState, cgcode); } #endif //__DARWIN__