CamResource Class Reference

To control the translation of resources within Camelot Notes: In the OIL See Also:. More...

#include <camresource.h>

Inheritance diagram for CamResource:

CCObject SimpleCCObject List of all members.

Public Member Functions

virtual CCRuntimeClassGetRuntimeClass () const
 This function allows access to the CCRuntimeClass object for this class, which in turn allows dynamic classing and construction. This function is automatically overridden on derived classes if you use the CC_DECLARE_... and CC_IMPLEMENT_... macros.
 CamResource ()
 Constructor.
virtual ~CamResource ()
 Destructor.
CCLexFileOpen (ResourceID ID, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Return a pointer to the open file.
CCLexFileOpen (const TCHAR *pFileName, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE)
 Return a pointer to the open file.
wxFSFile * OpenwxFSFile (ResourceID ID)
 Return a pointer to the open file.
wxFSFile * OpenwxFSFile (const TCHAR *pFileName)
 Return a pointer to the open file.
void Close ()
 Close the relevant file.
CCLexFileGet ()
wxFSFile * GetwxFSFile ()

Static Public Member Functions

static CCRuntimeClassGetMyClass ()
static void PASCAL Construct (void *p)
static BOOL LoadwxImage (wxImage &rImage, const TCHAR *pFileName, BOOL Grey=FALSE)
 Static function to load a bitmap.
static BOOL LoadwxBitmap (wxBitmap &rBitmap, const TCHAR *pFileName, BOOL Grey=FALSE)
 Static function to load a bitmap.
static wxImage * GetCachedBitmap (const TCHAR *pName)
 Returns a pointer to the preloaded bitmap.
static void MakeGreyImage (wxImage &rImage)
 Static function to grey an image.
static void MakeHotImage (wxImage &rImage)
 Static function to make a hot version of an image.
static ResourceID GetResourceID (const TCHAR *ObjectName)
static const TCHARGetTextFail (ResourceID Resource)
static const TCHARGetText (ResourceID Resource)
static const TCHARGetObjectNameFail (ResourceID Resource)
static const TCHARGetObjectName (ResourceID Resource)
static wxString GetResourceFilePath (const wxString &str, BOOL AllowOverride=TRUE)
 Destructor.
static void SetResourceFilePath (const wxString &str)
 Destructor.
static BOOL IsBitmapName (const wxString &str)
 Determine whether or not a path points to a bitmap.
static wxString GetBitmapExtension (const wxString &str)
 Determines the extension of a bitmap.
static wxString GetBitmapBaseName (const wxString &str)
 Determines the extension of a bitmap.
static wxString GetBitmapFlagString (const wxString &str)
 Determines the extension of a bitmap.
static wxString MakeBitmapString (const wxString base, const wxString flags, const wxString ext)
static BOOL Init ()
 Initialize resources.
static BOOL DeInit ()
 Initialize resources.
static BOOL DoneInit (BOOL CanYield=TRUE)
 Signals to the resouce system initialization is completed. The splah screen can thus be removed.
static wxLocale * GetLocale ()
static void SetGenerateXRCCheck (BOOL flag)
static void * LoadFile (const wxString &str1, UINT32 *pSize)
 


Static Public Attributes

static CCRuntimeClass cc_classCamResource
static wxArrayString BitmapExtensions

Static Private Member Functions

static void AddStringResource (const TCHAR *name, const TCHAR *text, ResourceID r=0)
 Initialize resources.
static void RememberDuringStaticInit (const TCHAR *ObjectName)
 Remembers an objectname that has been GetResourceID'd prior to the ObjectHash existing.
static BOOL ReadStringTableFile ()
 Initialize resources.
static void ProcessWindowAndChildren (wxWindow *pWindow)
 Initialize resources.
static void GetBinaryFileInfo (void **pPtr, UINT32 *pSize)
static BOOL InitXmlResource ()
 Initialize resources.
static BOOL Splash ()
 Put up a splash screen.
static BOOL CheckResourcePath (const wxString &str1, const wxString &str2)
 

static const TCHARFixObjectName (const TCHAR *ObjectName)
static BOOL AddBitmaps (wxString &Path)
 Add all bitmaps in the path.
static BOOL LoadBitmaps ()
 Add internal and external bitmaps.
static void DeleteBitmapHashEntries ()
 Delete every bitmap hash table entry.
static void MakeVariantBitmaps (ResourceStringToBitmap::iterator *it=NULL)
 Make variant copies of all bitmaps.

Private Attributes

CCLexFilepFile
void * pMemory
UINT32 Size
wxFSFile * pwxFSFile

Static Private Attributes

static wxFileSystem * pwxFileSystem = NULL
static wxLocale * m_pLocale = NULL
static wxHelpProvider * m_pHelpProvider = NULL
static BOOL s_GenerateXRCCheck = FALSE
static ResIDToString * pHash = NULL
static ResIDToString * pObjectNameHash = NULL
static TCHARDefaultString = _T("[Resource string not found]")
static TCHARDefaultObjectName = _T("[Object name not Found]")
static wxString * pResourcePath = NULL
static BOOL HaveCheckedResourcePath = FALSE
static CamResourceRememberpFirstRemember = NULL
static wxBitmap * pSplashBitmap = NULL
static wxAdvSplashScreenpSplashScreen = NULL
static ResourceStringToBitmap * pBitmapHash = NULL

Detailed Description

To control the translation of resources within Camelot Notes: In the OIL See Also:.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
This is a class composed of static member functions which rapidly translates resources, and a dynamic object which provides capabilities of loading from the disk.

String tables

The GetText() member functions look up the integer ID's passed to it in a hash map, via inline functions, so should be pretty rapid in execution. Thus the actual mechanism of loading the strings is effectively encapsulated.

Dialogs and other resources

The GetResourceID() member function implements the _R() macro, which allows a resource in a dialog (or a stringtable resource) to be translated into the numeric ID's Camelot likes.

Example usage:

ResourceID myResource; myResource = _R("_R(IDS_BLOBBYSTRING)"); // Uses CamResource::GetResourceID()

... pass around the integer value ...

const TCHAR * myString = CamResource::GetText(myResource); // Can't fail ... do something with the text of the entry ...

Note that the _R() macros is clevere than you think. That's because it can be used as a static initializer (e.g. in wxWidgets event tables). What is happening here is that the GetXRCID() hash table gets initialized at static initialization time creating a map from the resource string (IDS_ etc.) to a unique integer value, and when the XML resources are loaded later, they are assigned that integer value.

Note this is a static class, and thus no constructors and destructors are offered.

Definition at line 199 of file camresource.h.


Constructor & Destructor Documentation

CamResource::CamResource  ) 
 

Constructor.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-
Example of how to use this class:

CamResource myResource; // Allocate a new resource object

CCLexFile * myFile = myResource.Open(_R(IDB_BLOBBY)); // Open the BLOBBY bitmap Could have specified a string instead

myFile->Read( ... ) // or whatever

The user can either close the file, or not. However, operations must NOT be done on the file once the corresponding resource object is destroyed (as the resource object may have allocated a memory copy of the image). To prevent damage, the destructor will ALWAYS close the file and free the resources.

The caller should NOT delete the open CCLexFile object that is returned. Either use our Close mechanism, or let the destructor take its course.

Definition at line 1883 of file camresource.cpp.

01884 {
01885     Size = 0;
01886     pMemory = NULL;
01887     pFile = NULL;
01888     pwxFSFile = NULL;
01889     return;
01890 }

CamResource::~CamResource  )  [virtual]
 

Destructor.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1909 of file camresource.cpp.

01910 {
01911     Close(); // releases pFile and pMemory
01912 }


Member Function Documentation

BOOL CamResource::AddBitmaps wxString &  Path  )  [static, private]
 

Add all bitmaps in the path.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
01/01/2005
Parameters:
Path - the path to add [INPUTS]
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Definition at line 979 of file camresource.cpp.

00980 {
00981     ERROR2IF(!pBitmapHash, FALSE, "No bitmap hash");
00982     ERROR2IF(!pwxFileSystem, FALSE, "No filesystem");
00983 
00984     TRACEUSER("amb",_T("Adding bitmaps from %s"),Path.c_str());
00985 
00986     wxString fn = pwxFileSystem->FindFirst(Path+_T("*.*"), wxFILE); // This isn't an MSDOS-ism - we are looking for files with an extension
00987     while (!fn.IsEmpty())
00988     {
00989         wxString LeafName = fn.Mid(Path.Length());
00990 
00991         if (IsBitmapName(LeafName))
00992         {
00993     
00994             ResourceStringToBitmap::iterator i=pBitmapHash->find(LeafName);
00995     
00996             if (i==pBitmapHash->end())  // ignore if we already have an entry
00997             {
00998 #if PRELOAD_BITMAPS 
00999                 wxImage * pBitmap=new wxImage;
01000                 if (!pBitmap)
01001                     return FALSE;
01002     
01003     //          TRACE(_T("Loading bitmap %s"),fn.c_str());
01004                 if (LoadwxImage(*pBitmap, LeafName))
01005                     (*pBitmapHash)[camStrdup(LeafName.c_str())]=pBitmap;
01006                 else
01007                 {
01008                     ERROR3_PF((_T("Could not load bitmap %s"),fn.c_str()));
01009                     delete pBitmap;
01010                 }
01011 #else
01012                 (*pBitmapHash)[camStrdup(LeafName.c_str())]=NULL; // Mark as there, but needs to be loaded
01013 #endif
01014             }
01015         }
01016     
01017         fn = pwxFileSystem->FindNext();
01018     }
01019     return TRUE;
01020 }

void CamResource::AddStringResource const TCHAR name,
const TCHAR text,
ResourceID  r = 0
[static, private]
 

Initialize resources.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
name - object name to add [INPUTS] text - text asssociated with it r - numeric ResourceID or 0 to allocate it
None [OUTPUTS]
Returns:
None

Errors: via wxMessageBox

See also:
-
Read controls out of this window, and put into string table. Then process children recursively.

Definition at line 449 of file camresource.cpp.

00450 {
00451     ResourceID r2=GetResourceID(name);
00452     if (r)
00453     {
00454         if (r != r2)
00455         {
00456             TRACE(_T("Possible duplicate label %s\n"),text);
00457         }
00458     }
00459     else
00460     {
00461         r = r2;
00462     }
00463 
00464     if (!name || !text)
00465     {
00466         TRACE(_T("Resource ID %d is blank\n"),r);
00467         ERROR3("Resource is blank");
00468     }
00469     else
00470     {
00471         ResIDToString::iterator i=pHash->find(r);
00472         if (i!=pHash->end())
00473         {
00474             TRACE(_T("Resource ID %d name <%s> has duplicate definitions: <%s> and <%s>\n"),r,name,text,i->second);
00475         }
00476         else
00477         {
00478             const TCHAR * tcopy = camStrdup(text);
00479             (*pHash)[r] = tcopy;
00480 
00481             const TCHAR * t = GetText(r);
00482             if (t!=tcopy)
00483             {
00484                 ERROR3("Resource string does not match local copy");
00485             }       
00486         }
00487     }
00488 }

BOOL CamResource::CheckResourcePath const wxString &  str1,
const wxString &  str2
[static, private]
 

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
str1,str2 - filenames to check [INPUTS]
[OUTPUTS] 
Returns:
TRUE if the files are identical, else false

Errors: -

See also:
-
This routine compares two small files. If they are equal, it returns true, else it returns false. This allows checking of the checksum. This is reasonably resilient to some fool creating a huge xrc.check as we only read the files if the lengths are equal, which means we never read more than the size of the file bound into the executable.

Definition at line 878 of file camresource.cpp.

00879 {
00880     if (!pwxFileSystem) return FALSE;
00881 
00882     UINT32 size1=0;
00883     UINT32 size2=0;
00884     void * mem1=LoadFile(str1, &size1);
00885     void * mem2=LoadFile(str2, &size2);
00886 
00887     if (!mem1)
00888     {
00889         if (mem2)
00890             free(mem2);
00891         return FALSE; // and we can't generate an xrc.check
00892     }
00893 
00894     BOOL same = mem2 && ( size1 == size2) && !memcmp(mem1, mem2, size1);
00895 
00896     if (!same && s_GenerateXRCCheck)
00897     {
00898         wxMessageBox(_T("You have requested XaraLX to generate a checksum for resources which may not match the binary in question. "
00899                         "A checksum will be generated, but the program may not be stable."), _T("XaraLX Resource system warning"));
00900 
00901         wxFile f;
00902         f.Create(str2, wxFile::write);
00903         if (!f.IsOpened() || (f.Write(mem1, size1) != size1))
00904         {
00905             wxMessageBox(_T("Failed to write xrc.check file ")+str2, _T("XaraLX resource system"));
00906         }
00907         f.Close();
00908         same=TRUE;
00909     }
00910 
00911 
00912     if (mem1)
00913         free (mem1);
00914 
00915     if (mem2)
00916         free (mem2);
00917 
00918     return same;
00919 }

void CamResource::Close void   ) 
 

Close the relevant file.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1930 of file camresource.cpp.

01931 {
01932     if (pFile)
01933     {
01934         pFile->close();
01935         delete (pFile);
01936         pFile = NULL;
01937     }
01938 
01939     if (pwxFSFile)
01940     {
01941         delete (pwxFSFile);
01942         pwxFSFile=NULL;
01943     }
01944 
01945     if (pMemory) free(pMemory);
01946     pMemory = NULL;
01947 
01948     Size = 0; // leave in tidy state
01949 }

static void PASCAL CamResource::Construct void *  p  )  [static]
 

BOOL CamResource::DeInit void   )  [static]
 

Initialize resources.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Definition at line 1672 of file camresource.cpp.

01673 {
01674     if (m_pHelpProvider)
01675     {
01676         wxHelpProvider::Set(NULL);
01677         delete m_pHelpProvider;
01678         m_pHelpProvider = NULL;
01679     }
01680 
01681     if (pwxFileSystem)
01682     {
01683         delete (pwxFileSystem);
01684         pwxFileSystem = NULL;
01685     }
01686 
01687 #if !defined(EXCLUDE_FROM_XARLIB)
01688     if (pBitmapHash)
01689     {
01690         DeleteBitmapHashEntries();
01691         delete pBitmapHash;
01692         pBitmapHash = NULL;
01693     }
01694 #endif  // EXCLUDE_FROM_XARLIB
01695     if (pHash)
01696     {
01697         ResIDToString::iterator current;
01698 
01699         while (!pHash->empty())
01700         {
01701             current = pHash->begin();
01702             ResourceString s=current->second;
01703             pHash->erase(current);
01704             free((void *)s);
01705         }
01706         // for good measure
01707         pHash->clear();
01708         
01709         delete (pHash);
01710         pHash = NULL;
01711     }
01712 
01713     if (pObjectNameHash)
01714     {
01715         ResIDToString::iterator current;
01716 
01717         while (!pObjectNameHash->empty())
01718         {
01719             current = pObjectNameHash->begin();
01720             ResourceString s=current->second;
01721             pObjectNameHash->erase(current);
01722             free((void *)s);
01723         }
01724         // for good measure
01725         pObjectNameHash->clear();
01726         
01727         delete (pObjectNameHash);
01728         pObjectNameHash = NULL;
01729     }
01730 
01731 #if !defined(EXCLUDE_FROM_XARLIB)
01732     if (pSplashScreen)
01733     {
01734         delete (pSplashScreen);
01735         pSplashScreen = NULL;
01736     }
01737 
01738     if (pSplashBitmap)
01739     {
01740         delete (pSplashBitmap);
01741         pSplashBitmap = NULL;
01742     }
01743 #endif  // EXCLUDE_FROM_XARLIB
01744 
01745     if (m_pLocale)
01746     {
01747         delete (m_pLocale);
01748         m_pLocale = NULL;
01749     }
01750 
01751     return TRUE;
01752 }

void CamResource::DeleteBitmapHashEntries  )  [static, private]
 

Delete every bitmap hash table entry.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
30/12/2005
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 1633 of file camresource.cpp.

01634 {
01635     if (pBitmapHash)
01636     {
01637         ResourceStringToBitmap::iterator current;
01638 
01639         while (!pBitmapHash->empty())
01640         {
01641             current = pBitmapHash->begin();
01642             wxImage * b=current->second;
01643             TCHAR * s=(TCHAR *)current->first;
01644             pBitmapHash->erase(current);
01645             if (b)
01646                 delete b;
01647             free(s);
01648         }
01649         // for good measure
01650         pBitmapHash->clear();
01651     }
01652 }

BOOL CamResource::DoneInit BOOL  CanYield = TRUE  )  [static]
 

Signals to the resouce system initialization is completed. The splah screen can thus be removed.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Definition at line 1827 of file camresource.cpp.

01828 {
01829     TRACET(_T("CamResource::DoneInit() called"));
01830 #if !defined(EXCLUDE_FROM_XARLIB)
01831     if (pSplashScreen)
01832     {
01833         if (CanYield)
01834             ::wxYield();
01835         pSplashScreen->Destroy();
01836         pSplashScreen = NULL;
01837         if (CanYield)
01838             ::wxYield();
01839     }
01840     if (pSplashBitmap)
01841     {
01842         delete (pSplashBitmap);
01843         pSplashBitmap = NULL;
01844     }
01845 #endif  // EXCLUDE_FROM_XARLIB
01846     return TRUE;
01847 }

const TCHAR * CamResource::FixObjectName const TCHAR ObjectName  )  [static, private]
 

Definition at line 354 of file camresource.cpp.

00355 {
00356     if (!CamResourceFixNameEntry::pArray)
00357     {
00358         // Don't delete the comments or normalize.pl will unhelpfully convert the bits in quotes
00359         FNOMAP("IDOK", "wxID_OK"); //NORESOURCEFIX
00360         FNOMAP("IDCANCEL", "wxID_CANCEL"); //NORESOURCEFIX
00361         FNOMAP("IDAPPLY", "wxID_APPLY"); //NORESOURCEFIX
00362         FNOMAP("ID_APPLY_NOW", "wxID_APPLY"); //NORESOURCEFIX
00363         FNOMAP("ID_CC_APPLY_NOW", "wxID_APPLY"); //NORESOURCEFIX
00364         FNOMAP("ID_FILE_OPEN", "wxID_OPEN"); //NORESOURCEFIX
00365         FNOMAP("ID_FILE_CLOSE", "wxID_CLOSE"); //NORESOURCEFIX
00366         FNOMAP("ID_FILE_SAVE", "wxID_SAVE"); //NORESOURCEFIX
00367         FNOMAP("ID_FILE_SAVE_AS", "wxID_SAVEAS"); //NORESOURCEFIX
00368         FNOMAP("ID_APP_EXIT", "wxID_EXIT"); //NORESOURCEFIX
00369         FNOMAP("ID_FILE_PRINT", "wxID_PRINT"); //NORESOURCEFIX
00370         FNOMAP("ID_FILE_PRINT_PREVIEW", "wxID_PREVIEW"); //NORESOURCEFIX
00371         FNOMAP("ID_FILE_PRINT_SETUP", "wxID_PRINT_SETUP"); //NORESOURCEFIX
00372         FNOMAP("ID_APP_ABOUT", "wxID_ABOUT"); //NORESOURCEFIX
00373         FNOMAP("ID_EDIT_UNDO", "wxID_UNDO"); //NORESOURCEFIX
00374         FNOMAP("ID_EDIT_CUT", "wxID_CUT"); //NORESOURCEFIX
00375         FNOMAP("ID_EDIT_COPY", "wxID_COPY"); //NORESOURCEFIX
00376         FNOMAP("ID_EDIT_PASTE", "wxID_PASTE"); //NORESOURCEFIX
00377         FNOMAP("IDYES", "wxID_YES"); //NORESOURCEFIX
00378         FNOMAP("IDNO", "wxID_NO"); //NORESOURCEFIX
00379         FNOMAP("IDHELP", "wxID_HELP"); //NORESOURCEFIX
00380         
00381         CamResourceFixNameEntry::MakeResources();
00382     }
00383     const TCHAR * ret= CamResourceFixNameEntry::Find(ObjectName);
00384     if (pObjectNameHash && ret !=ObjectName) // don't do during static init
00385     {
00386         TRACEUSER("amb",_T("**Mapped %s to %s"),ObjectName,ret);
00387     }
00388     return ret;
00389 }

CCLexFile* CamResource::Get  )  [inline]
 

Definition at line 225 of file camresource.h.

00225 {return pFile;}

void CamResource::GetBinaryFileInfo void **  pPtr,
UINT32 pSize
[static, private]
 

Definition at line 50484 of file winresources.cpp.

50485 { *pPtr=(void *)&(binfile[0]); *pSize=sizeof(binfile)-1; return; }

wxString CamResource::GetBitmapBaseName const wxString &  str  )  [static]
 

Determines the extension of a bitmap.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/01/2005
Parameters:
str - sting to look at [INPUTS]
None [OUTPUTS]
Returns:
Empty string if none found, else the BaseName (without flags or extension)

Errors: -

See also:
-

Definition at line 1086 of file camresource.cpp.

01087 {
01088     // Find the rightmost dot
01089     INT32 i=str.Find(_T('.'), TRUE);
01090     if (i<0)
01091         return wxEmptyString;
01092     wxString barestr = str.Left(i);
01093 
01094     // Find the rightmost "-";
01095     i=barestr.Find(_T('-'), TRUE);
01096     if (i<0)
01097         return barestr;
01098 
01099     // Now check all characters after the "-" are alphanumeric
01100     INT32 j;
01101     for (j=i+1; j<(INT32)barestr.Length(); j++)
01102     {
01103         wxChar c=barestr[j];
01104         if ((c<_T('a')) || (c>_T('z')))
01105             return barestr;
01106     }
01107     return barestr.Left(i);
01108 }

wxString CamResource::GetBitmapExtension const wxString &  str  )  [static]
 

Determines the extension of a bitmap.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/01/2005
Parameters:
str - sting to look at [INPUTS]
None [OUTPUTS]
Returns:
Empty string if none found, else the extenstion

Errors: -

See also:
-

Definition at line 1060 of file camresource.cpp.

01061 {
01062     // Find the rightmost dot
01063     INT32 i=str.Find(_T('.'), TRUE);
01064     if (i<0)
01065         return wxEmptyString;
01066     else
01067         return str.Mid(i+1);
01068 }

wxString CamResource::GetBitmapFlagString const wxString &  str  )  [static]
 

Determines the extension of a bitmap.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
24/01/2005
Parameters:
str - sting to look at [INPUTS]
None [OUTPUTS]
Returns:
Empty string if none found, else the flags string (without the '-')

Errors: -

See also:
-

Definition at line 1126 of file camresource.cpp.

01127 {
01128     // Find the rightmost dot
01129     INT32 i=str.Find(_T('.'), TRUE);
01130     if (i<0)
01131         return wxEmptyString;
01132     wxString barestr = str.Left(i);
01133 
01134     // Find the rightmost "-";
01135     i=barestr.Find(_T('-'), TRUE);
01136     if (i<0)
01137         return wxEmptyString;
01138 
01139     // Now check all characters after the "-" are alphanumeric
01140     INT32 j;
01141     for (j=i+1; j<(INT32)barestr.Length(); j++)
01142     {
01143         wxChar c=barestr[j];
01144         if ((c<_T('a')) || (c>_T('z')))
01145             return wxEmptyString;
01146     }
01147     return barestr.Mid(i+1);
01148 }

wxImage * CamResource::GetCachedBitmap const TCHAR pName  )  [static]
 

Returns a pointer to the preloaded bitmap.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
01/01/2005
Parameters:
pName - pointer to name of bitmap (leaf name) [INPUTS]
None [OUTPUTS]
Returns:
a pointer to the bitmap

Errors: via wxMessageBox

See also:
-

Definition at line 1280 of file camresource.cpp.

01281 {
01282     if (!pBitmapHash) return NULL;
01283     ResourceStringToBitmap::iterator i=pBitmapHash->find(pName);
01284     if (i==pBitmapHash->end())
01285     {
01286         // We know this file does not exist in the resources. However, we might be able to
01287         // make one if it's greyed and we can get the ungreyed version
01288 
01289         wxString fn(pName);
01290 
01291         // Clear each of the flags in sequence
01292         BOOL Found=FALSE;
01293         // Do this entire lot for each flag
01294         CamArtFlags flag=CAF_CACHE_MAX;
01295         while ((flag=(CamArtFlags)(flag>>1)) !=0 )
01296         {
01297             if ((flag==CAF_GREYED) || (flag!=CAF_SELECTED)) // We don't know how to produce anything else, so ignore
01298             {
01299 
01300                 if (IsBitmapName(fn) && (CamArtProvider::GetBitmapFlags(fn) & flag))
01301                 {
01302                     // Find the ungreyed name of the bitmap
01303                     wxString ugfn=MakeBitmapString(GetBitmapBaseName(fn),
01304                                                 CamArtProvider::MakeBitmapFlagString((CamArtFlags)
01305                                                                                         (CamArtProvider::GetBitmapFlags(fn) &
01306                                                                                         ~flag)),
01307                                                                                         GetBitmapExtension(fn));
01308                     Found = TRUE; // we should at least look for another bitmap
01309     
01310                     // Recursively call ourself to load the ungreyed bitmap. We don't care about the result, but this
01311                     // will insert the greyed version into the cache as a byproduct
01312     
01313 #ifdef _DEBUG
01314                     static INT32 recursion=0;
01315                     recursion++;
01316                     ERROR3IF(recursion>16,"Too much recursion in CamResource::GetCachedBitmap");
01317 #endif
01318                     GetCachedBitmap(ugfn.c_str());
01319 #ifdef _DEBUG
01320                     recursion--;
01321 #endif
01322                 }
01323             }
01324         }
01325         if (!Found)
01326             return NULL;
01327 
01328         i=pBitmapHash->find(pName); // reset iterator
01329         if (i==pBitmapHash->end())
01330             return NULL; // we couldn't find a greyed version
01331     }
01332 
01333     if (!i->second)
01334     {
01335         // There is no bitmap there, but the name is there. We must be demand loading
01336 
01337         wxImage * pBitmap = new wxImage;
01338         if (!pBitmap) return NULL;
01339 
01340         if (!LoadwxImage(*pBitmap, pName))
01341         {
01342             ERROR3_PF((_T("Could not load bitmap %s"), pName));
01343             delete pBitmap;
01344             return NULL;
01345         }
01346 
01347         // Add it to the cache
01348         i->second=pBitmap;
01349 
01350         // Generate variant versions if we should
01351         MakeVariantBitmaps(&i);
01352 
01353         return pBitmap;
01354     }
01355     return i->second;
01356 }

static wxLocale* CamResource::GetLocale  )  [inline, static]
 

Definition at line 330 of file camresource.h.

00330 {return m_pLocale;}

static CCRuntimeClass* CamResource::GetMyClass  )  [static]
 

Reimplemented from CCObject.

static const TCHAR* CamResource::GetObjectName ResourceID  Resource  )  [inline, static]
 

Definition at line 301 of file camresource.h.

00302     {
00303         if (!pObjectNameHash) return DefaultString;
00304         ResIDToString::iterator i=pObjectNameHash->find(Resource);
00305         const TCHAR * text = (const TCHAR *)((i==pObjectNameHash->end())?NULL:i->second);
00306         return text?text:DefaultString;
00307     };

static const TCHAR* CamResource::GetObjectNameFail ResourceID  Resource  )  [inline, static]
 

Definition at line 295 of file camresource.h.

00296     {
00297         if (!pObjectNameHash) return NULL;
00298         ResIDToString::iterator i=pObjectNameHash->find(Resource);
00299         return (const TCHAR *)((i==pObjectNameHash->end())?NULL:i->second);
00300     };

wxString CamResource::GetResourceFilePath const wxString &  str,
BOOL  AllowOverride = TRUE
[static]
 

Destructor.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
str - the string to look up [INPUTS]
[OUTPUTS] 
Returns:
the path to load it from

Errors: -

See also:
-
By default this will return the MemoryFS path, however, if & when we support overriding of resources in a resource directory, this will under the appopriate circumstances use a differnt path. Note this can only be called AFTER the resource system is initialized.

If an empty string is specified, it returns the overridden resource path (if one exists) (so long as the override is set to TRUE), or failing that the memory resource path

Definition at line 749 of file camresource.cpp.

00750 {
00751     // If we are given a full path, then return. For the time being that's anything with a colon or a slash in it
00752     // as the resources file is flat
00753     if ( ((str.Find(_T(':')))>=0) || ((str.Find(_T('/')))>=0) || ((str.Find(_T('\\')))>=0) )
00754     {
00755         return str;
00756     }
00757 
00758     wxString mfn = _T("memory:resources#zip:");
00759 
00760     if (AllowOverride && pResourcePath && pwxFileSystem)
00761     {
00762         wxString fn = *pResourcePath + _T('/');
00763 
00764         // If we have not run the check on the checksum do it now.
00765         if (!HaveCheckedResourcePath)
00766         {
00767             if (CheckResourcePath(mfn+_T("xrc.check"),fn+_T("xrc.check")))
00768             {
00769                 HaveCheckedResourcePath = TRUE;
00770             }
00771             else
00772             {
00773                 wxMessageBox(_T("Ignoring resource path specified on command line due to bad resource checksum"), _T("Resource loading error"));
00774                 delete (pResourcePath);
00775                 pResourcePath = NULL;
00776             }
00777         }
00778 
00779         if (str.IsEmpty() && pResourcePath)
00780             return fn;
00781 
00782         fn += str;
00783 
00784         if (pResourcePath) // may have been cleared
00785         {
00786             wxFSFile * pTwxFSFile = pwxFileSystem->OpenFile(fn);
00787             if (pTwxFSFile)
00788             {
00789                 // we found it, so close it & return
00790                 delete pTwxFSFile;
00791                 return fn;
00792             }
00793         }
00794     }
00795     return mfn + str;
00796 }

static ResourceID CamResource::GetResourceID const TCHAR ObjectName  )  [inline, static]
 

Definition at line 267 of file camresource.h.

00268     {
00269         const TCHAR * fObjectName=FixObjectName(ObjectName);
00270         ResourceID Resource = wxXmlResource::GetXRCID(fObjectName);
00271         // need to record it in the hash that goes the other way lest we be asked. Note this will always
00272         // work as the caller to GetObjectName can't have a ResourceID without _R()'ing it (or at least
00273         // cannot legally have one).
00274         if (pObjectNameHash)    // skip on static initialization phase or we'll be dead
00275         {
00276             ResIDToString::iterator i=pObjectNameHash->find(Resource);
00277             if (i==pObjectNameHash->end()) (*pObjectNameHash)[Resource]=camStrdup(fObjectName);
00278         }
00279         else RememberDuringStaticInit(fObjectName); // add it to the hash later
00280         return Resource;
00281     }   

virtual CCRuntimeClass* CamResource::GetRuntimeClass  )  const [virtual]
 

This function allows access to the CCRuntimeClass object for this class, which in turn allows dynamic classing and construction. This function is automatically overridden on derived classes if you use the CC_DECLARE_... and CC_IMPLEMENT_... macros.

Author:
Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
Date:
19/7/93
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
Pointer to the CCRuntimeClass object associated with CCObject.

Errors: -

See also:
CCObject; CCRuntimeClass; CCObject::IsKindOf; CCRuntimeClass::CreateObject; CC_DECLARE_DYNAMIC; CC_IMPLEMENT_DYNAMIC; CC_DECLARE_DYNCREATE; CC_IMPLEMENT_DYNCREATE; CC_CLASS_MEMDUMP; CC_DECLARE_MEMDUMP; CC_IMPLEMENT_MEMDUMP; CCObject::GetRuntimeClass;

Reimplemented from CCObject.

static const TCHAR* CamResource::GetText ResourceID  Resource  )  [inline, static]
 

Definition at line 288 of file camresource.h.

00289     {
00290         if (!pHash) return DefaultString;
00291         ResIDToString::iterator i=pHash->find(Resource);
00292         const TCHAR * text = (const TCHAR *)((i==pHash->end())?NULL:i->second);
00293         return text?text:DefaultString;
00294     };

static const TCHAR* CamResource::GetTextFail ResourceID  Resource  )  [inline, static]
 

Definition at line 282 of file camresource.h.

00283     {
00284         if (!pHash) return NULL;
00285         ResIDToString::iterator i=pHash->find(Resource);
00286         return (const TCHAR *)((i==pHash->end())?NULL:i->second);
00287     };

wxFSFile* CamResource::GetwxFSFile  )  [inline]
 

Definition at line 226 of file camresource.h.

00226 {return pwxFSFile;}

BOOL CamResource::Init void   )  [static]
 

Initialize resources.

Author:
Alex_Bligh <alex@alex.org.uk>
Date:
02/12/2005
Parameters:
None [INPUTS]
None [OUTPUTS]
Returns:
TRUE if succeeded, FALSE if fails

Errors: via wxMessageBox

See also:
-

Reimplemented from SimpleCCObject.

Definition at line 1409 of file camresource.cpp.

01410 {
01411     void * pFile=NULL;
01412     UINT32 Length=0;
01413 
01414     TRACET(_T("CamResource::Init() called"));
01415 
01416     pHash = new (ResIDToString);
01417     if (!pHash) return FALSE;
01418     pHash->clear();
01419 
01420     pObjectNameHash = new (ResIDToString);
01421     if (!pObjectNameHash) return FALSE;
01422     pObjectNameHash->clear();
01423 
01424 #if !defined(EXCLUDE_FROM_XARLIB)
01425     pBitmapHash = new (ResourceStringToBitmap);
01426     if (!pBitmapHash) return FALSE;
01427     pBitmapHash->clear();
01428 #endif
01429 
01430     // Now go through ID's translated before we got here
01431     CamResourceRemember * pRem = pFirstRemember;
01432     pFirstRemember = NULL;
01433     while (pRem)
01434     {
01435         if (pRem->text)
01436         {
01437             // Do not comment out the next line. It does something useful (make the inverse object
01438             // map work for static text)
01439             /*ResourceID r =*/ GetResourceID(pRem->text);
01440 //          TRACEUSER("amb",_T("Fixed up static init translation from %s to %d"),pRem->text,r);
01441             free (pRem->text);
01442         }
01443         CamResourceRemember * pORem = pRem;
01444         pRem = pRem->next;
01445         delete pORem;
01446     }
01447 
01448     // Initialize the handlers
01449     wxXmlResource::Get()->InitAllHandlers();
01450 #if !defined(EXCLUDE_FROM_XARLIB)
01451     wxXmlResource::Get()->AddHandler(new wxCamArtControlXmlHandler);
01452     wxXmlResource::Get()->AddHandler(new wxCamDrawControlXmlHandler);
01453 #ifdef wxXTRA_XH_ODCOMBO