Tk Source Code

Artifact [2f4518c3]
Login

Artifact 2f4518c3799f5997307fa162f8ee4c5afc379fd4:

Attachment "combocrash.tcl" to ticket [767176ff] added by muonics 2003-07-07 23:12:31.
package require combobox

console show

proc centerWin { {hWnd "."} } {
    wm withdraw $hWnd
    wm override $hWnd 1
    wm geometry $hWnd 1x1+0+0
    wm deiconify $hWnd
    update idletasks

    set vx [winfo vrootx [winfo toplevel $hWnd]]
    set vy [winfo vrooty [winfo toplevel $hWnd]]

    set x [expr {[winfo screenwidth $hWnd]/2 - \
			[winfo reqwidth $hWnd]/2 - $vx}]
    set y [expr {[winfo screenheight $hWnd]/2 - \
			[winfo reqheight $hWnd]/2 - $vy}]
    set geometry [winfo reqwidth $hWnd]x[winfo reqheight $hWnd]+$x+$y
    update idletasks

    wm withdraw $hWnd
    wm override $hWnd 0
    wm geometry $hWnd $geometry
    update idletasks
    wm deiconify $hWnd
    update idletasks
}

proc unique { widget name args } {

    # Scan for a non-existant widget name given by the 'name' field
    # with an appended number.

    for {set i 0} {$i < 2147483647} {incr i} {
        if {![winfo exist $name$i]} {
            break
        }
    }

    # Make sure the decided-upon name doesn't exist.  With that high
    # of a number, it shouldn't ever happen, but just in case...

    if {[winfo exist $name$i]} {
        error "Cannot create unique widget $name -- too many windows"
    }

    return [eval $widget $name$i $args]
}

proc combopop { } {
    set hWnd [unique toplevel .toBlahBlah]

    wm title $hWnd "Blah Blah"

    if {$::tcl_platform(platform) == "windows"} {
        wm iconbitmap $hWnd table.ico
    }

    grid [combobox::combobox $hWnd.cmb] -sticky ew

    centerWin $hWnd
    return $hWnd
}

pack [button .b1 -text "Exit" -command [list after idle exit]] \
		-fill both -expand 1
pack [button .b2 -text "Combo" -command combopop] \
		-fill both -expand 1
set w	[expr {[winfo screenwidth .]-200}]
set h	[expr {[winfo screenheight .]-200}]
wm geom . [set w]x[set h]+100+100