home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 December / PCWorld_2000-12_cd.bin / Komunikace / Comanche / xul / xuiList.tcl < prev    next >
Text File  |  2000-11-02  |  2KB  |  95 lines

  1.  
  2. class xuiList {
  3.     inherit xuiObject
  4.     variable children {}
  5.     variable prototype {}
  6.     constructor {} { 
  7.     setXuiClass list
  8.     }
  9.     destructor {
  10.     delete object $prototype
  11.     eval delete object $children
  12.     }
  13.     method setPrototype { xuiObject }
  14.     method getPrototype { } { return $prototype }
  15.     method getChildren {}
  16.     method getChildrenByName {name}
  17.     method newChild {}
  18.     method deleteChild { xuiObject }
  19.  
  20.     
  21.     method clear {} { foreach child $children { $this deleteChild $child} }
  22.     method insertChild { xuiObject {position {}}}
  23.     method replaceChild { oldChild newChild}
  24.     method getText {}
  25.     method clone 
  26.     method copyClone { clone }
  27.     method reset {}
  28. }
  29.      
  30. body xuiList::reset {} {
  31.     clear
  32. }
  33.  
  34. body xuiList::clone {{parentName {::#auto}}} {
  35.    set clone [xuiList $parentName.$name]
  36.    copyClone $clone
  37.    return $clone
  38. }
  39.  
  40. body xuiList::copyClone {clone} {
  41.    xuiObject::copyClone $clone
  42.    $clone clear
  43.    $clone setPrototype [ $prototype clone ]
  44.    foreach child [getChildren] {
  45.       $clone insertChild [$child clone]
  46.    }
  47.    $clone setXuiClass $xuiClass
  48. }
  49.  
  50. body xuiList::setPrototype { xuiObject } {
  51.     set prototype $xuiObject
  52. }
  53.  
  54. body xuiList::getChildren {} {
  55.     return $children
  56. }
  57.  
  58. body xuiList::getChildrenByName { name } {
  59.     set result {}
  60.     foreach one $children {
  61.        if ![string compare [$one getName] $name] {
  62.            lappend result $one
  63.        }
  64.     }
  65.     return $result
  66. }
  67.  
  68. body xuiList::newChild {} {
  69.     return [$prototype clone]
  70. }
  71.  
  72. body xuiList::deleteChild { xuiObject } {
  73.     delete object $xuiObject
  74.     set pos [lsearch -exact $children $xuiObject]
  75.     set children [lreplace $children $pos $pos]
  76. }
  77.  
  78. body xuiList::insertChild { xuiObject {position {}}} {
  79.     lappend children $xuiObject
  80. }
  81.  
  82. body xuiList::getText {} {
  83.     set result {}
  84.     foreach item $children {
  85.     append result " [$item getText]"
  86.     }
  87.     return $result
  88. }
  89.  
  90. body xuiList::replaceChild { oldChild newChild } {
  91.     set pos [lsearch -exact $children $oldChild]
  92.     set children [lreplace $children $pos $pos $newChild]
  93. }
  94.  
  95.