File: ts_notebook.tcl

package info (click to toggle)
ts 9902p1-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,252 kB
  • ctags: 1,271
  • sloc: tcl: 5,638; sh: 129; makefile: 40
file content (63 lines) | stat: -rw-r--r-- 1,345 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# ts_notebook.tcl
# Derived from Harrison/McLennan

proc notebook_create {w} {
  global nbInfo

  set nbInfo($w-count) 0
  set nbInfo($w-current) ""
  set nbInfo($w-pages) ""
  frame $w
  pack propagate $w 0
}

proc notebook_page {w name} {
  global nbInfo

  set page "$w.page[incr nbInfo($w-count)]"
  lappend nbInfo($w-pages) $page
  set nbInfo($w-page-$name) $page
  frame $page
  if {$nbInfo($w-count) == 1} {
    after idle [list notebook_display $w $name]
  }
  return $page
}

proc notebook_display {w name} {
  global nbInfo

  set page ""
  if {[info exists nbInfo($w-page-$name)]} {
    set page $nbInfo($w-page-$name)
  } elseif {[winfo exists $w.page$name]} {
    set page $w.page$name
  }
  if {$page == ""} {
    error "bad notebook page \"$name\""
  }
  notebook_fix_size $w
  if {$nbInfo($w-current) != ""} {
    pack forget $nbInfo($w-current)
  }
  pack $page -expand yes -fill both
  set nbInfo($w-current) $page
}

proc notebook_fix_size {win} {
  global nbInfo

  update idletasks
  set wmax 0
  set hmax 0
  foreach page $nbInfo($win-pages) {
    set w [winfo reqwidth $page]
    set h [winfo reqheight $page]
    if {$w > $wmax} {set wmax $w}
    if {$h > $hmax} {set hmax $h}
  }
  set bd [$win cget -borderwidth]
  set wmax [expr $wmax+2*$bd]
  set hmax [expr $hmax+2*$bd]
  $win configure -width $wmax -height $hmax
}