diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2007-04-13 14:51:17 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2007-04-13 14:51:17 (GMT) |
commit | 57c91ad391ab148036a5c6e4f0fdee7381352a85 (patch) | |
tree | e9f3f498ec12ff4c5603356d84573c8242a537e0 /macosx/tkMacOSXEvent.c | |
parent | 59b73712486121720aa582183db730964dc8c8a9 (diff) | |
download | tk-57c91ad391ab148036a5c6e4f0fdee7381352a85.zip tk-57c91ad391ab148036a5c6e4f0fdee7381352a85.tar.gz tk-57c91ad391ab148036a5c6e4f0fdee7381352a85.tar.bz2 |
Reduce the #ifdef count a lot by adding debug-print macros
Diffstat (limited to 'macosx/tkMacOSXEvent.c')
-rw-r--r-- | macosx/tkMacOSXEvent.c | 235 |
1 files changed, 119 insertions, 116 deletions
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c index 82a4ad0..dd90d6e 100644 --- a/macosx/tkMacOSXEvent.c +++ b/macosx/tkMacOSXEvent.c @@ -1,4 +1,4 @@ -/* +/* * tkMacOSXEvent.c -- * * This file contains the basic Mac OS X Event handling routines. @@ -7,23 +7,23 @@ * Copyright 2001, Apple Computer, Inc. * Copyright (c) 2005-2006 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. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tkMacOSXEvent.c,v 1.12 2006/10/31 22:33:34 das Exp $ + * RCS: @(#) $Id: tkMacOSXEvent.c,v 1.13 2007/04/13 14:51:18 dkf Exp $ */ #include "tkMacOSXInt.h" #include "tkMacOSXEvent.h" #include "tkMacOSXDebug.h" - + /* *---------------------------------------------------------------------- * * TkMacOSXFlushWindows -- * - * This routine flushes all the Carbon windows of the application. It - * is called by the setup procedure for the Tcl/Carbon event source. + * This routine flushes all the Carbon windows of the application. It is + * called by the setup procedure for the Tcl/Carbon event source. * * Results: * None. @@ -35,10 +35,10 @@ */ MODULE_SCOPE void -TkMacOSXFlushWindows () +TkMacOSXFlushWindows(void) { WindowRef wRef = GetWindowList(); - + while (wRef) { CGrafPtr portPtr = GetWindowPort(wRef); if (QDIsPortBuffered(portPtr)) { @@ -48,62 +48,61 @@ TkMacOSXFlushWindows () } } -/* +/* *---------------------------------------------------------------------- - * + * * 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. + * 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: + * Results: * 0 on success * -1 on failure * * Side effects: * Converts a Carbon event to a Tk event - * + * *---------------------------------------------------------------------- */ -MODULE_SCOPE int -TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr) +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); - break; - case kEventClassMenu: - TkMacOSXProcessMenuEvent(eventPtr, statusPtr); - break; - case kEventClassCommand: - TkMacOSXProcessCommandEvent(eventPtr, statusPtr); - break; - default: -#ifdef TK_MAC_DEBUG - { - char buf [256]; - fprintf(stderr, - "Unrecognised event : %s\n", - TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf)); - } -#endif - break; - } + case kEventClassMouse: + TkMacOSXProcessMouseEvent(eventPtr, statusPtr); + break; + case kEventClassWindow: + TkMacOSXProcessWindowEvent(eventPtr, statusPtr); + break; + case kEventClassKeyboard: + TkMacOSXProcessKeyboardEvent(eventPtr, statusPtr); + break; + case kEventClassApplication: + TkMacOSXProcessApplicationEvent(eventPtr, statusPtr); + break; + case kEventClassMenu: + TkMacOSXProcessMenuEvent(eventPtr, statusPtr); + break; + case kEventClassCommand: + TkMacOSXProcessCommandEvent(eventPtr, statusPtr); + break; + default: { + char buf[256]; + + LOG_MSG("Unrecognised event : %s\n", + TkMacOSXCarbonEventToAscii(eventPtr->eventRef, buf)); + break; + } + } return 0; } @@ -112,8 +111,8 @@ TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr) * * TkMacOSXProcessMenuEvent -- * - * This routine processes the event in eventPtr, and - * generates the appropriate Tk events from it. + * This routine processes the event in eventPtr, and generates the + * appropriate Tk events from it. * * Results: * True if event(s) are generated - false otherwise. @@ -125,37 +124,37 @@ TkMacOSXProcessEvent(TkMacOSXEvent * eventPtr, MacEventStatus * statusPtr) */ MODULE_SCOPE int -TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) +TkMacOSXProcessMenuEvent( + TkMacOSXEvent *eventPtr, + MacEventStatus *statusPtr) { - int menuContext; - OSStatus status; + int menuContext; + OSStatus status; switch (eventPtr->eKind) { - case kEventMenuBeginTracking: - case kEventMenuEndTracking: - break; - default: - return 0; - break; + case kEventMenuBeginTracking: + case kEventMenuEndTracking: + break; + default: + return 0; + break; } - status = GetEventParameter(eventPtr->eventRef, - kEventParamMenuContext, - typeUInt32, NULL, - sizeof(menuContext), NULL, - &menuContext); + status = GetEventParameter(eventPtr->eventRef, kEventParamMenuContext, + typeUInt32, NULL, sizeof(menuContext), NULL, &menuContext); if (status == noErr && (menuContext & kMenuContextMenuBar)) { static int oldMode = TCL_SERVICE_ALL; + if (eventPtr->eKind == kEventMenuBeginTracking) { oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); TkMacOSXClearMenubarActive(); - + /* * Handle -postcommand */ - + TkMacOSXPreprocessMenu(); } else { - Tcl_SetServiceMode(oldMode); + Tcl_SetServiceMode(oldMode); } } return 0; @@ -166,8 +165,8 @@ TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) * * TkMacOSXProcessCommandEvent -- * - * This routine processes the event in eventPtr, and - * generates the appropriate Tk events from it. + * This routine processes the event in eventPtr, and generates the + * appropriate Tk events from it. * * Results: * True if event(s) are generated - false otherwise. @@ -179,32 +178,29 @@ TkMacOSXProcessMenuEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) */ MODULE_SCOPE int -TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) +TkMacOSXProcessCommandEvent( + TkMacOSXEvent *eventPtr, + MacEventStatus *statusPtr) { - HICommand command; - int menuContext; - OSStatus status; + HICommand command; + int menuContext; + OSStatus status; switch (eventPtr->eKind) { - case kEventCommandProcess: - case kEventCommandUpdateStatus: - break; - default: - return 0; - break; + case kEventCommandProcess: + case kEventCommandUpdateStatus: + break; + default: + return 0; + break; } - status = GetEventParameter(eventPtr->eventRef, - kEventParamDirectObject, - typeHICommand, NULL, - sizeof(command), NULL, - &command); + status = GetEventParameter(eventPtr->eventRef, kEventParamDirectObject, + typeHICommand, NULL, sizeof(command), NULL, &command); if (status == noErr && (command.attributes & kHICommandFromMenu)) { if (eventPtr->eKind == kEventCommandProcess) { - status = GetEventParameter(eventPtr->eventRef, - kEventParamMenuContext, - typeUInt32, NULL, - sizeof(menuContext), NULL, - &menuContext); + status = GetEventParameter(eventPtr->eventRef, + kEventParamMenuContext, typeUInt32, NULL, + sizeof(menuContext), NULL, &menuContext); if (status == noErr && (menuContext & kMenuContextMenuBar) && (menuContext & kMenuContextMenuBarTracking)) { TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef), @@ -212,26 +208,26 @@ TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) GetCurrentEventKeyModifiers() & optionKey); return 1; } - } else { + } else if (command.commandID == kHICommandPreferences + && eventPtr->interp) { 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); - } + + 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; } + statusPtr->stopProcessing = 1; + return 1; } } return 0; @@ -256,17 +252,17 @@ TkMacOSXProcessCommandEvent(TkMacOSXEvent *eventPtr, MacEventStatus * statusPtr) */ MODULE_SCOPE OSStatus -TkMacOSXReceiveAndProcessEvent() +TkMacOSXReceiveAndProcessEvent(void) { static EventTargetRef targetRef = NULL; EventRef eventRef; OSStatus err; /* - * This is a poll, since we have already counted the events coming - * into this routine, and are guaranteed to have one waiting. + * This is a poll, since we have already counted the events coming into + * this routine, and are guaranteed to have one waiting. */ - + err = ReceiveNextEvent(0, NULL, kEventDurationNoWait, true, &eventRef); if (err == noErr) { if (!targetRef) { @@ -277,11 +273,10 @@ TkMacOSXReceiveAndProcessEvent() TkMacOSXStopTclEventLoopCarbonTimer(); #ifdef TK_MAC_DEBUG if (err != noErr && err != eventLoopTimedOutErr - && err != eventNotHandledErr - ) { - char buf [256]; - fprintf(stderr, - "RCNE SendEventToEventTarget (%s) failed, %d\n", + && err != eventNotHandledErr) { + char buf[256]; + + ERR_MSG("RCNE SendEventToEventTarget (%s) failed, %d", TkMacOSXCarbonEventToAscii(eventRef, buf), (int)err); } #endif @@ -289,3 +284,11 @@ TkMacOSXReceiveAndProcessEvent() } return err; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |