Make default cursor resource work for Cocoa (PR #22391)

147 views
Skip to first unread message

oneeyeman1

unread,
May 3, 2022, 11:13:57 PM5/3/22
to wx-...@googlegroups.com, Subscribed

With this it will be possible to load a cur file on Cocoa from the Bundle resources.

I am putting this more for discussing this possibility.

If this code is OK'ed I might add the possibility to fall back to the png if the cur file is not available.

Could someone please take a look?

Thx in advance.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/22391

Commit Summary

  • e811232 Make default cursor resource work for Cocoa

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391@github.com>

oneeyeman1

unread,
May 5, 2022, 10:05:00 AM5/5/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 1 commit.

  • db6e3e4 Attempt to fix iPhone build


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/9803601301@github.com>

VZ

unread,
May 5, 2022, 11:10:13 AM5/5/22
to wx-...@googlegroups.com, Subscribed

@csomor Could you please look at this? I have no idea about how cursors are supposed to be handled under Mac.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1118674552@github.com>

Stefan Csomor

unread,
May 6, 2022, 1:21:34 PM5/6/22
to wx-...@googlegroups.com, Subscribed

@csomor commented on this pull request.

why wouldn't you just use the std-path of the Resources and use a wxImage to read in the CUR file and create a wxCursor from that ?


In src/osx/carbon/utilscocoa.mm:

> +        NSDictionary *properties = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex( image, 0, nil );
+        CGFloat x = [[properties objectForKey:@"hotspotX"]floatValue];

I think you could use a wxCFDictionaryRef here, no need to go to NSDictionary. And then a GetValue("hotspotX").GetValue(&x)


In src/osx/carbon/utilscocoa.mm:

> @@ -613,6 +613,27 @@ void  wxMacCocoaShowCursor()
 {
     [NSCursor unhide];
 }
+
+WX_NSCursor wxMacCocoaCreateCursorFromResource(const wxString &cursor_file, wxBitmapType flags)
+{
+    NSString *path;
+    NSBundle *bundle = [NSBundle mainBundle];
+    if( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
+        path = [bundle pathForResource:wxCFStringRef( cursor_file ).AsNSString() ofType:@"cur"];
+    if( path )
+    {
+        NSURL *url = [NSURL fileURLWithPath:path];
+        CGImageSourceRef image = CGImageSourceCreateWithURL( (__bridge CFURLRef) url, nil );
+        NSDictionary *properties = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex( image, 0, nil );
+        CGFloat x = [[properties objectForKey:@"hotspotX"]floatValue];
+        CGFloat y = [[properties objectForKey:@"hotspotY"]floatValue];
+        CFBridgingRelease(image);

We only need a simple CFRelease(image) here I think ...


In src/osx/carbon/utilscocoa.mm:

> +
+WX_NSCursor wxMacCocoaCreateCursorFromResource(const wxString &cursor_file, wxBitmapType flags)
+{
+    NSString *path;
+    NSBundle *bundle = [NSBundle mainBundle];
+    if( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
+        path = [bundle pathForResource:wxCFStringRef( cursor_file ).AsNSString() ofType:@"cur"];
+    if( path )
+    {
+        NSURL *url = [NSURL fileURLWithPath:path];
+        CGImageSourceRef image = CGImageSourceCreateWithURL( (__bridge CFURLRef) url, nil );
+        NSDictionary *properties = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex( image, 0, nil );
+        CGFloat x = [[properties objectForKey:@"hotspotX"]floatValue];
+        CGFloat y = [[properties objectForKey:@"hotspotY"]floatValue];
+        CFBridgingRelease(image);
+        CFBridgingRelease((__bridge CFTypeRef _Nullable)(properties));

if we use a wxCFDictionaryRef no explicit release is needed anymore


In src/osx/carbon/utilscocoa.mm:

> @@ -613,6 +613,27 @@ void  wxMacCocoaShowCursor()
 {
     [NSCursor unhide];
 }
+
+WX_NSCursor wxMacCocoaCreateCursorFromResource(const wxString &cursor_file, wxBitmapType flags)
+{
+    NSString *path;
+    NSBundle *bundle = [NSBundle mainBundle];
+    if( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )

I wouldn't say a MACCURSOR is typically a .CUR file ... this rang belongs to .PNG IMHO


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/964926742@github.com>

oneeyeman1

unread,
May 6, 2022, 2:15:44 PM5/6/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In src/osx/carbon/utilscocoa.mm:

> @@ -613,6 +613,27 @@ void  wxMacCocoaShowCursor()
 {
     [NSCursor unhide];
 }
+
+WX_NSCursor wxMacCocoaCreateCursorFromResource(const wxString &cursor_file, wxBitmapType flags)
+{
+    NSString *path;
+    NSBundle *bundle = [NSBundle mainBundle];
+    if( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )

@csomor,
I can make it to work with PNG.
I was not sure if the "CUR" file can be easily converted to "PNG".

I will also see if I can address other comments.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/964995843@github.com>

oneeyeman1

unread,
May 8, 2022, 8:04:52 PM5/8/22
to wx-...@googlegroups.com, Subscribed

@csomor ,

why wouldn't you just use the std-path of the Resources and use a wxImage to read in the CUR file and create a wxCursor from that ?

I was hoping to retrieve the hotspot coordinates and construct the cursor this way.

I don't know how OS identifies those coordinates, so...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1120513493@github.com>

oneeyeman1

unread,
May 8, 2022, 10:06:34 PM5/8/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In src/osx/carbon/utilscocoa.mm:

> +        NSDictionary *properties = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex( image, 0, nil );
+        CGFloat x = [[properties objectForKey:@"hotspotX"]floatValue];

@csomor ,
I tried following code:

        wxCFDictionaryRef properties( (wxCFDictionaryRef) CGImageSourceCopyPropertiesAtIndex( image, 0, nil ) );
        properties.GetValue( "hotspotX" ).GetValue( &x );
        properties.GetValue( "hotspotY" ).GetValue( &y );

and it failed on the retrieval of the x - BAD-EXEC exception.

Any suggestions?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/965528616@github.com>

Stefan Csomor

unread,
May 9, 2022, 1:25:09 AM5/9/22
to wx-...@googlegroups.com, Subscribed

@csomor commented on this pull request.


In src/osx/carbon/utilscocoa.mm:

> +        NSDictionary *properties = (__bridge NSDictionary *)CGImageSourceCopyPropertiesAtIndex( image, 0, nil );
+        CGFloat x = [[properties objectForKey:@"hotspotX"]floatValue];

A PNG does not have a hotspot, that's why you have to indicate it in the other parameters of the wxCursor from file parameter, an CUR does however, so the wxImage constructed from it already does know about the hotspot. We have everything in the our code already.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/965605458@github.com>

Stefan Csomor

unread,
May 9, 2022, 1:32:13 AM5/9/22
to wx-...@googlegroups.com, Subscribed

why wouldn't you just use the std-path of the Resources and use a wxImage to read in the CUR file and create a wxCursor from that ?

I was hoping to retrieve the hotspot coordinates and construct the cursor this way.

I don't know how OS identifies those coordinates, so...

You don't have to, as wx code already knows how to do that, only in the case eg of a png I'd add the hotspot from the parameters via

image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX);
image.SetOption(wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotY);


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1120660099@github.com>

oneeyeman1

unread,
May 10, 2022, 9:49:41 AM5/10/22
to wx-...@googlegroups.com, Subscribed

@csomor ,
Thank you for the input. I understand now.
Is it OK to make it a PNG by default, fall back to CUR if PNG is not found and if both are not there - give a message to the developer?
Or just implement in terms of PNG and that's it?

Thx.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1122424166@github.com>

oneeyeman1

unread,
May 11, 2022, 12:42:43 AM5/11/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/9849534742@github.com>

oneeyeman1

unread,
May 11, 2022, 12:45:25 AM5/11/22
to wx-...@googlegroups.com, Subscribed

@csomor ,
I reimplemented this as you suggested.

For right now, I did it just for PNG.

Let me know if we need a fallback or message box is inappropriate.

I will modify the docs after I hear OK from either you or Vadim.

Thank you.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1123181517@github.com>

oneeyeman1

unread,
May 12, 2022, 9:50:34 AM5/12/22
to wx-...@googlegroups.com, Subscribed

@csomor ,
Can you take a look?
Maybe it can be included in 3.1.7 then...

TIA!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1125021267@github.com>

Stefan Csomor

unread,
May 12, 2022, 5:26:40 PM5/12/22
to wx-...@googlegroups.com, Subscribed

@csomor commented on this pull request.


In src/osx/carbon/cursor.cpp:

> +            m_refData->DecRef() ;
+            m_refData = NULL ;

for PNG we need to set the hotspot explicitly in the image as in the else clause, also bracket with wxUSE_IMAGE


In src/osx/carbon/cursor.cpp:

> @@ -278,7 +278,16 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX
     if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
     {
 #if wxOSX_USE_COCOA
-        wxFAIL_MSG( wxT("Not implemented") );
+        wxString fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";
+        wxImage image( fileName, wxBITMAP_TYPE_PNG );
+        if( image.IsOk() )
+        {
+            m_refData->DecRef() ;
+            m_refData = NULL ;
+            InitFromImage( image );
+        }
+        else
+            wxMessageBox( "No PNG cursor image found in Resources" );

we should log an error IMHO, or wxFAIL_MSG, but definitely not pop-up a message box


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/971473956@github.com>

oneeyeman1

unread,
May 12, 2022, 5:56:59 PM5/12/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In src/osx/carbon/cursor.cpp:

> +            m_refData->DecRef() ;
+            m_refData = NULL ;

@csomor ,
I will verify it tonight, but I think it will be set in the "InitFromImage()".


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/971498766@github.com>

oneeyeman1

unread,
May 12, 2022, 5:57:55 PM5/12/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In src/osx/carbon/cursor.cpp:

> @@ -278,7 +278,16 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX
     if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
     {
 #if wxOSX_USE_COCOA
-        wxFAIL_MSG( wxT("Not implemented") );
+        wxString fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";
+        wxImage image( fileName, wxBITMAP_TYPE_PNG );
+        if( image.IsOk() )
+        {
+            m_refData->DecRef() ;
+            m_refData = NULL ;
+            InitFromImage( image );
+        }
+        else
+            wxMessageBox( "No PNG cursor image found in Resources" );

Yes, will change that. Probably use wxFAIL_MSG.
Do you think it will make sense to use CUR file as fall back?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/971499349@github.com>

Stefan Csomor

unread,
May 13, 2022, 1:13:45 AM5/13/22
to wx-...@googlegroups.com, Subscribed

@csomor commented on this pull request.


In src/osx/carbon/cursor.cpp:

> +            m_refData->DecRef() ;
+            m_refData = NULL ;

No wxImage code can only set it for a format that itself does know about the hotspot location, eg CUR, but not for PNG which does not carry this information


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/971708344@github.com>

oneeyeman1

unread,
May 13, 2022, 1:17:45 AM5/13/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In src/osx/carbon/cursor.cpp:

> +            m_refData->DecRef() ;
+            m_refData = NULL ;

@csomor,
Got it.
Do yo think it is a good idea to add a fallback to CUR file if PNG is not found?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/971710346@github.com>

Stefan Csomor

unread,
May 13, 2022, 1:31:45 AM5/13/22
to wx-...@googlegroups.com, Subscribed

@csomor commented on this pull request.


In src/osx/carbon/cursor.cpp:

> @@ -278,7 +278,16 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX
     if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
     {
 #if wxOSX_USE_COCOA
-        wxFAIL_MSG( wxT("Not implemented") );
+        wxString fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";
+        wxImage image( fileName, wxBITMAP_TYPE_PNG );
+        if( image.IsOk() )
+        {
+            m_refData->DecRef() ;
+            m_refData = NULL ;
+            InitFromImage( image );
+        }
+        else
+            wxMessageBox( "No PNG cursor image found in Resources" );

Do you think it will make sense to use CUR file as fall back?

this would be a good idea especially as CUR does support multi-res - although my current macOS code does not yet translate this properly


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/971717741@github.com>

oneeyeman1

unread,
May 13, 2022, 9:38:42 PM5/13/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/9879864436@github.com>

oneeyeman1

unread,
May 13, 2022, 9:40:16 PM5/13/22
to wx-...@googlegroups.com, Subscribed

@csomor,
Hopefully this now is good.

Take a look and let me know.

If it is - I will try to modify the documentation so that it can be included in the upcoming 3.1.7 release.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1126606933@github.com>

oneeyeman1

unread,
May 14, 2022, 7:32:42 PM5/14/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 1 commit.

  • 2be2c50 Fix the documentation for this functionality


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/9884009815@github.com>

oneeyeman1

unread,
May 14, 2022, 7:35:52 PM5/14/22
to wx-...@googlegroups.com, Subscribed

I tried to fix documentation but I'm sure my words can be improved.

Also, I don't know if the unit test is needed here.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1126827073@github.com>

Stefan Csomor

unread,
May 15, 2022, 10:57:26 AM5/15/22
to wx-...@googlegroups.com, Subscribed

P.S.: If you could please look at #22412 and give me a clue of where to look for the fix it would be great.

Sorry, I don't have the time to do that at the moment, it may very well be that macOS is taking over in cursor management


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1126958262@github.com>

Stefan Csomor

unread,
May 15, 2022, 11:12:53 AM5/15/22
to wx-...@googlegroups.com, Subscribed

@csomor commented on this pull request.

thanks we are getting closer I think, @vadz could you please have a look as well, Thanks


In interface/wx/cursor.h:

> @@ -138,11 +138,8 @@ class wxCursor : public wxGDIObject
               (to load a cursor from a .ico icon file) and @c wxBITMAP_TYPE_ANI
               (to load a cursor from a .ani icon file).
             - under MacOS, it defaults to @c wxBITMAP_TYPE_MACCURSOR_RESOURCE;
-              when specifying a string resource name, first the color cursors 'crsr'
-              and then the black/white cursors 'CURS' in the resource chain are scanned
-              through. Note that resource forks are deprecated on macOS so this
-              is only available for legacy reasons and should not be used in
-              new code.
+              when specifying a string resource name, first 'png' and then 'cur'
+              image are searched in resources.

I'm not an authority on wording, it's a foreign language to me as well, but I think either we go
.. first a PNG and then a CUR image is searched or
... first PNG and then CUR images are searched
I'm slightly preferring the first variant


In src/osx/carbon/cursor.cpp:

>              m_refData->DecRef() ;
             m_refData = NULL ;
             InitFromImage( image );
         }
         else
-            wxMessageBox( "No PNG cursor image found in Resources" );
+        {
+            fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".cur";
+            wxImage image( fileName, wxBITMAP_TYPE_CUR );
+            if( image.IsOk() )
+            {
+                InitFromImage( image );

I think here we need a

m_refData->DecRef() ;
m_refData = NULL ;

as well


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/973186125@github.com>

oneeyeman1

unread,
May 15, 2022, 11:22:24 AM5/15/22
to wx-...@googlegroups.com, Subscribed

@csomor

P.S.: If you could please look at #22412 and give me a clue of where to look for the fix it would be great.

Sorry, I don't have the time to do that at the moment, it may very well be that macOS is taking over in cursor management

Whenever, you have time.
I wasn't sure if you saw the report as only Vadim commented on it.

And yes - you may be right. Running under lldb I see the cursor is changing, but then CaptureMouse() is called...

If not for an immediate fix - maybe a quick workaround..

And I can test a possible fix as well...

TIA


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1126963248@github.com>

oneeyeman1

unread,
May 15, 2022, 11:23:23 AM5/15/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In src/osx/carbon/cursor.cpp:

>              m_refData->DecRef() ;
             m_refData = NULL ;
             InitFromImage( image );
         }
         else
-            wxMessageBox( "No PNG cursor image found in Resources" );
+        {
+            fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".cur";
+            wxImage image( fileName, wxBITMAP_TYPE_CUR );
+            if( image.IsOk() )
+            {
+                InitFromImage( image );

Yes, sorry about that.

Will fix after Vadim approves documentation wording.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/973187580@github.com>

oneeyeman1

unread,
May 17, 2022, 8:35:43 PM5/17/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 2 commits.

  • f853391 Fix releasing the pointer
  • f7690cd Fixing wording in documentation


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/9910718637@github.com>

oneeyeman1

unread,
May 17, 2022, 8:50:39 PM5/17/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.


In interface/wx/cursor.h:

> @@ -138,11 +138,8 @@ class wxCursor : public wxGDIObject
               (to load a cursor from a .ico icon file) and @c wxBITMAP_TYPE_ANI
               (to load a cursor from a .ani icon file).
             - under MacOS, it defaults to @c wxBITMAP_TYPE_MACCURSOR_RESOURCE;
-              when specifying a string resource name, first the color cursors 'crsr'
-              and then the black/white cursors 'CURS' in the resource chain are scanned
-              through. Note that resource forks are deprecated on macOS so this
-              is only available for legacy reasons and should not be used in
-              new code.
+              when specifying a string resource name, first 'png' and then 'cur'
+              image are searched in resources.

@csomor ,
I followed you first suggestion and fixed it.

Hopefully someone will be able to push this before 3.1.7...

Thx.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/976241588@github.com>

VZ

unread,
Jun 1, 2022, 10:11:32 AM6/1/22
to wx-...@googlegroups.com, Subscribed

I'm still very confused by the logic of this PR. Why do we need to support CUR files under macOS? It's not a natural format for them there, AFAIK nobody uses them there. If you want to allow any file format, as the existing code using wxImage::LoadFile() does, just do it like this. If you just want to use PNGs -- this is fine too. But supporting only PNG and CUR doesn't make much sense to me.

Next point is that, of course, we shouldn't duplicate the existing code in the else branch. Just construct the file path differently in this case and then reuse the existing code...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1143663944@github.com>

oneeyeman1

unread,
Jun 4, 2022, 10:31:56 PM6/4/22
to wx-...@googlegroups.com, Subscribed

@csomor ,
What would be the best fallback format if PNG is not available?
Or do you think we can use wxImage in this case and only then fail?

I'm not really familiar with the internals of OSX, therefore I'd like to ask...

And Vadim' point is probably a good one - CUR file format will look weird under OSX.

Any pointers?


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1146726998@github.com>

oneeyeman1

unread,
Jun 4, 2022, 10:33:42 PM6/4/22
to wx-...@googlegroups.com, Subscribed

@vadz ,
Do you think we need a unit test for this?

I mean both MSW and OSX will have a support for that and so we can try to test if this works.
And maybe for GTK as well.

Thank you.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1146727234@github.com>

Stefan Csomor

unread,
Jun 5, 2022, 8:03:15 AM6/5/22
to wx-...@googlegroups.com, Subscribed

@csomor , What would be the best fallback format if PNG is not available? Or do you think we can use wxImage in this case and only then fail?

using wxImage is fine if it can deduce the format, perfect, we should just avoid code duplication, Vadim is right there. CUR as a format is not so unreasonable because it is in itself multi-resolution capable, although our code does not deal with it right now, but of course multi-res PNGs are way more frequently used.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1146792025@github.com>

oneeyeman1

unread,
Jun 5, 2022, 9:42:13 AM6/5/22
to wx-...@googlegroups.com, Subscribed

@csomor ,
So do you suggest to keep the CUR format under OSX?
Thank you.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1146807023@github.com>

Stefan Csomor

unread,
Jun 5, 2022, 12:29:33 PM6/5/22
to wx-...@googlegroups.com, Subscribed

@csomor , So do you suggest to keep the CUR format under OSX? But it will be just as fallback if it's not available...

I think Vadim is right, we can support all formats, by just using wxImage::LoadFile if the PNG attempt fails, and have no explicit test with a CUR extension, thus supporting every format (wxBITMAP_TYPE_ANY being default), so to keep the code small, I'just interleave this perhaps along these lines (I haven't tested it, so perhaps I overlooked something):

wxImage image( fileName, wxBITMAP_TYPE_PNG );
if( !image.IsOk() )
{
     fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file;
     image.LoadFile(filename)
}
if( image.IsOk() )
           ...


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1146843724@github.com>

oneeyeman1

unread,
Aug 17, 2022, 12:16:12 AM8/17/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/10748570071@github.com>

oneeyeman1

unread,
Aug 17, 2022, 10:22:06 AM8/17/22
to wx-...@googlegroups.com, Subscribed

@vadz ,
Any idea what happened with the failed build here?
It looks like it failed to install something on the build VM...

Thx.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1218078703@github.com>

Scott Talbert

unread,
Aug 17, 2022, 10:45:25 AM8/17/22
to wx-...@googlegroups.com, Subscribed

@vadz , Any idea what happened with the failed build here? It looks like it failed to install something on the build VM...

Thx.

Actually, it looks like the version of pip being installed (19.1.1) is not compatible with Python 3.10. collections.Mapping was moved to collections.abc in Python 3.10.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1218109222@github.com>

Stefan Csomor

unread,
Aug 17, 2022, 2:29:04 PM8/17/22
to wx-...@googlegroups.com, Subscribed

@vadz , Any idea what happened with the failed build here? It looks like it failed to install something on the build VM...
Thx.

Actually, it looks like the version of pip being installed (19.1.1) is not compatible with Python 3.10. collections.Mapping was moved to collections.abc in Python 3.10.

so should I downgrade python to 3.9 or upgrade pip


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1218357370@github.com>

VZ

unread,
Aug 17, 2022, 2:39:23 PM8/17/22
to wx-...@googlegroups.com, Subscribed

Sorry, I just don't have time to look at this now, but I suspect we have to use latest pip for this macOS version then. Of course, just using latest pip everywhere doesn't work, or at least didn't, in the past, see e.g. this comment: https://github.com/wxWidgets/wxWidgets/blob/8c9b09dfa95a5ea8d4d1df2da01183b2dc1cb3ce/build/tools/httpbin.sh#L60-L62

I really, really hate Python ecosystem with a passion.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1218366262@github.com>

Scott Talbert

unread,
Aug 17, 2022, 2:44:56 PM8/17/22
to wx-...@googlegroups.com, Subscribed

Sorry, I just don't have time to look at this now, but I suspect we have to use latest pip for this macOS version then. Of course, just using latest pip everywhere doesn't work, or at least didn't, in the past, see e.g. this comment:

https://github.com/wxWidgets/wxWidgets/blob/8c9b09dfa95a5ea8d4d1df2da01183b2dc1cb3ce/build/tools/httpbin.sh#L60-L62

I really, really hate Python ecosystem with a passion.

I can take a stab at fixing it - I have an idea which should make everything much simpler.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1218370837@github.com>

Stefan Csomor

unread,
Aug 17, 2022, 2:51:39 PM8/17/22
to wx-...@googlegroups.com, Subscribed

@vadz , Any idea what happened with the failed build here? It looks like it failed to install something on the build VM...
Thx.

Actually, it looks like the version of pip being installed (19.1.1) is not compatible with Python 3.10. collections.Mapping was moved to collections.abc in Python 3.10.

I just checked system python is at 3.9 on the self-hosted runner

I realize that cmake task is not using our self-hosted runner ... sorry for the noise


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1218376342@github.com>

oneeyeman1

unread,
Aug 18, 2022, 1:50:35 PM8/18/22
to wx-...@googlegroups.com, Subscribed

@vadz,
I think it is time to create a unit test to check if the cursor loading from the resource on all platforms works.

I can add this here or make a new PR - whatever your prefer.

Let me know what is the best way.
(If you'd want this PR to be updated - it will have to wait).

Thank you.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1219769249@github.com>

VZ

unread,
Sep 10, 2022, 10:55:45 AM9/10/22
to wx-...@googlegroups.com, Subscribed

@vadz requested changes on this pull request.

Sorry, but this is still not ready to be applied unfortunately.


In src/osx/carbon/cursor.cpp:

> @@ -17,9 +17,9 @@

     #include "wx/icon.h"

     #include "wx/image.h"

 #endif // WX_PRECOMP

-

+#include "wx/msgdlg.h"

Not needed:

⬇️ Suggested change
-#include "wx/msgdlg.h"


In src/osx/carbon/cursor.cpp:

> +        wxString fileName;

+        wxImage image;

+        fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";

+        image.LoadFile( fileName, wxBITMAP_TYPE_PNG );

This would be more readable

⬇️ Suggested change
-        wxString fileName;

-        wxImage image;

-        fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";

-        image.LoadFile( fileName, wxBITMAP_TYPE_PNG );

+        const wxFileName fileName(wxStandardPaths::Get().GetResourcesDir(), cursor_file, ".png");

+        wxImage image(fileName.GetFullPath(), wxBITMAP_TYPE_PNG);


In src/osx/carbon/cursor.cpp:

> @@ -278,7 +278,28 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX

     if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )

     {

 #if wxOSX_USE_COCOA

-        wxFAIL_MSG( wxT("Not implemented") );

+        wxString fileName;

+        wxImage image;

+        fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";

+        image.LoadFile( fileName, wxBITMAP_TYPE_PNG );

+        if( image.IsOk() )

+        {

+            image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX ) ;

+            image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotSpotY ) ;

+        }

+        else

+        {

+            fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".cur";

Should also use wxFileName() here.


In src/osx/carbon/cursor.cpp:

> +        if( image.IsOk() )

+        {

+            m_refData->DecRef() ;

+            m_refData = NULL ;

This really shouldn't be done, it makes zero sense to allocate new wxCursorRefData just to delete it immediately after.


In src/osx/carbon/cursor.cpp:

> +            image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX ) ;

+            image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotSpotY ) ;

+        }

+        else

+        {

+            fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".cur";

+            image.LoadFile( fileName, wxBITMAP_TYPE_CUR );

+        }

+        if( image.IsOk() )

+        {

+            m_refData->DecRef() ;

+            m_refData = NULL ;

+            InitFromImage( image );

+        }

+        else

+            wxFAIL_MSG( "No PNG cursor image found in Resources" );

This probably should be wxLogError(). The error message is also misleading because it tries both PNG and CUR.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/1103140332@github.com>

oneeyeman1

unread,
Sep 19, 2022, 9:09:17 PM9/19/22
to wx-...@googlegroups.com, Subscribed

@oneeyeman1 commented on this pull request.

In src/osx/carbon/cursor.cpp:

> @@ -278,7 +278,28 @@ wxCursor::wxCursor(const wxString& cursor_file, wxBitmapType flags, int hotSpotX
     if ( flags == wxBITMAP_TYPE_MACCURSOR_RESOURCE )
     {
 #if wxOSX_USE_COCOA
-        wxFAIL_MSG( wxT("Not implemented") );
+        wxString fileName;
+        wxImage image;
+        fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".png";
+        image.LoadFile( fileName, wxBITMAP_TYPE_PNG );
+        if( image.IsOk() )
+        {
+            image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, hotSpotX ) ;
+            image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, hotSpotY ) ;
+        }
+        else
+        {
+            fileName = wxStandardPaths::Get().GetResourcesDir() + "/" + cursor_file + ".cur";

@vadz ,
I'm getting the following:

../src/osx/carbon/cursor.cpp:290:13: error: type 'wxFileName' does not provide a call operator
            fileName( wxStandardPaths::Get().GetResourcesDir(), cursor_file, ".cur" );
            ^~~~~~~~
../src/osx/carbon/cursor.cpp:291:13: error: type 'wxImage' does not provide a call operator
            image( fileName.GetFullPath(), wxBITMAP_TYPE_CUR );
            ^~~~~
2 errors generated.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/review/1113026000@github.com>

oneeyeman1

unread,
Sep 20, 2022, 11:01:02 PM9/20/22
to wx-...@googlegroups.com, Subscribed

@csomor ,
How do I add the cursor file (png) to the Bundle during the build?
I want to add the test code for this....

Thank you.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1253146201@github.com>

oneeyeman1

unread,
Sep 26, 2022, 12:52:11 AM9/26/22
to wx-...@googlegroups.com, Push

@oneeyeman1 pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/push/11132971573@github.com>

oneeyeman1

unread,
Sep 27, 2022, 12:55:07 AM9/27/22
to wx-...@googlegroups.com, Subscribed

@vadz ,
For some reason 1 build got cancelled and now the log file is unaccessible.

Should it be restarted?

Thank you.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1258977680@github.com>

Stefan Csomor

unread,
Oct 1, 2022, 11:52:58 AM10/1/22
to wx-...@googlegroups.com, Subscribed

@csomor , How do I add the cursor file (png) to the Bundle during the build? I want to add the test code for this....

in the Makefile.in of the tests you see how the icns file is copied into xxx.app/Contents/Resources


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c1264403651@github.com>

VZ

unread,
Apr 28, 2024, 11:08:05 AM (9 days ago) Apr 28
to wx-...@googlegroups.com, Subscribed

Closed #22391.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/issue_event/12635088782@github.com>

VZ

unread,
Apr 28, 2024, 11:08:06 AM (9 days ago) Apr 28
to wx-...@googlegroups.com, Subscribed

I think this got replaced by #24374.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/22391/c2081515277@github.com>

Reply all
Reply to author
Forward
0 new messages