home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CPrefsFile & Friends 1.0 / CGlobalPrefs.c next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  1.9 KB  |  85 lines  |  [TEXT/KAHL]

  1. /*
  2.  * CGlobalPrefs.c
  3.  * A sample subclass of CPrefsFile.
  4.  *
  5.  * by Jamie McCarthy
  6.  * Internet: k044477@kzoo.edu            AppleLink: j.mccarthy
  7.  * Telephone:  800-421-4157 or US 616-665-7075 (9:00-5:00 Eastern time)
  8.  *
  9.  * This subclass of CPrefsFile stores the preferences handle in a global
  10.  * variable.  The rest of the program accesses it directly;  for example,
  11.  * to get the font size, your code could read
  12.  *
  13.  *         short myFontSize;
  14.  *         myFontSize = (**gPrefs).fontSize;
  15.  *
  16.  * ...and to get the font name, you might use
  17.  *
  18.  *         Str63 myFontName;
  19.  *         CopyPString(& (**gPrefs).fontName, myCopyOfTheFontName);
  20.  *
  21.  * The advantage of not going the "pure OOP" route is that you don't
  22.  * have to type in every access method you're ever going to use.
  23.  *
  24.  * The disadvantage is that you may have to put special accessing code
  25.  * into your program anyway.  For example, the code to get the font name
  26.  * above.  Also note that the "defaultOverwriteExistingFiles" field,
  27.  * while declared as "BOOL" in the ResEdit template, must be a "short"
  28.  * in C!  Types.h defines "Boolean" as "unsigned char", but ResEdit
  29.  * reserves 16 bits for a "BOOL"--you don't want to mix those up.
  30.  * And since ResEdit stores "0x0100" for TRUE, you'll probably want to
  31.  * test with "( (**gPrefs).defaultOverwriteExistingFiles != FALSE )".
  32.  *
  33.  */
  34.  
  35.  
  36.  
  37. /********************************/
  38.  
  39. #include "CGlobalPrefs.h"
  40.  
  41. /********************************/
  42.  
  43. #include <TBUtilities.h>
  44.  
  45. /********************************/
  46.  
  47. #define globalStrsID (1024)
  48.  
  49. /********************************/
  50.  
  51. globalPrefsHndl gPrefs;
  52.  
  53. /********************************/
  54.  
  55.  
  56.  
  57. void CGlobalPrefs::IGlobalPrefs(void)
  58. {
  59.     inherited::IPrefsFile(globalStrsID, 'PREF', TRUE);
  60. }
  61.  
  62.  
  63.  
  64. void CGlobalPrefs::assignToPrefsHndl(Handle theHandle)
  65. {
  66.     gPrefs = (globalPrefsHndl) theHandle;
  67. }
  68.  
  69.  
  70.  
  71. Handle CGlobalPrefs::valueOfPrefsHndl(void)
  72. {
  73.     return (Handle) gPrefs;
  74. }
  75.  
  76.  
  77.  
  78. short CGlobalPrefs::sizeOfPrefs(void)
  79. {
  80.     return sizeof(globalPrefsStruct);
  81. }
  82.  
  83.  
  84.  
  85.