W3cubDocs

/Tcl/Tk

tk_mac

NAME
tk::mac — Access Mac-Specific Functionality on OS X from Tk
SYNOPSIS
EVENT HANDLER CALLBACKS
::tk::mac::ShowPreferences
::tk::mac::OpenApplication
::tk::mac::ReopenApplication
::tk::mac::OpenDocument file...
::tk::mac::PrintDocument file...
::tk::mac::Quit
::tk::mac::OnHide
::tk::mac::OnShow
::tk::mac::ShowHelp
ADDITIONAL DIALOGS
::tk::mac::standardAboutPanel
SYSTEM CONFIGURATION
::tk::mac::useCompatibilityMetrics boolean
::tk::mac::CGAntialiasLimit limit
::tk::mac::antialiasedtext number
::tk::mac::useThemedToplevel boolean
SUPPORT COMMANDS
::tk::mac::iconBitmap name width height -kind value
-file
-fileType
-osType
-systemType
-namedImage
-imageFile
SEE ALSO
KEYWORDS

Name

tk::mac — Access Mac-Specific Functionality on OS X from Tk

Synopsis

::tk::mac::ShowPreferences
::tk::mac::OpenApplication
::tk::mac::ReopenApplication
::tk::mac::OpenDocument file...
::tk::mac::PrintDocument file...
::tk::mac::Quit
::tk::mac::OnHide
::tk::mac::OnShow
::tk::mac::ShowHelp

::tk::mac::standardAboutPanel

::tk::mac::useCompatibilityMetrics boolean
::tk::mac::CGAntialiasLimit limit
::tk::mac::antialiasedtext number
::tk::mac::useThemedToplevel boolean

::tk::mac::iconBitmap name width height -kind value

Event handler callbacks

The Aqua/Mac OS X application environment defines a number of additional events that applications should respond to. These events are mapped by Tk to calls to commands in the ::tk::mac namespace; unless otherwise noted, if the command is absent, no action will be taken.
::tk::mac::ShowPreferences
The default Apple Event handler for kAEShowPreferences, “pref”. The application menu “Preferences” menu item is only enabled when this proc is defined. Typically this command is used to wrap a specific own preferences command, which pops up a preferences window. Something like:
proc ::tk::mac::ShowPreferences {} {
    setPref
}
::tk::mac::OpenApplication
If a proc of this name is defined, this proc fill fire when your application is intially opened. It is the default Apple Event handler for kAEOpenApplication, “oapp”.
::tk::mac::ReopenApplication
If a proc of this name is defined it is the default Apple Event handler for kAEReopenApplication, “rapp”, the Apple Event sent when your application is opened when it is already running (e.g. by clicking its icon in the Dock). Here is a sample that raises a minimized window when the Dock icon is clicked:
proc ::tk::mac::ReopenApplication {} {
    if {[wm state .] eq "withdrawn"} {
        wm state . normal
    } else {
        wm deiconify .
    }
    raise .
}
::tk::mac::OpenDocument file...
If a proc of this name is defined it is the default Apple Event handler for kAEOpenDocuments, “odoc”, the Apple Event sent when your application is asked to open one or more documents (e.g., by drag & drop onto the app or by opening a document of a type associated to the app). The proc should take as arguments paths to the files to be opened, like so:
proc ::tk::mac::OpenDocument {args} {
    foreach f $args {my_open_document $f}
}
::tk::mac::PrintDocument file...
If a proc of this name is defined it is the default Apple Event handler for kAEPrintDocuments, “pdoc”, the Apple Event sent when your application is asked to print one or more documents (e.g., via the Print menu item in the Finder). It works the same way as tk::mac::OpenDocument in terms of arguments.
::tk::mac::Quit
If a proc of this name is defined it is the default Apple Event handler for kAEQuitApplication, “quit”, the Apple Event sent when your application is asked to be quit, e.g. via the quit menu item in the application menu, the quit menu item in the Dock menu, or during a logout/restart/shutdown etc. If this is not defined, exit is called instead.
::tk::mac::OnHide
If defined, this is called when your application receives a kEventAppHidden event, e.g. via the hide menu item in the application or Dock menus.
::tk::mac::OnShow
If defined, this is called when your application receives a kEventAppShown event, e.g. via the show all menu item in the application menu, or by clicking the Dock icon of a hidden application.
::tk::mac::ShowHelp
Customizes behavior of Apple Help menu; if this procedure is not defined, the platform-specific standard Help menu item “YourApp Help” performs the default Cocoa action of showing the Help Book configured in the application's Info.plist (or displaying an alert if no Help Book is set).

Additional dialogs

The Aqua/Mac OS X defines additional dialogs that applications should support.
::tk::mac::standardAboutPanel
Brings the standard Cocoa about panel to the front, with all its information filled in from your application bundle files (standard about panel with no options specified). See Apple Technote TN2179 and the AppKit documentation for -[NSApplication orderFrontStandardAboutPanelWithOptions:] for details on the Info.plist keys and app bundle files used by the about panel.

System configuration

There are a number of additional global configuration options that control the details of how Tk renders by default.
::tk::mac::useCompatibilityMetrics boolean
Preserves compatibility with older Tk/Aqua metrics; set to false for more native spacing.
::tk::mac::CGAntialiasLimit limit
Sets the antialiasing limit; lines thinner that limit pixels will not be antialiased. Integer, set to 0 by default, making all lines be antialiased.
::tk::mac::antialiasedtext number
Sets anti-aliased text. Controls text antialiasing, possible values for number are -1 (default, use system default for text AA), 0 (no text AA), 1 (use text AA).
::tk::mac::useThemedToplevel boolean
Sets toplevel windows to draw with the modern grayish/ pinstripe Mac background. Equivalent to configuring the toplevel with “-background systemWindowHeaderBackground”, or to using a ttk::frame.

Support commands

::tk::mac::iconBitmap name width height -kind value
Renders native icons and bitmaps in Tk applications (including any image file readable by NSImage). A native bitmap name is interpreted as follows (in order):
  • predefined builtin 32x32 icon name (stop, caution, document, etc.)
  • name, as defined by tk::mac::iconBitmap
  • NSImage named image name
  • NSImage url string
  • 4-char OSType of IconServices icon

The width and height arguments to tk::mac::iconBitmap define the dimensions of the image to create, and -kind must be one of:

-file
icon of file at given path
-fileType
icon of given file type
-osType
icon of given 4-char OSType file type
-systemType
icon for given IconServices 4-char OSType
-namedImage
named NSImage for given name
-imageFile
image at given path

See also

bind, wm

Copyright © 2011 Kevin Walzer.
Copyright © 2011 Donal K. Fellows.