blob: f1dd5af21cef98eed7809c3f87d5854a1bca7c5c [file] [log] [blame]
Jack Jansenc982ef22001-02-15 22:56:41 +00001/*
2 WASTE Demo Project:
3 Sample WASTE Object Handlers
4
5 Copyright © 1993-1998 Marco Piovanelli
6 All Rights Reserved
7*/
8
9#include "WEObjectHandlers.h"
10
11#ifndef __ICONS__
12#include <Icons.h>
13#endif
14
15#ifndef __SOUND__
16#include <Sound.h>
17#endif
18
19/* PICTURES */
20
21pascal OSErr HandleNewPicture(Point *defaultObjectSize, WEObjectReference objectRef)
22{
23 PicHandle thePicture;
24 Rect frame;
25
26 /* get handle to object data (in this case, a picture handle) */
27 thePicture = (PicHandle) WEGetObjectDataHandle(objectRef);
28
29 /* figure out the default object size by looking at the picFrame record */
30 frame = (*thePicture)->picFrame;
31 OffsetRect(&frame, -frame.left, -frame.top);
32 defaultObjectSize->v = frame.bottom;
33 defaultObjectSize->h = frame.right;
34
35 return noErr;
36}
37
38pascal OSErr HandleDisposePicture(WEObjectReference objectRef)
39{
40 PicHandle thePicture;
41
42 /* get handle to object data (in this case, a picture handle) */
43 thePicture = (PicHandle) WEGetObjectDataHandle(objectRef);
44
45 /* kill the picture */
46 KillPicture(thePicture);
47
48 return MemError();
49}
50
51pascal OSErr HandleDrawPicture(const Rect *destRect, WEObjectReference objectRef)
52{
53 PicHandle thePicture;
54
55 /* get handle to object data (in this case, a picture handle) */
56 thePicture = (PicHandle) WEGetObjectDataHandle(objectRef);
57
58 /* draw the picture */
59 DrawPicture(thePicture, destRect);
60
61 return noErr;
62}
63
64
65/* SOUND */
66
67pascal OSErr HandleNewSound(Point *defaultObjectSize, WEObjectReference objectRef)
68{
69#pragma unused(objectRef)
70
71 /* sounds are drawn as standard 32x32 icons */
72 defaultObjectSize->v = 32;
73 defaultObjectSize->h = 32;
74
75 return noErr;
76}
77
78pascal OSErr HandleDrawSound(const Rect *destRect, WEObjectReference objectRef)
79{
80#pragma unused(objectRef)
81
82 /* draw the sound icon */
83 return PlotIconID(destRect, kAlignNone, kTransformNone, kSoundIconID);
84}
85
86pascal Boolean HandleClickSound(Point hitPt, EventModifiers modifiers,
87 UInt32 clickTime, WEObjectReference objectRef)
88{
89#pragma unused(hitPt, clickTime)
90
91 SndListHandle theSound;
92
93 /* WASTE sets the low bit of modifiers on double (multiple) clicks */
94 if (modifiers & 0x0001)
95 {
96
97 /* get a handle to the object data (in this case, a sound handle) */
98 theSound = (SndListHandle) WEGetObjectDataHandle(objectRef);
99
100 /* play the sound */
101 SndPlay(nil, theSound, false);
102
103 /* return TRUE so WASTE knows we handled the click */
104 return true;
105 }
106 else
107 {
108 /* not a double click: let WASTE handle the mouse-down */
109 return false;
110 }
111}