modifier l'icône du Dock Mac OS X d'une application Tk

 

L'exemple suivant permet de modifier l'icône du Dock Mac OS X d'une application Tk avec une image PNG passée en argument en utilisant Ffidl :

 # Set the Dock Tile from a png file with Ffidl
 #
 # Copyright (c) 2005, Daniel A. Steffen <das@users.sourceforge.net>
 # BSD License: c.f. <http://www.opensource.org/licenses/bsd-license>

 package require Tk
 package require Ffidl

 namespace eval carbon {
     proc api {name argl ret lib} {::ffidl::callout $name $argl $ret \
         [::ffidl::symbol $lib.framework/$lib $name]}
     proc type {name type} {::ffidl::typedef $name $type}
     proc const {name args} {variable {}; eval set [list ($name)] $args}

     type OSStatus sint32
     type bool int
     type CFURLRef pointer
     type CGDataProviderRef pointer
     type CGImageRef pointer
     type CGColorRenderingIntent int
     const kCGRenderingIntentDefault 0

     api CFURLCreateFromFileSystemRepresentation {pointer pointer-utf8 \
             int bool} CFURLRef CoreFoundation
     api CFRelease {pointer} void CoreFoundation
     api CGDataProviderCreateWithURL {CFURLRef} CGDataProviderRef \
             ApplicationServices
     api CGImageCreateWithPNGDataProvider {CGDataProviderRef pointer \
             bool CGColorRenderingIntent} CGImageRef ApplicationServices
     api SetApplicationDockTileImage {CGImageRef} OSStatus Carbon

     proc setDockTileToPNG {pngFile} {
         if {[file exists $pngFile]} {
             set url [CFURLCreateFromFileSystemRepresentation 0 $pngFile \
                     [string bytelength $pngFile] 0]
             if {$url} {
                 set dp [CGDataProviderCreateWithURL $url]
                 if {$dp} {
                     set img [CGImageCreateWithPNGDataProvider $dp 0 1 \
                             [const kCGRenderingIntentDefault]]
                     if {$img} {
                         SetApplicationDockTileImage $img
                         CFRelease $img
                     }
                     CFRelease $dp
                 }
                 CFRelease $url
             }
         }
     }
 }

 carbon::setDockTileToPNG test.png

Catégorie Mac OS X