home *** CD-ROM | disk | FTP | other *** search
- /*
- File: DialogUtils.c
-
- Description:
-
- Author: ME
-
- Copyright: Copyright: © 1999 by Apple Computer, Inc.
- all rights reserved.
-
- Disclaimer: You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- Change History (most recent first):
- 6/24/99 Updated for Metrowerks Codewarror Pro 2.1(KG)
-
- */
- /* DialogUtils.c */
-
- #include <QuickDraw.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <StandardFile.h>
- #ifndef topLeft
- #define topLeft(r) (((Point *)&(r))[0])
- #endif
- #ifndef botRight
- #define botRight(r) (((Point *)&(r))[1])
- #endif
- #include "DialogUtils.h"
-
- static void DU_CenterRect(Rect *rect_p);
- static Point DU_Where(short rsrcId);
- static short DU_Center(ResType type, short rsrcId);
-
- static void DU_CenterRect(Rect* rect_p){
- /*
- * Aligns *rect_p wrt screenBits.bounds - LR centered & in upper 1/3
- */
-
- /* exactly centered */
- OffsetRect(rect_p,
- (qd.screenBits.bounds.right + qd.screenBits.bounds.left)/2 -
- (rect_p->right + rect_p->left)/2
- ,
- (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)/2 -
- (rect_p->top + rect_p->bottom)/2
- );
-
- /* up a bit */
- OffsetRect(rect_p,0,
- GetMBarHeight() - 2*(rect_p->top - qd.screenBits.bounds.top)/3);
- }
-
- static Point DU_Where(short rsrcId){
- /*
- * Returns centering point for the topLeft corner of a dialog.
- */
- Handle h = GetResource('DLOG',rsrcId);
- Rect r = {0,0,0,0};
- if(h){
- r = *((Rect*)(*h));
- DU_CenterRect(&r);
- ReleaseResource(h);
- }
- return topLeft(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 it's display Rect.
- */
- Handle h = GetResource(type,rsrcId);
- 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);
- }
-