home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 December / PCWorld_2000-12_cd.bin / Komunikace / Comanche / BWidget-1.2 / notebook.tcl < prev    next >
Text File  |  2000-11-02  |  29KB  |  843 lines

  1. # ------------------------------------------------------------------------------
  2. #  notebook.tcl
  3. #  This file is part of Unifix BWidget Toolkit
  4. #  $Id: notebook.tcl,v 1.1.1.1 1996/02/22 06:05:56 daniel Exp $
  5. # ------------------------------------------------------------------------------
  6. #  Index of commands:
  7. #     - NoteBook::create
  8. #     - NoteBook::configure
  9. #     - NoteBook::cget
  10. #     - NoteBook::compute_size
  11. #     - NoteBook::insert
  12. #     - NoteBook::delete
  13. #     - NoteBook::itemconfigure
  14. #     - NoteBook::itemcget
  15. #     - NoteBook::raise
  16. #     - NoteBook::see
  17. #     - NoteBook::page
  18. #     - NoteBook::pages
  19. #     - NoteBook::index
  20. #     - NoteBook::getframe
  21. #     - NoteBook::_test_page
  22. #     - NoteBook::_itemconfigure
  23. #     - NoteBook::_compute_width
  24. #     - NoteBook::_get_x_page
  25. #     - NoteBook::_xview
  26. #     - NoteBook::_highlight
  27. #     - NoteBook::_select
  28. #     - NoteBook::_redraw
  29. #     - NoteBook::_draw_page
  30. #     - NoteBook::_draw_arrows
  31. #     - NoteBook::_draw_area
  32. #     - NoteBook::_resize
  33. #     - NoteBook::_realize
  34. # ------------------------------------------------------------------------------
  35.  
  36. namespace eval NoteBook {
  37.     ArrowButton::use
  38.  
  39.     namespace eval Page {
  40.         Widget::declare NoteBook::Page {
  41.             {-state      Enum       normal 0 {normal disabled}}
  42.             {-createcmd  String     ""     0}
  43.             {-raisecmd   String     ""     0}
  44.             {-leavecmd   String     ""     0}
  45.             {-image      TkResource ""     0 label}
  46.             {-text       String     ""     0}
  47.         }
  48.     }
  49.  
  50.     Widget::declare NoteBook {
  51.         {-foreground         TkResource "" 0 button}
  52.         {-background         TkResource "" 0 button}
  53.         {-activebackground   TkResource "" 0 button}
  54.         {-activeforeground   TkResource "" 0 button}
  55.         {-disabledforeground TkResource "" 0 button}
  56.         {-font               TkResource "" 0 button}
  57.         {-side               Enum       top 1 {top bottom}}
  58.         {-homogeneous        Boolean 0   0}
  59.         {-borderwidth        Int 1   0 {=1 =2}}
  60.         {-width              Int 0   0 {=0 ""}}
  61.         {-height             Int 0   0 {=0 ""}}
  62.  
  63.         {-repeatdelay        BwResource ""  0 ArrowButton}
  64.         {-repeatinterval     BwResource ""  0 ArrowButton}
  65.  
  66.         {-fg                 Synonym -foreground}
  67.         {-bg                 Synonym -background}
  68.         {-bd                 Synonym -borderwidth}
  69.     }
  70.  
  71.     Widget::addmap NoteBook "" :cmd {-background {}}
  72.     Widget::addmap NoteBook ArrowButton .fg \
  73.         {-foreground {} -background {} -activeforeground {} -activebackground {} \
  74.              -borderwidth {} -repeatinterval {} -repeatdelay {} -disabledforeground {}}
  75.     Widget::addmap NoteBook ArrowButton .fd \
  76.         {-foreground {} -background {} -activeforeground {} -activebackground {} \
  77.              -borderwidth {} -repeatinterval {} -repeatdelay {} -disabledforeground {}}
  78.  
  79.     variable _warrow 12
  80.  
  81.     proc ::NoteBook { path args } { return [eval NoteBook::create $path $args] }
  82.     proc use {} {}
  83. }
  84.  
  85.  
  86. # ------------------------------------------------------------------------------
  87. #  Command NoteBook::create
  88. # ------------------------------------------------------------------------------
  89. proc NoteBook::create { path args } {
  90.     variable $path
  91.     upvar 0  $path data
  92.  
  93.     Widget::init NoteBook $path $args
  94.  
  95.     set data(base)     0
  96.     set data(select)   ""
  97.     set data(pages)    {}
  98.     set data(pages)    {}
  99.     set data(cpt)      0
  100.     set data(realized) 0
  101.     set data(wpage)    0
  102.     set data(hpage)    [expr {[font metrics [Widget::getoption $path -font] -linespace] + 6}]
  103.     set bg             [Widget::getoption $path -background]
  104.  
  105.     # --- creation du canvas -----------------------------------------------------------------
  106.     set w [expr {[Widget::getoption $path -width]+4}]
  107.     set h [expr {[Widget::getoption $path -height]+$data(hpage)+4}]
  108.     canvas $path -relief flat -bd 0 -highlightthickness 0 -bg $bg -width $w -height $h
  109.  
  110.     # --- creation des arrow -----------------------------------------------------------------
  111.     eval ArrowButton::create $path.fg [Widget::subcget $path .fg] \
  112.         -highlightthickness 0 \
  113.         -type button  -dir left \
  114.         -armcommand [list "NoteBook::_xview $path -1"]
  115.  
  116.     eval ArrowButton::create $path.fd [Widget::subcget $path .fd] \
  117.         -highlightthickness 0 \
  118.         -type button  -dir right \
  119.         -armcommand [list "NoteBook::_xview $path 1"]
  120.  
  121.     set col       [BWidget::get3dcolor $path $bg]
  122.     set data(dbg) [lindex $col 0]
  123.     set data(lbg) [lindex $col 1]
  124.  
  125.     bind $path <Configure> "NoteBook::_realize $path"
  126.     bind $path <Destroy>   "NoteBook::_destroy $path"
  127.  
  128.     rename $path ::$path:cmd
  129.     proc ::$path { cmd args } "return \[eval NoteBook::\$cmd $path \$args\]"
  130.  
  131.     return $path
  132. }
  133.  
  134.  
  135. # ------------------------------------------------------------------------------
  136. #  Command NoteBook::configure
  137. # ------------------------------------------------------------------------------
  138. proc NoteBook::configure { path args } {
  139.     variable $path
  140.     upvar 0  $path data
  141.  
  142.     set res [Widget::configure $path $args]
  143.     set redraw 0
  144.     if { [set chf [Widget::hasChanged $path -font font]] ||
  145.          [Widget::hasChanged $path -homogeneous foo] } {
  146.         if { $chf } {
  147.             set data(hpage) [expr {[font metrics $font -linespace] + 6}]
  148.         }
  149.         _compute_width $path
  150.         set redraw 1
  151.     }
  152.     if { [Widget::hasChanged $path -background bg] } {
  153.         set col [BWidget::get3dcolor $path $bg]
  154.         set data(dbg)  [lindex $col 0]
  155.         set data(lbg)  [lindex $col 1]
  156.         set redraw 1
  157.     }
  158.     if { [Widget::hasChanged $path -foreground  fg] ||
  159.          [Widget::hasChanged $path -borderwidth bd] } {
  160.         set redraw 1
  161.     }
  162.     set wc [Widget::hasChanged $path -width  w]
  163.     set hc [Widget::hasChanged $path -height h]
  164.     if { $wc || $hc } {
  165.         $path:cmd configure -width [expr {$w+2}] -height [expr {$h + $data(hpage)+2}]
  166.     } elseif { $redraw } {
  167.         _redraw $path
  168.     }
  169.  
  170.     return $res
  171. }
  172.  
  173.  
  174. # ------------------------------------------------------------------------------
  175. #  Command NoteBook::cget
  176. # ------------------------------------------------------------------------------
  177. proc NoteBook::cget { path option } {
  178.     return [Widget::cget $path $option]
  179. }
  180.  
  181.  
  182. # ------------------------------------------------------------------------------
  183. #  Command NoteBook::compute_size
  184. # ------------------------------------------------------------------------------
  185. proc NoteBook::compute_size { path } {
  186.     variable $path
  187.     upvar 0  $path data
  188.  
  189.     set wmax 0
  190.     set hmax 0
  191.     update idletasks
  192.     foreach page $data(pages) {
  193.         set w    [winfo reqwidth  $path.f$page]
  194.         set h    [winfo reqheight $path.f$page]
  195.         set wmax [expr {$w>$wmax ? $w : $wmax}]
  196.         set hmax [expr {$h>$hmax ? $h : $hmax}]
  197.     }
  198.     configure $path -width $wmax -height $hmax
  199. }
  200.  
  201.  
  202. # ------------------------------------------------------------------------------
  203. #  Command NoteBook::insert
  204. # ------------------------------------------------------------------------------
  205. proc NoteBook::insert { path index page args } {
  206.     variable $path
  207.     upvar 0  $path data
  208.  
  209.     if { [lsearch $data(pages) $page] != -1 } {
  210.         return -code error "page \"$page\" already exists"
  211.     }
  212.  
  213.     Widget::init NoteBook::Page $path.f$page $args
  214.  
  215.     set data(pages) [linsert $data(pages) $index $page]
  216.     if { ![winfo exists $path.f$page] } {
  217.         frame $path.f$page \
  218.             -relief flat -background [Widget::getoption $path -background] -borderwidth 10
  219.         set data($page,realized) 0
  220.     }
  221.     _compute_width $path
  222.     _draw_page $path $page 1
  223.     _redraw $path
  224.  
  225.     return $path.f$page
  226. }
  227.  
  228.  
  229. # ------------------------------------------------------------------------------
  230. #  Command NoteBook::delete
  231. # ------------------------------------------------------------------------------
  232. proc NoteBook::delete { path page {destroyframe 1} } {
  233.     variable $path
  234.     upvar 0  $path data
  235.  
  236.     set pos [_test_page $path $page]
  237.     set data(pages) [lreplace $data(pages) $pos $pos]
  238.     _compute_width $path
  239.     $path:cmd delete p:$page
  240.     if { $data(select) == $page } {
  241.         set data(select) ""
  242.     }
  243.     if { $pos < $data(base) } {
  244.         incr data(base) -1
  245.     }
  246.     if { $destroyframe } {
  247.         destroy $path.f$page
  248.     }
  249.     _redraw $path
  250. }
  251.  
  252.  
  253. # ------------------------------------------------------------------------------
  254. #  Command NoteBook::itemconfigure
  255. # ------------------------------------------------------------------------------
  256. proc NoteBook::itemconfigure { path page args } {
  257.     _test_page $path $page
  258.     _itemconfigure $path $page $args
  259.     _redraw $path
  260. }
  261.  
  262.  
  263. # ------------------------------------------------------------------------------
  264. #  Command NoteBook::itemcget
  265. # ------------------------------------------------------------------------------
  266. proc NoteBook::itemcget { path page option } {
  267.     _test_page $path $page
  268.     return [Widget::cget $path.f$page $option]
  269. }
  270.  
  271.  
  272. # ------------------------------------------------------------------------------
  273. #  Command NoteBook::move
  274. # ------------------------------------------------------------------------------
  275. proc NoteBook::move { path page index } {
  276.     variable $path
  277.     upvar 0  $path data
  278.  
  279.     set pos [_test_page $path $page]
  280.     set data(pages) [linsert [lreplace $data(pages) $pos $pos] $index $page]
  281.     _redraw $path
  282. }
  283.  
  284.  
  285. # ------------------------------------------------------------------------------
  286. #  Command NoteBook::raise
  287. # ------------------------------------------------------------------------------
  288. proc NoteBook::raise { path {page ""} } {
  289.     variable $path
  290.     upvar 0  $path data
  291.  
  292.     if { $page != "" } {
  293.         _test_page $path $page
  294.         _select $path $page
  295.     }
  296.     return $data(select)
  297. }
  298.  
  299.  
  300. # ------------------------------------------------------------------------------
  301. #  Command NoteBook::see
  302. # ------------------------------------------------------------------------------
  303. proc NoteBook::see { path page } {
  304.     variable $path
  305.     upvar 0  $path data
  306.  
  307.     set pos [_test_page $path $page]
  308.     if { $pos < $data(base) } {
  309.         set data(base) $pos
  310.         _redraw $path
  311.     } else {
  312.         set w     [expr {[winfo width $path]-1}]
  313.         set fpage [expr {[_get_x_page $path $pos] + $data($page,width) + 6}]
  314.         set idx   $data(base)
  315.         while { $idx < $pos && $fpage > $w } {
  316.             set fpage [expr {$fpage - $data([lindex $data(pages) $idx],width)}]
  317.             incr idx
  318.         }
  319.         if { $idx != $data(base) } {
  320.             set data(base) $idx
  321.             _redraw $path
  322.         }
  323.     }
  324. }
  325.  
  326.  
  327. # ------------------------------------------------------------------------------
  328. #  Command NoteBook::page
  329. # ------------------------------------------------------------------------------
  330. proc NoteBook::page { path first {last ""} } {
  331.     variable $path
  332.     upvar 0  $path data
  333.  
  334.     if { $last == "" } {
  335.         return [lindex $data(pages) $first]
  336.     } else {
  337.         return [lrange $data(pages) $first $last]
  338.     }
  339. }
  340.  
  341.  
  342. # ------------------------------------------------------------------------------
  343. #  Command NoteBook::pages
  344. # ------------------------------------------------------------------------------
  345. proc NoteBook::pages { path } {
  346.     variable $path
  347.     upvar 0  $path data
  348.  
  349.     return $data(pages)
  350. }
  351.  
  352.  
  353. # ------------------------------------------------------------------------------
  354. #  Command NoteBook::index
  355. # ------------------------------------------------------------------------------
  356. proc NoteBook::index { path page } {
  357.     variable $path
  358.     upvar 0  $path data
  359.  
  360.     return [lsearch $data(pages) $page]
  361. }
  362.  
  363.  
  364. # ------------------------------------------------------------------------------
  365. #  Command NoteBook::_destroy
  366. # ------------------------------------------------------------------------------
  367. proc NoteBook::_destroy { path } {
  368.     variable $path
  369.     upvar 0  $path data
  370.  
  371.     foreach page $data(pages) {
  372.         Widget::destroy $path.f$page
  373.     }
  374.     Widget::destroy $path
  375.     unset data
  376.     rename $path {}
  377. }
  378.  
  379.  
  380. # ------------------------------------------------------------------------------
  381. #  Command NoteBook::getframe
  382. # ------------------------------------------------------------------------------
  383. proc NoteBook::getframe { path page } {
  384.     return $path.f$page
  385. }
  386.  
  387.  
  388. # ------------------------------------------------------------------------------
  389. #  Command NoteBook::_test_page
  390. # ------------------------------------------------------------------------------
  391. proc NoteBook::_test_page { path page } {
  392.     variable $path
  393.     upvar 0  $path data
  394.  
  395.     if { [set pos [lsearch $data(pages) $page]] == -1 } {
  396.         return -code error "page \"$page\" does not exists"
  397.     }
  398.     return $pos
  399. }
  400.  
  401.  
  402. # ------------------------------------------------------------------------------
  403. #  Command NoteBook::_itemconfigure
  404. # ------------------------------------------------------------------------------
  405. proc NoteBook::_itemconfigure { path page lres } {
  406.     variable $path
  407.     upvar 0  $path data
  408.  
  409.     set res [Widget::configure $path.f$page $lres]
  410.     if { [Widget::hasChanged $path.f$page -text foo] } {
  411.         _compute_width $path
  412.     } elseif  { [Widget::hasChanged $path.f$page -image foo] } {
  413.         set data(hpage) [expr {[font metrics [Widget::getoption $path -font] -linespace] + 6}]
  414.         _compute_width $path
  415.     }
  416.     if { [Widget::hasChanged $path.f$page -state state] &&
  417.          $state == "disabled" && $data(select) == $page } {
  418.         set data(select) ""
  419.     }
  420.     return $res
  421. }
  422.  
  423.  
  424. # ------------------------------------------------------------------------------
  425. #  Command NoteBook::_compute_width
  426. # ------------------------------------------------------------------------------
  427. proc NoteBook::_compute_width { path } {
  428.     variable $path
  429.     upvar 0  $path data
  430.  
  431.     set font [Widget::getoption $path -font]
  432.     set wmax 0
  433.     set hmax $data(hpage)
  434.     set wtot 0
  435.     if { ![info exists data(textid)] } {
  436.         set data(textid) [$path:cmd create text 0 -100 -font [Widget::getoption $path -font] -anchor nw]
  437.     }
  438.     set id $data(textid)
  439.     $path:cmd itemconfigure $id -font [Widget::getoption $path -font]
  440.     foreach page $data(pages) {
  441.         $path:cmd itemconfigure $id -text [Widget::getoption $path.f$page -text]
  442.         set  wtext [expr {[lindex [$path:cmd bbox $id] 2]+20}]
  443.         if { [set img [Widget::getoption $path.f$page -image]] != "" } {
  444.             set wtext [expr {$wtext+[image width $img]+4}]
  445.             set himg  [expr {[image height $img]+6}]
  446.             if { $himg > $hmax } {
  447.                 set hmax $himg
  448.             }
  449.         }
  450.         set  wmax  [expr {$wtext>$wmax ? $wtext : $wmax}]
  451.         incr wtot  $wtext
  452.         set  data($page,width) $wtext
  453.     }
  454.     if { [Widget::getoption $path -homogeneous] } {
  455.         foreach page $data(pages) {
  456.             set data($page,width) $wmax
  457.         }
  458.         set wtot [expr {$wmax * [llength $data(pages)]}]
  459.     }
  460.     set data(hpage) $hmax
  461.     set data(wpage) $wtot
  462. }
  463.  
  464.  
  465. # ------------------------------------------------------------------------------
  466. #  Command NoteBook::_get_x_page
  467. # ------------------------------------------------------------------------------
  468. proc NoteBook::_get_x_page { path pos } {
  469.     variable _warrow
  470.     variable $path
  471.     upvar 0  $path data
  472.  
  473.     set base $data(base)
  474.     set x    [expr {$_warrow+1}]
  475.     if { $pos < $base } {
  476.         foreach page [lrange $data(pages) $pos [expr {$base-1}]] {
  477.             incr x [expr {-$data($page,width)}]
  478.         }
  479.     } elseif { $pos > $base } {
  480.         foreach page [lrange $data(pages) $base [expr {$pos-1}]] {
  481.             incr x $data($page,width)
  482.         }
  483.     }
  484.     return $x
  485. }
  486.  
  487.  
  488. # ------------------------------------------------------------------------------
  489. #  Command NoteBook::_xview
  490. # ------------------------------------------------------------------------------
  491. proc NoteBook::_xview { path inc } {
  492.     variable $path
  493.     upvar 0  $path data
  494.  
  495.     if { $inc == -1 } {
  496.         set base [expr {$data(base)-1}]
  497.         set dx $data([lindex $data(pages) $base],width)
  498.     } else {
  499.         set dx [expr {-$data([lindex $data(pages) $data(base)],width)}]
  500.         set base [expr {$data(base)+1}]
  501.     }
  502.  
  503.     if { $base >= 0 && $base < [llength $data(pages)] } {
  504.         set data(base) $base
  505.         $path:cmd move page $dx 0
  506.         _draw_area   $path
  507.         _draw_arrows $path
  508.     }
  509. }
  510.  
  511.  
  512. # ------------------------------------------------------------------------------
  513. #  Command NoteBook::_highlight
  514. # ------------------------------------------------------------------------------
  515. proc NoteBook::_highlight { type path page } {
  516.     variable $path
  517.     upvar 0  $path data
  518.  
  519.     if { ![string compare [Widget::getoption $path.f$page -state] "disabled"] } {
  520.         return
  521.     }
  522.  
  523.     switch -- $type {
  524.         on {
  525.             $path:cmd itemconfigure "$page:poly" -fill [Widget::getoption $path -activebackground]
  526.             $path:cmd itemconfigure "$page:text" -fill [Widget::getoption $path -activeforeground]
  527.         }
  528.         off {
  529.             $path:cmd itemconfigure "$page:poly" -fill [Widget::getoption $path -background]
  530.             $path:cmd itemconfigure "$page:text" -fill [Widget::getoption $path -foreground]
  531.         }
  532.     }
  533. }
  534.  
  535.  
  536. # ------------------------------------------------------------------------------
  537. #  Command NoteBook::_select
  538. # ------------------------------------------------------------------------------
  539. proc NoteBook::_select { path page } {
  540.     variable $path
  541.     upvar 0  $path data
  542.  
  543.     if { ![string compare [Widget::getoption $path.f$page -state] "normal"] } {
  544.         set oldsel $data(select)
  545.         if { [string compare $page $oldsel] } {
  546.             if { $oldsel != "" } {
  547.                 if { [set cmd [Widget::getoption $path.f$oldsel -leavecmd]] != "" } {
  548.                     if { [catch {uplevel \#0 $cmd} res] && $res == 0 } {
  549.                         return
  550.                     }
  551.                 }
  552.                 set data(select) ""
  553.                 _draw_page $path $oldsel 0
  554.             }
  555.             set data(select) $page
  556.             if { $page != "" } {
  557.                 if { !$data($page,realized) } {
  558.                     set data($page,realized) 1
  559.                     if { [set cmd [Widget::getoption $path.f$page -createcmd]] != "" } {
  560.                         uplevel \#0 $cmd
  561.                     }
  562.                 }
  563.                 if { [set cmd [Widget::getoption $path.f$page -raisecmd]] != "" } {
  564.                     uplevel \#0 $cmd
  565.                 }
  566.                 _draw_page $path $page 0
  567.             }
  568.             _draw_area $path
  569.         }
  570.     }
  571. }
  572.  
  573.  
  574. # ------------------------------------------------------------------------------
  575. #  Command NoteBook::_redraw
  576. # ------------------------------------------------------------------------------
  577. proc NoteBook::_redraw { path } {
  578.     variable $path
  579.     upvar 0  $path data
  580.  
  581.     if { !$data(realized) } {
  582.         return
  583.     }
  584.  
  585.     foreach page $data(pages) {
  586.         _draw_page $path $page 0
  587.     }
  588.     _draw_area   $path
  589.     _draw_arrows $path
  590. }
  591.  
  592.  
  593. # ------------------------------------------------------------------------------
  594. #  Command NoteBook::_draw_page
  595. # ------------------------------------------------------------------------------
  596. proc NoteBook::_draw_page { path page create } {
  597.     variable $path
  598.     upvar 0  $path data
  599.  
  600.     # --- calcul des coordonnees et des couleurs de l'onglet ---------------------------------
  601.     set pos [lsearch $data(pages) $page]
  602.     set bg  [Widget::getoption $path -background]
  603.     set h   $data(hpage)
  604.     set xd  [_get_x_page $path $pos]
  605.     set xf  [expr {$xd + $data($page,width)}]
  606.     set lt  [list $xd $h $xd 4 [expr {$xd+3}] 1 $xf 1]
  607.     set lb  [list $xf 1 [expr {$xf+3}] 4 [expr {$xf+3}] [expr {$h-3}] [expr {$xf+6}] $h]
  608.     set img [Widget::getoption $path.f$page -image]
  609.     if { $data(select) == $page } {
  610.         set fgt   $data(lbg)
  611.         set fgb   $data(dbg)
  612.         set ytext [expr {$h/2-1}]
  613.         if { $img == "" } {
  614.             set xtext [expr {$xd+9}]
  615.         } else {
  616.             set ximg  [expr {$xd+9}]
  617.             set xtext [expr {$ximg+[image width $img]+4}]
  618.         }
  619.         set bd    [Widget::getoption $path -borderwidth]
  620.         set fg    [Widget::getoption $path -foreground]
  621.     } else {
  622.         set fgt   $data(dbg)
  623.         set fgb   $fgt
  624.         set ytext [expr {$h/2}]
  625.         if { $img == "" } {
  626.             set xtext [expr {$xd+10}]
  627.         } else {
  628.             set ximg  [expr {$xd+10}]
  629.             set xtext [expr {$ximg+[image width $img]+4}]
  630.         }
  631.         set bd    1
  632.         if { [Widget::getoption $path.f$page -state] == "normal" } {
  633.             set fg [Widget::getoption $path -foreground]
  634.         } else {
  635.             set fg [Widget::getoption $path -disabledforeground]
  636.         }
  637.     }
  638.  
  639.     # --- creation ou modification de l'onglet -----------------------------------------------
  640.     if { $create } {
  641.         eval $path:cmd create polygon [concat $lt $lb] \
  642.             -tag     {"page p:$page $page:poly"} \
  643.             -outline $bg \
  644.             -fill    $bg
  645.         eval $path:cmd create line $lt -tags {"page p:$page $page:top top"} -fill $fgt -width $bd
  646.         eval $path:cmd create line $lb -tags {"page p:$page $page:bot bot"} -fill $fgb -width $bd
  647.         $path:cmd create text $xtext $ytext           \
  648.             -text   [Widget::getoption $path.f$page -text] \
  649.             -font   [Widget::getoption $path -font]        \
  650.             -fill   $fg                               \
  651.             -anchor w                                 \
  652.             -tags   "page p:$page $page:text"
  653.  
  654.         $path:cmd bind p:$page <ButtonPress-1> "NoteBook::_select $path $page"
  655.         $path:cmd bind p:$page <Enter>         "NoteBook::_highlight on  $path $page"
  656.         $path:cmd bind p:$page <Leave>         "NoteBook::_highlight off $path $page"
  657.     } else {
  658.         eval $path:cmd coords "$page:poly" [concat $lt $lb]
  659.         eval $path:cmd coords "$page:top"  $lt
  660.         eval $path:cmd coords "$page:bot"  $lb
  661.         $path:cmd coords "$page:text" $xtext $ytext
  662.  
  663.         $path:cmd itemconfigure "$page:poly" -fill $bg  -outline $bg
  664.         $path:cmd itemconfigure "$page:top"  -fill $fgt -width $bd
  665.         $path:cmd itemconfigure "$page:bot"  -fill $fgb -width $bd
  666.         $path:cmd itemconfigure "$page:text"    \
  667.             -text [Widget::getoption $path.f$page -text]     \
  668.             -font [Widget::getoption $path -font]    \
  669.             -fill $fg
  670.     }
  671.     if { $img != "" } {
  672.         if { [set id [$path:cmd find withtag $page:img]] == "" } {
  673.             $path:cmd create image $ximg $ytext \
  674.                 -image  $img \
  675.                 -anchor w    \
  676.                 -tags   "page p:$page $page:img"
  677.         } else {
  678.             $path:cmd coords $id $ximg $ytext
  679.             $path:cmd itemconfigure $id -image $img
  680.         }
  681.     } else {
  682.         $path:cmd delete $page:img
  683.     }
  684.  
  685.     if { $data(select) == $page } {
  686.         $path:cmd raise p:$page
  687.     } elseif { $pos == 0 } {
  688.         if { $data(select) == "" } {
  689.             $path:cmd raise p:$page
  690.         } else {
  691.             $path:cmd lower p:$page p:$data(select)
  692.         }
  693.     } else {
  694.         set pred [lindex $data(pages) [expr {$pos-1}]]
  695.         if { $data(select) != $pred || $pos == 1 } {
  696.             $path:cmd lower p:$page p:$pred
  697.         } else {
  698.             $path:cmd lower p:$page p:[lindex $data(pages) [expr {$pos-2}]]
  699.         }
  700.     }
  701. }
  702.  
  703.  
  704. # ------------------------------------------------------------------------------
  705. #  Command NoteBook::_draw_arrows
  706. # ------------------------------------------------------------------------------
  707. proc NoteBook::_draw_arrows { path } {
  708.     variable _warrow
  709.     variable $path
  710.     upvar 0  $path data
  711.  
  712.     set w       [expr {[winfo width $path]-1}]
  713.     set h       [expr {$data(hpage)-1}]
  714.     set nbpages [llength $data(pages)]
  715.     set xl      0
  716.     set xr      [expr {$w-$_warrow+1}]
  717.  
  718.     if { $data(base) > 0 } {
  719.         if { ![llength [$path:cmd find withtag "leftarrow"]] } {
  720.             $path:cmd create window $xl 1 \
  721.                 -width  $_warrow          \
  722.                 -height $h                \
  723.                 -anchor nw                \
  724.                 -window $path.fg          \
  725.                 -tags   "leftarrow"
  726.         } else {
  727.             $path:cmd coords "leftarrow" $xl 1
  728.             $path:cmd itemconfigure "leftarrow" -width $_warrow -height $h
  729.         }
  730.     } else {
  731.         $path:cmd delete "leftarrow"
  732.     }
  733.  
  734.     if { $data(base) < $nbpages-1 &&
  735.          $data(wpage) + [_get_x_page $path 0] + 6 > $w } {
  736.         if { ![llength [$path:cmd find withtag "rightarrow"]] } {
  737.             $path:cmd create window $xr 1 \
  738.                 -width  $_warrow          \
  739.                 -height $h                \
  740.                 -window $path.fd          \
  741.                 -anchor nw                \
  742.                 -tags   "rightarrow"
  743.         } else {
  744.             $path:cmd coords "rightarrow" $xr 1
  745.             $path:cmd itemconfigure "rightarrow" -width $_warrow -height $h
  746.         }
  747.     } else {
  748.         $path:cmd delete "rightarrow"
  749.     }
  750. }
  751.  
  752.  
  753. # ------------------------------------------------------------------------------
  754. #  Command NoteBook::_draw_area
  755. # ------------------------------------------------------------------------------
  756. proc NoteBook::_draw_area { path } {
  757.     variable $path
  758.     upvar 0  $path data
  759.  
  760.     set w   [expr {[winfo width  $path]-1}]
  761.     set h   [expr {[winfo height $path]-1}]
  762.     set bd  [Widget::getoption $path -borderwidth]
  763.     set x0  [expr {$bd-1}]
  764.     set y0  $data(hpage)
  765.     set y1  $h
  766.     set dbg $data(dbg)
  767.     set sel $data(select)
  768.     if {  $sel == "" } {
  769.         set xd  [expr {$w/2}]
  770.         set xf  $xd
  771.         set lbg $data(dbg)
  772.     } else {
  773.         set xd [_get_x_page $path [lsearch $data(pages) $data(select)]]
  774.         set xf [expr {$xd + $data($sel,width)+6}]
  775.         set lbg $data(lbg)
  776.     }
  777.  
  778.     if { [llength [$path:cmd find withtag rect]] } {
  779.         $path:cmd coords "toprect1" $xd $y0 $x0 $y0 $x0 $h
  780.         $path:cmd coords "toprect2" $w $y0 $xf $y0
  781.         $path:cmd coords "botrect"  $x0 $h $w $h $w $y0
  782.         $path:cmd itemconfigure "toprect1" -fill $lbg -width $bd
  783.         $path:cmd itemconfigure "toprect2" -fill $lbg -width $bd
  784.         $path:cmd itemconfigure "botrect"  -width $bd
  785.         $path:cmd raise "rect"
  786.     } else {
  787.         $path:cmd create line $xd $y0 $x0 $y0 $x0 $y1 \
  788.             -tags "rect toprect1" -fill $lbg -width $bd
  789.         $path:cmd create line $w $y0 $xf $y0 \
  790.             -tags "rect toprect2" -fill $lbg -width $bd
  791.         $path:cmd create line 1 $h $w $h $w $y0 \
  792.             -tags "rect botrect"  -fill $dbg -width $bd
  793.     }
  794.  
  795.     if { $sel != "" } {
  796.         if { [llength [$path:cmd find withtag "window"]] } {
  797.             $path:cmd coords "window" 2 [expr {$y0+1}]
  798.             $path:cmd itemconfigure "window"    \
  799.                 -width  [expr {$w-1 -2}]        \
  800.                 -height [expr {$h-$y0-1 -2}]    \
  801.                 -window $path.f$sel
  802.         } else {
  803.             set y0 $data(hpage)
  804.             $path:cmd create window 2 [expr {$y0+1}] \
  805.                 -width  [expr {$w-3}]           \
  806.                 -height [expr {$h-$y0-3}]       \
  807.                 -anchor nw                      \
  808.                 -tags   "window"                \
  809.                 -window $path.f$sel
  810.         }
  811.     } else {
  812.         $path:cmd delete "window"
  813.     }
  814. }
  815.  
  816.  
  817. # ------------------------------------------------------------------------------
  818. #  Command NoteBook::_resize
  819. # ------------------------------------------------------------------------------
  820. proc NoteBook::_resize { path } {
  821.     _draw_area   $path
  822.     _draw_arrows $path
  823. }
  824.  
  825.  
  826. # ------------------------------------------------------------------------------
  827. #  Command NoteBook::_realize
  828. # ------------------------------------------------------------------------------
  829. proc NoteBook::_realize { path } {
  830.     variable $path
  831.     upvar 0  $path data
  832.  
  833.     if { [set width  [Widget::getoption $path -width]]  == 0 ||
  834.          [set height [Widget::getoption $path -height]] == 0 } {
  835.         compute_size $path
  836.     }
  837.  
  838.     set data(realized) 1
  839.     _draw_area $path
  840.     _draw_arrows $path
  841.     bind $path <Configure> "NoteBook::_resize $path"
  842. }
  843.