Applied patch for ArtProvider.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32769 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2005-03-12 10:33:00 +00:00
parent ab5ea030d8
commit e53a95bcb1
8 changed files with 100 additions and 48 deletions

View File

@@ -176,11 +176,12 @@ The bitmap if one of registered providers recognizes the ID or wxNullBitmap othe
Same as \helpref{wxArtProvider::GetBitmap}{wxartprovidergetbitmap}, but
return a wxIcon object (or wxNullIcon on failure).
\func{static wxSize}{GetSize}{\param{const wxArtClient\& }{client}, \param{bool }{platform_default = false}}
\func{static wxSize}{GetSizeHint}{\param{const wxArtClient\& }{client}, \param{bool }{platform_default = false}}
Returns the default size for the given art {\it client} by either using the topmost
wxArtProvider or if {\it platform_default} is \true then return a suitable default size for
{\it client} depending on the current platform.
Returns a suitable size hint for the given {\it wxArtClient}. If
{\it platform_default} is \true, return a size based on the current platform,
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.
\membersection{wxArtProvider::PopProvider}\label{wxartproviderctor}

View File

@@ -137,9 +137,9 @@ public:
const wxArtClient& client = wxART_OTHER,
const wxSize& size = wxDefaultSize);
// Get the size of an icon from a specific wxArtClient, queries
// Get the size hint of an icon from a specific wxArtClient, queries
// the topmost provider if platform_dependent = false
static wxSize GetSize(const wxArtClient& client, bool platform_dependent = false);
static wxSize GetSizeHint(const wxArtClient& client, bool platform_dependent = false);
protected:
friend class wxArtProviderModule;
@@ -151,9 +151,9 @@ protected:
static void CleanUpProviders();
// Get the default size of an icon for a specific client
virtual wxSize DoGetSize(const wxArtClient& client)
virtual wxSize DoGetSizeHint(const wxArtClient& client)
{
return GetSize(client, true);
return GetSizeHint(client, true);
}
// Derived classes must override this method to create requested

View File

@@ -146,6 +146,9 @@ wxArtBrowserDialog::wxArtBrowserDialog(wxWindow *parent)
subsizer->Add(m_list, 1, wxEXPAND | wxRIGHT, 10);
wxSizer *subsub = new wxBoxSizer(wxVERTICAL);
m_text = new wxStaticText(this, wxID_ANY, wxT("Size: 333x333"));
subsub->Add(m_text);
m_canvas = new wxStaticBitmap(this, wxID_ANY, wxBitmap(null_xpm));
subsub->Add(m_canvas);
subsub->Add(100, 100);
@@ -173,22 +176,24 @@ void wxArtBrowserDialog::SetArtClient(const wxArtClient& client)
img->Add(wxIcon(null_xpm));
int index = 0;
long sel = m_list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
if (sel < 0) sel = 0;
m_list->DeleteAllItems();
FillBitmaps(img, m_list, index, client, wxSize(16, 16));
m_list->AssignImageList(img, wxIMAGE_LIST_SMALL);
m_list->SetColumnWidth(0, wxLIST_AUTOSIZE);
m_list->SetItemState(sel, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
m_client = client;
SetArtBitmap((const wxChar*)m_list->GetItemData(sel), m_client);
}
void wxArtBrowserDialog::OnSelectItem(wxListEvent &event)
{
const wxChar *data = (const wxChar*)event.GetData();
wxBitmap bmp = wxArtProvider::GetBitmap(data, m_client);
m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
m_canvas->SetBitmap(bmp);
Refresh();
SetArtBitmap(data, m_client, wxDefaultSize);
}
void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
@@ -196,3 +201,12 @@ void wxArtBrowserDialog::OnChooseClient(wxCommandEvent &event)
const wxChar *data = (const wxChar*)event.GetClientData();
SetArtClient(data);
}
void wxArtBrowserDialog::SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size)
{
wxBitmap bmp = wxArtProvider::GetBitmap(id, client, size);
m_canvas->SetSize(bmp.GetWidth(), bmp.GetHeight());
m_canvas->SetBitmap(bmp);
m_text->SetLabel(wxString::Format(wxT("Size: %d x %d"), bmp.GetWidth(), bmp.GetHeight()));
Refresh();
}

View File

@@ -29,6 +29,7 @@ public:
wxArtBrowserDialog(wxWindow *parent);
void SetArtClient(const wxArtClient& client);
void SetArtBitmap(const wxArtID& id, const wxArtClient& client, const wxSize& size = wxDefaultSize);
private:
void OnSelectItem(wxListEvent &event);
@@ -36,6 +37,7 @@ private:
wxListCtrl *m_list;
wxStaticBitmap *m_canvas;
wxStaticText *m_text;
wxString m_client;
DECLARE_EVENT_TABLE()

View File

@@ -151,16 +151,14 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
/*static*/ wxBitmap wxArtProvider::GetBitmap(const wxArtID& id,
const wxArtClient& client,
const wxSize& reqSize)
const wxSize& size)
{
// safety-check against writing client,id,size instead of id,client,size:
wxASSERT_MSG( client.Last() == _T('C'), _T("invalid 'client' parameter") );
wxCHECK_MSG( sm_providers, wxNullBitmap, _T("no wxArtProvider exists") );
wxSize bestSize = (reqSize != wxDefaultSize) ? reqSize : GetSize(client);
wxString hashId = wxArtProviderCache::ConstructHashID(id, client, bestSize);
wxString hashId = wxArtProviderCache::ConstructHashID(id, client, size);
wxBitmap bmp;
if ( !sm_cache->GetBitmap(hashId, &bmp) )
@@ -168,25 +166,15 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
node; node = node->GetNext())
{
bmp = node->GetData()->CreateBitmap(id, client, bestSize);
bmp = node->GetData()->CreateBitmap(id, client, size);
if ( bmp.Ok() )
{
#if wxUSE_IMAGE
int bmp_w = bmp.GetWidth();
int bmp_h = bmp.GetHeight();
// want default size but it's smaller, paste into transparent image
if ((reqSize == wxDefaultSize) &&
(bmp_h < bestSize.x) && (bmp_w < bestSize.y))
{
wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
wxImage img = bmp.ConvertToImage();
img.Resize(bestSize, offset);
bmp = wxBitmap(img);
}
else if ( (bmp_w != bestSize.x) || (bmp_h != bestSize.y) )
if ( size != wxDefaultSize &&
(bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) )
{
wxImage img = bmp.ConvertToImage();
img.Rescale(bestSize.x, bestSize.y);
img.Rescale(size.x, size.y);
bmp = wxBitmap(img);
}
#endif
@@ -218,36 +206,45 @@ wxArtProviderCache *wxArtProvider::sm_cache = NULL;
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
#include <gtk/gtk.h>
extern GtkIconSize wxArtClientToIconSize(const wxArtClient& client);
#endif // __WXGTK__
#endif // defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
/*static*/ wxSize wxArtProvider::GetSize(const wxArtClient& client,
/*static*/ wxSize wxArtProvider::GetSizeHint(const wxArtClient& client,
bool platform_dependent)
{
if (!platform_dependent)
{
wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
if (node)
return node->GetData()->DoGetSize(client);
// else return platform dependent size
return node->GetData()->DoGetSizeHint(client);
}
// else return platform dependent size
#if defined(__WXGTK20__) && !defined(__WXUNIVERSAL__)
// Gtk has specific sizes for each client, see artgtk.cpp
GtkIconSize gtk_size = wxArtClientToIconSize(client);
// no size hints for this client
if (gtk_size == GTK_ICON_SIZE_INVALID)
return wxDefaultSize;
gint width, height;
gtk_icon_size_lookup( gtk_size, &width, &height);
return wxSize(width, height);
#else // !GTK+ 2
// NB: These size hints may have to be adjusted per platform
if (client == wxART_TOOLBAR)
return wxSize(32, 32);
return wxSize(16, 15);
else if (client == wxART_MENU)
return wxSize(16, 15);
else if (client == wxART_FRAME_ICON)
return wxSize(16, 15);
else if (client == wxART_CMN_DIALOG || client == wxART_MESSAGE_BOX)
return wxSize(32, 32);
else if (client == wxART_HELP_BROWSER)
return wxSize(16, 15);
else if (client == wxART_BUTTON)
return wxSize(16, 15);
else
return wxSize(16, 15); // this is arbitrary
else // wxART_OTHER or perhaps a user's client, no specified size
return wxDefaultSize;
#endif // GTK+ 2/else
}

View File

@@ -27,6 +27,7 @@
#endif
#include "wx/artprov.h"
#include "wx/image.h"
// ----------------------------------------------------------------------------
// wxDefaultArtProvider
@@ -143,13 +144,7 @@ protected:
#undef static
// ----------------------------------------------------------------------------
// CreateBitmap routine
// ----------------------------------------------------------------------------
wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
const wxArtClient& WXUNUSED(client),
const wxSize& WXUNUSED(size))
wxBitmap wxDefaultArtProvider_CreateBitmap(const wxArtID& id)
{
// wxMessageBox icons:
ART_MSGBOX(wxART_ERROR, wxICON_ERROR, error)
@@ -195,3 +190,38 @@ wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
return wxNullBitmap;
}
// ----------------------------------------------------------------------------
// CreateBitmap routine
// ----------------------------------------------------------------------------
wxBitmap wxDefaultArtProvider::CreateBitmap(const wxArtID& id,
const wxArtClient& client,
const wxSize& reqSize)
{
wxBitmap bmp = wxDefaultArtProvider_CreateBitmap(id);
if (bmp.Ok())
{
// fit into transparent image with desired size hint from the client
if (reqSize == wxDefaultSize)
{
// find out if there is a desired size for this client
wxSize bestSize = GetSizeHint(client);
if (bestSize != wxDefaultSize)
{
int bmp_w = bmp.GetWidth();
int bmp_h = bmp.GetHeight();
// want default size but it's smaller, paste into transparent image
if ((bmp_h < bestSize.x) && (bmp_w < bestSize.y))
{
wxPoint offset((bestSize.x - bmp_w)/2, (bestSize.y - bmp_h)/2);
wxImage img = bmp.ConvertToImage();
img.Resize(bestSize, offset);
bmp = wxBitmap(img);
}
}
}
}
return bmp;
}

View File

@@ -136,7 +136,7 @@ GtkIconSize wxArtClientToIconSize(const wxArtClient& client)
else if (client == wxART_BUTTON)
return GTK_ICON_SIZE_BUTTON;
else
return GTK_ICON_SIZE_BUTTON; // this is arbitrary
return GTK_ICON_SIZE_INVALID; // this is arbitrary
}
static GtkIconSize FindClosestIconSize(const wxSize& size)
@@ -245,6 +245,10 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
wxArtClientToIconSize(client) :
FindClosestIconSize(size);
// we must have some size, this is arbitrary
if (stocksize == GTK_ICON_SIZE_INVALID)
stocksize = GTK_ICON_SIZE_BUTTON;
// allow passing GTK+ stock IDs to wxArtProvider:
if (!stockid)
stockid = id.ToAscii();

View File

@@ -136,7 +136,7 @@ GtkIconSize wxArtClientToIconSize(const wxArtClient& client)
else if (client == wxART_BUTTON)
return GTK_ICON_SIZE_BUTTON;
else
return GTK_ICON_SIZE_BUTTON; // this is arbitrary
return GTK_ICON_SIZE_INVALID; // this is arbitrary
}
static GtkIconSize FindClosestIconSize(const wxSize& size)
@@ -245,6 +245,10 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
wxArtClientToIconSize(client) :
FindClosestIconSize(size);
// we must have some size, this is arbitrary
if (stocksize == GTK_ICON_SIZE_INVALID)
stocksize = GTK_ICON_SIZE_BUTTON;
// allow passing GTK+ stock IDs to wxArtProvider:
if (!stockid)
stockid = id.ToAscii();