From: Václav Slavík Date: Tue, 19 Mar 2002 23:40:25 +0000 (+0000) Subject: added wxArtProvider X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2aca4a98866064d116c30a477b49a7a7c04cf58c?hp=bbc3925a8a46e8c80b22277f5571dfb2465aca25 added wxArtProvider git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14688 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/art/browser/back.xpm b/art/browser/back.xpm new file mode 100644 index 0000000000..fbb4378bf6 --- /dev/null +++ b/art/browser/back.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * back_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #C0E4CB", +"@ c #77C490", +"# c #808080", +" ", +" ", +" . ", +" .. ", +" .+. ", +" .++........ ", +" .++@+++++++. ", +" .++@@@@@@@@@. ", +" .+@@@@@@@@@. ", +" #.+@........ ", +" #.+.####### ", +" #..# ", +" #.# ", +" ## ", +" # ", +" "}; diff --git a/art/browser/down.xpm b/art/browser/down.xpm new file mode 100644 index 0000000000..055540b649 --- /dev/null +++ b/art/browser/down.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * down_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #808080", +"@ c #C0E4CB", +"# c #77C490", +" ", +" .....+ ", +" .@##.+ ", +" .@##.+ ", +" .@##.+ ", +" .@##.+ ", +" .@##.+ ", +" .@##.+++++ ", +" ....@##....+ ", +" .@@####@.+ ", +" .@@##@.+ ", +" .@@@.+ ", +" .@.+ ", +" . ", +" ", +" "}; diff --git a/art/browser/forward.xpm b/art/browser/forward.xpm new file mode 100644 index 0000000000..6e3de64511 --- /dev/null +++ b/art/browser/forward.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * forward_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #C0E4CB", +"@ c #77C490", +"# c #808080", +" ", +" ", +" . ", +" .. ", +" .+. ", +" ........++. ", +" .+++++++@++. ", +" .@@@@@@@@@++. ", +" .@@@@@@@@@+. ", +" ........@+.# ", +" #######.+.# ", +" #..# ", +" #.# ", +" ## ", +" # ", +" "}; diff --git a/art/browser/toparent.xpm b/art/browser/toparent.xpm new file mode 100644 index 0000000000..04e996dfd5 --- /dev/null +++ b/art/browser/toparent.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * toparent_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #C0E4CB", +"@ c #808080", +"# c #77C490", +" ", +" ", +" . ", +" .+.@ ", +" .+++.@ ", +" .++##+.@ ", +" .++####+.@ ", +" ....+##....@ ", +" .+##.@@@@@ ", +" .+##...... ", +" .+#######.@ ", +" .+#######.@ ", +" .+#######.@ ", +" ..........@ ", +" ", +" "}; diff --git a/art/browser/up.xpm b/art/browser/up.xpm new file mode 100644 index 0000000000..5d75546ed5 --- /dev/null +++ b/art/browser/up.xpm @@ -0,0 +1,24 @@ +/* XPM */ +static char * up_xpm[] = { +"16 16 5 1", +" c None", +". c #000000", +"+ c #C0E4CB", +"@ c #808080", +"# c #77C490", +" ", +" . ", +" .+.@ ", +" .+++.@ ", +" .++##+.@ ", +" .++####+.@ ", +" ....+##....@ ", +" .+##.@@@@@ ", +" .+##.@ ", +" .+##.@ ", +" .+##.@ ", +" .+##.@ ", +" .+##.@ ", +" .....@ ", +" ", +" "}; diff --git a/art/framicon/help.xpm b/art/framicon/help.xpm new file mode 100644 index 0000000000..8371927b34 --- /dev/null +++ b/art/framicon/help.xpm @@ -0,0 +1,44 @@ +/* XPM */ +static char *help_xpm[] = { +/* columns rows colors chars-per-pixel */ +"32 32 6 1", +" c Gray0", +". c Blue", +"X c #808080808080", +"o c #c0c0c0c0c0c0", +"O c Gray100", +"+ c None", +/* pixels */ +"+++++++++++XXXXXXXX+++++++++++++", +"++++++++XXXoOOOOOOoXXX++++++++++", +"++++++XXoOOOOOOOOOOOOoXX++++++++", +"+++++XoOOOOOOOOOOOOOOOOoX+++++++", +"++++XOOOOOOOOOOOOOOOOOOOO ++++++", +"+++XOOOOOOOo......oOOOOOOO +++++", +"++XOOOOOOOo.oOO....oOOOOOOO ++++", +"+XoOOOOOOO..OOOO....OOOOOOOo +++", +"+XOOOOOOOO....OO....OOOOOOOO X++", +"XoOOOOOOOO....Oo....OOOOOOOOo X+", +"XOOOOOOOOOo..oO....OOOOOOOOOO X+", +"XOOOOOOOOOOOOOo...OOOOOOOOOOO XX", +"XOOOOOOOOOOOOO...OOOOOOOOOOOO XX", +"XOOOOOOOOOOOOO..oOOOOOOOOOOOO XX", +"XOOOOOOOOOOOOO..OOOOOOOOOOOOO XX", +"XoOOOOOOOOOOOOOOOOOOOOOOOOOOo XX", +"+XOOOOOOOOOOOo..oOOOOOOOOOOO XXX", +"+XoOOOOOOOOOO....OOOOOOOOOOo XXX", +"++XOOOOOOOOOO....OOOOOOOOOO XXX+", +"+++ OOOOOOOOOo..oOOOOOOOOO XXXX+", +"++++ OOOOOOOOOOOOOOOOOOOO XXXX++", +"+++++ oOOOOOOOOOOOOOOOOo XXXX+++", +"++++++ oOOOOOOOOOOOOo XXXX++++", +"+++++++X oOOOOOOo XXXXX+++++", +"++++++++XXX oOOO XXXXXXX++++++", +"++++++++++XXXX OOO XXXXX++++++++", +"+++++++++++++X OOO XX+++++++++++", +"+++++++++++++++ OO XX+++++++++++", +"++++++++++++++++ O XX+++++++++++", +"+++++++++++++++++ XX+++++++++++", +"++++++++++++++++++XXX+++++++++++", +"+++++++++++++++++++XX+++++++++++" +}; diff --git a/art/toolbar/fileopen.xpm b/art/toolbar/fileopen.xpm new file mode 100644 index 0000000000..740983e709 --- /dev/null +++ b/art/toolbar/fileopen.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char *fileopen_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 5 1", +" c None", +". c Black", +"X c Yellow", +"o c Gray100", +"O c #bfbf00", +/* pixels */ +" ", +" ... ", +" . . .", +" ..", +" ... ...", +" .XoX....... ", +" .oXoXoXoXo. ", +" .XoXoXoXoX. ", +" .oXoX..........", +" .XoX.OOOOOOOOO.", +" .oo.OOOOOOOOO. ", +" .X.OOOOOOOOO. ", +" ..OOOOOOOOO. ", +" ........... ", +" " +}; diff --git a/art/toolbar/print.xpm b/art/toolbar/print.xpm new file mode 100644 index 0000000000..3c2e2be781 --- /dev/null +++ b/art/toolbar/print.xpm @@ -0,0 +1,26 @@ +/* XPM */ +static char *print_xpm[] = { +/* columns rows colors chars-per-pixel */ +"16 15 5 1", +" c None", +". c Black", +"X c Gray100", +"o c #808000", +"O c Yellow", +/* pixels */ +" ", +" ......... ", +" .XXXXXXXX. ", +" .X.....X. ", +" .XXXXXXXX. ", +" .X.....X.... ", +" .XXXXXXXX. . .", +" .......... . ..", +". . . .", +"............. .", +". ooo . . ", +". OOO ... ", +"............. . ", +" . . . ", +" ........... " +}; diff --git a/art/wxhtml/addbookm.xpm b/art/wxhtml/addbookm.xpm new file mode 100644 index 0000000000..71de717634 --- /dev/null +++ b/art/wxhtml/addbookm.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * addbookm_xpm[] = { +"16 16 3 1", +" c None", +". c #33EF0E", +"+ c #000000", +" ", +" ... ", +" ... ", +" ...+ ", +" ...+ ", +" ...+ ", +" ............. ", +" ............. ", +" .............+ ", +" +++...++++++ ", +" ...+ ", +" ...+ ", +" ...+ ", +" ...+ ", +" ++ ", +" "}; diff --git a/art/wxhtml/book.xpm b/art/wxhtml/book.xpm new file mode 100644 index 0000000000..3146053f85 --- /dev/null +++ b/art/wxhtml/book.xpm @@ -0,0 +1,40 @@ +/* XPM */ +static char * book_xpm[] = { +"16 16 21 1", +" c None", +". c #007F7F", +"+ c #660000", +"@ c #CC0000", +"# c #E50000", +"$ c #FF0000", +"% c #F20000", +"& c #D80000", +"* c #720000", +"= c #7F0000", +"- c #BFBFBF", +"; c #E57F7F", +"> c #7F7F7F", +", c #FFFFFF", +"' c #F2BFBF", +") c #723F3F", +"! c #A5A5A5", +"~ c #E5E5E5", +"{ c #B2B2B2", +"] c #003F3F", +"^ c #000000", +" ", +" ......... ", +" +@#$$$$$%&+ ", +" +##$$$$$$$* ", +" +##$$$$$$$=- ", +" +##$$$$$$$=;> ", +" +##$$$$$$$=;,. ", +" +##$$$$$$$=;,. ", +" +##$$$$$$$=''. ", +" +##$$$$$$$=,;. ", +" +##$$$$$$%+,;. ", +" +&++++++++),;. ", +" ++!~~~~~~~~~,. ", +" ++!~~~~~~~~~{. ", +" ]^^^^^^^^^^^ ", +" "}; diff --git a/art/wxhtml/delbookm.xpm b/art/wxhtml/delbookm.xpm new file mode 100644 index 0000000000..1d334363e0 --- /dev/null +++ b/art/wxhtml/delbookm.xpm @@ -0,0 +1,22 @@ +/* XPM */ +static char * delbookm_xpm[] = { +"16 16 3 1", +" c None", +". c #FF0000", +"+ c #000000", +" ", +" ... . ", +" .... ..+ ", +" +.... ..+ ", +" ++... ..+ ", +" +.....+ ", +" +...+ ", +" ..... ", +" ...++.. ", +" ...+ +.. ", +" ...+ +. ", +" .... +. ", +" ...+ + ", +" +.+ . ", +" + + ", +" "}; diff --git a/art/wxhtml/folder.xpm b/art/wxhtml/folder.xpm new file mode 100644 index 0000000000..558dfb9e97 --- /dev/null +++ b/art/wxhtml/folder.xpm @@ -0,0 +1,28 @@ +/* XPM */ +static char * folder_xpm[] = { +/* width height ncolors chars_per_pixel */ +"16 16 6 1", +/* colors */ +" s None c None", +". c #000000", +"+ c #c0c0c0", +"@ c #808080", +"# c #ffff00", +"$ c #ffffff", +/* pixels */ +" ", +" @@@@@ ", +" @#+#+#@ ", +" @#+#+#+#@@@@@@ ", +" @$$$$$$$$$$$$@.", +" @$#+#+#+#+#+#@.", +" @$+#+#+#+#+#+@.", +" @$#+#+#+#+#+#@.", +" @$+#+#+#+#+#+@.", +" @$#+#+#+#+#+#@.", +" @$+#+#+#+#+#+@.", +" @$#+#+#+#+#+#@.", +" @@@@@@@@@@@@@@.", +" ..............", +" ", +" "}; diff --git a/art/wxhtml/navig.xpm b/art/wxhtml/navig.xpm new file mode 100644 index 0000000000..7072eb92e9 --- /dev/null +++ b/art/wxhtml/navig.xpm @@ -0,0 +1,122 @@ +/* XPM */ +static char * navig_xpm[] = { +"16 15 104 2", +" c None", +". c #7F7C7C", +"+ c #8A8E8E", +"@ c #D03232", +"# c #BA7E7E", +"$ c #555858", +"% c #5F5F5F", +"& c #656565", +"* c #5D5D5D", +"= c #939696", +"- c #FFFFFF", +"; c #F4C8C8", +"> c #DCDCF4", +", c #D3D3D3", +"' c #4E5151", +") c #7E7E7E", +"! c #9E9E9E", +"~ c #A7A7A7", +"{ c #5C5C5C", +"] c #9B9E9E", +"^ c #A3A3FF", +"/ c #BBBBFF", +"( c #DBDBDB", +"_ c #808B8B", +": c #5E5E5E", +"< c #858571", +"[ c #AEAE4B", +"} c #90902D", +"| c #8B8B8B", +"1 c #000027", +"2 c #D7D7FF", +"3 c #C3C3FF", +"4 c #A7A7FF", +"5 c #9B9BFF", +"6 c #D7D7D7", +"7 c #717474", +"8 c #727D7D", +"9 c #575721", +"0 c #BFBF7F", +"a c #DFDF8F", +"b c #DFDF60", +"c c #7F7F3B", +"d c #2F2F7F", +"e c #AFAFF3", +"f c #E7E7E7", +"g c #9797E7", +"h c #8787F3", +"i c #AFAFC3", +"j c #4F4F37", +"k c #8E9898", +"l c #484824", +"m c #4D4D0B", +"n c #8C8C8C", +"o c #7D7D36", +"p c #74742D", +"q c #535353", +"r c #636363", +"s c #5C5C4C", +"t c #818149", +"u c #78784C", +"v c #787840", +"w c #7E7E40", +"x c #787E46", +"y c #757F7F", +"z c #616121", +"A c #87874B", +"B c #C8C88C", +"C c #F6F6B6", +"D c #D4D498", +"E c #6C6C30", +"F c #424242", +"G c #9D9D23", +"H c #FDFD7B", +"I c #FFFF7F", +"J c #7F7F3F", +"K c #737C7C", +"L c #808038", +"M c #6B6B5F", +"N c #797935", +"O c #6E6E62", +"P c #8B8B43", +"Q c #8D8D8D", +"R c #1C4B4B", +"S c #959523", +"T c #F9F973", +"U c #7F7F43", +"V c #737D7D", +"W c #939343", +"X c #4FD3D3", +"Y c #185353", +"Z c #8D8D27", +"` c #F5F56B", +" . c #9B9B43", +".. c #57CFCF", +"+. c #145B5B", +"@. c #85851E", +"#. c #A3A343", +"$. c #3BA7A7", +"%. c #636300", +"&. c #CFCF67", +"*. c #F3F367", +"=. c #909A9A", +"-. c #4B4B07", +";. c #434325", +" . ", +" + @ # ", +" $ % & * = - ; > , ", +" ' ) ! ~ ~ { ] - - ^ / - ( ", +"_ : < [ [ } | 1 2 - 3 / 4 5 6 7 ", +"8 9 0 a b c 3 d e f f g h i j ", +"k l m n o p q r s t t t u v w x ", +"y z A B C D E F G H I I I I I J ", +"K I L M N O P Q R S T I I I I U ", +"V I I I I I I W X Y Z ` I I I U ", +"8 I I I I I I I ...+.@.I I I U ", +"K I I I I I I I I #.$.%.I I I U ", +"8 I I I I I I I I I &.*.I I I U ", +"V I I I I I I I I I I I I I I U ", +"=.-.-.-.-.-.-.-.-.-.-.-.-.-.-.;."}; diff --git a/art/wxhtml/page.xpm b/art/wxhtml/page.xpm new file mode 100644 index 0000000000..f8bf0c0057 --- /dev/null +++ b/art/wxhtml/page.xpm @@ -0,0 +1,25 @@ +/* XPM */ +static char * page_xpm[] = { +/* width height ncolors chars_per_pixel */ +"16 16 3 1", +/* colors */ +" s None c None", +". c #000000", +"+ c #ffffff", +/* pixels */ +" ", +" ........ ", +" .++++++.. ", +" .+.+.++.+. ", +" .++++++.... ", +" .+.+.+++++. ", +" .+++++++++. ", +" .+.+.+.+.+. ", +" .+++++++++. ", +" .+.+.+.+.+. ", +" .+++++++++. ", +" .+.+.+.+.+. ", +" .+++++++++. ", +" ........... ", +" ", +" "}; diff --git a/art/wxhtml/settings.xpm b/art/wxhtml/settings.xpm new file mode 100644 index 0000000000..f06e8e92a8 --- /dev/null +++ b/art/wxhtml/settings.xpm @@ -0,0 +1,21 @@ +/* XPM */ +static char * settings_xpm[] = { +"16 16 2 1", +" c None", +". c #000000", +" ", +" .. ", +" ... ", +" .... ", +" . ... ", +" .. ... ", +" . .. ", +" .. ... ", +" . .. ", +" ......... ", +" .. ... ", +" . ... ", +" .. ... ", +" .... ....... ", +" ", +" "}; diff --git a/include/wx/artprov.h b/include/wx/artprov.h new file mode 100644 index 0000000000..bae82969f3 --- /dev/null +++ b/include/wx/artprov.h @@ -0,0 +1,119 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: artprov.h +// Purpose: wxArtProvider class +// Author: Vaclav Slavik +// Modified by: +// Created: 18/03/2002 +// RCS-ID: $Id$ +// Copyright: (c) Vaclav Slavik +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_ARTPROV_H_ +#define _WX_ARTPROV_H_ + +#ifdef __GNUG__ +#pragma interface "artprov.h" +#endif + +#include "wx/string.h" +#include "wx/bitmap.h" +#include "wx/icon.h" + +class WXDLLEXPORT wxArtProvidersList; +class WXDLLEXPORT wxArtProviderCache; + +// ---------------------------------------------------------------------------- +// Types +// ---------------------------------------------------------------------------- + +typedef wxString wxArtDomain; +typedef wxString wxArtID; + +// ---------------------------------------------------------------------------- +// wxArtProvider class +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxArtProvider : public wxObject +{ +public: + // Add new provider to the top of providers stack. + static void PushProvider(wxArtProvider *provider); + + // Remove latest added provider and delete it. + static bool PopProvider(); + + // Remove provider. The provider must have been added previously! + // The provider is _not_ deleted. + static bool RemoveProvider(wxArtProvider *provider); + + // Query the providers for bitmap with given ID and return it. Return + // wxNullBitmap if no provider provides it. + static wxBitmap GetBitmap(const wxArtDomain& domain, const wxArtID& id, + const wxSize& size = wxDefaultSize); + + // Query the providers for icon with given ID and return it. Return + // wxNullIcon if no provider provides it. + static wxIcon GetIcon(const wxArtDomain& domain, const wxArtID& id, + const wxSize& size = wxDefaultSize); + + // Destroy caches & all providers + static void CleanUpProviders(); + +protected: + // Derived classes must override this method to create requested + // art resource. This method is called only once per instance's + // lifetime for each requested wxArtID. + virtual wxBitmap CreateBitmap(const wxArtDomain& WXUNUSED(domain), + const wxArtID& WXUNUSED(id), + const wxSize& WXUNUSED(size)) + { + wxFAIL_MSG(_T("pure virtual method wxArtProvider::CreateBitmap called!")); + return wxNullBitmap; + } + +private: + // list of providers: + static wxArtProvidersList *sm_providers; + // art resources cache (so that CreateXXX is not called that often): + static wxArtProviderCache *sm_cache; + + DECLARE_ABSTRACT_CLASS(wxArtProvider) +}; + + +// ---------------------------------------------------------------------------- +// Art pieces identifiers +// ---------------------------------------------------------------------------- + +// This is comprehensive list of art identifiers recognized by wxWindows. The +// identifiers follow two-levels scheme where a piece of art is described by +// its domain (file dialog, HTML help toolbar etc.) and resource identifier +// within the domain + +#define wxART_WXHTML _T("wxhtml") + #define wxART_ADD_BOOKMARK _T("add_bookmark") + #define wxART_DEL_BOOKMARK _T("del_bookmark") + #define wxART_NAVIG_PANEL _T("navig_panel") + #define wxART_HELP_SETTINGS _T("help_settings") + #define wxART_HELP_BOOK _T("help_book") + #define wxART_HELP_FOLDER _T("help_folder") + #define wxART_HELP_PAGE _T("help_page") + +#define wxART_BROWSER_TOOLBAR _T("browser_toolbar") + #define wxART_GO_BACK _T("go_back") + #define wxART_GO_FORWARD _T("go_forward") + #define wxART_GO_UP _T("go_up") + #define wxART_GO_DOWN _T("go_down") + #define wxART_GO_TO_PARENT _T("go_to_parent") + +#define wxART_TOOLBAR _T("toolbar") + #define wxART_FILE_OPEN _T("file_open") + #define wxART_PRINT _T("print") + +#define wxART_FRAME_ICON _T("frame_icon") + #define wxART_HELP _T("help") + + + +#endif // _WX_ARTPROV_H_ diff --git a/src/common/artprov.cpp b/src/common/artprov.cpp new file mode 100644 index 0000000000..a8785916b5 --- /dev/null +++ b/src/common/artprov.cpp @@ -0,0 +1,201 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: artprov.cpp +// Purpose: wxArtProvider class +// Author: Vaclav Slavik +// Modified by: +// Created: 18/03/2002 +// RCS-ID: $Id$ +// Copyright: (c) Vaclav Slavik +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "artprov.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/list.h" +#endif + +#include "wx/artprov.h" +#include "wx/hashmap.h" +#include "wx/module.h" + + +// =========================================================================== +// implementation +// =========================================================================== + +#include "wx/listimpl.cpp" +WX_DECLARE_LIST(wxArtProvider, wxArtProvidersList); +WX_DEFINE_LIST(wxArtProvidersList); + +// ---------------------------------------------------------------------------- +// Cache class - stores already requested bitmaps +// ---------------------------------------------------------------------------- + +WX_DECLARE_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash); + +class WXDLLEXPORT wxArtProviderCache +{ +public: + bool GetBitmap(const wxString& full_id, wxBitmap* bmp); + void PutBitmap(const wxString& full_id, const wxBitmap& bmp) + { m_bitmapsHash[full_id] = bmp; } + + void Clear(); + + static wxString ConstructHashID(const wxArtDomain& domain, + const wxArtID& id, + const wxSize& size); + +private: + wxArtProviderBitmapsHash m_bitmapsHash; +}; + +bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp) +{ + wxArtProviderBitmapsHash::iterator entry = m_bitmapsHash.find(full_id); + if ( entry == m_bitmapsHash.end() ) + { + return FALSE; + } + else + { + *bmp = entry->second; + return TRUE; + } +} + +void wxArtProviderCache::Clear() +{ + m_bitmapsHash.clear(); +} + +/*static*/ wxString wxArtProviderCache::ConstructHashID( + const wxArtDomain& domain, + const wxArtID& id, const wxSize& size) +{ + wxString str; + str.Printf(wxT("%s-%s-%i-%i"), domain.c_str(), id.c_str(), size.x, size.y); + return str; +} + + +// ---------------------------------------------------------------------------- +// wxArtProvider class +// ---------------------------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxArtProvider, wxObject) + +wxArtProvidersList *wxArtProvider::sm_providers = NULL; +wxArtProviderCache *wxArtProvider::sm_cache = NULL; + +/*static*/ void wxArtProvider::PushProvider(wxArtProvider *provider) +{ + if ( !sm_providers ) + { + sm_providers = new wxArtProvidersList; + sm_providers->DeleteContents(TRUE); + sm_cache = new wxArtProviderCache; + } + + sm_providers->Insert(provider); +} + +/*static*/ bool wxArtProvider::PopProvider() +{ + wxCHECK_MSG( sm_providers, FALSE, _T("no wxArtProvider exists") ); + wxCHECK_MSG( sm_providers->GetCount() > 0, FALSE, _T("wxArtProviders stack is empty") ); + + sm_providers->DeleteNode(sm_providers->GetFirst()); + sm_cache->Clear(); + return TRUE; +} + +/*static*/ bool wxArtProvider::RemoveProvider(wxArtProvider *provider) +{ + wxCHECK_MSG( sm_providers, FALSE, _T("no wxArtProvider exists") ); + + if ( sm_providers->DeleteObject(provider) ) + { + sm_cache->Clear(); + return TRUE; + } + + return FALSE; +} + +/*static*/ void wxArtProvider::CleanUpProviders() +{ + wxDELETE(sm_providers); + wxDELETE(sm_cache); +} + +/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtDomain& domain, + const wxArtID& id, + const wxSize& size) +{ + wxCHECK_MSG( sm_providers, wxNullBitmap, _T("no wxArtProvider exists") ); + + wxString hashId = wxArtProviderCache::ConstructHashID(domain, id, size); + + wxBitmap bmp; + if ( !sm_cache->GetBitmap(hashId, &bmp) ) + { + for (wxArtProvidersList::Node *node = sm_providers->GetFirst(); + node; node = node->GetNext()) + { + bmp = node->GetData()->CreateBitmap(domain, id, size); + if ( bmp.Ok() ) + break; + } + sm_cache->PutBitmap(hashId, bmp); + } + + return bmp; +} + +/*static*/ wxIcon wxArtProvider::GetIcon(const wxArtDomain& domain, + const wxArtID& id, + const wxSize& size) +{ + wxCHECK_MSG( sm_providers, wxNullIcon, _T("no wxArtProvider exists") ); + + wxBitmap bmp = GetBitmap(domain, id, size); + if ( bmp.Ok() ) + { + wxIcon icon; + icon.CopyFromBitmap(bmp); + return icon; + } + else + { + return wxNullIcon; + } +} + + + +class wxArtProviderModule: public wxModule +{ +public: + bool OnInit() { return TRUE; } + void OnExit() { wxArtProvider::CleanUpProviders(); } + + DECLARE_DYNAMIC_CLASS(wxArtProviderModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxArtProviderModule, wxModule) diff --git a/src/common/artstd.cpp b/src/common/artstd.cpp new file mode 100644 index 0000000000..bcd007fff3 --- /dev/null +++ b/src/common/artstd.cpp @@ -0,0 +1,133 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: artstd.cpp +// Purpose: stock wxArtProvider instance with default wxWin art +// Author: Vaclav Slavik +// Modified by: +// Created: 18/03/2002 +// RCS-ID: $Id$ +// Copyright: (c) Vaclav Slavik +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "artprov.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if defined(__BORLANDC__) + #pragma hdrstop +#endif + +#include "wx/artprov.h" +#include "wx/module.h" + +// ---------------------------------------------------------------------------- +// wxDefaultArtProvider +// ---------------------------------------------------------------------------- + +class wxDefaultArtProvider : public wxArtProvider +{ +protected: + virtual wxBitmap CreateBitmap(const wxArtDomain& domain, + const wxArtID& id, const wxSize& size); +}; + +#define BEGIN_DOMAIN(domainId) if ( domain == domainId ) { +#define END_DOMAIN() } +#define ART_ID(artId, xpmRc) if ( id == artId ) return wxBitmap(xpmRc##_xpm); + +// ---------------------------------------------------------------------------- +// wxDefaultArtProviderModule +// ---------------------------------------------------------------------------- + +class wxDefaultArtProviderModule: public wxModule +{ +public: + bool OnInit() + { + wxArtProvider::PushProvider(new wxDefaultArtProvider); + return TRUE; + } + void OnExit() {} + + DECLARE_DYNAMIC_CLASS(wxDefaultArtProviderModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxDefaultArtProviderModule, wxModule) + + +// ---------------------------------------------------------------------------- +// XPMs with the art +// ---------------------------------------------------------------------------- + +// XPM hack: make the arrays const +#define static static const + +#if wxUSE_HTML +#include "../../art/wxhtml/addbookm.xpm" +#include "../../art/wxhtml/delbookm.xpm" +#include "../../art/wxhtml/navig.xpm" +#include "../../art/wxhtml/settings.xpm" +#include "../../art/wxhtml/book.xpm" +#include "../../art/wxhtml/folder.xpm" +#include "../../art/wxhtml/page.xpm" +#endif // wxUSE_HTML + +#include "../../art/browser/back.xpm" +#include "../../art/browser/forward.xpm" +#include "../../art/browser/up.xpm" +#include "../../art/browser/down.xpm" +#include "../../art/browser/toparent.xpm" + +#include "../../art/toolbar/fileopen.xpm" +#include "../../art/toolbar/print.xpm" + +#include "../../art/framicon/help.xpm" + +#undef static + +// ---------------------------------------------------------------------------- +// CreateBitmap routine +// ---------------------------------------------------------------------------- + +wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtDomain& domain, + const wxArtID& id, + const wxSize& size) +{ +#if wxUSE_HTML + BEGIN_DOMAIN(wxART_WXHTML) + ART_ID(wxART_ADD_BOOKMARK, addbookm) + ART_ID(wxART_DEL_BOOKMARK, delbookm) + ART_ID(wxART_NAVIG_PANEL, navig) + ART_ID(wxART_HELP_SETTINGS, settings) + ART_ID(wxART_HELP_BOOK, book) + ART_ID(wxART_HELP_FOLDER, folder) + ART_ID(wxART_HELP_PAGE, page) + END_DOMAIN() +#endif // wxUSE_HTML + + BEGIN_DOMAIN(wxART_BROWSER_TOOLBAR) + ART_ID(wxART_GO_BACK, back) + ART_ID(wxART_GO_FORWARD, forward) + ART_ID(wxART_GO_UP, up) + ART_ID(wxART_GO_DOWN, down) + ART_ID(wxART_GO_TO_PARENT, toparent) + END_DOMAIN() + + BEGIN_DOMAIN(wxART_TOOLBAR) + ART_ID(wxART_FILE_OPEN, fileopen) + ART_ID(wxART_PRINT, print) + END_DOMAIN() + + BEGIN_DOMAIN(wxART_FRAME_ICON) + ART_ID(wxART_HELP, help) + END_DOMAIN() + + return wxNullBitmap; +}