home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / browstable.tcl < prev    next >
Text File  |  1996-10-10  |  3KB  |  114 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Cadre Technologies Inc.    1996
  4. #
  5. #      File:           @(#)browstable.tcl    /main/hindenburg/4
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)browstable.tcl    /main/hindenburg/4   10 Oct 1996 Copyright 1996 Cadre Technologies Inc.
  10.  
  11. # Start user added include file section
  12. # End user added include file section
  13.  
  14.  
  15. # BrowsView derived class that can calculate the width
  16. # of columns to fit the data in its objects exactly.
  17.  
  18. Class BrowsTable : {BrowsView} {
  19.     method destructor
  20.     constructor
  21.     method setHeaderLabels
  22.     method format
  23.     method removeAllHeaders
  24.     method removeAllObjects
  25. }
  26.  
  27. method BrowsTable::destructor {this} {
  28.     # Start destructor user section
  29.     # End destructor user section
  30. }
  31.  
  32. constructor BrowsTable {class this name} {
  33.     set this [BrowsView::constructor $class $this $name]
  34.     return $this
  35. }
  36.  
  37.  
  38. # Removes all header objects and creates new ones,
  39. # one for each string specified in the list.
  40. #
  41. method BrowsTable::setHeaderLabels {this list} {
  42.     $this removeAllHeaders
  43.     foreach hdr $list {
  44.         BrowsHeader new $this.$hdr -label $hdr
  45.     }
  46. }
  47.  
  48.  
  49. # Examines all objects in this view's objectSet and calculates the
  50. # maximum width foreach column, and stores that width in the
  51. # corresponding header object.
  52. #
  53. method BrowsTable::format {this} {
  54.     set headers [$this headerSet]
  55.     set objects [$this objectSet]
  56.  
  57.     if {[llength $headers] == 0} {
  58.         return 0
  59.     }
  60.  
  61.     set ncols [llength $headers]
  62.     for {set i 0} {$i < $ncols} {incr i} {
  63.         set hdr [lindex $headers $i]
  64.         set max($i) [string length [$hdr label]]
  65.     }
  66.  
  67.     foreach obj $objects {
  68.         set d [concat [list [$obj label]] [$obj details]]
  69.     for {set i 0} {$i < $ncols} {incr i} {
  70.             set l [string length [lindex $d $i]]
  71.  
  72.             # If object has a small icon, add 2 to the first column width.
  73.             #
  74.             if {$i == 0 && [$obj smallIcon] != ""} {
  75.                 incr l 2
  76.             }
  77.  
  78.             if {$l > $max($i)} {
  79.                 set max($i) $l
  80.             }
  81.         }
  82.     }
  83.  
  84.     set n 0
  85.     set i 0
  86.     foreach hdr $headers {
  87.         set m $max($i)
  88.         # add some column separator space
  89.         incr m 2
  90.         $hdr width $m
  91.         incr n $m
  92.         incr i
  93.     }
  94.  
  95.     return $n
  96. }
  97.  
  98.  
  99. # Removes all header objects.
  100. #
  101. method BrowsTable::removeAllHeaders {this} {
  102.     foreach e [$this headerSet] { $e delete }
  103. }
  104.  
  105.  
  106. # Removes all data objects.
  107. #
  108. method BrowsTable::removeAllObjects {this} {
  109.     foreach e [$this objectSet] { $e delete }
  110. }
  111.  
  112. # Do not delete this line -- regeneration end marker
  113.  
  114.