diff options
Diffstat (limited to 'macosx/tkMacOSXEvent.c')
-rw-r--r-- | macosx/tkMacOSXEvent.c | 330 |
1 files changed, 107 insertions, 223 deletions
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c index 5da46a9..73a67ad 100644 --- a/macosx/tkMacOSXEvent.c +++ b/macosx/tkMacOSXEvent.c @@ -4,8 +4,8 @@ * This file contains the basic Mac OS X Event handling routines. * * Copyright (c) 1995-1997 Sun Microsystems, Inc. - * Copyright 2001, Apple Computer, Inc. - * Copyright (c) 2005-2007 Daniel A. Steffen <das@users.sourceforge.net> + * Copyright 2001-2009, Apple Inc. + * Copyright (c) 2005-2009 Daniel A. Steffen <das@users.sourceforge.net> * * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. @@ -15,256 +15,140 @@ #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" - -/* - *---------------------------------------------------------------------- - * - * TkMacOSXFlushWindows -- - * - * This routine flushes all the Carbon windows of the application. It - * is called by XSync(). - * - * Results: - * None. - * - * Side effects: - * Flushes all Carbon windows - * - *---------------------------------------------------------------------- - */ +#pragma mark TKApplication(TKEvent) -MODULE_SCOPE void -TkMacOSXFlushWindows(void) -{ - WindowRef wRef = GetWindowList(); +enum { + NSWindowWillMoveEventType = 20 +}; - while (wRef) { - TK_IF_MAC_OS_X_API (3, HIWindowFlush, - ChkErr(HIWindowFlush, wRef); - ) TK_ELSE_MAC_OS_X (3, - CGrafPtr portPtr = GetWindowPort(wRef); +@implementation TKApplication(TKEvent) +/* TODO: replace by +[addLocalMonitorForEventsMatchingMask ? */ +- (NSEvent *)tkProcessEvent:(NSEvent *)theEvent { +#ifdef TK_MAC_DEBUG_EVENTS + TKLog(@"-[%@(%p) %s] %@", [self class], self, _cmd, theEvent); +#endif + NSEvent *processedEvent = theEvent; + NSEventType type = [theEvent type]; + NSInteger subtype; + NSUInteger flags; - if (QDIsPortBuffered(portPtr)) { - QDFlushPortBuffer(portPtr, NULL); - } - ) TK_ENDIF - wRef = GetNextWindow(wRef); - } -} - -/* - *---------------------------------------------------------------------- - * - * TkMacOSXProcessEvent -- - * - * This dispatches a filtered Carbon event to the appropriate handler - * - * Note on MacEventStatus.stopProcessing: Please be conservative in the - * individual handlers and don't assume the event is fully handled - * unless you *really* need to ensure that other handlers don't see the - * event anymore. Some OS manager or library might be interested in - * events even after they are already handled on the Tk level. - * - * Results: - * 0 on success - * -1 on failure - * - * Side effects: - * Converts a Carbon event to a Tk event - * - *---------------------------------------------------------------------- - */ + switch ((NSInteger)type) { + case NSAppKitDefined: + subtype = [theEvent subtype]; -MODULE_SCOPE int -TkMacOSXProcessEvent( - TkMacOSXEvent *eventPtr, - MacEventStatus *statusPtr) -{ - switch (eventPtr->eClass) { - case kEventClassMouse: - TkMacOSXProcessMouseEvent(eventPtr, statusPtr); - break; - case kEventClassWindow: - TkMacOSXProcessWindowEvent(eventPtr, statusPtr); - break; - case kEventClassKeyboard: - TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr); - break; - case kEventClassApplication: - TkMacOSXProcessApplicationEvent(eventPtr, statusPtr); + switch (subtype) { + case NSApplicationActivatedEventType: break; - case kEventClassAppearance: - TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr); + case NSApplicationDeactivatedEventType: break; - case kEventClassMenu: - TkMacOSXProcessMenuEvent(eventPtr, statusPtr); + case NSWindowExposedEventType: + case NSScreenChangedEventType: break; - case kEventClassCommand: - TkMacOSXProcessCommandEvent(eventPtr, statusPtr); - break; - default: { - TkMacOSXDbgMsg("Unrecognised event: %s", - TkMacOSXCarbonEventToAscii(eventPtr->eventRef)); + case NSWindowMovedEventType: break; + case NSWindowWillMoveEventType: + break; + + default: + break; + } + break; + case NSKeyUp: + case NSKeyDown: + case NSFlagsChanged: + flags = [theEvent modifierFlags]; + processedEvent = [self tkProcessKeyEvent:theEvent]; + break; + case NSLeftMouseDown: + case NSLeftMouseUp: + case NSRightMouseDown: + case NSRightMouseUp: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSMouseMoved: + case NSMouseEntered: + case NSMouseExited: + case NSScrollWheel: + case NSOtherMouseDown: + case NSOtherMouseUp: + case NSOtherMouseDragged: + case NSTabletPoint: + case NSTabletProximity: + processedEvent = [self tkProcessMouseEvent:theEvent]; + break; +#if 0 + case NSSystemDefined: + subtype = [theEvent subtype]; + break; + case NSApplicationDefined: { + id win; + win = [theEvent window]; + break; } + case NSCursorUpdate: + break; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 + case NSEventTypeGesture: + case NSEventTypeMagnify: + case NSEventTypeRotate: + case NSEventTypeSwipe: + case NSEventTypeBeginGesture: + case NSEventTypeEndGesture: + break; +#endif +#endif + + default: + break; } - return 0; + return processedEvent; } +@end + +#pragma mark - /* *---------------------------------------------------------------------- * - * TkMacOSXProcessMenuEvent -- + * TkMacOSXFlushWindows -- * - * This routine processes the event in eventPtr, and - * generates the appropriate Tk events from it. + * This routine flushes all the windows of the application. It is + * called by XSync(). * * Results: - * True if event(s) are generated - false otherwise. + * None. * * Side effects: - * Additional events may be place on the Tk event queue. + * Flushes all Carbon windows * *---------------------------------------------------------------------- */ -MODULE_SCOPE int -TkMacOSXProcessMenuEvent( - TkMacOSXEvent *eventPtr, - MacEventStatus *statusPtr) +MODULE_SCOPE void +TkMacOSXFlushWindows(void) { - int menuContext; - OSStatus err; + NSInteger windowCount; + NSInteger *windowNumbers; - switch (eventPtr->eKind) { - case kEventMenuBeginTracking: - case kEventMenuEndTracking: - case kEventMenuOpening: - case kEventMenuTargetItem: - break; - default: - return 0; - break; - } - err = ChkErr(GetEventParameter, eventPtr->eventRef, kEventParamMenuContext, - typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext); - if (err == noErr && ((menuContext & kMenuContextMenuBarTracking) || - (menuContext & kMenuContextPopUpTracking))) { - switch (eventPtr->eKind) { - MenuRef menu; - - case kEventMenuBeginTracking: - TkMacOSXClearMenubarActive(); - - /* - * Handle -postcommand - */ - - TkMacOSXPreprocessMenu(); - TkMacOSXTrackingLoop(1); - break; - case kEventMenuEndTracking: - TkMacOSXTrackingLoop(0); - break; - case kEventMenuOpening: - err = ChkErr(GetEventParameter, eventPtr->eventRef, - kEventParamDirectObject, typeMenuRef, NULL, - sizeof(menu), NULL, &menu); - if (err == noErr) { - TkMacOSXClearActiveMenu(menu); - return TkMacOSXGenerateParentMenuSelectEvent(menu); - } - break; - case kEventMenuTargetItem: - err = ChkErr(GetEventParameter, eventPtr->eventRef, - kEventParamDirectObject, typeMenuRef, NULL, - sizeof(menu), NULL, &menu); - if (err == noErr) { - MenuItemIndex index; - - err = ChkErr(GetEventParameter, eventPtr->eventRef, - kEventParamMenuItemIndex, typeMenuItemIndex, NULL, - sizeof(index), NULL, &index); - if (err == noErr) { - return TkMacOSXGenerateMenuSelectEvent(menu, index); - } - } - break; + NSCountWindows(&windowCount); + if(windowCount) { + windowNumbers = (NSInteger *) ckalloc(windowCount * sizeof(NSInteger)); + NSWindowList(windowCount, windowNumbers); + for (NSInteger index = 0; index < windowCount; index++) { + NSWindow *w = [NSApp windowWithWindowNumber:windowNumbers[index]]; + if (TkMacOSXGetXWindow(w)) { + [w flushWindow]; + } } + ckfree((char*) windowNumbers); } - return 0; } /* - *---------------------------------------------------------------------- - * - * TkMacOSXProcessCommandEvent -- - * - * This routine processes the event in eventPtr, and - * generates the appropriate Tk events from it. - * - * Results: - * True if event(s) are generated - false otherwise. - * - * Side effects: - * Additional events may be place on the Tk event queue. - * - *---------------------------------------------------------------------- + * Local Variables: + * mode: objc + * c-basic-offset: 4 + * fill-column: 79 + * coding: utf-8 + * End: */ - -MODULE_SCOPE int -TkMacOSXProcessCommandEvent( - TkMacOSXEvent *eventPtr, - MacEventStatus * statusPtr) -{ - HICommand command; - int menuContext; - OSStatus err; - - switch (eventPtr->eKind) { - case kEventCommandProcess: - case kEventCommandUpdateStatus: - break; - default: - return 0; - break; - } - err = ChkErr(GetEventParameter, eventPtr->eventRef, - kEventParamDirectObject, typeHICommand, NULL, sizeof(command), - NULL, &command); - if (err == noErr && (command.attributes & kHICommandFromMenu)) { - if (eventPtr->eKind == kEventCommandProcess) { - err = ChkErr(GetEventParameter, eventPtr->eventRef, - kEventParamMenuContext, typeUInt32, NULL, - sizeof(menuContext), NULL, &menuContext); - if (err == noErr && (menuContext & kMenuContextMenuBar) && - (menuContext & kMenuContextMenuBarTracking)) { - TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef), - command.menu.menuItemIndex, - (GetCurrentEventKeyModifiers() & optionKey) != 0); - return 1; - } - } else { - Tcl_CmdInfo dummy; - if (command.commandID == kHICommandPreferences && eventPtr->interp) { - if (Tcl_GetCommandInfo(eventPtr->interp, - "::tk::mac::ShowPreferences", &dummy)) { - if (!IsMenuItemEnabled(command.menu.menuRef, - command.menu.menuItemIndex)) { - EnableMenuItem(command.menu.menuRef, - command.menu.menuItemIndex); - } - } else { - if (IsMenuItemEnabled(command.menu.menuRef, - command.menu.menuItemIndex)) { - DisableMenuItem(command.menu.menuRef, - command.menu.menuItemIndex); - } - } - statusPtr->stopProcessing = 1; - return 1; - } - } - } - return 0; -} |