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...
How to tell if wxArtProvider::GetIcon() was successful?
-
- Knows some wx things
- Posts: 31
- Joined: Mon Nov 07, 2011 12:41 pm
Re: How to tell if wxArtProvider::GetIcon() was successful?
You could try this:
I haven't tested it though.
Code: Select all
if( your_icon.IsSameAs( wxNullIcon ) )
Use the source, Luke!
-
- Knows some wx things
- Posts: 31
- Joined: Mon Nov 07, 2011 12:41 pm
Re: How to tell if wxArtProvider::GetIcon() was successful?
Thanks for the hint but unfortunately it doesn't work.
Re: How to tell if wxArtProvider::GetIcon() was successful?
With platform and wx version?
I just tested it and wxNullIcon::Ok() returns false. Also its width and height are 0.
I just tested it and wxNullIcon::Ok() returns false. Also its width and height are 0.
Use the source, Luke!
-
- Knows some wx things
- Posts: 31
- Joined: Mon Nov 07, 2011 12:41 pm
Re: How to tell if wxArtProvider::GetIcon() was successful?
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.
Platform Fedora 17, 3.5.4-2.fc17.x86_64 / wxWidgets 2.9.3
Code: Select all
wxIcon icon = wxArtPrivoder::GetIcon("foobar", wxART_MENU);
if (!icon.IsOk()) {
/* This block is never being executed */
}
Re: How to tell if wxArtProvider::GetIcon() was successful?
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");
}
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!
-
- Knows some wx things
- Posts: 31
- Joined: Mon Nov 07, 2011 12:41 pm
Re: How to tell if wxArtProvider::GetIcon() was successful?
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...