home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!dv2t1!shmdgljd
- From: shmdgljd@rchland.vnet.ibm.com (Jay Schmidgall)
- Subject: Re: Motif-like message/error/warning dialogs
- Sender: news@rchland.ibm.com
- Message-ID: <1992Sep01.140451.19406@rchland.ibm.com>
- Date: Tue, 01 Sep 1992 14:04:51 GMT
- Reply-To: jay@vnet.ibm.com
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- References: <1992Aug31.204753.2556@twg.com>
- Nntp-Posting-Host: dv2t1.rchland.ibm.com
- Organization: IBM Rochester, MN
- Lines: 104
-
- Here's a quickie patch to the msgdialog script to make the dialog more
- like Motif's in that it is transient and grouped with the parent. This
- lets it duplicate Motif's dialog box behavior of iconifying the dialog
- when the parent is iconified. It also causes the parent to be raised
- when the dialog box is popped. (of course, this is all under mwm -- no
- idea what other wm's will do). I've also include a DLG:position proc
- which centers the dialog box over the parent.
-
- ../src/Tk> diff -c msgdialog.tk.old msgdialog.tk
- *** msgdialog.tk.old Tue Sep 1 08:54:17 1992
- --- msgdialog.tk Tue Sep 1 08:55:10 1992
- ***************
- *** 66,80 ****
- global $done
- set $done 0
-
- - set px [winfo x $parent]
- - set py [winfo y $parent]
- - set ph [winfo screenheight $parent]
- - set pw [winfo screenwidth $parent]
- -
- toplevel $w -class Dialog
- - wm geometry $w +[expr $px+($pw/3)]+[expr $py+($ph/3)]
- - wm minsize $w 1 1
-
- # wm raise $parent -- Motif does this but TK doesn't have the command.
-
- frame $w.msg
- --- 66,79 ----
- global $done
- set $done 0
-
- toplevel $w -class Dialog
-
- + # Lets the dialog window be handled like Motif dialogs by the WM
- + wm group $w $parent
- + wm transient $w $parent
- +
- + # This is unnecessary (at least under mwm) since the above
- + # causes parent to be raised when the dialog becomes visible.
- # wm raise $parent -- Motif does this but TK doesn't have the command.
-
- frame $w.msg
- ***************
- *** 152,158 ****
- --- 151,168 ----
- # DLG:keybindings $w.cmds.f.f.f3.btn3 "[lindex $btn3 1]"
- }
-
- + # The withdraw/update sequence allows $w's width, etc. to be set
- + # without becoming visible.
- + wm withdraw $w
- update
- + # Then we set the position
- + DLG:position $parent $w
- + # Let the new position by updated
- + update
- + # and now make it visible. Viola! Centered over the parent.
- + # What a kluge, though. :(.
- + wm deiconify $w
- +
- grab $w
- tkwait variable $done
- grab
- ***************
- *** 159,164 ****
- --- 169,200 ----
- destroy $w
-
- return "[set $done]"
- + }
- +
- + proc DLG:position {parent dialog} {
- + # Tell the WM that we'll do this ourselves.
- + wm sizefrom $dialog user
- + wm positionfrom $dialog user
- +
- + # Where is my parent and what are it's dimensions
- + set pargeo [split [wm geometry $parent] "+x"]
- + set parwidth [lindex $pargeo 0]
- + set parheight [lindex $pargeo 1]
- + set parx [lindex $pargeo 2]
- + set pary [lindex $pargeo 3]
- +
- + # What are my dimensions ?
- + set dialoggeo [split [wm geometry $dialog] "+x"]
- + set dialogwidth [lindex $dialoggeo 0]
- + set dialogheight [lindex $dialoggeo 1]
- +
- + # Build my new position (and dimensions)
- + set geo [ format "%dx%d+%d+%d" $dialogwidth $dialogheight \
- + [expr $parx+($parwidth-$dialogwidth)/2] \
- + [expr $pary+($parheight-$dialogheight)/2] ]
- +
- + # And set it
- + wm geometry $dialog $geo
- }
-
- # Future expansion: For when we are able to do keyboard focus and
- ../src/Tk>
-
- --
- : jay jay@vnet.ibm.com My opinions and ideas, not my employer's.
-
-