Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

Folderitem.AddCustomIconMBS(icon as IconFamilyMBS, Compat as boolean) as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes No No Yes, macOS only No
Function: Adds a custom icon to a file.
Example:
dim fo as FolderItem
dim g as IconFamilyMBS
dim p,m as Picture

fo=SpecialFolder.Desktop.Child("test.jpg")
// get some picture

p=fo.OpenAsPicture

// make a mask
m=NewPicture(p.Width,p.Height,1)
m.Graphics.ForeColor=rgb(0,0,0)
m.Graphics.fillrect 0,0,m.Width,m.Height

// You may prefer to make a picture and a mask centered within a quadratic picture

g=newIconFamilyMBS // new family

// Add icons
g.Thumbnail32BitData=p
g.Thumbnail8BitMask=m

g.Large1BitData=p
g.Large1BitMask=m
g.Large32BitData=p
g.Large4BitData=p
g.Large8BitData=p
g.Large8BitMask=m

g.Huge1BitData=p
g.Huge1BitMask=m
g.Huge32BitData=p
g.Huge4BitData=p
g.Huge8BitData=p
g.Huge8BitMask=m

g.Small1BitData=p
g.Small1BitMask=m
g.Small32BitData=p
g.Small4BitData=p
g.Small8BitData=p
g.Small8BitMask=m

// Save to file
MsgBox str(fo.AddCustomIconMBS(g,true))
Notes:
Requires Mac OS 8.5 or newer.
Returns a Mac OS error code, with 0 for no error and -1 for parameter error (Icon=nil or invalid folderitem).
If Compat=true then the old icon resources for Mac OS 7/8 will be generated.
For folders, please create an invisible file called "icon" inside the folder and add the icon to this file.
To change the icon, just add it a second time. This will overwrite the first icon.

Before setting icon, make sure you close all Binarystream, Textoutputstream or other classes which may have the file open.

Please use NSWorkspaceMBS.setIcon for newer projects.

Some examples which use this method:

Feedback, Comments & Corrections

Folderitem.DrawIconMBS(g as Graphics,x as Integer,y as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes Yes No Yes No
Function: Draws the icon of the folderitem on the position x/y inside the graphics object.
Example:
SpecialFolder.System.DrawIconMBS canvas1.graphics,0,0
Notes:
The works with masks.
For every other size than 32 pixels use DrawWideIcon.

Feedback, Comments & Corrections

Folderitem.DrawWideIconMBS(g as Graphics,x as Integer,y as Integer,width as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes Yes No Yes No
Function: Draws the icon of the folderitem on the position x/y inside the graphics object with the given width.
Example:
app.applicationfileMBS.DrawWideIconMBS(canvas1.graphics,0,0,128) 'for the nice OSX icons
Notes:
The works with masks.
Works even wonderfull with OSX Icons.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

folderitem.DrawWideIconMBS(g as Graphics,x as Integer,y as Integer,width as Integer, WindowsIconIndex as Integer)
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin 3.3 Yes Yes No Yes No
Function: Draws the icon of the folderitem on the position x/y inside the graphics object with the given width.
Example:
app.applicationfileMBS.DrawWideIconMBS(canvas1.graphics,0,0,128,0) 'for the nice OSX icons
Notes:
The works with masks.
Works even wonderfull with OSX Icons.
The WindowsIconIndex parameter is only for Windows and specifies which icon from inside the file is picked.

If you draw this in a listbox cellbackground, you need to draw on the correct position:

dim f as FolderItem
f=SpecialFolder.Desktop
f.DrawWideIconMBS(g,me.left,me.top+row*20,16)
Return true

try this in a listbox. The Graphics object there has a cliping and an offset which the plugin doesn't know about.

Not supported for Cocoa targt.

See also:

Some examples which use this method:

Feedback, Comments & Corrections

Folderitem.FinderUpdateMBS as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes No No Yes, macOS only No
Function: Updates the file or folder in the Finder.
Notes:
Returns 0 for successfull and any Mac OS error code on a problem.
Returns -1 on Windows.
This function is called automatically when adding or removing an icon.
If you add a folder icon, use this function to update the Finder to display it.

Some examples which use this method:

Feedback, Comments & Corrections

folderitem.IconImageMBS(width as Integer, WindowsFlags as Integer=0) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin 3.3 Yes Yes No Yes No
Function: Returns an picture with the icon image of a Folderitem.
Example:
Backdrop=SpecialFolder.Desktop.IconImageMBS(512)
Notes:
May return a picture which is smaller as requested if the given picture size is not available. (Changed in v5.3 to return the requested size)
On Windows the icon picture is scaled to the requested size. (Actually the plugin can only get 32bit pixels wide icons on Windows as maximum)
Good sizes on Mac OS are 16, 32, 48 and 128 pixels.
Returns nil on low memory.

Version 8.6: Now reads the 32bit image data if possible.

You can pass flags for Windows options:
SHGFI_ADDOVERLAYS= &h20Apply the appropriate overlays to the file's icon.
SHGFI_LINKOVERLAY= &h8000Adds the link overlay to the file's icon.
SHGFI_OPENICON= 2Retrieve the file's open icon
SHGFI_SELECTED= &h10000Blend the file's icon with the system highlight color.

This function can fail if the file does not exist.
Added 1024 pixel support in 12.3 plugins.

On Windows, it may be that you get a 256 pixel icon with small icon on top left. This is simply how windows handles the case when no big icon is available.

Some examples which use this method:

Feedback, Comments & Corrections

folderitem.IconMaskMBS(width as Integer, WindowsFlags as Integer=0) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin 3.3 Yes Yes No Yes No
Function: Returns an picture with the icon mask of a Folderitem.
Example:
Backdrop=SpecialFolder.Desktop.IconMaskMBS(512)
Notes:
May return a picture which is smaller as requested if the given picture size is not available. (Changed in v5.3 to return the requested size)
On Windows the icon picture is scaled to the requested size. (Actually the plugin can only get 32bit pixels wide icons on Windows as maximum)
Good sizes on Mac OS are 16, 32, 48 and 128 pixels.
Returns nil on low memory.

Please use with IconImageMBS and not with IconMBS function.
Version 8.6: Now reads the 8 bit alpha values if possible.

You can pass flags for Windows options:
SHGFI_ADDOVERLAYS= &h20Apply the appropriate overlays to the file's icon.
SHGFI_LINKOVERLAY= &h8000Adds the link overlay to the file's icon.
SHGFI_OPENICON= 2Retrieve the file's open icon
SHGFI_SELECTED= &h10000Blend the file's icon with the system highlight color.

This function can fail if the file does not exist.
Added 1024 pixel support in 12.3 plugins.

On Windows, it may be that you get a 256 pixel icon with small icon on top left. This is simply how windows handles the case when no big icon is available.

Some examples which use this method:

Feedback, Comments & Corrections

Folderitem.IconMBS(width as Integer, WindowsFlags as Integer=0) as picture
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes Yes No Yes No
Function: Returns an picture with the icon of a Folderitem for the given iconsize.
Example:
Backdrop=SpecialFolder.Desktop.IconMBS(512)

// newer way for Mac apps:

// get image
dim n as NSImageMBS = NSWorkspaceMBS.iconForFile(SpecialFolder.desktop)
// set the size we want
n.setSize 512,512
// make a copy as picture
Backdrop = n.CopyPictureWithMask
Notes:
Changed in plugin version 7.7 to return a picture with mask of the given size.

On Windows the icon picture is scaled to the requested size. (Actually the plugin can only get 32bit pixels wide icons on Windows as maximum)

Version 8.6: Now reads the 32bit image data with 8 bit alpha values if possible.

You can pass flags for Windows options:
SHGFI_ADDOVERLAYS= &h20Apply the appropriate overlays to the file's icon.
SHGFI_LINKOVERLAY= &h8000Adds the link overlay to the file's icon.
SHGFI_OPENICON= 2Retrieve the file's open icon
SHGFI_SELECTED= &h10000Blend the file's icon with the system highlight color.

This function can fail if the file does not exist.
Please note that icons on alias files takes much longer to get than normal files.
Added 1024 pixel support in 12.3 plugins.

On Windows, it may be that you get a 256 pixel icon with small icon on top left. This is simply how windows handles the case when no big icon is available.

Some examples which use this method:

Feedback, Comments & Corrections

Folderitem.OpenAsIconFamilyMBS as IconFamilyMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes Yes No Yes No
Function: Opens an icon file.
Notes:
Requires Mac OS 9 or newer.
This function is deprecated. Better you move to OpenAsIconsFamilyMBS.

Some examples which use this method:

Feedback, Comments & Corrections

Folderitem.OpenAsIconsFamilyMBS as IconFamilyMBS
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes Yes No Yes No
Function: Opens an icon file.
Notes: Requires Mac OS 8.5 or newer.

Feedback, Comments & Corrections

Folderitem.RemoveCustomIconFromFileMBS as Integer
Type Topic Plugin Version macOS Windows Linux Console & Web iOS
method Icon Service MBS Picture Plugin Yes No No Yes, macOS only No
Function: Removes a custom icon from a file.
Notes:
Requires Mac OS 8.5 or newer.
Returns a Mac OS error code, with 0 for no error and -1 for parameter error (e.g. invalid folderitem).

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Picture Plugin.




Links
MBS Xojo PDF Plugins