prefs.cpp

Go to the documentation of this file.
00001 // $Id: prefs.cpp 1464 2006-07-18 12:32:26Z gerry $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 // This code provides the interface to the Camelot application that allows
00100 // various preferences to be declared, and read/written from/to disk.
00101 // It communicates with the OIL layer to to do the disk transfer.
00102 
00103 
00104 #include "camtypes.h"
00105 
00106 //#include "prefs.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "oilprefs.h"
00108 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "basestr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 //#include "justin.h"
00112 //#include "optsres.h"  // general options based resources
00113 //#include "fixmem.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 
00115 static BOOL PrefsInitedOk = FALSE;
00116 
00117 // Dynamic classing implementation
00118 CC_IMPLEMENT_MEMDUMP(Preferences,       List)
00119 
00120 // Declare smart memory handling in Debug builds
00121 #define new CAM_DEBUG_NEW
00122 
00123 #if !defined(EXCLUDE_FROM_RALPH)
00124 
00125 /********************************************************************************************
00126 
00127 >   class PreferenceEntry : public CC_CLASS_MEMDUMP
00128 
00129     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00130     Created:    17/8/93
00131     Purpose:    Instances of this class hold information about a single preference.
00132                 This is a very simple public class with no member functions.
00133     SeeAlso:    PreferenceChunk; PreferenceSection; Preferences
00134 
00135 ********************************************************************************************/
00136 
00137 class PreferenceEntry : public CC_CLASS_MEMDUMP
00138 {
00139     CC_DECLARE_MEMDUMP(PreferenceEntry)
00140 
00141 public:
00142     // No constructor or destructor needed - simple public structure.
00143     
00144     LPTCHAR         Name;       // Pointer to the name of the preference.
00145     PrefData        Data;       // Pointer to the variable that holds the preference value.
00146     PreferenceType  Type;       // Type of the preference - INT32, STRING, etc.
00147     
00148 };
00149 
00150 
00151 /********************************************************************************************
00152 
00153 >   class PreferenceChunk : public ListItem
00154 
00155     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00156     Created:    17/8/93
00157     Purpose:    Objects of this class hold a chunk of preferences for a particular section
00158                 of the preferences.  There may be more than one chunk for a given section,
00159                 depending on how accurate the initial declaration of the section's size was.
00160     SeeAlso:    -
00161 
00162 ********************************************************************************************/
00163 
00164 
00165 class PreferenceChunk : public ListItem
00166 {
00167     CC_DECLARE_MEMDUMP(PreferenceChunk)
00168 
00169 public:
00170     PreferenceChunk(UINT32 InitialSize);
00171     ~PreferenceChunk();
00172     
00173     void Write(OILPreferences* OILPrefs, LPTCHAR Section);
00174     
00175     // Adds a preference to the chunk.  Returns FALSE if there is not enough room to do
00176     // this (and so the caller should create a new chunk for it).
00177     BOOL AddPref(LPTCHAR Name, PrefData EntryData, PreferenceType Type);
00178     
00179 private:
00180     UINT32 NumEntries;          // Number of entries in the chunk.
00181     UINT32 NumEntriesUsed;      // Number of entries in the chunk that have been used.
00182 
00183     PreferenceEntry *pEntries;  // Pointer to the array of PreferenceEntry objects 
00184                                 // for this chunk.
00185 public:                             
00186     BOOL Valid;                 // Indicates that this is a valid chunk (i.e. it
00187                                 // initialised ok).
00188 
00189     // Allows application options dialog box to read and write values already declared in the
00190     // preference system.
00191     BOOL GetPrefValue(LPTCHAR Pref, PrefData EntryData, PreferenceType Type);
00192     BOOL SetPrefValue(LPTCHAR Pref, PrefData EntryData, PreferenceType Type);
00193 
00194 #ifdef _DEBUG
00195     BOOL PrefExists(LPTCHAR Pref);
00196 #endif
00197 
00198 };
00199 
00200 
00201 /********************************************************************************************
00202 
00203 >   class PreferenceSection : public ListItem
00204 
00205     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00206     Created:    17/8/93
00207     Purpose:    Holds all the preferences for a particular section of the preference file.
00208                 These preferences are stored in one or more instances of the PreferenceChunk
00209                 class.  These instances are linked together as a List by this class.
00210     SeeAlso:    -
00211 
00212 ********************************************************************************************/
00213 
00214 
00215 class PreferenceSection : public ListItem
00216 {
00217     CC_DECLARE_MEMDUMP(PreferenceSection)
00218 
00219 public:
00220     PreferenceSection(LPTCHAR SectionName, UINT32 InitialSize);
00221     ~PreferenceSection();
00222     
00223     void Write(OILPreferences* OILPrefs);
00224     
00225     BOOL AddPref(OILPreferences* OILPrefs, LPTCHAR Pref,
00226                  PreferenceType Type, PrefData PrefVar);
00227 
00228     LPTCHAR Section;
00229     BOOL  Valid;
00230     
00231     List ChunkList;
00232 
00233     BOOL GetPrefValue(OILPreferences* OILPrefs, LPTCHAR Pref,
00234                       PreferenceType Type, PrefData PrefVar);
00235     BOOL SetPrefValue(OILPreferences* OILPrefs, LPTCHAR Pref,
00236                       PreferenceType Type, PrefData PrefVar);
00237 };
00238 
00239 // Dynamic classing implementation
00240 CC_IMPLEMENT_MEMDUMP(PreferenceEntry,   CC_CLASS_MEMDUMP)
00241 CC_IMPLEMENT_MEMDUMP(PreferenceChunk,   ListItem)
00242 CC_IMPLEMENT_MEMDUMP(PreferenceSection, ListItem)
00243 
00244 /********************************************************************************************
00245 
00246 >   PreferenceChunk::PreferenceChunk(UINT32 InitialSize)
00247 
00248     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00249     Created:    17/8/93
00250     Inputs:     InitialSize - the number of preferences this chunk should be able to hold.
00251     Outputs:    -
00252     Returns:    -
00253     Purpose:    Constructs a chunk of memory which can contain preferences.
00254     Errors:     The member variable 'Valid' is FALSE if the required memory was not
00255                 allocated.
00256     SeeAlso:    -
00257 
00258 ********************************************************************************************/
00259 
00260 PreferenceChunk::PreferenceChunk(UINT32 InitialSize)
00261 {
00262     Valid = FALSE;
00263     
00264     // Sanity check
00265     ENSURE(InitialSize > 0, "Attempt to create a PreferenceChunk object of zero size");
00266 
00267     // Allocate the memory for this chunk.
00268     pEntries = new PreferenceEntry[InitialSize];
00269     
00270     if (pEntries == NULL)
00271     {
00272         // Not enough memory
00273         NumEntries = 0;
00274         NumEntriesUsed = 0;
00275     }
00276     
00277     // Set the entries fields correctly and tell the caller it worked
00278     NumEntries = InitialSize;
00279     NumEntriesUsed = 0;
00280     Valid = TRUE;
00281 }
00282 
00283 /********************************************************************************************
00284 
00285 >   PreferenceChunk::~PreferenceChunk()
00286 
00287     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00288     Created:    17/8/93
00289     Inputs:     -
00290     Outputs:    -
00291     Returns:    -
00292     Purpose:    Destroys the PreferenceChunk - it deallocates any memory previously
00293                 allocated for PreferenceEntry objects by this object.
00294     Errors:     -
00295     SeeAlso:    -
00296 
00297 ********************************************************************************************/
00298 
00299 PreferenceChunk::~PreferenceChunk()
00300 {
00301     PreferenceEntry *pEntry = pEntries;
00302     
00303     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00304     {
00305         if (pEntry->Name)
00306         {
00307             CCFree(pEntry->Name);
00308             pEntry->Name=NULL;
00309         }
00310         pEntry++;
00311     }   
00312     
00313     if (pEntries != NULL)
00314         delete [] pEntries;
00315 }
00316 
00317     
00318 /********************************************************************************************
00319 
00320 >   BOOL PreferenceChunk::AddPref(LPTCHAR Name, PrefData EntryData, PreferenceType Type)
00321 
00322     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00323     Created:    17/8/93
00324     Inputs:     Name      - the name of the section to add this preference to.
00325                 EntryData - pointer to the memory that will hold the value of this
00326                             preference.
00327                 Type      - the type of this preference - i.e., the type of data pointed to
00328                             by the EntryData argument.
00329     Outputs:    -
00330     Returns:    TRUE if the preference could be added to this chunk - FALSE if the chunk
00331                 is full and the preference could not be added.
00332     Purpose:    Adds the given preference to this chunk.
00333     Errors:     -
00334     SeeAlso:    -
00335 
00336 ********************************************************************************************/
00337 
00338 BOOL PreferenceChunk::AddPref(LPTCHAR Name, PrefData EntryData, PreferenceType Type)
00339 {
00340     // Is there enough space left to do this?
00341     if ((!Valid) || (NumEntriesUsed >= NumEntries))
00342         return FALSE;
00343     
00344     // Fill in the entry (NB. obscure pointer arithmetic)
00345     PreferenceEntry *pEntry = pEntries + NumEntriesUsed;
00346     
00347     // Alex put in something to make a copy of the name
00348     UINT32 memsize = (camStrlen(Name) + 1) * sizeof(TCHAR);
00349     pEntry->Name = (LPTCHAR) CCMalloc( memsize );
00350     if (!pEntry->Name) return FALSE; // error already set
00351     camStrcpy(pEntry->Name, Name);
00352 //  pEntry->Name    = Name;
00353 
00354     pEntry->Data    = EntryData;
00355     pEntry->Type    = Type;
00356     
00357     // Update chunk information
00358     NumEntriesUsed++;
00359     
00360     // Return success
00361     return TRUE;
00362 }
00363 
00364 /********************************************************************************************
00365 
00366 >   void PreferenceChunk::Write(OILPreferences* OILPrefs, LPTCHAR Section)
00367 
00368     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00369     Created:    17/8/93
00370     Inputs:     OILPrefs - The OIL object to use to write the preferences out with.
00371                 Section  - the name of the section that this chunk is a part of.
00372     Outputs:    -
00373     Returns:    -
00374     Purpose:    Writes out all the preferences contained in this chunk object, using the OIL.
00375     Errors:     -
00376     SeeAlso:    -
00377 
00378 ********************************************************************************************/
00379 
00380 void PreferenceChunk::Write(OILPreferences* OILPrefs, LPTCHAR Section)
00381 {
00382     // Write out each preference in this chunk
00383 
00384     PreferenceEntry *pEntry = pEntries;
00385     
00386     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00387     {
00388         // Write this preference
00389         OILPrefs->Write(Section, pEntry->Name, pEntry->Type, pEntry->Data);
00390 
00391         // Move on to the next preference
00392         pEntry++;
00393     }
00394 }
00395 
00396 
00397 
00398 /********************************************************************************************
00399 
00400 >   BOOL PreferenceChunk::GetPrefValue(LPTCHAR Pref, PrefData EntryData, PreferenceType Type)
00401 
00402     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00403     Created:    17/10/94
00404     Inputs:     Pref      - name of preference to look for.
00405                 EntryData - pointer to the variable that will be used to pass the preference
00406                             value back in.
00407                 Type      - the type of this preference - i.e., the type of data pointed to
00408                             by the EntryData argument.
00409     Outputs:    EntryData - pointer to the variable that should now be set up to echo the
00410                             value of the specified preference.
00411     Returns:    TRUE if the preference exists, FALSE otherwise.
00412     Purpose:    Checks to see if the given preference exists in this chunk and if so returns
00413                 the value currently assigned to that preference value by placing it in the
00414                 variable pointed to by the PrefData structure passed in. This means one routine
00415                 can be used as opposed to one per preference type.
00416     Errors:     -
00417     SeeAlso:    PreferenceChunk::SetPrefValue
00418 
00419 ********************************************************************************************/
00420 
00421 BOOL PreferenceChunk::GetPrefValue(LPTCHAR Pref, PrefData EntryData, PreferenceType Type)
00422 {
00423     PreferenceEntry *pEntry = pEntries;
00424     
00425     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00426     {
00427         if (camStricmp(Pref, pEntry->Name) == 0)
00428         {
00429             // Found it so it does exist
00430             // Check that the type corresponds to the correct one
00431             if (pEntry->Type == Type)
00432             {
00433                 // Preference exits and is of the correct type so return it by writing 
00434                 // the value pointed to by the preference into the value pointed to by
00435                 // the preference structure passed in.
00436                 switch (Type)
00437                 {
00438                     case    PREF_INT:
00439                         // integer supplied so use the pointer to integer
00440                         *EntryData.pInt = *pEntry->Data.pInt;
00441                     break;
00442                     case    PREF_UINT:
00443                         *EntryData.pUInt = *pEntry->Data.pUInt;
00444                     break;
00445                     case    PREF_DOUBLE:
00446                         *EntryData.pDouble = *pEntry->Data.pDouble;
00447                     break;
00448                     case    PREF_STRING:
00449                         // Shouldn't be required so disable
00450                         //*EntryData.pString = *pEntry->Data.pString;
00451                         return FALSE;
00452                     break;
00453                 }
00454                 return TRUE;
00455             }
00456             else
00457             {
00458                 return FALSE;
00459             }
00460         }
00461         // Move on to the next preference
00462         pEntry++;
00463     }
00464     
00465     // Not found
00466     return FALSE;
00467 }
00468 
00469 /********************************************************************************************
00470 
00471 >   BOOL PreferenceChunk::SetPrefValue(LPTCHAR Pref, PrefData EntryData, PreferenceType Type)
00472 
00473     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00474     Created:    17/10/94
00475     Inputs:     Pref - name of preference to look for.
00476                 EntryData - pointer to the memory that is holding the value of this
00477                             preference that we wish to set.
00478                 Type      - the type of this preference - i.e., the type of data pointed to
00479                             by the EntryData argument.
00480     Outputs:    -
00481     Returns:    TRUE if the preference exists, FALSE otherwise.
00482     Purpose:    Checks to see if the given preference exists in this chunk and if so sets the
00483                 value stored in the preference user's variable to be the specified new value.
00484     Errors:     -
00485     SeeAlso:    PreferenceChunk::GetPrefValue
00486 
00487 ********************************************************************************************/
00488 
00489 BOOL PreferenceChunk::SetPrefValue(LPTCHAR Pref, PrefData EntryData, PreferenceType Type)
00490 {
00491     PreferenceEntry *pEntry = pEntries;
00492     
00493     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00494     {
00495         if (camStricmp(Pref, pEntry->Name) == 0)
00496         {
00497             // Found it so it does exist
00498             // Check that the type corresponds to the correct one
00499             if (pEntry->Type == Type)
00500             {
00501                 // Preference exits and is of the correct type so return it by writing 
00502                 // the value pointed to by the preference into the value pointed to by
00503                 // the preference structure passed in.
00504                 switch (Type)
00505                 {
00506                     case    PREF_INT:
00507                         // integer supplied so use the pointer to integer
00508                         *pEntry->Data.pInt = *EntryData.pInt;
00509                     break;
00510                     case    PREF_UINT:
00511                         *pEntry->Data.pUInt = *EntryData.pUInt;
00512                     break;
00513                     case    PREF_DOUBLE:
00514                         *pEntry->Data.pDouble = *EntryData.pDouble;
00515                     break;
00516                     case    PREF_STRING:
00517                         // Shouldn't be required so disable
00518                         //*EntryData.pString = *pEntry->Data.pString;
00519                         return FALSE;
00520                     break;
00521                 }
00522                 return TRUE;
00523             }
00524             else
00525             {
00526                 return FALSE;
00527             }
00528         }
00529         // Move on to the next preference
00530         pEntry++;
00531     }
00532     
00533     // Not found
00534     return FALSE;
00535 }
00536 
00537 
00538 /********************************************************************************************
00539 
00540 >   BOOL PreferenceChunk::PrefExists(LPTCHAR Pref)
00541 
00542     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00543     Created:    26/8/93
00544     Inputs:     Pref - name of preference to look for.
00545     Outputs:    -
00546     Returns:    TRUE if the preference exists, FALSE otherwise.
00547     Purpose:    Checks to see if the given preference exists in this chunk.
00548                 Only exists in DEBUG builds.
00549     Errors:     -
00550     SeeAlso:    -
00551 
00552 ********************************************************************************************/
00553 
00554 #ifdef _DEBUG
00555                                                 
00556 BOOL PreferenceChunk::PrefExists(LPTCHAR Pref)
00557 {
00558     PreferenceEntry *pEntry = pEntries;
00559     
00560     for (UINT32 i = 0; i < NumEntriesUsed; i++)
00561     {
00562         if (camStricmp(Pref, pEntry->Name) == 0)
00563             // Found it so it does exist
00564             return TRUE;
00565         
00566         // Move on to the next preference
00567         pEntry++;
00568     }
00569     
00570     // Not found
00571     return FALSE;
00572 }
00573 
00574 #endif
00575 
00576 /********************************************************************************************
00577 
00578 >   PreferenceSection::PreferenceSection(LPTCHAR SectionName, UINT32 InitialSize)
00579 
00580     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00581     Created:    17/8/93
00582     Inputs:     SectionName - The name to be associated with this section object.
00583                 InitialSize - The caller's estimate of how many preferences will typically
00584                               be stored in this section.  Used as a guideline for allocating
00585                               memory.
00586     Outputs:    -
00587     Returns:    -
00588     Purpose:    Creates a new section object.  A chunk of memory is allocated to hold the
00589                 preferences for this object.  If the memory is not available for this, then
00590                 the 'Valid' data member contains the value 'FALSE'.
00591     Errors:     -
00592     SeeAlso:    -
00593 
00594 ********************************************************************************************/
00595 
00596 PreferenceSection::PreferenceSection(LPTCHAR SectionName, UINT32 InitialSize)
00597 {
00598     Valid = FALSE;
00599     
00600     // Remember the name of this section (note that it uses the original - it does not
00601     // take a copy).
00602     Section = SectionName;
00603 
00604     // Get a preference chunk for this section, using the size recommended
00605     // by the caller
00606     PreferenceChunk *pChunk = new PreferenceChunk(InitialSize);
00607     
00608     if ((pChunk == NULL) || (!pChunk->Valid))
00609     {
00610         delete pChunk;
00611         return; // Section is invalid
00612     }
00613         
00614     // Got a chunk ok, so add it to the head of the (empty) list.
00615     ChunkList.AddHead(pChunk);
00616     
00617     // Success
00618     Valid = TRUE;
00619 }
00620 
00621 /********************************************************************************************
00622 
00623 >   PreferenceSection::~PreferenceSection()
00624 
00625     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00626     Created:    17/8/93
00627     Inputs:     -
00628     Outputs:    -
00629     Returns:    -
00630     Purpose:    Deletes all PreferenceChunk objects used by this section.
00631     Errors:     -
00632     SeeAlso:    -
00633 
00634 ********************************************************************************************/
00635 
00636 PreferenceSection::~PreferenceSection()
00637 {
00638     PreferenceChunk *pChunk;
00639     
00640     // Delete all the chunks for this section
00641     do
00642     {
00643         // Unlink the first item from the list
00644         pChunk = (PreferenceChunk *) ChunkList.RemoveHead();
00645 
00646         // It doesn't matter if pChunk is NULL - delete handles it
00647         delete pChunk;
00648         
00649     } while (pChunk != NULL);
00650 }
00651     
00652 /********************************************************************************************
00653 
00654 >   BOOL PreferenceSection::AddPref(OILPreferences* OILPrefs,
00655                                     LPTCHAR Pref, PreferenceType Type, PrefData PrefVar)
00656 
00657     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00658     Created:    17/8/93
00659     Inputs:     Pref     - the name of the preference to add (e.g. "autosaveinterval")
00660                 Type     - the type of data used for this preference.
00661                 PrefVar  - pointer to the memory that holds this preference's data.
00662                 OILPrefs - the object to use to read the preference from the file.
00663     Outputs:    -
00664     Returns:    TRUE if the preference was added to the preference system successfully, 
00665                 FALSE otherwise.
00666     Purpose:    Adds a preference to this PreferenceSection object.  If a new PreferenceChunk
00667                 is needed to do this, it is allocated automatically, and added to this
00668                 object's list of chunks.
00669     Errors:     -
00670     SeeAlso:    -
00671 
00672 ********************************************************************************************/
00673 
00674 BOOL PreferenceSection::AddPref(OILPreferences* OILPrefs,
00675                                 LPTCHAR Pref, PreferenceType Type, PrefData PrefVar)
00676 {
00677 #ifdef _DEBUG
00678     if ((camStrnicmp(Pref, _T("blobby"), 7) == 0) ||
00679         (camStrnicmp(Pref, _T("wobjob"), 7) == 0))
00680     {
00681         // Silly names not allowed
00682         ENSURE(FALSE, "Preference section has suffered a cliche overload");
00683         abort();
00684     }
00685 #endif
00686 
00687     // Used for scanning the chunk list
00688     PreferenceChunk *pChunk;
00689 
00690     // In debug builds, check that this preference has not already been declared.
00691     // This check ensures that two preferences with the same name are not used.
00692     
00693 #ifdef _DEBUG
00694     pChunk = (PreferenceChunk *) ChunkList.GetHead();
00695     
00696     while (pChunk != NULL)
00697     {
00698         ERROR3IF_PF((pChunk->PrefExists(Pref) != FALSE), ( "Preference '%s' in section '%s' declared more than once", Pref, Section ) );
00699 
00700         pChunk = (PreferenceChunk *) ChunkList.GetNext(pChunk);
00701     }
00702     
00703 #endif
00704 
00705     // New chunks are added to the head of the list, so the partially unused one
00706     // is always the first in the list.
00707     pChunk = (PreferenceChunk *) ChunkList.GetHead();
00708     
00709     // Try to add the preference to this chunk.
00710     if (!pChunk->AddPref(Pref, PrefVar, Type))
00711     {
00712         // No room left in this chunk - try to get another one and put it in that.
00713         // The extension chunk is big enough to hold another 10 preferences (this is pretty
00714         // arbitrary).
00715         pChunk = new PreferenceChunk(10);
00716         
00717         if ((pChunk == NULL) || (!pChunk->Valid))
00718         {
00719             delete pChunk;
00720             return FALSE; // Failure - no memory left.
00721         }
00722             
00723         // Got a chunk ok, so add it to the head of the list.
00724         ChunkList.AddHead(pChunk);
00725         
00726         // Add the preference to it ('guaranteed' to work)
00727         pChunk->AddPref(Pref, PrefVar, Type);
00728     }
00729 
00730     // Try to read the preference
00731     if (OILPrefs != NULL)
00732         OILPrefs->Read(Section, Pref, Type, PrefVar);
00733     
00734     return TRUE;
00735 }
00736 
00737 /********************************************************************************************
00738 
00739 >   BOOL PreferenceSection::GetPrefValue(OILPreferences* OILPrefs,
00740                                          LPTCHAR Pref, PreferenceType Type, PrefData PrefVar)
00741 
00742     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00743     Created:    17/10/94
00744     Inputs:     Pref     - the name of the preference to add (e.g. "autosaveinterval")
00745                 Type     - the type of data used for this preference.
00746                 PrefVar  - pointer to the memory that holds this preference's data.
00747                 OILPrefs - the object to use to read the preference from the file.
00748     Outputs:    -
00749     Returns:    TRUE if the preference was read from the preference system successfully, 
00750                 FALSE otherwise.
00751     Purpose:    Reads a preference value from this PreferenceSection object by looking
00752                 through all the chunks in this section for the named preference.
00753     Errors:     -
00754     SeeAlso:    PreferenceSection::GetPrefValue
00755 
00756 ********************************************************************************************/
00757 
00758 BOOL PreferenceSection::GetPrefValue(OILPreferences* OILPrefs,
00759                                      LPTCHAR Pref, PreferenceType Type, PrefData PrefVar)
00760 {
00761 #if !defined(EXCLUDE_FROM_RALPH)
00762     // Used for scanning the chunk list
00763     PreferenceChunk *pChunk;
00764 
00765     // Check that this preference has not already been declared.
00766     // New chunks are added to the head of the list, so the partially unused one
00767     // is always the first in the list.
00768     pChunk = (PreferenceChunk *) ChunkList.GetHead();
00769     
00770     while (pChunk != NULL )
00771     {
00772         // Try to read the preference value from this chunk.
00773         if (pChunk->GetPrefValue(Pref, PrefVar, Type))
00774             return TRUE;        // The read went ok so return that value to the caller
00775 
00776         // Preference not in that chunk so move onto next chunk in list 
00777         pChunk = (PreferenceChunk *) ChunkList.GetNext(pChunk);
00778     }
00779 #endif
00780 
00781     return FALSE;       // Value was not read ok, not the correct type or not present
00782 }
00783 
00784 /********************************************************************************************
00785 
00786 >   BOOL PreferenceSection::SetPrefValue(OILPreferences* OILPrefs,
00787                                          LPTCHAR Pref, PreferenceType Type, PrefData PrefVar)
00788 
00789     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00790     Created:    17/10/94
00791     Inputs:     Pref     - the name of the preference to add (e.g. "autosaveinterval")
00792                 Type     - the type of data used for this preference.
00793                 PrefVar  - pointer to the memory that holds the new preference's data value.
00794                 OILPrefs - the object to use to read the preference from the file.
00795     Outputs:    -
00796     Returns:    TRUE if the preference was found in the preference system successfully and
00797                 the new value applied to it, FALSE otherwise.
00798     Purpose:    Finds a preference value from this PreferenceSection object by looking
00799                 through all the chunks in this section for the named preference and then sets
00800                 the value to the specifed new value.
00801     Errors:     -
00802     SeeAlso:    PreferenceSection::GetPrefValue
00803 
00804 ********************************************************************************************/
00805 
00806 BOOL PreferenceSection::SetPrefValue(OILPreferences* OILPrefs,
00807                                      LPTCHAR Pref, PreferenceType Type, PrefData PrefVar)
00808 {
00809 #if !defined(EXCLUDE_FROM_RALPH)
00810     // Used for scanning the chunk list
00811     PreferenceChunk *pChunk;
00812 
00813     // Check that this preference has not already been declared.
00814     // New chunks are added to the head of the list, so the partially unused one
00815     // is always the first in the list.
00816     pChunk = (PreferenceChunk *) ChunkList.GetHead();
00817     
00818     while (pChunk != NULL )
00819     {
00820         // Try to read the preference value from this chunk.
00821         if (pChunk->SetPrefValue(Pref, PrefVar, Type))
00822             return TRUE;        // The read went ok so return that value to the caller
00823 
00824         // Preference not in that chunk so move onto next chunk in list 
00825         pChunk = (PreferenceChunk *) ChunkList.GetNext(pChunk);
00826     }
00827 #endif
00828 
00829     return FALSE;       // Value was not set ok, not the correct type or not present
00830 }
00831 
00832 
00833 /********************************************************************************************
00834 
00835 >   void PreferenceSection::Write(OILPreferences* OILPrefs)
00836 
00837     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00838     Created:    17/8/93
00839     Inputs:     OILPrefs - the OIL object to use to write out the preferences with.
00840     Outputs:    -
00841     Returns:    -
00842     Purpose:    Writes all the preferences in this section out to the preference file,
00843                 using the OIL.
00844     Errors:     -
00845     SeeAlso:    -
00846 
00847 ********************************************************************************************/
00848 
00849 void PreferenceSection::Write(OILPreferences* OILPrefs)
00850 {
00851     // Write out each chunk in this section
00852     PreferenceChunk *pChunk = (PreferenceChunk *) ChunkList.GetHead();
00853     
00854     while (pChunk != NULL)
00855     {
00856         // Write out this chunk and move on to the next
00857         pChunk->Write(OILPrefs, Section);
00858         pChunk = (PreferenceChunk *) ChunkList.GetNext(pChunk); 
00859     }
00860 }
00861 
00862 #endif
00863 
00864 /********************************************************************************************
00865 
00866 >   Preferences::Preferences()
00867 
00868 
00869     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00870     Created:    17/8/93
00871     Inputs:     -
00872     Outputs:    -
00873     Returns:    -
00874     Purpose:    Initialises the section caching system.
00875     Errors:     -
00876     SeeAlso:    -
00877 
00878 ********************************************************************************************/
00879 
00880 Preferences::Preferences()
00881 {
00882     CurrentSection = NULL;
00883     OILPrefs       = NULL;
00884 }
00885 
00886 /********************************************************************************************
00887 
00888 >   Preferences::~Preferences()
00889 
00890     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00891     Created:    17/8/93
00892     Inputs:     -
00893     Outputs:    -
00894     Returns:    -
00895     Purpose:    Deletes all PreferenceSection objects used by this object.
00896     Errors:     -
00897     SeeAlso:    -
00898 
00899 ********************************************************************************************/
00900 
00901 Preferences::~Preferences()
00902 {
00903 #if !defined(EXCLUDE_FROM_RALPH)
00904     // Close the preferences file
00905     if (OILPrefs != NULL)
00906     {
00907         OILPrefs->CloseInput();
00908         delete OILPrefs;
00909     }
00910         
00911     PreferenceSection *pSection;
00912     
00913     // Delete all the sections for this preferences object
00914     do
00915     {
00916         // Unlink the first item from the list
00917         pSection = (PreferenceSection *) this->RemoveHead();
00918 
00919         // It doesn't matter if pSection is NULL - delete handles it
00920         delete pSection;
00921         
00922     } while (pSection != NULL);
00923 #endif
00924 }
00925 
00926     
00927 /********************************************************************************************
00928 
00929 >   void Preferences::Write()
00930 
00931     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00932     Created:    17/8/93
00933     Inputs:     -
00934     Outputs:    -
00935     Returns:    -
00936     Purpose:    This writes out all Camelot preferences to the application's preference
00937                 file, using the OIL.
00938     Errors:     -
00939     SeeAlso:    -
00940 
00941 ********************************************************************************************/
00942 
00943 void Preferences::Write()
00944 {
00945 #if !defined(EXCLUDE_FROM_RALPH)
00946     // First check if there is a valid OILPrefs, as if there was a problem on start up such as
00947     // the MSCVRTn.DLL failing to load then the preferences may have been not fully set up.
00948     // Static variable used as the class may not have been created!
00949     if (PrefsInitedOk && (OILPrefs != NULL))
00950     {
00951         // Perform any preparation necessary to start writing preferences
00952         OILPrefs->OpenOutput();
00953 
00954         // Write out all the sections for this preferences object
00955         PreferenceSection *pSection = (PreferenceSection *) this->GetHead();
00956     
00957         while (pSection != NULL)
00958         {
00959             // Write out this section and move on to the next
00960             pSection->Write(OILPrefs);
00961             pSection = (PreferenceSection *) this->GetNext(pSection);   
00962         }
00963 
00964         // Perform any platform-deppy clean-up required after writing the preferences
00965         OILPrefs->CloseOutput();
00966     }
00967 #endif
00968 }
00969     
00970 /********************************************************************************************
00971 
00972 >   BOOL Preferences::Init()
00973 
00974     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00975     Created:    17/8/93
00976     Inputs:     -
00977     Outputs:    -
00978     Returns:    TRUE if ok, FALSE if an error occured.
00979     Purpose:    This initialises the Preferences object.  This includes setting up a link
00980                 to the OIL and opening the preference file for reading.
00981     Errors:     -
00982     SeeAlso:    Preferences::Deinit; OILPreferences
00983 
00984 ********************************************************************************************/
00985 
00986 BOOL Preferences::Init()
00987 {
00988 #if !defined(EXCLUDE_FROM_RALPH)
00989     // Create a link to the OIL
00990     OILPrefs = OILPreferences::Init();
00991     
00992     // Flag error if it failed
00993     if (OILPrefs == NULL)
00994         return FALSE;
00995 
00996     PrefsInitedOk = TRUE;
00997 
00998     // Initialise the preference file for reading
00999     return OILPrefs->OpenInput();
01000 
01001 #else //EXCLUDE_FROM_RALPH
01002     // Be gone you pesky prefs system :-)
01003     OILPrefs = NULL;
01004     PrefsInitedOk = FALSE;
01005     return TRUE;
01006 #endif //EXCLUDE_FROM_RALPH
01007 }
01008 
01009 /********************************************************************************************
01010 
01011 >   void Preferences::Deinit()
01012 
01013     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01014     Created:    17/8/93
01015     Inputs:     -
01016     Outputs:    -
01017     Returns:    TRUE if ok, FALSE if an error occured.
01018     Purpose:    This de-initialises the Preferences object.  This includes closing down
01019                 whatever OIL mechanisms were set up by Init().
01020     Errors:     -
01021     SeeAlso:    Preferences::Init; OILPreferences
01022 
01023 ********************************************************************************************/
01024 
01025 void Preferences::Deinit()
01026 {
01027 #if !defined(EXCLUDE_FROM_RALPH)
01028     // Close the preferences file
01029     if (OILPrefs != NULL)
01030         OILPrefs->CloseInput();
01031 #endif
01032 }
01033 
01034 /********************************************************************************************
01035 
01036 >   void Preferences::WipePreferenceFile()
01037 
01038     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01039     Created:    24/11/93
01040     Purpose:    Used to remove an old (possibly incompatible) preference file.  It assumes
01041                 that the preference system has been initialised and that it is still
01042                 active (i.e. Deinit() has not been called).
01043     Errors:     -
01044     SeeAlso:    -
01045 
01046 ********************************************************************************************/
01047 
01048 void Preferences::WipePreferenceFile()
01049 {
01050 #if !defined(EXCLUDE_FROM_RALPH)
01051     ENSURE(OILPrefs != NULL, "OILPreferences system not initialised");
01052 
01053     // Close the file, clear it, and re-open it
01054     OILPrefs->CloseInput();
01055     OILPrefs->WipePreferenceFile();
01056     OILPrefs->OpenInput();
01057 #endif
01058 }
01059 
01060 /********************************************************************************************
01061 
01062 >   void Preferences::WipePreferenceFile()
01063 
01064     Author:     Chris_Gallimore (Xara Group Ltd) <camelotdev@xara.com>
01065     Created:    8/2/2001
01066     Purpose:    Used to remove any dangerous sections from the registry, when upgrading from
01067                 an old version
01068     SeeAlso:    Application::WipeDangerousPrefs
01069 
01070 ********************************************************************************************/
01071 
01072 void Preferences::WipeDangerousPrefs()
01073 {
01074 #if !defined(EXCLUDE_FROM_RALPH)
01075     ENSURE(OILPrefs != NULL, "OILPreferences system not initialised");
01076 
01077     OILPrefs->WipeDangerousPrefs();
01078 #endif
01079 }
01080 
01081 /********************************************************************************************
01082 
01083 >   BOOL Preferences::DeclareSection(LPTCHAR Section, UINT32 InitialSize)
01084 
01085     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01086     Created:    17/8/93
01087     Inputs:     Section     - name of the section being declared.
01088                 InitialSize - caller's estimate of how many preferences will be stored in
01089                               this section.
01090     Outputs:    -
01091     Returns:    TRUE if the section was created successfully, FALSE otherwise.
01092                 NB. If the section is subsequently re-declared, this function does nothing,
01093                     but returns TRUE.
01094     Purpose:    This should be used to declare a new preference section to the system.
01095                 No preferences of this section can be declared until the section itself
01096                 has been declared.
01097     Errors:     -
01098     SeeAlso:    -
01099 
01100 ********************************************************************************************/
01101 
01102 BOOL Preferences::DeclareSection(LPTCHAR Section, UINT32 InitialSize)
01103 {
01104 #if !defined(EXCLUDE_FROM_RALPH)
01105     // Check that somebody is not trying to define a null section name or a zero length
01106     // string as this may cause problems in the string compares. (make it one or less for now)
01107     ERROR2IF(((Section == NULL) || (camStrclen(Section) <= 1)), FALSE, _R(IDN_BAD_DECLARE_SECTION));
01108 
01109     PreferenceSection* pSection = NULL;
01110 
01111     // Make sure this section hasn't already been declared
01112     pSection = GetSection(Section);
01113     if (pSection != NULL)
01114     {
01115         CurrentSection = pSection;
01116         return TRUE; // Should this be an error condition?
01117     }
01118         
01119     // Add a new section
01120     pSection = new PreferenceSection(Section, InitialSize);
01121     if ((pSection == NULL) || (!pSection->Valid))
01122     {
01123         // Not enough memory to do this
01124         delete pSection;
01125         return FALSE;
01126     }
01127     
01128     // It all worked, so add this section to the list, remember it for future use,
01129     // and return success.
01130     this->AddHead(pSection);
01131     CurrentSection = pSection;
01132     return TRUE;
01133 #else
01134     // Bodge so all hell doesn't break loose :-)
01135     return TRUE;
01136 #endif
01137 }
01138     
01139 /********************************************************************************************
01140 
01141 >   BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, 
01142                                   INT32 *PrefVar, INT32 Min, INT32 Max)
01143 
01144     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01145     Created:    17/8/93
01146     Inputs:     Section - the case-insensitive name of the section in which this preference
01147                           should be placed, (e.g. "Printing").
01148                 Pref    - the case-insensitive name of this preference 
01149                           (e.g. "AutoSaveInterval").
01150                 PrefVar - pointer to the integer variable that holds this preference's value.
01151                 Min,Max - Legal range for this value - if the preferences file holds a value
01152                           outside this range, it is ignored and the default value is used
01153                           instead.
01154     Outputs:    PrefVar - contains the value found in the preference file for this
01155                           preference.  If no such preference was found, the value is
01156                           unchanged.
01157     Returns:    TRUE if the preference was added to the preference system successfully,
01158                 FALSE otherwise.
01159     Purpose:    Declares a preference to the preference system.
01160     
01161                 This has two effects:
01162                 
01163                     + When this function returns, if this preference was found in the
01164                       preference file that was read on start-up, then the PrefVar variable
01165                       is filled in with the value from this file.
01166                       
01167                     + Whenever the preferences are saved (via Preferences::Write(), which
01168                       would happen on application exit, or when the user chooses "Save
01169                       Preferences"), this named preference is saved into the named section,
01170                       using whatever value the PrefVar points to *when the preferences
01171                       are saved*.
01172     Errors:     -
01173     SeeAlso:    -
01174 
01175 ********************************************************************************************/
01176 
01177 BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, 
01178                               INT32 *PrefVar, INT32 Min, INT32 Max)
01179 {
01180 #if !defined(EXCLUDE_FROM_RALPH)
01181     // Find the right section
01182     PreferenceSection *pSection = GetSection(Section);
01183     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01184 
01185     // Add the preference to the right section      
01186     PrefData Data;
01187     Data.pInt = PrefVar;
01188     
01189     // Remember default value
01190     INT32 Default = *PrefVar;
01191     
01192     if (!pSection->AddPref(OILPrefs, Pref, PREF_INT, Data))
01193     {
01194         *PrefVar = Default;
01195         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01196         return FALSE;                       // Something went wrong
01197     }
01198 
01199     // Ensure value is within specified range   
01200     if (*PrefVar < Min)
01201         *PrefVar = Min;
01202     if (*PrefVar > Max)
01203         *PrefVar = Max;
01204 #endif
01205     
01206     return TRUE;
01207 }
01208 
01209 /********************************************************************************************
01210 
01211 >   BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, 
01212                                   UINT32 *PrefVar, UINT32 Min, UINT32 Max)
01213 
01214     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01215     Created:    17/8/93
01216     Inputs:     Section - the case-insensitive name of the section in which this preference
01217                           should be placed, (e.g. "Printing").
01218                 Pref    - the case-insensitive name of this preference 
01219                           (e.g. "AutoSaveInterval").
01220                 PrefVar - pointer to the unsigned integer variable that holds this 
01221                           preference's value.
01222                 Min,Max - Legal range for this value - if the preferences file holds a value
01223                           outside this range, it is ignored and the default value is used
01224                           instead.
01225     Outputs:    PrefVar - contains the value found in the preference file for this
01226                           preference.  If no such preference was found, the value is
01227                           unchanged.
01228     Returns:    TRUE if the preference was added to the preference system successfully,
01229                 FALSE otherwise.
01230     Purpose:    Declares a preference to the preference system.
01231     
01232                 This has two effects:
01233                 
01234                     + When this function returns, if this preference was found in the
01235                       preference file that was read on start-up, then the PrefVar variable
01236                       is filled in with the value from this file.
01237                       
01238                     + Whenever the preferences are saved (via Preferences::Write(), which
01239                       would happen on application exit, or when the user chooses "Save
01240                       Preferences"), this named preference is saved into the named section,
01241                       using whatever value the PrefVar points to *when the preferences
01242                       are saved*.
01243     Errors:     -
01244     SeeAlso:    -
01245 
01246 ********************************************************************************************/
01247 
01248 BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, 
01249                               UINT32 *PrefVar, UINT32 Min, UINT32 Max)
01250 {
01251 #if !defined(EXCLUDE_FROM_RALPH)
01252     // Find the right section
01253     PreferenceSection *pSection = GetSection(Section);
01254     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01255 
01256     // Add the preference to the right section      
01257     PrefData Data;
01258     Data.pUInt = PrefVar;
01259     
01260     // Remember default value
01261     UINT32 Default = *PrefVar;
01262     
01263     if (!pSection->AddPref(OILPrefs, Pref, PREF_UINT, Data))
01264     {
01265         *PrefVar = Default;
01266         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01267         return FALSE; // Something went wrong
01268     }
01269 
01270     // Ensure value is within specified range   
01271     if (*PrefVar < Min)
01272         *PrefVar = Min;
01273     if (*PrefVar > Max)
01274         *PrefVar = Max;
01275 #endif      
01276     return TRUE;
01277 }
01278 
01279 /********************************************************************************************
01280 
01281 >   BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, double *PrefVar)
01282 
01283     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01284     Created:    17/8/93
01285     Inputs:     Section - the case-insensitive name of the section in which this preference
01286                           should be placed, (e.g. "Printing").
01287                 Pref    - the case-insensitive name of this preference 
01288                           (e.g. "AutoSaveInterval").
01289                 PrefVar - pointer to the floating point variable that holds this preference's
01290                           value.
01291                 Min,Max - Legal range for this value - if the preferences file holds a value
01292                           outside this range, it is ignored and the default value is used
01293                           instead.
01294     Outputs:    PrefVar - contains the value found in the preference file for this
01295                           preference.  If no such preference was found, the value is
01296                           unchanged.
01297     Returns:    TRUE if the preference was added to the preference system successfully,
01298                 FALSE otherwise.
01299     Purpose:    Declares a preference to the preference system.
01300     
01301                 This has two effects:
01302                 
01303                     + When this function returns, if this preference was found in the
01304                       preference file that was read on start-up, then the PrefVar variable
01305                       is filled in with the value from this file.
01306                       
01307                     + Whenever the preferences are saved (via Preferences::Write(), which
01308                       would happen on application exit, or when the user chooses "Save
01309                       Preferences"), this named preference is saved into the named section,
01310                       using whatever value the PrefVar points to *when the preferences
01311                       are saved*.
01312                       
01313                 Note that doubles are stored to 20 decimal places in the preference file.
01314                 Of course, how many of these are accurate depends on the value, e.g.
01315                 
01316                  2372645745823.3476354716324 would not be stored completely accurately
01317                  whereas 23.3245345646 probably would.
01318                  
01319     Errors:     -
01320     SeeAlso:    -
01321 
01322 ********************************************************************************************/
01323 
01324 BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, 
01325                               double *PrefVar, double Min, double Max)
01326 {
01327 #if !defined(EXCLUDE_FROM_RALPH)
01328     // Find the right section
01329     PreferenceSection *pSection = GetSection(Section);
01330     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01331 
01332     // Add the preference to the right section      
01333     PrefData Data;
01334     Data.pDouble = PrefVar;
01335     
01336     // Remember default value
01337     double Default = *PrefVar;
01338     
01339     if (!pSection->AddPref(OILPrefs, Pref, PREF_DOUBLE, Data))
01340     {
01341         *PrefVar = Default;
01342         ERROR(_R(IDE_BAD_INI_FILE), FALSE);     // Something went wrong
01343     }
01344 
01345     // Ensure value is within specified range   
01346     if (*PrefVar < Min)
01347         *PrefVar = Min;
01348     if (*PrefVar > Max)
01349         *PrefVar = Max;
01350 #endif      
01351     return TRUE;
01352 }
01353 
01354 /********************************************************************************************
01355 
01356 >   BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, StringBase *PrefVar)
01357 
01358     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01359     Created:    17/8/93
01360     Inputs:     Section - the case-insensitive name of the section in which this preference
01361                           should be placed, (e.g. "Printing").
01362                 Pref    - the case-insensitive name of this preference 
01363                           (e.g. "AutoSaveInterval").
01364                 PrefVar - pointer to the character buffer that holds this preference's value.
01365     Outputs:    PrefVar - contains the value found in the preference file for this
01366                           preference.  If no such preference was found, the value is
01367                           unchanged.
01368     Returns:    TRUE if the preference was added to the preference system successfully,
01369                 FALSE otherwise.
01370     Purpose:    Declares a preference to the preference system.
01371     
01372                 This has two effects:
01373                 
01374                     + When this function returns, if this preference was found in the
01375                       preference file that was read on start-up, then the PrefVar variable
01376                       is filled in with the value from this file.
01377                       
01378                     + Whenever the preferences are saved (via Preferences::Write(), which
01379                       would happen on application exit, or when the user chooses "Save
01380                       Preferences"), this named preference is saved into the named section,
01381                       using whatever value the PrefVar points to *when the preferences
01382                       are saved*.
01383     Errors:     -
01384     SeeAlso:    -
01385 
01386 ********************************************************************************************/
01387 
01388 BOOL Preferences::DeclarePref(LPTCHAR Section, LPTCHAR Pref, StringBase *PrefVar)
01389 {
01390 #if !defined(EXCLUDE_FROM_RALPH)
01391     // Find the right section
01392     PreferenceSection *pSection = GetSection(Section);
01393     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01394 
01395     // Add the preference to the right section
01396     PrefData Data;
01397     Data.pString = PrefVar;
01398     ERRORIF(!pSection->AddPref(OILPrefs, Pref, PREF_STRING, Data), _R(IDE_BAD_INI_FILE), FALSE);
01399 #endif
01400     return TRUE;
01401 }
01402 
01403 /********************************************************************************************
01404 
01405 >   PreferenceSection *Preferences::GetSection(LPTCHAR SectionName)
01406 
01407     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01408     Created:    17/8/93
01409     Inputs:     SectionName - the name of the section to find.
01410     Outputs:    -
01411     Returns:    A pointer to the PreferenceSection object that corresponds to the section
01412                 name specified, or NULL if no such section has yet been declared.
01413     Purpose:    Given a section name, this function will find the PreferenceSection object
01414                 that stores the preferences for this section.
01415     Errors:     -
01416     SeeAlso:    -
01417 
01418 ********************************************************************************************/
01419 
01420 PreferenceSection *Preferences::GetSection(LPTCHAR SectionName)
01421 {
01422 #if !defined(EXCLUDE_FROM_RALPH)
01423 #ifdef _DEBUG
01424     if ((SectionName != NULL) &&
01425         ((camStrnicmp(SectionName, _T("blobby"), 7) == 0) ||
01426          (camStrnicmp(SectionName, _T("wobjob"), 7) == 0)))
01427     {
01428         // Silly names not allowed
01429         ENSURE(FALSE, "Preference section has suffered a cliche overload");
01430         abort();
01431     }
01432 #endif
01433 
01434     // Check that somebody is not trying to use a null section name when there
01435     // is no current section set up 
01436     ERROR2IF((CurrentSection == NULL)
01437               && (SectionName == NULL), NULL, _R(IDN_BAD_CURRENT_SECTION));
01438     
01439     // A null section name means use the MRU section.
01440     if (SectionName == NULL)
01441         return CurrentSection;
01442 
01443     // Check that the specified section name is not specified as a zero length string
01444     // otherwise this could screw up the name comparing. Duplicate null check just in
01445     // case check above is removed.
01446     ERROR2IF(((SectionName != NULL) &&
01447              (camStrclen(SectionName) <= 1)), NULL, _R(IDN_BAD_CURRENT_SECTION));
01448         
01449     // Do a quick check to see if it is the cached section.
01450     if ((CurrentSection != NULL) && 
01451         (camStricmp(SectionName, CurrentSection->Section) == 0))
01452         // It's the same one as we tried last time.
01453         return CurrentSection;
01454         
01455     // Search the list for the right section
01456 
01457     PreferenceSection *pSection = (PreferenceSection *) this->GetHead();
01458     
01459     while (pSection != NULL)
01460     {
01461         if (camStricmp(SectionName, pSection->Section) == 0)
01462         {
01463             // Found the right section - remember it for next time and return it.
01464             CurrentSection = pSection;
01465             return pSection;
01466         }
01467             
01468         // Try the next one in the list
01469         pSection = (PreferenceSection *) this->GetNext(pSection);
01470     }
01471 #endif
01472     
01473     // Didn't find it...
01474     return NULL;
01475 }
01476 
01477 
01478 
01479 
01480 /********************************************************************************************
01481 
01482 >   BOOL Preferences::GetPrefValue(LPTCHAR Section, LPTCHAR Pref, INT32 *PrefVar)
01483 
01484     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01485     Created:    17/10/94
01486     Inputs:     Section - the case-insensitive name of the section in which this preference
01487                           should be placed, (e.g. "Printing").
01488                 Pref    - the case-insensitive name of this preference 
01489                           (e.g. "AutoSaveInterval").
01490                 PrefVar - pointer to the integer variable that holds this preference's value.
01491     Outputs:    PrefVar - contains the value found in the preference file for this
01492                           preference.  If no such preference was found, the value is
01493                           unchanged.
01494     Returns:    TRUE if the preference was found in the preference system successfully,
01495                 FALSE otherwise.
01496     Purpose:    Finds the value of the specified preference which should already be defined in
01497                 the preference system and returns it in the variable PrefVar. 
01498                 This is used by interested parties other than the owner of that preference
01499                 value e.g. the application options dialog box.
01500     
01501     Errors:     -
01502     SeeAlso:    Preferences::SetPrefValue
01503 
01504 ********************************************************************************************/
01505 
01506 BOOL Preferences::GetPrefValue(LPTCHAR Section, LPTCHAR Pref, INT32 *PrefVar)
01507 {
01508 #if !defined(EXCLUDE_FROM_RALPH)
01509     // Find the right section, error if not found and return FALSE
01510     PreferenceSection *pSection = GetSection(Section);
01511     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01512 
01513     // Set up the data structure required to read the preference value      
01514     PrefData Data;
01515     Data.pInt = PrefVar;
01516     
01517     // Remember default value
01518     INT32 Default = *PrefVar;
01519     
01520     if (!pSection->GetPrefValue(OILPrefs, Pref, PREF_INT, Data))
01521     {
01522         *PrefVar = Default;
01523         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01524         return FALSE;                       // Something went wrong
01525     }
01526     
01527     // Value found should have been placed in PrefVar 
01528 
01529     *PrefVar = *Data.pInt;
01530 #endif
01531     return TRUE;
01532 }
01533 
01534 /********************************************************************************************
01535 
01536 >   BOOL Preferences::GetPrefValue(LPTCHAR Section, LPTCHAR Pref, UINT32 *PrefVar)
01537 
01538     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01539     Created:    17/10/94
01540     Inputs:     Section - the case-insensitive name of the section in which this preference
01541                           should be placed, (e.g. "Printing").
01542                 Pref    - the case-insensitive name of this preference 
01543                           (e.g. "AutoSaveInterval").
01544                 PrefVar - pointer to the unsigned integer variable that holds this
01545                           preference's value.
01546     Outputs:    PrefVar - contains the value found in the preference file for this
01547                           preference.  If no such preference was found, the value is
01548                           unchanged.
01549     Returns:    TRUE if the preference was found in the preference system successfully,
01550                 FALSE otherwise.
01551     Purpose:    Finds the value of the specified preference which should already be defined in
01552                 the preference system and returns it in the variable PrefVar. 
01553                 This is used by interested parties other than the owner of that preference
01554                 value e.g. the application options dialog box.
01555     
01556     Errors:     -
01557     SeeAlso:    Preferences::SetPrefValue
01558 
01559 ********************************************************************************************/
01560 
01561 BOOL Preferences::GetPrefValue(LPTCHAR Section, LPTCHAR Pref, UINT32 *PrefVar)
01562 {
01563 #if !defined(EXCLUDE_FROM_RALPH)
01564     // Find the right section, error if not found and return FALSE
01565     PreferenceSection *pSection = GetSection(Section);
01566     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01567 
01568     // Set up the data structure required to read the preference value      
01569     PrefData Data;
01570     Data.pUInt = PrefVar;
01571     
01572     // Remember default value
01573     UINT32 Default = *PrefVar;
01574     
01575     if (!pSection->GetPrefValue(OILPrefs, Pref, PREF_UINT, Data))
01576     {
01577         *PrefVar = Default;
01578         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01579         return FALSE;                       // Something went wrong
01580     }
01581     
01582     // Value found should have been placed in PrefVar 
01583 
01584     *PrefVar = *Data.pUInt;
01585 #endif
01586     return TRUE;
01587 }
01588 
01589 /********************************************************************************************
01590 
01591 >   BOOL Preferences::GetPrefValue(LPTCHAR Section, LPTCHAR Pref, double *PrefVar)
01592 
01593     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01594     Created:    17/10/94
01595     Inputs:     Section - the case-insensitive name of the section in which this preference
01596                           should be placed, (e.g. "Printing").
01597                 Pref    - the case-insensitive name of this preference 
01598                           (e.g. "AutoSaveInterval").
01599                 PrefVar - pointer to the double variable that holds this preference's value.
01600     Outputs:    PrefVar - contains the value found in the preference file for this
01601                           preference.  If no such preference was found, the value is
01602                           unchanged.
01603     Returns:    TRUE if the preference was found in the preference system successfully,
01604                 FALSE otherwise.
01605     Purpose:    Finds the value of the specified preference which should already be defined in
01606                 the preference system and returns it in the variable PrefVar. 
01607                 This is used by interested parties other than the owner of that preference
01608                 value e.g. the application options dialog box.
01609     
01610     Errors:     -
01611     SeeAlso:    Preferences::SetPrefValue
01612 
01613 ********************************************************************************************/
01614 
01615 BOOL Preferences::GetPrefValue(LPTCHAR Section, LPTCHAR Pref, double *PrefVar)
01616 {
01617 #if !defined(EXCLUDE_FROM_RALPH)
01618     // Find the right section, error if not found and return FALSE
01619     PreferenceSection *pSection = GetSection(Section);
01620     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01621 
01622     // Set up the data structure required to read the preference value      
01623     PrefData Data;
01624     Data.pDouble = PrefVar;
01625     
01626     // Remember default value
01627     double Default = *PrefVar;
01628     
01629     if (!pSection->GetPrefValue(OILPrefs, Pref, PREF_DOUBLE, Data))
01630     {
01631         *PrefVar = Default;
01632         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01633         return FALSE;                       // Something went wrong
01634     }
01635     
01636     // Value found should have been placed in PrefVar 
01637 
01638     *PrefVar = *Data.pDouble;
01639 #endif
01640     return TRUE;
01641 }
01642 
01643 /********************************************************************************************
01644 
01645 >   BOOL Preferences::SetPrefValue(LPTCHAR Section, LPTCHAR Pref, INT32 *PrefVar)
01646 
01647     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01648     Created:    17/10/94
01649     Inputs:     Section - the case-insensitive name of the section in which this preference
01650                           should be placed, (e.g. "Printing").
01651                 Pref    - the case-insensitive name of this preference 
01652                           (e.g. "AutoSaveInterval").
01653                 PrefVar - pointer to the integer variable that holds this preference's value.
01654     Outputs:    PrefVar - contains the value found in the preference file for this
01655                           preference.  If no such preference was found, the value is
01656                           unchanged.
01657     Returns:    TRUE if the preference was found in the preference system successfully,
01658                 FALSE otherwise.
01659     Purpose:    Finds the value of the specified preference which should already be defined in
01660                 the preference system and then writes the new value specified into that 
01661                 variable.
01662                 This is used by interested parties other than the owner of that preference
01663                 value e.g. the application options dialog box.
01664     
01665     Errors:     -
01666     SeeAlso:    Preferences::GetPrefValue
01667 
01668 ********************************************************************************************/
01669 
01670 BOOL Preferences::SetPrefValue(LPTCHAR Section, LPTCHAR Pref, INT32 *PrefVar)
01671 {
01672 #if !defined(EXCLUDE_FROM_RALPH)
01673     // Find the right section, error if not found and return FALSE
01674     PreferenceSection *pSection = GetSection(Section);
01675     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01676 
01677     // Set up the data structure required to pass the new preference value
01678     // in with      
01679     PrefData Data;
01680     Data.pInt = PrefVar;
01681     
01682     if (!pSection->SetPrefValue(OILPrefs, Pref, PREF_INT, Data))
01683     {
01684         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01685         return FALSE;                       // Something went wrong
01686     }
01687 #endif  
01688     return TRUE;
01689 }
01690 
01691 /********************************************************************************************
01692 
01693 >   BOOL Preferences::SetPrefValue(LPTCHAR Section, LPTCHAR Pref, UINT32 *PrefVar)
01694 
01695     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01696     Created:    17/10/94
01697     Inputs:     Section - the case-insensitive name of the section in which this preference
01698                           should be placed, (e.g. "Printing").
01699                 Pref    - the case-insensitive name of this preference 
01700                           (e.g. "AutoSaveInterval").
01701                 PrefVar - pointer to the unsigned integer variable that holds this
01702                           preference's value.
01703     Outputs:    PrefVar - contains the value found in the preference file for this
01704                           preference.  If no such preference was found, the value is
01705                           unchanged.
01706     Returns:    TRUE if the preference was found in the preference system successfully,
01707                 FALSE otherwise.
01708     Purpose:    Finds the value of the specified preference which should already be defined in
01709                 the preference system and then writes the new value specified into that 
01710                 variable.
01711                 This is used by interested parties other than the owner of that preference
01712                 value e.g. the application options dialog box.
01713     
01714     Errors:     -
01715     SeeAlso:    Preferences::GetPrefValue
01716 
01717 ********************************************************************************************/
01718 
01719 BOOL Preferences::SetPrefValue(LPTCHAR Section, LPTCHAR Pref, UINT32 *PrefVar)
01720 {
01721 #if !defined(EXCLUDE_FROM_RALPH)
01722     // Find the right section, error if not found and return FALSE
01723     PreferenceSection *pSection = GetSection(Section);
01724     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01725 
01726     // Set up the data structure required to pass the new preference value
01727     // in with      
01728     PrefData Data;
01729     Data.pUInt = PrefVar;
01730     
01731     if (!pSection->SetPrefValue(OILPrefs, Pref, PREF_UINT, Data))
01732     {
01733         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01734         return FALSE;                       // Something went wrong
01735     }
01736 #endif  
01737     return TRUE;
01738 }
01739 /********************************************************************************************
01740 
01741 >   BOOL Preferences::SetPrefValue(LPTCHAR Section, LPTCHAR Pref, double *PrefVar)
01742 
01743     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01744     Created:    17/10/94
01745     Inputs:     Section - the case-insensitive name of the section in which this preference
01746                           should be placed, (e.g. "Printing").
01747                 Pref    - the case-insensitive name of this preference 
01748                           (e.g. "AutoSaveInterval").
01749                 PrefVar - pointer to the double variable that holds this preference's value.
01750     Outputs:    PrefVar - contains the value found in the preference file for this
01751                           preference.  If no such preference was found, the value is
01752                           unchanged.
01753     Returns:    TRUE if the preference was found in the preference system successfully,
01754                 FALSE otherwise.
01755     Purpose:    Finds the value of the specified preference which should already be defined in
01756                 the preference system and then writes the new value specified into that 
01757                 variable.
01758                 This is used by interested parties other than the owner of that preference
01759                 value e.g. the application options dialog box.
01760     
01761     Errors:     -
01762     SeeAlso:    Preferences::GetPrefValue
01763 
01764 ********************************************************************************************/
01765 
01766 BOOL Preferences::SetPrefValue(LPTCHAR Section, LPTCHAR Pref, double *PrefVar)
01767 {
01768 #if !defined(EXCLUDE_FROM_RALPH)
01769     // Find the right section, error if not found and return FALSE
01770     PreferenceSection *pSection = GetSection(Section);
01771     ERRORIF(!pSection, _R(IDE_BAD_INI_FILE), FALSE);
01772 
01773     // Set up the data structure required to pass the new preference value
01774     // in with      
01775     PrefData Data;
01776     Data.pDouble = PrefVar;
01777     
01778     if (!pSection->SetPrefValue(OILPrefs, Pref, PREF_DOUBLE, Data))
01779     {
01780         ERROR(_R(IDE_BAD_INI_FILE), FALSE);
01781         return FALSE;                       // Something went wrong
01782     }
01783 #endif  
01784     return TRUE;
01785 }
01786 
01787 
01788 /********************************************************************************************
01789 
01790 >   BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, const TCHAR *pValue, BOOL Force)
01791 
01792     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01793     Created:    06/01/95
01794     Inputs:     Section, Pref - the preference to write.
01795                 pValue - the value to write to the preference.
01796                 Force - TRUE => always write the specified preference out
01797                        FALSE => only write the preference if it doesn't already exist.
01798     Returns:    TRUE if written ok;
01799                 FALSE if not.
01800     Purpose:    Write a preference to the preference file directly, without 'declaring'
01801                 an associated preference.  This can be used just to ensure that a 
01802                 default value for the preference is in the file - if Force is FALSE, then
01803                 if the preference already exists it is not changed.
01804     SeeAlso:    Preferences::GetPrefDirect
01805 
01806 ********************************************************************************************/
01807 
01808 BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, const TCHAR *pValue, BOOL Force)
01809 {
01810 #if !defined(EXCLUDE_FROM_RALPH)
01811     // First check if there is a valid OILPrefs, as if there was a problem on start up such as
01812     // the MSCVRTn.DLL failing to load then the preferences may have been not fully set up.
01813     // Static variable used as the class may not have been created!
01814     if (PrefsInitedOk && (OILPrefs != NULL))
01815     {
01816         String_256 PrefValue;
01817         PrefData Data;
01818         Data.pString = &PrefValue;
01819 
01820         // Check to see if we need to change the preference
01821         if (!Force)
01822         {
01823             // First, try to read the preference
01824             OILPrefs->OpenInput();
01825             OILPrefs->Read(Section, Pref, PREF_STRING, Data);
01826             OILPrefs->CloseInput();
01827 
01828             if (Data.pString->Length() > 0)
01829                 // Preference already exists - do nothing
01830                 return TRUE;
01831         }
01832 
01833         // Perform any preparation necessary to start writing preferences
01834         OILPrefs->OpenOutput();
01835 
01836         // Write out the preference...
01837         PrefValue = pValue;
01838         OILPrefs->Write(Section, Pref, PREF_STRING, Data);
01839 
01840         // Perform any platform-deppy clean-up required after writing the preferences
01841         OILPrefs->CloseOutput();
01842 
01843         // All done
01844         return TRUE;
01845     }
01846 #endif
01847     // Something went wrong
01848     return FALSE;
01849 }
01850 
01851 /********************************************************************************************
01852 
01853 >   BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, PreferenceType Type, PrefData Data)
01854 
01855     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01856     Created:    25/03/97
01857     Inputs:     Section, Pref - the preference to write.
01858                 pValue - the value to write to the preference.
01859     Returns:    TRUE if written ok;
01860                 FALSE if not.
01861     Purpose:    Write a preference to the preference file directly, without 'declaring'
01862                 an associated preference.  This can be used just to ensure that a 
01863                 default value for the preference is in the file.
01864     SeeAlso:    Preferences::GetPrefDirect
01865 
01866 ********************************************************************************************/
01867 
01868 BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, PreferenceType Type, PrefData Data)
01869 {
01870 #if !defined(EXCLUDE_FROM_RALPH)
01871     // First check if there is a valid OILPrefs, as if there was a problem on start up such as
01872     // the MSCVRTn.DLL failing to load then the preferences may have been not fully set up.
01873     // Static variable used as the class may not have been created!
01874     if (PrefsInitedOk && (OILPrefs != NULL))
01875     {
01876         // Perform any preparation necessary to start writing preferences
01877         OILPrefs->OpenOutput();
01878 
01879         // Write out the preference...
01880         OILPrefs->Write(Section, Pref, Type, Data);
01881 
01882         // Perform any platform-deppy clean-up required after writing the preferences
01883         OILPrefs->CloseOutput();
01884 
01885         // All done
01886         return TRUE;
01887     }
01888 #endif
01889     // Something went wrong
01890     return FALSE;
01891 }
01892 
01893 /********************************************************************************************
01894 
01895 >   BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, INT32 *pValue)
01896 
01897     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01898     Created:    25/03/97
01899     Inputs:     Section, Pref - the preference to write.
01900                 pValue - the value to write to the preference.
01901     Returns:    TRUE if written ok;
01902                 FALSE if not.
01903     Purpose:    Write a preference to the preference file directly, without 'declaring'
01904                 an associated preference.  This can be used just to ensure that a 
01905                 default value for the preference is in the file.
01906     SeeAlso:    Preferences::GetPrefDirect
01907 
01908 ********************************************************************************************/
01909 
01910 BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, INT32 *pValue)
01911 {
01912     PrefData Data;
01913     Data.pInt = pValue;
01914     return SetPrefDirect(Section, Pref, PREF_INT, Data);
01915 }
01916 
01917 /********************************************************************************************
01918 
01919 >   BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, UINT32 *pValue)
01920 
01921     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01922     Created:    25/03/97
01923     Inputs:     Section, Pref - the preference to write.
01924                 pValue - the value to write to the preference.
01925     Returns:    TRUE if written ok;
01926                 FALSE if not.
01927     Purpose:    Write a preference to the preference file directly, without 'declaring'
01928                 an associated preference.  This can be used just to ensure that a 
01929                 default value for the preference is in the file.
01930     SeeAlso:    Preferences::GetPrefDirect
01931 
01932 ********************************************************************************************/
01933 
01934 BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, UINT32 *pValue)
01935 {
01936     PrefData Data;
01937     Data.pUInt = pValue;
01938     return SetPrefDirect(Section, Pref, PREF_UINT, Data);
01939 }
01940 
01941 /********************************************************************************************
01942 
01943 >   BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, double *pValue)
01944 
01945     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01946     Created:    25/03/97
01947     Inputs:     Section, Pref - the preference to write.
01948                 pValue - the value to write to the preference.
01949     Returns:    TRUE if written ok;
01950                 FALSE if not.
01951     Purpose:    Write a preference to the preference file directly, without 'declaring'
01952                 an associated preference.  This can be used just to ensure that a 
01953                 default value for the preference is in the file.
01954     SeeAlso:    Preferences::GetPrefDirect
01955 
01956 ********************************************************************************************/
01957 
01958 BOOL Preferences::SetPrefDirect(LPTCHAR Section, LPTCHAR Pref, double *pValue)
01959 {
01960     PrefData Data;
01961     Data.pDouble = pValue;
01962     return SetPrefDirect(Section, Pref, PREF_DOUBLE, Data);
01963 }
01964 
01965 /********************************************************************************************
01966 
01967 >   BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, PreferenceType Type, PrefData Data)
01968 
01969     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01970     Created:    25/03/97
01971     Inputs:     Section, Pref - the preference to write.
01972                 pValue - the value to write to the preference.
01973                 BufSize - number of bytes in the buffer pointed to by pValue.
01974     Returns:    TRUE if the preference exists and was small enough to fit in the buffer.
01975                 FALSE if the preference does not exist or could not fit in the buffer.
01976     Purpose:    Read a preference from the file directly, without the need to declare a
01977                 preference beforehand.
01978     SeeAlso:    Preferences::SetPrefDirect
01979 
01980 ********************************************************************************************/
01981 
01982 BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, PreferenceType Type, PrefData Data)
01983 {
01984 #if !defined(EXCLUDE_FROM_RALPH)
01985     // First check if there is a valid OILPrefs, as if there was a problem on start up such as
01986     // the MSCVRTn.DLL failing to load then the preferences may have been not fully set up.
01987     // Static variable used as the class may not have been created!
01988     if (PrefsInitedOk && (OILPrefs != NULL))
01989     {
01990         // Try to read the preference
01991         OILPrefs->OpenInput();
01992         OILPrefs->Read(Section, Pref, Type, Data);
01993         OILPrefs->CloseInput();
01994 
01995         if (Type == PREF_STRING)
01996         {
01997             // See if anything was put into the string
01998             return (Data.pString->Length() > 0);
01999         }
02000 
02001         return TRUE;
02002     }
02003 #endif
02004     // Something went wrong
02005     return FALSE;
02006 }
02007 
02008 /********************************************************************************************
02009 
02010 >   BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, StringBase *pValue)
02011 
02012     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
02013     Created:    06/01/95
02014     Inputs:     Section, Pref - the preference to write.
02015                 pValue - the value to write to the preference.
02016                 BufSize - number of bytes in the buffer pointed to by pValue.
02017     Returns:    TRUE if the preference exists and was small enough to fit in the buffer.
02018                 FALSE if the preference does not exist or could not fit in the buffer.
02019     Purpose:    Read a preference from the file directly, without the need to declare a
02020                 preference beforehand.
02021     SeeAlso:    Preferences::SetPrefDirect
02022 
02023 ********************************************************************************************/
02024 
02025 BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, StringBase *pValue)
02026 {
02027     // core moved into common function above 25/3/97
02028     PrefData Data;
02029     Data.pString = pValue;
02030     return GetPrefDirect(Section, Pref, PREF_STRING, Data);
02031 }
02032 
02033 /********************************************************************************************
02034 
02035 >   BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, INT32 *pValue)
02036 
02037     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02038     Created:    25/03/97
02039     Inputs:     Section, Pref - the preference to write.
02040                 pValue - the value to write to the preference.
02041                 BufSize - number of bytes in the buffer pointed to by pValue.
02042     Returns:    TRUE if the preference exists and was small enough to fit in the buffer.
02043                 FALSE if the preference does not exist or could not fit in the buffer.
02044     Purpose:    Read a preference from the file directly, without the need to declare a
02045                 preference beforehand.
02046     SeeAlso:    Preferences::SetPrefDirect
02047 
02048 ********************************************************************************************/
02049 
02050 BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, INT32 *pValue)
02051 {
02052     PrefData Data;
02053     Data.pInt = pValue;
02054     return GetPrefDirect(Section, Pref, PREF_INT, Data);
02055 }
02056 
02057 /********************************************************************************************
02058 
02059 >   BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, UINT32 *pValue)
02060 
02061     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02062     Created:    25/03/97
02063     Inputs:     Section, Pref - the preference to write.
02064                 pValue - the value to write to the preference.
02065                 BufSize - number of bytes in the buffer pointed to by pValue.
02066     Returns:    TRUE if the preference exists and was small enough to fit in the buffer.
02067                 FALSE if the preference does not exist or could not fit in the buffer.
02068     Purpose:    Read a preference from the file directly, without the need to declare a
02069                 preference beforehand.
02070     SeeAlso:    Preferences::SetPrefDirect
02071 
02072 ********************************************************************************************/
02073 
02074 BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, UINT32 *pValue)
02075 {
02076     PrefData Data;
02077     Data.pUInt = pValue;
02078     return GetPrefDirect(Section, Pref, PREF_UINT, Data);
02079 }
02080 
02081 /********************************************************************************************
02082 
02083 >   BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, double *pValue)
02084 
02085     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02086     Created:    25/03/97
02087     Inputs:     Section, Pref - the preference to write.
02088                 pValue - the value to write to the preference.
02089                 BufSize - number of bytes in the buffer pointed to by pValue.
02090     Returns:    TRUE if the preference exists and was small enough to fit in the buffer.
02091                 FALSE if the preference does not exist or could not fit in the buffer.
02092     Purpose:    Read a preference from the file directly, without the need to declare a
02093                 preference beforehand.
02094     SeeAlso:    Preferences::SetPrefDirect
02095 
02096 ********************************************************************************************/
02097 
02098 BOOL Preferences::GetPrefDirect(LPTCHAR Section, LPTCHAR Pref, double *pValue)
02099 {
02100     PrefData Data;
02101     Data.pDouble = pValue;
02102     return GetPrefDirect(Section, Pref, PREF_DOUBLE, Data);
02103 }
02104 

Generated on Sat Nov 10 03:46:34 2007 for Camelot by  doxygen 1.4.4