home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Project: POV-Ray
-
- Version: 3
-
- File: AppPrefs.c
-
- Description: Application preferences dialog and handlers
- ------------------------------------------------------------------------------
- Author:
- Eduard [esp] Schwan
- ------------------------------------------------------------------------------
- from Persistence of Vision(tm) Ray Tracer
- Copyright 1996 Persistence of Vision Team
- ------------------------------------------------------------------------------
- NOTICE: This source code file is provided so that users may experiment
- with enhancements to POV-Ray and to port the software to platforms other
- than those supported by the POV-Ray Team. There are strict rules under
- which you are permitted to use this file. The rules are in the file
- named POVLEGAL.DOC which should be distributed with this file. If
- POVLEGAL.DOC is not available or for more info please contact the POV-Ray
- Team Coordinator by leaving a message in CompuServe's Graphics Developer's
- Forum. The latest version of POV-Ray may be found there as well.
-
- This program is based on the popular DKB raytracer version 2.12.
- DKBTrace was originally written by David K. Buck.
- DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
- ------------------------------------------------------------------------------
- Change History:
- 941230 [esp] Created
- 960210 [esp] 3.0b5, added KeepGoingOnErrors
- 960621 [esp] 3.0b7, Changed Prefs file Creator type back to POV-Ray <bug-Steve Luce>
- ==============================================================================*/
-
- #define APPPREFS_C
-
- /*==== my header =====*/
- #include "AppPrefs.h"
- #include "ScreenUtils.h"
- #include "DialogUtils.h" // DisplayModalDialog
-
-
- // Application prefs file type
- #define kPrefsFileType 'PREF'
-
-
- /*==== Macintosh-specific headers ====*/
- #include <errors.h> /* dupFNErr, etc */
- #include <files.h> /* fsspec */
- #include <folders.h> /* konsystemdisk */
- #include <TextUtils.h> /* GetIndString */
- #include <Resources.h>
- #include <Sound.h> // soundListRsrc
- #include <gestalt.h> // gestaltFindFolderAttr
- #include <Processes.h> // GetProcessInformation
- #include <PPCToolBox.h> // PPCBrowser
-
- #include "volspaths.h" // pathnamefromdirid
- #include "stdfolder.h" // SF_PromptForFolder
-
-
-
- // ---------------------------------------------------------------------
-
- #define kDlogID_AppPrefs 2001
-
- //
- // POV-Ray Prefs Dialog items
- //
- #define kPU_AppThrottle 4
- #define kBT_ChooseSearchPath 5
- #define kST_SearchPath 6
- #define kCB_AutoTemplates 7
- #define kCB_ShowSplashScreen 8
- #define kCB_UseAppDefaultPrefs 9
- #define kPU_SoundsPopup 10
- #define kCB_AutoSaveImage 11
- #define kPU_AllDoneNotify 12
- #define kCB_ShutDownWhenDone 13
- #define kCB_AddCustomIcons 14
- #define kCB_KeepGoingOnErrors 15
-
-
-
- /*==== globals ====*/
- app_prefs_hdl_t gAppPrefs_h = NULL; // App prefs from prefs file
- file_prefs_hdl_t gDefltFilePrefs_h = NULL; // default file prefs from prefs file
- Boolean gUseAppDefaultPrefs = false; // True if overriding file prefs
- Boolean gShutDownWhenDone = false; // True if shutting down computer
-
- /*==== locals ====*/
- static short gAppPrefsRefNum = kRsrcFileClosed;
- static app_prefs_rec_t gOrigPrefs;
- static FSSpec gTempFSS;
-
-
- // ---------------------------------------------------------------------
- // Application Prefs accessors
-
- void APSet_TimeSlice(short newValue)
- {
- (**gAppPrefs_h).appThrottle = newValue;
- } // APSet_TimeSlice
-
- short APGet_TimeSlice(void)
- {
- return (**gAppPrefs_h).appThrottle;
- } // APSet_TimeSlice
-
-
- // ---------------------------------------------------------------------
- void APSet_AutoTemplates(Boolean newValue)
- {
- (**gAppPrefs_h).autoLoadTemplates = newValue;
- } // APSet_AutoTemplates
-
- Boolean APGet_AutoTemplates(void)
- {
- return (**gAppPrefs_h).autoLoadTemplates;
- } // APGet_AutoTemplates
-
-
- // ---------------------------------------------------------------------
- void APSet_AllDoneSoundID(short newValue)
- {
- (**gAppPrefs_h).allDoneSoundID = newValue;
- } // APSet_AllDoneSoundID
-
- short APGet_AllDoneSoundID(void)
- {
- return (**gAppPrefs_h).allDoneSoundID;
- } // APGet_AllDoneSoundID
-
-
- // ---------------------------------------------------------------------
- void APSet_AutoSaveImage(Boolean newValue)
- {
- (**gAppPrefs_h).autoSavePict = newValue;
- } // APSet_AutoSaveImage
-
- Boolean APGet_AutoSaveImage(void)
- {
- return (**gAppPrefs_h).autoSavePict;
- } // APGet_AutoSaveImage
-
-
- // ---------------------------------------------------------------------
- void APSet_AllDoneNotify(short newValue)
- {
- (**gAppPrefs_h).allDoneNotify = newValue;
- } // APSet_AllDoneNotify
-
- short APGet_AllDoneNotify(void)
- {
- return (**gAppPrefs_h).allDoneNotify;
- } // APGet_AllDoneNotify
-
-
- // ---------------------------------------------------------------------
- void APSet_UseAppDefaultPrefs(Boolean newValue)
- {
- (**gAppPrefs_h).useAppDefaultPrefs = newValue;
- // now actually switch which prefs to use
- if (newValue)
- gPrefs2Use_h = gDefltFilePrefs_h; // default file prefs
- else
- gPrefs2Use_h = gFilePrefs_h; // regular file prefs
- } // APSet_UseAppDefaultPrefs
-
- Boolean APGet_UseAppDefaultPrefs(void)
- {
- return (**gAppPrefs_h).useAppDefaultPrefs;
- } // APGet_UseAppDefaultPrefs
-
-
- // ---------------------------------------------------------------------
- void APSet_UseTempMem(Boolean newValue)
- {
- (**gAppPrefs_h).useTempMem = newValue;
- } // APSet_UseTempMem
-
- Boolean APGet_UseTempMem(void)
- {
- return (**gAppPrefs_h).useTempMem;
- } // APGet_UseTempMem
-
-
- // ---------------------------------------------------------------------
- void APSet_ShowSplashScreen(Boolean newValue)
- {
- (**gAppPrefs_h).showSplashScreen = newValue;
- } // APSet_ShowSplashScreen
-
- Boolean APGet_ShowSplashScreen(void)
- {
- return (**gAppPrefs_h).showSplashScreen;
- } // APGet_ShowSplashScreen
-
- // ---------------------------------------------------------------------
- void APSet_AddCustomIcons(Boolean newValue)
- {
- (**gAppPrefs_h).addCustomIcons = newValue;
- } // APSet_AddCustomIcons
-
- Boolean APGet_AddCustomIcons(void)
- {
- return (**gAppPrefs_h).addCustomIcons;
- } // APGet_AddCustomIcons
-
-
- // ---------------------------------------------------------------------
- void APSet_ShutDownWhenDone(Boolean newValue)
- {
- gShutDownWhenDone = newValue;
- } // APSet_ShutDownWhenDone
-
- Boolean APGet_ShutDownWhenDone(void)
- {
- return gShutDownWhenDone;
- } // APGet_ShutDownWhenDone
-
-
- // ---------------------------------------------------------------------
- void APSet_KeepGoingOnErrors(Boolean newValue)
- {
- (**gAppPrefs_h).keepGoingOnErrors = newValue;
- } // APSet_KeepGoingOnErrors
-
- Boolean APGet_KeepGoingOnErrors(void)
- {
- return (**gAppPrefs_h).keepGoingOnErrors;
- } // APGet_KeepGoingOnErrors
-
-
- // ---------------------------------------------------------------------
- void APSet_IncludePaths(FSSpecPtr newValue)
- {
- (**gAppPrefs_h).includeDirFSSpec = *newValue;
- } // APSet_IncludePaths
-
- FSSpecPtr APGet_IncludePaths(void)
- {
- return &(**gAppPrefs_h).includeDirFSSpec;
- } // APGet_IncludePaths
-
-
- // ---------------------------------------------------------------------
- void APSet_AppPrefsDlgPos(Rect * r)
- {
- (**gAppPrefs_h).appPrefsDlgPos = *r;
- } // APSet_AppPrefsDlgPos
-
- void APGet_AppPrefsDlgPos(Rect * r)
- {
- *r = (**gAppPrefs_h).appPrefsDlgPos;
- } // APGet_AppPrefsDlgPos
-
-
- // ---------------------------------------------------------------------
- void APSet_FilePrefsDlgPos(Rect * r)
- {
- (**gAppPrefs_h).filePrefsDlgPos = *r;
- } // APSet_FilePrefsDlgPos
-
- void APGet_FilePrefsDlgPos(Rect * r)
- {
- *r = (**gAppPrefs_h).filePrefsDlgPos;
- } // APGet_FilePrefsDlgPos
-
-
- // ---------------------------------------------------------------------
- // Create a default include FSSPec (first launch of POV-Ray, no prefs file)
- static void GetDefaultIncludePath(FSSpec * tempFSSpecPtr)
- {
- OSErr anError = noErr;
- ProcessSerialNumber myPSN;
- ProcessInfoRec myPSRec;
- CInfoPBRec myPBlock;
- Str255 relPath;
-
- //printf("-d-GetDefaultIncludePath()\n"); // <debug>
-
- // What is our Process ID?
- anError = GetCurrentProcess(&myPSN);
-
- //printf("-d- GetCurrentProcess err=%d\n",anError); // <debug>
-
- // Use that Process ID to get info on this app, specifically its directory
- if (!anError)
- {
- // prepare to read process info
- myPSRec.processInfoLength = sizeof(ProcessInfoRec);
- myPSRec.processName = NULL;
- myPSRec.processAppSpec = tempFSSpecPtr;
- // read app's FSSpec
- anError = GetProcessInformation(&myPSN, &myPSRec);
- }
-
- //printf("-d- GetProcessInformation pvref=%d pdirid=%d err=%d\n", myPSRec.processAppSpec->vRefNum, myPSRec.processAppSpec->parID, anError); // <debug>
-
- // find the relative path name to the :INCLUDE: folder, get from resource.
- // (This is set to look up one level, then down into "INCLUDE")
- if (!anError)
- {
- GetIndString(relPath, kSTRI_FileNames, kSTRIi_INCLUDE_Def);
- anError = ResError();
- }
-
- // now use app directory + relative path to find true dirID.
- if (!anError)
- {
- // set up to find dirID of the :INCLUDE: directory
- myPBlock.dirInfo.ioCompletion = NULL;
- myPBlock.dirInfo.ioNamePtr = relPath;
- myPBlock.dirInfo.ioVRefNum = tempFSSpecPtr->vRefNum;
- myPBlock.dirInfo.ioFDirIndex = 0;
- myPBlock.dirInfo.ioDrDirID = tempFSSpecPtr->parID;
- // look it up
- anError = PBGetCatInfoSync(&myPBlock);
- //printf("-d- PBGetCatInfoSync dirID=%ld err=%d\n", tempFSSpecPtr->parID, anError); // <debug>
- // if found, stick new dirID into fsspec
- if (!anError)
- tempFSSpecPtr->parID = myPBlock.dirInfo.ioDrDirID;
- }
-
- // OK, the vrefnum and DirID are correct, now fill in the name field
- // with the name of the volume (vrefnum). This is just a safe way to
- // store volumes (by name) that POV-Ray uses.
- if (!anError)
- {
- // stick the volume name into the FSSpec name field
- anError = VRef2VolName(tempFSSpecPtr->vRefNum, tempFSSpecPtr->name);
- //printf("-d- VRef2VolName(%d,'%s') err=%d\n", tempFSSpecPtr->vRefNum, tempFSSpecPtr->name, anError); // <debug>
- }
- }
-
- // ---------------------------------------------------------------------
- // Find and open the Application Prefs file
- OSErr AppPrefs_Open(void)
- {
- long theResponse; /* For call to Gestalt */
- OSErr anError = noErr;
- Boolean createdResFile=false;
- Handle resH;
- FSSpec prefsFileFS;
-
- // fill in the Prefs file name from resource
- GetIndString(prefsFileFS.name, kSTRI_FileNames, kSTRIi_Prefs);
- anError = ResError();
-
- // Find the preferences folder
- if (anError == noErr)
- anError = Gestalt(gestaltFindFolderAttr, &theResponse);
-
- if ((anError == noErr) && (theResponse & (1<<gestaltFindFolderPresent) ) )
- anError = FindFolder(kOnSystemDisk, kPreferencesFolderType, kCreateFolder,
- &prefsFileFS.vRefNum, &prefsFileFS.parID);
-
- // Try to create the prefs file.
- if (!anError)
- {
- FSpCreateResFile(&prefsFileFS, kAppSignature/*kAppXtraSignature*/, kPrefsFileType, (ScriptCode)NULL);
- anError = ResError();
- }
-
- // file's already created? Not an error, but remember for later down
- if (anError == noErr)
- createdResFile=true;
- else if (anError == dupFNErr)
- anError = noErr;
-
- if (anError == noErr)
- {
- gAppPrefsRefNum = FSpOpenResFile(&prefsFileFS, fsRdWrPerm);
- if (gAppPrefsRefNum == kRsrcFileClosed)
- anError = -1; // preset in case there is NO ResError
- if (ResError())
- anError = ResError();
- }
-
- if (createdResFile && (anError==noErr))
- {
- // get Finder "Don't Open" error string from app and add it to prefs file
- resH = GetResource('STR ', +16397); // get from application
- if (resH)
- {
- DetachResource(resH); // this copy no longer belongs to app
- AddResource(resH, 'STR ', -16397, "\pSo don't do that!"); // add to file
- }
- // get vers 2 from app and add it to prefs file
- resH = GetResource('vers', 2); // get from application
- if (resH)
- {
- DetachResource(resH); // this copy no longer belongs to app
- AddResource(resH, 'vers', 2, "\pOwner App"); // add to file
- }
- }
-
- return anError;
- } // AppPrefs_Open
-
-
-
- // ---------------------------------------------------------------------
- // Close the Application Prefs file
- void AppPrefs_Close(void)
- {
- CloseResFile (gAppPrefsRefNum);
- gAppPrefsRefNum = kRsrcFileClosed;
- } // AppPrefs_Close
-
-
-
- // ---------------------------------------------------------------------
- // Write the prefs resource back to the app prefs file
- void AppPrefs_Write(void)
- {
- OSErr theResError = noErr;
- short AppRefNum;
- file_prefs_hdl_t tmpFileHandle = NULL;
- app_prefs_hdl_t tmpAppHandle = NULL;
-
- AppRefNum = CurResFile();
- theResError = AppPrefs_Open();
-
- if (theResError != noErr)
- {
- // DEBUG <>
- (void)DisplayModalDialog(kdlog_GenericFatalErr, ok, 0,
- "AppPrefs_Write: Couldn't open prefs file", theResError, ewcDoCentering, eMainDevice);
- }
- else
- {
- UseResFile(gAppPrefsRefNum);
-
- // as long as there are old prefs resources, delete them..
- // note that I'm getting by index, so as to get any rsrc id #s..
- do {
- // App prefs
- tmpAppHandle = (app_prefs_hdl_t)Get1IndResource(kAppPrefsRsrc, 1);
- if (tmpAppHandle != NULL)
- {
- RemoveResource((Handle)tmpAppHandle);
- UpdateResFile(gAppPrefsRefNum);
- DisposeHandle((Handle)tmpAppHandle);
- }
- } while (tmpAppHandle != NULL);
- do {
- // Default File prefs
- tmpFileHandle = (file_prefs_hdl_t)Get1IndResource(kFilePrefsRsrc, 1);
- if (tmpFileHandle != NULL)
- {
- RemoveResource((Handle)tmpFileHandle);
- UpdateResFile(gAppPrefsRefNum);
- DisposeHandle((Handle)tmpFileHandle);
- }
- } while (tmpFileHandle != NULL);
-
- /* Create a new app prefs resource to add */
- tmpAppHandle = (app_prefs_hdl_t)NewHandle(sizeof(app_prefs_rec_t));
-
- /* Fill it up and add it to file */
- if (tmpAppHandle != NULL)
- {
- **tmpAppHandle = **gAppPrefs_h;
- AddResource((Handle)tmpAppHandle, kAppPrefsRsrc, kAppPrefs_rsrcID, "\pPOV-Ray App Prefs");
- theResError = ResError();
- if (!theResError)
- {
- WriteResource((Handle)tmpAppHandle);
- theResError = ResError();
- }
- }
-
- /* Create a new default file prefs resource to add */
- if (theResError == noErr)
- tmpFileHandle = (file_prefs_hdl_t)NewHandle(sizeof(file_prefs_rec_t));
-
- /* Fill it up and add it to file */
- if ((tmpFileHandle != NULL) && (theResError == noErr))
- {
- **tmpFileHandle = **gDefltFilePrefs_h;
- AddResource((Handle)tmpFileHandle, kFilePrefsRsrc, kFilePrefs_rsrcID, "\pPOV-Ray Default File Prefs");
- theResError = ResError();
- if (!theResError)
- {
- WriteResource((Handle)tmpFileHandle);
- theResError = ResError();
- }
- }
- UseResFile(AppRefNum);
-
- if ((theResError) || (tmpAppHandle == NULL) || (tmpFileHandle == NULL))
- {
- // error updating prefs file
- DisplayModalDialog(144, ok, 0, NULL, theResError, ewcDoCentering, eMainDevice);
- gAppPrefs_h = NULL;
- exit_handler();
- }
-
- // All done, clean up shop
- AppPrefs_Close();
-
- } // if !error
- UseResFile(AppRefNum);
- } // AppPrefs_Write
-
-
-
- // ---------------------------------------------------------------------
- // Open the App prefs file & get the prefs out of the file. If the file
- // is out of date or doesn't exist, create a new one and fill it with defaults.
- void AppPrefs_Read(void)
- {
- OSErr theResError = noErr;
- short AppRefNum;
- file_prefs_hdl_t tmpFileHandle = NULL;
- app_prefs_hdl_t tmpAppHandle = NULL;
-
- AppRefNum = CurResFile();
- theResError = AppPrefs_Open();
-
- // Get saved prefs for POV_Ray prefs dialog from the app prefs file
- if (theResError != noErr)
- {
- // DEBUG <>
- (void)DisplayModalDialog(kdlog_GenericFatalErr, ok, 0,
- "AppPrefs_Read: Couldn't open prefs file", theResError, ewcDoCentering, eMainDevice);
- }
- else
- {
- UseResFile(gAppPrefsRefNum);
- theResError = ResError();
-
- // read app prefs
- if (theResError == noErr)
- {
- tmpAppHandle = (app_prefs_hdl_t) Get1Resource(kAppPrefsRsrc, kAppPrefs_rsrcID);
- theResError = ResError();
- if (theResError != noErr)
- tmpAppHandle = NULL;
- }
-
- // read default file prefs
- if (theResError == noErr)
- {
- tmpFileHandle = (file_prefs_hdl_t) Get1Resource(kFilePrefsRsrc, kFilePrefs_rsrcID);
- theResError = ResError();
- if (theResError != noErr)
- tmpFileHandle = NULL;
- }
-
- if (theResError != noErr)
- {
- // error creating prefs file
- (void)DisplayModalDialog(145, ok, 0, NULL, theResError, ewcDoCentering, eMainDevice);
- exit_handler();
- }
-
- // did we get the App prefs?
- if (tmpAppHandle != NULL)
- {
- // Is it the wrong version? Delete it if so..
- if ((**tmpAppHandle).prefsVersion != kAppPrefs_Vers)
- {
- RemoveResource((Handle)tmpAppHandle);
- UpdateResFile(gAppPrefsRefNum);
- DisposeHandle((Handle)tmpAppHandle);
- tmpAppHandle = NULL; // flag code below to add new
- }
- }
-
- // did we get the Default File prefs?
- if (tmpFileHandle != NULL)
- {
- // Is it the wrong version or did we fail to get App prefs? Delete file prefs if so..
- if ( ((**tmpFileHandle).prefsVersion != kFilePrefs_Vers)
- || (tmpAppHandle == NULL) )
- {
- RemoveResource((Handle)tmpFileHandle);
- UpdateResFile(gAppPrefsRefNum);
- DisposeHandle((Handle)tmpFileHandle);
- tmpFileHandle = NULL; // flag code below to add new
- }
- }
-
- // Still got App Prefs? Use it!
- if (tmpAppHandle != NULL)
- {
- // copy contents from rsrc to our memory buffer
- **gAppPrefs_h = **tmpAppHandle;
-
- // ---------------------------------------------------------------
- // NOTE: Certain App Prefs are dangerous to remember between runs...
- // for example "Shut down when done". Always reset these to safer values.
- // ---------------------------------------------------------------
- APSet_UseAppDefaultPrefs(FALSE);
- APSet_ShutDownWhenDone(FALSE);
-
- // make sure our dialogs are on screen
- ForceRectOnScreen(&(**gAppPrefs_h).appPrefsDlgPos);
- ForceRectOnScreen(&(**gAppPrefs_h).filePrefsDlgPos);
- // all done with the resource, scuttle it
- ReleaseResource((Handle)tmpAppHandle);
- }
-
- // Still got File Prefs? Use it!
- if (tmpFileHandle != NULL)
- {
- // copy contents from rsrc to our memory buffer
- **gDefltFilePrefs_h = **tmpFileHandle;
-
- // make sure our windows are visible on THIS MACHINE'S screens
- ForceRectOnScreen(&(**gDefltFilePrefs_h).srcWind_pos);
- ForceRectOnScreen(&(**gDefltFilePrefs_h).statWind_pos);
- ForceRectOnScreen(&(**gDefltFilePrefs_h).imageWind_pos);
- ReleaseResource((Handle)tmpFileHandle);
- }
-
- // return to app rsrc for dialogs
- UseResFile(AppRefNum);
-
- // All done, clean up shop
- AppPrefs_Close();
-
- // fill & add new ones if we couldn't read or use the old ones
- if ((tmpAppHandle == NULL) || (tmpFileHandle == NULL))
- {
- // Beep at user to let them know of update
- SysBeep(4);
-
- //
- // --- set global app record to defaults
- //
-
- if (tmpAppHandle == NULL)
- {
- Rect tempRect;
- FSSpec tempFSSpec;
-
- // set default app prefs values
- (**gAppPrefs_h).prefsVersion = kAppPrefs_Vers;
-
- APSet_TimeSlice(eThrottle_Default);
- APSet_UseAppDefaultPrefs(FALSE);
- APSet_AutoTemplates(TRUE);
- APSet_AllDoneSoundID(1003); // just to make people want to change it! :-)
- APSet_AllDoneNotify(eDone_Beep);
- APSet_AutoSaveImage(TRUE);
- APSet_UseAppDefaultPrefs(FALSE);
- APSet_UseTempMem(FALSE);
- APSet_ShowSplashScreen(TRUE);
- APSet_ShutDownWhenDone(FALSE);
- APSet_AddCustomIcons(TRUE);
- APSet_KeepGoingOnErrors(FALSE);
-
- // create default INCLUDE path starting from current application directory
- GetDefaultIncludePath(&tempFSSpec);
- APSet_IncludePaths(&tempFSSpec);
- // dialog positions
- SetRect(&tempRect, // left, top, right, bottom
- qd.screenBits.bounds.left + 30,
- qd.screenBits.bounds.top + GetMBarHeight()+50,
- qd.screenBits.bounds.left + 30+200,
- qd.screenBits.bounds.top + GetMBarHeight()+50+200);
- APSet_AppPrefsDlgPos(&tempRect);
- APSet_FilePrefsDlgPos(&tempRect);
- } // if (tmpAppHandle == NULL)
-
- //
- // --- set global default file record to defaults
- //
-
- if (tmpFileHandle == NULL)
- {
- // FillDefaultFilePrefs(*gDefltFilePrefs_h);
- (**gDefltFilePrefs_h).prefsVersion = kFilePrefs_Vers;
-
- // SOURCE window
- SetRect(&(**gDefltFilePrefs_h).srcWind_pos, // left, top, right, bottom
- qd.screenBits.bounds.left + 2,
- qd.screenBits.bounds.top + GetMBarHeight()+40,
- min(qd.screenBits.bounds.left + 480, qd.screenBits.bounds.right - 40),
- 400);
-
- // STATUS window
- SetRect(&(**gDefltFilePrefs_h).statWind_pos, // left, top, right, bottom
- qd.screenBits.bounds.left + 3,
- qd.screenBits.bounds.bottom - 260,
- min(qd.screenBits.bounds.left + 480, qd.screenBits.bounds.right - 40),
- qd.screenBits.bounds.bottom - 20);
-
- // IMAGE window
- SetRect(&(**gDefltFilePrefs_h).imageWind_pos, // left, top, right, bottom
- qd.screenBits.bounds.left + 1,
- qd.screenBits.bounds.top + GetMBarHeight()+20,
- 0, 0); // not used
-
- SetPt(&(**gDefltFilePrefs_h).LastPrefsDlgPos, 0, 0);
-
- (**gDefltFilePrefs_h).imageWidth = 100; // x
- (**gDefltFilePrefs_h).imageHeight = 100; // y
- (**gDefltFilePrefs_h).imageUpperLeft.h = 0;
- (**gDefltFilePrefs_h).imageUpperLeft.v = 0;
-
- SetRect(&(**gDefltFilePrefs_h).selectionArea, 1, 1,
- (**gDefltFilePrefs_h).imageWidth,
- (**gDefltFilePrefs_h).imageHeight);
-
- (**gDefltFilePrefs_h).pictFileCreator = 'ttxt';
- (**gDefltFilePrefs_h).targaFileCreator = '8BIM';
-
- // Create Ini file
- (**gDefltFilePrefs_h).doCreateINI = false;
-
- (**gDefltFilePrefs_h).renderQuality = 9;
- (**gDefltFilePrefs_h).radQuality = 0;
- (**gDefltFilePrefs_h).custom_palette = palette_median;
- (**gDefltFilePrefs_h).imageMagFactor = viewmn_normal;
-
- (**gDefltFilePrefs_h).outfileType = eOutfNone;
- (**gDefltFilePrefs_h).outfileBuffSize = 0;
- (**gDefltFilePrefs_h).continueTarga = false;
- (**gDefltFilePrefs_h).bitsPerColor = 8;
- (**gDefltFilePrefs_h).doAlphaChannel = false;
- (**gDefltFilePrefs_h).doDither = true;
- (**gDefltFilePrefs_h).doPictCompression = false;
-
- (**gDefltFilePrefs_h).doBoundSlabs = true;
- (**gDefltFilePrefs_h).boundSlabThreshold = 5;
-
- (**gDefltFilePrefs_h).progress = eProgMac;
- (**gDefltFilePrefs_h).languageVersion = eMaxLangVersion;
-
- (**gDefltFilePrefs_h).previewStart = 3; // 0=off 1,2,3,4
- (**gDefltFilePrefs_h).previewEnd = 1;
-
- (**gDefltFilePrefs_h).doAntialias = false;
- (**gDefltFilePrefs_h).antialiasMethod = 1; // 1 or 2
- (**gDefltFilePrefs_h).antialiasThreshold = 0.30;
- (**gDefltFilePrefs_h).antialiasDepth = 3;
- (**gDefltFilePrefs_h).antiJitterScale = 0.0;
-
- (**gDefltFilePrefs_h).doHistogram = false;
- (**gDefltFilePrefs_h).histogramType = 1;
- (**gDefltFilePrefs_h).histogramXSize = 0;
- (**gDefltFilePrefs_h).histogramYSize = 0;
-
- (**gDefltFilePrefs_h).doFieldRender = false;
- (**gDefltFilePrefs_h).doOddField = true;
-
- (**gDefltFilePrefs_h).doSplitUnions = true;
- (**gDefltFilePrefs_h).removeBounds = true;
- (**gDefltFilePrefs_h).doVistaBuffer = true;
- (**gDefltFilePrefs_h).doLightBuffer = true;
- (**gDefltFilePrefs_h).doVistaDraw = false;
-
- // CLOCK - animation
- (**gDefltFilePrefs_h).doAnimation = false;
- (**gDefltFilePrefs_h).animRec.frameVal0 = 1;
- (**gDefltFilePrefs_h).animRec.frameValN = 20; // some medium # of frames
- (**gDefltFilePrefs_h).animRec.frameValS = (**gDefltFilePrefs_h).animRec.frameVal0;
- (**gDefltFilePrefs_h).animRec.frameValE = (**gDefltFilePrefs_h).animRec.frameValN;
- (**gDefltFilePrefs_h).animRec.clockVal0 = 0.0;
- (**gDefltFilePrefs_h).animRec.clockValN = 1.0;
-
- // Initial defaults for SC compression dialog
- if (gtheSCComponent)
- {
- (void)SCGetInfo(gtheSCComponent, scSpatialSettingsType, &(**gDefltFilePrefs_h).sc_DialogParams);
- }
- } // if (tmpFileHandle == NULL)
-
- // Save our settings
- AppPrefs_Write();
-
- } // didn't get it, create new
-
- // make sure file prefs is initialized too
- **gFilePrefs_h = **gDefltFilePrefs_h; // initialize this to defaults
-
- // set up our current prefs to be those of the file.
- // This can be changed with the App Prefs dialog
- gPrefs2Use_h = gFilePrefs_h;
-
- }
- UseResFile(AppRefNum);
- } // AppPrefs_Read
-
-
-
- // ---------------------------------------------------------------------
- static Boolean PromptForSearchPath(FSSpecPtr theDirFSSpecPtr)
- {
- Point sfWhere;
- StandardFileReply theReply;
-
- // preset Std file to start out at current FSSpec folder
- SF_SetSFCurrent(theDirFSSpecPtr);
-
- // prompt for Include files
- GetBestDialogPos(&sfWhere, (WindowPtr)gp2wWindow);
- SF_PromptForFolder(sfWhere, "\pFind the POV-Ray INCLUDE folder", &theReply);
-
- if (!theReply.sfGood)
- return false;
- else
- {
- *theDirFSSpecPtr = theReply.sfFile;
-
- printf("-d-PromptForSearchPath() pvref=%d pdirid=%d\n",
- theReply.sfFile.vRefNum, theReply.sfFile.parID); // <debug>
-
- return true;
- }
- } // PromptForSearchPath
-
-
- // ---------------------------------------------------------------------
- // When we finally have time to add ful AppleScript and connect to remote POV-Rays
- static void DoConnectPrompt(void)
- {
- OSErr anError;
- LocationNameRec pLocNameRec;
- PortInfoRec pPortInfoRec;
-
- anError = PPCBrowser(
- "\pChoose a POV-Ray Server",
- "\pPOV-Servers",
- false, // no defaults
- &pLocNameRec,
- &pPortInfoRec,
- NULL,
- NULL
- );
- } // DoConnectPrompt
-
-
- // ---------------------------------------------------------------------
- // Get the menu handle of a popup menu
- static MenuRef GetPopupMenuHandle(DialogPtr dlgWindPtr, short popupDitlID)
- {
- ControlHandle popupControlH = NULL;
- MenuRef theMenuRef = NULL;
-
- // get the popup menu control, then get menu handle from it
- popupControlH = (ControlHandle)GrabDItemHandle(dlgWindPtr, popupDitlID);
- // popup menu handle inside struct pointed to by contrlData handle! (NIM:Essentials:5-28,5-77)
- if (popupControlH)
- theMenuRef = (MenuRef) (**(Handle**)(**popupControlH).contrlData);
- return theMenuRef;
- }
-
- // ---------------------------------------------------------------------
- // Initialize the sound popup menu with list of sounds
- static void InitSoundsPopup(DialogPtr dlgWindPtr)
- {
- int k;
- short menuItemFound;
- short theSoundRsrcID = 0;
- MenuRef soundsMenuRef = NULL;
- OSType theSoundRsrcType;
- Handle theSoundRsrcH = NULL;
- Str255 userSoundName;
- Str255 menuSoundName;
-
- // get the popup menu
- soundsMenuRef = GetPopupMenuHandle(dlgWindPtr, kPU_SoundsPopup);
- // add all the sounds in the app and system to this menu
- if (soundsMenuRef)
- {
- // (all the sounds are added to the menu automatically by the popup CNTL)
- // now search the menu for the previously chosen sound,
- // so we can set that as the current menu item
- theSoundRsrcH = GetResource(soundListRsrc, APGet_AllDoneSoundID());
- // use the sound resource handle found to get its name
- userSoundName[0]=0; // reset string in case it is not found
- if (theSoundRsrcH)
- GetResInfo(theSoundRsrcH, &theSoundRsrcID, &theSoundRsrcType, userSoundName);
- // now loop through menu items comparing names until we find a match
- menuItemFound = 1; // assume first item until we really find one
- for (k=1; k<CountMenuItems(soundsMenuRef); k++)
- {
- // get this menu item's name
- GetMenuItemText(soundsMenuRef, k, menuSoundName);
- if (0 == CompareString(userSoundName, menuSoundName, NULL))
- {
- // found it!
- menuItemFound = k;
- break;
- }
- }
- // now menuItemFound holds the item to set the menu to,
- // set current value of popup to this item
- SetDialogItemValue(dlgWindPtr, kPU_SoundsPopup, menuItemFound);
- }
- }
-
- // ---------------------------------------------------------------------
- // convert current item selected in popup menu into a sound resource ID
- static short GetAllDoneSoundID(DialogPtr dlgWindPtr)
- {
- short itemIndex;
- short theSoundRsrcID = 0;
- OSType theSoundRsrcType;
- Handle theSoundRsrcH = NULL;
- MenuRef soundsMenuRef = NULL;
- Str255 theSoundName;
-
- // get the currently selected item number of popup menu
- itemIndex = GetDialogItemValue(dlgWindPtr, kPU_SoundsPopup);
- // get the popup menu itself
- soundsMenuRef = GetPopupMenuHandle(dlgWindPtr, kPU_SoundsPopup);
- // now get the item text for that item, this is the sound resource name
- theSoundName[0]=0; // reset string in case not found
- if (soundsMenuRef)
- GetMenuItemText(soundsMenuRef, itemIndex, theSoundName);
- // Now search for the resource by its name
- theSoundRsrcH = GetNamedResource(soundListRsrc, theSoundName);
- // finally, use the sound resource handle found to get its resource ID!
- if (theSoundRsrcH)
- GetResInfo(theSoundRsrcH, &theSoundRsrcID, &theSoundRsrcType, theSoundName);
- // return the resource ID to the caller
- return theSoundRsrcID;
- }
-
-
- // ---------------------------------------------------------------------
- // Prompt the user to change the Application Preferences
- static void AppPrefs_HandleEvents(EventRecord * theEventPtr)
- {
- short itemHit;
- Boolean gotItem;
- WindowPtr myDialog;
- Rect dRect;
- Str255 thePath;
-
- gotItem = false;
- myDialog = GetCurrMModalDialog();
-
- // handle activate events
- if (theEventPtr->what == activateEvt)
- {
- // enable or disable our main buttons on activate/deactivate
- HiliteControl(GrabDItemHandle(myDialog, ok), (theEventPtr->modifiers & 1)?0:255);
- HiliteControl(GrabDItemHandle(myDialog, cancel), (theEventPtr->modifiers & 1)?0:255);
- }
-
- // Handle CR/ESC ourselves
- if (theEventPtr->what == keyDown)
- {
- char theKey = theEventPtr->message & charCodeMask;
- if ((theKey == 13) || (theKey == 3)) // CR or ENTER
- {
- itemHit = ok;
- gotItem = true;
- FlashDItem(myDialog, itemHit);
- }
- if ((theKey == 27) || // escape key
- ((theKey == '.') && (theEventPtr->modifiers & cmdKey))) // <cmd>-period
- {
- itemHit = cancel;
- gotItem = true;
- FlashDItem(myDialog, itemHit);
- }
-
- }
-
- // look for other events
- if (!gotItem)
- gotItem = DialogSelect(theEventPtr, &myDialog, &itemHit);
-
- if (gotItem)
- {
- switch (itemHit)
- {
- case kBT_ChooseSearchPath:
- // Call up Standard File to let user find the path
- if (PromptForSearchPath(&gTempFSS))
- {
- // find this folder name's dirID
- gTempFSS.parID = SF_GetFSSubDirID(&gTempFSS);
- // convert it to full pathname for display
- PathNameFromDirID(gTempFSS.parID, gTempFSS.vRefNum, (char*)thePath);
- c2pstr((char*)thePath);
- SetDialogItemText((Handle)GrabDItemHandle(myDialog, kST_SearchPath), thePath);
- // save volume name in the NAME field, for permanent retrieval
- VRef2VolName(gTempFSS.vRefNum, gTempFSS.name);
- }
- break;
-
- case kCB_AutoTemplates:
- case kCB_AutoSaveImage:
- case kCB_UseAppDefaultPrefs:
- case kCB_ShowSplashScreen:
- case kCB_ShutDownWhenDone:
- case kCB_AddCustomIcons:
- case kCB_KeepGoingOnErrors:
- SetDialogItemValue(myDialog, itemHit, !GetDialogItemValue(myDialog, itemHit));
- break;
-
- // not yet...
- // case kBT_ChooseRenderer:
- // // Call up PPCBrowser
- // DoConnectPrompt();
- // break;
-
- case ok:
- APSet_TimeSlice(GetDialogItemValue(myDialog, kPU_AppThrottle));
- APSet_AutoTemplates(GetDialogItemValue(myDialog, kCB_AutoTemplates));
- APSet_UseAppDefaultPrefs(GetDialogItemValue(myDialog, kCB_UseAppDefaultPrefs));
- APSet_AllDoneSoundID(GetAllDoneSoundID(myDialog));
- APSet_AllDoneNotify(GetDialogItemValue(myDialog, kPU_AllDoneNotify));
- APSet_AutoSaveImage(GetDialogItemValue(myDialog, kCB_AutoSaveImage));
- APSet_ShowSplashScreen(GetDialogItemValue(myDialog, kCB_ShowSplashScreen));
- APSet_ShutDownWhenDone(GetDialogItemValue(myDialog, kCB_ShutDownWhenDone));
- APSet_AddCustomIcons(GetDialogItemValue(myDialog, kCB_AddCustomIcons));
- APSet_KeepGoingOnErrors(GetDialogItemValue(myDialog, kCB_KeepGoingOnErrors));
-
- APSet_IncludePaths(&gTempFSS);
- GetGlobalWindowRect(myDialog, &dRect); // ScreenUtils.c
- APSet_AppPrefsDlgPos(&dRect);
-
- // save prefs in file
- AppPrefs_Write();
-
- CloseMModalDialog();
- EnableMenus(); // re-enable menus
- break;
-
- case cancel:
- **gAppPrefs_h = gOrigPrefs; // restore original values
- CloseMModalDialog();
- EnableMenus(); // re-enable menus
- break;
- } // switch
- } // if
- } // AppPrefs_HandleEvents
-
-
- // ---------------------------------------------------------------------
- // Prompt the user to change the Application Preferences
- void AppPrefs_Prompt_Init(void)
- {
- Rect aRect;
- DialogPtr myDialog;
- Str255 thePath;
-
- // retrieve dialog from resource
- myDialog = GetMModalDialog(kDlogID_AppPrefs);
- if (!myDialog)
- {
- SysBeep(4);
- return;
- }
-
- // set this as current dialog and event handler
- SetCurrMModalDialog(myDialog, &AppPrefs_HandleEvents);
-
- // remember temporary prefs record until user clicks OK!
- gOrigPrefs = **gAppPrefs_h;
-
- // Init the App throttle popup
- SetDialogItemValue(myDialog, kPU_AppThrottle, APGet_TimeSlice());
-
- // Init the Auto-load Templates
- SetDialogItemValue(myDialog, kCB_AutoTemplates, APGet_AutoTemplates());
-
- // Init All done Notify popup
- SetDialogItemValue(myDialog, kPU_AllDoneNotify, APGet_AllDoneNotify());
-
- // Init the done sound popup
- InitSoundsPopup(myDialog);
-
- // Init the Autosave checkbox
- SetDialogItemValue(myDialog, kCB_AutoSaveImage, APGet_AutoSaveImage());
-
- // Init the Show Splash Screen checkbox
- SetDialogItemValue(myDialog, kCB_ShowSplashScreen, APGet_ShowSplashScreen());
-
- // Init the Shut down checkbox
- SetDialogItemValue(myDialog, kCB_ShutDownWhenDone, APGet_ShutDownWhenDone());
-
- // Init the custom icon checkbox
- SetDialogItemValue(myDialog, kCB_AddCustomIcons, APGet_AddCustomIcons()&&gHasQuickTime);
- // disable it if no QuickTime present
- HiliteControl(GrabDItemHandle(myDialog, kCB_AddCustomIcons),
- gHasQuickTime?kControlNoPart:kControlInactivePart);
-
- // Init the keep going checkbox
- SetDialogItemValue(myDialog, kCB_KeepGoingOnErrors, APGet_KeepGoingOnErrors());
-
-
- // Init the default settings
- SetDialogItemValue(myDialog, kCB_UseAppDefaultPrefs, APGet_UseAppDefaultPrefs());
-
- // convert volume name to vref for making full path
- gTempFSS = *(APGet_IncludePaths());
- VolName2VRef(gTempFSS.name, &gTempFSS.vRefNum);
-
- // make full path
- PathNameFromDirID(gTempFSS.parID, gTempFSS.vRefNum, (char*)thePath);
- c2pstr((char*)thePath);
- // stuff path into display field
- SetDialogItemText((Handle)GrabDItemHandle(myDialog, kST_SearchPath), thePath);
- TruncStaticTextItem(myDialog, kST_SearchPath); // shorten it
-
- APGet_AppPrefsDlgPos(&aRect);
- if ((aRect.left==0) && (aRect.top==0))
- PositionWindow(myDialog, ewcDoCentering, eSameAsPassedWindow, (WindowPtr)gp2wWindow);
- else
- {
- // make sure our windows are visible on THIS MACHINE'S screens
- ForceRectOnScreen(&aRect);
- MoveWindow(myDialog, aRect.left, aRect.top, true);
- }
-
- // set the standard action for OK/cancel buttons
- InstallUserDrawProc(myDialog, kDefaultOutlineItem, &OutlineButtonDrawProc);
-
- // show it
- ShowMModalDialog();
-
- } // AppPrefs_Prompt_Init
-
-
-