cartprov.h

Go to the documentation of this file.
00001 // $Id: cartprov.h 1282 2006-06-09 09:46:49Z 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_CARTPROV
00100 #define INC_CARTPROV
00101 
00102 //#include "ccobject.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00103 
00104 class CamArtCacheEntry;
00105 class wxCamArtProviderEvent;
00106 
00107 enum CamArtFlags
00108 {
00109     // Caching flags start here - the art provider may have a different bitmap depending on the
00110     // state of these flags...
00111     CAF_SELECTED        = 1<<0,
00112     CAF_FOCUS           = 1<<1,
00113     CAF_GREYED          = 1<<2,
00114     CAF_SMALL           = 1<<3,
00115 
00116     CAF_CACHE_MAX       = 1<<4, // MUST lie at the end of the flags used for caching
00117 
00118     // These flags do not influence the bitmap itself, but influence how it is drawn
00119     CAF_TOOLBACKGROUND  = 1<<5,
00120     CAF_PUSHBUTTON      = 1<<6,
00121     CAF_TOGGLEBUTTON    = 1<<7, // unused here, but for the CACS_ stuff
00122     CAF_ALLOWHOVER      = 1<<8,
00123     CAF_TEXT            = 1<<9,
00124     CAF_EXACTFIT        = 1<<10, // For wxCACS
00125     CAF_HALFHEIGHT      = 1<<11, // For wxCACS
00126 
00127     CAF_TOP             = 1<<12,
00128     CAF_BOTTOM          = 1<<13,
00129     CAF_LEFT            = 1<<14,
00130     CAF_RIGHT           = 1<<15,
00131 
00132     CAF_BUTTONHOVER     = 1<<16, // this is set if the pointer IS CURRENTLY hovering
00133     CAF_ALWAYS3D        = 1<<17, // 3D even when not pushed in
00134 
00135     CAF_NOINTERNALBORDER= 1<<18, // Don't paint an internal border (unused, for CACS_)
00136 
00137     CAF_NOAUTOREPEAT    = 1<<19, // Used for CACS_
00138 
00139     CAF_STATUSBARTEXT   = 1<<20, // Used for status bar - render bit before :: in bold, chop on word boundaries
00140 
00141     // And this goes right at the end
00142     CAF_MAX             = 1<<21,
00143 
00144     // And here is the default
00145     CAF_DEFAULT         = 0
00146 };
00147 
00148 // A very simple class which the hash function hashes to
00149 class ImageAndBitmap : public SimpleCCObject
00150 {
00151 public:
00152     wxImage * m_pImage;
00153     wxBitmap * m_pBitmap;
00154     ImageAndBitmap(wxImage * pImage=NULL, wxBitmap * pBitmap=NULL) : m_pImage(pImage) , m_pBitmap(pBitmap) {}
00155     ~ImageAndBitmap() {if (m_pBitmap) delete (m_pBitmap); m_pBitmap=NULL; m_pImage=NULL; }
00156 };
00157 
00158 // Declare the hash map from ResourceID to a bitmap cache entry pointer
00159 // Note we have to set the hash map value to a wx type ... grrr...
00160 //typedef wxULongLong_t ResourceIDWithFlags;
00161 typedef UINT64 ResourceIDWithFlags;
00162 
00163 // hashing function
00164 class ResourceIDWithFlagsHash
00165 {
00166 public:
00167     ResourceIDWithFlagsHash() { }
00168 
00169     unsigned long /*TYPENOTE: Correct*/ operator()( const ResourceIDWithFlags& k ) const
00170         { return (/*TYPENOTE: Correct*/unsigned long)(k ^ (k>>32));}
00171 
00172     ResourceIDWithFlagsHash& operator=(const ResourceIDWithFlagsHash&) { return *this; }
00173 };
00174 
00175 // comparison operator
00176 class ResourceIDWithFlagsEqual
00177 {
00178 public:
00179     ResourceIDWithFlagsEqual() { }
00180     bool /*TYPENOTE: Correct*/ operator()( const ResourceIDWithFlags& a, const ResourceIDWithFlags& b ) const
00181         { return (a==b); }
00182 
00183     ResourceIDWithFlagsEqual& operator=(const ResourceIDWithFlagsEqual&) { return *this; }
00184 };
00185 
00186 WX_DECLARE_HASH_MAP( ResourceIDWithFlags, ImageAndBitmap, ResourceIDWithFlagsHash, ResourceIDWithFlagsEqual, ResIDWithFlagsToBitmapPtr );
00187 
00188 /*******************************************************************************************
00189 
00190 >   class CamArtProvider : public wxEvtHandler
00191 
00192     Author:     Alex_Bligh <alex@alex.org.uk>
00193     Created:    19/12/2005
00194     Purpose:    A derived event handler which providers art for bitmap buttons and
00195                 other controls within Camelot
00196     Notes:      In the OIL
00197     See Also:   
00198 
00199 This class is specificly written so it will provided cached vector-drawn art.
00200 
00201 ********************************************************************************************/
00202 
00203 class CamArtProvider : public wxEvtHandler
00204 {
00205 public:
00206     CamArtProvider();
00207     ~CamArtProvider(); // Note - do not call the destructor from within an event being handled!
00208 
00209 private:
00210     static CamArtProvider * m_ArtProvider;
00211 
00212 public:
00213     static BOOL Init();
00214     static void DeInit();
00215     static CamArtProvider * Get() {return m_ArtProvider;}
00216 
00217     void GetBitmapEvent(wxCamArtProviderEvent &event);
00218     void InvalidateArtEvent(wxCamArtProviderEvent &event);
00219     void Draw (wxDC& dc, const wxRect & rect, ResourceID Resource, CamArtFlags Flags = CAF_DEFAULT, const wxString &text = wxEmptyString);
00220 
00221     wxSize GetSize(ResourceID r, CamArtFlags Flags=CAF_DEFAULT, const wxString &text = wxEmptyString);
00222     
00223     void EnsureBitmapLoaded(ResourceID Resource, BOOL SkipArtLoad = FALSE);
00224     void EnsureChildBitmapsLoaded(wxWindow * pWindow = NULL, BOOL SkipArtLoad = FALSE);
00225     void ReloadAllArt();
00226     wxBitmap * FindBitmap(ResourceID Resource, CamArtFlags Flags = CAF_DEFAULT, BOOL SkipArtLoad=FALSE);
00227     wxImage * FindImage(ResourceID Resource, CamArtFlags Flags = CAF_DEFAULT, BOOL SkipArtLoad=FALSE);
00228 
00229     static CamArtFlags GetBitmapFlags(const wxString &str);
00230     static wxString MakeBitmapFlagString(const CamArtFlags flags);
00231 
00232     wxImage * GetMissingImage() const {return m_pMissingImage;}
00233     wxBitmap * GetMissingBitmap() const {return m_pMissingBitmap;}
00234 
00235 protected:
00236     ResIDWithFlagsToBitmapPtr::iterator Find(ResourceID Resource, CamArtFlags Flags, BOOL SkipArtLoad);
00237 
00238     ResourceIDWithFlags CombineFlags(ResourceID Resource, CamArtFlags Flags) { return Resource | (((UINT64)Flags)<<32) ; }
00239     CamArtFlags GetFlags(ResourceIDWithFlags ResWithFlags) { return (CamArtFlags)(ResWithFlags>>32); }
00240     ResourceID GetResourceID(ResourceIDWithFlags ResWithFlags) { return (ResourceID)(ResWithFlags & 0xFFFFFFFF); } // mask unnecessary but for clarity
00241 
00242     static wxColor DarkenColour(const wxColor& c, INT32 amount);
00243     static wxColor LightenColour(const wxColor& c, INT32 amount);
00244 
00245     wxImage * MakeBitmap(ResourceIDWithFlags ResWithFlags);
00246     void InvalidateAllArt();
00247     void InvalidateAllArtInChildren(wxWindow * pWindow);
00248     void DeleteHashContents();
00249     void ArtLoad(BOOL newbitmaps = FALSE, BOOL defer=TRUE);
00250 
00251     wxSize GetBorderSize(CamArtFlags Flags=CAF_DEFAULT);
00252     wxString GetTextInfoOrDraw(ResourceID r, CamArtFlags f, wxDC &dc, BOOL Draw=FALSE, wxCoord *w=NULL, wxCoord *h=NULL,
00253                                 wxCoord x=0, wxCoord y=0, wxCoord MaxWidth=-1, const wxString &text = wxEmptyString);
00254 
00255     ResIDWithFlagsToBitmapPtr * m_pHash;
00256     BOOL m_GetBitmapEventPending;
00257     BOOL m_InvalidateArtEventPending;
00258     wxImage * m_pMissingImage;
00259     wxBitmap * m_pMissingBitmap;
00260 
00261     DECLARE_CLASS(wxEvtHandler)
00262     DECLARE_EVENT_TABLE()
00263 
00264 };
00265 
00266 
00267 /*******************************************************************************************
00268 
00269 >   class wxCamArtProviderEvent : public wxEvent
00270 
00271     Author:     Alex_Bligh <alex@alex.org.uk>
00272     Created:    19/12/2005
00273     Purpose:    A derived event to allow for postprocessing of dialog events
00274     Notes:      In the OIL
00275     See Also:   
00276 
00277 ********************************************************************************************/
00278 
00279 class wxCamArtProviderEvent : public wxEvent
00280 {
00281 public:
00282     // Aargh note wxEvent's constructor has paramaters the otherway around from this - designed to match wxCommandEvent
00283     wxCamArtProviderEvent(wxEventType commandType = wxEVT_NULL, INT32 id=0, BOOL deferred=FALSE ) : wxEvent(id, commandType) {m_deferred=deferred;}
00284 
00285     wxCamArtProviderEvent(const wxCamArtProviderEvent& event) : wxEvent(event) {m_deferred=event.m_deferred;}
00286 
00287     virtual wxEvent *Clone() const {return new wxCamArtProviderEvent(*this); }
00288 
00289     BOOL m_deferred;
00290 
00291     DECLARE_DYNAMIC_CLASS(wxCamArtProviderEvent);
00292 
00293 };
00294 
00295 
00296 typedef void (wxEvtHandler::*wxCamArtProviderEventFunction)(wxCamArtProviderEvent &);
00297 
00298 BEGIN_DECLARE_EVENT_TYPES()
00299     DECLARE_EVENT_TYPE(wxEVT_CAMARTPROVIDER_GETBITMAP, 1101)
00300     DECLARE_EVENT_TYPE(wxEVT_CAMARTPROVIDER_INVALIDATEART, 1102)
00301 END_DECLARE_EVENT_TYPES()
00302 
00303 #define EVT_CAMARTPROVIDER_GETBITMAP(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_CAMARTPROVIDER_GETBITMAP, id, -1, \
00304     (wxObjectEventFunction)(wxEventFunction)(wxCamArtProviderEventFunction) &fn, (wxObject *) NULL),
00305 #define EVT_CAMARTPROVIDER_INVALIDATEART(id, fn) DECLARE_EVENT_TABLE_ENTRY(wxEVT_CAMARTPROVIDER_INVALIDATEART, id, -1, \
00306     (wxObjectEventFunction)(wxEventFunction)(wxCamArtProviderEventFunction) &fn, (wxObject *) NULL),
00307 
00308 #endif
00309 

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