home *** CD-ROM | disk | FTP | other *** search
/ PC World 1997 November / PCWorld_1997-11_cd.bin / software / programy / komix / DATA.Z / browsviewd.tcl < prev    next >
Text File  |  1996-05-29  |  4KB  |  161 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. #      (c)     Westmount Technology    1994
  4. #
  5. #      File:           @(#)browsviewd.tcl    1.6
  6. #      Author:         <generated>
  7. #      Description:
  8. #---------------------------------------------------------------------------
  9. # SccsId = @(#)browsviewd.tcl    1.6   11 Jan 1996 Copyright 1994 Westmount Technology
  10.  
  11. # Start user added include file section
  12. require "dlgbrowsob.tcl"
  13. require "wmt_util.tcl"
  14. # End user added include file section
  15.  
  16.  
  17. Class BrowsViewDialog : {TemplateDialog} {
  18.     constructor
  19.     method destructor
  20.     method display
  21.     method handleHelp
  22.     method handleSelectionChanged
  23.     method popUp
  24.     method sort
  25.     method view
  26.     attribute objectSpecList
  27.     attribute headerSpecList
  28.     attribute objectList
  29.     attribute message
  30. }
  31.  
  32. constructor BrowsViewDialog {class this name} {
  33.     set this [TemplateDialog::constructor $class $this $name]
  34.     # Start constructor user section
  35.  
  36.     interface DlgColumn $this.top {
  37.         Label message {}
  38.         BrowsView view {
  39.         rowCount 5
  40.         mode DETAIL
  41.         selectionPolicy EXTENDED
  42.         }
  43.     }
  44.     $this config \
  45.         -modal yes \
  46.         -helpPressed "$this handleHelp"
  47.     [$this view] selectionChanged "$this handleSelectionChanged"
  48.  
  49.     # End constructor user section
  50.     return $this
  51. }
  52.  
  53. method BrowsViewDialog::destructor {this} {
  54.     # Start destructor user section
  55.     # End destructor user section
  56. }
  57.  
  58. method BrowsViewDialog::display {this} {
  59.     $this.top.message text [$this message]
  60.  
  61.     # clear the view
  62.     foreach object [[$this view] objectSet] {
  63.     $object delete
  64.     }
  65.     foreach header [[$this view] headerSet] {
  66.     $header delete
  67.     }
  68.  
  69.     # create headers
  70.     set count 0
  71.     set columnCount 0
  72.     foreach headerSpec [$this headerSpecList] {
  73.     BrowsHeader new [$this view].header$count \
  74.         -label "[lindex $headerSpec 0]" \
  75.         -width [lindex $headerSpec 1]
  76.     if {$count < 2} {
  77.         incr columnCount [lindex $headerSpec 1]
  78.     }
  79.     incr count 1
  80.     }
  81.     [$this view] columnCount $columnCount
  82.  
  83.     #create objects
  84.     set count 0
  85.     foreach objectSpec [$this objectSpecList] {
  86.     set dlgBrowsObject [$this view].object$count
  87.     DlgBrowsObject new $dlgBrowsObject \
  88.         -object [lindex [$this objectList] $count] \
  89.         -label [lindex $objectSpec 1] \
  90.         -details [lrange $objectSpec 2 end] \
  91.         -activated "$this popDown; eval \[$this okPressed\]"
  92.     if {"[lindex $objectSpec 0]" != ""} {
  93.         $dlgBrowsObject smallIcon [lindex $objectSpec 0]
  94.     }
  95.     incr count 1
  96.     }
  97.  
  98.     $this sort
  99. }
  100.  
  101. method BrowsViewDialog::handleHelp {this} {
  102.     [getParent $this] helpOnName [nt_get_type $this]
  103. }
  104.  
  105. method BrowsViewDialog::handleSelectionChanged {this} {
  106.     if {[llength [[$this view] selectedSet]] == 0} {
  107.     set selected 0
  108.     } else {
  109.     set selected 1
  110.     }
  111.     $this okSensitive $selected
  112.     $this okDefault $selected
  113.     $this cancelDefault [expr 1 - $selected]
  114. }
  115.  
  116. method BrowsViewDialog::popUp {this} {
  117.     $this display
  118.  
  119.     $this handleSelectionChanged
  120.     $this TemplateDialog::popUp
  121. }
  122.  
  123. method BrowsViewDialog::sort {this} {
  124.     if [lempty [[$this view] objectSet]] {
  125.     return
  126.     }
  127.  
  128.     set count -1
  129.     foreach headerSpec [$this headerSpecList] {
  130.     incr count 1
  131.     if {[llength $headerSpec] < 4} continue
  132.     set type [lindex $headerSpec 2]
  133.     set sortPolicy [lindex [lindex $headerSpec 3] 0]
  134.     if {"$sortPolicy" == "" || "$sortPolicy" == "none"} continue
  135.     set index [lindex [lindex $headerSpec 3] 1]
  136.     if {"$index" == "" || $index < 1} continue
  137.     set sortSpec($index) \
  138.         "-column {[$this view].header$count $type $sortPolicy}"
  139.     }
  140.  
  141.     set sortSpecList ""
  142.     if {! [catch {set indices [lsort -integer [array names sortSpec]]}]} {
  143.     foreach index $indices {
  144.         append sortSpecList " $sortSpec($index)"
  145.     }
  146.     }
  147.  
  148.     if [lempty $sortSpecList] {
  149.     return
  150.     }
  151.  
  152.     eval [$this view] sort $sortSpecList
  153. }
  154.  
  155. method BrowsViewDialog::view {this} {
  156.     return $this.top.view
  157. }
  158.  
  159. # Do not delete this line -- regeneration end marker
  160.  
  161.