How to tell if wxArtProvider::GetIcon() was successful?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
gbuergisser
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon Nov 07, 2011 12:41 pm

How to tell if wxArtProvider::GetIcon() was successful?

Post by gbuergisser »

This may be a dumb question... My application is calling wxArtProvider::GetIcon() and adds the returned wxIcon to an imag list with wxImageList::Add(). The documentation of GetIcon() says it returns a wxNullIcon upon failure.
Now how can I tell if GetIcon() really found the icon I wanted? How can I check the returned value against wxNullIcon or check if it is a valid (not empty) icon? IsOk() also returns true for a wxNullIcon...
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to tell if wxArtProvider::GetIcon() was successful?

Post by doublemax »

You could try this:

Code: Select all

if( your_icon.IsSameAs( wxNullIcon ) ) 
I haven't tested it though.
Use the source, Luke!
gbuergisser
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon Nov 07, 2011 12:41 pm

Re: How to tell if wxArtProvider::GetIcon() was successful?

Post by gbuergisser »

Thanks for the hint but unfortunately it doesn't work.
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to tell if wxArtProvider::GetIcon() was successful?

Post by doublemax »

With platform and wx version?

I just tested it and wxNullIcon::Ok() returns false. Also its width and height are 0.
Use the source, Luke!
gbuergisser
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon Nov 07, 2011 12:41 pm

Re: How to tell if wxArtProvider::GetIcon() was successful?

Post by gbuergisser »

Hmm, I think it needs some clarification: I originally tried IsOK() and not Ok(). But I now have tried both. And for a wxNullIcon they really return false. So far so good. But the real problem seems to be that wxArtProvider::GetIcon() doesn not return a wxNullIcon if it is called with a name it cannot find.

Code: Select all

wxIcon icon = wxArtPrivoder::GetIcon("foobar", wxART_MENU);
if (!icon.IsOk()) {
   /* This block is never being executed */
}
Platform Fedora 17, 3.5.4-2.fc17.x86_64 / wxWidgets 2.9.3
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How to tell if wxArtProvider::GetIcon() was successful?

Post by doublemax »

Code: Select all

wxIcon icon = wxArtProvider::GetIcon("foobar", wxART_MENU);
wxLogMessage(wxT("icon: ok=%d width=%d height=%d"), icon.Ok(), icon.GetWidth(), icon.GetHeight() );
if (!icon.IsOk()) {
  wxLogMessage("icon not found");
}
This works fine for me under MSW (2.9.4). Maybe it's a platform specific problem.
What kind of icon does it return? Maybe the implementation is different and returns some kind of default icon in any case.
Use the source, Luke!
gbuergisser
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon Nov 07, 2011 12:41 pm

Re: How to tell if wxArtProvider::GetIcon() was successful?

Post by gbuergisser »

I copied/pasted your snippet into my application and it reports "ok=1 width=16 height=16". But then no icon is visible in the list ctrl that uses it. May be a platform dependent behaviour...
Post Reply