Change dock icon?

Howdy doody,
Is it possible to change the app’s dock item programatically?

For example, when a certain window opens, change the dock item completely, and then restore the original dock icon when the window closes.

Thanks.

http://documentation.xojo.com/index.php/DockItem

or NSDockTile in macoslib.

Jason, I already looked at the link you gave, but no real information to actually change it.
I will try macoslib.

Thanks.

What information were you missing? It looks well explained to me, save an example. This clears, draws new and then shows it…

[code] dim g As Graphics = App.DockItem.Graphics
g.ClearRect(0, 0, g.Width, g.Height)

g.ForeColor = HSV(rnd, rnd, rnd)
g.FillOval(0, 0, g.Width, g.Height)
g.ForeColor = HSV(rnd, rnd, rnd)
g.FillOval(50, 50, g.Width-100, g.Height-100)

App.DockItem.UpdateNow[/code]

And to revert to the original…

    App.DockItem.ResetIcon

Will,
I just looked into the macoslib DockTile example, and that only seems to allow text to be superimposed over the icon etc.
I need to completely change the icon to another image.

I am only just starting to learn Xojo properly, so some of the concepts are still a bit confusing to me.
Looking at your code above, I presume that creates 2 oval shapes of different colours (1 of which is 100 pixels smaller that the other).

I am still at a loss as to how to replace the entire dock image, with another image.
For example - if I have a 1024 x x1024 image in my app, how do I modify your example to replace your 2 ovals with my desired image?

Do I use DrawRectangle, and then somehow draw my desired image into that rectangle? Or am I completely on the wrong track?

Thanks.

Ahhh - DrawPicture seems to be what I was looking for (I think) ?

g.Drawpicture(mypicture,0,0)

Thanks - just saw that and now have my code as follows:

[code]dim g As Graphics = App.DockItem.Graphics
g.ClearRect(0, 0, g.Width, g.Height)

g.ForeColor= &cFFFFFF
g.DrawRect(0,0,g.width,g.height)
g.DrawPicture(myImage,0,0)

App.DockItem.UpdateNow[/code]

[quote=107842:@Richard Summers]

g.ForeColor= &cFFFFFF
g.DrawRect(0,0,g.width,g.height)[/quote]

You only need that if you want your icon to have a black border.

Thanks Michel :slight_smile:
Updated accordingly:

[code]Dim g As Graphics = App.DockItem.Graphics
g.ClearRect(0, 0, g.Width, g.Height)
g.DrawPicture(droppedImage,0,0)

App.DockItem.UpdateNow[/code]

[quote=107850:@Richard Summers]Thanks Michel :slight_smile:
Updated accordingly:

[code]Dim g As Graphics = App.DockItem.Graphics
g.ClearRect(0, 0, g.Width, g.Height)
g.DrawPicture(droppedImage,0,0)

App.DockItem.UpdateNow[/code][/quote]

Your dropped image must have the correct dimensions, otherwise the icon will not be drawn correctly. If this was not the case, you would need to use the extra parameters in DrawPicture to make it fit.

Oh? - If my app’s dock icon changes size due to dock magnification, how do I know which size my replacement app icon should be??
My current replacement image is 512 x 512?

Well, it seems it should not be too much of an issue. From the dockItem LR :

You may simply want to experiment with different picture sizes, to see if the automatic scaling works fine. I would also try with rectangular pictures, to see what the system does with them when it usually uses square ones.

I will try my 512 x 512 image and see what happens - thanks for the tip :slight_smile:

OK,
Just tried my code below and the penultimate line produces an error:

[code]Dim g As Graphics = App.DockItem.Graphics
g.ClearRect (0, 0, g.Width, g.Height)
g.DrawPicture (myImage, 0, 0)

App.DockItem.UpdateNow[/code]

Any ideas?

[quote=107965:@Richard Summers]OK,
Just tried my code below and the penultimate line produces an error:

[code]Dim g As Graphics = App.DockItem.Graphics
g.ClearRect (0, 0, g.Width, g.Height)
g.DrawPicture (myImage, 0, 0)

App.DockItem.UpdateNow[/code]

Any ideas?[/quote]

what is droppedReviewImage ? A folderitem ? A graphics ? You must use a picture.

Ok, my code below is in the DropObject event of a canvas:

[code] // CHECK IF AN IMAGE WAS DROPPED ONTO THE CANVAS
if obj.FolderItemAvailable then

//SET THE PROPERTY CALLED droppedReviewImage TO THE DROPPED IMAGE
droppedReviewImage = obj.FolderItem

Dim g As Graphics = App.DockItem.Graphics
g.ClearRect (0, 0, g.Width, g.Height)
g.DrawPicture (droppedReviewImage, 0, 0)

App.DockItem.UpdateNow

End if[/code]

The error is shown in my above screenshot.

That is what I thought. You want to use dim droppedReviewImage as Picture and use Picture.Open(obj.FolderItem).

I noticed you seem to have consistently trouble understanding the notion of type of variables. A picture is not the place where it is stored (FolderItem). As Van Vogt would say in the World of ?, the map is not the territory :wink:

My code now looks like this, but produces a different error:
I am now completely lost :frowning:

[code] if obj.FolderItemAvailable then

Dim droppedReviewImage as Picture
Picture.Open(obj.FolderItem)

Dim g As Graphics = App.DockItem.Graphics
g.ClearRect (0, 0, g.Width, g.Height)
g.DrawPicture (droppedReviewImage, 0, 0)

App.DockItem.UpdateNow

End if[/code]

[quote=107975:@Richard Summers]My code now looks like this, but produces a different error:
I am now completely lost :([/quote]

Richard, you MUST at least read the LR to see how to use a method :

http://documentation.xojo.com/index.php/Picture.Open