@vslavik pushed 2 commits.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
One more thing: this restores the logic to pre- 337940f and does the same as the other wxMenuItem::Set/Update methods do:
void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap) { wxMenuItemBase::SetBitmap(bitmap); UpdateItemBitmap(); } void wxMenuItem::UpdateItemBitmap() { if ( !m_parentMenu ) // ?????????? return; if ( m_bitmap.IsOk() ) { GetPeer()->SetBitmap(m_bitmap); } }
However, @csomor, I don't understand why the !m_parentMenu
check is there? I don't see any corresponding code to create native representations in DoInsertOrAppend
(they weren't there before the reverted changes either)? It seems to be that this never worked correctly for detached menu items and is unnecessary: the peer object is already there and has a perfectly good NSMenuItem
, so this check is unnecessary in all the UpdateItemXXX
methods, no? Am I missing something here?
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@vadz approved this pull request.
Thanks, the changes indeed make sense to me and it's, of course, nice to simplify the code while fixing bugs.
Concerning NSImage
in the public API: it looked wrong to me to provide access to impl-specific details in wxBitmapBundler
itself. If we need a way to do it from outside wx, perhaps we should add void* wxBitmapBundleImpl::GetNativeHandle() const { return nullptr; }
and override it in wxOSXImageBundleImpl
to return the NSImage
? We could probably also get rid of gs_nativeImages
then...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
If we need a way to do it from outside wx, perhaps we should add void* wxBitmapBundleImpl::GetNativeHandle() const { return nullptr; }
Honestly, why reinvent the wheel? Anything untyped or different from wxBitmap
is not worth the hassle. That is:
#ifdef __WXOSX__ WX_NSImage GetNSImage() const { return wxOSXGetImageFromBundle(*this); } static wxBitmapBundle FromNSImage(WX_NSImage img) { return wxOSXMakeBundleFromImage(img); } #endif
This allows you to use NSImage
easily :SetBitmap([NSImage imageName:@"..."]);
wxOSX is a special case here. It is the only platform where native handle makes sense, so why over-generalize it?
and override it in wxOSXImageBundleImpl to return the NSImage?
Note the that the global mapping - as far as I could understand - is not limited to wxOSXImageBundleImpl
and the design of these classes necessitates hooking OSX-specific code into other implementations (wxBitmapBundleImplSet
here):
https://github.com/wxWidgets/wxWidgets/blob/fd0c23ee24c37035a4f87c963e4844b1e0bdb231/src/common/bmpbndl.cpp#L236-L238
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Honestly, why reinvent the wheel?
Having the accessor function in wxBitmapBundle
itself means that we'll have to always use gs_nativeImages
which doesn't seem great (adding a static FromNSImage()
is fine though).
Note the that the global mapping - as far as I could understand - is not limited to wxOSXImageBundleImpl and the design of these classes necessitates hooking OSX-specific code into other implementations (wxBitmapBundleImplSet here):
I would like to change this too, of course, but I'm too afraid of touching this code...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
However, @csomor, I don't understand why the
!m_parentMenu
check is there? I don't see any corresponding code to create native representations inDoInsertOrAppend
(they weren't there before the reverted changes either)? It seems to be that this never worked correctly for detached menu items and is unnecessary: the peer object is already there and has a perfectly goodNSMenuItem
, so this check is unnecessary in all theUpdateItemXXX
methods, no? Am I missing something here?
No, you are not :-) we are missing the Carbon implementation where there was no native menu item and everything had to be done via the parent menu. So these checks are not needed neither for Cocoa nor UIKit.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@csomor approved this pull request.
Thank you, looks fine to me, I have not yet discovered where we really do lose the native NSImage that was stored in the wxBitmap, but I think having the bundle in the API makes things more safe in regard to keeping multi-res native. So +1 from me
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Vaclav, do you want to remove the parent menu check as part of this PR or should I merge/push it as is? There is no hurry either way, I just don't want to want this prematurely nor to leave it unmerged for too long unnecessarily.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
@vslavik pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.
Vaclav, do you want to remove the parent menu check as part of this PR or should I merge/push it as is?
Sorry, I was AFK. I added the removal in 4437050 now.
I have not yet discovered where we really do lose the native NSImage that was stored in the wxBitmap
This was because the SetupBitmaps
code called wxMenuItemBase::GetBitmap()
, which under the hood uses GetBitmapFromBundle()
, which eventually calls this code where forcing scale factor does the destruction inwxBitmapBundle::GetBitmap(size)
:
https://github.com/wxWidgets/wxWidgets/blob/170c38631458dcef648c31b9d98dcc20a8c57f9c/src/common/bmpbndl.cpp#L587-L590
But I didn't verify this hypothesis once I realized the fix was to sidestep all this...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Having the accessor function in wxBitmapBundle itself means that we'll have to always use gs_nativeImages which doesn't seem great (adding a static FromNSImage() is fine though).
I don't see how the global map is related to having wxOSXGetImageFromBundle
exposed publicly? Note that the map and all return values are implicitly ref-counted by the Objective-C++ compiler and any user of the API will necessarily invoke it from Obj-C++, so while it looks like passing raw pointers, it's best thought of as shared_ptr
, i.e. it would be possible to reimplement NSView* GetNSImage()
w/o the global map.
Note the that the global mapping - as far as I could understand - is not limited to wxOSXImageBundleImpl and the design of these classes necessitates hooking OSX-specific code into other implementations (wxBitmapBundleImplSet here):
I would like to change this too, of course, but I'm too afraid of touching this code...
I'm not a fan of neither the global map nor this, but AFAIK both are consequences of
wxBitmapBundle
instance into NSImage
on macOS"Efficient" implies you can't just do it every time a conversion is done. And point 1 forces the implementation to be off-band and not part of wxOSXImageBundleImpl
...
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
- the design choice to allow multiple implementations, instead of having one per platform and
This was my decision and I still think it makes sense, at least for the other platforms that don't provide any standard/native way of doing what this class does. But it would almost certainly be awkward to use a different approach in wxOSX.
- the fact that you will always need efficient way to convert any
wxBitmapBundle
instance intoNSImage
on macOS
We could add an extra virtual member function returning NSImage
to wxBitmapBundleImpl
under Mac to make it possible to handle this efficiently in wxOSXImageBundleImpl
or am I missing something?
Anyhow, for now I'll merge this already, thanks again!
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.
Merged #25744 into master.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.