pascal OSStatus PreferencesDialog::WindowEventHandler(EventHandlerCallRef myHandler, EventRef event, void* userData) { OSStatus result = eventNotHandledErr; UInt32 eventClass, eventKind; eventClass = GetEventClass(event); eventKind = GetEventKind(event); PreferencesDialog* prefDlg = reinterpret_cast<PreferencesDialog*>(userData); switch (eventClass) { case kEventClassControl: { ControlRef targetControl = NULL; ControlID targetControlID; GetEventParameter(event, kEventParamDirectObject, typeControlRef, NULL, sizeof(targetControl), NULL, &targetControl); if (targetControl) GetControlID(targetControl, &targetControlID); switch (eventKind) { case kEventControlHit: { switch (targetControlID.id) { // simulate insert key with ctrl+up case 131: prefDlg->setFakeInsertKey(GetControl32BitValue(targetControl)-1); result = noErr; break; // 15 bit color toggle case 132: prefDlg->toggleUse15BitColorDepth(); result = noErr; break; // Enable MIDI device case 129: prefDlg->toggleUseMidiDevice(); result = noErr; break; // Save MIDI preferences case 128: prefDlg->toggleSavePreferences(); result = noErr; break; // Record key velocity case 127: prefDlg->toggleRecordVelocity(); result = noErr; break; // velocity amplify slider case 125: { prefDlg->storeVelocityAmplify(GetControlValue(targetControl)); result = noErr; break; } } break; } } break; } // Handle window close event (= discard) case kEventClassWindow: { switch (eventKind) { case kEventWindowClose: { prefDlg->restoreDataBase(); prefDlg->hide(); result = noErr; break; } } break; } case kEventClassCommand: { switch (eventKind) { case kEventCommandProcess: { HICommand command; GetEventParameter(event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &command); switch (command.commandID) { case kDiscardPreferences: prefDlg->restoreDataBase(); case kConfirmPreferences: { // These two events are better off when sent to the main window SendEventToWindow(event, prefDlg->mainWindow); break; } default: // Handle MIDI device selection from pop-up menu if (command.commandID >= kMIDIDeviceBaseCommand && command.commandID <= kMIDIDeviceBaseCommand + prefDlg->getNumMidiDevices()) { prefDlg->storeMidiDeviceName(command.commandID - kMIDIDeviceBaseCommand); result = noErr; } } break; } } break; } } return result; }
void COSXScreen::handleSystemEvent(const CEvent& event, void*) { EventRef* carbonEvent = reinterpret_cast<EventRef*>(event.getData()); assert(carbonEvent != NULL); UInt32 eventClass = GetEventClass(*carbonEvent); switch (eventClass) { case kEventClassMouse: switch (GetEventKind(*carbonEvent)) { case kSynergyEventMouseScroll: { OSStatus r; long xScroll; long yScroll; // get scroll amount r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisX, typeLongInteger, NULL, sizeof(xScroll), NULL, &xScroll); if (r != noErr) { xScroll = 0; } r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisY, typeLongInteger, NULL, sizeof(yScroll), NULL, &yScroll); if (r != noErr) { yScroll = 0; } if (xScroll != 0 || yScroll != 0) { onMouseWheel(-mapScrollWheelToSynergy(xScroll), mapScrollWheelToSynergy(yScroll)); } } } break; case kEventClassKeyboard: switch (GetEventKind(*carbonEvent)) { case kEventHotKeyPressed: case kEventHotKeyReleased: onHotKey(*carbonEvent); break; } break; case kEventClassWindow: SendEventToWindow(*carbonEvent, m_userInputWindow); switch (GetEventKind(*carbonEvent)) { case kEventWindowActivated: LOG((CLOG_DEBUG1 "window activated")); break; case kEventWindowDeactivated: LOG((CLOG_DEBUG1 "window deactivated")); break; case kEventWindowFocusAcquired: LOG((CLOG_DEBUG1 "focus acquired")); break; case kEventWindowFocusRelinquish: LOG((CLOG_DEBUG1 "focus released")); break; } break; default: SendEventToEventTarget(*carbonEvent, GetEventDispatcherTarget()); break; } }
void COSXScreen::handleSystemEvent(const CEvent& event, void*) { EventRef* carbonEvent = reinterpret_cast<EventRef*>(event.getData()); assert(carbonEvent != NULL); UInt32 eventClass = GetEventClass(*carbonEvent); switch (eventClass) { case kEventClassMouse: switch (GetEventKind(*carbonEvent)) { case kEventMouseDown: { UInt16 myButton; GetEventParameter(*carbonEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(myButton), NULL, &myButton); onMouseButton(true, myButton); break; } case kEventMouseUp: { UInt16 myButton; GetEventParameter(*carbonEvent, kEventParamMouseButton, typeMouseButton, NULL, sizeof(myButton), NULL, &myButton); onMouseButton(false, myButton); break; } case kEventMouseDragged: case kEventMouseMoved: { HIPoint point; GetEventParameter(*carbonEvent, kEventParamMouseLocation, typeHIPoint, NULL, sizeof(point), NULL, &point); onMouseMove((SInt32)point.x, (SInt32)point.y); break; } case kEventMouseWheelMoved: { EventMouseWheelAxis axis; SInt32 delta; GetEventParameter(*carbonEvent, kEventParamMouseWheelAxis, typeMouseWheelAxis, NULL, sizeof(axis), NULL, &axis); if (axis == kEventMouseWheelAxisX || axis == kEventMouseWheelAxisY) { GetEventParameter(*carbonEvent, kEventParamMouseWheelDelta, typeLongInteger, NULL, sizeof(delta), NULL, &delta); if (axis == kEventMouseWheelAxisX) { onMouseWheel(-mapScrollWheelToSynergy((SInt32)delta), 0); } else { onMouseWheel(0, mapScrollWheelToSynergy((SInt32)delta)); } } break; } case kSynergyEventMouseScroll: { OSStatus r; long xScroll; long yScroll; // get scroll amount r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisX, typeLongInteger, NULL, sizeof(xScroll), NULL, &xScroll); if (r != noErr) { xScroll = 0; } r = GetEventParameter(*carbonEvent, kSynergyMouseScrollAxisY, typeLongInteger, NULL, sizeof(yScroll), NULL, &yScroll); if (r != noErr) { yScroll = 0; } if (xScroll != 0 || yScroll != 0) { onMouseWheel(-mapScrollWheelToSynergy(xScroll), mapScrollWheelToSynergy(yScroll)); } } } break; case kEventClassKeyboard: switch (GetEventKind(*carbonEvent)) { case kEventRawKeyUp: case kEventRawKeyDown: case kEventRawKeyRepeat: case kEventRawKeyModifiersChanged: onKey(*carbonEvent); break; case kEventHotKeyPressed: case kEventHotKeyReleased: onHotKey(*carbonEvent); break; } break; case kEventClassWindow: SendEventToWindow(*carbonEvent, m_userInputWindow); switch (GetEventKind(*carbonEvent)) { case kEventWindowActivated: LOG((CLOG_DEBUG1 "window activated")); break; case kEventWindowDeactivated: LOG((CLOG_DEBUG1 "window deactivated")); break; case kEventWindowFocusAcquired: LOG((CLOG_DEBUG1 "focus acquired")); break; case kEventWindowFocusRelinquish: LOG((CLOG_DEBUG1 "focus released")); break; } break; default: SendEventToEventTarget(*carbonEvent, GetEventDispatcherTarget()); break; } }