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.
C Headers/CarbonEventHandlers.h
////////////////////////////////////////////////////////////////////////////////// |
/* |
File: CarbonEventHandlers.h |
Project: CarbonEvent Shell |
Contains: Declarations for the Carbon event functions demonstrated |
in this project |
Author: Todd Previte |
Copyright: 2001 Apple Computer, Inc., All Rights Reserved |
Copyright: (c) 2002 Apple Computer, Inc., All Rights Reserved |
Disclaimer: |
IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. |
("Apple") in consideration of your agreement to the following terms, and your |
use, installation, modification or redistribution of this Apple software |
constitutes acceptance of these terms. If you do not agree with these terms, |
please do not use, install, modify or redistribute this Apple software. |
In consideration of your agreement to abide by the following terms, and subject |
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs |
copyrights in this original Apple software (the "Apple Software"), to use, |
reproduce, modify and redistribute the Apple Software, with or without |
modifications, in source and/or binary forms; provided that if you redistribute |
the Apple Software in its entirety and without modifications, you must retain |
this notice and the following text and disclaimers in all such redistributions of |
the Apple Software. Neither the name, trademarks, service marks or logos of |
Apple Computer, Inc. may be used to endorse or promote products derived from the |
Apple Software without specific prior written permission from Apple. Except as |
expressly stated in this notice, no other rights or licenses, express or implied, |
are granted by Apple herein, including but not limited to any patent rights that |
may be infringed by your derivative works or by other works in which the Apple |
Software may be incorporated. |
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO |
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED |
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN |
COMBINATION WITH YOUR PRODUCTS. |
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR |
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE |
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION |
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT |
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN |
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
////////////////////////////////////////////////////////////////////////////////// |
#ifndef __CarbonEventHandlers |
#define __CarbonEventHandlers |
#include "CarbonHead.h" |
#include "ControlInfo.h" |
#include "MenuInfo.h" |
#include "GLDataStructs.h" |
#include "WindowControl.h" |
// NOTE: Globals are defined in CarbonEventHandlers.c |
extern EventHandlerUPP appCommandProcessor; |
extern EventHandlerUPP windowEventProcessor; |
extern EventHandlerUPP menuEventProcessor; |
extern EventHandlerUPP controlEventProcessor; |
extern ControlRef buttonSnapshot; |
extern ControlRef buttonSequence; |
extern ControlRef buttonStart; |
extern ControlRef sequenceTimeInterval; |
extern ControlRef sequenceFrameCount; |
extern ControlRef movieTimeLimit; |
extern ControlRef movieFrameCount; |
extern ControlRef movieFramesCapturedCounter; |
extern ControlRef movieProgressBar; |
extern ControlRef movieSwitchUseTimeLimit; |
extern ControlRef movieSwitchUseFrameLimit; |
extern ControlRef movieFrameRate; |
// Rendering loop timer. Controls the rate at which we're drawing frames |
extern EventLoopTimerRef renderTimer; |
extern EventLoopTimerUPP renderTimerUPP; |
// Snapshot timer. Controls the rate at which we're taking snapshot/movie sequences |
extern EventLoopTimerRef snapshotTimer; |
extern EventLoopTimerUPP snapshotTimerUPP; |
// Other globals |
extern WindowRef pMainWindow; |
extern MenuHandle pMainMenu; |
extern MenuRef theMenu; |
extern bool appQuit; |
extern ControlRef ctrlRef; |
extern ControlID ctrlID; |
extern bool appQuit; |
extern GLWindow mainWindow; |
extern int movieUseFrameLimit; |
extern int movieUseTimeLimit; |
extern long seqTimeInt; |
extern long seqFrameCount; |
extern long movTimeLimit; |
extern long movFrameCount; |
extern long fps; |
extern long movFramesCaptured; |
extern GWorldPtr *gwBuffer; |
extern long imageCount; |
// Event handlers & their global variables |
extern pascal OSStatus MainAppEventHandler(EventHandlerCallRef appHandler, EventRef theEvent, void* appData); |
extern pascal OSStatus MainWindowEventHandler(EventHandlerCallRef windowHandler, EventRef theEvent, void* winData); |
extern pascal OSStatus MainMenuEventHandler(EventHandlerCallRef windowHandler, EventRef theEvent, void* winData); |
extern pascal OSStatus ControlEventHandler(EventHandlerCallRef windowHandler, EventRef theEvent, void* ctrlData); |
extern pascal void RenderTimedEventProcessor(EventLoopTimerRef inTimer, void* timeData); |
extern pascal void SnapshotTimedEventProcessor(EventLoopTimerRef inTimer, void* timeData); |
extern pascal void MovieCaptureTimedEventProcessor(EventLoopTimerRef inTimer, void* timeData); |
// Other utility functions |
extern void UpdateTimer(long newFireTime); |
extern void InstallEventHandlers(void); |
// The following is defined in GLMain.c |
extern void Render(GLWindow *glw); |
// These are the event types we're registering for. The complete list (semi-documented) is contained |
// in the CarbonEvents.h header file in the Carbon SDK. |
// Note on mouse deltas: if you install the handler at the APPLICATION level, you get the global |
// delta, as in for the entire width of the screen. If you install it at the WINDOW level, |
// you only get the deltas while the mouse remains within the bounds of the window. |
// I don't deal with menu events here. They're mainly for doing things when you need to know when your |
// menus begin and end tracking, when they display, etc. To handle commands from menus, it's best to |
// specify them in InterfaceBuilder (if nib-based. programmatically otherwise) and handle them with |
// your HICommand handling function. |
static const EventTypeSpec appEventList[] = |
{ |
{kEventClassCommand, kEventCommandProcess}, |
{kEventClassMouse, kEventMouseDown}, |
{kEventClassMouse, kEventMouseUp}, |
{kEventClassMouse, kEventMouseMoved}, |
{kEventClassMouse, kEventMouseDragged}, |
{kEventClassMouse, kEventMouseWheelMoved} |
}; |
static const EventTypeSpec windowEventList[] = |
{ |
{kEventClassKeyboard, kEventRawKeyDown}, |
{kEventClassKeyboard, kEventRawKeyRepeat}, |
{kEventClassKeyboard, kEventRawKeyUp}, |
{kEventClassKeyboard, kEventRawKeyModifiersChanged}, |
{kEventClassKeyboard, kEventHotKeyPressed}, |
{kEventClassKeyboard, kEventHotKeyReleased}, |
{kEventClassWindow, kEventWindowClose}, |
{kEventClassWindow, kEventWindowDrawContent}, |
{kEventClassWindow, kEventWindowBoundsChanged}, |
// Handled at the APP level. Change if need to be window-constrained |
// {kEventClassMouse, kEventMouseDown}, |
// {kEventClassMouse, kEventMouseUp}, |
// {kEventClassMouse, kEventMouseMoved}, |
// {kEventClassMouse, kEventMouseDragged}, |
// {kEventClassMouse, kEventMouseWheelMoved} |
}; |
static const EventTypeSpec menuEventList[] = |
{ |
{kEventClassMenu, kEventMenuBeginTracking}, |
{kEventClassMenu, kEventMenuEndTracking}, |
{kEventClassMenu, kEventMenuChangeTrackingMode}, |
{kEventClassMenu, kEventMenuOpening}, |
{kEventClassMenu, kEventMenuClosed}, |
{kEventClassMenu, kEventMenuTargetItem}, |
{kEventClassMenu, kEventMenuMatchKey}, |
{kEventClassMenu, kEventMenuEnableItems}, |
}; |
// These are the events we handle for controls in our support window |
// Note, this list is basically all control events. We handle very few. |
static const EventTypeSpec supportWindowEventList[] = |
{ |
// {kEventClassControl, kEventControlInitialize}, |
// {kEventClassControl, kEventControlDispose}, |
// {kEventClassControl, kEventControlGetOptimalBounds}, |
// {kEventClassControl, kEventControlDefInitialize}, |
// {kEventClassControl, kEventControlDefDispose}, |
{kEventClassControl, kEventControlHit}, |
// {kEventClassControl, kEventControlSimulateHit}, |
// {kEventClassControl, kEventControlHitTest}, |
// {kEventClassControl, kEventControlDraw}, |
// {kEventClassControl, kEventControlApplyBackground}, |
// {kEventClassControl, kEventControlApplyTextColor}, |
// {kEventClassControl, kEventControlSetFocusPart}, |
// {kEventClassControl, kEventControlGetFocusPart}, |
// {kEventClassControl, kEventControlActivate}, |
// {kEventClassControl, kEventControlDeactivate}, |
// {kEventClassControl, kEventControlSetCursor}, |
// {kEventClassControl, kEventControlContextualMenuClick }, |
// {kEventClassControl, kEventControlClick}, |
// {kEventClassControl, kEventControlTrack}, |
// {kEventClassControl, kEventControlGetScrollToHereStartPoint}, |
// {kEventClassControl, kEventControlGetIndicatorDragConstraint}, |
// {kEventClassControl, kEventControlIndicatorMoved}, |
// {kEventClassControl, kEventControlGhostingFinished}, |
// {kEventClassControl, kEventControlGetActionProcPart}, |
// {kEventClassControl, kEventControlGetPartRegion}, |
// {kEventClassControl, kEventControlGetPartBounds}, |
{kEventClassControl, kEventControlSetData}, |
{kEventClassControl, kEventControlGetData}, |
// {kEventClassControl, kEventControlValueFieldChanged}, |
// {kEventClassControl, kEventControlAddedSubControl}, |
// {kEventClassControl, kEventControlRemovingSubControl}, |
// {kEventClassControl, kEventControlBoundsChanged}, |
// {kEventClassControl, kEventControlOwningWindowChanged}, |
// {kEventClassControl, kEventControlArbitraryMessage} |
}; |
#endif |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-07-07