home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Carousel
/
CAROUSEL.cdr
/
mactosh
/
fonts
/
fontshow.sit
/
FontShow.Pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1988-09-13
|
9KB
|
164 lines
PROGRAM FontShow;
(* This program lets the user select a font and size (from Font and Size menus, of course), and *)
(* displays all of the characters at the selected font/size along with their Hexadecimal codes. *)
(* It includes several special features, including: *)
(* Ñ "Automatic" window updates. *)
(* Ñ Automatic notification when we are running out of memory (as well as measures *)
(* designed to help keep us out of a crash). *)
(* Ñ Memory management techniques designed to reduce fragmentation. *)
(* Ñ A Size menu which outlines lists the available font sizes. *)
(* Ñ Multiple window types, and the mechanisms necesary to update them. *)
(* Ñ Full Desk Accessory support. *)
(* Ñ Font information may be transported through the Clipboard. *)
(* *)
(* This program doesn't do anything special under MultiFinder, although is does have a SIZE *)
(* resource. *)
(* *)
(* This code is in the Public Domain. You may use any part of it in your own programs, and I'm *)
(* not asking for any money. *)
(* *)
(* Version History: *)
(* Version 1.0, September 9, 1988 *)
(* Version 1.1, September 13, 1988 *)
(* Ñ Fixed problems with PICT objects and the Clipboard by creating a seperate *)
(* PICT for the clipboard itself (instead of recycling a window pict.) *)
(* Ñ Added TEXT type to the clipboard (string contains all 256 characters) *)
(* *)
(* Written by Richard Clark. You can reach me at: *)
(* GEnie/DELPHI/MCI Mail/The MouseHole (Orange County, CA): RDCLARK *)
(* Compu$erve: (I have an account, but never use it. Try the MCI gateway) *)
(* The Desktop BBS (Orange County, CA): Box #003. *)
{$D+}
{$U-} (* Don't include Standard I/O units *)
{$S+} (* Use segmentation *)
{$B+} (* Turn on the Bundle Bit *)
{$R FontShow.rsrc} (* Use these resources *)
{$T APPLFSho} (* Our creator code is "FSho" (NOT registered with Apple) *)
{$U Globals}
{$U Windows}
{$U Menus}
{$U MemHandler}
{$U Initialization}
USES
{$S MainSeg} MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf,
Globals,
{$S WindSeg} Windows, (* Windows and menus have their own segments. *)
{$S MenuSeg} Menus, (* Initialization is in its own segment *)
{$S MainSeg} MemHandler, (* Our globals, memory watchdog, and main loop share a segment *)
{$S InitSeg} Initialization;
{$S MainSeg} (* This is in the MAIN segment *)
PROCEDURE MainLoop;
(* Collect and process events. *)
VAR
theEvent : EventRecord; (* Our current event *)
realEvent : Boolean;
PROCEDURE handleMouseDown;
(* This handles a mouse-down event anywhere in our screen *)
VAR
location : INTEGER; (* Which area was it in? *)
whichWindow : WindowPtr; (* Which window as it in? *)
menuCode : LONGINT; (* If we had a menu event, here's the code for it *)
newWindSize : LONGINT; (* If we're resizing a window, here's the new size *)
BEGIN
location := FindWindow(theEvent.where, whichWindow); (* Locate where the mouse was clicked *)
CASE location OF (* Take the appropriate action *)
inMenuBar : BEGIN (* ...pulling down a menu *)
menuCode := MenuSelect(theEvent.where); (* Hilite the menu and track the mouse *)
DoMenus(menuCode); (* Give the result to the menu handler *)
END;
inContent : SelectWindow(whichWindow); (* Bring this window to the front *)
inSysWindow : SystemClick(theEvent, whichWindow); (* Give DAs their clicks *)
inGoAway : IF TrackGoAway(whichWindow, theEvent.where) THEN (* We have a click in the close box *)
BEGIN
CloseAWindow(whichWindow);
AdjustMenus(FALSE);
END;
inDrag : DragWindow(whichWindow, theEvent.where, DragLimits); (* Move this window *)
inGrow : BEGIN (* resize this window *)
newWindSize := GrowWindow(whichWindow, theEvent.where, SizeLimits);
IF (newWindSize <> 0) THEN (* resize the window, and let the Mac take care of the updating *)
SizeWindow(whichWindow, LoWord(newWindSize), HiWord(newWindSize), TRUE);
END;
OTHERWISE
; (* Do nothing *)
END; (* case location *)
END; (* handleMouseDown *)
PROCEDURE handleKeyDown;
(* This procedure checks to see if a keypress is a menu command, and if so, calls the menu handler *)
VAR
ch : Char; (* the current character *)
menuCode : LONGINT; (* Our menu selection *)
BEGIN
ch := chr(BitAnd(theEvent.message, charCodeMask)); (* Extract the character from the event record *)
IF BitAnd(CmdKey, theEvent.modifiers) <> 0 THEN
BEGIN (* This is a menu command *)
menuCode := MenuKey(ch); (* Find out which item, and hilite the menu *)
doMenus(menuCode); (* Give the information to our menu handler *)
END;
END; (* handleKeyDown *)
BEGIN (* MainLoop *)
REPEAT
UnloadSeg(@DoMenus); (* We're not using these code segments now, so free up *)
UnloadSeg(@UpdateWindow); (* some memory *)
MemStatus; (* Report if we're running out of memory *)
PreAllocate; (* Get any fixed blocks while the heap is as clean as possible *)
UpdateUsage; (* If the "about" window is open, update the memory information *)
SystemTask; (* Give open Desk Accessories some time *)
realEvent := GetNextEvent(everyEvent, theEvent); (* Get our next event *)
CASE (theEvent.what) OF (* Dispatch the event to the appropriate handler *)
nullEvent : (* Do nothing *) ;
MouseDown : handleMouseDown;
KeyDown : handleKeyDown;
UpdateEvt : UpdateWindow(WindowPtr(theEvent.message));
ActivateEvt : BEGIN (* If a Font window is coming to the front, update *)
ActivateWindow(WindowPeek(theEvent.message), (* our font and size globals *)
odd(theEvent.modifiers));
AdjustMenus(TRUE); (* Adjust the menus to reflect the new window, and force *)
END; (* them to be redrawn. *)
OTHERWISE
; (* Trap all other event codes *)
END; (* case (theEvent.where) *)
UNTIL Quit;
END; (* MainLoop *)
PROCEDURE Shutdown;
(* This procedure cleans up when we quit *)
VAR
scrapErr : LONGINT;
BEGIN
CloseAllWindows;
scrapErr := LoadScrap; (* Make certain that the scrap is kept in memory *)
END; (* Shutdown *)
BEGIN
Initialize;
UnloadSeg(@Initialize); (* We won't need this segment again, so free up the memory *)
MainLoop;
Shutdown;
END.