Skip to main content
Inspiring
February 20, 2008
Question

using IconRef...

  • February 20, 2008
  • 6 replies
  • 726 views
For the Mac only, how can I use the IconRef with the SDK's widget?

There is this API called GetIconRef() that I can get ahold of all kinds of icons from the OS, but I don't know how to pass that data to any of the widget (such as IconSuiteWidget).

Many thanks.
This topic has been closed for replies.

6 replies

Peter S LAuthor
Inspiring
February 21, 2008
I did a search for "public CControlView" among the sample code files and I think I found a few examples on how to extend CControlView... the code looks a bit scary right now but once I play with it a bit, it should be okay... I will post more questions once I start working on it.

Many thanks.

pete
Participating Frequently
February 21, 2008
Peter,

I am not really familiar with the IconRef, but I would imagine you use GetIconRef to get a reference to the icon, provided you have a valid return, then you should be able to plot the icon in your own IControlView::Draw method. Sorry, that was my mistake, there is no DrawIcon method. But you would handle your custom drawing in the IControlView::Draw method. I did a quick search and it looks like you can use PlotIconRef to draw the icon in a rectangle that you should be calculating in the IControlView::Draw.

Cheers!
lee
Peter S LAuthor
Inspiring
February 21, 2008
Thanks for the info, Dirk.

The idea to use Icon Services (IconRef and GetIconRef()) is to retrieve the icons directly from the OS so that it will be consistent (hopefully) everywhere.

I probably will still have the resource there asback up in case the call failed...

pete
Inspiring
February 21, 2008
If you can get along with stock implementations, the icon resource ID and resource plugin ID are both required to identify an icon.

f you want to draw it yourself:

Inherit a control view implementation from CControlView.

In your MyControlView::Draw() method, you can use ResourceEnabler (at auto/local scope) to refer to the resources of your plugin, then use PlatformIconClass to load & draw.

As I only use PNG icons, I don't know about IconRef.

Dirk
Peter S LAuthor
Inspiring
February 21, 2008
Hi Lee,

Here's my problem:

I have a IconSuiteWidget and I can call the member function SetRsrcID() through an IControlView interface with a valid resource id from the icon resource (on the Mac platform) to set the icon.

Now, instead of obtaining or setting the icon through the resource id, I can get ahold with the icon through an IconRef after I called GetIconRef(). My first thought would be to use the "rsrc id" published in Icons.h, but that does not seem to work. May be because I call SetRsrcPluginID() with our plugin id before I call SetRsrcID()?

Anyway, I kind of understand what you were saying in your reply up to when you mentioned "IControlView::DrawIcon"... I see Draw() but not DrawIcon()... is there any sample code (from the SDK?) that you can point me to experiment a bit?

Thanks.
Participating Frequently
February 20, 2008
Peter,

I am not sure what you mean by using the IconRef with the SDK's widget, but you can always override the behavior of a widget such as IconSuiteWidget. For example, if you want to provide custom icon drawing for the widget, you would create a widget boss based on kIconSuiteButtonWidgetBoss and provide your own IControlView implementation. In the implementation of IControlView::DrawIcon, you can call GetIconRef to get your icon.

Thanks!
lee