#
# My thbind configuration file
#


# I have two commands added to all widgets. One is Control-O, it changes the
# default font (It toggles between a large font and a small one, and for text
# widgets, it changes the font for all tags to the default font.) The other is
# Control-C, and it switches the default foreground and background color of the
# widget.


# Adding the keybindings is easy...
bind all <Control-O> {th_redo_font %W}
bind all <Control-C> {th_recolor %W}

# Adding the menus is a bit harder...I'd use the appropriate menu procedure if
# I were adding bindings to a particular widget class. 'Misc' is appropriate
# for all widgets.
set code [info body th_Misc_menus]
proc th_Misc_menus {w} [concat $code { ; 
  "$TH(Menubar,$w).mb_extras.m" add command -label "Resize Font" -u 7 \
	-accel "<Control-O>" -command "th_redo_font $w"
  "$TH(Menubar,$w).mb_extras.m" add command -label "Recolor" -u 3 \
	-accel "<Control-C>" -command "th_recolor $w"
}]


# This simply toggles the font between big and small.
# Will only work for widgets with a -font option, of course.
proc th_redo_font {w} {
  set bigfont "-*-*-medium-*-narrow--28-*-*-*-*-*-*-1"
  if {([$w cget -font] == "fixed")} {set font $bigfont} else {set font fixed}
  th_configure $w -font $font
}

# This simply toggles the foreground and background colors.
# (It won't work on scrollbars, which don't have a -background option).
proc th_recolor {w} {
  th_configure $w -foreground [$w cget -background] -background [$w cget -foreground]
}

# Wrapper around Tk's configure command...it also configures tags in texts.
proc th_configure {w args} {
  eval $w configure $args
  if {[winfo class $w] == "Text"} {
    foreach tag [$w tag names] {eval $w tag configure $tag $args}
}}
