Font Dialog (code)
Volume Number: 4
Issue Number: 7
Column Tag: Assembly Language Lab
Font Dialog Box Using List Manager (code)
; File Window.Asm
;----------------------------------------------------------
; Macintosh 68000 Development System
;----------------------------------------------------------
; The Window Sample Program issued with the MDS.
; Modified by Ray.A.Cameron to demonstate a Modal Dialog Box.
; Mon May 4, 1988 21:29:54
This application displays a window within which you can enter and edit text.
Program control is through four menus: the Apple menu, the File menu, the Edit menu,
and the Font menu.The Apple menu has the standard desk accessories and an About
feature. The File menu lets you quit the application. The Edit menu lets you cut, copy,
paste, and clear the text in the window or in the desk accessories. Undo is provided for
desk accesories only. Command key equivalents for undo, cut, copy, and paste are
provided. The Font menu lets you display a Modal Dialog Box to select a Font Name, Size
and attributes.
;----------------------- Includes ----------------
Include Traps.D ; Use System and ToolBox traps
Include ToolEqu.D ; Use ToolBox equates
Include QuickEqu.D ; Use QuickDraw equates
Include SysEqu.D ; Use System equates
Include PackMacs.Txt ; Use Package equates
;------------------- Use of Registers -----------
; Operating Sys and Toolbox calls preserve D3-D7, A2-A4.
; Register use: A5-A7 are reserved by the system
; D1-D3, A0-A1 are unused
; D0 is used as a temp
ModifyReg Equ D4 ; modifier bits from GetNextEvent
MenuReg Equ D5 ; menu ID from MenuSelect,MenuKey
MenuItemReg Equ D6 ; item ID from MenuSelect,MenuKey
AppleHReg Equ D7 ; handle to the Apple Menu
TextHReg Equ A2 ; handle to TextEdit record
WindowPReg Equ A3 ; pointer to editing window
EditHReg Equ A4 ; handle to Edit menu
;------------------- Equates ----------------
; These are equates associated with the resources
; for the Window example.
AppleMenu Equ 1 ; First item in MENU resource
AboutItem Equ 1 ; First item in Apple menu
FileMenu Equ 2 ; Second item in MENU resource
QuitItem Equ 1 ; First item in File menu
EditMenu Equ 3 ; Third item in MENU resource
UndoItem Equ 1 ; Items in Edit menu
CutItem Equ 3 ; (Item 2 is a line)
CopyItem Equ 4
PasteItem Equ 5
ClearItem Equ 6

FontMenu Equ 4 ; Fourth item in MENU resource
DialogItem Equ 1 ; Only item in Font menu
AboutDialog Equ 1 ; About dialog is DLOG resource #1
ButtonItem Equ 1 ; First item in DITL used by DLOG #1
ASample Equ 1 ; Sample Window is WIND resource #1
;-------------------- Xdefs ----------------
; Xdef all labels to be symbolically displayed by debugger.
Xdef Start
Xdef InitManagers
Xdef SetupMenu
Xdef SetupWindow
Xdef SetupTextEdit
Xdef Activate
Xdef Deactivate
Xdef Update
Xdef KeyDown
Xdef MouseDown
Xdef SystemEvent
Xdef Content
Xdef Drag
Xdef InMenu
Xdef About
XRef SetupFontMap ; Routines
XRef FontDialog
XRef FontMap ; Variable
;----------------- Main Program -------------
Bsr InitManagers ; Initialize managers
Bsr SetupMenu ; Build menus, draw menu bar
Bsr SetupWindow ; Draw Editing Window
Bsr SetupTextEdit ; Initialize TextEdit
Bsr SetupFontMap ; Initialize the FontMap
EventLoop ; Main Program Loop
_SystemTask ; Update Desk Accessories
; Procedure TEIdle (hTE:TEHandle);
Move.l TextHReg,-(SP) ; Get handle to text record
_TEIdle ; blink cursor etc.
; Function GetNextEvent( eventMask: Integer
; Var theEvent: EventRecord) : Boolean
Clr -(SP) ; Clear space for result
Move #$0FFF,-(SP) ; Allow 12 low events
Pea EventRecord ; Place to return results
_GetNextEvent ; Look for an event
Move (SP)+,D0 ; Get result code
Beq EventLoop ; No event... Keep waiting
Bsr HandleEvent ; Go handle event
Beq EventLoop ; Not Quit, keep going
Rts ; Quit, exit to Finder
Note: When an event handler finishes, it returns the Z flag set. If Quit was
selected, it returns with the Z flag clear. An Rts is guaranteed to close all files and
launch the Finder.