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.
IconDisplay.c
/* |
File: IconDisplay.c |
Contains: Demonstartion of manual drawing from icon resources to an offscreen buffer, |
then onscreen blitting. |
Written by: |
Copyright: Copyright © 1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
7/9/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
*/ |
#include <MacTypes.h> |
#include <Quickdraw.h> |
#include <Fonts.h> |
#include <Windows.h> |
#include <Dialogs.h> |
#include <Menus.h> |
#include <TextEdit.h> |
#include <Menus.h> |
#include <Events.h> |
#include "IconMenus.h" |
#include "IconWindow.h" |
extern WindowPtr bullseyeWindow; |
extern Rect dragRect; |
extern Rect PlotRect; |
void InitMacintosh(); |
void HandleMouseDown(EventRecord *theEvent); |
void HandleEvent(); |
/**** |
* InitMacintosh() |
* |
* Initialize all the managers & memory |
* |
****/ |
void InitMacintosh() |
{ |
MaxApplZone(); |
InitGraf(&qd.thePort); |
InitFonts(); |
FlushEvents(everyEvent, 0); |
InitWindows(); |
InitMenus(); |
TEInit(); |
InitDialogs(0L); |
InitCursor(); |
} |
/* end InitMacintosh */ |
/**** |
* HandleMouseDown (theEvent) |
* |
* Take care of mouseDown events. |
* |
****/ |
void HandleMouseDown(EventRecord *theEvent) |
{ |
WindowPtr theWindow; |
int windowCode = FindWindow (theEvent->where, &theWindow); |
switch (windowCode) |
{ |
case inSysWindow: |
SystemClick (theEvent, theWindow); |
break; |
case inMenuBar: |
AdjustMenus(); |
HandleMenu(MenuSelect(theEvent->where)); |
break; |
case inDrag: |
if (theWindow == bullseyeWindow) |
DragWindow(bullseyeWindow, theEvent->where, &dragRect); |
FindNewDevice(bullseyeWindow); /* see if the device has changed and inval small icon if so*/ |
break; |
case inContent: |
if (theWindow == bullseyeWindow) |
{ |
if (theWindow != FrontWindow()) |
SelectWindow(bullseyeWindow); |
else |
InvalRect(&bullseyeWindow->portRect); |
} |
break; |
case inGoAway: |
if (theWindow == bullseyeWindow && |
TrackGoAway(bullseyeWindow, theEvent->where)) |
HideWindow(bullseyeWindow); |
break; |
} |
} |
/* end HandleMouseDown */ |
/**** |
* HandleEvent() |
* |
* The main event dispatcher. This routine should be called |
* repeatedly (it handles only one event). |
* |
*****/ |
void HandleEvent() |
{ |
int ok; |
EventRecord theEvent; |
HiliteMenu(0); |
SystemTask (); /* Handle desk accessories */ |
ok = GetNextEvent (everyEvent, &theEvent); |
if (ok) |
switch (theEvent.what) |
{ |
case mouseDown: |
HandleMouseDown(&theEvent); |
break; |
case keyDown: |
case autoKey: |
if ((theEvent.modifiers & cmdKey) != 0) |
{ |
AdjustMenus(); |
HandleMenu(MenuKey((char) (theEvent.message & charCodeMask))); |
} |
break; |
case updateEvt: |
BeginUpdate(bullseyeWindow); |
DrawBullseye(((WindowPeek) bullseyeWindow)->hilited); |
EndUpdate(bullseyeWindow); |
break; |
case activateEvt: |
InvalRect(&bullseyeWindow->portRect); |
break; |
} |
} |
/* end HandleEvent */ |
/***** |
* main() |
* |
* This is where everything happens |
* |
*****/ |
void main() |
{ |
InitMacintosh(); |
SetUpMenus(); |
SetUpWindow(); |
for (;;) |
HandleEvent(); |
} |
/* end main */ |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-07-22