/*
* Dialog Utilities
*/
// Assumes inclusion of
/* Return topLeft point to center standard file dialogs. */
Point DU_StdPutWhere(void); Point DU_StdGetWhere(void); /*
* Pre-load and center ALRT/DLOG template resources. Changes do not affect
* the resource file, but if the ALRT/DLOG is created soon after the call
* it will use the modified (centered) template in memory. Both routines
* return the passed rsrc id to allow calls like:
* Alert(DU_CenterALRT( alertID),filter);
* GetNewDialog(DU_CenterDLOG(dlogID),dStorage,behindWindow);
*/
short DU_CenterALRT( short rsrcId);
short DU_CenterDLOG( short rsrcId);
static Rect DU_MouseGDRect(void) { /* Returns the gdRect of the screen device the mouse is currently in. */
Rect r = screenBits.bounds; GetMouse(&p);
while(curDevice){
r = (*curDevice)->gdRect;
}
return r;
}
static void DU_CenterRect(Rect* rect_p){ /*
* Aligns *rect_p with screenBits.bounds - LR centered & with 1/3 of the
* empty space above the rect.
*/
Rect bRect = DU_MouseGDRect(); /* exactly centered */
OffsetRect(rect_p, (bRect.right + bRect.left)/2 - (rect_p->right + rect_p->left)/2, (bRect.top + bRect.bottom)/2 -
(rect_p->top + rect_p->bottom)/2);
/* 1/2 empty space above -> 1/3 empty space above */
OffsetRect(rect_p,0,-(rect_p->top - bRect.top)/3); }
static Point DU_Where( short rsrcId){ /*
* Returns centering point for the topLeft corner of a dialog.
*/
if(h){
DU_CenterRect(&r);
}
}
Point DU_StdPutWhere(void){ return DU_Where(putDlgID);
}
Point DU_StdGetWhere(void){ return DU_Where(getDlgID);
}
static short DU_Center(ResType type, short rsrcId){ /*
* Reads in an 'ALRT' or 'DLOG' rsrc template & centers its display Rect.
*/
if(h)
DU_CenterRect((Rect*)(*h)); return rsrcId;
}
short DU_CenterALRT( short rsrcId){
return DU_Center('ALRT',rsrcId);
}
short DU_CenterDLOG( short rsrcId){
return DU_Center('DLOG',rsrcId);
}