DragDrop.tcl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: DragDrop.tcl,v 1.4 2001/12/09 05:04:02 idiscovery Exp $
  4. #
  5. # DragDrop.tcl ---
  6. #
  7. # Implements drag+drop for Tix widgets.
  8. #
  9. # Copyright (c) 1993-1999 Ioi Kim Lam.
  10. # Copyright (c) 2000-2001 Tix Project Group.
  11. #
  12. # See the file "license.terms" for information on usage and redistribution
  13. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14. #
  15. tixClass tixDragDropContext {
  16. -superclass {}
  17. -classname TixDragDropContext
  18. -method {
  19. cget configure drag drop set startdrag
  20. }
  21. -flag {
  22. -command -source
  23. }
  24. -configspec {
  25. {-command ""}
  26. {-source ""}
  27. }
  28. }
  29. proc tixDragDropContext:Constructor {w} {
  30. upvar #0 $w data
  31. }
  32. #----------------------------------------------------------------------
  33. # Private methods
  34. #
  35. #----------------------------------------------------------------------
  36. proc tixDragDropContext:CallCommand {w target command X Y} {
  37. upvar #0 $w data
  38. set x [expr $X-[winfo rootx $target]]
  39. set y [expr $Y-[winfo rooty $target]]
  40. regsub %x $command $x command
  41. regsub %y $command $y command
  42. regsub %X $command $X command
  43. regsub %Y $command $Y command
  44. regsub %W $command $target command
  45. regsub %S $command [list $data(-command)] command
  46. eval $command
  47. }
  48. proc tixDragDropContext:Send {w target event X Y} {
  49. upvar #0 $w data
  50. global tixDrop
  51. foreach tag [tixDropBindTags $target] {
  52. if {[info exists tixDrop($tag,$event)]} {
  53. tixDragDropContext:CallCommand $w $target \
  54. $tixDrop($tag,$event) $X $Y
  55. }
  56. }
  57. }
  58. #----------------------------------------------------------------------
  59. # set --
  60. #
  61. # Set the "small data" of the type supported by the source widget
  62. #----------------------------------------------------------------------
  63. proc tixDragDropContext:set {w type data} {
  64. }
  65. #----------------------------------------------------------------------
  66. # startdrag --
  67. #
  68. # Start the dragging action
  69. #----------------------------------------------------------------------
  70. proc tixDragDropContext:startdrag {w x y} {
  71. upvar #0 $w data
  72. set data(oldTarget) ""
  73. $data(-source) config -cursor "[tix getbitmap drop] black"
  74. tixDragDropContext:drag $w $x $y
  75. }
  76. #----------------------------------------------------------------------
  77. # drag --
  78. #
  79. # Continue the dragging action
  80. #----------------------------------------------------------------------
  81. proc tixDragDropContext:drag {w X Y} {
  82. upvar #0 $w data
  83. global tixDrop
  84. set target [winfo containing -displayof $w $X $Y]
  85. if {$target != $data(oldTarget)} {
  86. if {$data(oldTarget) != ""} {
  87. tixDragDropContext:Send $w $data(oldTarget) <Out> $X $Y
  88. }
  89. if {$target != ""} {
  90. tixDragDropContext:Send $w $target <In> $X $Y
  91. }
  92. set data(oldTarget) $target
  93. }
  94. if {$target != ""} {
  95. tixDragDropContext:Send $w $target <Over> $X $Y
  96. }
  97. }
  98. proc tixDragDropContext:drop {w X Y} {
  99. upvar #0 $w data
  100. global tixDrop
  101. set target [winfo containing -displayof $w $X $Y]
  102. if {$target != ""} {
  103. tixDragDropContext:Send $w $target <Drop> $X $Y
  104. }
  105. if {$data(-source) != ""} {
  106. $data(-source) config -cursor ""
  107. }
  108. set data(-source) ""
  109. }
  110. #----------------------------------------------------------------------
  111. # Public Procedures -- This is NOT a member of the tixDragDropContext
  112. # class!
  113. #
  114. # parameters :
  115. # $w: who wants to start dragging? (currently ignored)
  116. #----------------------------------------------------------------------
  117. proc tixGetDragDropContext {w} {
  118. global tixDD
  119. if {[info exists tixDD]} {
  120. return tixDD
  121. }
  122. return [tixDragDropContext tixDD]
  123. }
  124. proc tixDropBind {w event command} {
  125. global tixDrop
  126. set tixDrop($w) 1
  127. set tixDrop($w,$event) $command
  128. }
  129. proc tixDropBindTags {w args} {
  130. global tixDropTags
  131. if {$args == ""} {
  132. if {[info exists tixDropTags($w)]} {
  133. return $tixDropTags($w)
  134. } else {
  135. return [list [winfo class $w] $w]
  136. }
  137. } else {
  138. set tixDropTags($w) $args
  139. }
  140. }