camresource.h

Go to the documentation of this file.
00001 // $Id: camresource.h 1184 2006-05-23 19:27:20Z alex $
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 #ifndef INC_CAMRESOURCE
00100 #define INC_CAMRESOURCE
00101 
00102 // Define _R() before we include other Camelot headers
00103 // NOTE THIS MACRO IS EXPANDABLE IN A STATIC INITIALIZER
00104 #if 0 != wxUSE_UNICODE
00105 #define _RESQUOTE(x) L ## #x
00106 #else
00107 #define _RESQUOTE(x) #x
00108 #endif
00109 #define _R(x) ( CamResource::GetResourceID( _RESQUOTE(x)) )
00110 
00111 #include "ccobject.h"
00112 
00113 class CCLexFile;
00114 class wxFSFile;
00115 class wxBimtap;
00116 class wxAdvSplashScreen;
00117 class wxHelpProvider;
00118 
00119 typedef UINT32 ResourceID;
00120 
00121 // Need a type for the hash data or we get duplicate const error
00122 typedef const TCHAR * ResourceString;
00123 
00124 // Declare the hash map from ResourceID to String
00125 WX_DECLARE_HASH_MAP( ResourceID, ResourceString, wxIntegerHash, wxIntegerEqual, ResIDToString );
00126 WX_DECLARE_HASH_MAP( ResourceString, wxImage *, wxStringHash, wxStringEqual, ResourceStringToBitmap);
00127 
00128 // Some bodgy stuff from tbbitmap which we will fix some time
00129 extern wxImage          imageBevelTool;
00130 extern wxImage          imageBezTool;
00131 extern wxImage          imageBlendTool;
00132 //extern wxImage            imagelbuttonst32_xpm );
00133 //extern wxImage            lbuttst232_xpm );
00134 //extern wxImage            lbutts_liveeffect_xpm );
00135 extern wxImage          imageContourTool;
00136 extern wxImage          imageElipTool;
00137 extern wxImage          imageFHandTool;
00138 extern wxImage          imageGradTool;
00139 extern wxImage          imageLiveEffectTool;
00140 extern wxImage          imageMouldTool;
00141 extern wxImage          imagePenTool;
00142 extern wxImage          imagePush;
00143 extern wxImage          imageRectTool;
00144 extern wxImage          imageRegShapeTool;
00145 extern wxImage          imageSelTool;
00146 extern wxImage          imageShadrwTool;
00147 extern wxImage          imageSlicetool;
00148 extern wxImage          imageTextTool;
00149 extern wxImage          imageTransTool;
00150 extern wxImage          imageZoomTool;
00151 
00152 class CamResourceRemember;
00153 
00154 /*******************************************************************************************
00155 
00156 >   class CamResource : public CCObject
00157 
00158     Author:     Alex_Bligh <alex@alex.org.uk>
00159     Created:    02/12/2005
00160     Purpose:    To control the translation of resources within Camelot
00161     Notes:      In the OIL
00162     See Also:   
00163 
00164 This is a class composed of static member functions which rapidly translates resources,
00165 and a dynamic object which provides capabilities of loading from the disk.
00166 
00167 String tables
00168 
00169 The GetText() member functions look up the integer ID's passed to it in a hash map, via inline
00170 functions, so should be pretty rapid in execution. Thus the actual mechanism of loading
00171 the strings is effectively encapsulated.
00172 
00173 Dialogs and other resources
00174 
00175 The GetResourceID() member function implements the _R() macro, which allows a resource in
00176 a dialog (or a stringtable resource) to be translated into the numeric ID's Camelot likes.
00177 
00178 Example usage:
00179 
00180     ResourceID  myResource;
00181     myResource = _R("_R(IDS_BLOBBYSTRING)"); // Uses CamResource::GetResourceID()
00182 
00183     ... pass around the integer value ...
00184 
00185     const TCHAR * myString = CamResource::GetText(myResource); // Can't fail
00186     ... do something with the text of the entry ...
00187 
00188 Note that the _R() macros is clevere than you think. That's because it can be used
00189 as a static initializer (e.g. in wxWidgets event tables). What is happening here is
00190 that the GetXRCID() hash table gets initialized at static initialization time creating
00191 a map from the resource string (IDS_ etc.) to a unique integer value, and when the XML
00192 resources are loaded later, they are assigned that integer value.
00193 
00194 Note this is a static class, and thus no constructors and destructors are offered.
00195 
00196 ********************************************************************************************/
00197 
00198 
00199 class CamResource : public CCObject
00200 {
00201     CC_DECLARE_DYNCREATE( CamResource )
00202 
00203 // The per-object bits
00204 
00205 public:
00206     CamResource();
00207     virtual ~CamResource();
00208 
00209 private:
00210     CCLexFile * pFile;
00211     void * pMemory;
00212     UINT32 Size;
00213     wxFSFile * pwxFSFile;
00214     static wxFileSystem * pwxFileSystem;
00215     static wxLocale * m_pLocale;
00216     static wxHelpProvider * m_pHelpProvider;
00217     static BOOL s_GenerateXRCCheck;
00218 
00219 public:
00220     CCLexFile * Open ( ResourceID ID, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE);
00221     CCLexFile * Open ( const TCHAR * pFileName, BOOL ErrorReporting=TRUE, BOOL ExceptionThrowing=FALSE);
00222     wxFSFile * OpenwxFSFile (ResourceID ID);
00223     wxFSFile * OpenwxFSFile (const TCHAR * pFileName);
00224     void Close();
00225     CCLexFile * Get () {return pFile;}
00226     wxFSFile * GetwxFSFile () {return pwxFSFile;}
00227 
00228 // The static stuff
00229 
00230 private:
00231     static void AddStringResource(const TCHAR * name, const TCHAR * text, ResourceID r=0);
00232     static void RememberDuringStaticInit(const TCHAR * ObjectName);
00233     static BOOL ReadStringTableFile();
00234     static void ProcessWindowAndChildren(wxWindow * pWindow);
00235     static void GetBinaryFileInfo (void **pPtr, UINT32 *pSize);
00236     static BOOL InitXmlResource();
00237     static BOOL Splash();
00238     static BOOL CheckResourcePath( const wxString &str1, const wxString &str2 );
00239     static const TCHAR * FixObjectName(const TCHAR * ObjectName);
00240     static BOOL AddBitmaps(wxString &Path);
00241     static BOOL LoadBitmaps();
00242     static void DeleteBitmapHashEntries();
00243     static void MakeVariantBitmaps(ResourceStringToBitmap::iterator * it=NULL);
00244 
00245     static ResIDToString * pHash;
00246     static ResIDToString * pObjectNameHash;
00247     static TCHAR * DefaultString;
00248     static TCHAR * DefaultObjectName;
00249     static wxString * pResourcePath;
00250     static BOOL HaveCheckedResourcePath;
00251     static CamResourceRemember * pFirstRemember;
00252 
00253     static wxBitmap * pSplashBitmap;
00254     static wxAdvSplashScreen * pSplashScreen;
00255 
00256     static ResourceStringToBitmap * pBitmapHash;
00257 
00258 public:
00259     static BOOL LoadwxImage (wxImage & rImage, const TCHAR * pFileName, BOOL Grey=FALSE);
00260     static BOOL LoadwxBitmap (wxBitmap & rBitmap, const TCHAR * pFileName, BOOL Grey=FALSE);
00261 
00262     static wxImage* GetCachedBitmap(const TCHAR * pName);
00263 
00264     static void MakeGreyImage (wxImage & rImage);
00265     static void MakeHotImage (wxImage & rImage);
00266 
00267     static inline ResourceID GetResourceID(const TCHAR * ObjectName) // Implement the _R macro
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     }   
00282     static inline const TCHAR * GetTextFail(ResourceID Resource)
00283     {
00284         if (!pHash) return NULL;
00285         ResIDToString::iterator i=pHash->find(Resource);
00286         return (const TCHAR *)((i==pHash->end())?NULL:i->second);
00287     };
00288     static inline const TCHAR * GetText(ResourceID Resource)
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     };
00295     static inline const TCHAR * GetObjectNameFail(ResourceID Resource)
00296     {
00297         if (!pObjectNameHash) return NULL;
00298         ResIDToString::iterator i=pObjectNameHash->find(Resource);
00299         return (const TCHAR *)((i==pObjectNameHash->end())?NULL:i->second);
00300     };
00301     static inline const TCHAR * GetObjectName(ResourceID Resource)
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     };
00308 
00309     static wxString GetResourceFilePath( const wxString &str, BOOL AllowOverride=TRUE );
00310     static void SetResourceFilePath( const wxString &str );
00311 
00312     // String manipulation functions for bitmaps
00313     static BOOL IsBitmapName(const wxString &str);
00314     static wxString GetBitmapExtension(const wxString &str);
00315     static wxString GetBitmapBaseName(const wxString &str);
00316     static wxString GetBitmapFlagString(const wxString & str);
00317     static wxString MakeBitmapString(const wxString base, const wxString flags, const wxString ext)
00318     {
00319         if (flags.IsEmpty())
00320             return base+wxString(_T("."))+ext;
00321         else
00322             return base+wxString(_T("-"))+flags+wxString(_T("."))+ext;
00323     }
00324 
00325     static BOOL Init();
00326     static BOOL DeInit();
00327 
00328     static BOOL DoneInit(BOOL CanYield=TRUE);
00329 
00330     static wxLocale * GetLocale() {return m_pLocale;}
00331 
00332     static wxArrayString BitmapExtensions;
00333 
00334     static void SetGenerateXRCCheck(BOOL flag) {s_GenerateXRCCheck=flag;}
00335     static void * LoadFile( const wxString &str1, UINT32 * pSize );
00336 };
00337 
00338 
00339 class CamResourceRemember
00340 {
00341     friend class CamResource;
00342 
00343 private:
00344     CamResourceRemember * next;
00345     TCHAR * text;
00346 };
00347 
00348 
00349 
00350 #endif
00351 

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