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
/
chap23pascal_demo
/
chap06pascal_demoPPC
/
DialogsAndAlertsPascalPPC.p
< prev
next >
Wrap
Text File
|
1997-01-07
|
33KB
|
1,367 lines
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
// DialogsAndAlertsPascalPPC.p
// ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
//
// This program:
//
// • Opens a window for the purposes of displaying text and for proving correct window
// updating and activation/deactivation in the presence of alert and dialog boxes.
//
// • Allows the user to invoke a demonstration alert, a modal dialog box, a movable
// modal dialog box and a modeless dialog box via the Demonstration menu.
//
// The modal dialog box contains three checkboxes.
//
// The movable modal dialog box contains three radio buttons.
//
// The modeless dialog box contains an icon and an editable text item. The editable text
// item is supported by the Edit menu Cut, Copy, Paste and Clear commands.
//
// An application-defined event filter function is used for the alert box and modal
// dialog box.
//
// An application-defined function is used to draw the bold outline around the default
// button in the modal, movable modal and modeless dialog boxes.
//
// The program utilizes the following resources:
//
// • An 'MBAR' resource, and 'MENU' resources for Apple, File, Demonstration and Help
// menus (preload, non-purgeable).
//
// • A 'WIND' resource (purgeable) (initially visible).
//
// • An 'ALRT' resource (purgeable).
//
// • 'DLOG' resources (purgeable) (initially not visible) and associated 'DITL'
// resources (purgeable).
//
// • 'dctb' resources (purgeable) to force the Dialog Manager to create colour graphics
// ports for the movable modal and modeless dialog boxes.
//
// • A 'cicn' resource (purgeable).
//
// • A 'SIZE' resource with the acceptSuspendResumeEvents and doesActivateOnFGSwitch
// flags set.
//
// ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
program DialogsAndAlertsPascal(input, output);
{ ………………………………………………………………………………………………………………… include the following Universal Interfaces }
uses
Controls, Windows, Menus, Quickdraw, Fonts, Events, OSUtils, Processes, TextUtils, Dialogs,
TextEdit, QuickdrawText, Types, Memory, Palettes, ToolUtils, Devices, LowMem, SegLoad;
{ ………………………………………………………………………………………………………………………………………………… define the following constants }
const
mApple = 128;
iAbout = 1;
mFile = 129;
iClose = 4;
iQuit = 11;
mEdit = 130;
iCut = 3;
iCopy = 4;
iPaste = 5;
iClear = 6;
mDemonstration = 131;
iAlert = 1;
iModal = 2;
iMovable = 3;
iModeless = 4;
rMenubar = 128;
rNewWindow = 128;
rAlert = 128;
iOK = 1;
iCancel = 2;
iUserItem = 3;
rModal = 129;
iGridSnap = 4;
iShowGrid = 5;
iShowRulers = 6;
rMovable = 130;
iCharcoal = 4;
iOilPaint = 5;
iWaterColour = 6;
rModeless = 131;
iSearch = 1;
iEditText = 4;
kMovableModal = 1;
kModeless = 2;
kReturn = $0D;
kEnter = $03;
kEscape = $1B;
kPeriod = $2E;
kMaxLong = $7FFFFFFF;
{ ………………………………………………………………………………………………………………………………………………………………………………… user-defined types }
type
DocRec = record
vScrollbarHdl, hScrollbarHdl : ControlHandle;
end;
DocRecPointer = ^DocRec;
DocRecHandle = ^DocRecPointer;
{ ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
var
gWindowPtr : WindowPtr;
gSleepTime : longint;
gDone : boolean;
gInBackground : boolean;
gGridSnap : integer;
gShowGrid : integer;
gShowRule : integer;
gBrushType : integer;
gOldBrushType : integer;
gModelessDlgPtr : DialogRef;
menubarHdl : Handle;
menuHdl : MenuHandle;
docRecHdl : DocRecHandle;
eventFilterRD : ModalFilterUPP; { For PowerPC }
drawDefaultButtonOutlineRD : UserItemUPP; { For PowerPC }
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
procedure DoInitManagers;
begin
MaxApplZone;
MoreMasters;
InitGraf(@qd.thePort);
InitFonts;
InitWindows;
InitMenus;
TEInit;
InitDialogs(nil);
InitCursor;
FlushEvents(everyEvent, 0);
end;
{of procedure DoInitManagers}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoIdle }
procedure DoIdle(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
dialogType : integer;
itemHit : integer;
ignored : boolean;
begin
myWindowPtr := FrontWindow;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if (dialogType = kModeless) then
ignored := DialogSelect(eventRec, DialogPtr(myWindowPtr), itemHit);
end;
end;
{of procedure DoIdle}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAdjustMenus }
procedure DoAdjustMenus;
var
myWindowPtr : WindowPtr;
dialogType : integer;
menuHdl : MenuHandle;
begin
myWindowPtr := FrontWindow;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
case (dialogType) of
kMovableModal:
begin
menuHdl := GetMenuHandle(mFile);
DisableItem(menuHdl, 0);
menuHdl := GetMenuHandle(mEdit);
DisableItem(menuHdl, 0);
menuHdl := GetMenuHandle(mDemonstration);
DisableItem(menuHdl, 0);
EnableItem(menuHdl, 4);
end;
kModeless:
begin
menuHdl := GetMenuHandle(mFile);
EnableItem(menuHdl, 0);
EnableItem(menuHdl, 4);
menuHdl := GetMenuHandle(mEdit);
EnableItem(menuHdl, 0);
menuHdl := GetMenuHandle(mDemonstration);
EnableItem(menuHdl, 0);
DisableItem(menuHdl, 4);
end;
end;
{of case statement}
end
else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
begin
menuHdl := GetMenuHandle(mFile);
EnableItem(menuHdl, 0);
DisableItem(menuHdl, 4);
menuHdl := GetMenuHandle(mEdit);
DisableItem(menuHdl, 0);
menuHdl := GetMenuHandle(mDemonstration);
EnableItem(menuHdl, 0);
EnableItem(menuHdl, 4);
end;
DrawMenuBar;
end;
{of procedure DoAdjustMenus}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDownMovableModal }
procedure DoKeyDownMovableModal(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
charCode : char;
itemType : integer;
itemHandle : Handle;
itemRect : Rect;
finalTicks : longint;
begin
myWindowPtr := FrontWindow;
charCode := chr(BAnd(eventRec.message, charCodeMask));
if ((charCode = char(kReturn)) or (charCode = char(kEnter))) then
begin
GetDialogItem(DialogRef(myWindowPtr), iOK, itemType, itemHandle, itemRect);
HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
Delay(8, finalTicks);
HiliteControl(ControlHandle(itemHandle), 0);
DisposeDialog(DialogRef(myWindowPtr));
end
else if ((charCode = char(kEscape)) or ((BAnd(eventRec.modifiers, cmdKey) <> 0)
and (charCode = char(kPeriod)))) then
begin
GetDialogItem(DialogRef(myWindowPtr), iCancel, itemType, itemHandle, itemRect);
HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
Delay(8, finalTicks);
HiliteControl(ControlHandle(itemHandle), 0);
gBrushType := gOldBrushType;
DisposeDialog(DialogRef(myWindowPtr));
end;
end;
{of procedure DoKeyDownDocument}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoItemHitModeless }
procedure DoItemHitModeless(myDialogRef : DialogRef);
var
oldPort : WindowPtr;
printRect, itemRect : Rect;
itemType : integer;
itemHdl : Handle;
itemString : string;
begin
GetPort(oldPort);
SetPort(gWindowPtr);
SetRect(printRect, 15, 13, 369, 36);
PenMode(patBic);
PaintRect(printRect);
GetDialogItem(myDialogRef, iEditText, itemType, itemHdl, itemRect);
GetDialogItemText(itemHdl, itemString);
MoveTo(20, 29);
DrawString('Search string: ');
DrawString(itemString);
PenNormal;
SetPort(oldPort);
end;
{of procedure DoItemHitModeless}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDownModeless }
procedure DoKeyDownModeless(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
charCode : char;
itemType : integer;
itemHandle : Handle;
itemRect : Rect;
finalTicks : longint;
theDialogRef : DialogRef;
itemHit : integer;
ignored : boolean;
begin
myWindowPtr := FrontWindow;
charCode := chr(BAnd(eventRec.message, charCodeMask));
if ((charCode = char(kReturn)) or (charCode = char(kEnter)))then
begin
GetDialogItem(DialogRef(myWindowPtr), iSearch, itemType, itemHandle, itemRect);
HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
Delay(8, finalTicks);
HiliteControl(ControlHandle(itemHandle), 0);
DoItemHitModeless(DialogRef(myWindowPtr));
end
else begin
theDialogRef := DialogRef(myWindowPtr);
ignored := DialogSelect(eventRec, theDialogRef, itemHit);
end;
end;
{of procedure DoKeyDownModeless}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdateDocument }
procedure DoUpdateDocument(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
paintRect : Rect;
fillPattern : Pattern;
begin
myWindowPtr := WindowPtr(eventRec.message);
BeginUpdate(myWindowPtr);
if not (EmptyRgn(myWindowPtr^.visRgn)) then
begin
SetPort(myWindowPtr);
EraseRgn(myWindowPtr^.visRgn);
paintRect := myWindowPtr^.portRect;
paintRect.right := paintRect.right - 15;
paintRect.bottom := paintRect.bottom - 15;
GetIndPattern(fillPattern, 0, 16);
FillRect(paintRect, fillPattern);
DrawGrowIcon(myWindowPtr);
end;
EndUpdate(myWindowPtr);
end;
{of procedure DoUpdateDocument}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdateMovableOrModeless }
procedure DoUpdateMovableOrModeless(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
begin
myWindowPtr := WindowPtr(eventRec.message);
BeginUpdate(myWindowPtr);
UpdateDialog(myWindowPtr, myWindowPtr^.visRgn);
EndUpdate(myWindowPtr);
end;
{of procedure DoUpdateMovableOrModeless}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateDocument }
procedure DoActivateDocument(myWindowPtr : WindowPtr; becomingActive : boolean);
begin
if (becomingActive) then
DoAdjustMenus;
DrawGrowIcon(myWindowPtr);
end;
{of procedure DoActivateDocument}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DrawDefaultButtonOutline }
procedure DrawDefaultButtonOutline(myDialogRef : DialogRef; theItem : integer);
var
oldPort : WindowPtr;
oldPenState : PenState;
itemType : integer;
itemHandle : Handle;
itemRect : Rect;
colGrafPtr : CGrafPtr;
isColour : boolean;
buttonOval : SInt8;
backColour : RGBColor;
foreSaveColour : RGBColor;
newForeColour : RGBColor;
newGray : boolean;
targetDevice : GDHandle;
begin
GetPort(oldPort);
GetPenState(oldPenState);
GetDialogItem(myDialogRef, iOK, itemType, itemHandle, itemRect);
SetPort(ControlHandle(itemHandle)^^.contrlOwner);
InsetRect(itemRect, -4, -4);
colGrafPtr := CGrafPtr(ControlHandle(itemHandle)^^.contrlOwner);
if (BAnd(BSR(colGrafPtr^.portVersion, 14), $00000003) <> 0)
then isColour := true
else isColour := false;
buttonOval := trunc((itemRect.bottom - itemRect.top) / 2) + 2;
if (ControlHandle(itemHandle)^^.contrlHilite = 255)
then begin
newGray := false;
if (isColour) then
begin
GetBackColor(backColour);
GetForeColor(foreSaveColour);
newForeColour := foreSaveColour;
targetDevice := GetMainDevice;
newGray := GetGray(targetDevice, backColour, newForeColour);
end;
if (newGray)
then RGBForeColor(newForeColour)
else PenPat(qd.gray);
PenSize(3, 3);
FrameRoundRect(itemRect, buttonOval, buttonOval);
if (isColour) then
RGBForeColor(foreSaveColour);
end
else begin
PenPat(qd.black);
PenSize(3, 3);
FrameRoundRect(itemRect, buttonOval, buttonOval);
end;
SetPenState(oldPenState);
SetPort(oldPort);
end;
{of procedure DrawDefaultButtonOutline}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateMovableModal }
procedure DoActivateMovableModal(myWindowPtr : WindowPtr; becomingActive : boolean);
var
a, itemType : integer;
itemHdl : Handle;
itemRect : Rect;
begin
if (becomingActive)
then begin
for a := iOK to iWaterColour do
begin
if (a <> iUserItem) then
begin
GetDialogItem(DialogRef(myWindowPtr), a, itemType, itemHdl, itemRect);
HiliteControl(ControlHandle(itemHdl), 0);
end;
end;
DrawDefaultButtonOutline(DialogRef(myWindowPtr), iOK);
DoAdjustMenus;
end
else begin
for a := iOK to iWaterColour do
begin
if (a <> iUserItem) then
begin
GetDialogItem(DialogRef(myWindowPtr), a, itemType, itemHdl, itemRect);
HiliteControl(ControlHandle(itemHdl), 255);
end;
end;
DrawDefaultButtonOutline(DialogRef(myWindowPtr), iOK);
end;
end;
{of procedure DoActivateMovableModal}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateModeless }
procedure DoActivateModeless(myWindowPtr : WindowPtr; becomingActive : boolean);
var
itemType : integer;
itemHdl : Handle;
itemRect : Rect;
begin
if (becomingActive)
then begin
GetDialogItem(DialogRef(myWindowPtr), iSearch, itemType, itemHdl, itemRect);
HiliteControl(ControlHandle(itemHdl), 0);
DrawDefaultButtonOutline(DialogRef(myWindowPtr), iSearch);
SelectDialogItemText(DialogRef(myWindowPtr), iEditText, 0, 32767);
gSleepTime := LMGetCaretTime;
DoAdjustMenus;
end
else begin
GetDialogItem(DialogRef(myWindowPtr), iSearch, itemType, itemHdl, itemRect);
HiliteControl(ControlHandle(itemHdl), 255);
DrawDefaultButtonOutline(DialogRef(myWindowPtr), iSearch);
SelectDialogItemText(DialogRef(myWindowPtr), iEditText, 0, 0);
gSleepTime := kMaxLong;
end;
end;
{of procedure DoActivateModeless}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivate }
procedure DoActivate(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
dialogType : integer;
becomingActive : boolean;
begin
myWindowPtr := WindowPtr(eventRec.message);
becomingActive := BAnd(eventRec.modifiers, activeFlag) = activeFlag;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if (dialogType = kMovableModal) then
DoActivateMovableModal(myWindowPtr, becomingActive)
else if (dialogType = kModeless) then
DoActivateModeless(myWindowPtr, becomingActive);
end
else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
DoActivateDocument(myWindowPtr, becomingActive);
end;
{of procedure DoActivate}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
procedure DoOSEvent(var eventRec : EventRecord);
var
dialogType : integer;
myWindowPtr : WindowPtr;
begin
myWindowPtr := FrontWindow;
case BAnd(BSR(eventRec.message, 24), $000000FF) of
suspendResumeMessage:
begin
gInBackground := BAnd(eventRec.message, resumeFlag) = 0;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if (dialogType = kMovableModal) then
DoActivateMovableModal(myWindowPtr, not(gInBackground))
else if (dialogType = kModeless) then
DoActivateModeless(myWindowPtr, not(gInBackground));
end
else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
DoActivateDocument(myWindowPtr, not(gInBackground));
end;
mouseMovedMessage:
begin
end;
end;
{of outer case statement}
end;
{of procedure DoOSEvent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdate }
procedure DoUpdate(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
dialogType : integer;
begin
myWindowPtr := WindowPtr(eventRec.message);
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if ((dialogType = kMovableModal) or (dialogType = kModeless)) then
DoUpdateMovableOrModeless(eventRec);
end
else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
DoUpdateDocument(eventRec);
end;
{of procedure DoUpdate}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoHideModeless }
procedure DoHideModeless;
var
myWindowPtr : WindowPtr;
dialogType : integer;
begin
myWindowPtr := FrontWindow;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if (dialogType = kModeless) then
begin
HideWindow(myWindowPtr);
InvalRgn(gWindowPtr^.visRgn);
gSleepTime := kMaxLong;
end;
end;
end;
{of procedure DoHideModeless}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEditMenu }
procedure DoEditMenu(menuItem : integer);
var
myWindowPtr : WindowPtr;
dialogType : integer;
begin
myWindowPtr := FrontWindow;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if (dialogType = kModeless) then
case (menuItem) of
iCut:
begin
DialogCut(DialogRef(myWindowPtr));
end;
iCopy:
begin
DialogCopy(DialogRef(myWindowPtr));
end;
iPaste:
begin
DialogPaste(DialogRef(myWindowPtr));
end;
iClear:
begin
DialogDelete(DialogRef(myWindowPtr));
end;
end;
{of case statement}
end;
end;
{of procedure DoEditMenu}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ EventFilter }
function EventFilter(myDialogRef : DialogRef; eventRec : EventRecord;
var itemHit : integer) : boolean;
var
charCode : char;
itemType : integer;
itemHandle : Handle;
itemRect : Rect;
finalTicks : longint;
handledEvent : boolean;
begin
handledEvent := false;
if ((eventRec.what = updateEvt) and (WindowPtr(eventRec.message) <> myDialogRef))
then DoUpdate(eventRec)
else begin
case (eventRec.what) of
keyDown, autoKey:
begin
charCode := chr(BAnd(eventRec.message, charCodeMask));
if ((charCode = char(kReturn)) or (charCode = char(kEnter))) then
begin
GetDialogItem(myDialogRef, iOK, itemType, itemHandle, itemRect);
HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
Delay(8, finalTicks);
HiliteControl(ControlHandle(itemHandle), 0);
handledEvent := true;
itemHit := iOK;
end;
if ((charCode = char(kEscape)) or ((BAnd(eventRec.modifiers, cmdKey) <> 0)
and (charCode = char(kPeriod)))) then
begin
GetDialogItem(myDialogRef, iCancel, itemType, itemHandle, itemRect);
HiliteControl(ControlHandle(itemHandle), kControlButtonPart);
Delay(8, finalTicks);
HiliteControl(ControlHandle(itemHandle),0);
handledEvent := true;
itemHit := iCancel;
end;
{Other keyboard equivalents handled here.}
end;
{Disk-inserted and other events handled here.}
end;
{of case statement}
end;
EventFilter := handledEvent;
end;
{of procedure EventFilter}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoModalDialog }
function DoModalDialog : boolean;
var
modalDlgPtr : DialogRef;
itemType, itemHit : integer;
itemHdl : Handle;
itemRect : Rect;
begin
modalDlgPtr := GetNewDialog(rModal, nil, WindowPtr(-1));
if (modalDlgPtr = nil) then
begin
DoModalDialog := false;
Exit(DoModalDialog);
end;
GetDialogItem(modalDlgPtr, iUserItem, itemType, itemHdl, itemRect);
SetDialogItem(modalDlgPtr, iUserItem, itemType, Handle(drawDefaultButtonOutlineRD),
itemRect); { For PowerPC }
GetDialogItem(modalDlgPtr, iGridSnap, itemType, itemHdl, itemRect);
SetControlValue(ControlHandle(itemHdl), gGridSnap);
GetDialogItem(modalDlgPtr, iShowGrid, itemType, itemHdl, itemRect);
SetControlValue(ControlHandle(itemHdl), gShowGrid);
GetDialogItem(modalDlgPtr, iShowRulers, itemType, itemHdl, itemRect);
SetControlValue(ControlHandle(itemHdl), gShowRule);
ShowWindow(modalDlgPtr);
repeat
ModalDialog(eventFilterRD, itemHit); { For PowerPC }
GetDialogItem(modalDlgPtr, itemHit, itemType, itemHdl, itemRect);
if (GetControlValue(ControlHandle(itemHdl)) = 1)
then SetControlValue(ControlHandle(itemHdl), 0)
else if (GetControlValue(ControlHandle(itemHdl)) = 0) then
SetControlValue(ControlHandle(itemHdl), 1);
until ((itemHit = iOK) or (itemHit = iCancel));
if (itemHit = iOK) then
begin
GetDialogItem(modalDlgPtr, iGridSnap, itemType, itemHdl, itemRect);
gGridSnap := GetControlValue(ControlHandle(itemHdl));
GetDialogItem(modalDlgPtr, iShowGrid, itemType, itemHdl, itemRect);
gShowGrid := GetControlValue(ControlHandle(itemHdl));
GetDialogItem(modalDlgPtr, iShowRulers, itemType, itemHdl, itemRect);
gShowRule := GetControlValue(ControlHandle(itemHdl));
end;
DisposeDialog(modalDlgPtr);
DoModalDialog := true;
end;
{of function DoModalDialog}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMovableModalDialog }
function DoMovableModalDialog : boolean;
var
modalDlgPtr : DialogRef;
itemType : integer;
itemHdl : Handle;
itemRect : Rect;
begin
modalDlgPtr := GetNewDialog(rMovable, nil, WindowPtr(-1));
if (modalDlgPtr = nil) then
begin
DoMovableModalDialog := false;
Exit(DoMovableModalDialog);
end;
SetWRefCon(modalDlgPtr, longint(kMovableModal));
GetDialogItem(modalDlgPtr, iUserItem, itemType, itemHdl, itemRect);
SetDialogItem(modalDlgPtr, iUserItem, itemType, Handle(drawDefaultButtonOutlineRD),
itemRect); { For PowerPC }
GetDialogItem(modalDlgPtr, gBrushType, itemType, itemHdl, itemRect);
SetControlValue(ControlHandle(itemHdl),1);
ShowWindow(modalDlgPtr);
gOldBrushType := gBrushType;
DoMovableModalDialog := true;
end;
{of function DoMovableModalDialog}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoModelessDialog }
function DoModelessDialog : boolean;
var
itemType : integer;
itemHdl : Handle;
itemRect : Rect;
begin
if (gModelessDlgPtr = nil)
then begin
gModelessDlgPtr := GetNewDialog(rModeless, nil, WindowPtr(-1));
if (gModelessDlgPtr = nil) then
begin
DoModelessDialog := false;
Exit(DoModelessDialog);
end;
SetWRefCon(gModelessDlgPtr, longint(kModeless));
GetDialogItem(gModelessDlgPtr, iUserItem, itemType, itemHdl, itemRect);
SetDialogItem(gModelessDlgPtr, iUserItem, itemType,
Handle(drawDefaultButtonOutlineRD), itemRect); { For PowerPC }
ShowWindow(gModelessDlgPtr);
SelectDialogItemText(gModelessDlgPtr, iEditText, 0, 32767);
end
else begin
ShowWindow(gModelessDlgPtr);
SelectWindow(gModelessDlgPtr);
end;
DoModelessDialog := true;
end;
{of function DoModelessDialog}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDemonstrationMenu }
procedure DoDemonstrationMenu(menuItem : integer);
var
myWindowPtr : WindowPtr;
theRect : Rect;
ignored : integer;
begin
case (menuItem) of
iAlert: begin
myWindowPtr := FrontWindow;
if (GetAlertStage > 0) then
begin
if (myWindowPtr <> nil) then
begin
if (WindowPeek(myWindowPtr)^.windowKind <> dialogKind) then
begin
SetRect(theRect, myWindowPtr^.portRect.right - 15,
myWindowPtr^.portRect.bottom - 15, myWindowPtr^.portRect.right,
myWindowPtr^.portRect.bottom);
InvalRect(theRect);
DoActivateDocument(myWindowPtr, false);
end
else if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
DoActivateModeless(myWindowPtr, false);
end;
end;
end;
ignored := NoteAlert(rAlert, eventFilterRD); { For PowerPC }
end;
iModal: begin
myWindowPtr := FrontWindow;
if (myWindowPtr <> nil) then
begin
if (WindowPeek(myWindowPtr)^.windowKind <> dialogKind) then
begin
SetRect(theRect, myWindowPtr^.portRect.right - 15,
myWindowPtr^.portRect.bottom - 15, myWindowPtr^.portRect.right,
myWindowPtr^.portRect.bottom);
InvalRect(theRect);
DoActivateDocument(myWindowPtr, false);
end
else if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
DoActivateModeless(myWindowPtr, false);
end;
end;
if not (DoModalDialog) then
begin
SysBeep(10);
ExitToShell;
end;
end;
iMovable: begin
if not (DoMovableModalDialog) then
begin
SysBeep(10);
ExitToShell;
end;
end;
iModeless: begin
if not (DoModelessDialog) then
begin
SysBeep(10);
ExitToShell;
end;
end;
end;
{of case statement}
end;
{of procedure DoDemonstrationMenu}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
procedure DoMenuChoice(menuChoice : longint);
var
menuID, menuItem : integer;
itemName : string;
daDriverRefNum : integer;
begin
menuID := HiWord(menuChoice);
menuItem := LoWord(menuChoice);
if (menuID = 0) then
Exit(DoMenuChoice);
case (menuID) of
mApple:
begin
if (menuItem = iAbout)
then SysBeep(10)
else begin
GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
daDriverRefNum := OpenDeskAcc(itemName);
end;
end;
mFile:
begin
if (menuItem = iQuit)
then gDone := true
else if (menuItem = iClose) then
DoHideModeless;
end;
mEdit:
begin
DoEditMenu(menuItem);
end;
mDemonstration:
begin
DoDemonstrationMenu(menuItem);
end;
end;
{of case statement}
HiliteMenu(0);
end;
{of procedure DoMenuChoice}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDownDocument }
procedure DoKeyDownDocument(var eventRec : EventRecord);
var
charCode : char;
begin
charCode := chr(BAnd(eventRec.message, charCodeMask));
if (BAnd(eventRec.modifiers, cmdKey) <> 0) then
begin
DoAdjustMenus;
DoMenuChoice(MenuKey(charCode));
end;
end;
{of procedure DoKeyDownDocument}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDown }
procedure DoKeyDown(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
dialogType : integer;
begin
myWindowPtr := FrontWindow;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
case (dialogType) of
kMovableModal:
begin
DoKeyDownMovableModal(eventRec);
end;
kModeless:
begin
DoKeyDownModeless(eventRec);
end;
end;
{of case statement}
end
else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
DoKeyDownDocument(eventRec);
end;
{of procedure DoKeyDown}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoItemHitMovableModal }
procedure DoItemHitMovableModal(myDialogRef : DialogRef; itemHit : integer);
var
a, itemType : integer;
itemHdl : Handle;
itemRect : Rect;
begin
if ((itemHit = iCharcoal) or (itemHit = iOilPaint) or (itemHit = iWaterColour))
then begin
for a := iCharcoal to iWaterColour do
begin
GetDialogItem(myDialogRef, a, itemType, itemHdl, itemRect);
SetControlValue(ControlHandle(itemHdl), 0);
end;
GetDialogItem(myDialogRef, itemHit, itemType, itemHdl, itemRect);
SetControlValue(ControlHandle(itemHdl), 1);
gBrushType := itemHit;
end
else begin
if ((itemHit = iOK) or (itemHit = iCancel)) then
begin
if (itemHit = iCancel) then
gBrushType := gOldBrushType;
DisposeDialog(myDialogRef);
end;
end;
end;
{of procedure DoItemHitMovableModal}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ InvalidateScrollBarArea }
procedure InvalidateScrollBarArea(myWindowPtr : WindowPtr);
var
tempRect : Rect;
begin
SetPort(myWindowPtr);
tempRect := myWindowPtr^.portRect;
tempRect.left := tempRect.right - 15;
InvalRect(tempRect);
tempRect := myWindowPtr^.portRect;
tempRect.top := tempRect.bottom - 15;
InvalRect(tempRect);
end;
{of procedure InvalidateScrollBarArea}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInContent }
procedure DoInContent(var eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
dialogType : integer;
myDialogRef : DialogRef;
itemHit : integer;
begin
myWindowPtr := FrontWindow;
if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
begin
dialogType := WindowPeek(myWindowPtr)^.refCon;
if (dialogType = kMovableModal) then
begin
if (DialogSelect(eventRec, myDialogRef, itemHit)) then
DoItemHitMovableModal(myDialogRef, itemHit);
end
else if (dialogType = kModeless) then
begin
if (DialogSelect(eventRec, myDialogRef, itemHit)) then
DoItemHitModeless(myDialogRef);
end;
end
else if (WindowPeek(myWindowPtr)^.windowKind = userKind) then
begin
{ Handle clicks in document content region here.}
end;
end;
{of procedure DoInContent}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
procedure DoMouseDown(eventRec : EventRecord);
var
myWindowPtr : WindowPtr;
partCode : integer;
growRect : Rect;
newSize : longint;
begin
partCode := FindWindow(eventRec.where, myWindowPtr);
case (partCode) of
inMenuBar:
begin
DoAdjustMenus;
DoMenuChoice(MenuSelect(eventRec.where));
end;
inSysWindow:
begin
SystemClick(eventRec, myWindowPtr);
end;
inContent:
begin
if (myWindowPtr <> FrontWindow)
then begin
if (WindowPeek(FrontWindow)^.refCon = kMovableModal)
then SysBeep(10)
else SelectWindow(myWindowPtr);
end
else DoInContent(eventRec);
end;
inDrag:
begin
if ((WindowPeek(FrontWindow)^.refCon = kMovableModal) and
(WindowPeek(myWindowPtr)^.refCon <> kMovableModal)) then
begin
SysBeep(10);
Exit(DoMouseDown);
end;
DragWindow(myWindowPtr, eventRec.where, qd.screenBits.bounds);
end;
inGoAway:
begin
if (TrackGoAway(myWindowPtr, eventRec.where)) then
DoHideModeless;
end;
inGrow:
begin
growRect := qd.screenBits.bounds;
growRect.top := 80;
growRect.left := 160;
newSize := GrowWindow(myWindowPtr, eventRec.where, growRect);
if (newSize <> 0) then
begin
InvalidateScrollBarArea(myWindowPtr);
SizeWindow(myWindowPtr, LoWord(newSize), HiWord(newSize), true);
InvalidateScrollBarArea(myWindowPtr);
end;
end;
end;
{of case statement}
end;
{of procedure DoMouseDown}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
procedure DoEvents(eventRec : EventRecord);
begin
case (eventRec.what) of
mouseDown:
begin
DoMouseDown(eventRec);
end;
keyDown, autoKey:
begin
DoKeyDown(eventRec);
end;
updateEvt:
begin
DoUpdate(eventRec);
end;
activateEvt:
begin
DoActivate(eventRec);
end;
osEvt:
begin
DoOSEvent(eventRec);
HiliteMenu(0);
end;
end;
{of case statement}
end;
{of procedure DoEvents}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ EventLoop }
procedure EventLoop;
var
eventRec : EventRecord;
gotEvent : Boolean;
begin
gSleepTime := kMaxLong;
gDone := false;
while not (gDone) do
begin
gotEvent := WaitNextEvent(everyEvent, eventRec, gSleepTime, nil);
if (gotEvent)
then DoEvents(eventRec)
else DoIdle(eventRec);
end;
end;
{of procedure EventLoop}
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
begin
gGridSnap := 0;
gShowGrid := 0;
gShowRule := 0;
gBrushType := iCharcoal;
gOldBrushType := iCharcoal;
gModelessDlgPtr := nil;
{ …………………………………………………………………………………………………………………………………………………………………… initialize managers }
DoInitManagers;
{ ………………………………………………………………………………………………………………………………………………… create routine descriptors }
eventFilterRD := NewModalFilterProc(ProcPtr(@EventFilter)); { For PowerPC }
drawDefaultButtonOutlineRD := NewUserItemProc(ProcPtr(@DrawDefaultButtonOutline));
{ …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
menubarHdl := GetNewMBar(rMenubar);
if (menubarHdl = nil) then
ExitToShell;
SetMenuBar(menubarHdl);
DrawMenuBar;
menuHdl := GetMenuHandle(mApple);
if (menuHdl = nil)
then ExitToShell
else AppendResMenu(menuHdl,'DRVR');
{ ………………………………………………………………………………………………………………………………………………………………………………………… open window }
gWindowPtr := GetNewWindow(rNewWindow, nil, WindowPtr(-1));
if (gWindowPtr = nil) then
ExitToShell;
docRecHdl := DocRecHandle(NewHandle(sizeof(DocRec)));
if (docRecHdl = nil) then
ExitToShell;
SetWRefCon(gWindowPtr, longint(docRecHdl));
{ ……………………………………………………………………………………………………………………………………………………………………………… enter eventLoop }
EventLoop;
end.
{ ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }