home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!decwrl!parc!welch
- From: welch@parc.xerox.com (Brent Welch)
- Subject: Placing diaglog boxes
- Message-ID: <welch.715131551@corvina>
- Summary: Here's how I place dialog boxes
- Keywords: TK
- Sender: news@parc.xerox.com
- Organization: Xerox PARC
- Date: 29 Aug 92 23:39:11 GMT
- Lines: 91
-
- In response to someones comment about not being able to
- put a dialog box up in the middle of a top-level,
- here's how I do it for my editor, mxedit.
-
-
- #
- # placePopUp -
- # Place a popup relative to its parent window
- #
- proc placePopUp { widget {where center} } {
- # mxedit is the main editing widget. It exports a gridsize
- # command that gives the bounding box size of characters and
- # is the basis for using the "wm grid" command
- global mxedit
-
- # The screenwidth command is just a call to
- # winfo screenwidth $mxedit
- # The error checking is historical
- if {[string compare [screenwidth] unknown] == 0} {
- set screenWidth [lindex [exec xwininfo -root | egrep Width:] 2]
- set screenHeight [lindex [exec xwininfo -root | egrep Height:] 2]
- }
-
- # Figure out where we are
- scan [wm geometry .] "%dx%d+%d+%d" charsWide linesHigh xoff yoff
- # puts stderr "Geometry $charsWide $linesHigh $xoff $yoff"
-
- # Use gridding parameters to get our width and height
- set gridWidth [lindex [$mxedit gridsize] 0]
- set gridHeight [lindex [$mxedit gridsize] 1]
- set mainWidth [expr {$charsWide * $gridWidth}]
- set mainHeight [expr {$linesHigh * $gridHeight}]
-
- # Hide the diaglog box
- wm withdraw $widget
- update
- scan [wm geometry $widget] "%dx%d" itsWidth itsHeight
- # puts stderr "Its $itsWidth $itsHeight"
-
- # This is for putting the dialog off to the side
- set leftRoom $xoff
- set rightRoom [expr {[screenwidth] - $xoff - $mainWidth}]
-
- set topRoom $yoff
- set bottomRoom [expr {[screenheight] - $yoff - $mainHeight}]
-
- case $where in {
- # The "off" placement is still a bit lame
- "off" {
- # puts stderr "placePopUp " nonewline
- if {$leftRoom > $rightRoom} {
- set itsXoff [expr {$xoff - $itsWidth}]
- if {$itsXoff < 0} {
- set itsXoff 0
- }
- # puts stderr "left $itsXoff " nonewline
- } else {
- set itsXoff [expr {$xoff + $mainWidth}]
- if {[expr {$itsXoff + $itsWidth}] > [screenwidth]} {
- set itsXoff [expr {[screenwidth] - $itsWidth}]
- }
- # puts stderr "right $itsXoff " nonewline
- }
- if {$topRoom > $bottomRoom} {
- set itsYoff [expr {$yoff - $itsHeight}]
- if {$itsYoff < 0} {
- set itsYoff 0
- }
- # puts stderr "top $itsYoff " nonewline
- } else {
- set itsYoff [expr {$yoff + $mainHeight}]
- if {[expr {$itsYoff + $itsHeight}] > [screenheight]} {
- set itsYoff [expr {[screenheight] - $itsHeight}]
- }
- # puts stderr "bottom $itsYoff " nonewline
- }
- }
- { default center } {
- if {[string compare $where center] == 0} {
- set itsXoff [expr {$xoff + ($mainWidth - $itsWidth) / 2}]
- set itsYoff [expr {$yoff + ($mainHeight - $itsHeight) / 2}]
- }
- }
- }
- wm geometry $widget +${itsXoff}+${itsYoff}
- wm deiconify $widget
- }
-
- --
-
- Brent Welch
-