Roll-Up -Modify MS-Windows palettes to provide Linux-like shading behaviour.

WJG 2006-04-07: In spite of the title, this is not about the joys of wakky-bakky -sorry :-) However, it does gives some sort of elevated joy to those of us who clutter up our GUIs with lots of palettes and floating stuff. Rather than having the window temporarily iconized to the task bar we can 'roll them up'. To achieve this simply intercept the WM_DELETE_WINDOW event on the floating palette and then resize the window. A checkbutton allows the user to determine whether or not to display the palette but this could also be achieved under menu control.

#---------------
# rollup.tcl
#---------------
# Created by William J Giddings
# 7/Apr/2006
#---------------
#
# Function:
# Provide MS Windows palette with a roll-up behaviour.
#
# Notes:
# If the palette is created as withdrawn it will never appear.
# So, the work-around has been to create the palette as a normal
# toplevel window and then to modify its transient setting on display/hiding.
# Version of Tcl/Tk used for development = 8.4.12
#---------------


#---------------
# determine whether or not to roll-up or roll-down
# called when the close-button is picked
#---------------
proc palette:state {w} {
    if {[set ${w}::state]} {
        # roll-up
        set ${w}::height [winfo height $w]
        wm geometry $w [winfo width $w]x0
        set ${w}::state 0
        wm resizable $w 0 0
    } else {
        # roll-down
        wm geometry $w [winfo width $w]x[set ${w}::height]  
        set ${w}::state 1
        wm resizable $w 1 1   
    }
}

#---------------
# determine whether or not to display the palette
# called by the toolbar button
#---------------
proc palette:show {w b} {
    if {[set ${w}::show]} {
        # show it
        wm deiconify $w 
        wm transient $w [winfo toplevel $b]
    } else {
        # hide it
        wm transient $w
        wm withdraw $w
    }
}

#---------------
# create button and palette
#---------------
proc palette {b w txt} {

    # namespace to hold palette info
    namespace eval $w {
        set state 1
        set show 0
    }
 
    # button to toggle the display of the palette
    checkbutton $b \
        -indicatoron 0 \
        -text $txt \
        -borderwidth 1 \
        -overrelief raised \
        -relief flat \
        -command "palette:show $w $b" \
        -variable ${w}::show

    # build the basic palette and configure
    toplevel $w
    wm withdraw $w
    # this is a problem, allow here then for some 
    # reason the palette will never appear!
    #wm transient $w [winfo toplevel $b]
    wm protocol $w WM_DELETE_WINDOW "palette:state $w" 
                                     
    return $b
}

# a simple example
# create palette and button
pack [palette .pb1 .p1 Palette-1] -side left  -anchor nw
pack [palette .pb2 .p2 Palette-2] -side left  -anchor nw