summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXEvent.c
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2008-10-27 11:55:44 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2008-10-27 11:55:44 (GMT)
commit957201cb93aa79eb303379cbfd71c1d37f4772ab (patch)
treeef28b1355dbaebeb1a8e7476dd622f89bd35c406 /macosx/tkMacOSXEvent.c
parent1f5835f567b76c544877c30f2eb28456a0db5643 (diff)
downloadtk-957201cb93aa79eb303379cbfd71c1d37f4772ab.zip
tk-957201cb93aa79eb303379cbfd71c1d37f4772ab.tar.gz
tk-957201cb93aa79eb303379cbfd71c1d37f4772ab.tar.bz2
Code style improvements, especially including making code less deeply nested.
Diffstat (limited to 'macosx/tkMacOSXEvent.c')
-rw-r--r--macosx/tkMacOSXEvent.c213
1 files changed, 117 insertions, 96 deletions
diff --git a/macosx/tkMacOSXEvent.c b/macosx/tkMacOSXEvent.c
index c3e3cea..11114c2 100644
--- a/macosx/tkMacOSXEvent.c
+++ b/macosx/tkMacOSXEvent.c
@@ -10,21 +10,20 @@
* 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.23 2007/12/13 15:27:09 dgp Exp $
+ * RCS: @(#) $Id: tkMacOSXEvent.c,v 1.24 2008/10/27 11:55:44 dkf Exp $
*/
#include "tkMacOSXPrivate.h"
#include "tkMacOSXEvent.h"
#include "tkMacOSXDebug.h"
-
/*
*----------------------------------------------------------------------
*
* TkMacOSXFlushWindows --
*
- * This routine flushes all the Carbon windows of the application. It
- * is called by XSync().
+ * This routine flushes all the Carbon windows of the application. It is
+ * called by XSync().
*
* Results:
* None.
@@ -62,10 +61,10 @@ TkMacOSXFlushWindows(void)
* 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:
* 0 on success
@@ -83,32 +82,32 @@ TkMacOSXProcessEvent(
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 kEventClassAppearance:
- TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr);
- break;
- case kEventClassMenu:
- TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
- break;
- case kEventClassCommand:
- TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
- break;
- default: {
- TkMacOSXDbgMsg("Unrecognised event: %s",
- TkMacOSXCarbonEventToAscii(eventPtr->eventRef));
- 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 kEventClassAppearance:
+ TkMacOSXProcessAppearanceEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassMenu:
+ TkMacOSXProcessMenuEvent(eventPtr, statusPtr);
+ break;
+ case kEventClassCommand:
+ TkMacOSXProcessCommandEvent(eventPtr, statusPtr);
+ break;
+ default: {
+ TkMacOSXDbgMsg("Unrecognised event: %s",
+ TkMacOSXCarbonEventToAscii(eventPtr->eventRef));
+ break;
+ }
}
return 0;
}
@@ -118,8 +117,8 @@ TkMacOSXProcessEvent(
*
* 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.
@@ -137,61 +136,65 @@ TkMacOSXProcessMenuEvent(
{
int menuContext;
OSStatus err;
+ MenuRef menu;
+ MenuItemIndex index;
switch (eventPtr->eKind) {
- case kEventMenuBeginTracking:
- case kEventMenuEndTracking:
- case kEventMenuOpening:
- case kEventMenuTargetItem:
- break;
- default:
- return 0;
- break;
+ case kEventMenuBeginTracking:
+ case kEventMenuEndTracking:
+ case kEventMenuOpening:
+ case kEventMenuTargetItem:
+ break;
+ default:
+ return 0;
+ }
+ err = ChkErr(GetEventParameter, eventPtr->eventRef,
+ kEventParamMenuContext, typeUInt32, NULL, sizeof(menuContext),
+ NULL, &menuContext);
+ if (err != noErr) {
+ return 0;
}
- 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();
+ if ((menuContext & kMenuContextMenuBarTracking) ||
+ (menuContext & kMenuContextPopUpTracking)) {
+ switch (eventPtr->eKind) {
+ case kEventMenuBeginTracking:
+ TkMacOSXClearMenubarActive();
- /*
- * Handle -postcommand
- */
+ /*
+ * 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;
+ 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) {
+ return 0;
+ }
+ TkMacOSXClearActiveMenu(menu);
+ return TkMacOSXGenerateParentMenuSelectEvent(menu);
+ case kEventMenuTargetItem:
+ err = ChkErr(GetEventParameter, eventPtr->eventRef,
+ kEventParamDirectObject, typeMenuRef, NULL, sizeof(menu),
+ NULL, &menu);
+ if (err != noErr) {
+ return 0;
+ }
- err = ChkErr(GetEventParameter, eventPtr->eventRef,
- kEventParamMenuItemIndex, typeMenuItemIndex, NULL,
- sizeof(index), NULL, &index);
- if (err == noErr) {
- return TkMacOSXGenerateMenuSelectEvent(menu, index);
- }
- }
- break;
+ err = ChkErr(GetEventParameter, eventPtr->eventRef,
+ kEventParamMenuItemIndex, typeMenuItemIndex, NULL,
+ sizeof(index), NULL, &index);
+ if (err != noErr) {
+ return 0;
+ }
+ return TkMacOSXGenerateMenuSelectEvent(menu, index);
}
}
return 0;
@@ -202,8 +205,8 @@ TkMacOSXProcessMenuEvent(
*
* 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.
@@ -217,29 +220,37 @@ TkMacOSXProcessMenuEvent(
MODULE_SCOPE int
TkMacOSXProcessCommandEvent(
TkMacOSXEvent *eventPtr,
- MacEventStatus * statusPtr)
+ MacEventStatus *statusPtr)
{
HICommand command;
int menuContext;
OSStatus err;
switch (eventPtr->eKind) {
- case kEventCommandProcess:
- case kEventCommandUpdateStatus:
- break;
- default:
- return 0;
- break;
+ case kEventCommandProcess:
+ case kEventCommandUpdateStatus:
+ break;
+ default:
+ return 0;
}
+
err = ChkErr(GetEventParameter, eventPtr->eventRef,
kEventParamDirectObject, typeHICommand, NULL, sizeof(command),
NULL, &command);
- if (err == noErr && (command.attributes & kHICommandFromMenu)) {
+ if (err != noErr) {
+ return 0;
+ }
+
+ if (command.attributes & kHICommandFromMenu) {
if (eventPtr->eKind == kEventCommandProcess) {
err = ChkErr(GetEventParameter, eventPtr->eventRef,
kEventParamMenuContext, typeUInt32, NULL,
sizeof(menuContext), NULL, &menuContext);
- if (err == noErr && (menuContext & kMenuContextMenuBar) &&
+ if (err != noErr) {
+ return 0;
+ }
+
+ if ((menuContext & kMenuContextMenuBar) &&
(menuContext & kMenuContextMenuBarTracking)) {
TkMacOSXHandleMenuSelect(GetMenuID(command.menu.menuRef),
command.menu.menuItemIndex,
@@ -248,7 +259,9 @@ TkMacOSXProcessCommandEvent(
}
} else {
Tcl_CmdInfo dummy;
- if (command.commandID == kHICommandPreferences && eventPtr->interp) {
+
+ if (command.commandID == kHICommandPreferences
+ && eventPtr->interp != NULL) {
if (Tcl_GetCommandInfo(eventPtr->interp,
"::tk::mac::ShowPreferences", &dummy)) {
if (!IsMenuItemEnabled(command.menu.menuRef,
@@ -270,3 +283,11 @@ TkMacOSXProcessCommandEvent(
}
return 0;
}
+
+/*
+ * Local Variables:
+ * mode: c
+ * c-basic-offset: 4
+ * fill-column: 78
+ * End:
+ */