home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / Texte / scribus / scribus-1.3.3.9-win32-install.exe / tcl / tix8.1 / DragDrop.tcl < prev    next >
Text File  |  2001-11-03  |  4KB  |  167 lines

  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #    $Id: DragDrop.tcl,v 1.3.2.1 2001/11/03 06:43:50 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.  
  16. tixClass tixDragDropContext {
  17.     -superclass {}
  18.     -classname  TixDragDropContext
  19.     -method {
  20.     cget configure drag drop set startdrag
  21.     }
  22.     -flag {
  23.     -command -source
  24.     }
  25.     -configspec {
  26.     {-command ""}
  27.     {-source ""}
  28.     }
  29. }
  30.  
  31. proc tixDragDropContext:Constructor {w} {
  32.     upvar #0 $w data
  33. }
  34.  
  35. #----------------------------------------------------------------------
  36. # Private methods
  37. #
  38. #----------------------------------------------------------------------
  39. proc tixDragDropContext:CallCommand {w target command X Y} {
  40.     upvar #0 $w data
  41.      
  42.     set x [expr $X-[winfo rootx $target]]
  43.     set y [expr $Y-[winfo rooty $target]]
  44.     
  45.     regsub %x $command $x command
  46.     regsub %y $command $y command
  47.     regsub %X $command $X command
  48.     regsub %Y $command $Y command
  49.     regsub %W $command $target command
  50.     regsub %S $command [list $data(-command)] command
  51.  
  52.     eval $command
  53. }
  54.  
  55. proc tixDragDropContext:Send {w target event X Y} {
  56.     upvar #0 $w data
  57.     global tixDrop
  58.  
  59.     foreach tag [tixDropBindTags $target] {
  60.     if {[info exists tixDrop($tag,$event)]} {
  61.         tixDragDropContext:CallCommand $w $target \
  62.         $tixDrop($tag,$event) $X $Y
  63.     }
  64.     }
  65. }
  66.  
  67. #----------------------------------------------------------------------
  68. # set --
  69. #
  70. #    Set the "small data" of the type supported by the source widget
  71. #----------------------------------------------------------------------
  72.  
  73. proc tixDragDropContext:set {w type data} {
  74.  
  75. }
  76.  
  77. #----------------------------------------------------------------------
  78. # startdrag --
  79. #
  80. #    Start the dragging action
  81. #----------------------------------------------------------------------
  82. proc tixDragDropContext:startdrag {w x y} {
  83.     upvar #0 $w data
  84.  
  85.     set data(oldTarget) ""
  86.  
  87.     $data(-source) config -cursor "[tix getbitmap drop] black"
  88.     tixDragDropContext:drag $w $x $y
  89. }
  90.  
  91. #----------------------------------------------------------------------
  92. # drag --
  93. #
  94. #    Continue the dragging action
  95. #----------------------------------------------------------------------
  96. proc tixDragDropContext:drag {w X Y} {
  97.     upvar #0 $w data
  98.     global tixDrop
  99.  
  100.     set target [winfo containing -displayof $w $X $Y]
  101.  
  102.     if {$target != $data(oldTarget)} {
  103.     if {$data(oldTarget) != ""} {
  104.         tixDragDropContext:Send $w $data(oldTarget) <Out> $X $Y 
  105.     }
  106.     if {$target != ""} {
  107.         tixDragDropContext:Send $w $target <In> $X $Y
  108.     }
  109.     set data(oldTarget) $target
  110.     }
  111.     if {$target != ""} {
  112.     tixDragDropContext:Send $w $target <Over> $X $Y
  113.     }
  114. }
  115.  
  116. proc tixDragDropContext:drop {w X Y} {
  117.     upvar #0 $w data
  118.     global tixDrop
  119.  
  120.     set target [winfo containing -displayof $w $X $Y]
  121.     if {$target != ""} {
  122.     tixDragDropContext:Send $w $target <Drop> $X $Y
  123.     }
  124.  
  125.     if {$data(-source) != ""} {
  126.     $data(-source) config -cursor ""
  127.     }
  128.     set data(-source) ""
  129. }
  130.  
  131. #----------------------------------------------------------------------
  132. # Public Procedures -- This is NOT a member of the tixDragDropContext
  133. #               class!
  134. #
  135. # parameters :
  136. #    $w:    who wants to start dragging? (currently ignored)
  137. #----------------------------------------------------------------------
  138. proc tixGetDragDropContext {w} {
  139.     global tixDD
  140.     if {[info exists tixDD]} {
  141.     return tixDD
  142.     }
  143.  
  144.     return [tixDragDropContext tixDD]
  145. }
  146.  
  147. proc tixDropBind {w event command} {
  148.     global tixDrop
  149.  
  150.     set tixDrop($w) 1
  151.     set tixDrop($w,$event) $command
  152. }
  153.  
  154. proc tixDropBindTags {w args} {
  155.     global tixDropTags
  156.  
  157.     if {$args == ""} {
  158.     if {[info exists tixDropTags($w)]} {
  159.         return $tixDropTags($w)
  160.     } else {
  161.         return [list [winfo class $w] $w]
  162.     }
  163.     } else {
  164.     set tixDropTags($w) $args
  165.     }
  166. }
  167.