TweetFollow Us on Twitter

Definition Routines
Volume Number:2
Issue Number:7
Column Tag:Pascal Procedures

Introduction to Definition Routines

By Darryl Lovato, Lovato Programming, Salt Lake City, UT

Introduction

This is the first of a series of articles which will cover Macintosh Definition Routines. I will use TML Pascal for all the programming examples because it is rapidly becoming the most popular Development System on the Mac, and because the new TML linker will allow you to create procedure resources (MDEF's PROC's WDEF's FKEY's ect.) quickly and efficiently.

This month I will cover the issues in common to all the different types of definition routines. In the following months I will cover Menu definition routines (MDEF's), Window definition routines (WDEF's), Control definition routines (CDEF's), List definition routines (LDEF's), and function key routines (FKEY's) in depth.

Defintion routines allow you to create a variation of a standard type of "Object" to better fit your needs. That is, they effect the general appearance and behavior of whatever they define. The pattern selection Menu in MacDraw is a good example of this. Definition routines are usually stored as resources but they may also be set up as routines within your program.

The best way to develop a Definition Routine is to make it a routine in your code, and when its finished, to compile it into a resource which can then be used with any application. The Menu, Window, Contol, and List managers all allow you to use definition routines.

Fig. 1 A non-standard Menu Item

Getting a Handle On Things

When you create a new object (menu, window ect.), you can specify a non-standard definition routine (a routine other than the normal Mac ROM way of doing something) for it to use. There are two ways of doing this.

1. By making the procedure a resource in a seperate file.

An example of this process for a non-standard menu follows. Listing #1 is the code that creates the Menu Definition Resource and listing #2 shows how to use it.

{---------listing fragment #1 the resource def program-------}
{must be compiled with the DeskAcc option checked}
program TheMDEFProc;

{pascal directive to create a MDEf resource}
{---> $C type id [attribute] [name] <---}

{$C 'MENU' 256 4 'TheMDEFRes'}

var { no globals allowed }

  procedure theMDEFProcedure(...);

  begin
    { code to impliment the Menu Def }
  end;

begin {no main program allowed}
end.

{------listing fragment #2 the program that uses the res-----}

program UseTheMenu;

{$L TheMDEFProc} {link the file we created above}
          {it includes the menu def we created}

Two methods can be used to put a handle to your MDEF resource in the MenuProc field of the menu.

(1) In the menu resource, change the menuID field to the resource id of your MDEF. Then,when you call the GetMenu function, the Menu Manager will automatically read the MDEF resource from the resource file, and place a handle to it in the MenuProcField of the menu

(2) If you create the menu (or window) by any means other than reading a resource (by calling NewMenu, for instance), you must get a handle to the MDEF by executing the following code:

 MyMenuHand := NewMenu(100,'menuTitle');
 myProcHdl := GetResource('MDEF',256);
 MyMenuHand^^.menuProc := myProcHdl;

2. By putting the proc in your code and creating a handle to it.

First get a handle to your object, by calling NewMenu or GetNewMenu. Then get a handle to the definition routine, which may be part of your code, and shove it into the MenuProc field of your objects record. An Example of this method follows:

var
 myMenuHdl : MenuHandle;

procedure TheMenuProc(...);
begin
.
.
.
end;
.
.
.
myMenuHdl := GetNewMenu(...);
myMenuHdl^^.menuProc := NewHandle(0);
myMenuHdl^^.menuProc^ := Ptr(@TheMenuProc);

Fig. 2 A non-standard window definition

Things to Come

All of the definition routines are passed a message which tell them what kind of action the are to do. Typical actions are Initialize, Draw, Select, Drag, Size, ect. A brief introduction to the individual definition routines we will cover in the in the next couple of months follow:

Menu Defintion Procedure

The menu definition procedure has the following Pascal definition:

procedure MyMenu(message : integer;
 theMenu : MenuHandle;
 var menuRect : Rect;
 hitPt : Point;
 var whichItem : Integer);

The message parameter tells you what kind of action to take, it may be one of the following values:

mDrawMsg

If the menu definition procedure is passed this value it should draw theMenu inside menuRect.

mChooseMsg

If the menu definition procedure is passed this value it should hilite the item which hitPt is in, unhilite the old item, and return the new item in whichItem.

mSizeMsg

If the menu definition procedure is passed this value it should calculate the width and height of the menu and put the results in theMenu^^.width and theMenu^^.height respectively.

Window Defintion function

The window definition function has the following Pascal definition:

function MyWindow(varCode : integer;
 theWindow : WindowPtr;
 message : integer;
 param : LongInt)
 : LongInt;

The message parameter tells you what kind of action to take, it may be one of the following values:

wDraw

If the window definition function is passed this value it should draw the window frame. Before doing this, however, the routine should check to see if the window frame should show hiliting, if the window is visible, if the window has a go-away box, ect.

wHit

If the window definition function is passed this value it should inspect param, which is the point where the mouse was pressed. Then it should check to see if the point is in one of the windows regions, such as the GoAway region, and return the appropriate result.

wCalcRgns

If the window definition function is passed this value it should calculate the windows current structure and content regions and store the results in the window record.

wNew

If the window definition function is passed this value it should perform any extra initialization and allocation it may require.

wDispose

If the window definition function is passed this value it should perform any additional disposal actions which it may require. This message "Undo's" whatever was done in the wNew routine.

wGrow

If the window definition function is passed this value it should draw a grow image of the window to fit the given rectangle. This operation is called repeatedly when the user drags inside the grow region.

wDrawGIcon

If the window definition function is passed this value it should draw the size box icon in the window.

Control Defintion Function

The control definition function has the following Pascal definition:

function MyControl(varCode : integer;
 theControl : ControlHandle;
 message : integer;
 param : LongInt)
 : LongInt;

The message parameter tells you what kind of action to take, it may be one of the following values:

drawCntl

If the control definition function is passed this value it should draw all or part of theControl.

testCntl

If the control definition function is passed this value it should test where the mouse button was pressed.

calcCRgns

If the control definition function is passed this value it should calculate the control or its indicators regions.

initCntl

If the control definition function is passed this value it should do any extra initialization actions it needs to perform.

dispCntl

If the control definition function is passed this value it should take any additional disposal actions.

posCntl

If the control definition function is passed this value it should reposition the controls indicator, and update it.

thumbCntl

If the control definition function is passed this value it should calculate parameters for dragging indicator.

dragCntl

If the control definition function is passed this value it should drag the control or its indicator.

autoTrack

If the control definition function is passed this value it should execute the control's action procedure.

List Defintion Procedure

The list definition procedure has the following Pascal definition:

procedure MyList(lmessage : integer;
 lSelect : Boolean;
 lRect : Rect;
 lCell : Cell;
 lDataOffset : integer;
 lDataLen : integer;
 lHandle : ListHandle);

The message parameter tells you what kind of action to take, it may be one of the following values:

lInitMsg

If the list definition procedure is passed this value it should do any additional list initialization.

lDrawMsg

If the list definition procedure is passed this value it should draw the cell.

lHiliteMsg

If the list definition procedure is passed this value it should invert the cell's highlite state.

lCloseMsg

If the list definition procedure is passed this value it should take any additional disposal actions.

A Warning From Apple

Apple has stated, "For the convienience of the application's user, remember to conform to the Macintosh User Interface Guidlines as much as possable". I agree totally. So don't make a round menu or a window in the shape of a Apple. (I've already done them both anyway!) [Wow! How about publishing the Apple window? -Ed.]

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Notion 2.1.3 - A unified workspace for m...
Notion is the unified workspace for modern teams. Features: Integration with Slack Documents Wikis Tasks More improvements to editing Browse through a page’s images from one place Choose a type... Read more
Cocktail 15.3.7 - General maintenance an...
Cocktail is a general purpose utility for macOS that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
Dropbox 158.4.4564 - Cloud backup and sy...
Dropbox is a file hosting service that provides cloud storage, file synchronization, personal cloud, and client software. It is a modern workspace that allows you to get to all of your files, manage... Read more
WhatsApp 2.2236.10 - Desktop client for...
WhatsApp is the desktop client for WhatsApp Messenger, a cross-platform mobile messaging app which allows you to exchange messages without having to pay for SMS. WhatsApp Messenger is available for... Read more
VOX 3.5.2 - Music player that supports m...
VOX just sounds better! The beauty is in its simplicity, yet behind the minimal exterior lies a powerful music player with a ton of features and support for all audio formats you should ever need.... Read more
TeamViewer 15.34.4 - Establish remote co...
TeamViewer gives you remote control of any computer or Mac over the Internet within seconds, or can be used for online meetings. Find out why more than 200 million users trust TeamViewer! Free for... Read more
ClamXAV 3.5 - Virus checker based on Cla...
ClamXAV is a popular virus checker for OS X. Time to take control ClamXAV keeps threats at bay and puts you firmly in charge of your Mac’s security. Scan a specific file or your entire hard drive.... Read more
Ableton Live 11.2 - Record music using d...
Ableton Live lets you create and record music on your Mac. Use digital instruments, pre-recorded sounds, and sampled loops to arrange, produce, and perform your music like never before. Ableton Live... Read more
Viber 18.5.0 - Send messages and make fr...
Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country! Viber syncs your contacts, messages and call history with your mobile device, so... Read more
CrossOver 22.0.1 - Run Windows apps on y...
CrossOver can get your Windows productivity applications and PC games up and running on your Mac quickly and easily. CrossOver runs the Windows software that you need on Mac at home, in the office,... Read more

Latest Forum Discussions

See All

TouchArcade Game of the Week: ‘Tallowmer...
With its pre-determined launch date of September 30th it didn’t quite make it in time for our weekly round-up of new game releases, but darn it, I just don’t care. I’m not letting that technicality keep me from picking Tallowmere 2 as our Game of... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 30th, 2022. In today’s article, our pal Mikhail has another review for us. Gosh, that guy needs a day off! He’s taking a look at Let’s Build a Zoo, and it’s not exactly the... | Read more »
Seven Knights 2 recieves global update i...
Netmarble has announced the latest global update for mobile role-playing game Seven Knights 2. The update will bring brand new characters, some very rewarding events, and reworks to a few old favourite heroes. [Read more] | Read more »
‘GRIS+’ Is This Week’s New Apple Arcade...
Nomada Studio and Devolver Digital’s brilliant GRIS+ () has joined Apple Arcade today as an App Store Great. If you’ve not played it yet, GRIS debuted on PC and Nintendo Switch before seeing PS4 and mobile releases later on. I reviewed the iOS... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 29th, 2022. In today’s article, we have a bunch of new releases to check out with the spearhead being The Elder Scrolls V: Skyrim Anniversary Edition. There’s a little here... | Read more »
‘Residual’ Controller Fix Update Release...
A few weeks back developer OrangePixel released their newest game on mobile called Residual. This is a roguelike survival game where you play as a pilot who crash lands on a procedurally generated planet, filled with all sorts of crazy creatures and... | Read more »
‘Queen’s Wish 2: The Tormentor’ Launchin...
We learned back in July that Spiderweb Software’s latest game Queen’s Wish 2: The Tormentor would be heading to desktop platforms in August, which is exactly what happened, and at that time we were guessing that the iOS version of the game would... | Read more »
‘Kingdom Rush Vengeance’ Primal Ravage U...
Ironhide Game Studio’s Kingdom Rush Vengeance ($4.99) has gotten quite a few updates over the years on iOS, Android, and PC. | Read more »
Interactive Film The Gallery screens at...
The FMV/interactive film hybrid video game genre has been around for a while but doesn’t seem to have that many games out there, but they just might get some more exposure as The Gallery has landed a spot in the Dinar Film Festival 2022. [Read... | Read more »
Terraria’s Massive Labor of Love Update...
Re-Logic’s action platforming sandbox game Terraria ($4.99) has just been updated on mobile and console platforms with its newest major update titled the ‘Labor of Love’ update. | Read more »

Price Scanner via MacPrices.net

Apple has M1 Mac minis in stock again startin...
Apple has restocked a full line of M1-powered Mac minis available in their Certified Refurbished section starting at only $589 and up to $140 off MSRP. Each mini comes with Apple’s one-year warranty... Read more
13″ M1 MacBook Airs with 16GB of RAM availabl...
Apple has 13″ M1 MacBook Airs (8-Core CPU/7-Core GPU) in stock today with 16GB of RAM for $190 off MSRP, Certified Refurbished. Apple includes a standard one-year warranty with these models, each... Read more
Update: 13-inch Apple M2 MacBook Airs now on...
Amazon has 13″ MacBook Airs with M2 CPUs in stock today and on sale for $150 off MSRP. Shipping is free. Their prices are now $150 off Apple’s MSRP, and they are the lowest prices available for these... Read more
Save $240 on a 14″ 8-core CPU M1 Pro MacBook...
Apple has the 14″ M1 Pro MacBook Pro with 32GB of RAM and a 512GB SSD (Space Gray) in stock for $2159, Certified Refurbished. Regular price for this configuration is $2399, so their savings amounts... Read more
Save $170 on this 13″ M2 MacBook Pro with 16G...
Apple has 13″ M2 MacBook Pros with 16GB of RAM and 512GB SSDs in stock today for $170 off MSRP ($1529), Certified Refurbished. These are the cheapest 13″ M2 MacBook Pros with this configuration... Read more
This Apple retailer is offering a $350 discou...
Apple retailer Expercom is offering a $350 instant discount on select upgraded 16″ Apple MacBook Pros through October 4, 2022. Shipping is free. Their sale price applies to the following... Read more
Clearance 27″ 5K Apple iMacs are on sale star...
Other World Computing has dropped prices on Apple refurbished, factory-sealed, recently-discontinued 27″ 5K iMacs with models now on sale for up to $950 off Apple’s MSRP, starting at only $849. Their... Read more
Get a new Mac for up to $400 off MSRP at Appl...
Need a new Apple Mac for school? Whether you’re a student, teacher, or staff member, you can use your .edu email address when ordering at Apple Education to take up to $400 off the price of a new Mac... Read more
13-inch Apple MacBook Airs with M2 processors...
Amazon has 13″ MacBook Airs with M2 CPUs in stock today and on sale for $1099. Shipping is free. Their prices are $100 off Apple’s MSRP, and they are the lowest prices available for M2-powered Macs... Read more
AR Glasses That Work With Apple’s Hardware? T...
NEWS – Lenovo has created quite the spectacle(s) with its latest product. “Apple Glass” — the purported name of Apple’s forthcoming AR glasses — is not expected to be released until 2025 (at the... Read more

Jobs Board

*Apple* Electronic Repair Technician - PlanI...
…a highly motivated individual to join our Production Department as an Apple Electronic Repair Technician. The computer repair technician will diagnose, assemble, Read more
( *Apple* ) Production Designer/Artist - TEKs...
…Art Ops team supports production, asset management, quality control, and global publishing for Apple Media Products, like Apple Music. The Art Ops team is Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Sephora Beauty Advisor - *Apple* Blossom Ma...
Sephora Beauty Advisor - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.