wxArtProvider with wxBitmapBundle
This commit is contained in:
committed by
Vadim Zeitlin
parent
ab619010bd
commit
fe3e0c558e
@@ -15,6 +15,7 @@
|
|||||||
#include "wx/bitmap.h"
|
#include "wx/bitmap.h"
|
||||||
#include "wx/icon.h"
|
#include "wx/icon.h"
|
||||||
#include "wx/iconbndl.h"
|
#include "wx/iconbndl.h"
|
||||||
|
#include "wx/bmpbndl.h"
|
||||||
|
|
||||||
class WXDLLIMPEXP_FWD_CORE wxArtProvidersList;
|
class WXDLLIMPEXP_FWD_CORE wxArtProvidersList;
|
||||||
class WXDLLIMPEXP_FWD_CORE wxArtProviderCache;
|
class WXDLLIMPEXP_FWD_CORE wxArtProviderCache;
|
||||||
@@ -157,6 +158,14 @@ public:
|
|||||||
const wxArtClient& client = wxASCII_STR(wxART_OTHER),
|
const wxArtClient& client = wxASCII_STR(wxART_OTHER),
|
||||||
const wxSize& size = wxDefaultSize);
|
const wxSize& size = wxDefaultSize);
|
||||||
|
|
||||||
|
// Query the providers for bitmapbundle with given ID and return it.
|
||||||
|
// If none is available, then the search for a bitmap with the same properties
|
||||||
|
// is performed. If successful, the bitmap is wrapped into a bitmap bundle.
|
||||||
|
static wxBitmapBundle
|
||||||
|
GetBitmapBundle(const wxArtID& id,
|
||||||
|
const wxArtClient& client = wxASCII_STR(wxART_OTHER),
|
||||||
|
const wxSize& size = wxDefaultSize);
|
||||||
|
|
||||||
// Query the providers for icon with given ID and return it. Return
|
// Query the providers for icon with given ID and return it. Return
|
||||||
// wxNullIcon if no provider provides it.
|
// wxNullIcon if no provider provides it.
|
||||||
static wxIcon GetIcon(const wxArtID& id,
|
static wxIcon GetIcon(const wxArtID& id,
|
||||||
@@ -225,6 +234,15 @@ protected:
|
|||||||
return wxNullBitmap;
|
return wxNullBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Derived classes must override CreateBitmapBundle if they provide
|
||||||
|
// a bundle that cannot be represented through an ordinary bitmap.
|
||||||
|
virtual wxBitmapBundle CreateBitmapBundle(const wxArtID& id,
|
||||||
|
const wxArtClient& client,
|
||||||
|
const wxSize& size)
|
||||||
|
{
|
||||||
|
return wxBitmapBundle(CreateBitmap(id, client, size));
|
||||||
|
}
|
||||||
|
|
||||||
virtual wxIconBundle CreateIconBundle(const wxArtID& WXUNUSED(id),
|
virtual wxIconBundle CreateIconBundle(const wxArtID& WXUNUSED(id),
|
||||||
const wxArtClient& WXUNUSED(client))
|
const wxArtClient& WXUNUSED(client))
|
||||||
{
|
{
|
||||||
|
@@ -44,7 +44,7 @@ WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromIconRef( WXHICON iconref );
|
|||||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCFURL( CFURLRef urlref );
|
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromCFURL( CFURLRef urlref );
|
||||||
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type );
|
WX_NSImage WXDLLIMPEXP_CORE wxOSXGetIconForType(OSType type );
|
||||||
void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height);
|
void WXDLLIMPEXP_CORE wxOSXSetImageSize(WX_NSImage image, CGFloat width, CGFloat height);
|
||||||
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
wxBitmapBundle WXDLLIMPEXP_CORE wxOSXCreateSystemBitmapBundle(const wxString& id, const wxString &client, const wxSize& size);
|
||||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
WXWindow WXDLLIMPEXP_CORE wxOSXGetMainWindow();
|
||||||
WXWindow WXDLLIMPEXP_CORE wxOSXGetKeyWindow();
|
WXWindow WXDLLIMPEXP_CORE wxOSXGetKeyWindow();
|
||||||
WXImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromNSCursor(const WXHCURSOR cursor);
|
WXImage WXDLLIMPEXP_CORE wxOSXGetNSImageFromNSCursor(const WXHCURSOR cursor);
|
||||||
|
@@ -34,7 +34,7 @@ OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
|
|||||||
CGImageRef inImage) ;
|
CGImageRef inImage) ;
|
||||||
|
|
||||||
WX_UIImage WXDLLIMPEXP_CORE wxOSXGetUIImageFromCGImage( CGImageRef image );
|
WX_UIImage WXDLLIMPEXP_CORE wxOSXGetUIImageFromCGImage( CGImageRef image );
|
||||||
wxBitmap WXDLLIMPEXP_CORE wxOSXCreateSystemBitmap(const wxString& id, const wxString &client, const wxSize& size);
|
wxBitmapBundle WXDLLIMPEXP_CORE wxOSXCreateSystemBitmapBundle(const wxString& id, const wxString &client, const wxSize& size);
|
||||||
|
|
||||||
class WXDLLIMPEXP_CORE wxWidgetIPhoneImpl : public wxWidgetImpl
|
class WXDLLIMPEXP_CORE wxWidgetIPhoneImpl : public wxWidgetImpl
|
||||||
{
|
{
|
||||||
|
@@ -110,13 +110,21 @@ const char* wxART_EDIT;
|
|||||||
class MyProvider : public wxArtProvider
|
class MyProvider : public wxArtProvider
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
// Override this method to return a bundle containing the required
|
||||||
|
// bitmap in all available sizes.
|
||||||
|
wxBitmapBundle CreateBitmapBundle(const wxArtID& id,
|
||||||
|
const wxArtClient& client,
|
||||||
|
const wxSize& size) override;
|
||||||
|
|
||||||
|
// If all bitmaps are available in a single size only, it may be
|
||||||
|
// simpler to override just this one.
|
||||||
wxBitmap CreateBitmap(const wxArtID& id,
|
wxBitmap CreateBitmap(const wxArtID& id,
|
||||||
const wxArtClient& client,
|
const wxArtClient& client,
|
||||||
const wxSize& size);
|
const wxSize& size) override;
|
||||||
|
|
||||||
// optionally override this one as well
|
// optionally override this one as well
|
||||||
wxIconBundle CreateIconBundle(const wxArtID& id,
|
wxIconBundle CreateIconBundle(const wxArtID& id,
|
||||||
const wxArtClient& client);
|
const wxArtClient& client) override;
|
||||||
{ ... }
|
{ ... }
|
||||||
};
|
};
|
||||||
...
|
...
|
||||||
@@ -128,8 +136,8 @@ const char* wxART_EDIT;
|
|||||||
and supplying icon bundles that contain different bitmap sizes.
|
and supplying icon bundles that contain different bitmap sizes.
|
||||||
|
|
||||||
There's another way of taking advantage of this class: you can use it in your
|
There's another way of taking advantage of this class: you can use it in your
|
||||||
code and use platform native icons as provided by wxArtProvider::GetBitmap or
|
code and use platform native icons as provided by wxArtProvider::GetBitmapBundle
|
||||||
wxArtProvider::GetIcon.
|
or wxArtProvider::GetIcon.
|
||||||
|
|
||||||
@section artprovider_identify Identifying art resources
|
@section artprovider_identify Identifying art resources
|
||||||
|
|
||||||
@@ -272,6 +280,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
Query registered providers for bitmap with given ID.
|
Query registered providers for bitmap with given ID.
|
||||||
|
|
||||||
|
Note that applications using wxWidgets 3.1.6 or later should prefer
|
||||||
|
calling GetBitmapBundle().
|
||||||
|
|
||||||
@param id
|
@param id
|
||||||
wxArtID unique identifier of the bitmap.
|
wxArtID unique identifier of the bitmap.
|
||||||
@param client
|
@param client
|
||||||
@@ -286,6 +297,28 @@ public:
|
|||||||
const wxArtClient& client = wxART_OTHER,
|
const wxArtClient& client = wxART_OTHER,
|
||||||
const wxSize& size = wxDefaultSize);
|
const wxSize& size = wxDefaultSize);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Query registered providers for a bundle of bitmaps with given ID.
|
||||||
|
|
||||||
|
@since 3.1.6
|
||||||
|
|
||||||
|
@param id
|
||||||
|
wxArtID unique identifier of the bitmap.
|
||||||
|
@param client
|
||||||
|
wxArtClient identifier of the client (i.e. who is asking for the bitmap).
|
||||||
|
@param size
|
||||||
|
Default size for the returned bundle.
|
||||||
|
|
||||||
|
@return If any of the registered providers recognizes the ID in its
|
||||||
|
CreateBitmapBundle(), this bundle is returned. Otherwise, if any of
|
||||||
|
providers returns a valid bitmap from CreateBitmap(), the bundle
|
||||||
|
containing only this bitmap is returned. Otherwise, an empty bundle
|
||||||
|
is returned.
|
||||||
|
*/
|
||||||
|
static wxBitmapBundle GetBitmapBundle(const wxArtID& id,
|
||||||
|
const wxArtClient& client = wxART_OTHER,
|
||||||
|
const wxSize& size = wxDefaultSize);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Same as wxArtProvider::GetBitmap, but return a wxIcon object
|
Same as wxArtProvider::GetBitmap, but return a wxIcon object
|
||||||
(or ::wxNullIcon on failure).
|
(or ::wxNullIcon on failure).
|
||||||
@@ -404,8 +437,13 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Derived art provider classes must override this method to create requested art
|
Derived art provider classes may override this method to create requested art
|
||||||
resource. Note that returned bitmaps are cached by wxArtProvider and it is
|
resource.
|
||||||
|
|
||||||
|
For bitmaps available in more than one size, CreateBitmapBundle()
|
||||||
|
should be overridden instead.
|
||||||
|
|
||||||
|
Note that returned bitmaps are cached by wxArtProvider and it is
|
||||||
therefore not necessary to optimize CreateBitmap() for speed (e.g. you may
|
therefore not necessary to optimize CreateBitmap() for speed (e.g. you may
|
||||||
create wxBitmap objects from XPMs here).
|
create wxBitmap objects from XPMs here).
|
||||||
|
|
||||||
@@ -429,6 +467,29 @@ protected:
|
|||||||
const wxArtClient& client,
|
const wxArtClient& client,
|
||||||
const wxSize& size);
|
const wxSize& size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Override this method to create the requested art resources available in
|
||||||
|
more than one size.
|
||||||
|
|
||||||
|
Unlike CreateBitmap(), this method can be overridden to return the same
|
||||||
|
bitmap in several (or all, if wxBitmapBundle::FromSVG() is used) sizes
|
||||||
|
at once, which will allow selecting the size best suited for the
|
||||||
|
current display resolution automatically.
|
||||||
|
|
||||||
|
@param id
|
||||||
|
wxArtID unique identifier of the bitmap.
|
||||||
|
@param client
|
||||||
|
wxArtClient identifier of the client (i.e. who is asking for the bitmap).
|
||||||
|
This only serves as a hint.
|
||||||
|
@param size
|
||||||
|
Default size of the bitmaps returned by the bundle.
|
||||||
|
|
||||||
|
@since 3.1.6
|
||||||
|
*/
|
||||||
|
virtual wxBitmapBundle CreateBitmapBundle(const wxArtID& id,
|
||||||
|
const wxArtClient& client,
|
||||||
|
const wxSize& size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This method is similar to CreateBitmap() but can be used when a bitmap
|
This method is similar to CreateBitmap() but can be used when a bitmap
|
||||||
(or an icon) exists in several sizes.
|
(or an icon) exists in several sizes.
|
||||||
|
@@ -39,6 +39,7 @@ WX_DEFINE_LIST(wxArtProvidersList)
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash);
|
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmap, wxArtProviderBitmapsHash);
|
||||||
|
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxBitmapBundle, wxArtProviderBitmapBundlesHash);
|
||||||
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxIconBundle, wxArtProviderIconBundlesHash);
|
WX_DECLARE_EXPORTED_STRING_HASH_MAP(wxIconBundle, wxArtProviderIconBundlesHash);
|
||||||
|
|
||||||
class WXDLLEXPORT wxArtProviderCache
|
class WXDLLEXPORT wxArtProviderCache
|
||||||
@@ -48,6 +49,10 @@ public:
|
|||||||
void PutBitmap(const wxString& full_id, const wxBitmap& bmp)
|
void PutBitmap(const wxString& full_id, const wxBitmap& bmp)
|
||||||
{ m_bitmapsHash[full_id] = bmp; }
|
{ m_bitmapsHash[full_id] = bmp; }
|
||||||
|
|
||||||
|
bool GetBitmapBundle(const wxString& full_id, wxBitmapBundle* bmpbndl);
|
||||||
|
void PutBitmapBundle(const wxString& full_id, const wxBitmapBundle& bmpbndl)
|
||||||
|
{ m_bitmapsBundlesHash[full_id] = bmpbndl; }
|
||||||
|
|
||||||
bool GetIconBundle(const wxString& full_id, wxIconBundle* bmp);
|
bool GetIconBundle(const wxString& full_id, wxIconBundle* bmp);
|
||||||
void PutIconBundle(const wxString& full_id, const wxIconBundle& iconbundle)
|
void PutIconBundle(const wxString& full_id, const wxIconBundle& iconbundle)
|
||||||
{ m_iconBundlesHash[full_id] = iconbundle; }
|
{ m_iconBundlesHash[full_id] = iconbundle; }
|
||||||
@@ -62,8 +67,9 @@ public:
|
|||||||
const wxArtClient& client);
|
const wxArtClient& client);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxArtProviderBitmapsHash m_bitmapsHash; // cache of wxBitmaps
|
wxArtProviderBitmapsHash m_bitmapsHash; // cache of wxBitmaps
|
||||||
wxArtProviderIconBundlesHash m_iconBundlesHash; // cache of wxIconBundles
|
wxArtProviderBitmapBundlesHash m_bitmapsBundlesHash; // cache of wxBitmaps
|
||||||
|
wxArtProviderIconBundlesHash m_iconBundlesHash; // cache of wxIconBundles
|
||||||
};
|
};
|
||||||
|
|
||||||
bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp)
|
bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp)
|
||||||
@@ -80,6 +86,21 @@ bool wxArtProviderCache::GetBitmap(const wxString& full_id, wxBitmap* bmp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxArtProviderCache::GetBitmapBundle(const wxString& full_id, wxBitmapBundle* bmpbndl)
|
||||||
|
{
|
||||||
|
wxArtProviderBitmapBundlesHash::iterator entry = m_bitmapsBundlesHash.find(full_id);
|
||||||
|
if ( entry == m_bitmapsBundlesHash.end() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*bmpbndl = entry->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool wxArtProviderCache::GetIconBundle(const wxString& full_id, wxIconBundle* bmp)
|
bool wxArtProviderCache::GetIconBundle(const wxString& full_id, wxIconBundle* bmp)
|
||||||
{
|
{
|
||||||
wxArtProviderIconBundlesHash::iterator entry = m_iconBundlesHash.find(full_id);
|
wxArtProviderIconBundlesHash::iterator entry = m_iconBundlesHash.find(full_id);
|
||||||
@@ -274,6 +295,37 @@ void wxArtProvider::RescaleBitmap(wxBitmap& bmp, const wxSize& sizeNeeded)
|
|||||||
return bmp;
|
return bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*static*/
|
||||||
|
wxBitmapBundle wxArtProvider::GetBitmapBundle(const wxArtID& id,
|
||||||
|
const wxArtClient& client,
|
||||||
|
const wxSize& size)
|
||||||
|
{
|
||||||
|
// safety-check against writing client,id,size instead of id,client,size:
|
||||||
|
wxASSERT_MSG( client.Last() == wxT('C'), wxT("invalid 'client' parameter") );
|
||||||
|
|
||||||
|
wxCHECK_MSG( sm_providers, wxNullBitmap, wxT("no wxArtProvider exists") );
|
||||||
|
|
||||||
|
wxString hashId = wxArtProviderCache::ConstructHashID(id, client);
|
||||||
|
|
||||||
|
wxBitmapBundle bitmapbundle; // (DoGetIconBundle(id, client));
|
||||||
|
|
||||||
|
if ( !sm_cache->GetBitmapBundle(hashId, &bitmapbundle) )
|
||||||
|
{
|
||||||
|
for (wxArtProvidersList::compatibility_iterator node = sm_providers->GetFirst();
|
||||||
|
node; node = node->GetNext())
|
||||||
|
{
|
||||||
|
bitmapbundle = node->GetData()->CreateBitmapBundle(id, client, size);
|
||||||
|
if ( bitmapbundle.IsOk() )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sm_cache->PutBitmapBundle(hashId, bitmapbundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bitmapbundle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*static*/
|
/*static*/
|
||||||
wxIconBundle wxArtProvider::GetIconBundle(const wxArtID& id, const wxArtClient& client)
|
wxIconBundle wxArtProvider::GetIconBundle(const wxArtID& id, const wxArtClient& client)
|
||||||
{
|
{
|
||||||
|
@@ -35,11 +35,11 @@ protected:
|
|||||||
const wxArtClient& client) wxOVERRIDE;
|
const wxArtClient& client) wxOVERRIDE;
|
||||||
#endif
|
#endif
|
||||||
#if wxOSX_USE_COCOA_OR_IPHONE
|
#if wxOSX_USE_COCOA_OR_IPHONE
|
||||||
virtual wxBitmap CreateBitmap(const wxArtID& id,
|
virtual wxBitmapBundle CreateBitmapBundle(const wxArtID& id,
|
||||||
const wxArtClient& client,
|
const wxArtClient& client,
|
||||||
const wxSize& size) wxOVERRIDE
|
const wxSize& size) wxOVERRIDE
|
||||||
{
|
{
|
||||||
return wxOSXCreateSystemBitmap(id, client, size);
|
return wxOSXCreateSystemBitmapBundle(id, client, size);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/fontutil.h"
|
#include "wx/fontutil.h"
|
||||||
|
#include "wx/private/bmpbndl.h"
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
|
|
||||||
@@ -165,14 +166,14 @@ WXWindow wxOSXGetKeyWindow()
|
|||||||
|
|
||||||
#if wxOSX_USE_IPHONE
|
#if wxOSX_USE_IPHONE
|
||||||
|
|
||||||
wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &client, const wxSize& size)
|
wxBitmapBundle wxOSXCreateSystemBitmapBundle(const wxString& name, const wxString &client, const wxSize& size)
|
||||||
{
|
{
|
||||||
#if 1
|
#if 1
|
||||||
// unfortunately this only accesses images in the app bundle, not the system wide globals
|
// unfortunately this only accesses images in the app bundle, not the system wide globals
|
||||||
wxCFStringRef cfname(name);
|
wxCFStringRef cfname(name);
|
||||||
return wxBitmap( [[UIImage imageNamed:cfname.AsNSString()] CGImage] );
|
return wxOSXMakeBundleFromImage( [UIImage imageNamed:cfname.AsNSString()] );
|
||||||
#else
|
#else
|
||||||
return wxBitmap();
|
return wxNullBitmap;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,14 +198,12 @@ WXImage wxOSXGetSystemImage(const wxString& name)
|
|||||||
return nsimage;
|
return nsimage;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap wxOSXCreateSystemBitmap(const wxString& name, const wxString &WXUNUSED(client), const wxSize& WXUNUSED(sizeHint))
|
wxBitmapBundle wxOSXCreateSystemBitmapBundle(const wxString& name, const wxString &WXUNUSED(client), const wxSize& WXUNUSED(sizeHint))
|
||||||
{
|
{
|
||||||
NSImage* nsimage = wxOSXGetSystemImage(name);
|
NSImage* nsimage = wxOSXGetSystemImage(name);
|
||||||
if ( nsimage )
|
if ( nsimage )
|
||||||
{
|
{
|
||||||
// if ( sizeHint != wxDefaultSize )
|
return wxOSXMakeBundleFromImage( nsimage );
|
||||||
// [nsimage setSize:NSMakeSize(sizeHint.GetHeight(), sizeHint.GetWidth())];
|
|
||||||
return wxBitmap( nsimage );
|
|
||||||
}
|
}
|
||||||
return wxNullBitmap;
|
return wxNullBitmap;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user