Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Source/SettingsUtils.c
#include <Types.h> |
#include <Resources.h> |
#include "SettingsUtils.h" |
/*********************************************************************************/ |
/* settings utils */ |
enum { |
settingsType = 'SFpf', |
settingsID = -4080 |
}; |
void SaveSettings(settingsHandle theSettings) |
{ |
Str255 foo; |
if (!theSettings) { |
DebugStr("\pBogus settings handle in SaveSettings."); |
return; |
} |
ChangedResource((Handle)theSettings); |
if (ResError()!=noErr) DebugStr("\pError updating resource?!"); |
UpdateResFile(CurResFile()); |
if (ResError()!=noErr) DebugStr("\pError updating resFile?!"); |
} |
settingsHandle RetrieveSettings(void) |
{ |
Handle oldSettings = GetResource(settingsType,settingsID); |
if (!oldSettings) { |
Handle theSettings = NewHandleClear(sizeof(settings)); |
Str255 foo; |
foo[0] = 0; |
// DebugStr("\pAdding new settings resource"); |
AddResource(theSettings,settingsType,settingsID,foo); |
if (ResError()!=noErr) DebugStr("\pError adding new resource?!"); |
UpdateResFile(CurResFile()); |
if (ResError()!=noErr) DebugStr("\pError updating resFile w/new?!"); |
oldSettings = theSettings; |
} |
if (GetHandleSize(oldSettings)!=sizeof(settings)) { |
DebugStr("\pBad Handle Size in RetrieveSettings"); |
return 0; |
} |
return((settingsHandle)oldSettings); |
} |
void SaveItemNumber(short item) |
{ |
settingsHandle theSettings = RetrieveSettings(); |
(**theSettings).selectedItemNumber = item; |
SaveSettings(theSettings); |
} |
short GetSavedItemNumber(void) |
{ |
settingsHandle theSettings = RetrieveSettings(); |
return((**theSettings).selectedItemNumber); |
} |
void SaveRadioOption(Boolean state) |
{ |
settingsHandle theSettings = RetrieveSettings(); |
(**theSettings).isRadioOptionOn = state; |
SaveSettings(theSettings); |
} |
Boolean GetSavedRadioOption(void) |
{ |
settingsHandle theSettings = RetrieveSettings(); |
return((**theSettings).isRadioOptionOn); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-03-26