home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
macintosh-pascal
/
macintoshp-1.2-demos.sit.hqx
/
chap22pascal_demo
/
UDemos.p
< prev
next >
Wrap
Text File
|
1999-04-05
|
16KB
|
639 lines
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
// UDemos.p
// ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
unit UDemos;
interface
{ ………………………………………………………………………………………………………………… include the following Universal Interfaces }
uses
Windows, Fonts, Menus, TextEdit, Dialogs, SegLoad, ToolUtils, Devices, GestaltEqu,
Resources, Sound, Notification, Icons, Processes, ColorPicker, Traps, LowMem, TextUtils;
{ ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
var
gNotificationRecord : NMRec;
gStartingTickCount : longint;
gNotificationDemoInvoked : boolean;
gNotificationInQueue : boolean;
gInBackground : boolean;
gWindowPtr : WindowPtr; external;
gColorQuickDraw : boolean; external;
gProcessSerNum : ProcessSerialNumber; external;
procedure DemosSegment;
procedure DoCommandPeriodAndStatusBar;
procedure DoSetUpNotification;
procedure DoDeviceLoopDraw(depth, deviceFlags : integer; targetDeviceHdl : GDHandle;
userData : longint);
procedure DoNullEvent;
procedure DoOSEvent(theEvent : EventRecord);
procedure DoColourPicker;
function DoCheckSlotVInstallAvailable : boolean;
procedure DoZoomWindowMultiMonitors(theWindowPtr : WindowPtr;
zoomInOrOut : longint);
implementation
uses
{ ……………………………………………………………………………………………………………………… include the following user-defined units }
UMain;
{ ………………………………………………………………………………………………………………………………………… function and procedure interfaces }
procedure DoDrawStatusBar(modalDlgPtr : DialogPtr; barRect : Rect;
statusCurrent, statusMax : integer); forward;
function DoCheckForCommandPeriod : boolean; forward;
procedure DoPrepareNotificationRecord; forward;
procedure DoDisplayMessageToUser; forward;
function DoDecimalToHexadecimal(decimalNumber : UInt16) : string; forward;
function TrapAvailable(theTrap : integer) : boolean; forward;
procedure DoRedoWindowContent(theWindowPtr : WindowPtr); forward;
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DemosSegment }
procedure DemosSegment;
begin
end;
{of procedure DemosSegment}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCommandPeriodAndStatusBar }
procedure DoCommandPeriodAndStatusBar;
var
modalDlgPtr : DialogPtr;
barBackColour, barColour : RGBColor;
itemType : integer;
itemHdl : Handle;
itemRect : Rect;
a, b, c, temp1, temp2 : integer;
soundHdl : Handle;
theRect : Rect;
statusMax, statusCurrent : integer;
finalTicks : UInt32;
ignored : OSErr;
begin
EraseRect(gWindowPtr^.portRect);
modalDlgPtr := GetNewDialog(rDialog, nil, WindowPtr(-1));
if (modalDlgPtr = nil) then
ExitToShell;
DrawDialog(modalDlgPtr);
SetPort(modalDlgPtr);
if (gColorQuickDraw) then
begin
barBackColour.red := $BFFF;
barBackColour.green := $BFFF;
barBackColour.blue := $FFFF;
barColour.red := $6FFF;
barColour.green := $6FFF;
barColour.blue := $6FFF;
end;
GetDialogItem(modalDlgPtr, iUserItem, itemType, itemHdl, itemRect);
InsetRect(itemRect, -1, -1);
FrameRect(itemRect);
InsetRect(itemRect, 1, 1);
if (gColorQuickDraw) then
begin
RGBBackColor(barBackColour);
FillRect(itemRect, qd.white);
RGBForeColor(barColour);
end;
SetPort(gWindowPtr);
statusMax := 2184;
statusCurrent := 0;
for a := 0 to 7 do
begin
if (DoCheckForCommandPeriod) then
begin
soundHdl := GetResource('snd ', rBarkSound);
ignored := SndPlay(nil, SndListHandle(soundHdl), false);
ReleaseResource(soundHdl);
DisposeDialog(modalDlgPtr);
SetPort(gWindowPtr);
EraseRect(gWindowPtr^.portRect);
MoveTo(115, 110);
ForeColor(blackColor);
DrawString('Operation cancelled at user request');
Exit(DoCommandPeriodAndStatusBar);
end;
for temp1 := 0 to 20 do
begin
b := temp1 * 18 + 12;
for temp2 := 0 to 12 do
begin
c := temp2 * 18 + 8;
SetRect(theRect, b + a, c + a, b + 16 - a, c + 16 - a);
if (a < 3) then
ForeColor(redColor)
else if ((a > 2) and (a < 6)) then
ForeColor(greenColor)
else if (a > 5) then
ForeColor(blueColor);
FrameRect(theRect);
DoDrawStatusBar(modalDlgPtr, itemRect, statusCurrent, statusMax);
statusCurrent := statusCurrent + 1;
end;
Delay(2, finalTicks);
end;
end;
DisposeDialog(modalDlgPtr);
EraseRect(gWindowPtr^.portRect);
MoveTo(150, 110);
ForeColor(blackColor);
DrawString('Operation completed');
end;
{of procedure DoCommandPeriodAndStatusBar}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDrawStatusBar }
procedure DoDrawStatusBar(modalDlgPtr : DialogPtr; barRect : Rect;
statusCurrent, statusMax : integer);
var
barMaxWidth : integer;
barRequiredWidth : real;
begin
SetPort(modalDlgPtr);
barMaxWidth := barRect.right - barRect.left;
barRequiredWidth := (statusCurrent / statusMax) * barMaxWidth;
barRect.right := barRect.left + trunc(barRequiredWidth);
if (gColorQuickDraw) then
FillRect(barRect, qd.black)
else
FillRect(barRect, qd.gray);
SetPort(gWindowPtr);
end;
{of procedure DoDrawStatusBar}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCheckForCommandPeriod }
function DoCheckForCommandPeriod : boolean;
var
foundCommandPeriod : boolean;
eventQHdrPtr : QHdrPtr;
eventQElPtr : EvQElPtr;
keyCode : longint;
commandKeyDown : longint;
begin
foundCommandPeriod := false;
eventQHdrPtr := GetEvQHdr;
eventQElPtr := EvQElPtr(eventQHdrPtr^.qHead);
while ((eventQElPtr <> nil) and not (foundCommandPeriod)) do
begin
if (eventQElPtr^.evtQWhat = keyDown) then
begin
keyCode := BAnd(eventQElPtr^.evtQMessage, charCodeMask);
commandKeyDown := BAnd(eventQElPtr^.evtQModifiers, cmdKey);
if (commandKeyDown <> 0) then
if (keyCode = ord('.')) then
foundCommandPeriod := true;
end;
if not (foundCommandPeriod) then
eventQElPtr := EvQElPtr(eventQElPtr^.qLink);
end;
DoCheckForCommandPeriod := foundCommandPeriod;
end;
{of function DoCheckForCommandPeriod}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoSetUpNotification }
procedure DoSetUpNotification;
begin
DoPrepareNotificationRecord;
gNotificationDemoInvoked := true;
gStartingTickCount := TickCount;
MoveTo(12, 100);
DrawString('Please click on the desktop now to make the Finder ');
DrawString('the frontmost application.');
MoveTo(42, 120);
DrawString('(This application will post a notification 10 seconds from now.)');
end;
{of procedure DoSetUpNotification}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoPrepareNotificationRecord }
procedure DoPrepareNotificationRecord;
var
iconSuiteHdl : Handle;
soundHdl : Handle;
stringHdl : StringHandle;
ignored : OSErr;
begin
ignored := GetIconSuite(iconSuiteHdl, rIconFamily, svAllSmallData);
soundHdl := GetResource('snd ', rBarkSound);
stringHdl := GetString(rString);
gNotificationRecord.qType := nmType;
gNotificationRecord.nmMark := 1;
gNotificationRecord.nmIcon := iconSuiteHdl;
gNotificationRecord.nmSound := soundHdl;
gNotificationRecord.nmStr := stringHdl^;
gNotificationRecord.nmResp := nil;
gNotificationRecord.nmRefCon := 0;
end;
{of procedure DoPrepareNotificationRecord}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoNullEvent }
procedure DoNullEvent;
var
frontProcessSerNum : ProcessSerialNumber;
isSameProcess : boolean;
ignored : OSErr;
begin
if (gNotificationDemoInvoked) then
begin
if (TickCount > (gStartingTickCount + 600)) then
begin
ignored := GetFrontProcess(frontProcessSerNum);
ignored := SameProcess(frontProcessSerNum, gProcessSerNum, isSameProcess);
if not (isSameProcess) then
begin
ignored := NMInstall(NMRecPtr(@gNotificationRecord));
gNotificationDemoInvoked := false;
gNotificationInQueue := true;
end
else begin
DoDisplayMessageToUser;
gNotificationDemoInvoked := false;
end;
EraseRect(gWindowPtr^.portRect);
end;
end;
end;
{of procedure DoNullEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
procedure DoOSEvent(theEvent : EventRecord);
begin
case (BAnd(BSR(theEvent.message, 24), $000000FF)) of
suspendResumeMessage: begin
gInBackground := BAnd(theEvent.message, resumeFlag) = 0;
if (not (gInBackground) and gNotificationInQueue) then
DoDisplayMessageToUser;
end;
mouseMovedMessage: begin
end;
end;
{of case statement}
end;
{of procedure DoOSEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDisplayMessageToUser }
procedure DoDisplayMessageToUser;
var
ignored : OSErr;
begin
if (gNotificationInQueue) then
begin
ignored := NMRemove(NMRecPtr(@gNotificationRecord));
gNotificationInQueue := false;
end;
ignored := NoteAlert(rAlert, nil);
ignored := DisposeIconSuite(gNotificationRecord.nmIcon, false);
ReleaseResource(gNotificationRecord.nmSound);
ReleaseResource(Handle(gNotificationRecord.nmStr));
end;
{of procedure DoDisplayMessageToUser}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoColourPicker }
procedure DoColourPicker;
var
inColour, outColour, blackColour : RGBColor;
theRect : Rect;
where : Point;
prompt : Str255;
okButton : boolean;
theString : string;
begin
prompt := 'Choose a rectangle colour:';
EraseRect(gWindowPtr^.portRect);
inColour.red := $FFFF;
inColour.green := $0000;
inColour.blue := $0000;
blackColour.red := $0000;
blackColour.green := $0000;
blackColour.blue := $0000;
theRect := gWindowPtr^.portRect;
InsetRect(theRect, 50, 50);
RGBForeColor(inColour);
FillRect(theRect, qd.black);
where.v := 0;
where.h := 0;
okButton := GetColor(where, prompt, inColour, outColour);
if (okButton) then
begin
RGBForeColor(outColour);
FillRect(theRect, qd.black);
RGBForeColor(blackColour);
MoveTo(50, 20);
DrawString('Red Value: ');
theString := DoDecimalToHexadecimal(outColour.red);
MoveTo(115, 20);
DrawString(theString);
MoveTo(50, 33);
DrawString('Green Value: ');
theString := DoDecimalToHexadecimal(outColour.green);
MoveTo(115, 33);
DrawString(theString);
MoveTo(50, 46);
DrawString('Blue Value: ');
theString := DoDecimalToHexadecimal(outColour.blue);
MoveTo(115, 46);
DrawString(theString);
end
else begin
RGBForeColor(inColour);
FillRect(theRect, qd.black);
RGBForeColor(blackColour);
MoveTo(75, 125);
DrawString('Cancel button was clicked. Rectangle remains red.');
end;
end;
{of procedure DoColourPicker}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDecimalToHexadecimal }
function DoDecimalToHexadecimal(decimalNumber : UInt16) : string;
var
theString : string;
hexCharas : string;
a : integer;
begin
theString := 'OxXXXX';
hexCharas := '0123456789ABCDEF';
for a := 0 to 3 do
begin
theString[6 - a] := hexCharas[BAnd(decimalNumber, $F) + 1];
decimalNumber := BSR(decimalNumber, 4);
end;
DoDecimalToHexadecimal := theString;
end;
{of function DoDecimalToHexadecimal}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCheckSlotVInstallAvailable }
function DoCheckSlotVInstallAvailable : boolean;
begin
DoCheckSlotVInstallAvailable := TrapAvailable(_SlotVInstall);
end;
{of function DoCheckSlotVInstallAvailable}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ TrapAvailable }
function TrapAvailable(theTrap : integer) : boolean;
var
theTrapType : TrapType;
trapMask : integer;
numToolboxTraps : integer;
begin
trapMask := $0800;
if (BAnd(theTrap, trapMask) > 0) then
theTrapType := ToolTrap
else
theTrapType := OSTrap;
if (theTrapType = ToolTrap) then
theTrap := BAnd(theTrap, $07FF);
if (NGetTrapAddress(_InitGraf, ToolTrap) = NGetTrapAddress($AA6E, ToolTrap)) then
numToolboxTraps := $0200
else
numToolboxTraps := $0400;
if (theTrap >= numToolboxTraps) then
theTrap := _Unimplemented;
TrapAvailable :=
NGetTrapAddress(theTrap, theTrapType) <> NGetTrapAddress(_Unimplemented, ToolTrap);
end;
{of function TrapAvailable}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDeviceLoopDraw }
procedure DoDeviceLoopDraw(depth, deviceFlags : integer; targetDeviceHdl : GDHandle;
userData : longint);
var
theWindowPtr : WindowPtr;
theRect : Rect;
oldForeColour : RGBColor;
green: RGBColor;
red : RGBColor;
blue : RGBColor;
begin
green.red := $6666;
green.green := $FFFF;
green.blue := $6666;
red.red := $FFFF;
red.green := $6666;
red.blue := $6666;
blue.red := $9999;
blue.green := $9999;
blue.blue := $FFFF;
theWindowPtr := WindowPtr(userData);
EraseRect(theWindowPtr^.portRect);
case (depth) of
1, 2: begin
SetRect(theRect, 70, 40, 320, 200);
FillRect(theRect, qd.ltGray);
InsetRect(theRect, 30, 30);
FillRect(theRect, qd.gray);
InsetRect(theRect, 30, 30);
FillRect(theRect, qd.dkGray);
end;
4, 8, 16, 32: begin
GetForeColor(oldForeColour);
SetRect(theRect, 70, 40, 320, 200);
RGBForeColor(green);
PaintRect(theRect);
InsetRect(theRect, 30, 30);
RGBForeColor(red);
PaintRect(theRect);
InsetRect(theRect, 30, 30);
RGBForeColor(blue);
PaintRect(theRect);
RGBForeColor(oldForeColour);
end;
end;
{of case statement}
end;
{of procedure DoDeviceLoopDraw}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoZoomWindowMultiMonitors }
procedure DoZoomWindowMultiMonitors(theWindowPtr : WindowPtr; zoomInOrOut : longint);
var
oldPort : GrafPtr;
windRect, intersectRect, zoomRect : Rect;
titleBarHeight : integer;
winStateDataPtr : WStateDataPtr;
deviceHdl, zoomDeviceHdl : GDHandle;
intersectArea, greatestArea : longint;
sectFlag : boolean;
begin
GetPort(oldPort);
SetPort(theWindowPtr);
EraseRect(theWindowPtr^.portRect);
windRect := theWindowPtr^.portRect;
LocalToGlobal(windRect.topLeft);
LocalToGlobal(windRect.botRight);
titleBarHeight := windRect.top - WindowPeek(theWindowPtr)^.strucRgn^^.rgnBBox.top - 1;
if (zoomInOrOut = inZoomOut) then
begin
if not (gColorQuickDraw) then
begin
zoomRect := qd.screenBits.bounds;
zoomRect.top := zoomRect.top + LMGetMBarHeight + titleBarHeight;
InsetRect(zoomRect, 3, 3);
winStateDataPtr := WStateDataPtr(WindowPeek(theWindowPtr)^.dataHandle);
winStateDataPtr^.stdState := zoomRect;
end
else begin
windRect.top := windRect.top - titleBarHeight;
deviceHdl := LMGetDeviceList;
greatestArea := 0;
while (deviceHdl <> nil) do
begin
if (TestDeviceAttribute(deviceHdl, screenDevice)) then
if (TestDeviceAttribute(deviceHdl, screenActive)) then
begin
sectFlag := SectRect(windRect, deviceHdl^^.gdRect, intersectRect);
intersectArea := longint((intersectRect.right - intersectRect.left) *
(intersectRect.bottom - intersectRect.top));
if (intersectArea > greatestArea) then
begin
greatestArea := intersectArea;
zoomDeviceHdl := deviceHdl;
end;
deviceHdl := GetNextDevice(deviceHdl);
end;
end;
if (zoomDeviceHdl = LMGetMainDevice) then
titleBarHeight := titleBarHeight + LMGetMBarHeight;
SetRect(zoomRect, zoomDeviceHdl^^.gdRect.left + 3,
zoomDeviceHdl^^.gdRect.top + titleBarHeight + 3,
zoomDeviceHdl^^.gdRect.right - 3,
zoomDeviceHdl^^.gdRect.bottom - 3);
winStateDataPtr := WStateDataPtr(WindowPeek(theWindowPtr)^.dataHandle);
winStateDataPtr^.stdState := zoomRect;
end;
end;
ZoomWindow(theWindowPtr, zoomInOrOut, theWindowPtr = FrontWindow);
DoRedoWindowContent(theWindowPtr);
SetPort(oldPort);
end;
{of procedure DoZoomWindowMultiMonitors}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoRedoWindowContent }
procedure DoRedoWindowContent(theWindowPtr : WindowPtr);
begin
{ Do scroll bar and TextEdit, etc, adjustments here as appropriate. }
InvalRect(theWindowPtr^.portRect);
end;
{of procedure DoRedoWindowContent}
end.
{of unit UDemos}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }