DialogS.tcl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: DialogS.tcl,v 1.5 2004/03/28 02:44:57 hobbs Exp $
  4. #
  5. # DialogS.tcl --
  6. #
  7. #
  8. # Implements the DialogShell widget. It tells the window
  9. # manager that it is a dialog window and should be treated specially.
  10. # The exact treatment depends on the treatment of the window
  11. # manager
  12. #
  13. # Copyright (c) 1994-1996, Expert Interface Technologies
  14. #
  15. # See the file "license.terms" for information on usage and redistribution
  16. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  17. #
  18. tixWidgetClass tixDialogShell {
  19. -superclass tixShell
  20. -classname TixDialogShell
  21. -method {
  22. popdown popup center
  23. }
  24. -flag {
  25. -mapped -minheight -minwidth -parent -transient
  26. }
  27. -static {}
  28. -configspec {
  29. {-mapped mapped Mapped 0}
  30. {-minwidth minWidth MinWidth 0}
  31. {-minheight minHeight MinHeight 0}
  32. {-transient transient Transient true}
  33. {-parent parent Parent ""}
  34. }
  35. }
  36. #----------------------------------------------------------------------
  37. # Construct widget
  38. #----------------------------------------------------------------------
  39. proc tixDialogShell:ConstructWidget {w} {
  40. upvar #0 $w data
  41. tixChainMethod $w ConstructWidget
  42. # Set the title of this shell appropriately
  43. #
  44. if {$data(-title) == ""} {
  45. # dynamically sets the title
  46. #
  47. set data(-title) [winfo name $w]
  48. }
  49. wm title $w $data(-title)
  50. # Set the parent of this dialog shell
  51. #
  52. if {$data(-parent) == ""} {
  53. set data(-parent) [winfo parent $w]
  54. }
  55. # Set the minsize and maxsize of the thing
  56. #
  57. wm minsize $w $data(-minwidth) $data(-minheight)
  58. wm transient $w ""
  59. }
  60. # The next procedures manage the dialog boxes
  61. #
  62. proc tixDialogShell:popup {w {parent ""}} {
  63. upvar #0 $w data
  64. # First update to make sure the boxes are the right size
  65. #
  66. update idletask
  67. # Then we set the position and update
  68. #
  69. # tixDialogShell:center $w $parent
  70. # and now make it visible. Viola! Centered over parent.
  71. #
  72. wm deiconify $w
  73. after idle raise $w
  74. }
  75. # This procedure centers a dialog box over a window making sure that the
  76. # dialog box doesn't appear off the screen
  77. #
  78. # However, if the parent is smaller than this dialog, make this dialog
  79. # appear at parent(x,y) + (20,20)
  80. #
  81. proc tixDialogShell:center {w {parent ""}} {
  82. upvar #0 $w data
  83. # Tell the WM that we'll do this ourselves.
  84. wm sizefrom $w user
  85. wm positionfrom $w user
  86. if {$parent == ""} {
  87. set parent $data(-parent)
  88. }
  89. if {$parent == "" || [catch {set parent [winfo toplevel $parent]}]} {
  90. set parent "."
  91. }
  92. # Where is my parent and what are it's dimensions
  93. #
  94. if {$parent != ""} {
  95. set pargeo [split [wm geometry $parent] "+x"]
  96. set parentW [lindex $pargeo 0]
  97. set parentH [lindex $pargeo 1]
  98. set parx [lindex $pargeo 2]
  99. set pary [lindex $pargeo 3]
  100. if {[string is true -strict $data(-transient)]} {
  101. wm transient $w $parent
  102. }
  103. } else {
  104. set parentW [winfo screenwidth $w]
  105. set parentH [winfo screenheight $w]
  106. set parx 0
  107. set pary 0
  108. set parent [winfo parent $w]
  109. }
  110. # What are is the offset of the virtual window
  111. set vrootx [winfo vrootx $parent]
  112. set vrooty [winfo vrooty $parent]
  113. # What are my dimensions ?
  114. set dialogW [winfo reqwidth $w]
  115. set dialogH [winfo reqheight $w]
  116. if {$dialogW < $parentW-30 || $dialogW < $parentH-30} {
  117. set dialogx [expr {$parx+($parentW-$dialogW)/2+$vrootx}]
  118. set dialogy [expr {$pary+($parentH-$dialogH)/2+$vrooty}]
  119. } else {
  120. # This dialog is too big. Place it at (parentx, parenty) + (20,20)
  121. #
  122. set dialogx [expr {$parx+20+$vrootx}]
  123. set dialogy [expr {$pary+20+$vrooty}]
  124. }
  125. set maxx [expr {[winfo screenwidth $parent] - $dialogW}]
  126. set maxy [expr {[winfo screenheight $parent] - $dialogH}]
  127. # Make sure it doesn't go off screen
  128. #
  129. if {$dialogx < 0} {
  130. set dialogx 0
  131. } else {
  132. if {$dialogx > $maxx} {
  133. set dialogx $maxx
  134. }
  135. }
  136. if {$dialogy < 0} {
  137. set dialogy 0
  138. } else {
  139. if {$dialogy > $maxy} {
  140. set dialogy $maxy
  141. }
  142. }
  143. # set my new position (and dimensions)
  144. #
  145. if {[wm geometry $w] == "1x1+0+0"} {
  146. wm geometry $w ${dialogW}x${dialogH}+${dialogx}+${dialogy}
  147. }
  148. }
  149. proc tixDialogShell:popdown {w args} {
  150. wm withdraw $w
  151. }