1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxArtProvider class 
   4 // Author:      Vaclav Slavik 
   8 // Copyright:   (c) Vaclav Slavik 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // --------------------------------------------------------------------------- 
  14 // --------------------------------------------------------------------------- 
  17     #pragma implementation "artprov.h" 
  20 // For compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  23 #if defined(__BORLANDC__) 
  32 #include "wx/artprov.h" 
  33 #include "wx/hashmap.h" 
  34 #include "wx/module.h" 
  37 // =========================================================================== 
  39 // =========================================================================== 
  41 #include "wx/listimpl.cpp" 
  42 WX_DECLARE_LIST(wxArtProvider
, wxArtProvidersList
); 
  43 WX_DEFINE_LIST(wxArtProvidersList
); 
  45 // ---------------------------------------------------------------------------- 
  46 // Cache class - stores already requested bitmaps 
  47 // ---------------------------------------------------------------------------- 
  49 WX_DECLARE_STRING_HASH_MAP(wxBitmap
, wxArtProviderBitmapsHash
); 
  51 class WXDLLEXPORT wxArtProviderCache
 
  54     bool GetBitmap(const wxString
& full_id
, wxBitmap
* bmp
); 
  55     void PutBitmap(const wxString
& full_id
, const wxBitmap
& bmp
) 
  56         { m_bitmapsHash
[full_id
] = bmp
; } 
  60     static wxString 
ConstructHashID(const wxArtDomain
& domain
,  
  65     wxArtProviderBitmapsHash m_bitmapsHash
; 
  68 bool wxArtProviderCache::GetBitmap(const wxString
& full_id
, wxBitmap
* bmp
) 
  70     wxArtProviderBitmapsHash::iterator entry 
= m_bitmapsHash
.find(full_id
); 
  71     if ( entry 
== m_bitmapsHash
.end() ) 
  82 void wxArtProviderCache::Clear() 
  84     m_bitmapsHash
.clear(); 
  87 /*static*/ wxString 
wxArtProviderCache::ConstructHashID( 
  88                                     const wxArtDomain
& domain
,  
  89                                     const wxArtID
& id
, const wxSize
& size
) 
  92     str
.Printf(wxT("%s-%s-%i-%i"), domain
.c_str(), id
.c_str(), size
.x
, size
.y
); 
  97 // ---------------------------------------------------------------------------- 
  98 // wxArtProvider class 
  99 // ---------------------------------------------------------------------------- 
 101 IMPLEMENT_ABSTRACT_CLASS(wxArtProvider
, wxObject
) 
 103 wxArtProvidersList 
*wxArtProvider::sm_providers 
= NULL
; 
 104 wxArtProviderCache 
*wxArtProvider::sm_cache 
= NULL
; 
 106 /*static*/ void wxArtProvider::PushProvider(wxArtProvider 
*provider
) 
 110         sm_providers 
= new wxArtProvidersList
; 
 111         sm_providers
->DeleteContents(TRUE
); 
 112         sm_cache 
= new wxArtProviderCache
; 
 115     sm_providers
->Insert(provider
); 
 118 /*static*/ bool wxArtProvider::PopProvider() 
 120     wxCHECK_MSG( sm_providers
, FALSE
, _T("no wxArtProvider exists") ); 
 121     wxCHECK_MSG( sm_providers
->GetCount() > 0, FALSE
, _T("wxArtProviders stack is empty") ); 
 123     sm_providers
->DeleteNode(sm_providers
->GetFirst()); 
 128 /*static*/ bool wxArtProvider::RemoveProvider(wxArtProvider 
*provider
) 
 130     wxCHECK_MSG( sm_providers
, FALSE
, _T("no wxArtProvider exists") ); 
 132     if ( sm_providers
->DeleteObject(provider
) ) 
 141 /*static*/ void wxArtProvider::CleanUpProviders() 
 143     wxDELETE(sm_providers
); 
 147 /*static*/ wxBitmap 
wxArtProvider::GetBitmap(const wxArtDomain
& domain
, 
 151     wxCHECK_MSG( sm_providers
, wxNullBitmap
, _T("no wxArtProvider exists") ); 
 153     wxString hashId 
= wxArtProviderCache::ConstructHashID(domain
, id
, size
); 
 156     if ( !sm_cache
->GetBitmap(hashId
, &bmp
) ) 
 158         for (wxArtProvidersList::Node 
*node 
= sm_providers
->GetFirst(); 
 159              node
; node 
= node
->GetNext()) 
 161             bmp 
= node
->GetData()->CreateBitmap(domain
, id
, size
); 
 165         sm_cache
->PutBitmap(hashId
, bmp
); 
 171 /*static*/ wxIcon 
wxArtProvider::GetIcon(const wxArtDomain
& domain
,  
 175     wxCHECK_MSG( sm_providers
, wxNullIcon
, _T("no wxArtProvider exists") ); 
 177     wxBitmap bmp 
= GetBitmap(domain
, id
, size
); 
 181         icon
.CopyFromBitmap(bmp
); 
 192 class wxArtProviderModule
: public wxModule
 
 195     bool OnInit() { return TRUE
; } 
 196     void OnExit() { wxArtProvider::CleanUpProviders(); } 
 198     DECLARE_DYNAMIC_CLASS(wxArtProviderModule
) 
 201 IMPLEMENT_DYNAMIC_CLASS(wxArtProviderModule
, wxModule
)