#!/star/bin/awish
#
# gwm.tcl
#
# This file is an example of using the gwm widget and associated procedures
#
# It creates a gwm server window with scroll bars for scrolling the
# window and buttons for changing colours, printing, clearing and exiting.
# A crosshair is optionally displayed at the cursor position.
#
# Any arguments to the script that are not recognised as wish options
# are used as arguments for the widget creation command.
#
# Add the location of the gwm procedures to the auto load path.
lappend auto_path /star/lib/startcl
# Create the gwm widget with scroll bars. The arguments to this script
# are concatonated with the command to create the widget and the resulting
# string evaluated so that the script arguments become additional arguments
# to the command.
set create [concat {gwm_gwmWithScroll .gwm} $argv]
set gwm [eval $create]
# Create and pack a frame for the control buttons.
pack [frame .bottom] -side bottom -fill x
pack [frame .buttons -relief sunken -border 2] -padx 3 -pady 3 \
-side right -in .bottom
# Pack a label along side the button frame to match the appearance of the
# frame
pack [label .bottom.fill -relief sunken -border 2 -anchor w] -fill both \
-padx 3 -pady 3 -side left -expand y
# Create the command buttons.
button .buttons.exit -text Exit -command exit -padx 10
button .buttons.colours -text Colours -padx 10 \
-command "gwm_colourDialog .col $gwm .buttons.colours"
button .buttons.clear -text Clear -padx 10 -command "$gwm clear"
button .buttons.ovclear -text "Clear Overlay" -padx 10 \
-command "$gwm ovclear"
button .buttons.print -text Print -padx 10 \
-command "gwm_printDialog .pr $gwm .buttons.print"
checkbutton .buttons.crosshair -text Crosshair -padx 10 \
-variable crosshair -command crossHair
# Pack the buttons into the frame.
pack .buttons.exit .buttons.clear .buttons.print .buttons.crosshair \
-side left -expand y -padx 5 -pady 5
pack .buttons.colours -after .buttons.exit -padx 3 -pady 3 \
-side left -expand y
# Pack the "clear overlay" button if the window has an overlay.
if [$gwm cget -overlay] {
pack .buttons.ovclear -after .buttons.clear -padx 3 -pady 3 \
-side left -expand y
}
# Bind a procedure that displays the current pointer position in a pop-up
# window to pressing mouse button 2.
bind $gwm <ButtonPress-2> {showPointer %x %y}
bind $gwm <ButtonRelease-2> {destroy .position}
# Change the cursor so that is doesn’t interfere with the pop-up.
$gwm configure -cursor draft_small
# Pack the gwm widget’s frame into the top level widget. This is done last
# so that when the top level is resized it is the gwm widget that gets
# resized to fit rather than the frame containing the buttons.
pack .gwm -in .
# Allow the window to be resized by the window manager by setting the
# minimum size.
wm minsize . 1 1
# Map the window and find out how big it is and use this as the maximum
# size allowed by the window manager. Also constrain the minimum size so
# that the buttons are always visible.
update idletasks
wm maxsize . [winfo width .] [winfo height .]
wm minsize . [winfo reqwidth .buttons ] [winfo reqwidth .buttons ]
# Change the main window title to be the name of gwm window
wm title . [$gwm cget -gwmname]
proc crossHair {} {
#+
# This procedure is called whenever the "crosshair" checkbutton is toggled
# and either enables the crosshair whenever the pointer is in the gwm
# widget and binds the crosshair position to the pointer or disables the
# crosshair.
#-
global crosshair
global gwm
if $crosshair {
bind $gwm <Any-Motion> { %W set crosshair %x %y }
bind $gwm <Any-Enter> { %W configure -crosshair yes }
bind $gwm <Any-Leave> { %W configure -crosshair no }
} {
bind $gwm <Any-Motion> {}
bind $gwm <Any-Enter> {}
bind $gwm <Any-Leave> {}
$gwm configure -crosshair no
}
}
proc showPointer {x y} {
#+
# This procedure pops up a panel that displays values of the parameters
# x and y corrected for any scrolling of the gwm widget.
#-
toplevel .position -bd 3 -relief raised
wm overrideredirect .position 1
global gwm
set xpos [expr [winfo rootx $gwm] + $x]
set ypos [expr [winfo rooty $gwm] + $y]
wm geometry .position +$xpos+$ypos
set x [expr $x - [$gwm cget -xoffset]]
set y [expr $y - [$gwm cget -yoffset]]
label .position.x -text "X = $x"
label .position.y -text "Y = $y"
pack .position.x .position.y
}
# End of script - enter event loop...