summaryrefslogtreecommitdiffstats
path: root/library/ttk/scrollbar.tcl
diff options
context:
space:
mode:
authorhobbs <hobbs>2006-10-31 01:42:25 (GMT)
committerhobbs <hobbs>2006-10-31 01:42:25 (GMT)
commit68d670bcf4084b9b910f9a94115271a454e20d49 (patch)
tree61d5e957eccfcba57b0dd27ebc73db085385834e /library/ttk/scrollbar.tcl
parent6c14c5897ab231a04b7e4edae08cb6f2cccbf7a1 (diff)
downloadtk-68d670bcf4084b9b910f9a94115271a454e20d49.zip
tk-68d670bcf4084b9b910f9a94115271a454e20d49.tar.gz
tk-68d670bcf4084b9b910f9a94115271a454e20d49.tar.bz2
* doc/ttk_Geometry.3, doc/ttk_Theme.3, doc/ttk_button.n:
* doc/ttk_checkbutton.n, doc/ttk_combobox.n, doc/ttk_dialog.n: * doc/ttk_entry.n, doc/ttk_frame.n, doc/ttk_image.n: * doc/ttk_intro.n, doc/ttk_label.n, doc/ttk_labelframe.n: * doc/ttk_menubutton.n, doc/ttk_notebook.n, doc/ttk_panedwindow.n: * doc/ttk_progressbar.n, doc/ttk_radiobutton.n, doc/ttk_scrollbar.n: * doc/ttk_separator.n, doc/ttk_sizegrip.n, doc/ttk_style.n: * doc/ttk_treeview.n, doc/ttk_widget.n,: * generic/ttk/ttk.decls, generic/ttk/ttkBlink.c: * generic/ttk/ttkButton.c, generic/ttk/ttkCache.c: * generic/ttk/ttkClamTheme.c, generic/ttk/ttkClassicTheme.c: * generic/ttk/ttkDecls.h, generic/ttk/ttkDefaultTheme.c: * generic/ttk/ttkElements.c, generic/ttk/ttkEntry.c: * generic/ttk/ttkFrame.c, generic/ttk/ttkImage.c: * generic/ttk/ttkInit.c, generic/ttk/ttkLabel.c: * generic/ttk/ttkLayout.c, generic/ttk/ttkManager.c: * generic/ttk/ttkManager.h, generic/ttk/ttkNotebook.c: * generic/ttk/ttkPanedwindow.c, generic/ttk/ttkProgress.c: * generic/ttk/ttkScale.c, generic/ttk/ttkScroll.c: * generic/ttk/ttkScrollbar.c, generic/ttk/ttkSeparator.c: * generic/ttk/ttkSquare.c, generic/ttk/ttkState.c: * generic/ttk/ttkStubInit.c, generic/ttk/ttkStubLib.c: * generic/ttk/ttkTagSet.c, generic/ttk/ttkTheme.c: * generic/ttk/ttkTheme.h, generic/ttk/ttkThemeInt.h: * generic/ttk/ttkTrace.c, generic/ttk/ttkTrack.c: * generic/ttk/ttkTreeview.c, generic/ttk/ttkWidget.c: * generic/ttk/ttkWidget.h: * library/demos/ttk_demo.tcl, library/demos/ttk_iconlib.tcl: * library/demos/ttk_repeater.tcl: * library/ttk/altTheme.tcl, library/ttk/aquaTheme.tcl: * library/ttk/button.tcl, library/ttk/clamTheme.tcl: * library/ttk/classicTheme.tcl, library/ttk/combobox.tcl: * library/ttk/cursors.tcl, library/ttk/defaults.tcl: * library/ttk/dialog.tcl, library/ttk/entry.tcl: * library/ttk/fonts.tcl, library/ttk/icons.tcl: * library/ttk/keynav.tcl, library/ttk/menubutton.tcl: * library/ttk/notebook.tcl, library/ttk/panedwindow.tcl: * library/ttk/progress.tcl, library/ttk/scale.tcl: * library/ttk/scrollbar.tcl, library/ttk/sizegrip.tcl: * library/ttk/treeview.tcl, library/ttk/ttk.tcl: * library/ttk/utils.tcl, library/ttk/winTheme.tcl: * library/ttk/xpTheme.tcl: * macosx/ttkMacOSXTheme.c: * tests/ttk/all.tcl, tests/ttk/bwidget.test, tests/ttk/combobox.test: * tests/ttk/entry.test, tests/ttk/image.test: * tests/ttk/labelframe.test, tests/ttk/layout.test: * tests/ttk/misc.test, tests/ttk/notebook.test: * tests/ttk/panedwindow.test, tests/ttk/progressbar.test: * tests/ttk/scrollbar.test, tests/ttk/treetags.test: * tests/ttk/treeview.test, tests/ttk/ttk.test, tests/ttk/validate.test: * win/ttkWinMonitor.c, win/ttkWinTheme.c, win/ttkWinXPTheme.c: First import of Ttk themed Tk widgets as branched from tile 0.7.8 * generic/tkInt.h, generic/tkWindow.c: add Ttk_Init call, copy tk classic widgets to ::tk namespace. * library/tk.tcl: add source of ttk/ttk.tcl, define $::ttk::library. * unix/Makefile.in, win/Makefile.in: add Ttk build bits * win/configure, win/configure.in: check for uxtheme.h (XP theme).
Diffstat (limited to 'library/ttk/scrollbar.tcl')
-rw-r--r--library/ttk/scrollbar.tcl107
1 files changed, 107 insertions, 0 deletions
diff --git a/library/ttk/scrollbar.tcl b/library/ttk/scrollbar.tcl
new file mode 100644
index 0000000..6b37b24
--- /dev/null
+++ b/library/ttk/scrollbar.tcl
@@ -0,0 +1,107 @@
+#
+# $Id: scrollbar.tcl,v 1.1 2006/10/31 01:42:27 hobbs Exp $
+#
+# Bindings for TScrollbar widget
+#
+
+namespace eval ttk::scrollbar {
+ variable State
+ # State(xPress) --
+ # State(yPress) -- initial position of mouse at start of drag.
+ # State(first) -- value of -first at start of drag.
+}
+
+bind TScrollbar <ButtonPress-1> { ttk::scrollbar::Press %W %x %y }
+bind TScrollbar <B1-Motion> { ttk::scrollbar::Drag %W %x %y }
+bind TScrollbar <ButtonRelease-1> { ttk::scrollbar::Release %W %x %y }
+
+bind TScrollbar <ButtonPress-2> { ttk::scrollbar::Jump %W %x %y }
+bind TScrollbar <B2-Motion> { ttk::scrollbar::Drag %W %x %y }
+bind TScrollbar <ButtonRelease-2> { ttk::scrollbar::Release %W %x %y }
+
+proc ttk::scrollbar::Scroll {w n units} {
+ set cmd [$w cget -command]
+ if {$cmd ne ""} {
+ uplevel #0 $cmd scroll $n $units
+ }
+}
+
+proc ttk::scrollbar::Moveto {w fraction} {
+ set cmd [$w cget -command]
+ if {$cmd ne ""} {
+ uplevel #0 $cmd moveto $fraction
+ }
+}
+
+proc ttk::scrollbar::Press {w x y} {
+ variable State
+
+ set State(xPress) $x
+ set State(yPress) $y
+
+ switch -glob -- [$w identify $x $y] {
+ *uparrow -
+ *leftarrow {
+ ttk::Repeatedly Scroll $w -1 units
+ }
+ *downarrow -
+ *rightarrow {
+ ttk::Repeatedly Scroll $w 1 units
+ }
+ *thumb {
+ set State(first) [lindex [$w get] 0]
+ }
+ *trough {
+ set f [$w fraction $x $y]
+ if {$f < [lindex [$w get] 0]} {
+ # Clicked in upper/left trough
+ ttk::Repeatedly Scroll $w -1 pages
+ } elseif {$f > [lindex [$w get] 1]} {
+ # Clicked in lower/right trough
+ ttk::Repeatedly Scroll $w 1 pages
+ } else {
+ # Clicked on thumb (???)
+ set State(first) [lindex [$w get] 0]
+ }
+ }
+ }
+}
+
+proc ttk::scrollbar::Drag {w x y} {
+ variable State
+ if {![info exists State(first)]} {
+ # Initial buttonpress was not on the thumb,
+ # or something screwy has happened. In either case, ignore:
+ return;
+ }
+ set xDelta [expr {$x - $State(xPress)}]
+ set yDelta [expr {$y - $State(yPress)}]
+ Moveto $w [expr {$State(first) + [$w delta $xDelta $yDelta]}]
+}
+
+proc ttk::scrollbar::Release {w x y} {
+ variable State
+ unset -nocomplain State(xPress) State(yPress) State(first)
+ ttk::CancelRepeat
+}
+
+# scrollbar::Jump -- ButtonPress-2 binding for scrollbars.
+# Behaves exactly like scrollbar::Press, except that
+# clicking in the trough jumps to the the selected position.
+#
+proc ttk::scrollbar::Jump {w x y} {
+ variable State
+
+ switch -glob -- [$w identify $x $y] {
+ *thumb -
+ *trough {
+ set State(first) [$w fraction $x $y]
+ Moveto $w $State(first)
+ set State(xPress) $x
+ set State(yPress) $y
+ }
+ default {
+ Press $w $x $y
+ }
+ }
+}