1. deprecate redundantly sounding wxArtProvider::FooProvider() to just Foo()

2. wxArtProvider::Remove() now really only removes the provider without
   deleting it, Delete() does delete it
3. moreover, ~wxArtProvider removes the provider as well so there is almost
   no need to call Delete() explicitly any more


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41398 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-09-23 20:16:18 +00:00
parent 43e995b6e3
commit 571d2e0f23
10 changed files with 150 additions and 43 deletions

View File

@@ -13,7 +13,7 @@ replace standard art with their own version. All
that is needed is to derive a class from wxArtProvider, override its that is needed is to derive a class from wxArtProvider, override its
\helpref{CreateBitmap}{wxartprovidercreatebitmap} method and register the \helpref{CreateBitmap}{wxartprovidercreatebitmap} method and register the
provider with provider with
\helpref{wxArtProvider::PushProvider}{wxartproviderpushprovider}: \helpref{wxArtProvider::Push}{wxartproviderpush}:
\begin{verbatim} \begin{verbatim}
class MyProvider : public wxArtProvider class MyProvider : public wxArtProvider
@@ -25,7 +25,7 @@ provider with
{ ... } { ... }
}; };
... ...
wxArtProvider::PushProvider(new MyProvider); wxArtProvider::Push(new MyProvider);
\end{verbatim} \end{verbatim}
There's another way of taking advantage of this class: you can use it in your code and use There's another way of taking advantage of this class: you can use it in your code and use
@@ -34,6 +34,7 @@ platform native icons as provided by \helpref{wxArtProvider::GetBitmap}{wxartpro
possible as of wxWidgets 2.3.3, the set of wxArtProvider bitmaps is too possible as of wxWidgets 2.3.3, the set of wxArtProvider bitmaps is too
small). small).
\membersection{Identifying art resources}\label{artprovideridentifying} \membersection{Identifying art resources}\label{artprovideridentifying}
Every bitmap is known to wxArtProvider under an unique ID that is used by when Every bitmap is known to wxArtProvider under an unique ID that is used by when
@@ -75,7 +76,7 @@ constants in the \helpref{artprov}{sampleartprovider} sample):
\end{itemize} \end{itemize}
Additionally, any string recognized by custom art providers registered using Additionally, any string recognized by custom art providers registered using
\helpref{PushProvider}{wxartproviderpushprovider} may be used. \helpref{Push}{wxartproviderpush} may be used.
\wxheading{GTK+ Note} \wxheading{GTK+ Note}
@@ -88,6 +89,7 @@ by GTK+ follow the
icons, so wxArtProvider may return {\tt wxNullBitmap} or {\tt wxNullIcon}. icons, so wxArtProvider may return {\tt wxNullBitmap} or {\tt wxNullIcon}.
Default theme is typically installed in {\tt /usr/share/icons/hicolor}. Default theme is typically installed in {\tt /usr/share/icons/hicolor}.
\membersection{Clients}\label{artproviderclients} \membersection{Clients}\label{artproviderclients}
Client is the entity that calls wxArtProvider's GetBitmap or GetIcon Client is the entity that calls wxArtProvider's GetBitmap or GetIcon
@@ -125,6 +127,15 @@ See the \helpref{artprov}{sampleartprovider} sample for an example of wxArtProvi
\latexignore{\rtfignore{\wxheading{Members}}} \latexignore{\rtfignore{\wxheading{Members}}}
\membersection{wxArtProvider::\destruct{wxArtProvider}}\label{wxartproviderdtor}
\func{}{\destruct{wxArtProvider}}{\void}
The destructor automatically removes the provider from the provider stack used
by \helpref{GetBitmap}{wxartprovidergetbitmap}.
\membersection{wxArtProvider::CreateBitmap}\label{wxartprovidercreatebitmap} \membersection{wxArtProvider::CreateBitmap}\label{wxartprovidercreatebitmap}
\func{wxBitmap}{CreateBitmap}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client}, \param{const wxSize\& }{size}} \func{wxBitmap}{CreateBitmap}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client}, \param{const wxSize\& }{size}}
@@ -151,6 +162,14 @@ This is {\bf not} part of wxArtProvider's public API, use
\helpref{wxArtProvider::GetIcon}{wxartprovidergeticon} \helpref{wxArtProvider::GetIcon}{wxartprovidergeticon}
to query wxArtProvider for a resource. to query wxArtProvider for a resource.
\membersection{wxArtProvider::Delete}\label{wxartproviderdelete}
\func{static bool}{Delete}{\param{wxArtProvider* }{provider}}
Delete the given \arg{provider}.
\membersection{wxArtProvider::GetBitmap}\label{wxartprovidergetbitmap} \membersection{wxArtProvider::GetBitmap}\label{wxartprovidergetbitmap}
\func{static wxBitmap}{GetBitmap}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client = wxART\_OTHER}, \param{const wxSize\& }{size = wxDefaultSize}} \func{static wxBitmap}{GetBitmap}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client = wxART\_OTHER}, \param{const wxSize\& }{size = wxDefaultSize}}
@@ -169,6 +188,7 @@ Query registered providers for bitmap with given ID.
The bitmap if one of registered providers recognizes the ID or wxNullBitmap otherwise. The bitmap if one of registered providers recognizes the ID or wxNullBitmap otherwise.
\membersection{wxArtProvider::GetIcon}\label{wxartprovidergeticon} \membersection{wxArtProvider::GetIcon}\label{wxartprovidergeticon}
\func{static wxIcon}{GetIcon}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client = wxART\_OTHER}, \param{const wxSize\& }{size = wxDefaultSize}} \func{static wxIcon}{GetIcon}{\param{const wxArtID\& }{id}, \param{const wxArtClient\& }{client = wxART\_OTHER}, \param{const wxSize\& }{size = wxDefaultSize}}
@@ -183,38 +203,42 @@ Returns a suitable size hint for the given {\it wxArtClient}. If
otherwise return the size from the topmost wxArtProvider. {\it wxDefaultSize} may be otherwise return the size from the topmost wxArtProvider. {\it wxDefaultSize} may be
returned if the client doesn't have a specified size, like wxART\_OTHER for example. returned if the client doesn't have a specified size, like wxART\_OTHER for example.
\membersection{wxArtProvider::InsertProvider}\label{wxartproviderinsertprovider}
\func{static void}{InsertProvider}{\param{wxArtProvider* }{provider}} \membersection{wxArtProvider::Insert}\label{wxartproviderinsert}
\func{static void}{Insert}{\param{wxArtProvider* }{provider}}
Register new art provider and add it to the bottom of providers stack (i.e. Register new art provider and add it to the bottom of providers stack (i.e.
it will be queried as the last one). it will be queried as the last one).
\wxheading{See also} \wxheading{See also}
\helpref{PushProvider}{wxartproviderpushprovider} \helpref{Push}{wxartproviderpush}
\membersection{wxArtProvider::PopProvider}\label{wxartproviderctor}
\func{static bool}{PopProvider}{\void} \membersection{wxArtProvider::Pop}\label{wxartproviderctor}
\func{static bool}{Pop}{\void}
Remove latest added provider and delete it. Remove latest added provider and delete it.
\membersection{wxArtProvider::PushProvider}\label{wxartproviderpushprovider}
\func{static void}{PushProvider}{\param{wxArtProvider* }{provider}} \membersection{wxArtProvider::Push}\label{wxartproviderpush}
\func{static void}{Push}{\param{wxArtProvider* }{provider}}
Register new art provider and add it to the top of providers stack (i.e. it Register new art provider and add it to the top of providers stack (i.e. it
will be queried as the first provider). will be queried as the first provider).
\wxheading{See also} \wxheading{See also}
\helpref{InsertProvider}{wxartproviderinsertprovider} \helpref{Insert}{wxartproviderinsert}
\membersection{wxArtProvider::RemoveProvider}\label{wxartproviderremoveprovider}
\func{static bool}{RemoveProvider}{\param{wxArtProvider* }{provider}} \membersection{wxArtProvider::Remove}\label{wxartproviderremove}
Remove a provider from the stack. The provider must have been added previously \func{static bool}{Remove}{\param{wxArtProvider* }{provider}}
and is {\it not} deleted.
Remove a provider from the stack if it is on it. The provider is {\emph not}
deleted, unlike when using \helpref{Delete()}{wxartproviderdelete}.

View File

@@ -112,20 +112,27 @@ typedef wxString wxArtID;
class WXDLLEXPORT wxArtProvider : public wxObject class WXDLLEXPORT wxArtProvider : public wxObject
{ {
public: public:
// Dtor removes the provider from providers stack if it's still on it
virtual ~wxArtProvider();
// Add new provider to the top of providers stack (i.e. the provider will // Add new provider to the top of providers stack (i.e. the provider will
// be querier first of all). // be queried first of all).
static void PushProvider(wxArtProvider *provider); static void Push(wxArtProvider *provider);
// Add new provider to the bottom of providers stack (i.e. the provider // Add new provider to the bottom of providers stack (i.e. the provider
// will be queried as the last one). // will be queried as the last one).
static void InsertProvider(wxArtProvider *provider); static void Insert(wxArtProvider *provider);
// Remove latest added provider and delete it. // Remove latest added provider and delete it.
static bool PopProvider(); static bool Pop();
// Remove provider from providers stack but don't delete it.
static bool Remove(wxArtProvider *provider);
// Delete the given provider and remove it from the providers stack.
static bool Delete(wxArtProvider *provider);
// 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 // Query the providers for bitmap with given ID and return it. Return
// wxNullBitmap if no provider provides it. // wxNullBitmap if no provider provides it.
@@ -143,6 +150,18 @@ public:
// the topmost provider if platform_dependent = false // the topmost provider if platform_dependent = false
static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false); static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
#if WXWIN_COMPATIBILITY_2_6
// use the corresponding methods without redundant "Provider" suffix
wxDEPRECATED( static void PushProvider(wxArtProvider *provider) );
wxDEPRECATED( static void InsertProvider(wxArtProvider *provider) );
wxDEPRECATED( static bool PopProvider() );
// use Delete() if this is what you really need, or just delete the
// provider pointer, do not use Remove() as it does not delete the pointer
// unlike RemoveProvider() which does
wxDEPRECATED( static bool RemoveProvider(wxArtProvider *provider) );
#endif // WXWIN_COMPATIBILITY_2_6
protected: protected:
friend class wxArtProviderModule; friend class wxArtProviderModule;
// Initializes default provider // Initializes default provider

View File

@@ -216,7 +216,7 @@ void MyFrame::OnBrowser(wxCommandEvent& WXUNUSED(event))
void MyFrame::OnPlugProvider(wxCommandEvent& event) void MyFrame::OnPlugProvider(wxCommandEvent& event)
{ {
if ( event.IsChecked() ) if ( event.IsChecked() )
wxArtProvider::PushProvider(new MyArtProvider); wxArtProvider::Push(new MyArtProvider);
else else
wxArtProvider::PopProvider(); wxArtProvider::Pop();
} }

View File

@@ -90,15 +90,28 @@ void wxArtProviderCache::Clear()
} }
// ---------------------------------------------------------------------------- // ============================================================================
// wxArtProvider class // wxArtProvider class
// ---------------------------------------------------------------------------- // ============================================================================
IMPLEMENT_ABSTRACT_CLASS(wxArtProvider, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxArtProvider, wxObject)
wxArtProvidersList *wxArtProvider::sm_providers = NULL; wxArtProvidersList *wxArtProvider::sm_providers = NULL;
wxArtProviderCache *wxArtProvider::sm_cache = NULL; wxArtProviderCache *wxArtProvider::sm_cache = NULL;
// ----------------------------------------------------------------------------
// wxArtProvider ctors/dtor
// ----------------------------------------------------------------------------
wxArtProvider::~wxArtProvider()
{
Remove(this);
}
// ----------------------------------------------------------------------------
// wxArtProvider operations on provider stack
// ----------------------------------------------------------------------------
/*static*/ void wxArtProvider::CommonAddingProvider() /*static*/ void wxArtProvider::CommonAddingProvider()
{ {
if ( !sm_providers ) if ( !sm_providers )
@@ -110,36 +123,34 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
sm_cache->Clear(); sm_cache->Clear();
} }
/*static*/ void wxArtProvider::PushProvider(wxArtProvider *provider) /*static*/ void wxArtProvider::Push(wxArtProvider *provider)
{ {
CommonAddingProvider(); CommonAddingProvider();
sm_providers->Insert(provider); sm_providers->Insert(provider);
} }
/*static*/ void wxArtProvider::InsertProvider(wxArtProvider *provider) /*static*/ void wxArtProvider::Insert(wxArtProvider *provider)
{ {
CommonAddingProvider(); CommonAddingProvider();
sm_providers->Append(provider); sm_providers->Append(provider);
} }
/*static*/ bool wxArtProvider::PopProvider() /*static*/ bool wxArtProvider::Pop()
{ {
wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") ); wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") );
wxCHECK_MSG( sm_providers->GetCount() > 0, false, _T("wxArtProviders stack is empty") ); wxCHECK_MSG( !sm_providers->empty(), false, _T("wxArtProviders stack is empty") );
delete sm_providers->GetFirst()->GetData(); delete sm_providers->GetFirst()->GetData();
sm_providers->Erase(sm_providers->GetFirst());
sm_cache->Clear(); sm_cache->Clear();
return true; return true;
} }
/*static*/ bool wxArtProvider::RemoveProvider(wxArtProvider *provider) /*static*/ bool wxArtProvider::Remove(wxArtProvider *provider)
{ {
wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") ); wxCHECK_MSG( sm_providers, false, _T("no wxArtProvider exists") );
if ( sm_providers->DeleteObject(provider) ) if ( sm_providers->DeleteObject(provider) )
{ {
delete provider;
sm_cache->Clear(); sm_cache->Clear();
return true; return true;
} }
@@ -147,12 +158,32 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
return false; return false;
} }
/*static*/ bool wxArtProvider::Delete(wxArtProvider *provider)
{
// provider will remove itself from the stack in its dtor
delete provider;
return true;
}
/*static*/ void wxArtProvider::CleanUpProviders() /*static*/ void wxArtProvider::CleanUpProviders()
{ {
WX_CLEAR_LIST(wxArtProvidersList, *sm_providers); if ( sm_providers )
wxDELETE(sm_providers); {
wxDELETE(sm_cache); while ( !sm_providers->empty() )
delete *sm_providers->begin();
delete sm_providers;
sm_providers = NULL;
delete sm_cache;
sm_cache = NULL;
} }
}
// ----------------------------------------------------------------------------
// wxArtProvider: retrieving bitmaps/icons
// ----------------------------------------------------------------------------
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id, /*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
const wxArtClient& client, const wxArtClient& client,
@@ -253,6 +284,39 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
#endif // GTK+ 2/else #endif // GTK+ 2/else
} }
// ----------------------------------------------------------------------------
// deprecated wxArtProvider methods
// ----------------------------------------------------------------------------
#if WXWIN_COMPATIBILITY_2_6
/* static */ void wxArtProvider::PushProvider(wxArtProvider *provider)
{
Push(provider);
}
/* static */ void wxArtProvider::InsertProvider(wxArtProvider *provider)
{
Insert(provider);
}
/* static */ bool wxArtProvider::PopProvider()
{
return Pop();
}
/* static */ bool wxArtProvider::RemoveProvider(wxArtProvider *provider)
{
// RemoveProvider() used to delete the provider being removed so this is
// not a typo, we must call Delete() and not Remove() here
return Delete(provider);
}
#endif // WXWIN_COMPATIBILITY_2_6
// ============================================================================
// wxArtProviderModule
// ============================================================================
class wxArtProviderModule: public wxModule class wxArtProviderModule: public wxModule
{ {

View File

@@ -74,7 +74,7 @@ protected:
/*static*/ void wxArtProvider::InitStdProvider() /*static*/ void wxArtProvider::InitStdProvider()
{ {
wxArtProvider::PushProvider(new wxDefaultArtProvider); wxArtProvider::Push(new wxDefaultArtProvider);
} }
#if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__) #if !defined(__WXGTK20__) || defined(__WXUNIVERSAL__)

View File

@@ -54,7 +54,7 @@ protected:
/*static*/ void wxArtProvider::InitNativeProvider() /*static*/ void wxArtProvider::InitNativeProvider()
{ {
wxArtProvider::PushProvider(new wxGTK2ArtProvider); wxArtProvider::Push(new wxGTK2ArtProvider);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -137,7 +137,7 @@ wxThemeInfo::wxThemeInfo(Constructor c,
// has one // has one
wxArtProvider *art = ms_theme->GetArtProvider(); wxArtProvider *art = ms_theme->GetArtProvider();
if ( art ) if ( art )
wxArtProvider::PushProvider(art); wxArtProvider::Push(art);
} }
return themeOld; return themeOld;

View File

@@ -563,7 +563,7 @@ wxGTKTheme::~wxGTKTheme()
{ {
delete m_renderer; delete m_renderer;
delete m_scheme; delete m_scheme;
wxArtProvider::RemoveProvider(m_artProvider); delete m_artProvider;
} }
wxRenderer *wxGTKTheme::GetRenderer() wxRenderer *wxGTKTheme::GetRenderer()

View File

@@ -511,7 +511,7 @@ wxMonoTheme::~wxMonoTheme()
{ {
delete m_renderer; delete m_renderer;
delete m_scheme; delete m_scheme;
wxArtProvider::RemoveProvider(m_artProvider); delete m_artProvider;
} }
wxRenderer *wxMonoTheme::GetRenderer() wxRenderer *wxMonoTheme::GetRenderer()

View File

@@ -1069,7 +1069,7 @@ wxWin32Theme::~wxWin32Theme()
{ {
delete m_renderer; delete m_renderer;
delete m_scheme; delete m_scheme;
wxArtProvider::RemoveProvider(m_artProvider); delete m_artProvider;
} }
wxRenderer *wxWin32Theme::GetRenderer() wxRenderer *wxWin32Theme::GetRenderer()