[comp.sys.mac.programmer] Centering alerts vs. centering dialogs

lipa@POLYA.STANFORD.EDU (William Lipa) (06/20/88)

As far as I can tell, centering alerts is much harder than centering dialogs.
Try it sometime, you'll like it! Of course, I realize that I could just use a
dialog instead of an alert. But this won't let me use any of the features of
alerts (different levels of sound and visibility, handy caution icons, and
ease of programming).

I don't think this is a terrible deficiency in the Mac OS. Rather, it is
something that should be cleaned up to keep programmers from becoming
frustrated by manager interfaces defined for the 128K Mac.

Bill Lipa
lipa@polya.stanford.edu

fry@huma1.HARVARD.EDU (David Fry) (06/21/88)

In article <CMM.0.86.582748031.lipa@polya.stanford.edu> lipa@POLYA.STANFORD.EDU (William Lipa) writes:
>As far as I can tell, centering alerts is much harder than centering dialogs.
>Try it sometime, you'll like it!

Centering alerts is very simple.  You simply read in the
Handle of the ALRT resource, center it and immediately call
Alert().  Here's an example in C.  A similar technique can be
used to center StdFile dialogs.  


/* 
   The variables ScreenHeight and ScreenWidth are calculated at
   runtime and mean what you think they mean.  They should take into
   account variable menuBar heights and multiple screens on Mac IIs.
*/

CenterAlert(ID)
short	ID;
{
	AlertTHndl 		aboutALRT;
	    
    aboutALRT = GetResource('ALRT',ID);
    CenterRBox(aboutALRT);
	Alert(ID, 0L);
	ReleaseResource(aboutALRT);  
}

CenterRBox(boxHandle)
Handle boxHandle;
{
/* 
	given a Handle to a block (usually a resource) whose first 8 
	bytes represent a box on the screen, this function changes 
	that rectangle to be positioned nicely on the screen
*/
	int		w,h;
	Rect	temp;

    temp =  *(Rect *)*boxHandle;
    h = temp.bottom - temp.top;
    CenterRect(&temp);
    temp.top = menuH + (ScreenHeight - h)/3;
    temp.bottom = temp.top + h;
    *(Rect *)*boxHandle = temp;
}	

CenterRect(r)
Rect	*r;
{
/* "centers" a rectangle on the screen */
	int	w,h;
	
	w = r->right - r->left;
	h = r->bottom - r->top;
	r->left = (ScreenWidth - w)/2;
	r->right = r->left + w;
	r->top = (ScreenHeight - h - menuH)/2
		+ menuH;
	r->bottom = r->top + h;
}


David Fry				fry@huma1.harvard.EDU
Department of Mathematics		fry@huma1.bitnet
Harvard University			...!harvard!huma1!fry
Cambridge, MA  02138		

jmm@thoth10.berkeley.edu (06/21/88)

Someone objected to having a routine that would center an alert in the ROMs,
and had good reason for doing so.  But what about including a routine in MPW?
This doesn't take ROM space that could be used for useful things, would
be easy to do (Apple could just publish a tech note with the source,
which would make the routine available to everyone, not just MPW users),
and would keep the world standard.  Pascal would seem to be the obvious
language to do this in, although versions in C would also be nice.

James Moore				| B'fhearr don net mura mbeadh
jmm@bartleby.berkeley.edu		| Bearla ar bith ann.
#airigh "leithsceal caighdeanach"	| 			:-)