home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 3.7 KB | 146 lines | [TEXT/MPS ] |
- {[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]}
- { CalcUtilities.inc1.p}
- { Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved.}
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE FitString(VAR theString: Str255;
- maxWidth: INTEGER);
- { Truncates theString to fit in maxWidth pixels }
-
- VAR
- currWidth: INTEGER;
- noOfChars: INTEGER;
-
- BEGIN
- IF StringWidth(theString) > maxWidth THEN
- BEGIN
- currWidth := CharWidth('…');
- noOfChars := 0;
- REPEAT
- noOfChars := noOfChars + 1;
- currWidth := currWidth + CharWidth(theString[noOfChars]);
- UNTIL currWidth > maxWidth;
-
- {$Push} {$R-}
- theString[0] := CHR(noOfChars); { Set length of theString }
- {$Pop}
- theString[noOfChars] := '…';
- END;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- FUNCTION IsDigit(Ch: CHAR): BOOLEAN;
-
- BEGIN
- IsDigit := (Ch >= '0') AND (Ch <= '9');
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE SetEditCmdName(theCommand, customCommand: INTEGER);
- { Sets the Edit menu command name to the custom name, e.g. 'Copy Cells'. }
-
- VAR
- commandName: Str255;
-
- BEGIN
- CmdToName(customCommand, commandName);
- SetCmdName(theCommand, commandName);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE SetTheFont(fontNumber, fontSize: INTEGER;
- fontStyle: Style);
-
- BEGIN
- TextFont(fontNumber);
- TextSize(fontSize);
- TextFace(fontStyle);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S ARes}
-
- PROCEDURE SmartDrawString(theString: Str255;
- area: Rect;
- justification: INTEGER);
- { Draws the string at the [h,v] coordinate, taking into account the
- width and justification. }
-
- BEGIN
- WITH area DO
- FitString(theString, right - left);
- MADrawString(@theString, area, justification);
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AReadFile}
-
- PROCEDURE ReadBytes(theRefNum: INTEGER;
- size: LONGINT;
- buffer: Ptr);
- { Utility for reading data from a file }
-
- BEGIN
- FailOSErr(FSRead(theRefNum, size, buffer));
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AWriteFile}
-
- PROCEDURE WriteBytes(theRefNum: INTEGER;
- size: LONGINT;
- buffer: Ptr);
- { Utility for writing data to a file }
-
- BEGIN
- FailOSErr(FSWrite(theRefNum, size, buffer));
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AClipBoard}
-
- PROCEDURE ReadScrap(theScrap: Handle;
- VAR scrapOffset: LONGINT;
- theData: Ptr;
- dataLength: INTEGER);
- { Utility for extracting data from the scrap, where scrapOffset indicates
- the start of the data within the scrap handle, and dataLength is the length of
- the data to be extracted. dataLength is added to scrapOffset. }
-
- VAR
- p: Ptr;
-
- BEGIN
- p := POINTER(ORD4(theScrap^) + scrapOffset);
- BlockMove(p, theData, dataLength);
- scrapOffset := scrapOffset + dataLength;
- END;
-
- {--------------------------------------------------------------------------------------------------}
- {$S AClipBoard}
-
- PROCEDURE WriteScrap(theScrap: Handle;
- VAR scrapOffset: LONGINT;
- theData: Ptr;
- dataLength: INTEGER);
- { Utility for appending data to the end of the scrap handle }
-
- VAR
- p: Ptr;
-
- BEGIN
- SetHandleSize(theScrap, scrapOffset + dataLength);
- FailMemError;
- p := POINTER(ORD4(theScrap^) + scrapOffset);
- BlockMove(theData, p, dataLength);
- scrapOffset := scrapOffset + dataLength;
- END;
-