PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/02-development/uDrawGraph-3.1/lib/BWidget-1.7.0/notebook.tcl

https://bitbucket.org/jmelo_lyncode/thesis
TCL | 1162 lines | 792 code | 156 blank | 214 comment | 155 complexity | 546c476af78217c99928f9e8aa0dba64 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-3.0
  1. # ---------------------------------------------------------------------------
  2. # notebook.tcl
  3. # This file is part of Unifix BWidget Toolkit
  4. # $Id: notebook.tcl,v 1.19 2003/10/20 21:23:52 damonc 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::bindtabs
  16. # - NoteBook::raise
  17. # - NoteBook::see
  18. # - NoteBook::page
  19. # - NoteBook::pages
  20. # - NoteBook::index
  21. # - NoteBook::getframe
  22. # - NoteBook::_test_page
  23. # - NoteBook::_itemconfigure
  24. # - NoteBook::_compute_width
  25. # - NoteBook::_get_x_page
  26. # - NoteBook::_xview
  27. # - NoteBook::_highlight
  28. # - NoteBook::_select
  29. # - NoteBook::_redraw
  30. # - NoteBook::_draw_page
  31. # - NoteBook::_draw_arrows
  32. # - NoteBook::_draw_area
  33. # - NoteBook::_resize
  34. # ---------------------------------------------------------------------------
  35. namespace eval NoteBook {
  36. Widget::define NoteBook notebook ArrowButton DynamicHelp
  37. namespace eval Page {
  38. Widget::declare NoteBook::Page {
  39. {-state Enum normal 0 {normal disabled}}
  40. {-createcmd String "" 0}
  41. {-raisecmd String "" 0}
  42. {-leavecmd String "" 0}
  43. {-image TkResource "" 0 label}
  44. {-text String "" 0}
  45. {-foreground String "" 0}
  46. {-background String "" 0}
  47. {-activeforeground String "" 0}
  48. {-activebackground String "" 0}
  49. {-disabledforeground String "" 0}
  50. }
  51. }
  52. DynamicHelp::include NoteBook::Page balloon
  53. Widget::bwinclude NoteBook ArrowButton .c.fg \
  54. include {-foreground -background -activeforeground \
  55. -activebackground -disabledforeground -repeatinterval \
  56. -repeatdelay -borderwidth} \
  57. initialize {-borderwidth 1}
  58. Widget::bwinclude NoteBook ArrowButton .c.fd \
  59. include {-foreground -background -activeforeground \
  60. -activebackground -disabledforeground -repeatinterval \
  61. -repeatdelay -borderwidth} \
  62. initialize {-borderwidth 1}
  63. Widget::declare NoteBook {
  64. {-foreground TkResource "" 0 button}
  65. {-background TkResource "" 0 button}
  66. {-activebackground TkResource "" 0 button}
  67. {-activeforeground TkResource "" 0 button}
  68. {-disabledforeground TkResource "" 0 button}
  69. {-font TkResource "" 0 button}
  70. {-side Enum top 0 {top bottom}}
  71. {-homogeneous Boolean 0 0}
  72. {-borderwidth Int 1 0 "%d >= 1 && %d <= 2"}
  73. {-internalborderwidth Int 10 0 "%d >= 0"}
  74. {-width Int 0 0 "%d >= 0"}
  75. {-height Int 0 0 "%d >= 0"}
  76. {-repeatdelay BwResource "" 0 ArrowButton}
  77. {-repeatinterval BwResource "" 0 ArrowButton}
  78. {-fg Synonym -foreground}
  79. {-bg Synonym -background}
  80. {-bd Synonym -borderwidth}
  81. {-ibd Synonym -internalborderwidth}
  82. {-arcradius Int 2 0 "%d >= 0 && %d <= 8"}
  83. {-tabbevelsize Int 0 0 "%d >= 0 && %d <= 8"}
  84. {-tabpady Padding {0 6} 0 "%d >= 0"}
  85. }
  86. Widget::addmap NoteBook "" .c {-background {}}
  87. variable _warrow 12
  88. bind NoteBook <Configure> [list NoteBook::_resize %W]
  89. bind NoteBook <Destroy> [list NoteBook::_destroy %W]
  90. }
  91. # ---------------------------------------------------------------------------
  92. # Command NoteBook::create
  93. # ---------------------------------------------------------------------------
  94. proc NoteBook::create { path args } {
  95. variable $path
  96. upvar 0 $path data
  97. Widget::init NoteBook $path $args
  98. set data(base) 0
  99. set data(select) ""
  100. set data(pages) {}
  101. set data(pages) {}
  102. set data(cpt) 0
  103. set data(realized) 0
  104. set data(wpage) 0
  105. _compute_height $path
  106. # Create the canvas
  107. set w [expr {[Widget::cget $path -width]+4}]
  108. set h [expr {[Widget::cget $path -height]+$data(hpage)+4}]
  109. frame $path -class NoteBook -borderwidth 0 -highlightthickness 0 \
  110. -relief flat
  111. eval [list canvas $path.c] [Widget::subcget $path .c] \
  112. [list -relief flat -borderwidth 0 -highlightthickness 0 \
  113. -width $w -height $h]
  114. pack $path.c -expand yes -fill both
  115. # Removing the Canvas global bindings from our canvas as
  116. # application specific bindings on that tag may interfere with its
  117. # operation here. [SF item #459033]
  118. set bindings [bindtags $path.c]
  119. set pos [lsearch -exact $bindings Canvas]
  120. if {$pos >= 0} {
  121. set bindings [lreplace $bindings $pos $pos]
  122. }
  123. bindtags $path.c $bindings
  124. # Create the arrow button
  125. eval [list ArrowButton::create $path.c.fg] [Widget::subcget $path .c.fg] \
  126. [list -highlightthickness 0 -type button -dir left \
  127. -armcommand [list NoteBook::_xview $path -1]]
  128. eval [list ArrowButton::create $path.c.fd] [Widget::subcget $path .c.fd] \
  129. [list -highlightthickness 0 -type button -dir right \
  130. -armcommand [list NoteBook::_xview $path 1]]
  131. Widget::create NoteBook $path
  132. set bg [Widget::cget $path -background]
  133. foreach {data(dbg) data(lbg)} [BWidget::get3dcolor $path $bg] {break}
  134. return $path
  135. }
  136. # ---------------------------------------------------------------------------
  137. # Command NoteBook::configure
  138. # ---------------------------------------------------------------------------
  139. proc NoteBook::configure { path args } {
  140. variable $path
  141. upvar 0 $path data
  142. set res [Widget::configure $path $args]
  143. set redraw 0
  144. set opts [list -font -homogeneous -tabpady]
  145. foreach {cf ch cp} [eval Widget::hasChangedX $path $opts] {break}
  146. if {$cf || $ch || $cp} {
  147. if { $cf || $cp } {
  148. _compute_height $path
  149. }
  150. _compute_width $path
  151. set redraw 1
  152. }
  153. set chibd [Widget::hasChanged $path -internalborderwidth ibd]
  154. set chbg [Widget::hasChanged $path -background bg]
  155. if {$chibd || $chbg} {
  156. foreach page $data(pages) {
  157. $path.f$page configure \
  158. -borderwidth $ibd -background $bg
  159. }
  160. }
  161. if {$chbg} {
  162. set col [BWidget::get3dcolor $path $bg]
  163. set data(dbg) [lindex $col 0]
  164. set data(lbg) [lindex $col 1]
  165. set redraw 1
  166. }
  167. if { [Widget::hasChanged $path -foreground fg] ||
  168. [Widget::hasChanged $path -borderwidth bd] ||
  169. [Widget::hasChanged $path -arcradius radius] ||
  170. [Widget::hasChanged $path -tabbevelsize bevel] ||
  171. [Widget::hasChanged $path -side side] } {
  172. set redraw 1
  173. }
  174. set wc [Widget::hasChanged $path -width w]
  175. set hc [Widget::hasChanged $path -height h]
  176. if { $wc || $hc } {
  177. $path.c configure \
  178. -width [expr {$w + 4}] \
  179. -height [expr {$h + $data(hpage) + 4}]
  180. }
  181. if { $redraw } {
  182. _redraw $path
  183. }
  184. return $res
  185. }
  186. # ---------------------------------------------------------------------------
  187. # Command NoteBook::cget
  188. # ---------------------------------------------------------------------------
  189. proc NoteBook::cget { path option } {
  190. return [Widget::cget $path $option]
  191. }
  192. # ---------------------------------------------------------------------------
  193. # Command NoteBook::compute_size
  194. # ---------------------------------------------------------------------------
  195. proc NoteBook::compute_size { path } {
  196. variable $path
  197. upvar 0 $path data
  198. set wmax 0
  199. set hmax 0
  200. update idletasks
  201. foreach page $data(pages) {
  202. set w [winfo reqwidth $path.f$page]
  203. set h [winfo reqheight $path.f$page]
  204. set wmax [expr {$w>$wmax ? $w : $wmax}]
  205. set hmax [expr {$h>$hmax ? $h : $hmax}]
  206. }
  207. configure $path -width $wmax -height $hmax
  208. # Sven... well ok so this is called twice in some cases...
  209. NoteBook::_redraw $path
  210. # Sven end
  211. }
  212. # ---------------------------------------------------------------------------
  213. # Command NoteBook::insert
  214. # ---------------------------------------------------------------------------
  215. proc NoteBook::insert { path index page args } {
  216. variable $path
  217. upvar 0 $path data
  218. if { [lsearch -exact $data(pages) $page] != -1 } {
  219. return -code error "page \"$page\" already exists"
  220. }
  221. set f $path.f$page
  222. Widget::init NoteBook::Page $f $args
  223. set data(pages) [linsert $data(pages) $index $page]
  224. # If the page doesn't exist, create it; if it does reset its bg and ibd
  225. if { ![winfo exists $f] } {
  226. frame $f \
  227. -relief flat \
  228. -background [Widget::cget $path -background] \
  229. -borderwidth [Widget::cget $path -internalborderwidth]
  230. set data($page,realized) 0
  231. } else {
  232. $f configure \
  233. -background [Widget::cget $path -background] \
  234. -borderwidth [Widget::cget $path -internalborderwidth]
  235. }
  236. _compute_height $path
  237. _compute_width $path
  238. _draw_page $path $page 1
  239. _set_help $path $page
  240. _redraw $path
  241. return $f
  242. }
  243. # ---------------------------------------------------------------------------
  244. # Command NoteBook::delete
  245. # ---------------------------------------------------------------------------
  246. proc NoteBook::delete { path page {destroyframe 1} } {
  247. variable $path
  248. upvar 0 $path data
  249. set pos [_test_page $path $page]
  250. set data(pages) [lreplace $data(pages) $pos $pos]
  251. _compute_width $path
  252. $path.c delete p:$page
  253. if { $data(select) == $page } {
  254. set data(select) ""
  255. }
  256. if { $pos < $data(base) } {
  257. incr data(base) -1
  258. }
  259. if { $destroyframe } {
  260. destroy $path.f$page
  261. }
  262. _redraw $path
  263. }
  264. # ---------------------------------------------------------------------------
  265. # Command NoteBook::itemconfigure
  266. # ---------------------------------------------------------------------------
  267. proc NoteBook::itemconfigure { path page args } {
  268. _test_page $path $page
  269. set res [_itemconfigure $path $page $args]
  270. _redraw $path
  271. return $res
  272. }
  273. # ---------------------------------------------------------------------------
  274. # Command NoteBook::itemcget
  275. # ---------------------------------------------------------------------------
  276. proc NoteBook::itemcget { path page option } {
  277. _test_page $path $page
  278. return [Widget::cget $path.f$page $option]
  279. }
  280. # ---------------------------------------------------------------------------
  281. # Command NoteBook::bindtabs
  282. # ---------------------------------------------------------------------------
  283. proc NoteBook::bindtabs { path event script } {
  284. if { $script != "" } {
  285. append script " \[NoteBook::_get_page_name [list $path] current 2\]"
  286. $path.c bind "page" $event $script
  287. } else {
  288. $path.c bind "page" $event {}
  289. }
  290. }
  291. # ---------------------------------------------------------------------------
  292. # Command NoteBook::move
  293. # ---------------------------------------------------------------------------
  294. proc NoteBook::move { path page index } {
  295. variable $path
  296. upvar 0 $path data
  297. set pos [_test_page $path $page]
  298. set data(pages) [linsert [lreplace $data(pages) $pos $pos] $index $page]
  299. _redraw $path
  300. }
  301. # ---------------------------------------------------------------------------
  302. # Command NoteBook::raise
  303. # ---------------------------------------------------------------------------
  304. proc NoteBook::raise { path {page ""} } {
  305. variable $path
  306. upvar 0 $path data
  307. if { $page != "" } {
  308. _test_page $path $page
  309. _select $path $page
  310. }
  311. return $data(select)
  312. }
  313. # ---------------------------------------------------------------------------
  314. # Command NoteBook::see
  315. # ---------------------------------------------------------------------------
  316. proc NoteBook::see { path page } {
  317. variable $path
  318. upvar 0 $path data
  319. set pos [_test_page $path $page]
  320. if { $pos < $data(base) } {
  321. set data(base) $pos
  322. _redraw $path
  323. } else {
  324. set w [expr {[winfo width $path]-1}]
  325. set fpage [expr {[_get_x_page $path $pos] + $data($page,width) + 6}]
  326. set idx $data(base)
  327. while { $idx < $pos && $fpage > $w } {
  328. set fpage [expr {$fpage - $data([lindex $data(pages) $idx],width)}]
  329. incr idx
  330. }
  331. if { $idx != $data(base) } {
  332. set data(base) $idx
  333. _redraw $path
  334. }
  335. }
  336. }
  337. # ---------------------------------------------------------------------------
  338. # Command NoteBook::page
  339. # ---------------------------------------------------------------------------
  340. proc NoteBook::page { path first {last ""} } {
  341. variable $path
  342. upvar 0 $path data
  343. if { $last == "" } {
  344. return [lindex $data(pages) $first]
  345. } else {
  346. return [lrange $data(pages) $first $last]
  347. }
  348. }
  349. # ---------------------------------------------------------------------------
  350. # Command NoteBook::pages
  351. # ---------------------------------------------------------------------------
  352. proc NoteBook::pages { path {first ""} {last ""}} {
  353. variable $path
  354. upvar 0 $path data
  355. if { ![string length $first] } {
  356. return $data(pages)
  357. }
  358. if { ![string length $last] } {
  359. return [lindex $data(pages) $first]
  360. } else {
  361. return [lrange $data(pages) $first $last]
  362. }
  363. }
  364. # ---------------------------------------------------------------------------
  365. # Command NoteBook::index
  366. # ---------------------------------------------------------------------------
  367. proc NoteBook::index { path page } {
  368. variable $path
  369. upvar 0 $path data
  370. return [lsearch -exact $data(pages) $page]
  371. }
  372. # ---------------------------------------------------------------------------
  373. # Command NoteBook::_destroy
  374. # ---------------------------------------------------------------------------
  375. proc NoteBook::_destroy { path } {
  376. variable $path
  377. upvar 0 $path data
  378. foreach page $data(pages) {
  379. Widget::destroy $path.f$page
  380. }
  381. Widget::destroy $path
  382. unset data
  383. }
  384. # ---------------------------------------------------------------------------
  385. # Command NoteBook::getframe
  386. # ---------------------------------------------------------------------------
  387. proc NoteBook::getframe { path page } {
  388. return $path.f$page
  389. }
  390. # ---------------------------------------------------------------------------
  391. # Command NoteBook::_test_page
  392. # ---------------------------------------------------------------------------
  393. proc NoteBook::_test_page { path page } {
  394. variable $path
  395. upvar 0 $path data
  396. if { [set pos [lsearch -exact $data(pages) $page]] == -1 } {
  397. return -code error "page \"$page\" does not exists"
  398. }
  399. return $pos
  400. }
  401. proc NoteBook::_getoption { path page option } {
  402. set value [Widget::cget $path.f$page $option]
  403. if {![string length $value]} {
  404. set value [Widget::cget $path $option]
  405. }
  406. return $value
  407. }
  408. # ---------------------------------------------------------------------------
  409. # Command NoteBook::_itemconfigure
  410. # ---------------------------------------------------------------------------
  411. proc NoteBook::_itemconfigure { path page lres } {
  412. variable $path
  413. upvar 0 $path data
  414. set res [Widget::configure $path.f$page $lres]
  415. if { [Widget::hasChanged $path.f$page -text foo] } {
  416. _compute_width $path
  417. } elseif { [Widget::hasChanged $path.f$page -image foo] } {
  418. _compute_height $path
  419. _compute_width $path
  420. }
  421. if { [Widget::hasChanged $path.f$page -state state] &&
  422. $state == "disabled" && $data(select) == $page } {
  423. set data(select) ""
  424. }
  425. return $res
  426. }
  427. # ---------------------------------------------------------------------------
  428. # Command NoteBook::_compute_width
  429. # ---------------------------------------------------------------------------
  430. proc NoteBook::_compute_width { path } {
  431. variable $path
  432. upvar 0 $path data
  433. set wmax 0
  434. set wtot 0
  435. set hmax $data(hpage)
  436. set font [Widget::cget $path -font]
  437. if { ![info exists data(textid)] } {
  438. set data(textid) [$path.c create text 0 -100 -font $font -anchor nw]
  439. }
  440. set id $data(textid)
  441. $path.c itemconfigure $id -font $font
  442. foreach page $data(pages) {
  443. $path.c itemconfigure $id -text [Widget::cget $path.f$page -text]
  444. # Get the bbox for this text to determine its width, then substract
  445. # 6 from the width to account for canvas bbox oddness w.r.t. widths of
  446. # simple text.
  447. foreach {x1 y1 x2 y2} [$path.c bbox $id] break
  448. set x2 [expr {$x2 - 6}]
  449. set wtext [expr {$x2 - $x1 + 20}]
  450. if { [set img [Widget::cget $path.f$page -image]] != "" } {
  451. set wtext [expr {$wtext + [image width $img] + 4}]
  452. set himg [expr {[image height $img] + 6}]
  453. if { $himg > $hmax } {
  454. set hmax $himg
  455. }
  456. }
  457. set wmax [expr {$wtext > $wmax ? $wtext : $wmax}]
  458. incr wtot $wtext
  459. set data($page,width) $wtext
  460. }
  461. if { [Widget::cget $path -homogeneous] } {
  462. foreach page $data(pages) {
  463. set data($page,width) $wmax
  464. }
  465. set wtot [expr {$wmax * [llength $data(pages)]}]
  466. }
  467. set data(hpage) $hmax
  468. set data(wpage) $wtot
  469. }
  470. # ---------------------------------------------------------------------------
  471. # Command NoteBook::_compute_height
  472. # ---------------------------------------------------------------------------
  473. proc NoteBook::_compute_height { path } {
  474. variable $path
  475. upvar 0 $path data
  476. set font [Widget::cget $path -font]
  477. set pady0 [Widget::_get_padding $path -tabpady 0]
  478. set pady1 [Widget::_get_padding $path -tabpady 1]
  479. set metrics [font metrics $font -linespace]
  480. set imgh 0
  481. set lines 1
  482. foreach page $data(pages) {
  483. set img [Widget::cget $path.f$page -image]
  484. set text [Widget::cget $path.f$page -text]
  485. set len [llength [split $text \n]]
  486. if {$len > $lines} { set lines $len}
  487. if {$img != ""} {
  488. set h [image height $img]
  489. if {$h > $imgh} { set imgh $h }
  490. }
  491. }
  492. set height [expr {$metrics * $lines}]
  493. if {$imgh > $height} { set height $imgh }
  494. set data(hpage) [expr {$height + $pady0 + $pady1}]
  495. }
  496. # ---------------------------------------------------------------------------
  497. # Command NoteBook::_get_x_page
  498. # ---------------------------------------------------------------------------
  499. proc NoteBook::_get_x_page { path pos } {
  500. variable _warrow
  501. variable $path
  502. upvar 0 $path data
  503. set base $data(base)
  504. # notebook tabs start flush with the left side of the notebook
  505. set x 0
  506. if { $pos < $base } {
  507. foreach page [lrange $data(pages) $pos [expr {$base-1}]] {
  508. incr x [expr {-$data($page,width)}]
  509. }
  510. } elseif { $pos > $base } {
  511. foreach page [lrange $data(pages) $base [expr {$pos-1}]] {
  512. incr x $data($page,width)
  513. }
  514. }
  515. return $x
  516. }
  517. # ---------------------------------------------------------------------------
  518. # Command NoteBook::_xview
  519. # ---------------------------------------------------------------------------
  520. proc NoteBook::_xview { path inc } {
  521. variable $path
  522. upvar 0 $path data
  523. if { $inc == -1 } {
  524. set base [expr {$data(base)-1}]
  525. set dx $data([lindex $data(pages) $base],width)
  526. } else {
  527. set dx [expr {-$data([lindex $data(pages) $data(base)],width)}]
  528. set base [expr {$data(base)+1}]
  529. }
  530. if { $base >= 0 && $base < [llength $data(pages)] } {
  531. set data(base) $base
  532. $path.c move page $dx 0
  533. _draw_area $path
  534. _draw_arrows $path
  535. }
  536. }
  537. # ---------------------------------------------------------------------------
  538. # Command NoteBook::_highlight
  539. # ---------------------------------------------------------------------------
  540. proc NoteBook::_highlight { type path page } {
  541. variable $path
  542. upvar 0 $path data
  543. if { [string equal [Widget::cget $path.f$page -state] "disabled"] } {
  544. return
  545. }
  546. switch -- $type {
  547. on {
  548. $path.c itemconfigure "$page:poly" \
  549. -fill [_getoption $path $page -activebackground]
  550. $path.c itemconfigure "$page:text" \
  551. -fill [_getoption $path $page -activeforeground]
  552. }
  553. off {
  554. $path.c itemconfigure "$page:poly" \
  555. -fill [_getoption $path $page -background]
  556. $path.c itemconfigure "$page:text" \
  557. -fill [_getoption $path $page -foreground]
  558. }
  559. }
  560. }
  561. # ---------------------------------------------------------------------------
  562. # Command NoteBook::_select
  563. # ---------------------------------------------------------------------------
  564. proc NoteBook::_select { path page } {
  565. variable $path
  566. upvar 0 $path data
  567. if {![string equal [Widget::cget $path.f$page -state] "normal"]} { return }
  568. set oldsel $data(select)
  569. if {[string equal $page $oldsel]} { return }
  570. if { ![string equal $oldsel ""] } {
  571. set cmd [Widget::cget $path.f$oldsel -leavecmd]
  572. if { ![string equal $cmd ""] } {
  573. set code [catch {uplevel \#0 $cmd} res]
  574. if { $code == 1 || $res == 0 } {
  575. return -code $code $res
  576. }
  577. }
  578. set data(select) ""
  579. _draw_page $path $oldsel 0
  580. }
  581. set data(select) $page
  582. if { ![string equal $page ""] } {
  583. if { !$data($page,realized) } {
  584. set data($page,realized) 1
  585. set cmd [Widget::cget $path.f$page -createcmd]
  586. if { ![string equal $cmd ""] } {
  587. uplevel \#0 $cmd
  588. }
  589. }
  590. set cmd [Widget::cget $path.f$page -raisecmd]
  591. if { ![string equal $cmd ""] } {
  592. uplevel \#0 $cmd
  593. }
  594. _draw_page $path $page 0
  595. }
  596. _draw_area $path
  597. }
  598. # -----------------------------------------------------------------------------
  599. # Command NoteBook::_redraw
  600. # -----------------------------------------------------------------------------
  601. proc NoteBook::_redraw { path } {
  602. variable $path
  603. upvar 0 $path data
  604. if { !$data(realized) } { return }
  605. _compute_height $path
  606. foreach page $data(pages) {
  607. _draw_page $path $page 0
  608. }
  609. _draw_area $path
  610. _draw_arrows $path
  611. }
  612. # ----------------------------------------------------------------------------
  613. # Command NoteBook::_draw_page
  614. # ----------------------------------------------------------------------------
  615. proc NoteBook::_draw_page { path page create } {
  616. variable $path
  617. upvar 0 $path data
  618. # --- calcul des coordonnees et des couleurs de l'onglet ------------------
  619. set pos [lsearch -exact $data(pages) $page]
  620. set bg [_getoption $path $page -background]
  621. # lookup the tab colors
  622. set fgt $data(lbg)
  623. set fgb $data(dbg)
  624. set h $data(hpage)
  625. set xd [_get_x_page $path $pos]
  626. set xf [expr {$xd + $data($page,width)}]
  627. # Set the initial text offsets -- a few pixels down, centered left-to-right
  628. set textOffsetY [expr [Widget::_get_padding $path -tabpady 0] + 3]
  629. set textOffsetX 9
  630. # Coordinates of the tab corners are:
  631. # c3 c4
  632. #
  633. # c2 c5
  634. #
  635. # c1 c6
  636. #
  637. # where
  638. # c1 = $xd, $h
  639. # c2 = $xd+$xBevel, $arcRadius+2
  640. # c3 = $xd+$xBevel+$arcRadius, $arcRadius
  641. # c4 = $xf+1-$xBevel, $arcRadius
  642. # c5 = $xf+$arcRadius-$xBevel, $arcRadius+2
  643. # c6 = $xf+$arcRadius, $h
  644. set top 2
  645. set arcRadius [Widget::cget $path -arcradius]
  646. set xBevel [Widget::cget $path -tabbevelsize]
  647. if { $data(select) != $page } {
  648. if { $pos == 0 } {
  649. # The leftmost page is a special case -- it is drawn with its
  650. # tab a little indented. To achieve this, we incr xd. We also
  651. # decr textOffsetX, so that the text doesn't move left/right.
  652. incr xd 2
  653. incr textOffsetX -2
  654. }
  655. } else {
  656. # The selected page's text is raised higher than the others
  657. incr top -2
  658. }
  659. # Precompute some coord values that we use a lot
  660. set topPlusRadius [expr {$top + $arcRadius}]
  661. set rightPlusRadius [expr {$xf + $arcRadius}]
  662. set leftPlusRadius [expr {$xd + $arcRadius}]
  663. # Sven
  664. set side [Widget::cget $path -side]
  665. set tabsOnBottom [string equal $side "bottom"]
  666. set h1 [expr {[winfo height $path]}]
  667. set bd [Widget::cget $path -borderwidth]
  668. if {$bd < 1} { set bd 1 }
  669. if { $tabsOnBottom } {
  670. set top [expr {$top * -1}]
  671. set topPlusRadius [expr {$topPlusRadius * -1}]
  672. # Hrm... the canvas has an issue with drawing diagonal segments
  673. # of lines from the bottom to the top, so we have to draw this line
  674. # backwards (ie, lt is actually the bottom, drawn from right to left)
  675. set lt [list \
  676. $rightPlusRadius [expr {$h1-$h-1}] \
  677. [expr {$rightPlusRadius - $xBevel}] [expr {$h1 + $topPlusRadius}] \
  678. [expr {$xf - $xBevel}] [expr {$h1 + $top}] \
  679. [expr {$leftPlusRadius + $xBevel}] [expr {$h1 + $top}] \
  680. ]
  681. set lb [list \
  682. [expr {$leftPlusRadius + $xBevel}] [expr {$h1 + $top}] \
  683. [expr {$xd + $xBevel}] [expr {$h1 + $topPlusRadius}] \
  684. $xd [expr {$h1-$h-1}] \
  685. ]
  686. # Because we have to do this funky reverse order thing, we have to
  687. # swap the top/bottom colors too.
  688. set tmp $fgt
  689. set fgt $fgb
  690. set fgb $tmp
  691. } else {
  692. set lt [list \
  693. $xd $h \
  694. [expr {$xd + $xBevel}] $topPlusRadius \
  695. [expr {$leftPlusRadius + $xBevel}] $top \
  696. [expr {$xf + 1 - $xBevel}] $top \
  697. ]
  698. set lb [list \
  699. [expr {$xf + 1 - $xBevel}] [expr {$top + 1}] \
  700. [expr {$rightPlusRadius - $xBevel}] $topPlusRadius \
  701. $rightPlusRadius $h \
  702. ]
  703. }
  704. set img [Widget::cget $path.f$page -image]
  705. set ytext $top
  706. if { $tabsOnBottom } {
  707. # The "+ 2" below moves the text closer to the bottom of the tab,
  708. # so it doesn't look so cramped. I should be able to achieve the
  709. # same goal by changing the anchor of the text and using this formula:
  710. # ytext = $top + $h1 - $textOffsetY
  711. # but that doesn't quite work (I think the linespace from the text
  712. # gets in the way)
  713. incr ytext [expr {$h1 - $h + 2}]
  714. }
  715. incr ytext $textOffsetY
  716. set xtext [expr {$xd + $textOffsetX}]
  717. if { $img != "" } {
  718. # if there's an image, put it on the left and move the text right
  719. set ximg $xtext
  720. incr xtext [expr {[image width $img] + 2}]
  721. }
  722. if { $data(select) == $page } {
  723. set bd [Widget::cget $path -borderwidth]
  724. if {$bd < 1} { set bd 1 }
  725. set fg [_getoption $path $page -foreground]
  726. } else {
  727. set bd 1
  728. if { [Widget::cget $path.f$page -state] == "normal" } {
  729. set fg [_getoption $path $page -foreground]
  730. } else {
  731. set fg [_getoption $path $page -disabledforeground]
  732. }
  733. }
  734. # --- creation ou modification de l'onglet --------------------------------
  735. # Sven
  736. if { $create } {
  737. # Create the tab region
  738. eval [list $path.c create polygon] [concat $lt $lb] [list \
  739. -tags [list page p:$page $page:poly] \
  740. -outline $bg \
  741. -fill $bg \
  742. ]
  743. eval [list $path.c create line] $lt [list \
  744. -tags [list page p:$page $page:top top] -fill $fgt -width $bd]
  745. eval [list $path.c create line] $lb [list \
  746. -tags [list page p:$page $page:bot bot] -fill $fgb -width $bd]
  747. $path.c create text $xtext $ytext \
  748. -text [Widget::cget $path.f$page -text] \
  749. -font [Widget::cget $path -font] \
  750. -fill $fg \
  751. -anchor nw \
  752. -tags [list page p:$page $page:text]
  753. $path.c bind p:$page <ButtonPress-1> \
  754. [list NoteBook::_select $path $page]
  755. $path.c bind p:$page <Enter> \
  756. [list NoteBook::_highlight on $path $page]
  757. $path.c bind p:$page <Leave> \
  758. [list NoteBook::_highlight off $path $page]
  759. } else {
  760. $path.c coords "$page:text" $xtext $ytext
  761. $path.c itemconfigure "$page:text" \
  762. -text [Widget::cget $path.f$page -text] \
  763. -font [Widget::cget $path -font] \
  764. -fill $fg
  765. }
  766. eval [list $path.c coords "$page:poly"] [concat $lt $lb]
  767. eval [list $path.c coords "$page:top"] $lt
  768. eval [list $path.c coords "$page:bot"] $lb
  769. $path.c itemconfigure "$page:poly" -fill $bg -outline $bg
  770. $path.c itemconfigure "$page:top" -fill $fgt -width $bd
  771. $path.c itemconfigure "$page:bot" -fill $fgb -width $bd
  772. # Sven end
  773. if { $img != "" } {
  774. # Sven
  775. set id [$path.c find withtag $page:img]
  776. if { [string equal $id ""] } {
  777. set id [$path.c create image $ximg $ytext \
  778. -anchor nw \
  779. -tags [list page p:$page $page:img]]
  780. }
  781. $path.c coords $id $ximg $ytext
  782. $path.c itemconfigure $id -image $img
  783. # Sven end
  784. } else {
  785. $path.c delete $page:img
  786. }
  787. if { $data(select) == $page } {
  788. $path.c raise p:$page
  789. } elseif { $pos == 0 } {
  790. if { $data(select) == "" } {
  791. $path.c raise p:$page
  792. } else {
  793. $path.c lower p:$page p:$data(select)
  794. }
  795. } else {
  796. set pred [lindex $data(pages) [expr {$pos-1}]]
  797. if { $data(select) != $pred || $pos == 1 } {
  798. $path.c lower p:$page p:$pred
  799. } else {
  800. $path.c lower p:$page p:[lindex $data(pages) [expr {$pos-2}]]
  801. }
  802. }
  803. }
  804. # -----------------------------------------------------------------------------
  805. # Command NoteBook::_draw_arrows
  806. # -----------------------------------------------------------------------------
  807. proc NoteBook::_draw_arrows { path } {
  808. variable _warrow
  809. variable $path
  810. upvar 0 $path data
  811. set w [expr {[winfo width $path]-1}]
  812. set h [expr {$data(hpage)-1}]
  813. set nbpages [llength $data(pages)]
  814. set xl 0
  815. set xr [expr {$w-$_warrow+1}]
  816. # Sven
  817. set side [Widget::cget $path -side]
  818. if { [string equal $side "bottom"] } {
  819. set h1 [expr {[winfo height $path]-1}]
  820. set bd [Widget::cget $path -borderwidth]
  821. if {$bd < 1} { set bd 1 }
  822. set y0 [expr {$h1 - $data(hpage) + $bd}]
  823. } else {
  824. set y0 1
  825. }
  826. # Sven end (all y positions where replaced with $y0 later)
  827. if { $data(base) > 0 } {
  828. # Sven
  829. if { ![llength [$path.c find withtag "leftarrow"]] } {
  830. $path.c create window $xl $y0 \
  831. -width $_warrow \
  832. -height $h \
  833. -anchor nw \
  834. -window $path.c.fg \
  835. -tags "leftarrow"
  836. } else {
  837. $path.c coords "leftarrow" $xl $y0
  838. $path.c itemconfigure "leftarrow" -width $_warrow -height $h
  839. }
  840. # Sven end
  841. } else {
  842. $path.c delete "leftarrow"
  843. }
  844. if { $data(base) < $nbpages-1 &&
  845. $data(wpage) + [_get_x_page $path 0] + 6 > $w } {
  846. # Sven
  847. if { ![llength [$path.c find withtag "rightarrow"]] } {
  848. $path.c create window $xr $y0 \
  849. -width $_warrow \
  850. -height $h \
  851. -window $path.c.fd \
  852. -anchor nw \
  853. -tags "rightarrow"
  854. } else {
  855. $path.c coords "rightarrow" $xr $y0
  856. $path.c itemconfigure "rightarrow" -width $_warrow -height $h
  857. }
  858. # Sven end
  859. } else {
  860. $path.c delete "rightarrow"
  861. }
  862. }
  863. # -----------------------------------------------------------------------------
  864. # Command NoteBook::_draw_area
  865. # -----------------------------------------------------------------------------
  866. proc NoteBook::_draw_area { path } {
  867. variable $path
  868. upvar 0 $path data
  869. set w [expr {[winfo width $path] - 1}]
  870. set h [expr {[winfo height $path] - 1}]
  871. set bd [Widget::cget $path -borderwidth]
  872. if {$bd < 1} { set bd 1 }
  873. set x0 [expr {$bd - 1}]
  874. set arcRadius [Widget::cget $path -arcradius]
  875. # Sven
  876. set side [Widget::cget $path -side]
  877. if {"$side" == "bottom"} {
  878. set y0 0
  879. set y1 [expr {$h - $data(hpage)}]
  880. set yo $y1
  881. } else {
  882. set y0 $data(hpage)
  883. set y1 $h
  884. set yo [expr {$h-$y0}]
  885. }
  886. # Sven end
  887. set dbg $data(dbg)
  888. set sel $data(select)
  889. if { $sel == "" } {
  890. set xd [expr {$w/2}]
  891. set xf $xd
  892. set lbg $data(dbg)
  893. } else {
  894. set xd [_get_x_page $path [lsearch -exact $data(pages) $data(select)]]
  895. set xf [expr {$xd + $data($sel,width) + $arcRadius + 1}]
  896. set lbg $data(lbg)
  897. }
  898. # Sven
  899. if { [llength [$path.c find withtag rect]] == 0} {
  900. $path.c create line $xd $y0 $x0 $y0 $x0 $y1 \
  901. -tags "rect toprect1"
  902. $path.c create line $w $y0 $xf $y0 \
  903. -tags "rect toprect2"
  904. $path.c create line 1 $h $w $h $w $y0 \
  905. -tags "rect botrect"
  906. }
  907. if {"$side" == "bottom"} {
  908. $path.c coords "toprect1" $w $y0 $x0 $y0 $x0 $y1
  909. $path.c coords "toprect2" $x0 $y1 $xd $y1
  910. $path.c coords "botrect" $xf $y1 $w $y1 $w $y0
  911. $path.c itemconfigure "toprect1" -fill $lbg -width $bd
  912. $path.c itemconfigure "toprect2" -fill $dbg -width $bd
  913. $path.c itemconfigure "botrect" -fill $dbg -width $bd
  914. } else {
  915. $path.c coords "toprect1" $xd $y0 $x0 $y0 $x0 $y1
  916. $path.c coords "toprect2" $w $y0 $xf $y0
  917. $path.c coords "botrect" $x0 $h $w $h $w $y0
  918. $path.c itemconfigure "toprect1" -fill $lbg -width $bd
  919. $path.c itemconfigure "toprect2" -fill $lbg -width $bd
  920. $path.c itemconfigure "botrect" -fill $dbg -width $bd
  921. }
  922. $path.c raise "rect"
  923. # Sven end
  924. if { $sel != "" } {
  925. # Sven
  926. if { [llength [$path.c find withtag "window"]] == 0 } {
  927. $path.c create window 2 [expr {$y0+1}] \
  928. -width [expr {$w-3}] \
  929. -height [expr {$yo-3}] \
  930. -anchor nw \
  931. -tags "window" \
  932. -window $path.f$sel
  933. }
  934. $path.c coords "window" 2 [expr {$y0+1}]
  935. $path.c itemconfigure "window" \
  936. -width [expr {$w-3}] \
  937. -height [expr {$yo-3}] \
  938. -window $path.f$sel
  939. # Sven end
  940. } else {
  941. $path.c delete "window"
  942. }
  943. }
  944. # -----------------------------------------------------------------------------
  945. # Command NoteBook::_resize
  946. # -----------------------------------------------------------------------------
  947. proc NoteBook::_resize { path } {
  948. variable $path
  949. upvar 0 $path data
  950. if {!$data(realized)} {
  951. if { [set width [Widget::cget $path -width]] == 0 ||
  952. [set height [Widget::cget $path -height]] == 0 } {
  953. compute_size $path
  954. }
  955. set data(realized) 1
  956. }
  957. NoteBook::_redraw $path
  958. }
  959. # Tree::_set_help --
  960. #
  961. # Register dynamic help for a node in the tree.
  962. #
  963. # Arguments:
  964. # path Tree to query
  965. # node Node in the tree
  966. # force Optional argument to force a reset of the help
  967. #
  968. # Results:
  969. # none
  970. # Tree::_set_help --
  971. #
  972. # Register dynamic help for a node in the tree.
  973. #
  974. # Arguments:
  975. # path Tree to query
  976. # node Node in the tree
  977. # force Optional argument to force a reset of the help
  978. #
  979. # Results:
  980. # none
  981. proc NoteBook::_set_help { path page } {
  982. Widget::getVariable $path help
  983. set item $path.f$page
  984. set opts [list -helptype -helptext -helpvar]
  985. foreach {cty ctx cv} [eval [list Widget::hasChangedX $item] $opts] break
  986. set text [Widget::getoption $item -helptext]
  987. ## If we've never set help for this item before, and text is not blank,
  988. ## we need to setup help. We also need to reset help if any of the
  989. ## options have changed.
  990. if { (![info exists help($page)] && $text != "") || $cty || $ctx || $cv } {
  991. set help($page) 1
  992. set type [Widget::getoption $item -helptype]
  993. switch $type {
  994. balloon {
  995. DynamicHelp::register $path.c balloon p:$page $text
  996. }
  997. variable {
  998. set var [Widget::getoption $item -helpvar]
  999. DynamicHelp::register $path.c variable p:$page $var $text
  1000. }
  1001. }
  1002. }
  1003. }
  1004. proc NoteBook::_get_page_name { path {item current} {tagindex end-1} } {
  1005. return [string range [lindex [$path.c gettags $item] $tagindex] 2 end]
  1006. }