Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Source/Events.c
/****************************/ |
/* EVENTS */ |
/* By Brian Greenstone */ |
/****************************/ |
/***************/ |
/* EXTERNALS */ |
/***************/ |
#include <Windows.h> |
#include <ToolUtils.h> |
#include <QD3D.h> |
#include "myglobals.h" |
#include "myevents.h" |
#include "mymenus.h" |
#include "main.h" |
#include "misc.h" |
#include "qd3d_support.h" |
#include "process.h" |
extern WindowPtr gModelWindow; |
extern QD3DSetupOutputType gModelViewInfo; |
/****************************/ |
/* PROTOTYPES */ |
/****************************/ |
static void DoHighLevelEvent(void); |
static Boolean IsDAWindow(WindowPtr whichWindow); |
static OSErr hasGotRequiredParams(AppleEvent *appEvent); |
/****************************/ |
/* CONSTANTS */ |
/****************************/ |
#define MIN_SLEEP 0L |
#define NIL_MOUSE_REGION 0L |
/**********************/ |
/* VARIABLES */ |
/**********************/ |
EventRecord gTheEvent; |
/******************/ |
/* HANDLE EVENTS */ |
/******************/ |
void HandleEvents() |
{ |
char theChar; |
GrafPtr oldPort; |
WaitNextEvent(everyEvent,&gTheEvent, MIN_SLEEP, NIL_MOUSE_REGION); |
switch (gTheEvent.what) |
{ |
case nullEvent: |
HandleNullEvent(); |
break; |
case mouseDown: |
HandleMouseDown(); |
break; |
case keyDown: |
case autoKey: |
theChar = gTheEvent.message & charCodeMask; |
if ((gTheEvent.modifiers & cmdKey) != 0) |
HandleMenuChoice(MenuKey(theChar)); |
else |
HandleKeyDown(theChar); |
break; |
case updateEvt: |
if (!IsDAWindow((WindowPtr)gTheEvent.message)) |
{ |
GetPort (&oldPort); |
SetPort ((WindowPtr)gTheEvent.message); |
BeginUpdate((WindowPtr)gTheEvent.message); |
DrawControls((WindowPtr)gTheEvent.message); |
if ((WindowPtr)gTheEvent.message == gModelWindow) |
UpdateModelWindow(); |
EndUpdate((WindowPtr)gTheEvent.message); |
SetPort(oldPort); |
} |
else |
{ |
BeginUpdate((WindowPtr)gTheEvent.message); |
EndUpdate((WindowPtr)gTheEvent.message); |
} |
break; |
case kHighLevelEvent: |
DoHighLevelEvent(); |
break; |
} |
} |
/**************** DO HIGH LEVEL EVENT *****************/ |
static void DoHighLevelEvent(void) |
{ |
OSErr myErr; |
myErr = AEProcessAppleEvent(&gTheEvent); |
} |
/**********************/ |
/* HANDLE MOUSE DOWN */ |
/**********************/ |
void HandleMouseDown(void) |
{ |
WindowPtr whichWindow; |
short thePart; |
long menuChoice, windSize; |
thePart = FindWindow(gTheEvent.where, &whichWindow); |
switch(thePart) |
{ |
case inMenuBar: |
menuChoice = MenuSelect(gTheEvent.where); |
HandleMenuChoice(menuChoice); |
break; |
case inSysWindow: |
SystemClick(&gTheEvent, whichWindow); |
break; |
case inDrag: |
DragWindow(whichWindow,gTheEvent.where, &qd.screenBits.bounds); |
break; |
case inGoAway: |
DisposeWindow (whichWindow); |
break; |
case inContent: |
SelectWindow(whichWindow); |
break; |
case inGrow: |
windSize = GrowWindow(whichWindow, gTheEvent.where, |
&(**GetGrayRgn()).rgnBBox); |
if (windSize != 0) |
{ |
SetPort(whichWindow); |
EraseRect(&whichWindow->portRect); |
SizeWindow(whichWindow,LoWord(windSize), |
HiWord(windSize), NORMAL_UPDATES); |
InvalRect(&whichWindow->portRect); |
if (whichWindow == gModelWindow) // see if change Skeleton window |
{ |
QD3D_ChangeDrawSize(&gModelViewInfo); |
} |
} |
break; |
} |
} |
/*****************/ |
/* Is DA Window? */ |
/*****************/ |
// DA WINDOWS HAVE NEGATEIVE windowKinds // |
static Boolean IsDAWindow(WindowPtr whichWindow) |
{ |
if (whichWindow == NIL_POINTER) |
return (false); |
else |
return (((WindowPeek)whichWindow)->windowKind < 0); |
} |
/**********************/ |
/* HANDLE NULL EVENT */ |
/**********************/ |
void HandleNullEvent() |
{ |
// DoModelWindowNullEvent(); |
} |
/******************** HANDLE KEY DOWN *******************/ |
void HandleKeyDown(char theKey) |
{ |
#pragma unused(theKey) |
} |
/*********************** MY APPLE EVENT: QUIT APPLICATION *************************/ |
pascal OSErr MyAE_QuitApplication(AppleEvent *theAppleEvent, AppleEvent *reply, |
SInt32 handlerRefcon) |
{ |
#pragma unused(theAppleEvent, reply, handlerRefcon) |
CleanQuit(); |
return(noErr); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14