home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / DTS.Lib / DTS.Lib.headers / Utilities.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  38.9 KB  |  925 lines  |  [TEXT/MPS ]

  1. /*-----------------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    Collection of Utilities for DTS Sample code
  6. #
  7. #    Program:    Utilities.c.o
  8. #    File:        Utilities.h    -    Header for C Source
  9. #
  10. #    Copyright © 1988-1990 Apple Computer, Inc.
  11. #    All rights reserved.
  12. #
  13. -----------------------------------------------------------------------------------------*/
  14.  
  15. #ifndef __UTILITIES__
  16. #define __UTILITIES__
  17.  
  18. #if defined(applec) || defined (powerc)
  19.  
  20. #    ifndef __TYPES__
  21. #        include <Types.h>
  22. #    endif
  23.  
  24. #    ifndef __QUICKDRAW__
  25. #        include <QuickDraw.h>
  26. #    endif
  27.  
  28. #    ifndef __DIALOGS__
  29. #        include <Dialogs.h>
  30. #    endif
  31.  
  32. #    ifndef __FILES__
  33. #        include <Files.h>
  34. #    endif
  35.  
  36. #    ifndef __MEMORY__
  37. #        include <Memory.h>
  38. #    endif
  39.  
  40. #    ifndef __MENUS__
  41. #        include <Menus.h>
  42. #    endif
  43.  
  44. #    ifndef __OSUTILS__
  45. #        include <OSUtils.h>
  46. #    endif
  47.  
  48. #    ifndef __WINDOWS__
  49. #        include <Windows.h>
  50. #    endif
  51.  
  52. #endif
  53.  
  54.  
  55. #include "UtilitiesCommon.h"
  56. #ifndef __STRINGUTILS__
  57. #include "StringUtils.h"
  58. #endif
  59.  
  60.  
  61. #if defined(powerc) || defined (__powerc)
  62. #pragma options align=mac68k
  63. #endif
  64. struct PopupCtlData {
  65.     MenuHandle        mHandle;
  66.     short            mID;
  67.     char            mPrivate[1];
  68. };
  69. typedef struct PopupCtlData PopupCtlData;
  70. typedef PopupCtlData *PopupCtlDataPtr, **PopupCtlDataHandle;
  71. #if defined(powerc) || defined(__powerc)
  72. #pragma options align=reset
  73. #endif
  74.  
  75. #define    kMenuItemTxtInsert    -1
  76. #define    kMenuItemNumInsert    -2
  77. #define kMenuItemSectionEnd    -3
  78.  
  79. /*-----------------------------------------------------------------------------------------
  80.     Global constants
  81. -----------------------------------------------------------------------------------------*/
  82. #ifndef applec
  83.  
  84. #ifndef nil
  85. #define nil    0L
  86. #endif
  87.  
  88. #ifndef _WaitNextEvent
  89. #define _WaitNextEvent    0xA860
  90. #endif
  91.  
  92. #ifndef _InitGraf
  93. #define _InitGraf        0xA86E
  94. #endif
  95.  
  96. #ifndef _Unimplemented
  97. #define _Unimplemented    0xA89F
  98. #endif
  99.  
  100. /*
  101. #define screenActive            15
  102. */
  103. #endif
  104.  
  105. #define    kNoEvents                0            /* no events mask */
  106. #define kDelayTime                4            /* For the delay time when flashing the
  107.                                                menubar and highlighting a button.
  108.                                                4/60ths of a second*/
  109.  
  110. #define kStartPtH                2            /* offset from the left of the screen */
  111. #define kStartPtV                2            /* offset from the top of the screen */
  112. #define kStaggerH                12            /* staggering amounts for new windows */
  113. #define kStaggerV                16
  114.  
  115. #define chHome                    '\001'        /* ASCII code for the Home key */
  116. #define chEnter                    '\003'        /* ASCII code for Enter character */
  117. #define chEnd                    '\004'        /* ASCII code for the End key */
  118. #define chHelp                    '\005'        /* ASCII code for Help key */
  119. #define chBackspace                '\010'        /* ASCII code for Backspace character */
  120. #define chTab                    '\011'        /* ASCII code for Tab character */
  121. #define chPageUp                '\013'        /* ASCII code for Page Up key */
  122. #define chPageDown                '\014'        /* ASCII code for Page Down key */
  123. #define chReturn                '\015'        /* ASCII code for Return character */
  124. #define chFunction                '\020'        /* ASCII code for any function key */
  125. #define chClear                    '\033'        /* ASCII code for Clear key (aka ESC) */
  126. #define chEscape                '\033'        /* ASCII code for Escape (aka Clear) key */
  127. #define chLeft                    '\034'        /* ASCII code for left arrow */
  128. #define chRight                    '\035'        /* ASCII code for right arrow */
  129. #define chUp                    '\036'        /* ASCII code for up arrow */
  130. #define chDown                    '\037'        /* ASCII code for down arrow */
  131. #define chFwdDelete                '\177'        /* ASCII code for forward delete */
  132. #define chSpace                    ' '            /* ASCII code for Space character */
  133.  
  134. enum { kQDOriginal = 0, kQD8Bit, kQD32Bit };    /* For use with gQDVersion */
  135.  
  136. /*-----------------------------------------------------------------------------------------
  137.     Types
  138. -----------------------------------------------------------------------------------------*/
  139.  
  140. typedef short *IntegerPtr, **IntegerHandle;
  141.  
  142. typedef long *LongintPtr, **LongintHandle;
  143.  
  144. typedef Boolean *BooleanPtr, **BooleanHandle;
  145.  
  146. #ifndef THINK_C
  147. typedef Rect *RectPtr, **RectHandle;
  148. #endif
  149.  
  150. #if defined(powerc) || defined (__powerc)
  151. #pragma options align=mac68k
  152. #endif
  153. struct    WindowTemplate    {                    /*template to a WIND resource*/
  154.     Rect    boundsRect;
  155.     short    procID;
  156.     Boolean    visible;
  157.     Boolean    filler1;
  158.     Boolean    goAwayFlag;
  159.     Boolean    filler2;
  160.     long    refCon;
  161.     Str255    title;
  162. };
  163. typedef    struct    WindowTemplate    WindowTemplate;
  164. typedef            WindowTemplate    *WindowTPtr, **WindowTHndl;
  165. #if defined(powerc) || defined(__powerc)
  166. #pragma options align=reset
  167. #endif
  168.  
  169. /* following is here to account for lapses in the THINK C headers */
  170.  
  171. #ifndef applec
  172. #ifndef powerc
  173. #ifndef THINK_C
  174. /*
  175. typedef unsigned char TrapType;
  176. */
  177.  
  178. #if defined(powerc) || defined (__powerc)
  179. #pragma options align=mac68k
  180. #endif
  181. struct NumVersion {
  182.     unsigned char majorRev;             /* 1st part of version number in BCD*/
  183. /*    unsigned short minorRev : 4;            2nd part is 1 nibble in BCD*/
  184. /*    unsigned short bugFixRev : 4;             3rd part is 1 nibble in BCD*/
  185.     unsigned char minorAndBugFixRev;
  186.     unsigned char stage;                /*stage code: dev, alpha, beta, final*/
  187.     unsigned char nonRelRev;            /*revision level of non-released version*/
  188. };
  189. typedef struct NumVersion NumVersion;    /* Numeric version part of 'vers' resource */
  190. #if defined(powerc) || defined(__powerc)
  191. #pragma options align=reset
  192. #endif
  193.  
  194. #if defined(powerc) || defined (__powerc)
  195. #pragma options align=mac68k
  196. #endif
  197. struct VersRec {
  198.     NumVersion numericVersion;        /*encoded version number*/
  199.     short countryCode;                /*country code from intl utilities*/
  200.     Str255 shortVersion;            /*version number string - worst case*/
  201.     Str255 reserved;                /*longMessage string packed after shortVersion*/
  202. };
  203. typedef struct VersRec VersRec;
  204. typedef VersRec *VersRecPtr, **VersRecHndl;
  205. #if defined(powerc) || defined(__powerc)
  206. #pragma options align=reset
  207. #endif
  208.  
  209.  
  210. #define Length(string) (*(unsigned char *)(string))
  211. #define Gestalt            GESTALT
  212. #define NewGestalt        NEWGESTALT
  213. #define ReplaceGestalt    REPLACEGESTALT
  214. #endif
  215. #endif
  216. #endif
  217.  
  218. #ifdef powerc
  219. #define FlushInstructionCache()
  220. #endif
  221.  
  222. typedef Rect    (*PositionWndProcPtr)(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  223. typedef void    (*DrawControlProcPtr)(ControlHandle ctl);
  224. typedef short    (*GetButtonVariantProcPtr)(ControlHandle ctl, Boolean *stop);
  225.  
  226.  
  227. #if defined(powerc) || defined (__powerc)
  228. #pragma options align=mac68k
  229. #endif
  230. typedef struct PFSSpec {
  231.     FSSpec    fss;
  232.     Str31    volName;
  233. } PFSSpec;
  234. typedef PFSSpec *PFSSpecPtr;
  235. #if defined(powerc) || defined(__powerc)
  236. #pragma options align=reset
  237. #endif
  238.  
  239. typedef Boolean    (*TrackControlProcPtr)(ControlHandle ctl, short part, EventRecord *event);
  240. typedef void    (*ScrollProcPtr)(ControlHandle ctl, short part, short oldVal, short newVal);
  241. typedef struct ControlStyleInfo {
  242.     short                ctlID;
  243.     TrackControlProcPtr    trackProc;
  244.     ScrollProcPtr        scrollProc;
  245.     short                hArrowVal;
  246.     short                vArrowVal;
  247.     short                hPageVal;
  248.     short                vPageVal;
  249.     DrawControlProcPtr    drawControl;
  250.     short                fontSize;
  251.     Style                fontStyle;
  252.     Str32                font;
  253.     Str63                keyEquivs;
  254.     Str255                balloonHelp;
  255. } ControlStyleInfo;
  256. typedef ControlStyleInfo *ControlStyleInfoPtr;
  257.  
  258.  
  259.  
  260. /*-----------------------------------------------------------------------------------------
  261.     Handy Macros/inlines
  262. -----------------------------------------------------------------------------------------*/
  263. #ifdef false                                        /* The c++ stuff is turned OFF!!! */
  264.  
  265. inline Point* TopLeft(Rect& r)                        /* provide access to rect.topLeft  */
  266. {    return (Point*)(&r.top); }
  267.  
  268. inline Point* BotRight(Rect& r)                        /* provide access to rect.botRight  */
  269. {    return (Point*)(&r.bottom); }
  270.  
  271. inline short HiWrd(long aLong)                        /* return the hi word of a long */
  272. {    return ((aLong >> 16) & 0xFFFF); }
  273.  
  274. inline short LoWrd(long aLong)                        /* return the lo word of a long */
  275. {    return (aLong & 0xFFFF); }
  276.  
  277. inline void SETPT(Point *pt,short h,short v)
  278. {    (*pt).h = h; (*pt).v = v); }
  279.  
  280. inline void SETRECT(Rect *r,short left,short top,short right,short bottom)
  281. {    SETPT(TopLeft(*r), left, top); SETPT(BotRight(*r), right, bottom); }
  282.  
  283. /* 
  284.  *    Useful functions for testing gestalt attribute responses
  285.  *
  286.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  287.  *    BTstQ which simply returns a non-zero value if the bit is set which
  288.  *    means the result could get lost if assigned to a short, for example.
  289.  *
  290.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  291.  *    bitnbr = 0 is the least significant bit.
  292.  */
  293. inline short BTstBool(arg, bitnbr)    
  294. {    return ((arg >> bitnbr) & 1); }
  295.  
  296. inline long BTstQ(arg, bitnbr)
  297. {    return (arg & (1 << bitnbr)); }
  298.  
  299. #else
  300.  
  301.  
  302. #ifndef THINK_C
  303. #define QD(whatever) (qd.##whatever)
  304. #else
  305. #define QD(whatever) (whatever)
  306. #endif
  307.  
  308.  
  309. #define TopLeft(r)        (* (Point *) &(r).top)
  310. #define BotRight(r)        (* (Point *) &(r).bottom)
  311. #define HiWrd(aLong)    (((aLong) >> 16) & 0xFFFF)
  312. #define LoWrd(aLong)    ((aLong) & 0xFFFF)
  313. #define MIN(a, b) ((a) < (b) ? (a) : (b) )
  314. #define MAX(a, b) ((a) > (b) ? (a) : (b) )
  315. #define SETPT(pt, x, y)    (*(pt)).h = (x); (*(pt)).v = (y)
  316. #define SETRECT(r, left, top, right, bottom)    \
  317.                         SETPT(&TopLeft(*(r)), (left), (top)); \
  318.                         SETPT(&BotRight(*(r)), (right), (bottom))
  319.  
  320. #define offsetof(structure,field) ((unsigned long)&((structure *) 0)->field)
  321.  
  322. /* 
  323.  *    Useful macros for testing gestalt attribute responses
  324.  *
  325.  *    BTstBool returns a true boolean value (0 or 1), but is slower than:
  326.  *    BTstQ which simply returns a non-zero value if the bit is set which
  327.  *    means the result could get lost if assigned to a short, for example.
  328.  *
  329.  *    arg is any integer value, bitnbr is the number of the bit to be tested.
  330.  *    bitnbr = 0 is the least significant bit.
  331.  */
  332. #define BTstBool(arg, bitnbr)    ((arg >> bitnbr) & 1)
  333. #define BTstQ(arg, bitnbr)        (arg & (1 << bitnbr))
  334.  
  335. #endif
  336.  
  337. /*-----------------------------------------------------------------------------------------
  338.     Global variables
  339. -----------------------------------------------------------------------------------------*/
  340. /*    The following global variables are initialized by StardardInitialization to
  341.  *    define the environnment.  This used to be a single SysEnvRec, but now,
  342.  *    all those variables defined in a SysEnvRec can be returned by Gestalt
  343.  *    (except sysVRefNum; see FindSysFolder).  Note that all the variables
  344.  *    below will be correctly initialized whether Gestalt is available or not;
  345.  *    the Gestalt glue handles this.
  346.  */
  347.  
  348. extern ModalFilterUPP    gAlertFilterUPP;
  349. extern ModalFilterUPP    gKeyEquivFilterUPP;
  350.  
  351. extern short            gMachineType;            /* which machine this is */
  352. extern short            gSystemVersion;            /* System version number */
  353. extern short            gProcessorType;            /* which CPU this is */
  354. extern Boolean            gHasFPU;                /* true if machine has an FPU */
  355. extern short            gQDVersion;                /* major QD version #; 0 for original, 
  356.                                                     1 for color QD, 2 for 32-bit QD */
  357. extern short            gKeyboardType;            /* which type of keyboard is present */
  358. extern short            gAppleTalkVersion;        /* AppleTalk version number */
  359.         
  360. /*    These are also handled by Gestalt. gHasPMMU has no corresponding SysEnvRec
  361.  *    field, but it is handled by the glue, so we include it here for completeness.
  362.  *    gAUXVersion will be initialized with Gestalt if present, but correctly
  363.  *    set even if Gestalt is not available
  364.  */
  365. extern Boolean            gHasPMMU;                /* true if machine has a PMMU or equivalent */
  366. extern short            gAUXVersion;            /* major A/UX version number (0 if not present) */
  367.  
  368. /*    
  369.  *    gHasWaitNextEvent is set to TRUE if the Macintosh we are running on has
  370.  *    WaitNextEvent implemented. We can use this in our main event loop to
  371.  *    determine whether to call WaitNextEvent or GetNextEvent.
  372.  */
  373. extern Boolean            gHasWaitNextEvent;
  374.  
  375. /*
  376.  *    gAppResRef is the application’s resource file reference. I need to save
  377.  *    this since I can open other resource files. The current resource file is
  378.  *    always gAppResRef unless I momentarily set it to another file to read its
  379.  *    resources, and then immediately restore it back.
  380.  */
  381. extern short            gAppResRef;
  382.  
  383. /*
  384.  *    gInBackground is maintained by our osEvent handling routines. Any part of
  385.  *    the program can check it to find out if it is currently in the background.
  386.  */
  387. extern Boolean            gInBackground;            /* maintained by StandardInitialization
  388.                                                       and DoEvent */
  389.                                                       
  390. /*
  391.  *    gAppName holds the name of the application that's running. You can use if
  392.  *    for any purpose you'd like. It is also used by StandardAbout if it can't
  393.  *    find a string to use for the application name in a resource, so make sure
  394.  *    you call InitForStandardAbout if you are going to call StandardAbout. If you
  395.  *    call StandardInitialization, this is done for you.
  396.  */
  397. extern Str255            gAppName;
  398.  
  399. /*
  400.  *    gSignature holds the creator signature for the running application. It follows the
  401.  *    same rules as those for gAppName.
  402.  */
  403. extern OSType            gSignature;
  404.  
  405. /*
  406.  *    Initial values of these global variables are set to zero or FALSE by MPW's 
  407.  *    runtime initialization routines.  If the Utilities initialization routines
  408.  *    have been properly called, then gUtilitiesInited will be true.  If it is
  409.  *    not true, then the values of the above global variables are invalid.
  410.  */
  411. extern Boolean            gUtilitiesInited;
  412.  
  413. /*
  414.  *    These are global UniversalProcPtrs for AlertFilter() and KeyEquivFilter()
  415.  *    These are always initialized.
  416.  */
  417. extern ModalFilterUPP    gAlertFilterUPP;
  418. extern ModalFilterUPP    gKeyEquivFilterUPP;
  419.  
  420. extern GetButtonVariantProcPtr    gGetButtonVariant;
  421. /*
  422.  *    Use this global to add to or override the GetButtonVariant function.  There there
  423.  *    are other controls that you would like to automatically behave like check boxes
  424.  *    and radio buttons, write a function that returns the correct variant, given the
  425.  *    control, and then set this global procPtr to it.
  426.  */
  427.  
  428. /*-----------------------------------------------------------------------------------------
  429.     Interface to routines
  430. -----------------------------------------------------------------------------------------*/
  431.  
  432. #ifdef __cplusplus
  433. extern "C" {
  434. #endif
  435.  
  436. Rect        SetWindowPlacementRect(Rect *rct);
  437.             /* Set the window placement rect.  This rect overrides normal window positioning
  438.                in favor of the rect passed in.  For reference, the function also returns the
  439.                old window placement rect.  If nil is passed in for the new rect, then no
  440.                change to the positioning rect is made.  The old rect is still returned. */
  441.  
  442. short        CenteredAlert(short alertID, WindowPtr relatedWindow, ModalFilterUPP filter);
  443.             /* Given an Alert ID and a related window pointer, this routine will center
  444.                the alert on the same device as the related window.  If the related
  445.                window pointer is nil, then the alert will be centered on the device
  446.                that the alert would normally be placed if Alert was called directly. */
  447.  
  448. void        CenterRectInRect(Rect outerRect, Rect *innerRect);
  449.             /* Given two rectangles, this routine centers the second one within the first. */
  450.  
  451. Rect        CenterWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  452.             /* Given a window pointer and a related window pointer, this routine will
  453.                center the window on the same device as the related window.  If the
  454.                related window pointer is nil, then the window will be centered on the
  455.                device that the window already is.
  456.                WARNING: This routine may move or purge memory. */
  457.  
  458. void        CloseAnyWindow(WindowPtr window);
  459.             /* Closes the indicated window.  Does the right thing, taking into account
  460.                that the window may belong to a DA.
  461.                WARNING: An application window is closed via a CloseWindow call.  Use
  462.                            this call when you want to keep the storage for the window
  463.                         record.  (Compare against DisposeAnyWindow.) */
  464.  
  465. void        DisposeAnyWindow(WindowPtr window);
  466.             /* Disposes of the indicated window.  Does the right thing, taking into account
  467.                that the window may belong to a DA.
  468.                WARNING: An application window is closed via a DisposeWindow call.  Use
  469.                            this call when you want to free up the storage for the window
  470.                         record.  (Compare against CloseAnyWindow.) */
  471.  
  472. void        DeathAlert(short errResID, short errStringIndex);
  473.             /* Display an alert that tells the user an error occurred, then exit the
  474.                program. This routine is used as an ultimate bail-out for serious errors
  475.                that prohibit the continuation of the application. */ 
  476.  
  477. void        DeathAlertMessage(short errResID, short errStringIndex, short message);
  478.  
  479. void        ErrorAlert(short errResID, short errStringIndex);
  480.  
  481. void        ErrorAlertMessage(short errResID, short errStringIndex, short message);
  482.  
  483. OSErr        FindSysFolder(short *foundVRefNum, long *foundDirID);
  484.             /* FindSysFolder returns the (real) vRefNum, and the DirID of the current
  485.                system folder.  It uses the Folder Manager if present, otherwise
  486.                it falls back to SysEnvirons.  It returns zero on success, otherwise
  487.                a standard system error. */
  488.  
  489. Handle        GetAppIndResource(ResType theType, short index, OSErr *err);
  490.             /* GetAppIndResource gets a resource from the application's res file by index */
  491.  
  492. Handle        GetAppNamedResource(ResType theType, StringPtr name, OSErr *err);
  493.             /* GetAppNamedResource gets a resource from the application's res file by name */
  494.  
  495. Handle        GetAppResource(ResType theType, short theID, OSErr *err);
  496.             /* GetAppResource gets a resource from the application's res file by resource ID */
  497.  
  498. short        GetAUXVersion( void);
  499.             /* getAUXVersion -- Checks for the presence of A/UX by whatever means is
  500.                appropriate.  Returns the major version number of A/UX (i.e. 0 if A/UX 
  501.                is not present, 1 for any 1.x.x version 2 for any 2.x version, etc.
  502.                This code should work for all past, present and future A/UX systems. */
  503.  
  504. short        GetButtonVariant(ControlHandle ctl);
  505.                 /* This function returns which kind of button the control is.  This does more
  506.                 ** than GetCVariant in that it makes sure that the control is actually a
  507.                 ** button.  It does this by comparing the defProc against the known defProc
  508.                 ** for the various button types.  For 7.0, there is only one defProc for all
  509.                 ** variants, but for pre-7.0, there is one defProc value for each variant.
  510.                 ** The method below handles either case. */
  511.  
  512. OSErr        SimpleCanDialog(void);
  513.             /* Check to see if dialogs are allowed.  They may not be if AppleScript is
  514.                running the show. */
  515.  
  516. DialogPtr    GetCenteredDialog(short id, DialogPtr storage, WindowPtr relatedWindow, WindowPtr behind);
  517.             /* Given a dialog ID and a related window pointer, this routine will center
  518.                the dialog on the same device as the related window.  If the related
  519.                window pointer is nil, then the dialog will be centered on the device
  520.                that the dialog would normally be placed if GetNewDialog was called. */
  521.  
  522. WindowPtr    GetCenteredWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  523.                               WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  524.             /* Given a window ID and a related window pointer, this routine will center
  525.                the window on the same device as the related window.  If the related
  526.                window pointer is nil, then the window will be centered on the device
  527.                that the window would normally be placed if GetNewWindow was called.  The
  528.                function is also passed the sizeInfo rect, which holds min and max size
  529.                information for the window.  (See GetSomeKindOfWindow.) */
  530.  
  531. Boolean     GetCheckOrRadio(DialogPtr dlgPtr, short itemNo);
  532.  
  533. long        GetGestaltResult(OSType gestaltSelector);
  534.             /* GetGestaltResult returns the result value from Gestalt for the specified
  535.                selector.  If Gestalt returned an error GetGestaltResult returns zero.  Use 
  536.                of this function is only cool if we don't care whether Gestalt returned an 
  537.                error.  In many casesyou may need to know the exact Gestalt error code so 
  538.                then this routine would be inappropriate. */
  539.  
  540. Point        GetGlobalMouse(void);
  541.             /* Returns the location of the mouse in local coordinates. It does this by
  542.                calling OSEventAvail(). */ 
  543.  
  544. Point        GetGlobalTopLeft(WindowPtr window);
  545.             /*     Given a window, this will return the top left point of the window’s port in
  546.                   global coordinates. Something this doesn’t include, is the window’s drag
  547.                   region (or title bar). This returns the top left point of the window’s
  548.                   content area only. */
  549.  
  550. long        GetKFreeSpace(short vRefNum);
  551.  
  552. Rect        GetMainScreenRect(void);
  553.  
  554. GDHandle    GetRectDevice(Rect globalRect);
  555.             /* Find the greatest overlap device for the given global rectangle.
  556.             ** This function assumes that you have a system that GDHandle can happen.
  557.             ** If you call this function on other QuickDraws, you will crash. */
  558.  
  559. Rect        GetRectDeviceRect(Rect globalRect);
  560.             /* Find the rect of the greatest overlap device for the given global rect. */
  561.  
  562. WindowPtr    GetSomeKindOfWindow(PositionWndProcPtr whatKind, short windID, Ptr storage,
  563.                                 Boolean vis, WindowPtr relatedWindow, WindowPtr behind,
  564.                                 Boolean inColor, Rect sizeInfo, long refCon);
  565.             /* Given a window positioning procedure pointer, a window ID and a window
  566.                pointer the window relates to, this function open a new window by either
  567.                a NewCWindow or a NewWindow call, depending on the value of inColor.  The
  568.                window will be opened invisible, independent of what the resource says.
  569.                Once the window is opened successfully, the positioning procedure is
  570.                called.  The positioning procedure is passed a pointer to the just-opened
  571.                invisible window,a pointer to the related window, and the sizeInfo rect.
  572.                The sizeInfo rect holds the minimum size in the upper-left point, and the
  573.                max size in the lower-left point.  It is up to the positioning procedure
  574.                to move the invisible window to the correct location on the correct device.
  575.                Once the positioning procedure returns, the window will be made visible if
  576.                so indicated by the resource. */
  577.  
  578. WindowPtr    GetStaggeredWindow(short id, Ptr storage, Boolean vis, WindowPtr relWindow,
  579.                                WindowPtr behind, Boolean inColor, Rect sizeInfo, long refCon);
  580.             /* Given a window ID and a window pointer the window relates to, this function
  581.                will stagger the window’s rectangle before showing it on the proper screen.
  582.                This follows the Apple Human Interface Guidelines for where to place a
  583.                staggered window on the screen.  If the window is not closely associated
  584.                with another window, pass a nil for the window pointer of the related
  585.                window.  If you pass a nil, the window is simply displayed where the
  586.                resource would indicate.  The function is also passed the sizeInfo rect, which
  587.                holds min and max size information for the window.  (See GetSomeKindOfWindow.) */
  588.  
  589. void        GetSystemInfo(void);
  590.             /* This sets up some global variables for use by the utilities package and
  591.                your application.  If you call StandardInitialization, you don't need to
  592.                call this, as it will do it for you. */ 
  593.  
  594. TrapType    GetTrapType(short theTrap);
  595.             /* Returns the type (OSType or ToolType) of the trap. It does this by checking
  596.                the bits of the trap word. */ 
  597.  
  598. Rect        GetWindowContentRect(WindowPtr window);
  599.             /* Given a window pointer, return the global rectangle that encloses the
  600.                content area of the window. */
  601.  
  602. short        GetWindowCount(Boolean includeDAs, Boolean includeDLOGs, Boolean includeInvisibles);
  603.             /* This procedure counts the number of windows in the application plane.  You have the
  604.                choices of also counting DAs, DLOGs, and invisible windows in this count. */
  605.  
  606. GDHandle    GetWindowDevice(WindowPtr window);
  607.             /* Find the greatest overlap device for the given window. */
  608.  
  609. Rect        GetWindowDeviceRect(WindowPtr window);
  610.             /* Given a window pointer, find the device that contains most of the window
  611.                and return the device's bounding rectangle. */
  612.  
  613. Rect        GetWindowDeviceRectNMB(WindowPtr window);
  614.             /* Given a window pointer, find the device that contains most of the window
  615.                and return the device's bounding rectangle.  If this device is the main
  616.                device, then remove the menubar area from the rectangle. */
  617.  
  618. Rect        GetWindowStructureRect(WindowPtr window);
  619.             /* This procedure is used to get the rectangle that surrounds the entire
  620.                structure of a window.  This is true whether or not the window is visible.
  621.                If the window is visible, then it is a simple matter of using the bounding
  622.                rectangle of the structure region.  If the window is invisible, then the
  623.                strucRgn is not correct.  To make it correct, then window has to be moved
  624.                way off the screen and then made visible.  This generates a valid strucRgn,
  625.                although it is valid for the position that is way off the screen.  It still
  626.                needs to be offset back into the original position.  Once the bounding
  627.                rectangle for the strucRgn is obtained, the window can then be hidden again
  628.                and moved back to its correct location.  Note that ShowHide is used,
  629.                instead of ShowWindow and HideWindow.  HideWindow can change the plane of
  630.                the window.  Also, ShowHide does not affect the hiliting of windows. */
  631.   
  632. void        GlobalToLocalRect(Rect *aRect);
  633.  
  634. void        InitToolBox(void);
  635.  
  636. Boolean        IsAppWindow(WindowPtr window);
  637.             /* Returns TRUE if the windowKind of the window is greater than or equal to
  638.                userKind. If it is less, or the window is NIL, then return FALSE. */ 
  639.  
  640. Boolean        IsDAWindow(WindowPtr window);
  641.             /* Returns TRUE if the windowKind of the window is less than zero. If not, or
  642.                the window is NIL, then return FALSE. */ 
  643.  
  644. Boolean        IsScrollBar(ControlHandle ctl);
  645.             /* Returns TRUE if the control is a scrollbar. */
  646.  
  647. void        LocalToGlobalRect(Rect *aRect);
  648.  
  649. char        LockHandleHigh(Handle theHandle);
  650.             /* Does a MoveHHi on the handle and then locks it.  Also, the original state
  651.                of the handle is returned, so you can keep it and set the handle back to it's
  652.                original state with a HSetState call. */
  653.  
  654. short        NumToolboxTraps(void);
  655.             /* Determines the size of the Tool trap table. It does this by sampling a
  656.                couple of trap locations and seeing which, if any are Unimplemented. */ 
  657.  
  658. void        OutlineControl(ControlHandle button);
  659.  
  660. void         OutlineDialogItem(DialogPtr dlgPtr, short item);
  661.  
  662. void        PositionRectInRect(Rect outerRect, Rect *innerRect, Fixed horzRatio, Fixed vertRatio);
  663.             /* Given two rectangles, this routine positions the second within the first one
  664.                so that the it maintains the spacing specified the the horzRatio and vertRatio
  665.                parameters. In other words, to center an inner rectangle hoizontally, but
  666.                have its center be 1/3 from the top of the outer rectangle, call this
  667.                routine with horzRatio = FixRatio(1, 2), vertRatio = FixRatio(1, 3). */
  668.  
  669. void        PullApplicationToFront(void);
  670.             
  671. void        SelectButton(ControlHandle button);
  672.             /* Given the button control handle, this will cause the button to look as if it
  673.                has been clicked in. This is nice to do for the user if they type return or
  674.                enter to select the default item. */
  675.  
  676. void        SetCheckOrRadioButton(DialogPtr dlgPtr, short itemNo, short state);
  677.  
  678. Rect        StaggerWindow(WindowPtr window, WindowPtr relatedWindow, Rect sizeInfo);
  679.             /* This algorithm for staggering windows does quite a good job.  It also is
  680.                quite gnarly.  Here's the deal:
  681.                There are pre-designated positions that we will try when positioning a
  682.                window.  These slots will be tried from the upper-left corner towards the
  683.                lower-right corner.  If there are other windows in that slot, then we will
  684.                consider that slot taken, and proceed to the next slot.  A slot is
  685.                determined to be taken by checking a point with a slop area.  This slop
  686.                area is diamond-shaped, not simply rectangular.  If there is no other
  687.                visible window with an upper-left corner within the slopt diamond, then
  688.                we are allowed to position our window there.
  689.                The above rule holds true unless this forces the window to be partly
  690.                off the screen.  If the window ends up partly off the screen, then we give
  691.                up and just put it in the first slot. */
  692.  
  693. void        StandardAbout(short appNameStringID);
  694.             /* Shows a standard about box with the name of the application, its version
  695.                number, a copyright notice, and DTS credits. Most of this information is
  696.                taking from a standard DITL and the application’s 'vers' resource. The name
  697.                of the application is taken either from the 'STR ' resource passed in to
  698.                this routine, or from GetAppParms() if that resource doesn’t exist, or you
  699.                pass in -1. */ 
  700.  
  701. void        StandardInitialization(short callsToMoreMasters);
  702.             /* Initializes “gInBackGround” to FALSE. Makes the following InitXXX calls:
  703.                InitGraf(), InitFonts(), InitWindows(), InitMenus(), TEInit(),
  704.                InitDialogs(), InitCursor(). Brings application to front with 3 EventAvail
  705.                calls. Calls SysEnvirons to initialize “gMac”. Calls TrapExists() to
  706.                initialize “gHasWaitNextEvent”. */ 
  707.    
  708. void        StandardMenuSetup(short MBARID, short AppleMenuID);
  709.             /* Installs and draws the menus indicated by 'MBAR'(MBARID). Adds DA’s to the
  710.                menu indicated by AppleMenuID by calling AddResMenu. If the menuBar cannot
  711.                be created, the alert specified by rDeathAlert is displayed. */   
  712.  
  713. void        InsertHierMenus(MenuHandle menu);
  714.             /* Look through the menu items for hierarchical references.  For each found,
  715.                insert the hierarchical menu, and then recursively search that menu for
  716.                hierarchical menus.  This function is called by StandardMenuSetup so that
  717.                all hierarchical menus are inserted at application startup time. */
  718.  
  719. void         ToggleCheck(DialogPtr dlgPtr, short cChkItem);
  720.  
  721. Boolean        TrapExists(short theTrap);
  722.                 /* Returns TRUE if the trap exists (i.e., it’s callable without getting DS
  723.                    error 12) */ 
  724.  
  725. Boolean        WhichControl(Point mouseLoc, long when, WindowPtr window, ControlHandle *ctlHit);
  726.                 /* Returns which visible control mouseLoc is within, independent of
  727.                    the state of the control.  Scrollbars that are inactive are not
  728.                    found by FindControl. */
  729.  
  730. void        ZoomToWindowDevice(WindowPtr window, short maxWidth, short maxHeight,
  731.                                short zoomDir, Boolean front);
  732.  
  733.  
  734.  
  735. pascal Boolean    AlertFilter(DialogPtr dlg, EventRecord *event, short *item);
  736. /* The alert filter makes sure that that the outline for the button gets
  737. ** redrawn.  This is important if balloon help is on, as the balloon window
  738. ** can overlap the outline of the button and leave a portion of it erased. */
  739.  
  740. pascal Boolean    KeyEquivFilter(DialogPtr dlg, EventRecord *event, short *item);
  741. /* The key equivalent filter allows you to assign key equivalents to dialog
  742. ** items.  Each item can have as many key equivalents as you wish.  You can
  743. ** also specify the exact state of the modifiers that you will or won't allow.
  744. ** The key equivalent information is stored in the resource fork, so the
  745. ** key equivalents can be easily localized.
  746. ** This code expects the key equivalents to be in item #2, which is a StatText
  747. ** item that is located so the text is outside of the dialog.  This allows us
  748. ** to put key equivalent information in the resource fork, so the key
  749. ** equivalents are localizable.
  750. **
  751. ** An example save changes before closing or quitting res source with
  752. ** keyEquiv info would look like:
  753. **
  754. ** resource 'DITL' (rYesNoCancel, purgeable) {
  755. **     {
  756. **         {71, 315, 91, 367}, Button     { enabled, "Save" },
  757. **         {0, -1000, 20, 2},  StaticText { disabled,
  758. **             "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004" },
  759. **         {71, 80, 91, 162},  Button { enabled, "Don’t Save" },
  760. **         {71, 244, 91, 302}, Button { enabled, "Cancel" },
  761. **         {11, 78, 61, 366},  StaticText { disabled,
  762. **             "Save changes to the document “^0” before ^1?" },
  763. **         {11, 23, 43, 55},        Icon { disabled, 2 }
  764. **     }
  765. ** };
  766. **
  767. ** The document name would be the string for param #0.
  768. ** The text "closing" or "quitting" would be the string for param #1.
  769. **
  770. ** The keyEquiv entry is item #2, which has a rect that pushes it out of the
  771. ** dialog.  The string info is interpreted as to what the key/modifier combo
  772. ** is, and what dialog item it relates to.
  773. **
  774. ** A single key equiv entry is 8 characters.  Entries are separated by commas.
  775. **
  776. ** If the first character of an entry is an =, then the next character is the 
  777. ** key.  If the first character isn't an =, then the first two characters are 
  778. ** the hex value of the key.  (Ex:  =S or =s for save, 1B for ESC.)
  779. **
  780. ** If the key pressed is the same as the key value for any of the entries, then 
  781. ** the next two characters are the hex value for which modifiers to test.  This
  782. ** modifier test value is anded with the modifier.  The result is then compared 
  783. ** to the value of the next two hex digits.  If they are equal, then the 
  784. ** modifiers are correct, as well as the key.  If this is so, we have a winner.
  785. **
  786. ** "=S190001,=s190001,=D190003,=d190003,=.190104,1B190004"
  787. **
  788. ** The above string breaks down as follows:
  789. ** =S190001  =S  if event keypress is an S, check the modifier values
  790. **           19  check controlKey/optionKey/cmdKey
  791. **           00  all modifiers we are testing for should be false
  792. **           01  if above is true, keypress maps to item # 1
  793. ** =s190001  Same as =S, but lowercase
  794. ** =D190001  Same as =S, but maps to item #3
  795. ** =d190001  Same as =D, but lowercase
  796. ** =.190104  =.  if event keypress is a period, check the modifier values
  797. **           19  check controlKey/optionKey/cmdKey
  798. **           01  controlKey/optionKey should be false, cmdKey should be true
  799. **           04  if above is true, keypress maps to item # 4
  800. ** 1B190004  1B  if event keypress is an ESC, check the modifier values
  801. **           19  check controlKey/optionKey/cmdKey
  802. **           00  all modifiers we are testing for should be false
  803. **           04  if above is true, keypress maps to item # 4
  804. */
  805.  
  806. void            OffsetControl(ControlHandle ctl, short dx, short dy);
  807. /* This function is a convenient way to move a control a specified amount. */
  808.  
  809. void            DoDrawGrowIcon(WindowPtr window, Boolean horLine, Boolean verLine);
  810. /* This function draws the grow icon for the window in the specified manner.  You
  811. ** can clip out the horizontal or vertical line that is also drawn along with
  812. ** the grow icon, or you can have them draw. */
  813.  
  814. void            DoDrawControls(WindowPtr window, Boolean scrollBarsOnly);
  815. /* This function drawn all of the controls in a window, or just the scrollbar
  816. ** controls.  The reason for this function is that scrollbars are really
  817. ** tri-state, especially now with 7.0.  A scrollbar can be hilighted or not,
  818. ** or it can be drawn in a window that isn't the frontmost of the application
  819. ** plane.  DoDrawControls takes this third scrollbar state into consideration. */
  820.  
  821. void            DoDraw1Control(ControlHandle ctl, Boolean scrollBarsOnly);
  822. /* This function is where the work for scrollbar/control drawing is actually
  823. ** done.  DoDrawControls calls this function for each control in a window. */
  824.  
  825. ControlHandle    GetPopupCtlHandle(DialogPtr theDialog, short itemNum);
  826. /* GetPopupCtlHandle takes a dialog and its item number and (assuming it is a
  827. ** popup menu control) and returns the control handle for the popup. */
  828.  
  829. MenuHandle    GetPopupMenuHandle(ControlHandle popupCtl);
  830. /* GetPopupMenuHandle takes a popup control and returns the menu handle from
  831. ** the control. */
  832.  
  833. short    GetPopupCtlValue(DialogPtr theDialog, short popItem);
  834. /* GetPopupCtlValue returns value for the popup control. */
  835.  
  836. void    SetPopupCtlValue(DialogPtr theDialog, short popItem, short value);
  837. /* SetPopupCtlValue makes value the new value for the popup control. */
  838.  
  839. short    SmartInsMenuItem(MenuHandle theMenu, StringPtr theText, short section, short where);
  840. /* This is used to "intelligently" insert a menu item into a menu.  Pass it
  841. ** the menu to be modified, the text of the item being added, plus where the
  842. ** item is to be inserted.  The location to be inserted is described by two
  843. ** parameters:  section & where.
  844. **
  845. ** section:  Indicates which group of menu items you wish to add an item to.
  846. **           Menu item section 1 is all of the items before the first
  847. **           dividing line.  Menu item section 2 is all items after the
  848. **           first dividing line and before the second, and so on.  If you
  849. **           have no dividing lines, you have just 1 section so pass in 1.
  850. **
  851. ** where:    Indicates the item position relative to the section.  To add an
  852. **           item such that it is the first item in a section, pass in a 1.
  853. **           It will be added in front of the first item in the section.
  854. **
  855. **           NOTE:  You should never pass in a section or where parameter of 0.
  856. **
  857. ** Negative values for "where" are magic.  If where = kMenuItemTxtInsert, then
  858. ** it inserts the item alphabetically into the section.  A where of 
  859. ** kMenuItemNumInsert works the same as kMenuItemTxtInsert, except it treats
  860. ** the strings are numbers for comparison purposes.  If you want to add the
  861. ** item to the end of a section, use kMenuItemSectionEnd.
  862. **
  863. ** As a final goodie, SmartInsMenuItem returns the menu item # from the
  864. ** beginning of the menu, not section. */
  865.  
  866. short    CountMSections(MenuHandle theMenu);
  867. /* Return the number of menu sections.  The number of sections is equal to the
  868. ** number of dividing lines + 1. */
  869.  
  870. short    FindMenuItem(MenuHandle theMenu, StringPtr cmpTxt);
  871. /* Find the menu item number, given the text of the menu. */
  872.  
  873. OSErr    PersistFSSpec(PFSSpecPtr pfss);
  874. /* Do what is necessary to get an FSSpec to persist when saved to disk.  The parID
  875. ** will still be valid, along with the file name.  The part that isn't valid is
  876. ** the vRefNum.  This function converts the FSSpec's vRefNum to a volume name, or
  877. ** converts the volume name into a vRefNum.  An extended FSSpec is used.  The
  878. ** extension is, logically enough, a volume name.  If the FSSpec's vRefNum is non-0,
  879. ** then it fills in the volume name for that vRefNum.  If the vRefNum is 0, it then
  880. ** uses the volume name to generate a vRefNum.
  881. ** Prior to saving a PFSSpec to disk, call PersistFSSpec.  It will fill in the
  882. ** volume name.  After having read a PFSSpec from disk, set the vRefNum to 0 and
  883. ** then call PersistFSSpec.  It will fill in the vRefNum that corresponds to the
  884. ** volume name. */
  885.  
  886. StringPtr    PathNameFromDirID(long DirID, short vRefNum, StringPtr str);
  887. /* This function is straight out of tech note #238.  See this note for more info. */
  888.  
  889. void    InitQuickTime(void);
  890. /* Call this to generically initialize QuickTime.  It sets two globals:
  891. **     gQTVersion                    QuickTime version (0 means not available).
  892. **     gMovieControllerComponent    QuickTime movie controller component reference. */
  893.  
  894. RgnHandle    LocalScreenDepthRegion(short depth);
  895. /* This function serves the same purpose as ScreenDepthRegion(), except that it localizes the
  896. ** region to the current port.  If the global gScreenPort is not nil, then it localizes to that
  897. ** port.  The reason for this is that the currentl port may be an offscreen port.  If it is
  898. ** offscreen, then it doesn't have a direct relationship to the screen. */
  899.  
  900. void    MoveStyledControl(ControlHandle ctl, short xloc, short yloc);
  901. void    SizeStyledControl(ControlHandle ctl, short xsize, short ysize);
  902. void    SetStyledCtlValue(ControlHandle ctl, short value);
  903. void    ShowStyledControl(ControlHandle ctl);
  904. void    HideStyledControl(ControlHandle ctl);
  905. void    UseControlStyle(ControlHandle ctl);
  906. void    SetStyledCTitle(ControlHandle ctl, StringPtr title);
  907. short    GetControlID(ControlHandle ctl);
  908. Boolean    GetControlStyle(ControlHandle ctl, ControlStyleInfoPtr cinfo);
  909. OSErr    SetControlStyle(ControlHandle ctl, ControlStyleInfoPtr cinfo);
  910. void    SetTrackControlProc(ControlHandle ctl, TrackControlProcPtr proc);
  911. Boolean    ControlKeyEquiv(WindowPtr window, EventRecord *event, ControlHandle *retCtl, StringPtr defaultEquivs);
  912.     /* These functions are for extending the functionality of controls.  The structure
  913.     ** ControlStyleInfo is appended to a control, immediately after the title field.
  914.     ** This is valid, as the only control manager function that changes the size of a
  915.     ** control is SetCTitle.  (The function SetStyledCTitle is used instead to maintain
  916.     ** the control style info.) */
  917.  
  918.  
  919.  
  920. #ifdef __cplusplus
  921. }
  922. #endif
  923.  
  924. #endif
  925.